Search code examples
xcodelldb

lldb command jump: resume outside the current function?


LLDB command jump lets me resume program execution at a different position from where it has stopped, but it seems to be restricted to addresses inside the current function:

(lldb) jump CLI.cpp:15
error: CLI.cpp:15 is outside the current function.

I'm curious about that, since this restriction is not documented in lldb's help, and the syntax jump <file>:<line> somehow indicates that one could use arbitrary entry points:

(lldb) help jump
     ('_regexp-jump')  Set the program counter to a new address.  Expects 'raw'
     input (see 'help raw-input'.)

Syntax: 
_regexp-jump <line>
_regexp-jump +<line-offset> | -<line-offset>
_regexp-jump <file>:<line>
_regexp-jump *<addr>

'jump' is an abbreviation for '_regexp-jump'

I'm aware that resuming in a different frame/stack may bring the program into an inconsistent state with "wonderful" side effects.

How can I jump to lines outside the current function in lldb (ignoring possible side effects)?


Solution

  • jump is a wrapper command that packages up some common uses of the underlying thread jump into a compact form. That's what all the _regex- commands are in lldb. Do:

    (lldb) help command regex
    

    if you want more details on this regex commands, and of course

    (lldb) help thread jump
    

    for everything you can do with that command.

    The wrapper doesn't have an affordance to allow jumping outside the current function because that is definitely NOT a safe operation, so the default is to assume you made a mistake in typing the line or file name...

    The underlying command does have a --force option that allows you to move the pc out of the current function.