File 2021-Handle-load_binary-result-in-debugger-int-load.patch of Package erlang
From 09a1a609dceb0173608b8caf0e3595d4f4ccbc76 Mon Sep 17 00:00:00 2001
From: Lukasz Samson <lukaszsamson@gmail.com>
Date: Wed, 5 Feb 2025 18:46:01 +0100
Subject: [PATCH] Handle load_binary result in debugger int:load
Fixes https://github.com/erlang/otp/issues/7819
---
lib/debugger/src/int.erl | 69 ++++++++++++++++++++++++++++------------
1 file changed, 49 insertions(+), 20 deletions(-)
diff --git a/lib/debugger/src/int.erl b/lib/debugger/src/int.erl
index 740f52b1e7..5d27bac370 100644
--- a/lib/debugger/src/int.erl
+++ b/lib/debugger/src/int.erl
@@ -866,28 +866,57 @@ check(Mod) when is_atom(Mod) -> catch check_module(Mod);
check(File) when is_list(File) -> catch check_file(File).
load({Mod, Src, Beam, BeamBin, Exp, Abst}, Dist) ->
- _ = everywhere(Dist,
- fun() ->
- code:purge(Mod),
- erts_debug:breakpoint({Mod,'_','_'}, false),
- {module,Mod} = code:load_binary(Mod, Beam, BeamBin)
- end),
- case erl_prim_loader:read_file(filename:absname(Src)) of
- {ok, SrcBin} ->
- MD5 = code:module_md5(BeamBin),
- SrcBin1 = unicode:characters_to_binary(SrcBin, enc(SrcBin)),
- true = is_binary(SrcBin1),
- Bin = term_to_binary({interpreter_module,Exp,Abst,SrcBin1,MD5}),
- {module, Mod} = dbg_iserver:safe_call({load, Mod, Src, Bin}),
- _ = everywhere(Dist,
- fun() ->
- true = erts_debug:breakpoint({Mod,'_','_'}, true) > 0
- end),
- {module, Mod};
- error ->
- error
+ RawLoadResult = everywhere(Dist,
+ fun() ->
+ code:purge(Mod),
+ erts_debug:breakpoint({Mod, '_', '_'}, false),
+ code:load_binary(Mod, Beam, BeamBin)
+ end),
+ LoadResult = extract_result(RawLoadResult),
+ case LoadResult of
+ {module, Mod} ->
+ case erl_prim_loader:read_file(filename:absname(Src)) of
+ {ok, SrcBin} ->
+ MD5 = code:module_md5(BeamBin),
+ SrcBin1 = unicode:characters_to_binary(SrcBin, enc(SrcBin)),
+ true = is_binary(SrcBin1),
+ Bin = term_to_binary({interpreter_module, Exp, Abst, SrcBin1, MD5}),
+ {module, Mod} = dbg_iserver:safe_call({load, Mod, Src, Bin}),
+ _ = everywhere(Dist,
+ fun() ->
+ true = erts_debug:breakpoint({Mod, '_', '_'}, true) > 0
+ end),
+ {module, Mod};
+ error ->
+ error
+ end;
+ {error, _} ->
+ error;
+ {badrpc, _} ->
+ error
end.
+extract_result({Results, _BadNodes}) when is_list(Results) ->
+ %% In distributed mode, rpc:multicall returns {Results, BadNodes}.
+ %% Look for any successful result in the list.
+ case lists:filter(fun
+ ({module, _}) -> true;
+ (_) -> false
+ end, Results) of
+ [] ->
+ %% No node succeeded; return the first result from Results,
+ %% which should be an error tuple or badrpc tuple.
+ case Results of
+ [First | _] -> First;
+ [] -> error
+ end;
+ [Success | _] ->
+ Success
+ end;
+extract_result(Result) ->
+ %% For local (non-distributed) calls, the result is returned directly.
+ Result.
+
check_module(Mod) ->
case code:which(Mod) of
Beam when is_list(Beam) ->
--
2.43.0