Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use gdb to skip a line without having to type line numbers?

Tags:

gdb

I know I can use jump to set the program counter to a specific line and so I can skip one or more lines (or execute some lines again). Can I easily just skip the next line without having to enter line numbers?

This would be very convenient to "comment out" something at run time.

like image 386
Ortwin Gentz Avatar asked Oct 27 '10 20:10

Ortwin Gentz


People also ask

Can you skip a line in gdb?

So just type skip in gdb to skip a line.

How do you break a line in gdb?

To do this, just type "break [functionname]". gdb will stop your program just before that function is called. Breakpoints stay set when your program ends, so you do not have to reset them unless you quit gdb and restart it.

How do I skip instructions in gdb?

Sure: jump *0x1234 will jump to instruction at address 0x1234 .

What does jump do in gdb?

jump * address. Resume execution at the instruction at address address . makes the next continue command or stepping command execute at address 0x485 , rather than at the address where your program stopped. See section Continuing and stepping.


2 Answers

jump +1 

jumps to the next line line i.e. skipping the current line. You may also want to combine it with tbreak +1 to set a temporary breakpoint at the jump target.

See http://sourceware.org/gdb/current/onlinedocs/gdb/Specify-Location.html for more ways of expressing locations with gdb.

Note that without a breakpoint gdb is likely to continue execution normally instead of jumping. So if jumping doesn't seem to work, make sure you set a breakpoint at the destination.

like image 106
laalto Avatar answered Sep 19 '22 13:09

laalto


I have the following in my .gdbinit config file:

define skip     tbreak +1     jump +1 end 

So just type skip in gdb to skip a line.

like image 29
gospes Avatar answered Sep 21 '22 13:09

gospes