mfabik / rpms / satyr

Forked from rpms/satyr 3 years ago
Clone

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

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