From 36d6b09bc537483dbd7a12823f2111abdadd68cb Mon Sep 17 00:00:00 2001 From: Martin Milata Date: Wed, 27 Aug 2014 14:21:55 +0200 Subject: [PATCH] unwind: throw away the most recent frames In case there's more than 1024 frames. Fixes #179. Signed-off-by: Martin Milata --- lib/core_unwind_elfutils.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/core_unwind_elfutils.c b/lib/core_unwind_elfutils.c index 78470bc..7be7ec7 100644 --- a/lib/core_unwind_elfutils.c +++ b/lib/core_unwind_elfutils.c @@ -72,13 +72,7 @@ frame_callback(Dwfl_Frame *frame, void *data) *frame_arg->frames_tail = result; frame_arg->frames_tail = &result->next; - - /* Avoid huge stacktraces from programs stuck in infinite recursion. */ frame_arg->nframes++; - if (frame_arg->nframes >= FRAME_LIMIT) - { - return CB_STOP_UNWIND; - } return DWARF_CB_OK; } @@ -127,6 +121,15 @@ unwind_thread(Dwfl_Thread *thread, void *data) goto abort; } + /* Truncate the stacktrace to FRAME_LIMIT least recent frames. */ + while (result->frames && frame_arg.nframes > FRAME_LIMIT) + { + struct sr_core_frame *old_frame = result->frames; + result->frames = old_frame->next; + sr_core_frame_free(old_frame); + frame_arg.nframes--; + } + *thread_arg->threads_tail = result; thread_arg->threads_tail = &result->next; -- 2.1.0