[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 14:53:52 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 1/3] [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)

>From a5b8e974f4e2c433b926b53c4708f1a1f7b7632e Mon Sep 17 00:00:00 2001
From: Alex Langford <alangford at apple.com>
Date: Wed, 3 Jan 2024 14:29:04 -0800
Subject: [PATCH 2/3] change formatting and make test more robust

---
 .../serialize/TestBreakpointSerialization.py      | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/lldb/test/API/functionalities/breakpoint/serialize/TestBreakpointSerialization.py b/lldb/test/API/functionalities/breakpoint/serialize/TestBreakpointSerialization.py
index 4f128aa33bc40a..deb83e03e1b74c 100644
--- a/lldb/test/API/functionalities/breakpoint/serialize/TestBreakpointSerialization.py
+++ b/lldb/test/API/functionalities/breakpoint/serialize/TestBreakpointSerialization.py
@@ -54,21 +54,24 @@ def test_resolver_serialization(self):
         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'")
+        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"
+            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_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"
+            bkpt.IsValid(), "Could not place breakpoint on 'main' by address"
         )
         stream = lldb.SBStream()
         sd = bkpt.SerializeToStructuredData()
@@ -76,7 +79,7 @@ def test_resolver_serialization(self):
         serialized_data = json.loads(stream.GetData())
 
         self.assertIn(
-            "a.out",
+            exe_path,
             serialized_data["Breakpoint"]["BKPTResolver"]["Options"]["ModuleName"],
         )
 

>From 7ce95b006a123fa7f8b784366f08078cc6fe2178 Mon Sep 17 00:00:00 2001
From: Alex Langford <alangford at apple.com>
Date: Wed, 3 Jan 2024 14:53:39 -0800
Subject: [PATCH 3/3] fixup

---
 .../breakpoint/serialize/TestBreakpointSerialization.py       | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/lldb/test/API/functionalities/breakpoint/serialize/TestBreakpointSerialization.py b/lldb/test/API/functionalities/breakpoint/serialize/TestBreakpointSerialization.py
index deb83e03e1b74c..b6cc3d9989a699 100644
--- a/lldb/test/API/functionalities/breakpoint/serialize/TestBreakpointSerialization.py
+++ b/lldb/test/API/functionalities/breakpoint/serialize/TestBreakpointSerialization.py
@@ -56,7 +56,9 @@ def test_resolver_serialization(self):
 
         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")
+        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)



More information about the lldb-commits mailing list