Bug 263423 - [PATCH] allow gdb attach for self-forking processes that modify fd 0,1 and 2
Summary: [PATCH] allow gdb attach for self-forking processes that modify fd 0,1 and 2
Status: RESOLVED INTENTIONAL
Alias: None
Product: valgrind
Classification: Developer tools
Component: general (show other bugs)
Version: 3.7 SVN
Platform: Compiled Sources Linux
: NOR normal
Target Milestone: ---
Assignee: Julian Seward
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-01-17 14:40 UTC by Christian Borntraeger
Modified: 2014-09-25 08:27 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
allow gdb attach if fds 0-2 are changed (6.17 KB, patch)
2011-01-17 14:40 UTC, Christian Borntraeger
Details

Note You need to log in before you can comment on or make changes to this bug.
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.