Skip to content

Commit 60b90b5

Browse files
authored
[lldb][DynamicLoader] Fix lldb unable to stop at _dl_debug_state if user set it before the process launched. (#88792)
If user sets a breakpoint at `_dl_debug_state` before the process launched, the breakpoint is not resolved yet. When lldb loads dynamic loader module, it's created with `Target::GetOrCreateModule` which notifies any pending breakpoint to resolve. However, the module's sections are not loaded at this time. They are loaded after returned from [Target::GetOrCreateModule](https://github.com/llvm/llvm-project/blob/0287a5cc4e2a5ded1ae2e4079f91052e6a6b8d9b/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp#L574-L577). This change fixes it by manually resolving breakpoints after creating dynamic loader module.
1 parent d0c51f7 commit 60b90b5

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -571,10 +571,17 @@ ModuleSP DynamicLoaderPOSIXDYLD::LoadInterpreterModule() {
571571
FileSpec file(info.GetName().GetCString());
572572
ModuleSpec module_spec(file, target.GetArchitecture());
573573

574-
if (ModuleSP module_sp = target.GetOrCreateModule(module_spec,
575-
true /* notify */)) {
574+
// Don't notify that module is added here because its loading section
575+
// addresses are not updated yet. We manually notify it below.
576+
if (ModuleSP module_sp =
577+
target.GetOrCreateModule(module_spec, /*notify=*/false)) {
576578
UpdateLoadedSections(module_sp, LLDB_INVALID_ADDRESS, m_interpreter_base,
577579
false);
580+
// Manually notify that dynamic linker is loaded after updating load section
581+
// addersses so that breakpoints can be resolved.
582+
ModuleList module_list;
583+
module_list.Append(module_sp);
584+
target.ModulesDidLoad(module_list);
578585
m_interpreter_module = module_sp;
579586
return module_sp;
580587
}

lldb/test/API/functionalities/breakpoint/breakpoint_command/TestBreakpointCommand.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,3 +671,20 @@ def test_breakpoint_statistics_hitcount(self):
671671
self.assertNotEqual(breakpoints_stats, None)
672672
for breakpoint_stats in breakpoints_stats:
673673
self.assertIn("hitCount", breakpoint_stats)
674+
675+
@skipIf(oslist=no_match(["linux"]))
676+
def test_break_at__dl_debug_state(self):
677+
"""
678+
Test lldb is able to stop at _dl_debug_state if it is set before the
679+
process is launched.
680+
"""
681+
self.build()
682+
exe = self.getBuildArtifact("a.out")
683+
self.runCmd("target create %s" % exe)
684+
bpid = lldbutil.run_break_set_by_symbol(
685+
self, "_dl_debug_state", num_expected_locations=0
686+
)
687+
self.runCmd("run")
688+
self.assertIsNotNone(
689+
lldbutil.get_one_thread_stopped_at_breakpoint_id(self.process(), bpid)
690+
)

0 commit comments

Comments
 (0)