[Lldb-commits] [lldb] [lldb] Fix breakpoint resolver serialization bug (PR #76766)
Alex Langford via lldb-commits
lldb-commits at lists.llvm.org
Wed Jan 3 12:44:27 PST 2024
https://github.com/bulbazord updated https://github.com/llvm/llvm-project/pull/76766
>From 9688e85a01c8c952a3db17510cc97ce6db570e96 Mon Sep 17 00:00:00 2001
From: Alex Langford <alangford at apple.com>
Date: Tue, 2 Jan 2024 15:44:30 -0800
Subject: [PATCH] [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).
---
.../Breakpoint/BreakpointResolverAddress.cpp | 12 +++----
.../serialize/TestBreakpointSerialization.py | 31 +++++++++++++++++++
2 files changed, 36 insertions(+), 7 deletions(-)
diff --git a/lldb/source/Breakpoint/BreakpointResolverAddress.cpp b/lldb/source/Breakpoint/BreakpointResolverAddress.cpp
index a0c628a8e299ce..ee4cbd50f9eee2 100644
--- a/lldb/source/Breakpoint/BreakpointResolverAddress.cpp
+++ b/lldb/source/Breakpoint/BreakpointResolverAddress.cpp
@@ -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 {
diff --git a/lldb/test/API/functionalities/breakpoint/serialize/TestBreakpointSerialization.py b/lldb/test/API/functionalities/breakpoint/serialize/TestBreakpointSerialization.py
index be9b4e587b2969..4f128aa33bc40a 100644
--- a/lldb/test/API/functionalities/breakpoint/serialize/TestBreakpointSerialization.py
+++ b/lldb/test/API/functionalities/breakpoint/serialize/TestBreakpointSerialization.py
@@ -49,6 +49,37 @@ 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()
+
+ sym_ctx_list = self.orig_target.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(
+ "a.out",
+ serialized_data["Breakpoint"]["BKPTResolver"]["Options"]["ModuleName"],
+ )
+
def test_structured_data_serialization(self):
target = self.dbg.GetDummyTarget()
self.assertTrue(target.IsValid(), VALID_TARGET)
More information about the lldb-commits
mailing list