One of the great things about lldb is that it is easy to extend with a small number of python scripts. For example, I easily encountered the new jump command:
import lldb def jump(debugger, command, result, dict): """Usage: jump LINE-NUMBER Jump to a specific source line of the current frame. Finds the first code address for a given source line, sets the pc to that value. Jumping across any allocation/deallocation boundaries (may not be obvious with ARC!), or with optimized code, quickly leads to undefined/crashy behavior. """ if lldb.frame and len(command) >= 1: line_num = int(command) context = lldb.frame.GetSymbolContext (lldb.eSymbolContextEverything) if context and context.GetCompileUnit(): compile_unit = context.GetCompileUnit() line_index = compile_unit.FindLineEntryIndex (0, line_num, compile_unit.GetFileSpec(), False) target_line = compile_unit.GetLineEntryAtIndex (line_index) if target_line and target_line.GetStartAddress().IsValid(): addr = target_line.GetStartAddress().GetLoadAddress (lldb.target) if addr != lldb.LLDB_INVALID_ADDRESS: if lldb.frame.SetPC (addr): print "PC has been set to 0x%x for %s:%d" % (addr, target_line.GetFileSpec().GetFilename(), target_line.GetLine()) def __lldb_init_module (debugger, dict): debugger.HandleCommand('command script add -f %s.jump jump' % __name__)
I put this in the directory where I store the Python commands for lldb, ~/lldb/ , and I load it into the ~/.lldbinit with
command script import ~/lldb/jump.py
and now I have a jump ( j works) command that jumps to the specified line number. eg.
(lldb) j 5 PC has been set to 0x100000f0f for ac:5 (lldb)
This new jump command will be available both in the lldb command line and in Xcode, if you load it into your ~/.lldbinit , you will need to use the debugger console panel in Xcode to move the computer instead of moving the indicator in the editor window.
source share