Fall back to dyld's _dyld_start when no LC_MAIN / main() func can be found
authorJason Molenda <jmolenda@apple.com>
Thu, 18 Jul 2019 20:55:24 +0000 (20:55 +0000)
committerJason Molenda <jmolenda@apple.com>
Thu, 18 Jul 2019 20:55:24 +0000 (20:55 +0000)
commit956761adb0ffdf6be50018aea1fb804ecb2da9f2
treef4411e548e43eb3f1c731889bf25827c2e16f856
parent01963cec9b3fbc8ec98da449180d95be224dfadd
Fall back to dyld's _dyld_start when no LC_MAIN / main() func can be found

The new DriverKit user-land kernel drivers in macOS 10.15 / Catalina
do not have a main() function or an LC_MAIN load command.  lldb uses
the address of main() as the return address for inferior function
calls; it puts a breakpoint on main, runs the inferior function call,
and when the main() breakpoint is hit, lldb knows unambiguously that
the inferior function call ran to completion - no other function calls
main.

This change hoists the logic for finding the "entry address" from
ThreadPlanCallFunction to Target.  It changes the logic to first
try to get the entry address from the main executable module,
but if that module does not have one, it will iterate through all
modules looking for an entry address.

The patch also adds code to ObjectFileMachO to use dyld's
_dyld_start function as an entry address.

<rdar://problem/52343958>

Differential Revision: https://reviews.llvm.org/D64897

llvm-svn: 366493
lldb/include/lldb/Target/Target.h
lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h
lldb/source/Target/Target.cpp
lldb/source/Target/ThreadPlanCallFunction.cpp