|
From: Philippe W. <phi...@sk...> - 2013-03-11 21:38:16
|
On Mon, 2013-03-11 at 17:52 +0100, Dan Shelton wrote: > Has anyone found a way that for each valgrind hit a gdb command is issued? > I need a way to print a certain amount of commands per valgrind hit on > a live application (i.e. variables of interest). I guess that by valgrind hit, you mean an error reported by valgrind. One way with which you can do that is to have a gdb connected to Valgrind (use --vgdb-error=0 and follow the on-screen instructions). You can then put commands in the GDB "stop hook", using define hook-stop print this_var print other_var ... any command accepted by gdb ... including the Valgrind gdbserver monitor commands end (the commands of a hook-stop are run each time your program stops). There is one weakness with the GDB hook-stop: you cannot use a continue command in the list of commands. So, the bypass is to have a file containing a *lot* of continue command. You then source this file in GDB. So, in summary, at GDB side, you do: gdb your_program define hook-stop ... all your needed commands ... end target remote | ... (as told by valgrind) set height 0 (this is needed to avoid having gdb pausing for each page of output source a_file_containing_a_lot_of_continue_command I guess it will be possible to do the above also with --db-attach=yes and giving GDB arguments to source a file of commands. This will however be very slow as this will imply two forks and one GDB execution for each error. Philippe |