tags:

views:

87

answers:

3
+4  Q: 

how does gdb work?

I want to know how does gdb work internally. e.g. I know a brief idea that it makes use of ptrace() system call to monitor traced program. But I want to know how it handles signals, how it inserts new code, and other such fabulous things it does.

+1  A: 

The only way you'll find out is by studying the source.

You can also build it and debug it with itself. Step through the code, and you'll know exactly how it does what it does.

Reading GDB source is not for the faint of heart though -- it is chock-full of macros, and heavily uses libbfd, which itself is hard to understand.

It has to, because it is portable (and in particular, builds and works on platforms which do not have ptrace() at all).

Employed Russian
I think you mean [chock full](http://en.wiktionary.org/wiki/chock_full)
sje397
http://www.cs.utah.edu/dept/old/texinfo/gdb/gdbint.html#SEC1
zengr
+1  A: 

Check out this pdf it covers some of the important aspects of GDB internals.

From the pdf:

This document documents the internals of the GNU debugger, gdb. It includes descrip- tion of gdb’s key algorithms and operations, as well as the mechanisms that adapt gdb to specific hosts and targets.

zengr
A: 

You may want to take a look at the libthread_db interface, which is the main interface (with proc_service) between thread libraries and debuggers.

This article and its presentation detail how the processes interact with each other, which is useful to understand which part of the thread handling GDB is reliable for, and which part is 'out-sourced' to the thread library:

Thread debug

Kevin
I have debugged problems in libthread_db. It is approximately 10 times harder to understand how libthread_db works (compared to how GDB itself works). Are you trying to inflict pain on OP?
Employed Russian
No I'm not !!! I really think that 'studying the source' is not possible, because it's sooo complicated, I had to study the `Thread module` in question and that was hard enough, so I feel it would be more convenient to attack GDB from the side instead of diving in the middle of nowhere !
Kevin