Vector35 / debugger

Binary Ninja debugger
Other
207 stars 14 forks source link

LLDB: Specify target architecture #237

Open bb010g opened 2 years ago

bb010g commented 2 years ago

When using lldb's console interface, to create a target for a Universal excutable on macOS, --arch <arch> must be provided (e.g. --arch x86_64) to target create, or else creating the target fails. Binary Ninja's LLDB adapter calls the SBDebugger::CreateTarget(const char *filename) function when creating a target, which does not specify the target's platform or architecture and does not fail on Universal executables. As a result, when it calls process launch without --arch <arch> later, the command fails (e.g. dbg.launch() returns False).

This is probably avoidable by passing --arch <arch> to process launch, but it looks like this isn't how LLDB wants to be doing things moving forward (this is accomplished via lldb_private::ProcessInfo::GetArchitecture()).

Instead, the SBDebugger::CreateTarget(const char *filename, const char *target_triple, const char *platform_name, bool add_dependent_modules, lldb::SBError &error) function could be called when creating a target. target_triple can be left empty to specify the currently selected platform's architecture (per SBDebugger::GetSelectedPlatform()), and platform_name also can be left empty to specify the currently selected platform. If a valid architecture is specified for a target, it's used as a default when launching. I don't see a way to assign an arch later via the launch_info argument to SBTarget::Launch(SBLaunchInfo &launch_info, SBError &error); SBLaunchInfo doesn't expose lldb_private::ProcessInfo::GetArchitecture().

xusheng6 commented 1 year ago

Related to #262

xusheng6 commented 1 year ago

https://github.com/Vector35/debugger/issues/262 resolves the issue that we cannot debug fat binaries on macOS. Although this issue tracks to a broader problem, it does not seem to be immediately blocking any workflow. So I keep this issue open, while assigning a lower priority to it.