Repository navigation
Conversation
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
left a comment
There was a problem hiding this comment.
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?
143565e to
a88bc15
Compare
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.
a88bc15 to
cd5b430
Compare
jcpetruzza
left a comment
There was a problem hiding this comment.
This is looking good! Let's follow the existing approach for tests and discuss a bit more what the "reset()" call
| 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] | ||
| } | ||
| ), |
There was a problem hiding this comment.
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:
- start a debuggee node, with suitable custom modules
foo1,foo2andfoo3. - start a dap server, configure
?MODULEmodule as language callback, with asource_to_modules()implementation that returnsfoo1andfoo2wheneverbaris given as module - set breakpoints on
bar, on several lines that map to lines infoo1andfoo2only - 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
There was a problem hiding this comment.
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?
6c9a79e to
3c72d4b
Compare
3c72d4b to
d47aecd
Compare
jcpetruzza
left a comment
There was a problem hiding this comment.
The new test looks good!
| Opts0 = [{args, Args}, exit_status, eof, binary, stream, use_stdio], | ||
| Opts = | ||
| case Env of | ||
| [] -> Opts0; | ||
| _ -> [{env, Env} | Opts0] | ||
| end, |
There was a problem hiding this comment.
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
|
@jcpetruzza has imported this pull request. If you are a Meta employee, you can view this in D112366084. |
4b4d16f to
08e4fdd
Compare
|
@jcpetruzza merged this pull request in bdefa19. |
Erlang has a constraint that ensures there is a mapping from filename to module name:
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/0andsource_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: