public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
* some questions about the underlying implementation principle of gdb
@ 2022-11-09 15:30 tangming chen
  2022-11-10 15:08 ` Bruno Larsen
  0 siblings, 1 reply; 2+ messages in thread
From: tangming chen @ 2022-11-09 15:30 UTC (permalink / raw)
  To: gdb

[-- Attachment #1: Type: text/plain, Size: 485 bytes --]

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!

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: some questions about the underlying implementation principle of gdb
  2022-11-09 15:30 some questions about the underlying implementation principle of gdb tangming chen
@ 2022-11-10 15:08 ` Bruno Larsen
  0 siblings, 0 replies; 2+ messages in thread
From: Bruno Larsen @ 2022-11-10 15:08 UTC (permalink / raw)
  To: tangming chen, gdb

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!
>
Hello!

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.

-- 
Cheers,
Bruno


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-11-10 15:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-09 15:30 some questions about the underlying implementation principle of gdb tangming chen
2022-11-10 15:08 ` Bruno Larsen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).