在Xcode / lldb中移动执行点

时间:2013-07-11 15:04:08

标签: ios xcode lldb

有没有办法在调试Xcode / lldb时设置执行点?更具体地说,在点击断点后,手动将执行点移动到另一行代码?

4 个答案:

答案 0 :(得分:12)

如果您正在查看使用方法向上或向下移动它,可以单击并将绿色箭头拖动到特定点。所以如果你想在断点之前备份一行。单击生成的绿色箭头并将其向上拖动。如果你跑了,你会再次击中你的断点

答案 1 :(得分:4)

在Xcode 6中,您可以使用j lineNumber - 请参阅以下文档:

(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'

答案 2 :(得分:1)

关于lldb的一个好处是,通过一些python脚本来扩展它很容易。例如,我把一个新的jump命令拼凑起来没有太多麻烦:

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__)

我把它放在一个目录中,我保存lldb,~/lldb/的Python命令,然后我将它加载到我的~/.lldbinit文件中

command script import ~/lldb/jump.py

现在我有一个命令jumpj工作),它将跳转到给定的行号。 e.g。

(lldb) j 5
PC has been set to 0x100000f0f for a.c:5
(lldb)

如果你在jump文件中加载它,那么在命令行lldb和Xcode中都可以使用这个新的~/.lldbinit命令 - 你需要使用Xcode中的调试器控制台窗格来移动电脑,而不是在编辑器窗口中移动指示器。

答案 3 :(得分:0)

您可以使用lldb命令register write pc在lldb中移动程序计数器(pc)。但它是基于指令的。

有一个很好的lldb / gdb比较here,可用作lldb概述。