Blob Blame History Raw
From d94a7b5c516c0446d1c49e8446707a64b4b45148 Mon Sep 17 00:00:00 2001
From: Jakub Filak <jfilak@redhat.com>
Date: Tue, 2 Aug 2016 08:50:10 +0200
Subject: [PATCH] Honor frame number limit in GDB core unwinder

Related to #1260074

Signed-off-by: Jakub Filak <jfilak@redhat.com>
---
 lib/core_unwind.c          | 15 +++++++++++++++
 lib/core_unwind_elfutils.c |  6 ++----
 lib/internal_unwind.h      |  5 +++++
 3 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/lib/core_unwind.c b/lib/core_unwind.c
index b8c0235..05b94a5 100644
--- a/lib/core_unwind.c
+++ b/lib/core_unwind.c
@@ -429,6 +429,8 @@ sr_core_stacktrace_from_gdb(const char *gdb_output, const char *core_file,
     {
         struct sr_core_thread *core_thread = sr_core_thread_new();
 
+        unsigned long nframes = CORE_STACKTRACE_FRAME_LIMIT;
+        struct sr_gdb_frame *top_frame = gdb_thread->frames;
         for (struct sr_gdb_frame *gdb_frame = gdb_thread->frames;
              gdb_frame;
              gdb_frame = gdb_frame->next)
@@ -436,6 +438,19 @@ sr_core_stacktrace_from_gdb(const char *gdb_output, const char *core_file,
             if (gdb_frame->signal_handler_called)
                 continue;
 
+            if (nframes)
+                --nframes;
+            else
+                top_frame = top_frame->next;
+        }
+
+        for (struct sr_gdb_frame *gdb_frame = top_frame;
+             gdb_frame;
+             gdb_frame = gdb_frame->next)
+        {
+            if (gdb_frame->signal_handler_called)
+                continue;
+
             struct sr_core_frame *core_frame = resolve_frame(ch->dwfl,
                     gdb_frame->address, false);
 
diff --git a/lib/core_unwind_elfutils.c b/lib/core_unwind_elfutils.c
index 1482dba..d273a03 100644
--- a/lib/core_unwind_elfutils.c
+++ b/lib/core_unwind_elfutils.c
@@ -33,8 +33,6 @@
 #include <sys/ptrace.h>
 #include <sys/wait.h>
 
-#define FRAME_LIMIT 256
-
 struct frame_callback_arg
 {
     struct sr_core_frame **frames_tail;
@@ -84,8 +82,8 @@ frame_callback(Dwfl_Frame *frame, void *data)
 static void
 truncate_long_thread(struct sr_core_thread *thread, struct frame_callback_arg *frame_arg)
 {
-    /* Truncate the stacktrace to FRAME_LIMIT least recent frames. */
-    while (thread->frames && frame_arg->nframes > FRAME_LIMIT)
+    /* Truncate the stacktrace to CORE_STACKTRACE_FRAME_LIMIT least recent frames. */
+    while (thread->frames && frame_arg->nframes > CORE_STACKTRACE_FRAME_LIMIT)
     {
         struct sr_core_frame *old_frame = thread->frames;
         thread->frames = old_frame->next;
diff --git a/lib/internal_unwind.h b/lib/internal_unwind.h
index 84261c6..b9e162a 100644
--- a/lib/internal_unwind.h
+++ b/lib/internal_unwind.h
@@ -66,6 +66,11 @@ _set_error(char **error_msg, const char *fmt, ...) __sr_printf(2, 3);
         }                                    \
     } while(0)
 
+/* This macro is used as a limit for the number of function frames included in
+ * every single thread of a core stacktrace generated by satyr.
+ */
+#define CORE_STACKTRACE_FRAME_LIMIT 256
+
 struct exe_mapping_data
 {
     uint64_t start;
-- 
2.17.1