函数局部变量上的观察点通常在函数返回时被删除,并显示消息«Watchpoint 7 deleted because the program has left the block in»。插图:
struct mystruct{
int a, b, c;
};
void MyFunc(){
mystruct obj;
obj.a = 2;
}
int main(){
MyFunc();
}
gdb 会话示例
(gdb) b 7
Breakpoint 1 at 0x4004f1: file /tmp/test2.cpp, line 7.
(gdb) r
Starting program: /tmp/test2
Breakpoint 1, MyFunc () at /tmp/test2.cpp:7
7 obj.a = 2;
(gdb) wa obj
Hardware watchpoint 2: obj
(gdb) c
Continuing.
Hardware watchpoint 2: obj
Old value = {a = 4195600, b = 0, c = 4195328}
New value = {a = 2, b = 0, c = 4195328}
MyFunc () at /tmp/test2.cpp:8
8 }
(gdb) c
Continuing.
Watchpoint 2 deleted because the program has left the block in
which its expression is valid.
main () at /tmp/test2.cpp:12
12 }
我尝试像wa *(mystruct *)&obj
and一样投射它wa *(mystruct *)(void*)&obj
,但无济于事。
我需要它,因为我正在使用的嵌入式 ARM 设备上的 GDB 已损坏:有时它会无缘无故地删除观察点;然后回溯看起来像标有“??”的行 标志,以及有关损坏堆栈的消息。即使应用程序实际上很好。