some questions about the underlying implementation principle of gdb

Bruno Larsen
Thu Nov 10 15:08:30 GMT 2022

On 09/11/2022 16:30, tangming chen via Gdb wrote:
> Hello:
>       I am an undergraduate, and i am studying gdb. I have some questions
> about the underlying implementation principle of gdb.
>       I learned that the implementation of gdb is related to ptrace.
> Therefore,how does gdb debug programs through ptrace?  More specifically, I
> recently learned the awatch command,ignore command(ignore n number (n is
> watchpoint number)),continue command. how does gdb implement the
> commands(awatch ignore continue)?
>     Thank you!

I am not very familiar with how GDB uses ptrace, but I do know a tiny 
bit about the ignore command.

Breakpoints are a data structure (defined in gdb/breakpoint.h:623), and 
one of the members of the struct is an ignore count (line 751). The 
function run when you use this command is defined in 
gdb/breakpoint.c:12905 (ignore_command). It just sets the number in the 
breakpoint and moves along.

Once you set the inferior running again with 'continue' or anything 
else, the breakpoint will be hit and GDB will enter the function 
handle_signal_stop, which will set the status of the breakpoint by 
calling bpstat_stop_status, which (through other function calls) will 
check if the ignore_count is greater than 0 (gdb/breakpoint.c:5438), and 
if it isn't it will be decremented and say that GDB shouldn't stop. 
handle_signal_stop will then send a signal for the inferior to carry on 
as if nothing has happened.

Essentially, GDB doesn't ignore the breakpoint, but it looks like it for 
the user :). Now keep in mind this is glossing over a lot of error 
checking and possibly other things related to ignored breakpoints, and I 
might just be straight up wrong since I haven't been working on GDB for 
long, but I hope this helps your understanding and gives enough 
substance for you to look more in-depth.


More information about the Gdb mailing list