Bug #31599 Attaching debugger to MTR valgrind session with --db-attach is unusable
Submitted: 15 Oct 2007 9:43 Modified: 29 Oct 2007 21:21
Reporter: Mats Kindahl Email Updates:
Status: Verified Impact on me:
None 
Category:Tools: MTR / mysql-test-run Severity:S3 (Non-critical)
Version:5.0, 5.1 BK OS:Any
Assigned to: Bjørn Munch CPU Architecture:Any

[15 Oct 2007 9:43] Mats Kindahl
Description:
When using valgrind to trace memory failures, it is possible to pass options to valgrind using the --valgrind-options. However, when supplying the option --db-attach=yes, the option is successfully passed to valgrind, which causes valgrind to query on the terminal if a debug session should be started, and if the answer is "y", then a debugger (gdb by default) is started on the position so that it is possible to investigate the reason for the problem.

However, all output from valgrind, including prompts and the gdb session is written to the log file and not to the terminal. It makes it close to impossible to debug, since one has to check the log file repeatedly and then type commands on the terminal where the test case is being executed.

This severely limits the usability of --valgrind and makes it very difficult to debug valgrind failures.

How to repeat:
On a test case with a valgrind error

  ./mtr --valgrind --valgrind-options=--db-attach=yes 

Suggested fix:
Ensure that the prompting and the gdb session is written to a terminal, for example, in a similar fashion to how --gdb works.
[15 Oct 2007 9:55] Guilhem Bichot
Hi Mats, try this: create a script (I call it valgrind-db-attach):
#! /bin/sh
# we sleep so that the window does not go away too fast
exec xterm -e "valgrind --db-attach=yes $*; sleep 36000"

And run ./mtr with --valgrind-path=yourscript.
[17 Oct 2007 6:32] Mats Kindahl
The suggested solution solves my immediate problems, but still if you supply the --db-attach option to MTR, it means that the test will "hang" (actually wait for user input, but there is no way to tell). This makes it very hard to realize something is wrong.

It would still be beneficial to either forbid the use of any options that will make valgrind read input from the terminal, ensure that the prompts are printed to the terminal, or open a separate xterm window in the manner described by Guilhem (this is also in line with how --gdb behaves).
[29 Oct 2007 21:21] Sveta Smirnova
Thank you for the report.

Verified as described.