无法在gdb中打印全局对象 [英] can not print global objects in gdb

查看:167
本文介绍了无法在gdb中打印全局对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个简单的c ++代码:

I have this simple c++ code :

#include<bits/stdc++.h>

using namespace std;
vector<string> q;

int main()
{
    q.push_back("test1");
    q.push_back("test2");
    cout<<q.front();
    return 0;
}

当我使用 gdb 打印变量 q 出现以下错误:

When I use gdb to print variable q I get following error:

No symbol "q" in current context.

我使用g ++编译我的程序,如下所示:

I compile my program using g++ like this:

 g++ -g a.cpp

这里是我的gdb命令:

And here is my gdb commands:

gdb a.out 
GNU gdb (GDB) 7.12
Copyright (C) 2016 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 "x86_64-pc-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from a.out...done.
(gdb) b 6
Breakpoint 1 at 0x400c6f: file a.cpp, line 6.
(gdb) r
Starting program: /home/mohammad/Desktop/a.out 

Breakpoint 1, main () at a.cpp:9
9       q.push_back("test");
(gdb) print q
No symbol "q" in current context.


推荐答案

这个问题与某些新的gcc Dual ABI有关,在gcc 5中引入了
gdb对这些新的C ++ 11 ABI标签的支持很差。例如,查看这些错误:

This issue is somehow related to new gcc Dual ABI, introduced in gcc 5. gdb has poor support of these new C++11 ABI tags. See these bugs for example:

  • https://sourceware.org/bugzilla/show_bug.cgi?id=19436
  • https://sourceware.org/bugzilla/show_bug.cgi?id=18601

作为解决方法,您可以通过使用 -D_GLIBCXX_USE_CXX11_ABI = 0 进行编译来禁用此新gcc ABI:

As a workaround you may disable this new gcc ABI by compiling with -D_GLIBCXX_USE_CXX11_ABI=0:

g++ -D_GLIBCXX_USE_CXX11_ABI=0 -g a.cpp

这篇关于无法在gdb中打印全局对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