aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLukas Larsson <[email protected]>2017-04-10 13:21:34 +0200
committerLukas Larsson <[email protected]>2017-04-10 13:21:34 +0200
commitbde386af4dfc22cbf63d7cbe611c7147c6242e31 (patch)
tree752d839df764cab6129fbb767b4e85686876b334
parentb16a1de7e939d3f2c1d8f70ca6b168468608b975 (diff)
parent63b0880e714bd305033a7b07644bc87f8c949b66 (diff)
downloadotp-bde386af4dfc22cbf63d7cbe611c7147c6242e31.tar.gz
otp-bde386af4dfc22cbf63d7cbe611c7147c6242e31.tar.bz2
otp-bde386af4dfc22cbf63d7cbe611c7147c6242e31.zip
Merge branch 'lukas/erts/print_complex_crash_slogan/OTP-14303'
* lukas/erts/print_complex_crash_slogan/OTP-14303: erts: Print more complex terms in crash reason
-rw-r--r--erts/preloaded/src/init.erl39
1 files changed, 27 insertions, 12 deletions
diff --git a/erts/preloaded/src/init.erl b/erts/preloaded/src/init.erl
index 3dc6953b4c..c12a5b159a 100644
--- a/erts/preloaded/src/init.erl
+++ b/erts/preloaded/src/init.erl
@@ -263,21 +263,30 @@ boot(Start,Flags,Args) ->
boot_loop(BootPid,State).
%%% Convert a term to a printable string, if possible.
-to_string(X) when is_list(X) -> % assume string
+to_string(X, D) when is_list(X), D < 4 -> % assume string
F = flatten(X, []),
case printable_list(F) of
- true -> F;
- false -> ""
+ true when length(F) > 0 -> F;
+ _false ->
+ List = [to_string(E, D+1) || E <- X],
+ flatten(["[",join(List),"]"], [])
end;
-to_string(X) when is_atom(X) ->
+to_string(X, _D) when is_list(X) ->
+ "[_]";
+to_string(X, _D) when is_atom(X) ->
atom_to_list(X);
-to_string(X) when is_pid(X) ->
+to_string(X, _D) when is_pid(X) ->
pid_to_list(X);
-to_string(X) when is_float(X) ->
+to_string(X, _D) when is_float(X) ->
float_to_list(X);
-to_string(X) when is_integer(X) ->
+to_string(X, _D) when is_integer(X) ->
integer_to_list(X);
-to_string(_X) ->
+to_string(X, D) when is_tuple(X), D < 4 ->
+ List = [to_string(E, D+1) || E <- tuple_to_list(X)],
+ flatten(["{",join(List),"}"], []);
+to_string(X, _D) when is_tuple(X) ->
+ "{_}";
+to_string(_X, _D) ->
"". % can't do anything with it
%% This is an incorrect and narrow definition of printable characters.
@@ -291,6 +300,13 @@ printable_list([$\t|T]) -> printable_list(T);
printable_list([]) -> true;
printable_list(_) -> false.
+join([] = T) ->
+ T;
+join([_Elem] = T) ->
+ T;
+join([Elem|T]) ->
+ [Elem,","|join(T)].
+
flatten([H|T], Tail) when is_list(H) ->
flatten(H, flatten(T, Tail));
flatten([H|T], Tail) ->
@@ -299,7 +315,7 @@ flatten([], Tail) ->
Tail.
things_to_string([X|Rest]) ->
- " (" ++ to_string(X) ++ ")" ++ things_to_string(Rest);
+ " (" ++ to_string(X, 0) ++ ")" ++ things_to_string(Rest);
things_to_string([]) ->
"".
@@ -307,9 +323,8 @@ halt_string(String, List) ->
String ++ things_to_string(List).
%% String = string()
-%% List = [string() | atom() | pid() | number()]
-%% Any other items in List, such as tuples, are ignored when creating
-%% the string used as argument to erlang:halt/1.
+%% List = [string() | atom() | pid() | number() | list() | tuple()]
+%% Items in List are truncated if found to be too large
-spec crash(_, _) -> no_return().
crash(String, List) ->
halt(halt_string(String, List)).