Watch points on memory address

本秂侑毒 提交于 2020-01-11 19:18:11

问题


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 ?


回答1:


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'


来源:https://stackoverflow.com/questions/21063995/watch-points-on-memory-address

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!