This is the mail archive of the
gdb@sourceware.org
mailing list for the GDB project.
Re: How GDB knows a breakpoint is hit?
- From: "Satendra..." <satendra dot pratap at gmail dot com>
- To: kceiwH <kceiwh at gmail dot com>
- Cc: gdb at sourceware dot org
- Date: Wed, 19 Aug 2009 22:07:48 +0530
- Subject: Re: How GDB knows a breakpoint is hit?
- References: <84D22DD1-F4AD-4985-A0EC-AF3B53774D10@gmail.com>
whenever you put a breakpoint at some address using GDB then GDB
replaces instruction at
that address with a trap, illegal divide, or some other instruction
that will cause an exception.
So when it's encountered, GDB will take the exception and stop the program.
Before you browse the code, go through
http://sourceware.org/gdb/current/onlinedocs/gdbint_toc.html
once.
-Satendra
On 19/08/2009, kceiwH <kceiwh@gmail.com> wrote:
> Hi,
>
> I wonder how GDB knows it should stop the inferior when a breakpoint
> is hit. I try to read the code but only to find how GDB creates a
> breakpoint. I thought GDB might change some instructions of inferior
> so that when the inferior executes the modified instructions, GDB
> should know. But what the function "create_breakpoint" does is to add
> a breakpoint to the list "breakpoint_chain". It is not what I thought.
> So I am confused. Does GDB monitor each instruction of the inferior
> and check whether there is a breakpoint and stop the inferior before
> the instruction is executed? If so, how GDB monitor the inferior? And
> it will be too slow. Could anybody tell how GDB handle it and plus the
> codes. Thanks in advance.
>
> Regards,
>
> Mao
>