Parmanoir

Who'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.


Follow me on Twitter
Planet Cocoa
Cocoa.fr

2010 02 272Core Image black fringes
2010 02 21Quickest Way to Shell
2010 02 08Who's calling ?
2009 09 2128 ways to use Blocks in Snow Leopard
2009 08 182Bracket Mess
2009 08 121Taming JavascriptCore within and without WebView
2009 04 15Debugging with Activity Monitor
2009 03 25How Core Image Color Tracking works
2009 03 158Custom NSThemeFrame
2009 03 10Which framework is running ?
2009 03 074CoreUI can paint pretty big
2009 02 18Localization with functions
2009 01 30Did you forget to nest alloc and init?
2009 01 16JSCocoa on the iPhone
2009 01 11Mixing WebView and JavascriptCore
2009 01 09Badge overflow
2009 01 09Find your Garbage Collection leaks with Instruments
2008 12 19384 percent dynamic
2008 12 151Class pairs and super
2008 12 113Redirecting NSLog to a file

Powered by MediaWiki