Symbolic exception breakpoint on -[NSRangeException raise]

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-05 21:33:58
Jim Ingham

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.

inorganik

To make a breakpoint for NSRangeException, use an Exception breakpoint. It's one of the options when you click the "+" in the breakpoint navigator. Found this info from this answer: https://stackoverflow.com/a/9718552/591487

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!