如何在VS Code中调试Erlang程序

问题描述

我正在学习Erlang。据我所知,有一个名为 rebar3 的工具可以生成项目样板。好的,所以在安装之后,我将生成一个空项目,如下所示:

$ rebar3 new umbrella myproj

甜。现在,我打开安装了Erlang extension的VS Code。按照文档中的说明,我添加一个 launch.json 文件

{
  // Use IntelliSense to learn about possible attributes.
  // Hover to view descriptions of existing attributes.
  // For more @R_187_4045@ion,visit: https://go.microsoft.com/fwlink/?linkid=830387
  "version": "0.2.0","configurations": [        
    {
      "name": "Launch erlang","type": "erlang","request": "launch","cwd": "${workspaceRoot}","prelaunchTask": "rebar3 compile"
    }
  ]
}

然后,我添加一个 tasks.json 文件

{
  // See https://go.microsoft.com/fwlink/?LinkId=733558
  // for the documentation about the tasks.json format
  "version": "2.0.0","tasks": [
    {
      "label": "rebar3 compile","type": "shell","command": "rebar3 compile","group": {
        "kind": "build","isDefault": true
      },"problemmatcher": "$erlang"
    }
  ]
}

然后,我在 myproj_app.erl 文件中设置一个断点:

%%%-------------------------------------------------------------------
%% @doc myproj public API
%% @end
%%%-------------------------------------------------------------------

-module(myproj_app).

-behavIoUr(application).

-export([start/2,stop/1]).

start(_StartType,_StartArgs) ->
    io:format("Hello,world!~n"),%<-- BREAKPOINT
    myproj_sup:start_link().

stop(_State) ->
    io:format("Hello,ok.

%% internal functions

我按F5键,调试器将启动,但它永远不会停止。这是输出

> Executing task: rebar3 compile <

===> Verifying dependencies...
===> Analyzing applications...
===> Compiling myproj

Terminal will be reused by tasks,press any key to close it.

Compiling arguments file  "/tmp/bp_2863283.erl"
Compile result: sucess 
Module bp_2863283 loaded

如果我添加以下行:

"arguments": "-config dev -s sample"

对于 launch.json 文件,它给我一个错误,并且无法启动。而且我很确定那些不是我要传递给负责启动我的程序的参数。输出为:

{
"
c
o
u
l
d

n
o
t

s
t
a
r
t
 kernel pid",application_controller,"error in config file \"./dev.config\" (none): configuration file not found"}
c
o
u
l
d

n
o
t

s
t
a
r
t

k
e
r
n
e
l

p
id (application_controller) (error in config file "./dev.config" (none): configuration file not found)

Crash dump is being written to: erl_crash.dump...
d
o
n
e


erl exit code:1
erl exit with code 1

如何配置VS Code进行调试?缺少什么?

解决方法

我是 Erlang 的新手,遇到了同样的问题……显然,启动调试会话并不会启动您的程序,而只会启动带有调试标志的 elang shell,您可以在其中启动任何模块:function(args) you调试很有趣。请注意,调试控制台窗口有“>”提示,您可以在其中调用它。因此,在您的具体示例中,我将使用“myproj_app:start(1,2)”。 args 并不重要,因为它们没有被使用。一旦进入