9

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?

Mistalis
  • 17,793
  • 13
  • 73
  • 97
Chris Farmiloe
  • 13,935
  • 5
  • 48
  • 57

2 Answers2

1

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.

hohohmm
  • 197
  • 1
  • 12
0

Might not be the best answer, but the implementation of xpc_printJSStack may be helpful to you: http://mxr.mozilla.org/mozilla-central/source/js/xpconnect/src/XPCDebug.cpp#255

Jonathan Protzenko
  • 1,709
  • 8
  • 13