mfabik / rpms / satyr

Forked from rpms/satyr 3 years ago
Clone

Blame SOURCES/satyr-0.13-normalization-normalize-out-exit-frames.patch

f41043
From b4120f370475bde243a1ae5bde64f4f0a641c3c3 Mon Sep 17 00:00:00 2001
f41043
From: =?UTF-8?q?Marek=20Bry=C5=A1a?= <mbrysa@redhat.com>
f41043
Date: Wed, 27 May 2015 18:43:52 +0200
f41043
Subject: [PATCH] normalization: normalize out exit frames
f41043
f41043
---
f41043
 include/core/thread.h |  3 +++
f41043
 lib/core_thread.c     | 30 +++++++++++++++++-------------
f41043
 lib/normalize.c       | 36 +++++++++++++++++++++---------------
f41043
 3 files changed, 41 insertions(+), 28 deletions(-)
f41043
f41043
diff --git a/include/core/thread.h b/include/core/thread.h
f41043
index 0ba71e4..d6125df 100644
f41043
--- a/include/core/thread.h
f41043
+++ b/include/core/thread.h
f41043
@@ -123,6 +123,9 @@ struct sr_core_thread *
f41043
 sr_core_thread_append(struct sr_core_thread *dest,
f41043
                       struct sr_core_thread *item);
f41043
 
f41043
+bool
f41043
+sr_core_thread_is_exit_frame(struct sr_core_frame *frame);
f41043
+
f41043
 struct sr_core_frame *
f41043
 sr_core_thread_find_exit_frame(struct sr_core_thread *thread);
f41043
 
f41043
diff --git a/lib/core_thread.c b/lib/core_thread.c
f41043
index 54fb89c..d8aa943 100644
f41043
--- a/lib/core_thread.c
f41043
+++ b/lib/core_thread.c
f41043
@@ -149,6 +149,22 @@ sr_core_thread_append(struct sr_core_thread *dest,
f41043
     return dest;
f41043
 }
f41043
 
f41043
+bool
f41043
+sr_core_thread_is_exit_frame(struct sr_core_frame *frame)
f41043
+{
f41043
+    return
f41043
+        sr_core_frame_calls_func(frame, "__run_exit_handlers", NULL) ||
f41043
+        sr_core_frame_calls_func(frame, "raise", "libc.so", "libc-", "libpthread.so", NULL) ||
f41043
+        sr_core_frame_calls_func(frame, "__GI_raise", NULL) ||
f41043
+        sr_core_frame_calls_func(frame, "exit", NULL) ||
f41043
+        sr_core_frame_calls_func(frame, "abort", "libc.so", "libc-", NULL) ||
f41043
+        sr_core_frame_calls_func(frame, "__GI_abort", NULL) ||
f41043
+        /* Terminates a function in case of buffer overflow. */
f41043
+        sr_core_frame_calls_func(frame, "__chk_fail", "libc.so", NULL) ||
f41043
+        sr_core_frame_calls_func(frame, "__stack_chk_fail", "libc.so", NULL) ||
f41043
+        sr_core_frame_calls_func(frame, "kill", NULL);
f41043
+}
f41043
+
f41043
 struct sr_core_frame *
f41043
 sr_core_thread_find_exit_frame(struct sr_core_thread *thread)
f41043
 {
f41043
@@ -156,19 +172,7 @@ sr_core_thread_find_exit_frame(struct sr_core_thread *thread)
f41043
     struct sr_core_frame *result = NULL;
f41043
     while (frame)
f41043
     {
f41043
-        bool is_exit_frame =
f41043
-            sr_core_frame_calls_func(frame, "__run_exit_handlers", NULL) ||
f41043
-            sr_core_frame_calls_func(frame, "raise", "libc.so", "libc-", "libpthread.so", NULL) ||
f41043
-            sr_core_frame_calls_func(frame, "__GI_raise", NULL) ||
f41043
-            sr_core_frame_calls_func(frame, "exit", NULL) ||
f41043
-            sr_core_frame_calls_func(frame, "abort", "libc.so", "libc-", NULL) ||
f41043
-            sr_core_frame_calls_func(frame, "__GI_abort", NULL) ||
f41043
-            /* Terminates a function in case of buffer overflow. */
f41043
-            sr_core_frame_calls_func(frame, "__chk_fail", "libc.so", NULL) ||
f41043
-            sr_core_frame_calls_func(frame, "__stack_chk_fail", "libc.so", NULL) ||
f41043
-            sr_core_frame_calls_func(frame, "kill", NULL);
f41043
-
f41043
-        if (is_exit_frame)
f41043
+        if (sr_core_thread_is_exit_frame(frame))
f41043
             result = frame;
f41043
 
f41043
         frame = frame->next;
f41043
diff --git a/lib/normalize.c b/lib/normalize.c
f41043
index bec2ccc..e3a7a13 100644
f41043
--- a/lib/normalize.c
f41043
+++ b/lib/normalize.c
f41043
@@ -282,6 +282,22 @@ remove_func_prefix(char *function_name, const char *prefix, int num)
f41043
     memmove(function_name, function_name + num, func_len - num + 1);
f41043
 }
f41043
 
f41043
+static bool
f41043
+sr_gdb_is_exit_frame(struct sr_gdb_frame *frame)
f41043
+{
f41043
+    return
f41043
+        sr_gdb_frame_calls_func(frame, "__run_exit_handlers", "exit.c", NULL) ||
f41043
+        sr_gdb_frame_calls_func(frame, "raise", "pt-raise.c", "libc.so", "libc-", "libpthread.so", NULL) ||
f41043
+        sr_gdb_frame_calls_func(frame, "__GI_raise", "raise.c", NULL) ||
f41043
+        sr_gdb_frame_calls_func(frame, "exit", "exit.c", NULL) ||
f41043
+        sr_gdb_frame_calls_func(frame, "abort", "abort.c", "libc.so", "libc-", NULL) ||
f41043
+        sr_gdb_frame_calls_func(frame, "__GI_abort", "abort.c", NULL) ||
f41043
+        /* Terminates a function in case of buffer overflow. */
f41043
+        sr_gdb_frame_calls_func(frame, "__chk_fail", "chk_fail.c", "libc.so", NULL) ||
f41043
+        sr_gdb_frame_calls_func(frame, "__stack_chk_fail", "stack_chk_fail.c", "libc.so", NULL) ||
f41043
+        sr_gdb_frame_calls_func(frame, "kill", "syscall-template.S", NULL);
f41043
+}
f41043
+
f41043
 void
f41043
 sr_normalize_gdb_thread(struct sr_gdb_thread *thread)
f41043
 {
f41043
@@ -352,7 +368,8 @@ sr_normalize_gdb_thread(struct sr_gdb_thread *thread)
f41043
             is_removable_vim(frame->function_name, frame->source_file);
f41043
 
f41043
         bool removable_with_above =
f41043
-            is_removable_glibc_with_above(frame->function_name, frame->source_file);
f41043
+            is_removable_glibc_with_above(frame->function_name, frame->source_file) ||
f41043
+            sr_gdb_is_exit_frame(frame);
f41043
 
f41043
         if (removable_with_above)
f41043
         {
f41043
@@ -496,7 +513,8 @@ sr_normalize_core_thread(struct sr_core_thread *thread)
f41043
             is_removable_vim(frame->function_name, frame->file_name);
f41043
 
f41043
         bool removable_with_above =
f41043
-            is_removable_glibc_with_above(frame->function_name, frame->file_name);
f41043
+            is_removable_glibc_with_above(frame->function_name, frame->file_name)  ||
f41043
+            sr_core_thread_is_exit_frame(frame);
f41043
 
f41043
         if (removable_with_above)
f41043
         {
f41043
@@ -689,19 +707,7 @@ sr_glibc_thread_find_exit_frame(struct sr_gdb_thread *thread)
f41043
     struct sr_gdb_frame *result = NULL;
f41043
     while (frame)
f41043
     {
f41043
-        bool is_exit_frame =
f41043
-            sr_gdb_frame_calls_func(frame, "__run_exit_handlers", "exit.c", NULL) ||
f41043
-            sr_gdb_frame_calls_func(frame, "raise", "pt-raise.c", "libc.so", "libc-", "libpthread.so", NULL) ||
f41043
-            sr_gdb_frame_calls_func(frame, "__GI_raise", "raise.c", NULL) ||
f41043
-            sr_gdb_frame_calls_func(frame, "exit", "exit.c", NULL) ||
f41043
-            sr_gdb_frame_calls_func(frame, "abort", "abort.c", "libc.so", "libc-", NULL) ||
f41043
-            sr_gdb_frame_calls_func(frame, "__GI_abort", "abort.c", NULL) ||
f41043
-            /* Terminates a function in case of buffer overflow. */
f41043
-            sr_gdb_frame_calls_func(frame, "__chk_fail", "chk_fail.c", "libc.so", NULL) ||
f41043
-            sr_gdb_frame_calls_func(frame, "__stack_chk_fail", "stack_chk_fail.c", "libc.so", NULL) ||
f41043
-            sr_gdb_frame_calls_func(frame, "kill", "syscall-template.S", NULL);
f41043
-
f41043
-        if (is_exit_frame)
f41043
+        if (sr_gdb_is_exit_frame(frame))
f41043
             result = frame;
f41043
 
f41043
         frame = frame->next;
f41043
-- 
f41043
1.8.3.1
f41043