28

Is there a way to skip over lines of code while debugging with lldb without having to recompile?

Fabian
  • 6,973
  • 2
  • 26
  • 27
BollMose
  • 3,002
  • 4
  • 32
  • 41

1 Answers1

50

UPDATE

In addition to the original answer below, the jump/j aliases can be used for skipping a number of lines or skipping to a specific line number:

To skip two lines ahead:

(lldb) jump +2

To skip to line 102:

(lldb) jump 102

See help jump for more info.

ORIGINAL

This can be achieved using the thread jump command by giving the --by/-b flag. Example:

(lldb) thread jump --by 2
(lldb) th j -b 2

Alternatively, instead of a relative move an absolute line number can be specific with --line/-l.

(lldb) thread jump --line 102
(lldb) th j -l 102

Note that these both move the program counter, and that could put the program into a broken state and lead to crashes.

Dave Lee
  • 6,299
  • 1
  • 36
  • 36
  • 3
    I've been able to use this in a small project, but in a large project `thread jump --by 2` throws an exception. I saw this technique in a WWDC 2018 debugging video, as well. Are you aware of any workarounds for larger projects with a lot of threads? – Adrian Mar 07 '19 at 14:01
  • Addendum to above: I'm able to get it working on the main thread by wrapping in `DispatchQueue.main.async { do stuff }`. – Adrian Mar 12 '19 at 00:56