Skip to content

Commit

Permalink
[DAP] Notify client when a process terminates (erlang-ls#1435)
Browse files Browse the repository at this point in the history
  • Loading branch information
robertoaloi authored Jun 1, 2023
1 parent 7ed288b commit e315f98
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
9 changes: 8 additions & 1 deletion apps/els_dap/src/els_dap_agent.erl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@

-spec int_cb(pid(), pid()) -> ok.
int_cb(Thread, ProviderPid) ->
ProviderPid ! {int_cb, Thread},
case lists:keyfind(Thread, 1, int:snapshot()) of
{_Pid, _Function, break, _Info} ->
ProviderPid ! {int_cb, Thread};
{_Pid, _Function, 'exit', _Info} ->
ProviderPid ! {int_cb_exit, Thread};
_ ->
ok
end,
ok.

-spec meta_eval(pid(), string()) -> any().
Expand Down
11 changes: 8 additions & 3 deletions apps/els_dap/src/els_dap_general_provider.erl
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ handle_request(
%% TODO: Fetch stack_trace mode from Launch Config
els_dap_rpc:stack_trace(ProjectNode, all),
MFA = {els_dap_agent, int_cb, [self()]},
els_dap_rpc:auto_attach(ProjectNode, [break], MFA),
els_dap_rpc:auto_attach(ProjectNode, ['break', 'exit'], MFA),

case LaunchParams of
#{
Expand Down Expand Up @@ -320,15 +320,15 @@ handle_request(

{#{<<"breakpoints">> => BreakpointsRsps}, State#{breakpoints => Breakpoints2}};
handle_request({<<"threads">>, _Params}, #{threads := Threads0} = State) ->
Threads =
ThreadsResp =
[
#{
<<"id">> => Id,
<<"name">> => format_term(Pid)
}
|| {Id, #{pid := Pid} = _Thread} <- maps:to_list(Threads0)
],
{#{<<"threads">> => Threads}, State};
{#{<<"threads">> => ThreadsResp}, State#{threads => Threads0}};
handle_request({<<"stackTrace">>, Params}, #{threads := Threads} = State) ->
#{<<"threadId">> := ThreadId} = Params,
Thread = maps:get(ThreadId, Threads),
Expand Down Expand Up @@ -692,6 +692,11 @@ handle_info(
mode => Mode1,
hits => Hits1
};
handle_info({int_cb_exit, ThreadPid}, #{threads := Threads} = State) ->
?LOG_DEBUG("int_cb_exit called. thread=~p", [ThreadPid]),
Params = #{<<"reason">> => <<"exited">>, <<"threadId">> => id(ThreadPid)},
els_dap_server:send_event(<<"thread">>, Params),
State#{threads => maps:remove(id(ThreadPid), Threads)};
handle_info({nodedown, Node}, State) ->
%% the project node is down, there is nothing left to do then to exit
?LOG_NOTICE("project node ~p terminated, ending debug session", [Node]),
Expand Down

0 comments on commit e315f98

Please sign in to comment.