【问题标题】:How do I debug rebar3 erlang in vscode with the erlang plugin?如何使用 erlang 插件在 vscode 中调试 rebar3 erlang?
【发布时间】:2021-12-03 23:30:49
【问题描述】:

我正在为 vscode 使用 Erlang 语言插件。我创建了一个新的 rebar3 应用程序并创建了一个不使用主管的简单应用程序:

-module(test_app_app).

-behaviour(application).

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

start(_StartType, _StartArgs) ->
    load_file("input.txt").

stop(_State) ->
    ok.

load_file(Filename) ->
    case file:read_file(Filename) of
        {ok, Bin} ->
            Bin;
        {error, Reason} ->
            erlang:error(Reason)
    end.

我已经像这样配置了一个 launch.json 文件:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Launch erlang",
            "type": "erlang",
            "request": "launch",
            "cwd": "${workspaceRoot}",
            "arguments": "-s test_app_app start",
            "preLaunchTask": "rebar3 compile"
        }
    ]
}

还有一个用于编译的tasks.json:

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "rebar3 compile",
            "type": "shell",
            "command": "rebar3 compile",
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "problemMatcher": "$erlang"
        }
    ]
}

当我按下 F5 时,我得到以下输出:

compiling erlang bridge to '/home/peter/.vscode/extensions/pgourlain.erlang-0.8.1/_build/default/lib/ebin'
Compiling arguments file  "/tmp/bp_1454870.erl"
Compile result: sucess 
Module bp_1454870 loaded
{"init terminating in do_boot",{undef,[{t
est_app_app,start,[],[]},{init,start_em,1,[]},{init,do_boot,3,[]}]}}
init terminating in do_boot ({undef,[{test_app_app,start,[],[]},{init,start_em,1,[]},{init,do_boot,3,[]}]})

Crash dump is being written to: erl_crash.dump...
done
erl exit code:1
erl exit with code 1

有人知道为什么这对我不起作用吗?

【问题讨论】:

    标签: debugging visual-studio-code erlang rebar3


    【解决方案1】:

    问题出在您的 launch.json 中。您尝试从模块 test_app_app 运行函数 start/0,但该函数不存在。

    尝试使用

    "arguments": "-eval \"application:start(test_app)\""
    

    【讨论】:

    • 非常感谢 :) 这对我有用!所以我之前尝试使用 -s 参数,但没有得到任何结果。 eval 是更好的方法吗?是否有与上述使用-s的等价物?我试过-s application start [] [] before
    • @PeterShort 我认为不可能为此使用-s-s 的 Erlang 文档说我们调用的函数应该是 arity 0 或 arity 1。在后一种情况下,函数应该接受提供的参数作为原子列表。 application:start 不接受原子列表作为参数。
    猜你喜欢
    • 2022-10-01
    • 1970-01-01
    • 2020-12-22
    • 2020-11-15
    • 2017-05-12
    • 2020-04-05
    • 2021-08-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多