GDB and LD_PRELOAD library-call interception

Kevin Pouget kevin.pouget@gmail.com
Mon Apr 4 13:35:00 GMT 2011


Here is a *prototype* patch of what I discussed earlier, which allows
to follow the N-th fork of a wrapper.

(my) `xterm' first forks /usr/libexec/utempter/utempter before
starting the program to debug, so it's skipped, then GDB follows the
forked child instead of the parent (I still need to figure out how not
to create a new inferior in this case).

C-c in the xterm is not intercepted by GDB, I don't know if that's a
bug or a feature;
however C-c in GDB terminal kills the xterm instead of stopping the
debuggee ... I guess it's a matter of terminal ownership, the signal
is just not sent to the right process (that's the opposite of Xavier's
problem :)


let me know what you think about it, I'll fix the bugs if it is seem
interesting for the community


Kevin

On Sun, Apr 3, 2011 at 12:54 PM, Xavier de Gaye <xdegaye@gmail.com> wrote:
>
> On Thu, Mar 31, 2011 at 2:16 PM, Jan Kratochvil wrote:
> >
> > It is not such straightforward, GDB expects the PID it has spawned will be
> > debugged while with xterm the process being debugged is its child.
> >
> > I guess you can write a small C helper which will:
> >  * create new pty
> >  * change its fds 0/1/2 to the slave of this pty
> >  * fork xterm -e own-helper-part pty-unique-id
> > In own-helper-part interconnect the pty master part and its fds 0/1/2.
> >
>
>
> The attached files 'xterm_wrapper.py' and 'interconnect_pty.py' are a
> raw implementation written in python of the above scheme. In gdb do:
>
>    set exec-wrapper python xterm_wrapper.py
>
> The problem with the implementation is that the debuggee cannot set
> the slave pty as its controlling terminal without forking (set
> SET_CONTROLLING_TERMINAL to True in 'xterm_wrapper.py' in order to do
> that, but then exec-wrapper cannot be used). So that it is not
> possible to interrupt the debuggee with a 'C-c' character.
>
> On the other hand the 'interconnect_pty.py' helper used by
> 'xterm_wrapper.py' can also be used by itself in stand-alone. When run
> without arguments, it creates a pty and prints the slave pty name so
> that it can be used in gdb with:
>
>    set inferior-tty /dev/pts/nn
>
> It can also be made to spawn gdb in a new xterm and set correctly the
> '-tty' gdb option with tne new pty name (kind of the reverse of the
> initial scheme):
>
>    python interconnect_pty.py --exec gdb --args '/path/to/debuggee'
>
> Xavier
-------------- next part --------------
A non-text attachment was scrubbed...
Name: gdb-xterm.diff
Type: application/octet-stream
Size: 2747 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/gdb/attachments/20110404/f7a0c431/attachment.obj>


More information about the Gdb mailing list