作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用GDB分析核心转储。我知道它指向“std::basic_fstream
如何在GDB提示符下将原始内存地址转换为该模板对象?
我尝试通过以下命令:
(gdb)p *('std::basic_fstream
在当前上下文中没有符号“std::basic_fstream
(gdb)p *(std::basic_fstream
表达式中语法错误,在`)0x7fae3800b280'附近。
最佳答案
I tried by below command:
set auto-solib-add off
中是否有
~/.gdbinit
?
cat t.cc
#include <fstream>
int main(int argc, char *argv[])
{
std::wfstream s("/dev/tty", s.out);
for (int j = 0; j < argc; j++)
s << j << " " << argv[j] << std::endl;
return 0;
}
g++ -g t.cc && gdb -q ./a.out
(gdb) b 8
Breakpoint 1 at 0x1235: file t.cc, line 8.
(gdb) run foo
Starting program: /tmp/a.out foo
0 /tmp/a.out
1 foo
Breakpoint 1, main (argc=2, argv=0x7fffffffdc28) at t.cc:8
8 return 0;
(gdb) set print static off
(gdb) p s
$1 = {<std::basic_iostream<wchar_t, std::char_traits<wchar_t> >> = {<std::basic_istream<wchar_t, std::char_traits<wchar_t> >> = {<std::basic_ios<wchar_t, std::char_traits<wchar_t> >> = ...
(gdb) p &s
$2 = (std::wfstream *) 0x7fffffffd900
(gdb) p *('std::basic_fstream<wchar_t, std::char_traits<wchar_t> >' *)0x7fffffffd900
$3 = {<std::basic_iostream<wchar_t, std::char_traits<wchar_t> >> = {<std::basic_istream<wchar_t, std::char_traits<wchar_t> >> = {<std::basic_ios<wchar_t, std::char_traits<wchar_t> >> = {<std::ios_base> = ...
您应该尝试复制上述输出。
core
转储。
No symbol
结果的一种方法是通过设置
auto-solib-add off
:
gdb -q ./a.out
Reading symbols from ./a.out...
(gdb) b 8
Breakpoint 1 at 0x1235: file t.cc, line 8.
(gdb) set auto-solib-add off
(gdb) run
Starting program: /tmp/a.out
0 /tmp/a.out
Breakpoint 1, main (argc=1, argv=0x7fffffffdc28) at t.cc:8
8 return 0;
(gdb) p &s
$1 = (std::wfstream *) 0x7fffffffd900
(gdb) p *('std::basic_fstream<wchar_t, std::char_traits<wchar_t> >' *) 0x7fffffffd900
No symbol "std::basic_fstream<wchar_t, std::char_traits<wchar_t> >" in current context.
关于c++ - GDB:如何将内存地址转换为STL对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63884022/
我是一名优秀的程序员,十分优秀!