[Lldb-commits] [lldb] [lldb][Commands] Show symbol change bit in SB API (PR #66144)

Chelsea Cassanova via lldb-commits lldb-commits at lists.llvm.org
Tue Sep 12 14:15:22 PDT 2023


https://github.com/chelcassanova created https://github.com/llvm/llvm-project/pull/66144:

This exposes the `eBroadcastBitSymbolChange` bit to the SB API to show when a symbol change event has been broadcast as this wasn't being done before. Also refactors `eBroadcastSymbolChange` to `eBroadcastBitSymbolChange` to match the naming convention for other event bits used in the debugger.

>From 1a544b9085c3a643b4880b239161fe6ed777fc71 Mon Sep 17 00:00:00 2001
From: Chelsea Cassanova <cassanova at Chelseas-MacBook-Pro-2.local>
Date: Tue, 12 Sep 2023 13:49:50 -0700
Subject: [PATCH] [lldb][Commands] Show symbol change bit in SB API

This exposes the `eBroadcastBitSymbolChange` bit to the SB
API to show when a symbol change event has been broadcast as
this wasn't being done before. Also refactors `eBroadcastSymbolChange`
to `eBroadcastBitSymbolChange` to match the naming convention
for other event bits used in the debugger.
---
 lldb/include/lldb/API/SBDebugger.h            |  2 ++
 lldb/include/lldb/Core/Debugger.h             |  2 +-
 lldb/source/Commands/CommandObjectTarget.cpp  |  4 ++++
 lldb/source/Core/Debugger.cpp                 |  4 ++--
 .../add-dsym/uuid/TestAddDsymCommand.py       | 24 +++++++++++++++++++
 5 files changed, 33 insertions(+), 3 deletions(-)

diff --git a/lldb/include/lldb/API/SBDebugger.h b/lldb/include/lldb/API/SBDebugger.h
index 29cf2c16fad4bd7..abb08e93d197a18 100644
--- a/lldb/include/lldb/API/SBDebugger.h
+++ b/lldb/include/lldb/API/SBDebugger.h
@@ -13,6 +13,7 @@
 
 #include "lldb/API/SBDefines.h"
 #include "lldb/API/SBPlatform.h"
+#include "lldb/API/SBStructuredData.h"
 
 namespace lldb_private {
 class CommandPluginInterfaceImplementation;
@@ -46,6 +47,7 @@ class LLDB_API SBDebugger {
       eBroadcastBitProgress = (1 << 0),
       eBroadcastBitWarning = (1 << 1),
       eBroadcastBitError = (1 << 2),
+      eBroadcastBitSymbolChange = (1 << 3),
   };
 
   SBDebugger();
diff --git a/lldb/include/lldb/Core/Debugger.h b/lldb/include/lldb/Core/Debugger.h
index 5532cace606bfed..6cdf1a183b18e54 100644
--- a/lldb/include/lldb/Core/Debugger.h
+++ b/lldb/include/lldb/Core/Debugger.h
@@ -83,7 +83,7 @@ class Debugger : public std::enable_shared_from_this<Debugger>,
     eBroadcastBitProgress = (1 << 0),
     eBroadcastBitWarning = (1 << 1),
     eBroadcastBitError = (1 << 2),
-    eBroadcastSymbolChange = (1 << 3),
+    eBroadcastBitSymbolChange = (1 << 3),
   };
 
   using DebuggerList = std::vector<lldb::DebuggerSP>;
diff --git a/lldb/source/Commands/CommandObjectTarget.cpp b/lldb/source/Commands/CommandObjectTarget.cpp
index 3e024ff91b382d7..8051b3826294ab3 100644
--- a/lldb/source/Commands/CommandObjectTarget.cpp
+++ b/lldb/source/Commands/CommandObjectTarget.cpp
@@ -4504,6 +4504,10 @@ class CommandObjectTargetSymbolsAdd : public CommandObjectParsed {
       if (process)
         process->Flush();
     }
+
+    if (result.Succeeded())
+      Debugger::ReportSymbolChange(module_spec);
+
     return result.Succeeded();
   }
 
diff --git a/lldb/source/Core/Debugger.cpp b/lldb/source/Core/Debugger.cpp
index 7ec1efc64fe9383..924741f45040bf0 100644
--- a/lldb/source/Core/Debugger.cpp
+++ b/lldb/source/Core/Debugger.cpp
@@ -1536,7 +1536,7 @@ void Debugger::ReportSymbolChange(const ModuleSpec &module_spec) {
     std::lock_guard<std::recursive_mutex> guard(*g_debugger_list_mutex_ptr);
     for (DebuggerSP debugger_sp : *g_debugger_list_ptr) {
       EventSP event_sp = std::make_shared<Event>(
-          Debugger::eBroadcastSymbolChange,
+          Debugger::eBroadcastBitSymbolChange,
           new SymbolChangeEventData(debugger_sp, module_spec));
       debugger_sp->GetBroadcaster().BroadcastEvent(event_sp);
     }
@@ -1844,7 +1844,7 @@ lldb::thread_result_t Debugger::DefaultEventHandler() {
 
   listener_sp->StartListeningForEvents(
       &m_broadcaster, eBroadcastBitProgress | eBroadcastBitWarning |
-                          eBroadcastBitError | eBroadcastSymbolChange);
+                          eBroadcastBitError | eBroadcastBitSymbolChange);
 
   // Let the thread that spawned us know that we have started up and that we
   // are now listening to all required events so no events get missed
diff --git a/lldb/test/API/commands/add-dsym/uuid/TestAddDsymCommand.py b/lldb/test/API/commands/add-dsym/uuid/TestAddDsymCommand.py
index d16ca32d79e6808..1d7caf3122dcccb 100644
--- a/lldb/test/API/commands/add-dsym/uuid/TestAddDsymCommand.py
+++ b/lldb/test/API/commands/add-dsym/uuid/TestAddDsymCommand.py
@@ -57,6 +57,30 @@ def test_add_dsym_with_dSYM_bundle(self):
         self.exe_name = "a.out"
         self.do_add_dsym_with_dSYM_bundle(self.exe_name)
 
+    @no_debug_info_test
+    def test_report_symbol_change(self):
+        """Test that when adding a symbol file, the eBroadcastBitSymbolChange event gets broadcasted."""
+        self.generate_main_cpp(version=1)
+        self.build(debug_info="dsym")
+
+        self.exe_name = "a.out"
+
+        # Get the broadcaster and listen for the symbol change event
+        self.broadcaster = self.dbg.GetBroadcaster()
+        self.listener = lldbutil.start_listening_from(
+            self.broadcaster, lldb.SBDebugger.eBroadcastBitSymbolChange
+        )
+
+        # Add the dSYM
+        self.do_add_dsym_with_success(self.exe_name)
+
+        # Get the next event
+        event = lldbutil.fetch_next_event(self, self.listener, self.broadcaster)
+
+        # Check that the event is valid
+        self.assertTrue(event.IsValid(), "Got a valid event.")
+
+
     def generate_main_cpp(self, version=0):
         """Generate main.cpp from main.cpp.template."""
         temp = os.path.join(self.getSourceDir(), self.template)



More information about the lldb-commits mailing list