简体   繁体   English

如何从我的reportError函数中获取SpiderMonkey(JSAPI)中的完整回溯?

[英]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 . 我正在使用spidermonkey在我的应用程序中嵌入javascript,并且我有一个名为reportError的函数,它接收一个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? 获取错误的当前行似乎很简单,但是可以让整个调用路径显示完整的回溯吗?

It's not doable through JSErrorReport. 通过JSErrorReport无法实现。 Instead, you have to look at the debugger APIS. 相反,您必须查看调试器APIS。 Find header jsdbgapi.h. 找到标头jsdbgapi.h。 It has a list of hook functions that will be invoked if you are running with debug enabled(JS_SetDebugMode(cx, true)). 它有一个钩子函数列表,如果你在启用调试的情况下运行它将被调用(JS_SetDebugMode(cx,true))。 Inside those hook functions you could simply call js_DumpBacktrace to get the full stack. 在这些钩子函数中,你可以简单地调用js_DumpBacktrace来获得完整的堆栈。 Note that js_DumpBacktrace would not work if you do not enable debugging first. 请注意,如果您不首先启用调试,则js_DumpBacktrace将不起作用。 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. 它实际上可以获取函数上下文,并且可以获取其参数和本地变量。

可能不是最佳答案,但xpc_printJSStack的实现可能对您有所帮助: httpxpc_printJSStack

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM