1.基础环境
| 环境 | 版本号 |
|---|---|
| MacOS | 12.4 |
| VSCode | 1.88.1 (Universal) |
2.配置步骤
2.1 QuickJS 源码准备
2.1.1 下载源码
git clone https://github.com/bellard/quickjs.git --depth 1
2.1.2 编译源码
cd quickjs
make
2.2 调试环境准备
2.2.1 打开源码
code .
2.2.2 添加 launch.json
cd .vscode
touch launch.json
launch.json 内容如下:
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug QuickJS",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/qjs", // make 执行后生成的可执行文件
"args": [
"${workspaceFolder}/examples/hello.js"
], // 替换为你要调试的 js 文件
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "lldb",
"MIDebuggerPath": "/usr/bin/lldb",
"setupCommands": [
{
"description": "Enable pretty-printing for lldb",
"text": "settings set target.load-script-from-symbol-file true",
"ignoreFailures": true
}
]
}
]
}
2.3 代码调试
2.3.1 添加断点
在 VSCode 页面,找到qjs.c 中的 main 方法,添加断点
2.3.2 启动调试
在运行菜单中找到启动调试即可
效果图:
3. TODO
- 如何同时调试 JS 代码
- 有些基础环境可能已经安装,后续碰到问题继续补充