在 gdb 中,如果你有一个指向某个东西的指针,你可以在打印它之前对其进行转换。
例如,这有效:
print *(int*) 0xDEADBEEF
但是,如何打印std::vector<T>
?具体来说是一个std::vector<std::string>
?
If it's std::string
,我可以这样做std::__cxx11::string
, which whatis std::string
输出,但我无法说服 gdb 喜欢std::vector<int>
(举个例子)。正如它所说,引用它没有帮助,No symbol "std::vector<int>" in current context.
实现此目的的一种方法是使用类型的损坏名称。例如,损坏的名称std::vector<int>
在当前的 gcc 和 libstdc++ 上是_ZSt6vectorIiSaIiEE
,我通过在编译器资源管理器:
#include <vector>
void foo(std::vector<int>) {}
// Mangled symbol name: _Z3fooSt6vectorIiSaIiEE
// _Z means "this is C++".
// 3foo means "identifier 3 chars long, which is `foo`"
// Strip those off and you're left with: St6vectorIiSaIiEE
// Add the _Z back: _ZSt6vectorIiSaIiEE
被破坏的名字std::vector<std::string>
is: _ZSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS5_EE
,可以通过以下方式验证whatis
.
实际表演演员:
print *(_Z3fooSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS5_EE*) 0xDEADBEEF
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)