Blame SOURCES/satyr-0.13-Honor-frame-number-limit-in-GDB-core-unwinder.patch

01add4
From d94a7b5c516c0446d1c49e8446707a64b4b45148 Mon Sep 17 00:00:00 2001
01add4
From: Jakub Filak <jfilak@redhat.com>
01add4
Date: Tue, 2 Aug 2016 08:50:10 +0200
01add4
Subject: [PATCH] Honor frame number limit in GDB core unwinder
01add4
01add4
Related to #1260074
01add4
01add4
Signed-off-by: Jakub Filak <jfilak@redhat.com>
01add4
---
01add4
 lib/core_unwind.c          | 15 +++++++++++++++
01add4
 lib/core_unwind_elfutils.c |  6 ++----
01add4
 lib/internal_unwind.h      |  5 +++++
01add4
 3 files changed, 22 insertions(+), 4 deletions(-)
01add4
01add4
diff --git a/lib/core_unwind.c b/lib/core_unwind.c
01add4
index b8c0235..05b94a5 100644
01add4
--- a/lib/core_unwind.c
01add4
+++ b/lib/core_unwind.c
01add4
@@ -429,6 +429,8 @@ sr_core_stacktrace_from_gdb(const char *gdb_output, const char *core_file,
01add4
     {
01add4
         struct sr_core_thread *core_thread = sr_core_thread_new();
01add4
 
01add4
+        unsigned long nframes = CORE_STACKTRACE_FRAME_LIMIT;
01add4
+        struct sr_gdb_frame *top_frame = gdb_thread->frames;
01add4
         for (struct sr_gdb_frame *gdb_frame = gdb_thread->frames;
01add4
              gdb_frame;
01add4
              gdb_frame = gdb_frame->next)
01add4
@@ -436,6 +438,19 @@ sr_core_stacktrace_from_gdb(const char *gdb_output, const char *core_file,
01add4
             if (gdb_frame->signal_handler_called)
01add4
                 continue;
01add4
 
01add4
+            if (nframes)
01add4
+                --nframes;
01add4
+            else
01add4
+                top_frame = top_frame->next;
01add4
+        }
01add4
+
01add4
+        for (struct sr_gdb_frame *gdb_frame = top_frame;
01add4
+             gdb_frame;
01add4
+             gdb_frame = gdb_frame->next)
01add4
+        {
01add4
+            if (gdb_frame->signal_handler_called)
01add4
+                continue;
01add4
+
01add4
             struct sr_core_frame *core_frame = resolve_frame(ch->dwfl,
01add4
                     gdb_frame->address, false);
01add4
 
01add4
diff --git a/lib/core_unwind_elfutils.c b/lib/core_unwind_elfutils.c
01add4
index 1482dba..d273a03 100644
01add4
--- a/lib/core_unwind_elfutils.c
01add4
+++ b/lib/core_unwind_elfutils.c
01add4
@@ -33,8 +33,6 @@
01add4
 #include <sys/ptrace.h>
01add4
 #include <sys/wait.h>
01add4
 
01add4
-#define FRAME_LIMIT 256
01add4
-
01add4
 struct frame_callback_arg
01add4
 {
01add4
     struct sr_core_frame **frames_tail;
01add4
@@ -84,8 +82,8 @@ frame_callback(Dwfl_Frame *frame, void *data)
01add4
 static void
01add4
 truncate_long_thread(struct sr_core_thread *thread, struct frame_callback_arg *frame_arg)
01add4
 {
01add4
-    /* Truncate the stacktrace to FRAME_LIMIT least recent frames. */
01add4
-    while (thread->frames && frame_arg->nframes > FRAME_LIMIT)
01add4
+    /* Truncate the stacktrace to CORE_STACKTRACE_FRAME_LIMIT least recent frames. */
01add4
+    while (thread->frames && frame_arg->nframes > CORE_STACKTRACE_FRAME_LIMIT)
01add4
     {
01add4
         struct sr_core_frame *old_frame = thread->frames;
01add4
         thread->frames = old_frame->next;
01add4
diff --git a/lib/internal_unwind.h b/lib/internal_unwind.h
01add4
index 84261c6..b9e162a 100644
01add4
--- a/lib/internal_unwind.h
01add4
+++ b/lib/internal_unwind.h
01add4
@@ -66,6 +66,11 @@ _set_error(char **error_msg, const char *fmt, ...) __sr_printf(2, 3);
01add4
         }                                    \
01add4
     } while(0)
01add4
 
01add4
+/* This macro is used as a limit for the number of function frames included in
01add4
+ * every single thread of a core stacktrace generated by satyr.
01add4
+ */
01add4
+#define CORE_STACKTRACE_FRAME_LIMIT 256
01add4
+
01add4
 struct exe_mapping_data
01add4
 {
01add4
     uint64_t start;
01add4
-- 
01add4
2.17.1
01add4