如果我使用命令设置了自动继续断点,那么我如何也可以打印出断点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
答案 0 :(得分: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