如何在 LLDB 断点条件下使用堆栈内容?

2023-11-22

问题:

我遇到过这样一种情况,我们在启动期间进行媒体播放,并且 objc_exception_throw() 在此期间点击了大约 5 次,但总是被捕获,并且它是way媒体播放器对象的南边。

我厌倦了(a)必须手动继续 n 次,或(b)必须禁用断点直到播放完成。

我尝试过的:

  • 使断点忽略前五次命中(问题:并不总是恰好五次)
  • 使用我的目标作为模块创建我自己的符号断点(问题:没有任何改变)

我想做的事:

我想到的一种解决方案是在断点命中时评估堆栈,如果其中列出了特定方法或函数则继续。但我不知道该怎么做。

也欢迎其他想法。


您可以使用 Python 来完成此操作。

下面定义了一个忽略列表和一个可以作为命令附加到断点的函数。

该函数获取回溯中的函数名称,并将这些名称与忽略列表设置相交。如果有任何名称匹配,它将继续运行该进程。这有效地避免了进入调试器中寻找不需要的堆栈。

(lldb) b objc_exception_throw
Breakpoint 1: where = libobjc.A.dylib`objc_exception_throw, address = 0x00000000000113c5
(lldb) script
Python Interactive Interpreter. To exit, type 'quit()', 'exit()' or Ctrl-D.
>>> ignored_functions = ['recurse_then_throw_and_catch']
def continue_ignored(frame, bp_loc, dict):
    global ignored_functions
    names = set([frame.GetFunctionName() for frame in frame.GetThread()])
    all_ignored = set(ignored_functions)
    ignored_here = all_ignored.intersection(names)
    if len(ignored_here) > 0:
        frame.GetThread().GetProcess().Continue()

quit()

(lldb) br comm add -F continue_ignored 1
(lldb) r

我对以下文件进行了尝试,它成功地跳过了其中的第一个抛出recurse_then_throw_and_catch并在内部抛出期间落入调试器throw_for_real.

#import <Foundation/Foundation.h>

void
f(int n)
{
    if (n <= 0) @throw [NSException exceptionWithName:@"plugh" reason:@"foo" userInfo:nil];

    f(n - 1);
}

void
recurse_then_throw_and_catch(void)
{
    @try {
        f(5);
    } @catch (NSException *e) {
        NSLog(@"Don't care: %@", e);
    }
}

void
throw_for_real(void)
{
    f(2);
}

int
main(void)
{
    recurse_then_throw_and_catch();
    throw_for_real();
}

我想你可以将此功能添加到你的.lldbinit然后根据需要从控制台将其连接到断点。 (我不认为你可以在 Xcode 中设置脚本命令。)

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在 LLDB 断点条件下使用堆栈内容? 的相关文章

随机推荐