无法在gdb中打印全局对象

Moh*_*ghi 4 c++ gdb global-variables

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

#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;
}
Run Code Online (Sandbox Code Playgroud)

当我gdb用来打印变量时,q我得到以下错误:

No symbol "q" in current context.
Run Code Online (Sandbox Code Playgroud)

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

 g++ -g a.cpp
Run Code Online (Sandbox Code Playgroud)

这是我的gdb命令:

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.
Run Code Online (Sandbox Code Playgroud)

ks1*_*322 5

这个问题与gcc 5中引入的新gcc Dual ABI有某种关系.gdb对这些新的C++ 11 ABI标记的支持很差.请参阅以下错误:

作为一种解决方法,您可以通过以下方式编译来禁用此新gcc ABI -D_GLIBCXX_USE_CXX11_ABI=0:

g++ -D_GLIBCXX_USE_CXX11_ABI=0 -g a.cpp
Run Code Online (Sandbox Code Playgroud)

  • 或者,`(gdb)p'q [abi:cxx11]'` (3认同)