GDB and LD_PRELOAD library-call interception

Xavier de Gaye xdegaye@gmail.com
Sun Apr 3 16:54:00 GMT 2011


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: interconnect_pty.py
Type: text/x-python
Size: 3670 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/gdb/attachments/20110403/3c8c3653/attachment.py>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: xterm_wrapper.py
Type: text/x-python
Size: 1072 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/gdb/attachments/20110403/3c8c3653/attachment-0001.py>


More information about the Gdb mailing list