符号异常断点 - - [NSRangeException raise] [英] Symbolic exception breakpoint on -[NSRangeException raise]

查看:197
本文介绍了符号异常断点 - - [NSRangeException raise]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Xcode中添加一个符号断点为您提供了一个 - [NSException raise] 的示例模板。我想在 - [NSRangeException raise] 上执行相同的操作,但 特别 。原因是我想在特定的数组边界异常处断点 ,例如:

  ***因未捕获异常'NSRangeException'而终止应用程序,原因:'***  -  [__ NSArrayI objectAtIndex:]:index 31超越范围[0 .. 30]'

是的,我知道我可以添加一个捕获所有异常断点。然而,我不想这样做,因为我不想断开整个使用应用程序生成的许多异常。



我尝试了很多基于在与 NSException 相关的其他帖子上。然而,我还没有发现任何成功的工作。



例如,我尝试过:



尽管没有结果:





因此,基本上,问题是,在Xcode中,如何特别指定断点并只在范围异常?

NSRangeException不是类:


grep NSRangeException /System/Library/Frameworks/Foundation.framework/Headers/NSException.h
FOUNDATION_EXPORT NSString * const NSRangeException;




原来,范围异常只是名称为NSRangeException的NSExceptions,即:

 $ 58216恢复
过程58216停止
*线程#1:tid = 0x1d7f4b,函数:objc_exception_throw,停止原因=断点2.1
帧#0:0x00007fff8e3c2e4a libobjc.A.dylib`objc_exception_throw
libobjc.A.dylib`objc_exception_throw:
- > 0x7fff8e3c2e4a:pushq%rbp
0x7fff8e3c2e4b:movq%rsp,%rbp
0x7fff8e3c2e4e:pushq%r15
0x7fff8e3c2e50:pushq%r14
(lldb)bt
* 1:tid = 0x1d7f4b,函数:objc_exception_throw,stop reason =断点2.1
frame#0:0x00007fff8e3c2e4a libobjc.A.dylib`objc_exception_throw
frame#1:0x00007fff841ca1df CoreFoundation` - [__ NSArrayI objectAtIndex:]
帧#2:0x0000000100000eb9范围 - 异常 - [Foo throwIt]范围异常.m:14
帧#3:0x0000000100000f27范围异常`范围-exception.m:22
frame#4:0x00007fff8468d5fd libdyld.dylib`start
frame#5:0x00007fff8468d5fd libdyld.dylib`start
(lldb)expr(NSString *)[((NSException *)$ arg1)name]
(NSString *)$ 0 = 0x00007fff74177990 @NSRangeException

所以你可以在objc_exception_throw上设置一个断点,并编写一个断点条件,将名称与NSRangeException进行比较。例如:

  [(NSString *)[((NSException *)$ arg1)name] isEqual:(NSString *)NSRangeException ] 

应该可以做到。

Adding a symbolic breakpoint in Xcode gives you an example template of -[NSException raise]. I want to do the same thing but specifically on -[NSRangeException raise]. The reason being that I want to breakpoint only on specific array bounds exceptions, for example:

*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 31 beyond bounds [0 .. 30]'

Yes, I know that I can add a catch all exception breakpoint. However, I do not want to do that as I do not want to breakpoint on the many exceptions generated throughout using the app.

I've tried quite a few things based on other posts related to NSException. However, I have not found anything that works successfully as yet.

For example I tried:

This journal entry was also of interest albeit inconclusive:

Dealing with NSArray "out of bounds"

So, basically, the question is, in Xcode, how to breakpoint specifically and only on a range exception?

解决方案

NSRangeException isn't a class:

grep NSRangeException /System/Library/Frameworks/Foundation.framework/Headers/NSException.h FOUNDATION_EXPORT NSString * const NSRangeException;

Turns out, range exceptions are just NSExceptions whose name is NSRangeException, i.e.:

(lldb) b s -n objc_exception_throw
Breakpoint 2: where = libobjc.A.dylib`objc_exception_throw, address = 0x00007fff8e3c2e4a
(lldb) c
Process 58216 resuming
Process 58216 stopped
* thread #1: tid = 0x1d7f4b, function: objc_exception_throw , stop reason = breakpoint 2.1
    frame #0: 0x00007fff8e3c2e4a libobjc.A.dylib`objc_exception_throw
libobjc.A.dylib`objc_exception_throw:
-> 0x7fff8e3c2e4a:  pushq  %rbp
   0x7fff8e3c2e4b:  movq   %rsp, %rbp
   0x7fff8e3c2e4e:  pushq  %r15
   0x7fff8e3c2e50:  pushq  %r14
(lldb) bt 
* thread #1: tid = 0x1d7f4b, function: objc_exception_throw , stop reason = breakpoint 2.1
    frame #0: 0x00007fff8e3c2e4a libobjc.A.dylib`objc_exception_throw
    frame #1: 0x00007fff841ca1df CoreFoundation`-[__NSArrayI objectAtIndex:]
    frame #2: 0x0000000100000eb9 range-exception`-[Foo throwIt] at range-exception.m:14
    frame #3: 0x0000000100000f27 range-exception`main at range-exception.m:22
    frame #4: 0x00007fff8468d5fd libdyld.dylib`start
    frame #5: 0x00007fff8468d5fd libdyld.dylib`start
(lldb) expr (NSString *) [((NSException *) $arg1) name]
(NSString *) $0 = 0x00007fff74177990 @"NSRangeException"

So you could set a breakpoint on objc_exception_throw, and write a breakpoint condition comparing the name to NSRangeException. Something like:

[(NSString *) [((NSException *) $arg1) name] isEqual: (NSString *) NSRangeException]

should do the trick.

这篇关于符号异常断点 - - [NSRangeException raise]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