debuggingvisual-studio-codeerlangrebar3

How do I debug rebar3 erlang in vscode with the erlang plugin?


I am using the Erlang language plugin for vscode. I created a new rebar3 app and created a simple app that doesnt use a supervisor:

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

I have configured a launch.json file like so:

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

and a tasks.json for the compile:

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

When I hit F5 I get the following output:

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

Does anyone have a clue as to why this isnt working for me?


Solution

  • The problem is in your launch.json. You try to run a function start/0 from module test_app_app and such function does not exist.

    Try to use

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