[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
Wed Sep 13 18:46:42 PDT 2023


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

>From 8754d93a72bdff94f95f991d9bf1112e5f9fe692 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 1/3] [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..01b7d41f85c1185 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 eBroadcastBitSymbolChange event.")
+
+
     def generate_main_cpp(self, version=0):
         """Generate main.cpp from main.cpp.template."""
         temp = os.path.join(self.getSourceDir(), self.template)

>From 0ae976f96a591d8129a459312fcd974d6ab3ea7d Mon Sep 17 00:00:00 2001
From: Chelsea Cassanova <cassanova at Chelseas-MacBook-Pro-2.local>
Date: Wed, 13 Sep 2023 13:11:21 -0700
Subject: [PATCH 2/3] fixup! [lldb][Commands] Show symbol change bit in SB API

---
 lldb/include/lldb/API/SBDebugger.h            |  2 --
 lldb/include/lldb/API/SBTarget.h              |  3 ++-
 lldb/include/lldb/Core/Debugger.h             |  2 +-
 lldb/include/lldb/Target/Target.h             |  3 ++-
 lldb/source/Core/Debugger.cpp                 |  4 ++--
 lldb/source/Core/DebuggerEvents.cpp           |  5 +++-
 lldb/source/Target/Target.cpp                 |  5 ++--
 .../add-dsym/uuid/TestAddDsymCommand.py       | 24 +++++++++++--------
 8 files changed, 28 insertions(+), 20 deletions(-)

diff --git a/lldb/include/lldb/API/SBDebugger.h b/lldb/include/lldb/API/SBDebugger.h
index abb08e93d197a18..29cf2c16fad4bd7 100644
--- a/lldb/include/lldb/API/SBDebugger.h
+++ b/lldb/include/lldb/API/SBDebugger.h
@@ -13,7 +13,6 @@
 
 #include "lldb/API/SBDefines.h"
 #include "lldb/API/SBPlatform.h"
-#include "lldb/API/SBStructuredData.h"
 
 namespace lldb_private {
 class CommandPluginInterfaceImplementation;
@@ -47,7 +46,6 @@ class LLDB_API SBDebugger {
       eBroadcastBitProgress = (1 << 0),
       eBroadcastBitWarning = (1 << 1),
       eBroadcastBitError = (1 << 2),
-      eBroadcastBitSymbolChange = (1 << 3),
   };
 
   SBDebugger();
diff --git a/lldb/include/lldb/API/SBTarget.h b/lldb/include/lldb/API/SBTarget.h
index 07bd6a8b76d2f19..d1cd23af67dccb4 100644
--- a/lldb/include/lldb/API/SBTarget.h
+++ b/lldb/include/lldb/API/SBTarget.h
@@ -40,7 +40,8 @@ class LLDB_API SBTarget {
     eBroadcastBitModulesLoaded = (1 << 1),
     eBroadcastBitModulesUnloaded = (1 << 2),
     eBroadcastBitWatchpointChanged = (1 << 3),
-    eBroadcastBitSymbolsLoaded = (1 << 4)
+    eBroadcastBitSymbolsLoaded = (1 << 4),
+    eBroadcastBitSymbolsChanged = (1 << 5),
   };
 
   // Constructors
diff --git a/lldb/include/lldb/Core/Debugger.h b/lldb/include/lldb/Core/Debugger.h
index 6cdf1a183b18e54..7a6aa9ad5f503ef 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),
-    eBroadcastBitSymbolChange = (1 << 3),
+    eBroadcastBitSymbolFileChange = (1 << 3),
   };
 
   using DebuggerList = std::vector<lldb::DebuggerSP>;
diff --git a/lldb/include/lldb/Target/Target.h b/lldb/include/lldb/Target/Target.h
index ed0ecbbddbf8149..b479229417b3b23 100644
--- a/lldb/include/lldb/Target/Target.h
+++ b/lldb/include/lldb/Target/Target.h
@@ -9,6 +9,7 @@
 #ifndef LLDB_TARGET_TARGET_H
 #define LLDB_TARGET_TARGET_H
 
