C语言 gdb:当前上下文中没有符号“i”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3758614/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
gdb: No symbol "i" in current context
提问by Ben2209
While debugging a C program in gdb I have a breakpoint in a for loop. I cannot print the value of "i" ( I get : No symbol "i" in current context.). I can print the value of all the other variables. Is it normal?
在 gdb 中调试 C 程序时,我在 for 循环中有一个断点。我无法打印“i”的值(我得到:当前上下文中没有符号“i”。)。我可以打印所有其他变量的值。正常吗?
Here is the loop:
这是循环:
for (i=0; i < datasize; i++){
if ( feature_mask[i] > 0 ){
k = feature_mask[i] - 1;
if (neighbors[k][nmax-1] != 0){
neighbors[k][nmax-1] = bvalue;
feature_mask[i] = -feature_mask[i];
}
}
}
采纳答案by a'r
It has probably been optimised out of your compiled code as you only use feature_mask[i]within the loop.
它可能已经从您的编译代码中优化出来,因为您只feature_mask[i]在循环中使用。
Did you specify an optimization level when you called your compiler? If you were using gcc, then just omit any -Ooptions and try again.
您在调用编译器时是否指定了优化级别?如果您使用的是 gcc,则只需省略任何-O选项并重试。
回答by dreamlax
I encountered this issue recently. I compiled GCC 5.1 and then used it to compile a C++11 codebase. And, although I could step through the program's code in gdb, I couldn't print the value of any variable, I kept getting “No symbol "xyz" in current context” errors, for everyvariable.
我最近遇到了这个问题。我编译了 GCC 5.1,然后用它来编译 C++11 代码库。而且,虽然我可以单步在gdb程序的代码,我无法打印任何变量的值,我一直得到“无符号‘XYZ’在目前情况下”的错误,对每一个变量。
I was using gdb 7.4, but the latest version available at the time was 7.9. I downloaded the latest version of gdb and compiled it (using GCC 5.1) and when using gdb 7.9 I was able to successfully inspect variable values again.
我使用的是 gdb 7.4,但当时可用的最新版本是 7.9。我下载了最新版本的 gdb 并编译了它(使用 GCC 5.1),当使用 gdb 7.9 时,我能够再次成功检查变量值。
I guess the debug information of GCC 5.1 is incompatible with gdb 7.4.
我猜 GCC 5.1 的调试信息与 gdb 7.4 不兼容。
回答by unwind
Make sure the program is compiled without optimization, and with debugging information enabled. It's quite likely that the loop counter ends up in a register.
确保程序在编译时没有进行优化,并且启用了调试信息。循环计数器很可能以寄存器结尾。
回答by pmg
You can try declaring i as volatile. That will prevent some compiler optimizations (and hopefully make ivisible inside the debugger).
您可以尝试将 i 声明为volatile。这将阻止一些编译器优化(并希望i在调试器中可见)。
回答by Aaron Digulla
Check your optimization options. It's possible the GCC could replace the variable with a pointer into feature_mask.
检查您的优化选项。GCC 可能会用指向feature_mask.

