Add an accompanying option to the 'frame variable -w' command to, instead of watching the variable,
watch the location pointed to by the variable. An example,
(lldb) frame variable -w write -x 1 -g g_char_ptr
(char *) g_char_ptr = 0x0000000100100860 ""...
Watchpoint created: WatchpointLocation 1: addr = 0x100100860 size = 1 state = enabled type = w
declare @ '/Volumes/data/lldb/svn/trunk/test/functionalities/watchpoint/hello_watchlocation/main.cpp:21'
...
(lldb) c
Process 3936 resuming
...
rocess 3936 stopped
* thread #2: tid = 0x3403, 0x00000001000009b7 a.out`do_bad_thing_with_location(char*, char) + 23 at main.cpp:27, stop reason = watchpoint 1
frame #0: 0x00000001000009b7 a.out`do_bad_thing_with_location(char*, char) + 23 at main.cpp:27
24 do_bad_thing_with_location(char *char_ptr, char new_val)
25 {
26 *char_ptr = new_val;
-> 27 }
28
29 uint32_t access_pool (uint32_t flag = 0);
30
(lldb)
Also add TestWatchLocation.py test to exercise this functionality.
git-svn-id: https://llvm.org/svn/llvm-project/llvdb/trunk@140836 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Commands/CommandObjectFrame.cpp b/source/Commands/CommandObjectFrame.cpp
index 4790eef..288a5ea 100644
--- a/source/Commands/CommandObjectFrame.cpp
+++ b/source/Commands/CommandObjectFrame.cpp
@@ -436,7 +436,7 @@
}
// Things have checked out ok...
- // m_option_watchpoint.watch_mode specifies the mode for watching.
+ // m_option_watchpoint.watch_type specifies the type of watching.
}
if (command.GetArgumentCount() > 0)
{
@@ -532,12 +532,20 @@
if (m_option_watchpoint.watch_variable)
{
AddressType addr_type;
- lldb::addr_t addr = valobj_sp->GetAddressOf(false, &addr_type);
+ lldb::addr_t addr = 0;
size_t size = 0;
- if (addr_type == eAddressTypeLoad) {
- // We're in business.
- // Find out the size of this variable.
- size = valobj_sp->GetByteSize();
+ if (m_option_watchpoint.watch_size == 0) {
+ addr = valobj_sp->GetAddressOf(false, &addr_type);
+ if (addr_type == eAddressTypeLoad) {
+ // We're in business.
+ // Find out the size of this variable.
+ size = valobj_sp->GetByteSize();
+ }
+ } else {
+ // The '-xsize'/'-x' option means to treat the value object as
+ // a pointer and to watch the pointee with the specified size.
+ addr = valobj_sp->GetValueAsUnsigned(0);
+ size = m_option_watchpoint.watch_size;
}
uint32_t watch_type = m_option_watchpoint.watch_type;
WatchpointLocation *wp_loc = exe_ctx.GetTargetRef().CreateWatchpointLocation(addr, size, watch_type).get();