【问题标题】:Move execution point in Xcode/lldb在 Xcode/lldb 中移动执行点
【发布时间】:2013-07-09 22:27:53
【问题描述】:

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

【问题讨论】:

    标签: ios xcode lldb


    【解决方案1】:

    如果您希望通过某种方法将其向上或向下移动,您可以单击绿色箭头并将其拖动到特定点。所以如果你想在断点之前备份一行。单击生成的绿色箭头并将其向上拖动。如果您点击运行,您将再次遇到断点

    【讨论】:

    • 在 Xcode 9.1 中,绿色箭头已更改为绿色汉堡,并移至右边距。
    • 这一定是 Xcode 调试中最酷的鲜为人知的功能。
    • @JerryKrinock 您的评论比投票最多的回复更“最新”。
    【解决方案2】:

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

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

    【讨论】:

      【解决方案3】:

      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 的 Python 命令~/lldb/,然后我将它加载到我的 ~/.lldbinit 文件中

      command script import ~/lldb/jump.py
      

      现在我有一个命令jumpj 有效),它将跳转到给定的行号。例如

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

      如果您将这个新的jump 命令加载到~/.lldbinit 文件中,则此新的jump 命令将在命令行lldb 和Xcode 中可用——您需要使用Xcode 中的调试器控制台窗格来移动PC在编辑器窗口中移动指标。

      【讨论】:

      • 你是如何测试/调试这个脚本的?
      【解决方案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'
      

      【讨论】:

        猜你喜欢
        • 2012-06-27
        • 1970-01-01
        • 1970-01-01
        • 2022-01-23
        • 2017-03-28
        • 2013-06-19
        • 1970-01-01
        • 2016-04-04
        • 1970-01-01
        相关资源
        最近更新 更多