views:

189

answers:

2

I don't like real-time debugging much, but if it's necessary I'll do it.

Is there any way to figure out what line of code a StackTrace in Objective-C refers to? What about the variable it refers to? For instance:

2010-05-13 19:39:11.673 Thingers[21003:207] *** -[NSCFString count]: unrecognized selector sent to instance 0x3b0ebb0
2010-05-13 19:39:11.674 Thingers[21003:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSCFString count]: unrecognized selector sent to instance 0x3b0ebb0'
2010-05-13 19:39:11.675 Thingers[21003:207] Stack: (
    29303899
    ...
    11130
)

I see that we're talking about sending a count message to something that doesn't have it (maybe it's a NSCFString?), but is there any way to figure out what a/the named reference to that instance (0x3b0ebb0) refers to?

+4  A: 
KennyTM
Thanks, that helps. Although this this case I really am sending a `count` message to an object that doesn't have that selector, it's good to know that NSZombie exists.
Yar
@yar: Oh. Don't ignore the compiler warnings :).
KennyTM
A: 

I just came back to my own question after a while and wanted to add this answer: the thing that you get in the log is NOT the stacktrace. Those numbers actually refer to something. If you run the "Debugger" from XCode (control shift Y) you get meaningful traces like this

#0  0x997dfef6 in __kill
#1  0x997dfee8 in kill$UNIX2003
#2  0x9987262d in raise
#3  0x998886e4 in abort
#4  0x93272fda in __gnu_cxx::__verbose_terminate_handler
#5  0x02cc661c in _objc_terminate
#6  0x9327117a in __cxxabiv1::__terminate
#7  0x932711ba in std::terminate
#8  0x932712b8 in __cxa_throw
#9  0x02cc63d8 in objc_exception_throw
#10 0x02b6b70b in +[NSException raise:format:arguments:]
#11 0x02b6b66a in +[NSException raise:format:]
#12 0x00008388 in -[ControlWrapper makeBig] at ControlWrapper.m:83
#13 0x0000824f in -[ControlWrapper setHighlighting:] at ControlWrapper.m:65
#14 0x00008ade in -[ControlWrapper touchesBegan:withEvent:] at ControlWrapper.m:147
#15 0x00008a46 in -[ControlWrapper touchesBegan:withEvent:] at ControlWrapper.m:139
#16 0x005c376b in forwardMethod2
#17 0x0079caad in _UIGestureRecognizerUpdateObserver
#18 0x02b2ea52 in __CFRunLoopDoObservers
#19 0x02afb345 in CFRunLoopRunSpecific
#20 0x02afa8a8 in CFRunLoopRunInMode
#21 0x0311e89d in GSEventRunModal
#22 0x0311e962 in GSEventRun
#23 0x0051a372 in UIApplicationMain
#24 0x00002964 in main at main.m:14

This will take you to the exact line of offending code.

Note: You have to have breakpoints on for this to work, which will unfortunately turn your breakpoints on :)

Yar