Skip to content

[lldb] Fix breakpoint resolver serialization bug #76766

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions lldb/source/Breakpoint/BreakpointResolverAddress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,11 @@ BreakpointResolverAddress::SerializeToStructuredData() {
new StructuredData::Dictionary());
SectionSP section_sp = m_addr.GetSection();
if (section_sp) {
ModuleSP module_sp = section_sp->GetModule();
ConstString module_name;
if (module_sp)
module_name.SetCString(module_name.GetCString());

options_dict_sp->AddStringItem(GetKey(OptionNames::ModuleName),
module_name.GetCString());
if (ModuleSP module_sp = section_sp->GetModule()) {
const FileSpec &module_fspec = module_sp->GetFileSpec();
options_dict_sp->AddStringItem(GetKey(OptionNames::ModuleName),
module_fspec.GetPath().c_str());
}
options_dict_sp->AddIntegerItem(GetKey(OptionNames::AddressOffset),
m_addr.GetOffset());
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,42 @@ def test_scripted_extra_args(self):
self.setup_targets_and_cleanup()
self.do_check_extra_args()

def test_resolver_serialization(self):
"""Test that breakpoint resolvers contain the expected information"""
self.build()
self.setup_targets_and_cleanup()

exe_path = self.getBuildArtifact("a.out")
exe_module = self.orig_target.module[exe_path]
self.assertTrue(
exe_module.IsValid(), "Failed to find the executable module in target"
)
sym_ctx_list = exe_module.FindFunctions("main")
self.assertTrue(sym_ctx_list.GetSize() == 1, "Unable to find function 'main'")
sym_ctx = sym_ctx_list.GetContextAtIndex(0)
self.assertTrue(
sym_ctx.IsValid(), "SBSymbolContext representing function 'main' is invalid"
)
main_func = sym_ctx.GetFunction()
self.assertTrue(
main_func.IsValid(), "SBFunction representing 'main' is invalid"
)
main_addr = main_func.GetStartAddress()

bkpt = self.orig_target.BreakpointCreateBySBAddress(main_addr)
self.assertTrue(
bkpt.IsValid(), "Could not place breakpoint on 'main' by address"
)
stream = lldb.SBStream()
sd = bkpt.SerializeToStructuredData()
sd.GetAsJSON(stream)
serialized_data = json.loads(stream.GetData())

self.assertIn(
exe_path,
serialized_data["Breakpoint"]["BKPTResolver"]["Options"]["ModuleName"],
)

def test_structured_data_serialization(self):
target = self.dbg.GetDummyTarget()
self.assertTrue(target.IsValid(), VALID_TARGET)
Expand Down