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