From 53e951d0076af7aa3e192473b10218cfbe0693b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-S=C3=A9bastien=20P=C3=A9dron?= Date: Thu, 30 Mar 2023 16:32:37 +0200 Subject: [PATCH] Support argument lists in stacktraces Sometimes, a stacktrace frame will contain the actual list of arguments to a function instead of just its arity. We need to transfer this list of arguments to the reconstructed stacktrace. We take a sublist of the arguments correpsonding to the arity of the original function. This is required because the extracted standalone function may take more arguments to take its environment into account. Arguments from the environment are therefore discarded. --- src/horus.erl | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/horus.erl b/src/horus.erl index ccf9a1d..4272f21 100644 --- a/src/horus.erl +++ b/src/horus.erl @@ -1066,8 +1066,17 @@ reconstruct_original_stracktrace( Stacktrace) -> lists:map( fun + ({Module, Name, Args, Extra}) + when GeneratedModuleName =:= Module andalso is_list(Args) -> + Arity = length(Args), + {RealModule, RealName, RealArity} = + maps:get({Name, Arity}, FunNameMapping), + + RealArgs = lists:sublist(Args, RealArity), + ?assertEqual(RealArity, length(RealArgs)), + {RealModule, RealName, RealArgs, Extra}; ({Module, Name, Arity, Extra}) - when GeneratedModuleName =:= Module -> + when GeneratedModuleName =:= Module andalso is_integer(Arity) -> {RealModule, RealName, RealArity} = maps:get({Name, Arity}, FunNameMapping),