So I was recently trying to track down a bug in an Adobe AIR application that we've been working on for the past year. Needless to say the application is pretty big and I had isolated the bug to a particular function. The problem is that I needed to know what other function was calling it when the error was being encountered and that could have been a couple dozen locations.
Here's a nice little code snippet that I placed in the buggy function to see who was calling it:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
var stackTrace:String; try { throw new Error(); } catch (e:Error) { stackTrace = e.getStackTrace(); } var lines:Array = stackTrace.split("\n"); var isDebug:Boolean = (lines[1] as String).indexOf('[') != -1; var path:String; var line:int = -1; if(isDebug) { var regex:RegExp = /at\x20(.+?)\[(.+?)\]/i; var matches:Array = regex.exec(lines[2]); path = matches[1]; //file:line = matches[2] //windows == 2 because of drive:\ line = matches[2].split(':')[2]; } else { path = (lines[2] as String).substring(4); } trace("\n\n\nmyFunction(" + $animTime + ", " + $scaleMultipler + ", " + (($options == null)? "options=null" : "options={...}" ) + ");"); trace("myFunction caller: " + path + (line != -1 ? '[' + line.toString() + ']' : '') + "\n\n\n"); |