Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dbg for remote nodes #8692

Merged
merged 1 commit into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 20 additions & 17 deletions lib/runtime_tools/src/dbg.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2346,30 +2346,33 @@ relay(SessionName, Node,To) when Node /= node() ->
-doc false.
do_relay(SessionName, Parent,RelP) ->
process_flag(trap_exit, true),
case RelP of
{Type,Data} ->
{ok,Tracer} = remote_tracer(Type,Data),
Parent ! {started, Tracer, trace:session_create(SessionName, Tracer, [])},
ok;
Pid when is_pid(Pid) ->
Parent ! {started, self(), trace:session_create(SessionName, self(), [])},
ok
end,
do_relay_1(RelP).

do_relay_1(RelP) ->
%% In the case of a port tracer, this process exists only so that
%% dbg know that the node is alive... should maybe use monitor instead?
Tracer =
case RelP of
{Type, Data} ->
{ok, Started} = remote_tracer(Type,Data),
Started;
Pid when is_pid(Pid) ->
self()
end,
Session = trace:session_create(SessionName, Tracer, []),
Parent ! {started, Tracer, Session},
do_relay_1(RelP, Session).

do_relay_1(RelP, Session) ->
%% This process exists to relay messages and keep trace session
%% alive - session is ref-counted locally, meaning just the main
%% node keeping a reference to the session won't prevent the session
%% from being garbage collected.
receive
{'EXIT', _P, _} ->
exit(normal);
TraceInfo when is_pid(RelP) -> % Here is the normal case for trace i/o
RelP ! TraceInfo,
do_relay_1(RelP);
RelP ! TraceInfo,
do_relay_1(RelP, Session);
Other ->
Modifier = modifier(user),
io:format(user,"** relay got garbage: ~"++Modifier++"p~n", [Other]),
do_relay_1(RelP)
do_relay_1(RelP, Session)
end.

-doc false.
Expand Down
9 changes: 5 additions & 4 deletions lib/runtime_tools/test/dbg_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -409,17 +409,18 @@ distributed(Config) when is_list(Config) ->
{value, {matched, Node, 1}} = lists:keysearch(Node, 2, Z),
dbg:cn(Node),
dbg:tp(dbg,ln,[]),
ok = rpc:block_call(Node, dbg, ltp, []),
ok = rpc:block_call(Node, dbg, ln, []),
ok = dbg:ln(),
[ok = rpc:block_call(Node, dbg, ltp, []) || _ <- lists:seq(1,100)],
ok = rpc:block_call(Node, dbg, ln, []),
S = self(),
{TraceSend, TraceCall} =
lists:partition(fun ({trace,RP,send,_,_}) when RP =:= RexPid -> true;
(_) -> false end,
flush()),
[_|_] = TraceSend,
[{trace,Pid,call,{dbg,ltp,[]}},
{trace,S,call,{dbg,ln,[]}}] = TraceCall,
[{trace,S,call,{dbg,ln,[]}} | RemoteCall] = TraceCall,
100 = length(RemoteCall),
[{trace,Pid,call,{dbg,ltp,[]}}] = lists:uniq(RemoteCall),
Node = node(Pid),
%%
stop()
Expand Down
Loading