This is an archive of the discontinued LLVM Phabricator instance.

Make DynamicLoaderPOSIXDYLD::DidAttach to deduce a target executable by pid if no executable hasn't been assigned to a target so far.
ClosedPublic

Authored by ovyalov on Dec 19 2014, 1:45 PM.

Details

Reviewers
clayborg
Summary

If user attaches to a local process by pid without executable assigned to a target we can deduce an executable path by pid, otherwise no symbols are loaded and not possible to set up breakpoints.

Diff Detail

Event Timeline

ovyalov updated this revision to Diff 17510.Dec 19 2014, 1:45 PM
ovyalov retitled this revision from to Make DynamicLoaderPOSIXDYLD::DidAttach to deduce a target executable by pid if no executable hasn't been assigned to a target so far..
ovyalov updated this object.
ovyalov edited the test plan for this revision. (Show Details)
ovyalov added a reviewer: clayborg.
ovyalov added a subscriber: Unknown Object (MLST).

Friendly ping.

clayborg requested changes to this revision.Jan 6 2015, 1:36 PM
clayborg edited edge metadata.

Doesn't the auxv data say what the executable is, or does it only contain the shared libraries? If it contains the executable you should check if the executable matches the executable in the target. If it doesn't you will need to get the process info and always update the executable if needed. Examples to show how this can happen are below:

You might want to check if the executable is correct or not regardless of what it is set to. Try this:

In one terminal:
% /bin/cat

And leave it there so it is waiting for stdin

Then in another terminal do:

(lldb) file /bin/ls
(lldb) process attach --pid 123

Where 123 is the process ID for /bin/cat. You should switch the executable if it isn't correct.

Also, try making a program "a.out" that exec()'s itself into something else like "b.out" and make sure the executable updates when the process exec's into another executable and can hit a breakpoint that you set in "a.out" and "b.out" (like setting a breakpoint at "main" with "(lldb) b main".

The job of the dynamic loader is to keep the target up to date and make sure the executable is always correct. You can't rely on what the target contains. The architecture also needs to be updated sometimes in case you do:

(lldb) target create --arch i386 a.out

And then you attach to a b.out that is "x86_64"...

This revision now requires changes to proceed.Jan 6 2015, 1:36 PM
ovyalov updated this revision to Diff 17846.Jan 6 2015, 4:12 PM
ovyalov edited edge metadata.

Thank you for suggestions - I've made corresponding changes to handle such situations when a module file name and/or architecture changes.
Initially I tried to use AT_EXECFN but as I can see it's not reliable option - for example, when I start application from its binary directory (e.g., ./CppTest) AT_EXECFN will be set to "./CppTest" instead of providing a full path.

clayborg accepted this revision.Jan 6 2015, 4:16 PM
clayborg edited edge metadata.

Looks good.

This revision is now accepted and ready to land.Jan 6 2015, 4:16 PM
Eugene.Zelenko added a subscriber: Eugene.Zelenko.

Committed in r225332.