aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Commands/CommandObjectWatchpoint.cpp
diff options
context:
space:
mode:
authorJason Molenda <jmolenda@apple.com>2023-09-20 13:18:12 -0700
committerJason Molenda <jmolenda@apple.com>2023-09-20 13:42:16 -0700
commit933ad5c897ee366759a54869b35b2d7285a92137 (patch)
tree169d13adc3124c5d521b53fa88e0241a3471ba5f /lldb/source/Commands/CommandObjectWatchpoint.cpp
parent618a22144db5e45da8c95dc22064103e1b5e5b71 (diff)
downloadllvm-933ad5c897ee366759a54869b35b2d7285a92137.zip
llvm-933ad5c897ee366759a54869b35b2d7285a92137.tar.gz
llvm-933ad5c897ee366759a54869b35b2d7285a92137.tar.bz2
[lldb] Add 'modify' type watchpoints, make it default (#66308)
Watchpoints in lldb can be either 'read', 'write', or 'read/write'. This is exposing the actual behavior of hardware watchpoints. gdb has a different behavior: a "write" type watchpoint only stops when the watched memory region *changes*. A user is using a watchpoint for one of three reasons: 1. Want to find what is changing/corrupting this memory. 2. Want to find what is writing to this memory. 3. Want to find what is reading from this memory. I believe (1) is the most common use case for watchpoints, and it currently can't be done in lldb -- the user needs to continue every time the same value is written to the watched-memory manually. I think gdb's behavior is the correct one. There are some use cases where a developer wants to find every function that writes/reads to/from a memory region, regardless of value, I want to still allow that functionality. This is also a bit of groundwork for my large watchpoint support proposal https://discourse.llvm.org/t/rfc-large-watchpoint-support-in-lldb/72116 where I will be adding support for AArch64 MASK watchpoints which watch power-of-2 memory regions. A user might ask to watch 24 bytes, and a MASK watchpoint stub can do this with a 32-byte MASK watchpoint if it is properly aligned. And we need to ignore writes to the final 8 bytes of that watched region, and not show those hits to the user. This patch adds a new 'modify' watchpoint type and it is the default. Re-landing this patch after addressing testsuite failures found in CI on Linux, Intel machines, and windows. rdar://108234227
Diffstat (limited to 'lldb/source/Commands/CommandObjectWatchpoint.cpp')
-rw-r--r--lldb/source/Commands/CommandObjectWatchpoint.cpp30
1 files changed, 23 insertions, 7 deletions
diff --git a/lldb/source/Commands/CommandObjectWatchpoint.cpp b/lldb/source/Commands/CommandObjectWatchpoint.cpp
index a4929ea..83c2fb8 100644
--- a/lldb/source/Commands/CommandObjectWatchpoint.cpp
+++ b/lldb/source/Commands/CommandObjectWatchpoint.cpp
@@ -803,7 +803,7 @@ public:
"Set a watchpoint on a variable. "
"Use the '-w' option to specify the type of watchpoint and "
"the '-s' option to specify the byte size to watch for. "
- "If no '-w' option is specified, it defaults to write. "
+ "If no '-w' option is specified, it defaults to modify. "
"If no '-s' option is specified, it defaults to the variable's "
"byte size. "
"Note that there are limited hardware resources for watchpoints. "
@@ -878,9 +878,9 @@ protected:
return false;
}
- // If no '-w' is specified, default to '-w write'.
+ // If no '-w' is specified, default to '-w modify'.
if (!m_option_watchpoint.watch_type_specified) {
- m_option_watchpoint.watch_type = OptionGroupWatchpoint::eWatchWrite;
+ m_option_watchpoint.watch_type = OptionGroupWatchpoint::eWatchModify;
}
// We passed the sanity check for the command. Proceed to set the
@@ -947,7 +947,23 @@ protected:
}
// Now it's time to create the watchpoint.
- uint32_t watch_type = m_option_watchpoint.watch_type;
+ uint32_t watch_type = 0;
+ switch (m_option_watchpoint.watch_type) {
+ case OptionGroupWatchpoint::eWatchModify:
+ watch_type |= LLDB_WATCH_TYPE_MODIFY;
+ break;
+ case OptionGroupWatchpoint::eWatchRead:
+ watch_type |= LLDB_WATCH_TYPE_READ;
+ break;
+ case OptionGroupWatchpoint::eWatchReadWrite:
+ watch_type |= LLDB_WATCH_TYPE_READ | LLDB_WATCH_TYPE_WRITE;
+ break;
+ case OptionGroupWatchpoint::eWatchWrite:
+ watch_type |= LLDB_WATCH_TYPE_WRITE;
+ break;
+ case OptionGroupWatchpoint::eWatchInvalid:
+ break;
+ };
error.Clear();
WatchpointSP watch_sp =
@@ -999,7 +1015,7 @@ public:
"Use the '-l' option to specify the language of the expression. "
"Use the '-w' option to specify the type of watchpoint and "
"the '-s' option to specify the byte size to watch for. "
- "If no '-w' option is specified, it defaults to write. "
+ "If no '-w' option is specified, it defaults to modify. "
"If no '-s' option is specified, it defaults to the target's "
"pointer byte size. "
"Note that there are limited hardware resources for watchpoints. "
@@ -1013,7 +1029,7 @@ public:
R"(
Examples:
-(lldb) watchpoint set expression -w write -s 1 -- foo + 32
+(lldb) watchpoint set expression -w modify -s 1 -- foo + 32
Watches write access for the 1-byte region pointed to by the address 'foo + 32')");
@@ -1073,7 +1089,7 @@ protected:
// If no '-w' is specified, default to '-w write'.
if (!m_option_watchpoint.watch_type_specified) {
- m_option_watchpoint.watch_type = OptionGroupWatchpoint::eWatchWrite;
+ m_option_watchpoint.watch_type = OptionGroupWatchpoint::eWatchModify;
}
// We passed the sanity check for the command. Proceed to set the