使用valgrind

时间:2017-11-08 15:42:57

标签: c debugging valgrind

简而言之,valgrind不会为新进程生成行号,但它确实在主应用程序上显示行号。注意,主应用程序和所有新生成的进程都是相同的应用程序。

我正在使用以下命令运行valgrind

valgrind --leak-check=full --track-origins=yes --trace-children=yes --vgdb=yes --vgdb-error=0 ./myapp

然后我运行gdb来启动应用程序。

gdb ./myapp
(gdb) target remote | vgdb

当我的应用程序运行时,valgrind将在生成新进程时输出以下消息。

==19414== (action at startup) vgdb me ... 
==19414== 
==19414== TO DEBUG THIS PROCESS USING GDB: start GDB like this
==19414==   /path/to/gdb ./myapp
==19414== and then give GDB the following command
==19414==   target remote | /usr/local/lib/valgrind/../../bin/vgdb --pid=19414
==19414== --pid is optional if only one valgrind process is running
==19414== 

这是我遇到问题的地方。我打开了gdb的新实例并运行命令。但是,我收到了一个错误。

(gdb) target remote | /usr/local/lib/valgrind/../../bin/vgdb --pid=18920
Remote debugging using | /usr/local/lib/valgrind/../../bin/vgdb --pid=18920
relaying data between gdb and process 18920
Reading symbols from /usr/local/lib/valgrind/vgpreload_core-amd64-freebsd.so...(no debugging symbols found)...done.
Reading symbols from /usr/local/lib/valgrind/vgpreload_memcheck-amd64-freebsd.so...(no debugging symbols found)...done.
Reading symbols from /usr/local/lib/libcurl.so.4...(no debugging symbols found)...done.
Reading symbols from /usr/local/lib/libjson-c.so.2...(no debugging symbols found)...done.
Reading symbols from /lib/libm.so.5...(no debugging symbols found)...done.
Reading symbols from /usr/local/lib/libpq.so.5...(no debugging symbols found)...done.
Reading symbols from /lib/libthr.so.3...(no debugging symbols found)...done.
Reading symbols from /lib/libc.so.7...(no debugging symbols found)...done.
Reading symbols from /usr/lib/libssl.so.7...(no debugging symbols found)...done.
Reading symbols from /usr/lib/libheimntlm.so.11...(no debugging symbols found)...done.
Reading symbols from /usr/lib/libhx509.so.11...(no debugging symbols found)...done.
Reading symbols from /usr/lib/libcom_err.so.5...(no debugging symbols found)...done.
Reading symbols from /lib/libcrypto.so.7...(no debugging symbols found)...done.
Reading symbols from /usr/lib/libasn1.so.11...(no debugging symbols found)...done.
Reading symbols from /usr/lib/libwind.so.11...(no debugging symbols found)...done.
Reading symbols from /usr/lib/libheimbase.so.11...(no debugging symbols found)...done.
Reading symbols from /usr/lib/libroken.so.11...(no debugging symbols found)...done.
Reading symbols from /lib/libcrypt.so.5...(no debugging symbols found)...done.
Reading symbols from /lib/libz.so.6...(no debugging symbols found)...done.
Reading symbols from /usr/lib/libkrb5.so.11...(no debugging symbols found)...done.
Reading symbols from /usr/lib/libgssapi.so.10...(no debugging symbols found)...done.
Reading symbols from /usr/lib/libgssapi_krb5.so.10...(no debugging symbols found)...done.
Reading symbols from /usr/local/lib/libintl.so.8...(no debugging symbols found)...done.
Reading symbols from /usr/lib/private/libheimipcc.so.11...(no debugging symbols found)...done.
Reading symbols from /libexec/ld-elf.so.1...(no debugging symbols found)...done.
0x00000000059aaa2a in syscall () from /lib/libc.so.7
(gdb) c
Continuing.
syscall failed: Bad file descriptor
close from_pid
Remote connection closed

这告诉我它没有找到调试信息。 valgrind是使用软件包安装的,因此未配置为调试。但是,我没有看到我的应用程序列出。我正在查看我正在使用的库,例如libcurllibjson-c,但不是我的应用程序。

我的下一个测试是在没有valgrind的情况下运行gdb

valgrind --leak-check=full --track-origins=yes --trace-children=yes ./myapp

这次valgrind会产生新进程的错误,但我无法看到新进程的行号。当我在主应用程序上出错时,我可以看到行号。我感觉无法在gdb中调试新流程是因为没有gdb没有看到行号的问题。

0 个答案:

没有答案