I am debugging in a recompile-debug cycle that looks as follows:
- Compile binary
- Run debugger
gdb prog
- Find an error and fix the source
- Exit debugger with pressing
ctrl+d
or typingquit
I would like to add Valgrind in the workflow to break as soon as I faced incorrect out-of-range memory read or write. I found that if I follow the officially documented process of running Valgrind with gdb I have to perform a lot more time-consuming steps.
- Compile binary
- Run valgrind
valgrind --vgdb=yes --vgdb-error=0 prog
- Open new terminal window and type
gdb prog
- Run
target remote | vgdb
(or, even worse, copy-paste command for connection printed in valgrind window if I am running multiple debug sessions) - Find an error and fix the source
- Exit debugger
- Kill application with valgrind process with
kill -9
(because Valgrind doesn't stops it on gdb exit)
How I can automate these 3 extra steps? Ideally, I would expect to have a command like mygdb
as a drop-in replacement for gdb
that runs Valgrind under the hood, maybe debug slower, but breaks as soon as Valgrind detects an error.