观察内存地址上的点

use*_*909 15 debugging xcode gdb lldb

随着从gdb到lldb的新变化,我找不到如何在某些内存地址上设置监视点的方法.

在gdb中我使用了这个

watch -location *0x123456
Run Code Online (Sandbox Code Playgroud)

在lldb中做同样的事情

w s e *0x123456
Run Code Online (Sandbox Code Playgroud)

不适合我.那么我可以用什么在lldb中运行相同的命令呢?

Mar*_*n R 32

*在lldb中设置监视点时省略"解除引用操作符" ,只需传递地址:

watchpoint set expression -- 0x123456
# short form:
w s e -- 0x123456
Run Code Online (Sandbox Code Playgroud)

在内存位置设置观察点0x123456.您可以选择设置要监视的字节数--size.简短形式示例:

w s e -s 2 -- 0x123456
Run Code Online (Sandbox Code Playgroud)

您还可以在变量上设置观察点:

watchpoint set variable <variable>
# short form:
w s v <variable>
Run Code Online (Sandbox Code Playgroud)

示例:使用以下代码并在第二行设置断点:

int x = 2;
x = 5;
Run Code Online (Sandbox Code Playgroud)

我是在Xcode调试器控制台中完成的:

(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)

更简单的说,我可以设置观察点

(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'