轻作



重拾写作的乐趣

使用VSCode调试Erlang虚拟机

2020.03.04

图片描述

1. 下载OTP源码

git clone git@github.com:erlang/otp.git && cd otp

2. 配置

./configure --enable-kernel-poll --enable-fips --enable-m64-build --with-dynamic-trace=systemtap

3. 以调试模式编译

make -j "$(grep -c "processor" /proc/cpuinfo)" TYPE=debug FLAVOR=smp 

4. 安装VSCode插件

安装C/C++插件
安装Makefile插件
安装Remote - SSH插件(远程需要)

5. 在OTP根目录建立.vscode文件夹

{
    "version": "2.0.0",
    "configurations": [
        {
            "name": "beam.smp",
            "preLaunchTask": "build",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceRoot}/bin/x86_64-pc-linux-gnu/beam.debug.smp",
            "args": ["--", "-root", "${workspaceRoot}", "-progname", "${workspaceRoot}/bin/cerl", "-debug", "--", "-home", "${HOME}", "--", "-name", "debug@127.0.0.1", "-setcookie", "erlang"],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [{ "name": "BINDIR", "value": "${workspaceRoot}/bin/x86_64-pc-linux-gnu" }],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "enable etp commands",
                    "text": "source ${workspaceRoot}/erts/etc/unix/etp-commands",
                    "ignoreFailures": true
                },
                {
                    "description": "enable pretty print",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}
{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build",
            "type": "shell",
            "command": "make",
            "args": ["TYPE=debug", "FLAVOR=smp"]
        }
    ]
}

6. 按下F5进行调试

  • 在你需要调试的地方打上断点
  • 在终端输入你要调试的命令

图片描述

  • 在调试控制台输入
-exec source 你的OTP绝对路径/erts/etc/unix/etp-commands

启用etp命令

  • 在调试控制台使用etp命令打印变量
-exec etp 参数

图片描述

发表评论