我在gdb中使用watch
时遇到问题。我想保持一个
在我的代码中观察变量m
。但由于某种原因,我收到以下消息
no symbol m in current context
。我在第7行保留了一个断点,因此m的范围是已知的。
steps performed by me :-
1>g++ -g a.cpp
2>gdb a.out
3>(gdb)break 7
4>(gdb)watch m
以下是我的计划: -
# include<iostream>
# include<stdio.h>
using namespace std;
int main()
{
int m=10;
char *abc = (char *)"ritesh";
cout << abc << endl ;
m=11;
m=13;
abc=NULL;
cout << *abc <<endl;
return 0;
}
我也看过How can I use "watch" GDB?但它对我帮助不大。有人可以解释我面临的这个问题。下面是与我的GNU相关的信息
ritesh@ubuntu:~$ gdb a.out
GNU gdb (Ubuntu/Linaro 7.3-0ubuntu2) 7.3-2011.08
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-linux-gnu".
For bug reporting instructions, please see:
<http://bugs.launchpad.net/gdb-linaro/>...
Reading symbols from /home/ritesh/a.out...done.
答案 0 :(得分:2)
将程序加载到调试器时,它尚未运行。但是,您尝试观看符号,该符号将在函数 - main()
函数中“开始”生效 - 并且当您从函数返回时将“消失”。
例如,在此代码中
void func() {
int b = 1;
++b;
cout << b << endl;
}
int main() {
int a = 1;
func();
cout << a << endl;
}
在开始执行程序之前,您无法设置a
值的监视,并且在执行进入b
之前监视func()
的值。