Skip to content

Commit 9688e85

Browse files
committed
[lldb] Fix breakpoint resolver serialization bug
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 ddd6acd commit 9688e85

File tree

2 files changed

+36
-7
lines changed

2 files changed

+36
-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: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,37 @@ 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+
sym_ctx_list = self.orig_target.FindFunctions("main")
58+
self.assertTrue(sym_ctx_list.GetSize() == 1, "Unable to find function `main'")
59+
sym_ctx = sym_ctx_list.GetContextAtIndex(0)
60+
self.assertTrue(
61+
sym_ctx.IsValid(), "SBSymbolContext representing function `main' is invalid"
62+
)
63+
main_func = sym_ctx.GetFunction()
64+
self.assertTrue(
65+
main_func.IsValid(), "SBFunction representing `main' is invalid"
66+
)
67+
main_addr = main_func.GetStartAddress()
68+
69+
bkpt = self.orig_target.BreakpointCreateBySBAddress(main_addr)
70+
self.assertTrue(
71+
bkpt.IsValid(), "Could not place breakpoint on `main' by address"
72+
)
73+
stream = lldb.SBStream()
74+
sd = bkpt.SerializeToStructuredData()
75+
sd.GetAsJSON(stream)
76+
serialized_data = json.loads(stream.GetData())
77+
78+
self.assertIn(
79+
"a.out",
80+
serialized_data["Breakpoint"]["BKPTResolver"]["Options"]["ModuleName"],
81+
)
82+
5283
def test_structured_data_serialization(self):
5384
target = self.dbg.GetDummyTarget()
5485
self.assertTrue(target.IsValid(), VALID_TARGET)

0 commit comments

Comments
 (0)