Skip to content

Commit 49029f9

Browse files
authored
[lldb] Fix breakpoint resolver serialization bug (#76766)
BreakpointResolverAddress optionally can include the module name related to the address that gets resolved. Currently this will never work because it sets the name to itself (which is empty).
1 parent 09de5e5 commit 49029f9

File tree

2 files changed

+41
-7
lines changed

2 files changed

+41
-7
lines changed

lldb/source/Breakpoint/BreakpointResolverAddress.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,11 @@ BreakpointResolverAddress::SerializeToStructuredData() {
6565
new StructuredData::Dictionary());
6666
SectionSP section_sp = m_addr.GetSection();
6767
if (section_sp) {
68-
ModuleSP module_sp = section_sp->GetModule();
69-
ConstString module_name;
70-
if (module_sp)
71-
module_name.SetCString(module_name.GetCString());
72-
73-
options_dict_sp->AddStringItem(GetKey(OptionNames::ModuleName),
74-
module_name.GetCString());
68+
if (ModuleSP module_sp = section_sp->GetModule()) {
69+
const FileSpec &module_fspec = module_sp->GetFileSpec();
70+
options_dict_sp->AddStringItem(GetKey(OptionNames::ModuleName),
71+
module_fspec.GetPath().c_str());
72+
}
7573
options_dict_sp->AddIntegerItem(GetKey(OptionNames::AddressOffset),
7674
m_addr.GetOffset());
7775
} else {

lldb/test/API/functionalities/breakpoint/serialize/TestBreakpointSerialization.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,42 @@ def test_scripted_extra_args(self):
4949
self.setup_targets_and_cleanup()
5050
self.do_check_extra_args()
5151

52+
def test_resolver_serialization(self):
53+
"""Test that breakpoint resolvers contain the expected information"""
54+
self.build()
55+
self.setup_targets_and_cleanup()
56+
57+
exe_path = self.getBuildArtifact("a.out")
58+
exe_module = self.orig_target.module[exe_path]
59+
self.assertTrue(
60+
exe_module.IsValid(), "Failed to find the executable module in target"
61+
)
62+
sym_ctx_list = exe_module.FindFunctions("main")
63+
self.assertTrue(sym_ctx_list.GetSize() == 1, "Unable to find function 'main'")
64+
sym_ctx = sym_ctx_list.GetContextAtIndex(0)
65+
self.assertTrue(
66+
sym_ctx.IsValid(), "SBSymbolContext representing function 'main' is invalid"
67+
)
68+
main_func = sym_ctx.GetFunction()
69+
self.assertTrue(
70+
main_func.IsValid(), "SBFunction representing 'main' is invalid"
71+
)
72+
main_addr = main_func.GetStartAddress()
73+
74+
bkpt = self.orig_target.BreakpointCreateBySBAddress(main_addr)
75+
self.assertTrue(
76+
bkpt.IsValid(), "Could not place breakpoint on 'main' by address"
77+
)
78+
stream = lldb.SBStream()
79+
sd = bkpt.SerializeToStructuredData()
80+
sd.GetAsJSON(stream)
81+
serialized_data = json.loads(stream.GetData())
82+
83+
self.assertIn(
84+
exe_path,
85+
serialized_data["Breakpoint"]["BKPTResolver"]["Options"]["ModuleName"],
86+
)
87+
5288
def test_structured_data_serialization(self):
5389
target = self.dbg.GetDummyTarget()
5490
self.assertTrue(target.IsValid(), VALID_TARGET)

0 commit comments

Comments
 (0)