Does GDB will remove trap instruction and restore original instruction when GDB quit?

Simon Marchi simon.marchi@polymtl.ca
Sun Oct 3 14:07:04 GMT 2021


On 2021-10-03 03:34, 周春明(日月) wrote:
> 
> Dear GDB experts,
> 
> I have a question, Does GDB will remove trap instruction and restore original instruction when GDB quit?
> Could you help to point where code to do that?

Of course GDB removes the breakpoint instructions, otherwise the
detached process would crash if it encounters one of them.

By default, when the program stops and all threads are stopped, GDB
removes the breakpoints from the program.  So if GDB detaches at that
moment, the breakpoints will already be removed.

If detaching while threads are running, then it happens through this
path:

 -> quit_force
 -> kill_or_detach
 -> target_detach
 -> linux_nat_target::detach (assuming you're on Linux, otherwise the equivalent detach method)
 -> remove_breakpoints_inf

Simon


More information about the Gdb-patches mailing list