简体   繁体   English

如何将 Javascript 代码转换为人类可读的操作码或 asm?

[英]How to convert Javascript code to human-readable opcodes or asm?

As far as I know, Javascript code can either result in JS bytecode or asm instructions (if the internal JIT-compiler was able to convert the code directly to machine instructions).据我所知,Javascript 代码可以生成JS bytecodeasm指令(如果内部 JIT 编译器能够将代码直接转换为机器指令)。

Is there any way to convert Javascript code to human-readable JS byte code (or asm instructions) - depending on how the V8 engine converts it?有什么方法可以将 Javascript 代码转换为人类可读的 JS 字节码(或 asm 指令) - 取决于 V8 引擎如何转换它?

You can run d8 or node with --print-bytecode --print-opt-code to print both bytecode and optimized assembly code to stdout when it is generated.您可以使用--print-bytecode --print-opt-code运行 d8 或 node 以在生成字节码和优化的汇编代码时将其打印到标准输出。 You can use --print-bytecode-filter=foo and --print-opt-code-filter=foo if you're only interested in function foo .如果您只对 function foo感兴趣,可以使用--print-bytecode-filter=foo--print-opt-code-filter=foo foo 。 You will need a debug build, or a release build with v8_enable_disassembler = true in its args.gn (regular release builds don't include the disassembler code in order to save binary size).您将需要一个调试版本,或在其args.gn中使用v8_enable_disassembler = true的发布版本(常规版本版本不包含反汇编代码以节省二进制大小)。 Optimized code will be generated when a function is "hot", ie has spent some time running.当 function 处于“热”状态,即运行了一段时间后,将生成优化代码。

You can use bytenode from npm to create an executable for your node app.您可以使用 npm 中的 bytenode 为您的节点应用程序创建可执行文件。 If you want to read the executable you might use tools like objdump, strace, radare2.如果您想阅读可执行文件,您可以使用 objdump、strace、radare2 等工具。 You can also open the executable in vim and use the option:%.xxd to get a more human friendly view.您还可以在 vim 中打开可执行文件并使用选项:%.xxd 以获得更人性化的视图。

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

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