+#include <_types/_uint32_t.h>
 #include <list>
 #include <map>
 #include <memory>
@@ -875,7 +876,7 @@ class Target : public std::enable_shared_from_this<Target>,
 
   void ModulesDidUnload(ModuleList &module_list, bool delete_locations);
 
-  void SymbolsDidLoad(ModuleList &module_list);
+  void SymbolsDidLoad(ModuleList &module_list, uint32_t load_or_change_broadcast_bit);
 
   void ClearModules(bool delete_locations);
 
diff --git a/lldb/source/Core/Debugger.cpp b/lldb/source/Core/Debugger.cpp
index 924741f45040bf0..d32823ab052e089 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::eBroadcastBitSymbolChange,
+          Debugger::eBroadcastBitSymbolFileChange,
           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 | eBroadcastBitSymbolChange);
+                          eBroadcastBitError | eBroadcastBitSymbolFileChange);
 
   // 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/source/Core/DebuggerEvents.cpp b/lldb/source/Core/DebuggerEvents.cpp
index dd77fff349a64a7..cd55352482b3db2 100644
--- a/lldb/source/Core/DebuggerEvents.cpp
+++ b/lldb/source/Core/DebuggerEvents.cpp
@@ -148,9 +148,12 @@ void SymbolChangeEventData::DoOnRemoval(Event *event_ptr) {
         if (!module_sp->GetSymbolFileFileSpec())
           module_sp->SetSymbolFileFileSpec(m_module_spec.GetSymbolFileSpec());
       }
+
+      // This method is only calling SymbolsDidLoad to indicate that the symbol
+      // file in question has changed, so indicate that to SymbolsDidLoad
       ModuleList module_list;
       module_list.Append(module_sp);
-      target_sp->SymbolsDidLoad(module_list);
+      target_sp->SymbolsDidLoad(module_list, Target::eBroadcastBitSymbolsChanged);
     }
   }
 }
diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp
index f5b551f581f9fdd..ed19b0f3263726d 100644
--- a/lldb/source/Target/Target.cpp
+++ b/lldb/source/Target/Target.cpp
@@ -66,6 +66,7 @@
 #include "llvm/ADT/ScopeExit.h"
 #include "llvm/ADT/SetVector.h"
 
+#include <_types/_uint32_t.h>
 #include <memory>
 #include <mutex>
 #include <optional>
@@ -1662,7 +1663,7 @@ void Target::ModulesDidLoad(ModuleList &module_list) {
   }
 }
 
