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

Gdb

Gdb Problem Overview


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.

Gdb Solutions


Solution 1 - Gdb

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.

Solution 2 - Gdb

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.

Solution 3 - Gdb

To Skip Any Numbers of Lines during Execution:

[Current Position -- in GDB] Line N
.......... // Lines To Skip
..........
..........
[Line To Execute - After Jumping] Line M

Put a Breakpoint on Line M:

gdb$b M

Jump To Line M:

gdb$jump M

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionOrtwin GentzView Question on Stackoverflow
Solution 1 - GdblaaltoView Answer on Stackoverflow
Solution 2 - GdbgospesView Answer on Stackoverflow
Solution 3 - GdbSandeep SinghView Answer on Stackoverflow