[Lldb-commits] [lldb] 60b90b5 - [lldb][DynamicLoader] Fix lldb unable to stop at _dl_debug_state if user set it before the process launched. (#88792)
via lldb-commits
lldb-commits at lists.llvm.org
Wed Apr 17 13:09:42 PDT 2024
Author: Zequan Wu
Date: 2024-04-17T16:09:38-04:00
New Revision: 60b90b523323f8196a9e4a68b1f33358624c09eb
URL: https://github.com/llvm/llvm-project/commit/60b90b523323f8196a9e4a68b1f33358624c09eb
DIFF: https://github.com/llvm/llvm-project/commit/60b90b523323f8196a9e4a68b1f33358624c09eb.diff
LOG: [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.
Added:
Modified:
lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
lldb/test/API/functionalities/breakpoint/breakpoint_command/TestBreakpointCommand.py
Removed:
################################################################################
diff --git a/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp b/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
index 9baf86da4dc799..9fa245fc41d40c 100644
--- a/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
+++ b/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
@@ -571,10 +571,17 @@ ModuleSP DynamicLoaderPOSIXDYLD::LoadInterpreterModule() {
FileSpec file(info.GetName().GetCString());
ModuleSpec module_spec(file, target.GetArchitecture());
- if (ModuleSP module_sp = target.GetOrCreateModule(module_spec,
- true /* notify */)) {
+ // Don't notify that module is added here because its loading section
+ // addresses are not updated yet. We manually notify it below.
+ if (ModuleSP module_sp =
+ target.GetOrCreateModule(module_spec, /*notify=*/false)) {
UpdateLoadedSections(module_sp, LLDB_INVALID_ADDRESS, m_interpreter_base,
false);
+ // Manually notify that dynamic linker is loaded after updating load section
+ // addersses so that breakpoints can be resolved.
+ ModuleList module_list;
+ module_list.Append(module_sp);
+ target.ModulesDidLoad(module_list);
m_interpreter_module = module_sp;
return module_sp;
}
diff --git a/lldb/test/API/functionalities/breakpoint/breakpoint_command/TestBreakpointCommand.py b/lldb/test/API/functionalities/breakpoint/breakpoint_command/TestBreakpointCommand.py
index ea242952e409ec..850235fdcefa70 100644
--- a/lldb/test/API/functionalities/breakpoint/breakpoint_command/TestBreakpointCommand.py
+++ b/lldb/test/API/functionalities/breakpoint/breakpoint_command/TestBreakpointCommand.py
@@ -671,3 +671,20 @@ def test_breakpoint_statistics_hitcount(self):
self.assertNotEqual(breakpoints_stats, None)
for breakpoint_stats in breakpoints_stats:
self.assertIn("hitCount", breakpoint_stats)
+
+ @skipIf(oslist=no_match(["linux"]))
+ def test_break_at__dl_debug_state(self):
+ """
+ Test lldb is able to stop at _dl_debug_state if it is set before the
+ process is launched.
+ """
+ self.build()
+ exe = self.getBuildArtifact("a.out")
+ self.runCmd("target create %s" % exe)
+ bpid = lldbutil.run_break_set_by_symbol(
+ self, "_dl_debug_state", num_expected_locations=0
+ )
+ self.runCmd("run")
+ self.assertIsNotNone(
+ lldbutil.get_one_thread_stopped_at_breakpoint_id(self.process(), bpid)
+ )
More information about the lldb-commits
mailing list