From 40c046fb04e8dfaf50c75a291105a8558b9aae11 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sat, 13 Apr 2019 00:47:00 +0200 Subject: Enable prefetching backtace MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- config.mk | 2 +- internal.h | 3 +++ save_backtrace.c | 12 +++++++++--- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/config.mk b/config.mk index 51e1c93..df0ba5d 100644 --- a/config.mk +++ b/config.mk @@ -2,5 +2,5 @@ PREFIX = /usr MANPREFIX = $(PREFIX)/share/man CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_XOPEN_SOURCE=700 -CFLAGS = -std=c99 -Wall -pedantic +CFLAGS = -std=c11 -Wall -pedantic LDFLAGS = -s -lunwind -ldw -lerror diff --git a/internal.h b/internal.h index a2be394..1975522 100644 --- a/internal.h +++ b/internal.h @@ -21,5 +21,8 @@ struct liberror_backtrace { }; +extern _Thread_local struct liberror_backtrace *liberror_saved_backtrace; + + void liberror_print_backtrace(struct liberror_error *, FILE *, const char *); int liberror_save_backtrace(struct liberror_error *); diff --git a/save_backtrace.c b/save_backtrace.c index e366abf..7214fa4 100644 --- a/save_backtrace.c +++ b/save_backtrace.c @@ -53,9 +53,15 @@ liberror_save_backtrace(struct liberror_error *error) ret = 0; out: - if (error->backtrace && !--error->backtrace->refcount) - free(error->backtrace); - error->backtrace = backtrace; + if (error) { + if (error->backtrace && !--error->backtrace->refcount) + free(error->backtrace); + error->backtrace = backtrace; + } else { + if (liberror_saved_backtrace && !--liberror_saved_backtrace->refcount) + free(liberror_saved_backtrace); + liberror_saved_backtrace = backtrace; + } errno = saved_errno; return ret; } -- cgit v1.2.3-70-g09d2