From: Bruno Larsen <blarsen@redhat.com>
To: tangming chen <tangmingchen8@gmail.com>, gdb@sourceware.org
Subject: Re: some questions about the underlying implementation principle of gdb
Date: Thu, 10 Nov 2022 16:08:30 +0100 [thread overview]
Message-ID: <8b2bd550-b7bd-8015-5c6c-92bf890508d1@redhat.com> (raw)
In-Reply-To: <CAAxoQC7iM55m-fR=iXemUPjfCQ8bwjx4yEYO6M_xDzvc2T=cLA@mail.gmail.com>
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
prev parent reply other threads:[~2022-11-10 15:08 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-09 15:30 tangming chen
2022-11-10 15:08 ` Bruno Larsen [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=8b2bd550-b7bd-8015-5c6c-92bf890508d1@redhat.com \
--to=blarsen@redhat.com \
--cc=gdb@sourceware.org \
--cc=tangmingchen8@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).