用节点检查器debuggingV8

我正在尝试使用节点检查器来debugging在V8中运行的JavaScript脚本。 在应用程序方面,我刚刚做到了

v8::Debug::EnableAgent("MyApp", 5858); 

节点检查器连接良好,甚至可以暂停/取消暂停和显示代码。 但是,逐步执行不起作用,既不是断点,也可能是其他许多事情。 当我尝试做这样的事情时,我从Node-inspector得到这些错误:

 Node Inspector v0.7.0 Visit http://127.0.0.1:8080/debug?port=5858 to start debugging. Received request for a method not implemented: Debugger.setSkipAllPauses Received request for a method not implemented: Debugger.setSkipAllPauses Received request for a method not implemented: Debugger.setSkipAllPauses Received request for a method not implemented: Debugger.setBreakpoint Received request for a method not implemented: Debugger.setBreakpoint Received request for a method not implemented: Debugger.setBreakpoint 

所以我想我错过了一些东西。

我不知道我试图做什么甚至支持 – 因为我猜,node-inspector是为了Node.js,而不是任意的V8,对不对? 如果是这样的话,需要做些什么才能使其工作?


感谢米罗斯拉夫的帮助,特别是 运行DEBUG=node-inspector:protocol:* node-inspector ,我有点进一步了。 逐步执行现在可以工作,大多数情况下,断点都可以执行(除非select错误的源文件 – 请参阅下文)。

我提供了一个像这样的全局process对象:

 // process object: http://nodejs.org/api/process.html#process_process process.stdout = ... process.stderr = ... process._baseDir = ... process.mainModule = {filename: process._baseDir + "/main.js"} process.argv = ["myapp.exe", process.mainModule.filename] process.cwd = function() { return process._baseDir; } 

现在我得到了错误Internal error: TypeError: Cannot read property 'line' of null控制台Internal error: TypeError: Cannot read property 'line' of null 。 在节点检查器,我得到这个:

 Wed, 19 Mar 2014 11:58:43 GMT node-inspector:protocol:v8-debug request: {"seq":170,"type":"request","command":"backtrace","arguments":{"inlineRefs":true,"fromFrame":0,"toFrame":50,"maxStringLength":10000}} Wed, 19 Mar 2014 11:58:43 GMT node-inspector:protocol:devtools frontend: {"method":"Debugger.setOverlayMessage","id":48} Wed, 19 Mar 2014 11:58:43 GMT node-inspector:protocol:devtools backend: {"id":48} Wed, 19 Mar 2014 11:58:43 GMT node-inspector:protocol:v8-debug response: {"seq":41,"request_seq":170,"type":"response","success":false,"message":"Internal error: TypeError: Cannot read property 'line' of null"} 

另一件事是脚本文件并不总是正确的。 在C ++端,我现在加载它们:

 ReturnType execJsFile(const std::string& jsSourceDir, const std::string& extfilename) { v8::TryCatch try_catch; std::string fullfilename = jsSourceDir + "/" + extfilename; std::string sourceStr; CHECK_RETURN(readFile(fullfilename, sourceStr)); // The origin is for the debugger, eg node-inspector. It expects an URL. Local<String> origin = jsStr("file:///" + fullfilename); Local<String> source = jsStr(sourceStr); Local<v8::Script> script = Script::Compile(source, origin); if(script.IsEmpty()) { assert(try_catch.HasCaught()); return "JS compile failed: " + jsReportExceptionToString(Isolate::GetCurrent(), &try_catch);; } Local<Value> result = script->Run(); if(result.IsEmpty()) { assert(try_catch.HasCaught()); return "JS script execution failed: " + jsReportExceptionToString(Isolate::GetCurrent(), &try_catch); } return true; } 

这将所有文件放在源列表中的file://域下。 但是, main.js(no domain)下获得额外的条目。 当我做出改变

 process.mainModule = {filename: "file:///" + process._baseDir + "/main.js"} 

它消失了,但是,这不是我如何根据文件预计。

当我在main.js中暂停/中断执行时,它会在另一个Source [VM] main.js并获得一个黄色的背景。

另外,在源file://下的所有文件file://获取(function (exports, require, module, __filename, __dirname) {前缀在源代码的第一行中添加,该行不是来自我的代码,而是来自节点检查器为什么在这里添加?这是特别奇怪的,因为我的代码添加了一个稍微不同的前缀( function(module, exports) {

运行DEBUG=node-inspector:protocol:* node-inspector并检查这些消息,你可以在这里find更多的信息。 您也可以尝试使用旧版本,例如0.1.9,它可能对节点特定的东西依赖性较less。

我说95%的Node Inspector代码只使用V8协议。 查找DebuggerClient.prototype.evaluateGlobal用法,以查找使用节点特定function的位置。

首先要改变的是lib/PageAgent.js getResourceTree 。 要么实现自己的方式列出所有的源文件(包括尚未加载),或返回一个空树。

UPDATE

首先尝试Node的CLIdebugging器:

 $ node debug localhost:5858 

据我所知,CLIdebugging器只使用V8debugging器协议function,没有任何特定的节点。 当您可以使用CLIdebugging您的V8应用程序时,您将会知道任何其他问题都在Node Inspector中,而不是在您的V8应用程序中。

这是一个用node-inspectordebuggingV8的解决scheme:

首先,最新的版本(0.12.3)有很多扩展来debuggingnode.js脚本,所以我使用了一个旧版本(0.5.0),它对node.js的负担较小。

我使用以下命令在Node.js命令提示符下安装v0.5.0:

 npm install node-inspector@0.5.0 

它默认安装在文件夹“%USERPROFILE%\ node_modules”中。

我向%USERPROFILE%\ node_modules \ node-inspector \ lib \ PageAgent.js添加了一行代码:

 getResourceTree: function(params, done) { return; //return empty tree ... 

这完成了安装。

以下是debugging使用ClearScript .NET库执行的JavaScript文件的指南:

打开命令提示符并执行以下命令:

%USERPROFILE%\ node_modules \的.bin \节点inspector.cmd

如果node-inspector正在成功运行,您应该看到以下几行。

 Node Inspector v0.5.0 info - socket.io started Visit http://127.0.0.1:8080/debug?port=5858 to start debugging. 

按照以下代码行(VB.NET代码)初始化您的V8引擎:

昏暗的引擎作为新的V8ScriptEngine(“全球”,V8ScriptEngineFlags.EnableDebugging,9222)

在代码的这一行之后放置一个断点,并运行应用程序以达到此断点。

确保你有“debugging器” 您的JavaScript代码的第一行中的语句。

打开Chrome浏览器并导航至以下地址:

http://127.0.0.1:8080/debug?port=9222

按VİsualStudio工具栏中的“继续debugging”button。

现在你应该看到你的脚本代码停在第一个“debugging器”上 在Chrome浏览器中运行。

你可以从这里继续debugging。