2010 02 08Who's calling ?
NSThread's callStackSymbols will dump the call stack in an array. What is usually the realm of gdb, callStackSymbols will do at runtime.
Here's how it looks called during awakeFromNib :
0 MyApp -[MyAppDelegate awakeFromNib] + 44 1 CoreFoundation -[NSSet makeObjectsPerformSelector:] + 205 2 AppKit -[NSIBObjectData nibInstantiateWithOwner:topLevelObjects:] + 1445 3 AppKit loadNib + 226 4 AppKit +[NSBundle(NSNibLoading) _loadNibFile:nameTable:withZone:ownerBundle:] + 248 5 AppKit +[NSBundle(NSNibLoading) loadNibNamed:owner:] + 326 6 AppKit NSApplicationMain + 279
When are bindings calling your code ? Walk up the callstack and look for NSBinder :
0 MyApp -[MyAppDelegate setSliderValue:] + 67 1 Foundation _NSSetIntValueAndNotify + 256 2 Foundation -[NSObject(NSKeyValueCoding) setValue:forKey:] + 434 3 Foundation -[NSObject(NSKeyValueCoding) setValue:forKeyPath:] + 240 4 AppKit -[NSBinder _setValue:forKeyPath:ofObject:mode:validateImmediately:raisesForNotApplicableKeys:error:] + 264 5 AppKit -[NSBinder setValue:forBinding:error:] + 266 6 AppKit -[NSValueBinder _applyObjectValue:forBinding:canRecoverFromErrors:handleErrors:typeOfAlert:discardEditingCallback:otherCallback:callbackContextInfo:didRunAlert:] + 197 7 AppKit -[NSValueBinder applyDisplayedValueHandleErrors:typeOfAlert:canRecoverFromErrors:discardEditingCallback:otherCallback:callbackContextInfo:didRunAlert:] + 567 8 AppKit -[NSValueBinder performAction:] + 300 9 AppKit -[_NSBindingAdaptor _objectDidTriggerAction:bindingAdaptor:] + 136 10 AppKit -[NSControl sendAction:to:] + 63 11 AppKit -[NSCell trackMouse:inRect:ofView:untilMouseUp:] + 1715 12 AppKit -[NSSliderCell trackMouse:inRect:ofView:untilMouseUp:] + 1053 13 AppKit -[NSControl mouseDown:] + 624 14 AppKit -[NSWindow sendEvent:] + 5409 15 AppKit -[NSApplication sendEvent:] + 4719 16 AppKit -[NSApplication run] + 474 17 AppKit NSApplicationMain + 364
Writing recursive code and stuck with a method definition that does not specify the recursion depth ? Count how many times the method appears in the call stack.
If you have a dummy NSLog that you want gone but can't find among the legit ones, add this to your precompiled header :
#define NSLog(args...) NSLog(args), NSLog(@"%@", [NSThread callStackSymbols])It will call the original
NSLog and pinpoint the offending function.