<div dir="ltr">I believe this patch passes all the test suites.  Though to be fair there really aren't tests for handling ~ expansion.  If you could go ahead and commit this that would be great.<br><br></div><div class="gmail_extra">
<br><br><div class="gmail_quote">On Tue, Jul 2, 2013 at 12:46 PM, Greg Clayton <span dir="ltr"><<a href="mailto:gclayton@apple.com" target="_blank">gclayton@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
As long as the test suite passes, this looks good.<br>
<div class="HOEnZb"><div class="h5"><br>
On Jul 2, 2013, at 11:37 AM, Matthew Sorrels <<a href="mailto:sorrels.m@gmail.com">sorrels.m@gmail.com</a>> wrote:<br>
<br>
> Any comments on this?<br>
><br>
><br>
> On Wed, Jun 26, 2013 at 3:41 PM, Matthew Sorrels <<a href="mailto:sorrels.m@gmail.com">sorrels.m@gmail.com</a>> wrote:<br>
> This changes TargetList so that it will expand the ~ cases, but not process any symbolic links while doing so.  It does this by using the FileSpec::ResolveUsername function directly.  It seems to work on cases where the binary is something like ~/a.out it also works on cases where the binary is a symbolic link ~/mytest the arg0 passed in is mytest and not a.out.<br>

><br>
> Index: source/Target/TargetList.cpp<br>
> ===================================================================<br>
> --- source/Target/TargetList.cpp    (revision 185025)<br>
> +++ source/Target/TargetList.cpp    (working copy)<br>
> @@ -221,8 +221,19 @@<br>
><br>
>      FileSpec file (user_exe_path, false);<br>
>      if (!file.Exists() && user_exe_path && user_exe_path[0] == '~')<br>
>      {<br>
> -        file = FileSpec(user_exe_path, true);<br>
> +        // we want to expand the tilde but we don't want to resolve any symbolic links<br>
> +        // so we can't use the FileSpec constructor's resolve flag<br>
> +        char unglobbed_path[PATH_MAX];<br>
> +        unglobbed_path[0] = '\0';<br>
> +<br>
> +        size_t return_count = FileSpec::ResolveUsername(user_exe_path, unglobbed_path, sizeof(unglobbed_path));<br>
> +<br>
> +        if (return_count == 0 || return_count >= sizeof(unglobbed_path))<br>
> +            ::snprintf (unglobbed_path, sizeof(unglobbed_path), "%s", user_exe_path);<br>
> +<br>
> +        file = FileSpec(unglobbed_path, false);<br>
>      }<br>
> +<br>
>      bool user_exe_path_is_bundle = false;<br>
>      char resolved_bundle_exe_path[PATH_MAX];<br>
>      resolved_bundle_exe_path[0] = '\0';<br>
> @@ -304,8 +315,8 @@<br>
><br>
>              }<br>
>              else<br>
>              {<br>
> -                // Just use what the user typed<br>
> -                target_sp->SetArg0 (user_exe_path);<br>
> +                // Use resolved path<br>
> +                target_sp->SetArg0 (file.GetPath().c_str());<br>
>              }<br>
>          }<br>
>          if (file.GetDirectory())<br>
><br>
><br>
><br>
> On Tue, Jun 25, 2013 at 1:47 PM, Greg Clayton <<a href="mailto:gclayton@apple.com">gclayton@apple.com</a>> wrote:<br>
> This patch will break people who try and do the following:<br>
><br>
> % lldb /usr/bin/clang++<br>
><br>
> clang++ is a symlink to "/usr/bin/clang". When we debug the program and it reaches main, clang will look at argv[0] and do something if the program is clang++ and something else if it is clang. We really want to _just_ resolve the "~" or the "~username" from the path and leave the rest alone so we don't change argv[0] from what the user specified.<br>

><br>
> On Jun 25, 2013, at 1:29 PM, Matthew Sorrels <<a href="mailto:sorrels.m@gmail.com">sorrels.m@gmail.com</a>> wrote:<br>
><br>
> > Bug 16443 - target create doesn't expand ~ on Linux<br>
> ><br>
> > I created a bug for this, but it wasn't as complex to fix as I had thought.  Though I'm not exactly sure what the effects this change could have.  The test suite runs the same on Linux with or without it, but I'm not sure that's enough.  It does seem like the code went out of its way to set the arg0 to be whatever the user typed, rather than the resolved path.  Perhaps there is a reason for this I don't understand?<br>

> ><br>
> ><br>
> > Here's the bug summary:<br>
> > If you start lldb and do a target create on a path with a ~ as part of the path, it is accepted but when trying to run the process the launch fails.<br>
> ><br>
> > Here's an example where the test binary is ~/a.out  it is also /home/matthews/a.out which works fine.  Both paths work fine when used on the command line (most likely due to shell expansion)<br>
> ><br>
> > matthews@matthews-linux:~/work/llvm/llvm/build$ bin/lldb<br>
> > (lldb) version<br>
> > lldb version 3.4 (<br>
> > <a href="http://llvm.org/svn/llvm-project/lldb/trunk" target="_blank">http://llvm.org/svn/llvm-project/lldb/trunk</a><br>
> >  revision 184861)<br>
> > (lldb) target create ~/a.out<br>
> > Current executable set to '~/a.out' (x86_64).<br>
> > (lldb) run<br>
> > error: process launch failed: Child exec failed.<br>
> ><br>
> ><br>
> > (lldb) target create /home/matthews/a.out<br>
> > Current executable set to '/home/matthews/a.out' (x86_64).<br>
> > (lldb) run<br>
> > Process 4493 launched: '/home/matthews/a.out' (x86_64)<br>
> > Hello world!<br>
> > Function 106<br>
> > Process 4493 exited with status = 13 (0x0000000d)<br>
> > (lldb)<br>
> ><br>
> > The target list command shows the full path to the file, but that full path isn't being used when the process is started with run.<br>
> ><br>
> > (lldb) target create ~/a.out<br>
> > Current executable set to '~/a.out' (x86_64).<br>
> > (lldb) target list<br>
> > Current targets:<br>
> > * target #0: /home/matthews/a.out ( arch=x86_64--linux, platform=localhost )<br>
> ><br>
> ><br>
> > Here's a possible patch:<br>
> ><br>
> > Index: source/Target/TargetList.cpp<br>
> > ===================================================================<br>
> > --- source/Target/TargetList.cpp    (revision 184861)<br>
> > +++ source/Target/TargetList.cpp    (working copy)<br>
> > @@ -304,8 +304,8 @@<br>
> >              }<br>
> >              else<br>
> >              {<br>
> > -                // Just use what the user typed<br>
> > -                target_sp->SetArg0 (user_exe_path);<br>
> > +                // Use resolved path<br>
> > +                target_sp->SetArg0 (file.GetPath().c_str());<br>
> >              }<br>
> >          }<br>
> >          if (file.GetDirectory())<br>
> ><br>
> > _______________________________________________<br>
> > lldb-commits mailing list<br>
> > <a href="mailto:lldb-commits@cs.uiuc.edu">lldb-commits@cs.uiuc.edu</a><br>
> > <a href="http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits</a><br>
><br>
><br>
><br>
<br>
</div></div></blockquote></div><br></div>