Skip to content

Support a configurable language module - #21

Closed
Gazler wants to merge 5 commits into
WhatsApp:mainfrom
Gazler:feat/edb_dap_language
Closed

Gazler wants to merge 5 commits into
WhatsApp:mainfrom
Gazler:feat/edb_dap_language

Conversation

@Gazler

@Gazler Gazler commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Erlang has a constraint that ensures there is a mapping from filename to module name:

foo.erl => -module(foo)
bar.erl => -module(bar)

This makes looking up a module based on a path name deterministic. This is not the case in other BEAM languages such as Elixir. In Elixir, there is no mapping between the file name and the module name. It is also possible for an Elixir file to contain multiple modules.

In order to allow edb to be used in Elixir, we need a way to configure the mapping from path to module. However, instead of baking in support just for Elixir, it would be ideal to have this be generic.

This commit introduces a configurable module which can be provided as start options for edb. This is implemented with a behaviour, and a default erlang implementation is provided which is just the code that previously existed. The behaviour implements init/0 and source_to_modules/3.

To allow passing this option through, the application config is required to be set before starting edb. This is should be handled by the caller.

The intention here, is for other languages to wrap edb with their own escript which provides a language implementation.

For example, an Elixir wrapper can use:

defmodule EdbElixir.CLI do
  @moduledoc false

  def main(args) do
    Application.put_env(:edb, :dap_language, EdbElixir.DapLanguage)
    :edb_main.main(args)
  end
end

Erlang has a constraint that ensures there is a mapping from filename to
module name:

```
foo.erl => -module(foo)
bar.erl => -module(bar)
```

This makes looking up a module based on a path name deterministic. This
is not the case in other BEAM languages such as Elixir. In Elixir, there
is no mapping between the file name and the module name. It is also
possible for an Elixir file to contain multiple modules.

In order to allow edb to be used in Elixir, we need a way to configure
the mapping from path to module. However, instead of baking in support
just for Elixir, it would be ideal to have this be generic.

This commit introduces a configurable module which can be provided as
start options for edb. This is implemented with a behaviour, and a
default erlang implementation is provided which is just the code that
previously existed. The behaviour implements `init/0` and
`source_to_modules/3`.

To allow passing this option through, the application config is required
to be set before starting edb. This is should be handled by the caller.

The intention here, is for other languages to wrap edb with their own
escript which provides a language implementation.

For example, an Elixir wrapper can use:

```
defmodule EdbElixir.CLI do
  @moduledoc false

  def main(args) do
    Application.put_env(:edb, :dap_language, EdbElixir.DapLanguage)
    :edb_main.main(args)
  end
end
```

@jcpetruzza jcpetruzza left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry it too me a bit long to look into this. It looks good. If we can move the language-callback handling outside of the main server, I think it would be much cleaner. Wdyt?

Comment thread apps/edb/src/edb_dap_language.erl Resolved
Comment thread apps/edb/src/edb_dap_language.erl Resolved
Comment thread apps/edb/src/edb_dap_language.erl Resolved
Comment thread apps/edb/src/edb_dap_language.erl Resolved
Comment thread apps/edb/src/edb_dap_language.erl Resolved
@Gazler
Gazler force-pushed the feat/edb_dap_language branch 5 times, most recently from 143565e to a88bc15 Compare July 8, 2026 11:00
The language module is now started as a genserver which is in charge of
its own state. This means that we don't need to thread it throughout the
existing edb server, which makes the code easier to parse and
understand.
@Gazler
Gazler force-pushed the feat/edb_dap_language branch from a88bc15 to cd5b430 Compare July 8, 2026 11:03
@Gazler
Gazler requested a review from jcpetruzza July 8, 2026 11:08

@jcpetruzza jcpetruzza left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking good! Let's follow the existing approach for tests and discuss a bit more what the "reset()" call

Comment thread apps/edb/src/edb_dap_language.erl Resolved
Comment thread apps/edb/src/edb_dap_language.erl Resolved
Comment thread apps/edb/src/edb_dap_language.erl Resolved
Comment on lines +77 to +85
application:set_env(edb, dap_language_test_state, DapLanguageState0),
ok = edb_dap_language:reset(),
Reaction = edb_dap_request_set_breakpoints:handle(
#{state => attached},
#{
source => #{path => SourcePath},
breakpoints => [#{line => Line} || Line <- BreakpointLines]
}
),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are trying to avoid this type of low-level "unit" tests as they are only checking/poking internal APIs that could change at any point, and instead go straight to "integration" tests, where we start a DAP server and perform some interactions and assert only on user-visible results. Could we do that here as well?

In particular, this test is also not exercising the non-trivial logic where the callback returns more than one module. So I'd propose that we replace this test by something like this:

  1. start a debuggee node, with suitable custom modules foo1, foo2 and foo3.
  2. start a dap server, configure ?MODULE module as language callback, with a source_to_modules() implementation that returns foo1 and foo2 whenever bar is given as module
  3. set breakpoints on bar, on several lines that map to lines in foo1 and foo2 only
  4. assert on the result, and verify the breakpoints are set by running some code on the debuggee and checking the breakpoints are hit

Let's make sure we cover the cases where a requested line is in both foo1 and foo2, where it is only in one, and where it is in none

Check for example the tests for set-breakpoints, that could be used as reference

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tried to cover all of the above cases in a single integration test. I had to set the ERL_AFLAGS for both the debuggee and the server to ensure they didn't conflict. Please can you confirm if this is the type of test you had in mind?

@Gazler
Gazler force-pushed the feat/edb_dap_language branch from 6c9a79e to 3c72d4b Compare July 8, 2026 13:03
@Gazler
Gazler requested a review from jcpetruzza July 8, 2026 13:12
@Gazler
Gazler force-pushed the feat/edb_dap_language branch from 3c72d4b to d47aecd Compare July 8, 2026 13:15

@jcpetruzza jcpetruzza left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new test looks good!

Comment thread apps/edb/test/edb_dap_test_client.erl Outdated
Comment on lines +195 to +200
Opts0 = [{args, Args}, exit_status, eof, binary, stream, use_stdio],
Opts =
case Env of
[] -> Opts0;
_ -> [{env, Env} | Opts0]
end,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: no need for the special case, just add {env, Env} unconditionally to the list of Opts, a open_port() just extends the environment with

@meta-codesync

meta-codesync Bot commented Jul 16, 2026

Copy link
Copy Markdown

@jcpetruzza has imported this pull request. If you are a Meta employee, you can view this in D112366084.

Comment thread apps/edb_core/test/edb_test_support.erl Resolved
@Gazler
Gazler force-pushed the feat/edb_dap_language branch from 4b4d16f to 08e4fdd Compare July 17, 2026 11:57
@Gazler
Gazler requested a review from jcpetruzza July 17, 2026 11:59
@meta-codesync meta-codesync Bot closed this in bdefa19 Jul 17, 2026
@meta-codesync meta-codesync Bot added the Merged label Jul 17, 2026
@meta-codesync

meta-codesync Bot commented Jul 17, 2026

Copy link
Copy Markdown

@jcpetruzza merged this pull request in bdefa19.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants