[lldb] Call Target::ClearAllLoadedSections earlier (#138892)

Minidump files contain explicit information about load addresses of
modules, so it can load them itself. This works on other platforms, but
fails on darwin because DynamicLoaderDarwin nukes the loaded module list
on initialization (which happens after the core file plugin has done its
work).

This used to work until #109477, which enabled the dynamic loader
plugins for minidump files in order to get them to provide access to
TLS.

Clearing the load list makes sense, but I think we could do it earlier
in the process, so that both Process and DynamicLoader plugins get a
chance to load modules. This patch does that by calling the function
early in the launch/attach/load core flows.

This fixes TestDynamicValue.py:test_from_core_file on darwin.
This commit is contained in:
Pavel Labath
2025-05-14 11:16:55 +02:00
committed by GitHub
parent 6b97a98e79
commit 97aa01bef7
3 changed files with 4 additions and 2 deletions

View File

@@ -872,7 +872,6 @@ void DynamicLoaderDarwin::PrivateInitialize(Process *process) {
StateAsCString(m_process->GetState()));
Clear(true);
m_process = process;
m_process->GetTarget().ClearAllLoadedSections();
}
// Member function that gets called when the process state changes.

View File

@@ -2763,6 +2763,7 @@ Status Process::LaunchPrivate(ProcessLaunchInfo &launch_info, StateType &state,
}
if (state == eStateStopped || state == eStateCrashed) {
GetTarget().ClearAllLoadedSections();
DidLaunch();
// Now that we know the process type, update its signal responses from the
@@ -2799,6 +2800,7 @@ Status Process::LaunchPrivate(ProcessLaunchInfo &launch_info, StateType &state,
}
Status Process::LoadCore() {
GetTarget().ClearAllLoadedSections();
Status error = DoLoadCore();
if (error.Success()) {
ListenerSP listener_sp(
@@ -3094,6 +3096,8 @@ void Process::CompleteAttach() {
Log *log(GetLog(LLDBLog::Process | LLDBLog::Target));
LLDB_LOGF(log, "Process::%s()", __FUNCTION__);
GetTarget().ClearAllLoadedSections();
// Let the process subclass figure out at much as it can about the process
// before we go looking for a dynamic loader plug-in.
ArchSpec process_arch;

View File

@@ -282,7 +282,6 @@ class DynamicValueTestCase(TestBase):
@no_debug_info_test
@expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24663")
@expectedFailureDarwin # dynamic loader unloads modules
@expectedFailureAll(archs=["arm"]) # Minidump saving not implemented
def test_from_core_file(self):
"""Test fetching C++ dynamic values from core files. Specifically, test