Move execution point in Xcode / lldb

Is there a way to set the execution point while debugging Xcode / lldb? To be more specific, after hitting a breakpoint, manually moving the execution point to another line of code?

+4
source share
4 answers

If you look at moving up or down using the method, you can click and drag the green arrow to a specific point. therefore, if you want to back up the line to a breakpoint. click on the green arrow to be created and drag it up. If you hit the run, you hit your breakpoint again.

+9
source

In Xcode 6, you can use j lineNumber - see the following documentation:

 (lldb) help j Sets the program counter to a new address. This command takes 'raw' input (no need to quote stuff). Syntax: _regexp-jump [<line>] _regexp-jump [<+-lineoffset>] _regexp-jump [<file>:<line>] _regexp-jump [*<addr>] 'j' is an abbreviation for '_regexp-jump' 
+4
source

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.

+1
source

You can move the program counter (pc) to lldb using the lldb register write pc command. But this instruction is based.

Here's a great comparison of lldb / gdb here , which is useful as an overview of lldb.

0
source

Source: https://habr.com/ru/post/1490932/


All Articles