LLDB中jump命令如何跳转到当前函数外的代码行?
Great question—you’re absolutely right that the jump shorthand (a wrapper for _regexp-jump) has an unstated restriction to stay within the current function, even though its help text suggests <file>:<line> should work anywhere. Let’s go over how to bypass this limitation.
To jump to arbitrary lines outside your current function, you need to work directly with the program counter (PC) register instead of relying on the restricted jump <file>:<line> syntax. Here are two reliable methods:
Method 1: Jump using the target line's raw address
First, resolve your target line (CLI.cpp:15) to its memory address with this command:
image lookup -f CLI.cpp -l 15
In the output, find the Address field (it will look like 0x100004abc for example). Then use the jump command with this address prefixed by *—this bypasses the function-bound restriction of the regex-based jump alias:
jump *0x100004abc
Method 2: Directly modify the PC register
LLDB lets you overwrite the PC register directly via the expression command. You can either use the address you looked up earlier:
expression -- $pc = 0x100004abc
Or skip the lookup step entirely with a direct reference to the line (this works if the line maps to a single, unique memory address):
expression -- $pc = (void*)&&CLI.cpp:15
Critical Caveat
As you already noted, jumping across functions skips critical stack frame setup and teardown logic. This can leave the program in an inconsistent state—think unbalanced stack pointers, leaked local variables, or incorrect register values—which will almost certainly cause crashes or unexpected behavior. Only use these methods if you fully understand and accept those risks.
内容的提问来源于stack exchange,提问作者Stephan Lechner

