mfabik / rpms / satyr

Forked from rpms/satyr 3 years ago
Clone

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

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