简体   繁体   English

如何独立运行v8引擎并使用Chrome DevTools进行调试

[英]How do I run a v8 engine standalone and debug with Chrome DevTools

I built a v8 binary for my platform (MacOS). 我为我的平台(MacOS)构建了一个v8二进制文件。

I could start a v8 shell by executing that binary and run arbitrary JS code. 我可以通过执行该二进制文件并运行任意JS代码来启动v8 shell。

bash-$ ./v8
v8> var foo = 42
v8> 42

What I want is to somehow use chrome devtools as the debugging front-end for this v8 instance, like how I can use devtools for remote-debugging another chrome instance. 我想要的是以某种方式使用chrome devtools作为这个v8实例的调试前端,就像我可以使用devtools来远程调试另一个chrome实例。

To put simply, something like this 简而言之,这样的事情

bash-$ ./v8 --remote-debugging-port=9222

Since NodeJS already has good support for Chrome DevTools, I forked NodeJS and tweaked it to run my code in vanilla V8 environment. 由于NodeJS已经对Chrome DevTools提供了很好的支持,我将NodeJS分叉并调整它以在vanilla V8环境中运行我的代码。

Build my fork: https://github.com/joelewis/node 构建我的分支: https//github.com/joelewis/node

Then run the binary: 然后运行二进制文件:

$ /out/Debug/node --inspect --inspect-brk mycode.js

This will open Chrome DevTools window with a breakpoint in the first line of mycode.js. 这将打开Chrome DevTools窗口,在mycode.js的第一行有一个断点。 In this environment there's no NodeJS globals (like require, exports, module). 在这种环境中,没有NodeJS全局变量(如require,exports,module)。 It's a pure V8 environment! 这是一个纯粹的V8环境!

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

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