From 9b0d41184821bc229a92d3734200c34a31603783 Mon Sep 17 00:00:00 2001 From: Martin Milata Date: Wed, 27 Aug 2014 13:55:50 +0200 Subject: [PATCH] unwind: Append threads/frames in O(1) Related to #179. Signed-off-by: Martin Milata --- lib/core_unwind_elfutils.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/core_unwind_elfutils.c b/lib/core_unwind_elfutils.c index 43d66be..78470bc 100644 --- a/lib/core_unwind_elfutils.c +++ b/lib/core_unwind_elfutils.c @@ -33,14 +33,14 @@ struct frame_callback_arg { - struct sr_core_thread *thread; + struct sr_core_frame **frames_tail; char *error_msg; unsigned nframes; }; struct thread_callback_arg { - struct sr_core_stacktrace *stacktrace; + struct sr_core_thread **threads_tail; char *error_msg; }; @@ -70,8 +70,8 @@ frame_callback(Dwfl_Frame *frame, void *data) return CB_STOP_UNWIND; } - frame_arg->thread->frames = - sr_core_frame_append(frame_arg->thread->frames, result); + *frame_arg->frames_tail = result; + frame_arg->frames_tail = &result->next; /* Avoid huge stacktraces from programs stuck in infinite recursion. */ frame_arg->nframes++; @@ -99,7 +99,7 @@ unwind_thread(Dwfl_Thread *thread, void *data) struct frame_callback_arg frame_arg = { - .thread = result, + .frames_tail = &(result->frames), .error_msg = NULL, .nframes = 0 }; @@ -121,14 +121,15 @@ unwind_thread(Dwfl_Thread *thread, void *data) goto abort; } - if (!error_msg && !frame_arg.thread->frames) + if (!error_msg && !result->frames) { set_error("No frames found for thread id %d", (int)result->id); goto abort; } - thread_arg->stacktrace->threads = - sr_core_thread_append(thread_arg->stacktrace->threads, result); + *thread_arg->threads_tail = result; + thread_arg->threads_tail = &result->next; + return DWARF_CB_OK; abort: @@ -166,7 +167,7 @@ sr_parse_coredump(const char *core_file, struct thread_callback_arg thread_arg = { - .stacktrace = stacktrace, + .threads_tail = &(stacktrace->threads), .error_msg = NULL }; -- 2.1.0