GDB:在内存位置打印函数参数的值
GDB: Printing value of a function argument in a memory location
我正在使用 Valgrind 和 GDB 调试内存泄漏。我有以下显示内存泄漏发生位置的调用跟踪:
(gdb) monitor block_list 10104
==961== 153 (18 direct, 135 indirect) bytes in 1 blocks are definitely lost in loss record 10,104 of 10,317
==961== at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==961== by 0x678199: create_node(unsigned char const*, unsigned int, document*) (a.cpp:436)
==961== by 0x67933A: insert(art_node*, art_node**, unsigned char const*, unsigned int, document*, unsigned int, int, int*) (a.cpp:704)
==961== by 0x68327B: Program::add(std::string const&) (program.cpp:84)
==961== by 0x7220BF: main (main.cpp:52)
我想打印传递给 Program::add
的字符串参数的值:
==961== by 0x68327B: Program::add(std::string const&) (program.cpp:84)
如何在 GDB 中执行此操作?
你可以一步一步来Valgrind manual:
If you want to debug a program with GDB when using the Memcheck tool,
start Valgrind like this:
valgrind --vgdb=yes --vgdb-error=0 prog
In another shell, start GDB:
gdb prog
Then give the following command to GDB:
(gdb) target remote | vgdb
现在您可以转到 gdb 中的帧 Program::add(std::string const&)
并打印参数值。
我正在使用 Valgrind 和 GDB 调试内存泄漏。我有以下显示内存泄漏发生位置的调用跟踪:
(gdb) monitor block_list 10104
==961== 153 (18 direct, 135 indirect) bytes in 1 blocks are definitely lost in loss record 10,104 of 10,317
==961== at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==961== by 0x678199: create_node(unsigned char const*, unsigned int, document*) (a.cpp:436)
==961== by 0x67933A: insert(art_node*, art_node**, unsigned char const*, unsigned int, document*, unsigned int, int, int*) (a.cpp:704)
==961== by 0x68327B: Program::add(std::string const&) (program.cpp:84)
==961== by 0x7220BF: main (main.cpp:52)
我想打印传递给 Program::add
的字符串参数的值:
==961== by 0x68327B: Program::add(std::string const&) (program.cpp:84)
如何在 GDB 中执行此操作?
你可以一步一步来Valgrind manual:
If you want to debug a program with GDB when using the Memcheck tool, start Valgrind like this:
valgrind --vgdb=yes --vgdb-error=0 prog
In another shell, start GDB:
gdb prog
Then give the following command to GDB:
(gdb) target remote | vgdb
现在您可以转到 gdb 中的帧 Program::add(std::string const&)
并打印参数值。