diff options
author | Björn Gustavsson <[email protected]> | 2011-03-10 16:53:50 +0100 |
---|---|---|
committer | Björn Gustavsson <[email protected]> | 2011-08-16 15:22:28 +0200 |
commit | 962c9a185eb4897d38b37170f20695608ca9a21b (patch) | |
tree | 17ccf956e95d77066322d0002e954cc50e916302 /erts/emulator/beam/beam_emu.c | |
parent | 053fb064496043207cfa807c900077f9bbc4c7d1 (diff) | |
download | otp-962c9a185eb4897d38b37170f20695608ca9a21b.tar.gz otp-962c9a185eb4897d38b37170f20695608ca9a21b.tar.bz2 otp-962c9a185eb4897d38b37170f20695608ca9a21b.zip |
beam_emu: Factor out saving of stack trace from save_stacktrace()
Put the actual saving of the continuation pointers on the stack
in the new function erts_save_stacktrace() so that it can be reused.
The code is too tricky and complicated to allow it to
become duplicated.
Diffstat (limited to 'erts/emulator/beam/beam_emu.c')
-rw-r--r-- | erts/emulator/beam/beam_emu.c | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/erts/emulator/beam/beam_emu.c b/erts/emulator/beam/beam_emu.c index a7d7e851cf..afdbd65bb5 100644 --- a/erts/emulator/beam/beam_emu.c +++ b/erts/emulator/beam/beam_emu.c @@ -5813,24 +5813,31 @@ save_stacktrace(Process* c_p, BeamInstr* pc, Eterm* reg, BifFunction bf, } /* Save the actual stack trace */ + erts_save_stacktrace(c_p, s, depth); +} + +void +erts_save_stacktrace(Process* p, struct StackTrace* s, int depth) +{ if (depth > 0) { Eterm *ptr; BeamInstr *prev = s->depth ? s->trace[s->depth-1] : NULL; BeamInstr i_return_trace = beam_return_trace[0]; BeamInstr i_return_to_trace = beam_return_to_trace[0]; + /* * Traverse the stack backwards and add all unique continuation * pointers to the buffer, up to the maximum stack trace size. * * Skip trace stack frames. */ - ptr = c_p->stop; - if (ptr < STACK_START(c_p) - && (is_not_CP(*ptr)|| (*cp_val(*ptr) != i_return_trace && - *cp_val(*ptr) != i_return_to_trace)) - && c_p->cp) { - /* Can not follow cp here - code may be unloaded */ - BeamInstr *cpp = c_p->cp; + ptr = p->stop; + if (ptr < STACK_START(p) && + (is_not_CP(*ptr)|| (*cp_val(*ptr) != i_return_trace && + *cp_val(*ptr) != i_return_to_trace)) && + p->cp) { + /* Cannot follow cp here - code may be unloaded */ + BeamInstr *cpp = p->cp; if (cpp == beam_exception_trace || cpp == beam_return_trace) { /* Skip return_trace parameters */ ptr += 2; @@ -5839,7 +5846,7 @@ save_stacktrace(Process* c_p, BeamInstr* pc, Eterm* reg, BifFunction bf, ptr += 1; } } - while (ptr < STACK_START(c_p) && depth > 0) { + while (ptr < STACK_START(p) && depth > 0) { if (is_CP(*ptr)) { if (*cp_val(*ptr) == i_return_trace) { /* Skip stack frame variables */ |