在没有优化的程序上使用gdb调试,但在当前上下文中没有用于局部变量的符号 [英] Debugging with gdb on a program with no optimization but still there is no symbol in the current context for local variables
问题描述
我一直有这个问题,虽然现在,但总是似乎推迟了问这个问题,因为它看起来像我做错了...但现在我觉得不然...采取这个代码:
#include< string>
#include< iostream>
#include< algorithm>
int main(int argc,char ** argv)
{
if(argc< 2)
{
std :: cout< usage:< argv [0]< < string> << std :: endl;
return 1;
}
std :: string str = argv [1];
std :: reverse(str.begin(),str.end());
std :: cout<< str<< std :: endl;
return 0;
}
使用命令编译:
g ++ -std = c ++ 11 -Wall main.cpp -o main -O0 -ggdb3
我正在使用一个最近的中继线版本的gcc,我的树干被约在9月23日左右ish ...还要注意,我不编译优化!
现在,我开始调试,如下:
gdb --quiet - args ./main string
我在第12行设置了一个断点>
b 12
然后我运行程序
运行
然后我尝试打印出字符串,看看是什么。
str
这个,亲爱的朋友,对我来说看起来很奇怪:
输出的上一个命令是:在当前上下文中没有符号str。
快速检查本地变量不会显示字符串
info locals
get是
std :: __ ioinit = {static _S_refcount = 2,static _S_synced_with_stdio = true}
所以我想知道,我是错的,或者是编译器或调试器在故障...这是一个很痛苦屁股的问题为我很长一段时间...所以感谢甚至阅读这个问题...)
编辑:现在已经清楚,我的gcc构建错误,我想知道是否有任何人遇到一个错误报告或任何其他情况下,似乎有一个类似于这个问题...我也将尝试检查与最近的一个gdb构建,确保没有一个问题,我当前的调试器(与ubuntu一起)...这是有意义吗?
EDIT2:所以在编译gdb v7.5 ,我得到相同的结果,除了没有当地人在所有...我想这意味着它是一个gcc的问题,谢谢大家...
解决方案不,即使--quiet它为我工作。可能您的设置有问题。
〜/ tmp $ g ++ -Wall tmp.cpp -o tmp -O0 -ggdb3
〜/ tmp $ gdb --quiet --args ./tmp string
从/xxxxxxxx/tmp...done读取符号。
(gdb)b 12
断点1在0x400c95:文件tmp.cpp,第12行。
(gdb)run
启动程序:/ xxxxxxxx / tmp string
断点1,main(argc = 2,argv = 0x7fffffffdc58)at tmp.cpp:12
12 std :: reverse(str.begin(),str.end());
(gdb)print str
$ 1 =string
(gdb)info locals
str =string
(gdb)
c $ c>
I've been having this problem for while now, but always seem to put off asking this question because it seems like I am doing something wrong... but right now I feel otherwise... taken this code:
#include <string> #include <iostream> #include <algorithm> int main(int argc, char** argv) { if(argc < 2) { std::cout << "usage: " << argv[0] << " <string>" << std::endl; return 1; } std::string str = argv[1]; std::reverse(str.begin(), str.end()); std::cout << str << std::endl; return 0; }
Compiled with the command:
g++ -std=c++11 -Wall main.cpp -o main -O0 -ggdb3
I am using a very recent trunk version of gcc, I the trunk was taken around September 23rd ish... Also note that I am not compiling with optimization!
Now anyway, I start debugging, like this:
gdb --quiet --args ./main string
I set a break point at line 12 (the reverse algorithm)
b 12
then I run the program
run
then I try to print out the string, to see what it is
print str
And this, my dear friends, is what seems strange to me: The output of that previous command is:
No symbol "str" in current context.
a quick check to the local variables doesn't show the string either
info locals
all I get is
std::__ioinit = {static _S_refcount = 2, static _S_synced_with_stdio = true}
so I'm wondering, am I at fault, or is the compiler or debugger at fault... this has been a pretty pain in the ass problem for a long time for me... so thanks for even reading this question... :)
EDIT: now that it has become clear that there is something wrong with my gcc build, I'm wondering if anyone has come across a bug report or any other case where there seems to a be a problem similar to this... I will also try checking with a recent build of gdb to make sure that there is definitely not a problem with my current debugger (that comes with ubuntu)... does that make sense?
EDIT2: So after compiling gdb v7.5, I got relatively the same result except there were no locals present at all... I guess that means it's a gcc issue, thanks everyone...
解决方案No, even with --quiet it works for me. Maybe there's something wrong with your setup.
~/tmp $ g++ -Wall tmp.cpp -o tmp -O0 -ggdb3 ~/tmp $ gdb --quiet --args ./tmp string Reading symbols from /xxxxxxxx/tmp...done. (gdb) b 12 Breakpoint 1 at 0x400c95: file tmp.cpp, line 12. (gdb) run Starting program: /xxxxxxxx/tmp string Breakpoint 1, main (argc=2, argv=0x7fffffffdc58) at tmp.cpp:12 12 std::reverse(str.begin(), str.end()); (gdb) print str $1 = "string" (gdb) info locals str = "string" (gdb)
这篇关于在没有优化的程序上使用gdb调试,但在当前上下文中没有用于局部变量的符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!