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

Make depth of current_stacktrace configurable #1263

Merged
merged 1 commit into from
Dec 20, 2016
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
8 changes: 6 additions & 2 deletions erts/doc/src/erlang.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4899,7 +4899,9 @@ RealSystem = system + MissedSystem</code>
<p>Returns the current call stack back-trace (<em>stacktrace</em>)
of the process. The stack has the same format as returned by
<seealso marker="#get_stacktrace/0">
<c>erlang:get_stacktrace/0</c></seealso>.</p>
<c>erlang:get_stacktrace/0</c></seealso>. The depth of the
stacktrace is truncated according to the <c>backtrace_depth</c>
system flag setting.</p>
</item>
<tag><c>{dictionary, <anno>Dictionary</anno>}</c></tag>
<item>
Expand Down Expand Up @@ -6611,7 +6613,9 @@ ok
<fsummary>Set system flag <c>backtrace_depth</c>.</fsummary>
<desc>
<p>Sets the maximum depth of call stack back-traces in the
exit reason element of <c>'EXIT'</c> tuples.</p>
exit reason element of <c>'EXIT'</c> tuples. The flag
also limits the stacktrace depth returned by <c>process_info</c>
item <c>current_stacktrace.</c></p>
<p>Returns the old value of the flag.</p>
</desc>
</func>
Expand Down
4 changes: 2 additions & 2 deletions erts/emulator/beam/erl_bif_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -1672,11 +1672,11 @@ current_stacktrace(Process* p, Process* rp, Eterm** hpp)
Eterm mfa;
Eterm res = NIL;

depth = 8;
depth = erts_backtrace_depth;
sz = offsetof(struct StackTrace, trace) + sizeof(BeamInstr *)*depth;
s = (struct StackTrace *) erts_alloc(ERTS_ALC_T_TMP, sz);
s->depth = 0;
if (rp->i) {
if (depth > 0 && rp->i) {
s->trace[s->depth++] = rp->i;
depth--;
}
Expand Down
11 changes: 11 additions & 0 deletions erts/emulator/test/process_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -437,11 +437,22 @@ t_process_info(Config) when is_list(Config) ->
verify_loc(Line2, Res2),
pi_stacktrace([{?MODULE,t_process_info,1,?LINE}]),

verify_stacktrace_depth(),

Gleader = group_leader(),
{group_leader, Gleader} = process_info(self(), group_leader),
{'EXIT',{badarg,_Info}} = (catch process_info('not_a_pid')),
ok.

verify_stacktrace_depth() ->
CS = current_stacktrace,
OldDepth = erlang:system_flag(backtrace_depth, 0),
{CS,[]} = erlang:process_info(self(), CS),
_ = erlang:system_flag(backtrace_depth, 8),
{CS,[{?MODULE,verify_stacktrace_depth,0,_},_|_]} =
erlang:process_info(self(), CS),
_ = erlang:system_flag(backtrace_depth, OldDepth).

pi_stacktrace(Expected0) ->
{Line,Res} = {?LINE,erlang:process_info(self(), current_stacktrace)},
{current_stacktrace,Stack} = Res,
Expand Down