Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the full backtrace in SpiderMonkey (JSAPI) from my reportError function?

I'm embedding javascript in my app using spidermonkey and I have a function called reportError that receives a JSErrorReport.

It seems simple to grab the current line of the error, but is it possible to get the entire call path to display a full backtrace?

like image 505
Chris Farmiloe Avatar asked Jan 23 '09 14:01

Chris Farmiloe


1 Answers

It's not doable through JSErrorReport. Instead, you have to look at the debugger APIS. Find header jsdbgapi.h. It has a list of hook functions that will be invoked if you are running with debug enabled(JS_SetDebugMode(cx, true)). Inside those hook functions you could simply call js_DumpBacktrace to get the full stack. Note that js_DumpBacktrace would not work if you do not enable debugging first. In debug mode, you could do way more than printing the stack. It's actually possible to get the function context and alls its arguments and local vars.

like image 118
hohohmm Avatar answered Oct 06 '22 00:10

hohohmm