Bug 263423

Summary: [PATCH] allow gdb attach for self-forking processes that modify fd 0,1 and 2
Product: [Developer tools] valgrind Reporter: Christian Borntraeger <borntraeger>
Component: generalAssignee: Julian Seward <jseward>
Status: RESOLVED INTENTIONAL    
Severity: normal CC: flo2030
Priority: NOR    
Version First Reported In: 3.7 SVN   
Target Milestone: ---   
Platform: Compiled Sources   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:
Attachments: allow gdb attach if fds 0-2 are changed

Description Christian Borntraeger 2011-01-17 14:40:22 UTC
Created attachment 56123 [details]
allow gdb attach if fds 0-2 are changed

Version:           3.7 SVN
OS:                Linux

With complex shell scripts bash usually forks a lot of of sub-bashes (no execve for these) and communicated via file descriptors. If you now use db-attach and one of these sub-bashes has a bug db attach will go wild for two reasons:
1. the " ---- Attach to debugger ? --- [Return/N/n/Y/y/C/c] ----" will ask for input on the input fd, but this might be redirected to something like a pipe
2. gdb might no get a proper stdout/stderr but also writes to a pipe

Example where the "input" is flooded with chars other than n,y or c.

==22024== ---- Attach to debugger ? --- [Return/N/n/Y/y/C/c] ---- ==22024== ---- Attach to debugger ? --- [Return/N/n/Y/y/C/c] ---- ==22024== ---- Attach to debugger ? --- [Return/N/n/Y/y/C/c] ---- ==22024== ---- Attach to debugger ? --- [Return/N/n/Y/y/C/c] ---- ==22024== ---- Attach to debugger ? --- [Return/N/n/Y/y/C/c] ---- ==22024== ---- Attach to debugger ? --- [Return/N/n/Y/y/C/c] ---- ==22024== ---- Attach to debugger ? --- [Return/N/n/Y/y/C/c] ---- ==22024== ---- Attach to debugger ? --- [Return/N/n/Y/y/C/c] ---- ==22024== ---- Attach to debugger ? --- [Return/N/n/Y/y/C/c] ---- ==22024== ---- Attach to debugger ? --- [Return/N/n/Y/y/C/c] ---- ==22024== ---- Attach to debugger ? --- [Return/N/n/Y/y/C/c] ---- ==22024== ---- Attach to debugger ? --- [Return/N/n/Y/y/C/c] ---- ==22024== ---- Attach to debugger ? --- [Return/N/n/Y/y/C/c] ---- ==22024== ---- Attach to debugger ? --- [Return/N/n/Y/y/C/c] ---- ==22024== ---- Attach to debugger ? --- [Return/N/n/Y/y/C/c] ---- ==22024== ---- Attach to debugger ? --- [Return/N/n/Y/y/C/c] ---- ==22024== ---- Attach to debugger ? --- [Return/N/n/Y/y/C/c] ---- ==22024== ---- Attach to debugger ? --- [Return/N/n/Y/y/C/c] ---- ==22024== ---- Attach to debugger ? --- [Return/N/n/Y/y/C/c] ---- ==22024== ---- Attach to debugger ? --- [Return/N/n/Y/y/C/c] ---- ==22024== ---- Attach to debugger ? --- [Return/N/n/Y/y/C/c] ---- ==22024== ---- Attach to debugger ? --- [Return/N/n/Y/y/C/c] ---- ==22024== ---- Attach to debugger ? --- [Return/N/n/Y/y/C/c] ---- ==22024== ---- Attach to debugger ? --- [Return/N/n/Y/y/C/c] ---- ==22024== ---- Attach to debugger ? --- [Return/N/n/Y/y/C/c] ---- ==22024== ---- Attach to debugger ? --- [Return/N/n/Y/y/C/c] ---- ==22024== ---- Attach to debugger ? --- [Return/N/n/Y/y/C/c] ---- ==22024== ---- Attach to debugger ? --- [Return/N/n/Y/y/C/c] ---- ==22024== ---- Attach to debugger ? --- [Return/N/n/Y/y/C/c] ---- ==22024== ---- Attach to debugger ? --- [Return/N/n/Y/y/C/c] ---- ==22024== ---- Attach to debugger ? --- [Return/N/n/Y/y/C/c] ---- ==22024== ---- Attach to debugger ? --- [Return/N/n/Y/y/C/c] ---- 

Reproducible: Didn't try




Here is a patch that tries to
-  build a sane terminal for gdb by saving the original fds
- copy the input fd to the valgrind private range
it also moved the static inline fd_exists to the haeder file and adds some comments about used private fds.

The patch certainly requires some review
Comment 1 Florian Krohm 2014-09-25 08:27:50 UTC
The --db-attach feature is deprecated as of valgrind 3.10.0.
It will be removed in the next valgrind feature release.
The built-in GDB server capabilities are superior and should be
used instead. 
Therefore, this bug will not be fixed.