[Lldb-commits] [lldb] 2a76429 - [lldb] Set the watchpoint spec for expression watchpoints

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Fri Mar 17 09:56:06 PDT 2023


Author: Jonas Devlieghere
Date: 2023-03-17T09:55:57-07:00
New Revision: 2a76429778768ed29404f0396194636e2bc11b90

URL: https://github.com/llvm/llvm-project/commit/2a76429778768ed29404f0396194636e2bc11b90
DIFF: https://github.com/llvm/llvm-project/commit/2a76429778768ed29404f0396194636e2bc11b90.diff

LOG: [lldb] Set the watchpoint spec for expression watchpoints

When setting a variable watchpoint, the watchpoint stores the variable
name in the watchpoint spec. For expression variables we should store
the expression in the watchpoint spec. This patch adds that
functionality.

rdar://106096860

Differential revision: https://reviews.llvm.org/D146262

Added: 
    

Modified: 
    lldb/source/Commands/CommandObjectWatchpoint.cpp
    lldb/test/API/commands/watchpoints/watchpoint_set_command/TestWatchLocationWithWatchSet.py

Removed: 
    


################################################################################
diff  --git a/lldb/source/Commands/CommandObjectWatchpoint.cpp b/lldb/source/Commands/CommandObjectWatchpoint.cpp
index 7aa9614634181..9463050f40b36 100644
--- a/lldb/source/Commands/CommandObjectWatchpoint.cpp
+++ b/lldb/source/Commands/CommandObjectWatchpoint.cpp
@@ -949,9 +949,8 @@ corresponding to the byte size of the data type.");
     uint32_t watch_type = m_option_watchpoint.watch_type;
 
     error.Clear();
-    Watchpoint *wp =
-        target->CreateWatchpoint(addr, size, &compiler_type, watch_type, error)
-            .get();
+    WatchpointSP wp =
+        target->CreateWatchpoint(addr, size, &compiler_type, watch_type, error);
     if (wp) {
       wp->SetWatchSpec(command.GetArgumentAtIndex(0));
       wp->SetWatchVariable(true);
@@ -1117,10 +1116,10 @@ class CommandObjectWatchpointSetExpression : public CommandObjectRaw {
     CompilerType compiler_type(valobj_sp->GetCompilerType());
 
     Status error;
-    Watchpoint *wp =
-        target->CreateWatchpoint(addr, size, &compiler_type, watch_type, error)
-            .get();
+    WatchpointSP wp =
+        target->CreateWatchpoint(addr, size, &compiler_type, watch_type, error);
     if (wp) {
+      wp->SetWatchSpec(std::string(expr));
       Stream &output_stream = result.GetOutputStream();
       output_stream.Printf("Watchpoint created: ");
       wp->GetDescription(&output_stream, lldb::eDescriptionLevelFull);

diff  --git a/lldb/test/API/commands/watchpoints/watchpoint_set_command/TestWatchLocationWithWatchSet.py b/lldb/test/API/commands/watchpoints/watchpoint_set_command/TestWatchLocationWithWatchSet.py
index aceb8f2bc4385..97e43c35127de 100644
--- a/lldb/test/API/commands/watchpoints/watchpoint_set_command/TestWatchLocationWithWatchSet.py
+++ b/lldb/test/API/commands/watchpoints/watchpoint_set_command/TestWatchLocationWithWatchSet.py
@@ -46,7 +46,7 @@ def test_watchlocation_using_watchpoint_set(self):
         self.setTearDownCleanup()
 
         exe = self.getBuildArtifact("a.out")
-        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
+        target = self.dbg.CreateTarget(exe)
 
         # Add a breakpoint to set a watchpoint when stopped on the breakpoint.
         lldbutil.run_break_set_by_file_and_line(
@@ -81,6 +81,12 @@ def test_watchlocation_using_watchpoint_set(self):
         self.expect("watchpoint list -v",
                     substrs=['hit_count = 0'])
 
+        # Check the underlying SBWatchpoint.
+        watchpoint = target.GetWatchpointAtIndex(0)
+        self.assertEqual(watchpoint.GetWatchSize(), 1)
+        self.assertEqual(watchpoint.GetHitCount(), 0)
+        self.assertEqual(watchpoint.GetWatchSpec(), "g_char_ptr + 7")
+
         self.runCmd("process continue")
 
         # We should be stopped again due to the watchpoint (write type), but


        


More information about the lldb-commits mailing list