[Lldb-commits] [lldb] r123307 - /lldb/trunk/source/Host/common/Host.cpp

Greg Clayton gclayton at apple.com
Wed Jan 12 10:36:46 PST 2011


Quick possible optimization on the code below: I am guessing that readlink() returns a path that is already resolved? If so then passing true to the FileSpec constructor line:

	g_program_filespec = FileSpec(exe_path, true);

will cause realpath() to be called on exe_path to try and resolve the path (which is typically meant for paths that might be symlinks, or "~/path/to/file", or "relative/path/to/file") which is probably redundant. We can pass false to this if the path is already resolved and avoid this:

	g_program_filespec = FileSpec(exe_path, false);

Better yet, since the FileSpec constructor calls FileSpec::SetFile(...) anyway, this could just become:

	g_program_filespec.SetFile (exe_path, false);

On Jan 11, 2011, at 8:21 PM, Stephen Wilson wrote:

> Author: wilsons
> Date: Tue Jan 11 22:21:21 2011
> New Revision: 123307
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=123307&view=rev
> Log:
> Null terminate path returned by readlink().
> 
> 
> Modified:
>    lldb/trunk/source/Host/common/Host.cpp
> 
> Modified: lldb/trunk/source/Host/common/Host.cpp
> URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/Host.cpp?rev=123307&r1=123306&r2=123307&view=diff
> ==============================================================================
> --- lldb/trunk/source/Host/common/Host.cpp (original)
> +++ lldb/trunk/source/Host/common/Host.cpp Tue Jan 11 22:21:21 2011
> @@ -620,9 +620,11 @@
>         }
> #elif defined (__linux__)
>         char exe_path[PATH_MAX];
> -        ssize_t len = readlink("/proc/self/exe", exe_path, sizeof(exe_path));
> -        if (len >= 0)
> +        ssize_t len = readlink("/proc/self/exe", exe_path, sizeof(exe_path) - 1);
> +        if (len > 0) {
> +            exe_path[len] = 0;
>             g_program_filespec = FileSpec(exe_path, true);
> +        }
> #elif defined (__FreeBSD__)
>         int exe_path_mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, getpid() };
>         size_t exe_path_size;
> 
> 
> _______________________________________________
> lldb-commits mailing list
> lldb-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits





More information about the lldb-commits mailing list