Skip to content

Commit 307dd7c

Browse files
committed
[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 (cherry picked from commit 2a76429)
1 parent 6a04c48 commit 307dd7c

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

lldb/source/Commands/CommandObjectWatchpoint.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -949,9 +949,8 @@ corresponding to the byte size of the data type.");
949949
uint32_t watch_type = m_option_watchpoint.watch_type;
950950

951951
error.Clear();
952-
Watchpoint *wp =
953-
target->CreateWatchpoint(addr, size, &compiler_type, watch_type, error)
954-
.get();
952+
WatchpointSP wp =
953+
target->CreateWatchpoint(addr, size, &compiler_type, watch_type, error);
955954
if (wp) {
956955
wp->SetWatchSpec(command.GetArgumentAtIndex(0));
957956
wp->SetWatchVariable(true);
@@ -1117,10 +1116,10 @@ class CommandObjectWatchpointSetExpression : public CommandObjectRaw {
11171116
CompilerType compiler_type(valobj_sp->GetCompilerType());
11181117

11191118
Status error;
1120-
Watchpoint *wp =
1121-
target->CreateWatchpoint(addr, size, &compiler_type, watch_type, error)
1122-
.get();
1119+
WatchpointSP wp =
1120+
target->CreateWatchpoint(addr, size, &compiler_type, watch_type, error);
11231121
if (wp) {
1122+
wp->SetWatchSpec(std::string(expr));
11241123
Stream &output_stream = result.GetOutputStream();
11251124
output_stream.Printf("Watchpoint created: ");
11261125
wp->GetDescription(&output_stream, lldb::eDescriptionLevelFull);

lldb/test/API/commands/watchpoints/watchpoint_set_command/TestWatchLocationWithWatchSet.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def test_watchlocation_using_watchpoint_set(self):
4646
self.setTearDownCleanup()
4747

4848
exe = self.getBuildArtifact("a.out")
49-
self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
49+
target = self.dbg.CreateTarget(exe)
5050

5151
# Add a breakpoint to set a watchpoint when stopped on the breakpoint.
5252
lldbutil.run_break_set_by_file_and_line(
@@ -81,6 +81,12 @@ def test_watchlocation_using_watchpoint_set(self):
8181
self.expect("watchpoint list -v",
8282
substrs=['hit_count = 0'])
8383

84+
# Check the underlying SBWatchpoint.
85+
watchpoint = target.GetWatchpointAtIndex(0)
86+
self.assertEqual(watchpoint.GetWatchSize(), 1)
87+
self.assertEqual(watchpoint.GetHitCount(), 0)
88+
self.assertEqual(watchpoint.GetWatchSpec(), "g_char_ptr + 7")
89+
8490
self.runCmd("process continue")
8591

8692
# We should be stopped again due to the watchpoint (write type), but

0 commit comments

Comments
 (0)