Skip to content

Commit

Permalink
2019-12-31 09:31:19 CST W52D2
Browse files Browse the repository at this point in the history
  • Loading branch information
aggresss committed Dec 31, 2019
1 parent f27a3df commit 7ee3599
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 20 deletions.
2 changes: 1 addition & 1 deletion workbench/asan/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
CC:=$(CROSS_COMPILE)gcc
all:
$(CC) $(CFLAGS) -O0 -g -rdynamic -Wall -fsanitize=address asan_hello.c -lpthread -o asan_hello.out
$(CC) $(CFLAGS) -O0 -g -rdynamic -Wall -fsanitize=address asan_hello.c -lasan -lpthread -o asan_hello.out
clean:
rm *.o *.out -rf
42 changes: 23 additions & 19 deletions workbench/segfault/segfault_catch.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <pthread.h>
#include <ucontext.h>

#ifdef __GLIBC__
#if defined(__GLIBC__) && !defined(__UCLIBC__)
#include <execinfo.h>
#endif

Expand Down Expand Up @@ -73,9 +73,6 @@ __cyg_profile_func_exit(void *this_func, void *call_site)

static void SignalSegFaultHandler(int signal, siginfo_t *si, void *ctx)
{
void *array[MAX_STACK_DEPTH];
size_t bt_size;
char **bt_strings;
int i, j;
ucontext_t *triger_context = (ucontext_t*)ctx;

Expand Down Expand Up @@ -109,24 +106,31 @@ static void SignalSegFaultHandler(int signal, siginfo_t *si, void *ctx)
printf ("\n");
}

#ifdef __GLIBC__
bt_size = backtrace(array, MAX_STACK_DEPTH);
bt_strings = backtrace_symbols(array, bt_size);
if (NULL == bt_strings) {
perror("backtrace_symbols");
exit(EXIT_FAILURE);
}

if (bt_size > 0) {
printf("backtrace() obtained %zd stack frames.\n", bt_size);
for (i = 0; i < bt_size; i++) {
printf("\t%s\n", bt_strings[i]);
#if defined(__GLIBC__) && !defined(__UCLIBC__)

if (1) {
void *array[MAX_STACK_DEPTH];
size_t bt_size;
char **bt_strings;
bt_size = backtrace(array, MAX_STACK_DEPTH);
bt_strings = backtrace_symbols(array, bt_size);
if (NULL == bt_strings) {
perror("backtrace_symbols");
exit(EXIT_FAILURE);
}
printf ("\n");

free(bt_strings);
bt_strings = NULL;
if (bt_size > 0) {
printf("backtrace() obtained %zd stack frames.\n", bt_size);
for (i = 0; i < bt_size; i++) {
printf("\t%s\n", bt_strings[i]);
}
printf ("\n");

free(bt_strings);
bt_strings = NULL;
}
}

#endif

int current_stack_depth = threads[current_thread_index].stack_depth;
Expand Down

0 comments on commit 7ee3599

Please sign in to comment.