This is an archive of the discontinued LLVM Phabricator instance.

If we still have all_image_infos use it in DynamicLoaderMacOSDYLD to detect exec's
ClosedPublic

Authored by jingham on Dec 6 2018, 4:19 PM.

Details

Summary

The test "TestExec.py" has been on and off flakey on the GreenDragon MacOS bots for a while now. I'm trying to fix that. It adds a lot of noise to the bots.

For background:

The job of detecting an exec used to be handled by the DynamicLoaderMacOSX plugin. But when dyld switched over to a remote API approach rather than data structures lldb inspects, that job became hard. About the only clue remaining for the new dyld API loader (DynamicLoaderMacOS) is whether the program is back at dyld_start when it gets a SIGTRAP. But if dyld has moved in the course of the exec then the new dyld_start address is not the one we knew it as before the exec, so this detection will fail. To make this work on the lldb side, we'd have to refresh the shared library state every time we got a SIGTRAP. But that's expensive.

Fortunately, newer debugservers figure this out on their end and annotate the stop packet with "reason:exec". So there's no need to do it on the lldb side. But because we didn't want to deal with code signing on the bots, they sometimes run older debugservers. And indeed, when Adrian and I were investigating the failures by looking at the packet log we only saw failures when the stop reason didn't include reason:exec.

Also fortunately, in order to support other tools that haven't updated to the new dyld API's, for now dyld is still maintaining the data structures lldb used to look at.

So this patch adds back the check for the dyld info data structure moving that the DynamicLoaderMacOSX used. For debugservers that send reason:exec, this code won't ever get run since ProcessGDBRemote will immediately turn the SIGTRAP into an exec. And it will work correctly with older debugservers until dyld actually removes this structure. At that point, the info address will be LLDB_INVALID_ADDRESS, and this code won't help anymore. But presumably by then we won't have any debugservers we care about that don't send "reason:exec".

Diff Detail

Repository
rLLDB LLDB

Event Timeline

jingham created this revision.Dec 6 2018, 4:19 PM
aprantl added inline comments.Dec 6 2018, 4:26 PM
source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp
83

Why not just write C++11-style = LLDB_INVALID_ADDRESS in the declaration?

102

clang-format :-)

source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.h
107

Perhaps add a /// comment explaining what is being stored here?

jingham updated this revision to Diff 177085.Dec 6 2018, 4:39 PM
jingham marked an inline comment as done.

Added a comment and removed an errant space.

jingham marked 2 inline comments as done.Dec 6 2018, 4:40 PM
jingham added inline comments.
source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp
83

I think it's confusing to have some declaration initialization and some constructor initialization, and I didn't want to change this class over to all initialization as it would add noise to the patch.

aprantl accepted this revision.Dec 6 2018, 4:41 PM

Let's try it.

This revision is now accepted and ready to land.Dec 6 2018, 4:41 PM

If this patch works, then this bot should turn green: http://green.lab.llvm.org/green/view/LLDB/job/lldb-sanitized/

jasonmolenda accepted this revision.Dec 6 2018, 4:46 PM

LGTM.

source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp
104

Do you want to copy the image_infos_address value into m_maybe_image_infos_address so we can detect the next exec?

jingham marked an inline comment as done.Dec 6 2018, 5:11 PM
jingham added inline comments.
source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp
104

You don't need to. If we've exec'ed we have to call DoInitialImageFetch again - since the world has changed - which resets the value. I don't want to do it twice, but I can put in a comment explaining why if that would help.

I don't feel strongly about it, your choice. But if I misunderstood it this time, I'll likely misunderstand it again in the future. :)

jingham marked an inline comment as done.Dec 6 2018, 5:20 PM
jingham added inline comments.
source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp
104

Eh, that's dumb, it's just a single assign, so why not. I added that in the committed version.

This revision was automatically updated to reflect the committed changes.