software breakpoint in gdb

Marc Khouzam marc.khouzam@ericsson.com
Mon Jan 30 15:51:00 GMT 2012


> -----Original Message-----
> From: gdb-owner@sourceware.org 
> [mailto:gdb-owner@sourceware.org] On Behalf Of Yao Qi
> Sent: Monday, January 30, 2012 1:17 AM
> To: Kevin Pouget
> Cc: Robert Dewar; Jan Kratochvil; Xin Tong; gdb@sourceware.org
> Subject: Re: software breakpoint in gdb
> 
> On 01/30/2012 01:54 PM, Kevin Pouget wrote:
> > I would be curious about why it would be "a disastrous mistake".
> > Please correct me if I'm wrong in my understanding:
> 
> The real disaster is interrupt instruction may corrupt the following
> instruction of breakpointed instruction, if interrupt instruction is
> longer than breakpointed instruction.  For example,
> 
>    JMP L1:
>    ...
>    INSN1 (1-byte)
> L1:INSN2 (2-byte)
> 
> Supposing the length of interrupt instruction is 2-byte, when setting
> breakpoint on INSN1, the INSN2 is corrupted.  If the program runs JMP
> instruction to L1 directly, something wrong will be executed.

In fact, I believe fast tracepoints in GDB had to deal with this very
limitation. Fast tracepoints don't use an interrupt instruction (too slow)
but instead use a jump instruction; that jump takes the execution to another
location to execute the tracepoint directly in the program.  Because we 
cannot replace more than one instruction, fast tracepoints are only allowed
on 5-byte instructions (actually, 4-byte instructions starting with GDB 7.4).

Marc



More information about the Gdb mailing list