-void Target::SymbolsDidLoad(ModuleList &module_list) {
+void Target::SymbolsDidLoad(ModuleList &module_list, uint32_t load_or_change_broadcast_bit) {
   if (m_valid && module_list.GetSize()) {
     if (m_process_sp) {
       for (LanguageRuntime *runtime : m_process_sp->GetLanguageRuntimes()) {
@@ -1672,7 +1673,7 @@ void Target::SymbolsDidLoad(ModuleList &module_list) {
 
     m_breakpoint_list.UpdateBreakpoints(module_list, true, false);
     m_internal_breakpoint_list.UpdateBreakpoints(module_list, true, false);
-    BroadcastEvent(eBroadcastBitSymbolsLoaded,
+    BroadcastEvent(load_or_change_broadcast_bit,
                    new TargetEventData(this->shared_from_this(), module_list));
   }
 }
diff --git a/lldb/test/API/commands/add-dsym/uuid/TestAddDsymCommand.py b/lldb/test/API/commands/add-dsym/uuid/TestAddDsymCommand.py
index 01b7d41f85c1185..d1db82cfd2cf5e1 100644
--- a/lldb/test/API/commands/add-dsym/uuid/TestAddDsymCommand.py
+++ b/lldb/test/API/commands/add-dsym/uuid/TestAddDsymCommand.py
@@ -58,27 +58,31 @@ def test_add_dsym_with_dSYM_bundle(self):
         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."""
+    def test_report_symbol_load(self):
+        """Test that when adding a symbol file, the eBroadcastBitSymbolsLoaded 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
+        listener = lldb.SBListener("listener")
+        listener.StartListeningForEventClass(
+            self.dbg,
+            lldb.SBTarget.GetBroadcasterClassName(),
+            lldb.SBTarget.eBroadcastBitSymbolsLoaded,
         )
 
+
+        self.exe_name = "a.out"
+
         # 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)
+        # event = lldbutil.fetch_next_event(self, self.listener, self.broadcaster)
+        event = lldb.SBEvent()
+        listener.WaitForEvent(1, event)
 
         # Check that the event is valid
-        self.assertTrue(event.IsValid(), "Got a valid eBroadcastBitSymbolChange event.")
+        self.assertTrue(event.IsValid(), "Got a valid eBroadcastBitSymbolsLoaded event.")
 
 
     def generate_main_cpp(self, version=0):

>From e39095be80624114a487b8859644e45faac74971 Mon Sep 17 00:00:00 2001
From: Chelsea Cassanova <chelsea_cassanova at apple.com>
Date: Wed, 13 Sep 2023 18:46:02 -0700
Subject: [PATCH 3/3] fixup! fixup! [lldb][Commands] Show symbol change bit in
 SB API

---
 lldb/include/lldb/Target/Target.h                          | 1 -
 lldb/source/Commands/CommandObjectTarget.cpp               | 2 +-
 lldb/source/Target/Target.cpp                              | 1 -
 lldb/test/API/commands/add-dsym/uuid/TestAddDsymCommand.py | 5 -----
 4 files changed, 1 insertion(+), 8 deletions(-)

diff --git a/lldb/include/lldb/Target/Target.h b/lldb/include/lldb/Target/Target.h
index b479229417b3b23..eeb247987a7d561 100644
--- a/lldb/include/lldb/Target/Target.h
+++ b/lldb/include/lldb/Target/Target.h
@@ -9,7 +9,6 @@
 #ifndef LLDB_TARGET_TARGET_H
 #define LLDB_TARGET_TARGET_H
 
-#include <_types/_uint32_t.h>
 #include <list>
 #include <map>
 #include <memory>
diff --git a/lldb/source/Commands/CommandObjectTarget.cpp b/lldb/source/Commands/CommandObjectTarget.cpp
index 8051b3826294ab3..5f9bf6d5f14575f 100644
--- a/lldb/source/Commands/CommandObjectTarget.cpp
+++ b/lldb/source/Commands/CommandObjectTarget.cpp
@@ -4212,7 +4212,7 @@ class CommandObjectTargetSymbolsAdd : public CommandObjectParsed {
           // currently loaded
           ModuleList module_list;
           module_list.Append(module_sp);
-          target->SymbolsDidLoad(module_list);
+          target->SymbolsDidLoad(module_list, Target::eBroadcastBitSymbolsLoaded);
 
           // Make sure we load any scripting resources that may be embedded
           // in the debug info files in case the platform supports that.
diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp
index ed19b0f3263726d..c28d942ba0c688d 100644
--- a/lldb/source/Target/Target.cpp
+++ b/lldb/source/Target/Target.cpp
@@ -66,7 +66,6 @@
 #include "llvm/ADT/ScopeExit.h"
 #include "llvm/ADT/SetVector.h"
 
-#include <_types/_uint32_t.h>
 #include <memory>
 #include <mutex>
 #include <optional>
diff --git a/lldb/test/API/commands/add-dsym/uuid/TestAddDsymCommand.py b/lldb/test/API/commands/add-dsym/uuid/TestAddDsymCommand.py
index d1db82cfd2cf5e1..540cb98265be39c 100644
--- a/lldb/test/API/commands/add-dsym/uuid/TestAddDsymCommand.py
+++ b/lldb/test/API/commands/add-dsym/uuid/TestAddDsymCommand.py
@@ -70,21 +70,16 @@ def test_report_symbol_load(self):
             lldb.SBTarget.eBroadcastBitSymbolsLoaded,
         )
 
-
-        self.exe_name = "a.out"
-
         # 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)
         event = lldb.SBEvent()
         listener.WaitForEvent(1, event)
 
         # Check that the event is valid
         self.assertTrue(event.IsValid(), "Got a valid eBroadcastBitSymbolsLoaded 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