【问题标题】:How to print breakpoint id in lldb如何在 lldb 中打印断点 ID
【发布时间】:2019-06-03 09:59:11
【问题描述】:

如果我使用命令设置了自动继续断点,我怎样才能打印出断点 ID,以便我知道哪个断点正在显示命令。

在下面的列表中我需要

br 命令添加“print brk-id” 27

但是执行此操作的命令是什么,我在文档或 SO 上没有找到它。

    Current breakpoints:
27: regex = 'coordinateReadingItemAtURL', module = Foundation, locations = 28, resolved = 28, hit count = 16 Options: enabled auto-continue
    Breakpoint commands:
      po $rdx

  27.1: where = Foundation`-[NSFileCoordinator coordinateReadingItemAtURL:options:error:byAccessor:], address = 0x00007fff534d2642, resolved, hit count = 3
  27.2: where = Foundation`-[NSFileCoordinator(NSPrivate) _coordinateReadingItemAtURL:options:error:byAccessor:], address = 0x00007fff534d2695, resolved, hit count = 3
  27.3: where = Foundation`__85-[NSFileCoordinator(NSPrivate) _coordinateReadingItemAtURL:options:error:byAccessor:]_block_invoke_2, address = 0x00007fff534d4d44, resolved, hit count = 2
  27.4: where = Foundation`__85-[NSFileCoordinator(NSPrivate) _coordinateReadingItemAtURL:options:error:byAccessor:]_block_invoke.404, address = 0x00007fff534d52bf, resolved, hit count = 2
  27.5: where = Foundation`__73-[NSFileCoordinator coordinateReadingItemAtURL:options:error:byAccessor:]_block_invoke, address = 0x00007fff534d5330, resolved, hit count = 2
  27.6: where = Foundation`__73-[NSFileCoordinator coordinateReadingItemAtURL:options:error:byAccessor:]_block_invoke_2, address = 0x00007fff534d5559, resolved, hit count = 2
  27.7: where = Foundation`__85-[NSFileCoordinator(NSPrivate) _coordinateReadingItemAtURL:options:error:byAccessor:]_block_invoke_2.405, address = 0x00007fff534d60e3, resolved, hit count = 2

【问题讨论】:

    标签: breakpoints lldb


    【解决方案1】:

    我不认为有一个命令会只打印断点ID。我所知道的最接近的是thread info

    br command add -o "thread info"
    

    这将打印一堆数据,断点id在最后:

    thread #1: tid = 0x2220c5, 0x000000010b6cc4dd SomeSDK`-[ABClass method:], queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
    

    此数据由thread-format 设置控制。您可以将默认值更改为更简洁,例如:

    settings set thread-format "thread #${thread.index}{, stop reason = ${thread.stop-reason}}"
    

    这样,thread info 显示:

    thread #1, stop reason = breakpoint 1.1
    

    请记住,此设置在其他地方使用,并且更改可以在其他地方显示。

    最后,您可以求助于 Python API。此命令将打印断点 id:

    br command add -s python -o 'print "{}.{}".format(bp_loc.GetBreakpoint().GetID(), bp_loc.GetID())'
    

    为了解释这一点,Python 断点命令实际上是一个函数,你可以运行break list 来查看 lldb 将如何调用它。其中一个参数是bp_loc,即SBBreakpointLocation。为了打印完整的断点 ID,此代码结合了两个 ID 值:bp_loc.GetBreakpoint().GetID()bp_loc.GetID()

    为了便于重复使用,您可以将其放在某个文件中,例如 helpers.py

    # helpers.py
    def brk_id(frame, bp_loc, internal_dict):
        bp_id = bp_loc.GetBreakpoint().GetID()
        loc_id = bp_loc.GetID()
        print "{}.{}".format(bp_id, loc_id)
    

    然后在您的~/.lldbinit 中像这样导入它:

    command script import path/to/helpers.py
    

    现在你可以轻松使用辅助函数了:

    br command add -F helpers.brk_id
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-15
      • 2014-08-29
      • 2019-04-19
      • 2021-05-27
      • 2013-01-12
      • 1970-01-01
      相关资源
      最近更新 更多