* How GDB knows a breakpoint is hit?
@ 2009-08-19 15:52 kceiwH
2009-08-19 19:13 ` Satendra...
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: kceiwH @ 2009-08-19 15:52 UTC (permalink / raw)
To: gdb
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
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: How GDB knows a breakpoint is hit?
2009-08-19 15:52 How GDB knows a breakpoint is hit? kceiwH
@ 2009-08-19 19:13 ` Satendra...
2009-08-19 22:11 ` Andreas Schwab
2009-08-20 6:54 ` Hui Zhu
2 siblings, 0 replies; 5+ messages in thread
From: Satendra... @ 2009-08-19 19:13 UTC (permalink / raw)
To: kceiwH; +Cc: gdb
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
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: How GDB knows a breakpoint is hit?
2009-08-19 15:52 How GDB knows a breakpoint is hit? kceiwH
2009-08-19 19:13 ` Satendra...
@ 2009-08-19 22:11 ` Andreas Schwab
2009-08-20 2:21 ` kceiwH
2009-08-20 6:54 ` Hui Zhu
2 siblings, 1 reply; 5+ messages in thread
From: Andreas Schwab @ 2009-08-19 22:11 UTC (permalink / raw)
To: kceiwH; +Cc: gdb
kceiwH <kceiwh@gmail.com> writes:
> 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".
Breakpoints are only inserted immediately before the inferior is
resumed, see insert_breakpoints.
Andreas.
--
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: How GDB knows a breakpoint is hit?
2009-08-19 22:11 ` Andreas Schwab
@ 2009-08-20 2:21 ` kceiwH
0 siblings, 0 replies; 5+ messages in thread
From: kceiwH @ 2009-08-20 2:21 UTC (permalink / raw)
To: Andreas Schwab; +Cc: gdb
Thanks very much.
Mao
On Aug 19, 2009, at 5:09 PM, Andreas Schwab wrote:
> kceiwH <kceiwh@gmail.com> writes:
>
>> 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".
>
> Breakpoints are only inserted immediately before the inferior is
> resumed, see insert_breakpoints.
>
> Andreas.
>
> --
> Andreas Schwab, schwab@linux-m68k.org
> GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276
> 4ED5
> "And now for something completely different."
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: How GDB knows a breakpoint is hit?
2009-08-19 15:52 How GDB knows a breakpoint is hit? kceiwH
2009-08-19 19:13 ` Satendra...
2009-08-19 22:11 ` Andreas Schwab
@ 2009-08-20 6:54 ` Hui Zhu
2 siblings, 0 replies; 5+ messages in thread
From: Hui Zhu @ 2009-08-20 6:54 UTC (permalink / raw)
To: kceiwH; +Cc: gdb
I think you can read the code around function bpstat_what.
Hui
On Wed, Aug 19, 2009 at 23:28, 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
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2009-08-20 6:53 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-08-19 15:52 How GDB knows a breakpoint is hit? kceiwH
2009-08-19 19:13 ` Satendra...
2009-08-19 22:11 ` Andreas Schwab
2009-08-20 2:21 ` kceiwH
2009-08-20 6:54 ` Hui Zhu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox