Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Watch points on memory address

Tags:

With the new change from gdb to lldb , I can't find a way how to set watch points on some memory addresses .

In gdb I used this

watch -location *0x123456 

Doing the same in lldb

w s e *0x123456 

Isn't working for me . So what can I use to run the same command in lldb ?

like image 905
user3001909 Avatar asked Jan 11 '14 15:01

user3001909


People also ask

How do I view a pointer in GDB?

You can force GDB to use only software watchpoints with the set can-use-hw-watchpoints 0 command. With this variable set to zero, GDB will never try to use hardware watchpoints, even if the underlying system supports them.

What are breakpoints and watchpoints?

Breakpoint is that you specified a point a row of program to debug. Watchpoint is that you specified a condition to debug.

How are watchpoints used?

Watchpoints can be used to monitor “write”, “read” or “read/write” accesses. For example, a watchpoint might be configured to trip when a variable gets updated, a region of the stack is written to, or a particular buffer is read from.


1 Answers

Omit the "dereferencing operator" * when setting the watch point in lldb, just pass the address:

watchpoint set expression -- 0x123456 # short form: w s e -- 0x123456 

sets a watchpoint at the memory location 0x123456. Optionally you can set the number of bytes to watch with --size. Example in short form:

w s e -s 2 -- 0x123456 

You can also set a watchpoint on a variable:

watchpoint set variable <variable> # short form: w s v <variable> 

Example: With the following code and a breakpoint set at the second line:

int x = 2; x = 5; 

I did this in the Xcode debugger console:

 (lldb) p &x (int *) $0 = 0xbfffcbd8 (lldb) w s e -- 0xbfffcbd8 Watchpoint created: Watchpoint 1: addr = 0xbfffcbd8 size = 4 state = enabled type = w     new value: 2 (lldb) n  Watchpoint 1 hit: old value: 2 new value: 5 (lldb) 

More simply, I could have set the watchpoint with

 (lldb) w s v x Watchpoint created: Watchpoint 1: addr = 0x7fff5fbff7dc size = 4 state = enabled type = w     declare @ '/Users/martin/Documents/tmpprojects/watcher/watcher/main.c:16'     watchpoint spec = 'x' 
like image 56
Martin R Avatar answered Sep 28 '22 08:09

Martin R