没有办法使用 Xcode 断点设置来做到这一点。
您可以在 C++ 异常断点上使用 Python 断点命令在 lldb 中执行此操作。您的回调将查找堆栈到抛出异常的点,并检查抛出的代码是否在您的共享库中,并从断点自动继续。
中的部分:
http://lldb.llvm.org/python-reference.html
在遇到断点时运行脚本将为您提供有关如何执行此操作的一些详细信息。
例如,您可以输入:
module_name = "TheNameOfYourExecutableOrSharedLibrary"
def bkpt_cmd (frame, loc, dict):
global module_name
thread = frame.GetThread()
frame_1 = thread.GetFrameAtIndex(1)
module = frame_1.GetModule()
name = module.GetFileSpec().GetFilename()
if module_name in name:
return True
return False
在一个名为 ~/bkpt_cmd.py 的文件中。然后在 lldb 控制台中,执行:
(lldb) br s -E c++
Breakpoint 1: no locations (pending).
(lldb) command script import ~/bkpt_cmd.py
(lldb) br com add -F bkpt_cmd.bkpt_cmd
这将设置一个 C++ 异常断点,该断点仅在引发框架位于名为“TheNameOfYourExecutableOrSharedLibrary”的共享库中时触发...
顺便说一句,如果您将以下定义放入您的 .py 文件中:
def __lldb_init_module(debugger, internal_dict):
它会在执行command script import 命令时运行,因此您可以使用它一次性将断点和命令添加到断点。我将把它作为练习留给读者。
另请注意,这在 Xcode 中运行 lldb 时会起作用,但您需要创建自己的异常断点,如上所示,因为 Xcode 有不同的方式来处理它管理的断点的命令。