假设有这样的事情:
#include <map>
int main(){
std::map<int,int> m;
m[1] = 2;
m[2] = 4;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我希望能够从gdb检查运行该程序的地图的内容.
如果我尝试使用下标运算符,我得到:
(gdb) p m[1]
Attempt to take address of value not located in memory.
Run Code Online (Sandbox Code Playgroud)
使用find方法不会产生更好的结果:
(gdb) p m.find(1)
Cannot evaluate function -- may be inlined
Run Code Online (Sandbox Code Playgroud)
有没有办法实现这个目标?
我按照GDB维基上的说明安装了用于查看STL容器的python pretty-printers.我~/.gdbinit现在看起来像这样:
python
import sys
sys.path.insert(0, '/opt/gdb_prettyprint/python')
from libstdcxx.v6.printers import register_libstdcxx_printers
register_libstdcxx_printers (None)
end
Run Code Online (Sandbox Code Playgroud)
但是,当我运行GDB并尝试打印STL类型时,我得到以下内容:
print myString
Python Exception <class 'gdb.error'> No type named std::basic_string<char>::_Rep.:
$3 =
Run Code Online (Sandbox Code Playgroud)
任何人都可以对此有所了解吗?我正在运行Ubuntu 12.04,它带有GDB 7.4.
我从事广泛使用boost和模板的财务应用程序(Linux/C++/gcc).通过GDB进行调试时生成的堆栈跟踪非常复杂,内部模板连接的boost会在输出中添加大量难看的噪声.有没有人知道如何为C++模板(特别是增加重量级)代码获得更清晰,更漂亮和更具洞察力的堆栈跟踪?