如何从gdb内部自动重新连接到valgrind控制的进程?

时间:2021-10-22 22:49:04

I made a memory error that is quite difficult to debug, happening every once in a few command-line runs, each taking about two hours to complete. Because of that, I thought it could be a good idea to create logs like this:

我犯了一个很难调试的内存错误,每运行几次命令行就会发生一次,每次都要花大约两个小时来完成。正因为如此,我认为创建这样的日志是个好主意:

while true; do 
  valgrind ./command 2>&1 | tee command
  grep -q Invalid && break
done

The problem is that my debug logs and stack traces produced by Valgrind aren't enough, so I decided to add --vgdb-error=0 to the command line. Unfortunately, since Valgrind now adds a breakpoint on startup, I need to run the following:

问题是,Valgrind生成的调试日志和堆栈跟踪不够,所以我决定向命令行添加—vgdb-error=0。不幸的是,由于Valgrind现在在启动时增加了一个断点,所以我需要运行以下代码:

$ gdb ./command
...gdb init string follows...
(gdb) target remote | /usr/lib/valgrind/../../bin/vgdb
Remote debugging using | /usr/lib/valgrind/../../bin/vgdb
relaying data between gdb and process 4361
Reading symbols from /lib/ld-linux.so.2...(no debugging symbols found)...done.
Loaded symbols for /lib/ld-linux.so.2
[Switching to Thread 4361]
0x04000840 in ?? () from /lib/ld-linux.so.2
(gdb) continue
Continuing.

How can I script the process so that either Valgrind does not break on startup or a script keeps attaching to vgdb processes and tell them to continue until one of the processes completes abnormally?

我如何编写这个过程,以便在启动时不中断,或者脚本继续连接到vgdb进程,并告诉它们继续执行,直到其中一个进程异常完成?

1 个解决方案

#1


2  

The argument to --vgdb-error is the number of errors to expect before valgrind stops the program and attaches the debugger. If you set it to 0, then it will stop immediately before running your program. You want --vgdb-error=1, which will run to the first error then stop. Then you can attach a debugger.

vgdb-error的参数是在valgrind停止程序并附加调试器之前预期的错误数量。如果您将它设置为0,那么它将在运行程序之前立即停止。您需要——vgdb-error=1,它将运行到第一个错误,然后停止。然后可以附加调试器。

#1


2  

The argument to --vgdb-error is the number of errors to expect before valgrind stops the program and attaches the debugger. If you set it to 0, then it will stop immediately before running your program. You want --vgdb-error=1, which will run to the first error then stop. Then you can attach a debugger.

vgdb-error的参数是在valgrind停止程序并附加调试器之前预期的错误数量。如果您将它设置为0,那么它将在运行程序之前立即停止。您需要——vgdb-error=1,它将运行到第一个错误,然后停止。然后可以附加调试器。