Skip to content

Commit 04afeaa

Browse files
authored
Merge pull request erlang#9399 from lukaszsamson/ls-fix-int-crash
Handle load_binary result in debugger int:load OTP-19484
2 parents f4f2d1a + 09a1a60 commit 04afeaa

File tree

1 file changed

+49
-20
lines changed

1 file changed

+49
-20
lines changed

lib/debugger/src/int.erl

Lines changed: 49 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -866,28 +866,57 @@ check(Mod) when is_atom(Mod) -> catch check_module(Mod);
866866
check(File) when is_list(File) -> catch check_file(File).
867867

868868
load({Mod, Src, Beam, BeamBin, Exp, Abst}, Dist) ->
869-
_ = everywhere(Dist,
870-
fun() ->
871-
code:purge(Mod),
872-
erts_debug:breakpoint({Mod,'_','_'}, false),
873-
{module,Mod} = code:load_binary(Mod, Beam, BeamBin)
874-
end),
875-
case erl_prim_loader:read_file(filename:absname(Src)) of
876-
{ok, SrcBin} ->
877-
MD5 = code:module_md5(BeamBin),
878-
SrcBin1 = unicode:characters_to_binary(SrcBin, enc(SrcBin)),
879-
true = is_binary(SrcBin1),
880-
Bin = term_to_binary({interpreter_module,Exp,Abst,SrcBin1,MD5}),
881-
{module, Mod} = dbg_iserver:safe_call({load, Mod, Src, Bin}),
882-
_ = everywhere(Dist,
883-
fun() ->
884-
true = erts_debug:breakpoint({Mod,'_','_'}, true) > 0
885-
end),
886-
{module, Mod};
887-
error ->
888-
error
869+
RawLoadResult = everywhere(Dist,
870+
fun() ->
871+
code:purge(Mod),
872+
erts_debug:breakpoint({Mod, '_', '_'}, false),
873+
code:load_binary(Mod, Beam, BeamBin)
874+
end),
875+
LoadResult = extract_result(RawLoadResult),
876+
case LoadResult of
877+
{module, Mod} ->
878+
case erl_prim_loader:read_file(filename:absname(Src)) of
879+
{ok, SrcBin} ->
880+
MD5 = code:module_md5(BeamBin),
881+
SrcBin1 = unicode:characters_to_binary(SrcBin, enc(SrcBin)),
882+
true = is_binary(SrcBin1),
883+
Bin = term_to_binary({interpreter_module, Exp, Abst, SrcBin1, MD5}),
884+
{module, Mod} = dbg_iserver:safe_call({load, Mod, Src, Bin}),
885+
_ = everywhere(Dist,
886+
fun() ->
887+
true = erts_debug:breakpoint({Mod, '_', '_'}, true) > 0
888+
end),
889+
{module, Mod};
890+
error ->
891+
error
892+
end;
893+
{error, _} ->
894+
error;
895+
{badrpc, _} ->
896+
error
889897
end.
890898

899+
extract_result({Results, _BadNodes}) when is_list(Results) ->
900+
%% In distributed mode, rpc:multicall returns {Results, BadNodes}.
901+
%% Look for any successful result in the list.
902+
case lists:filter(fun
903+
({module, _}) -> true;
904+
(_) -> false
905+
end, Results) of
906+
[] ->
907+
%% No node succeeded; return the first result from Results,
908+
%% which should be an error tuple or badrpc tuple.
909+
case Results of
910+
[First | _] -> First;
911+
[] -> error
912+
end;
913+
[Success | _] ->
914+
Success
915+
end;
916+
extract_result(Result) ->
917+
%% For local (non-distributed) calls, the result is returned directly.
918+
Result.
919+
891920
check_module(Mod) ->
892921
case code:which(Mod) of
893922
Beam when is_list(Beam) ->

0 commit comments

Comments
 (0)