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

时光毁灭记忆、已成空白 提交于 2020-05-28 09:51:47

问题


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).

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?


回答1:


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. You can use --print-bytecode-filter=foo and --print-opt-code-filter=foo if you're only interested in function 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). Optimized code will be generated when a function is "hot", i.e. has spent some time running.




回答2:


You can use bytenode from npm to create an executable for your node app. If you want to read the executable you might use tools like objdump, strace, radare2. You can also open the executable in vim and use the option :%!xxd to get a more human friendly view.



来源:https://stackoverflow.com/questions/58229838/how-to-convert-javascript-code-to-human-readable-opcodes-or-asm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!