From b72a04dc51bb7d34ad04e9f75a07b0f92e96a262 Mon Sep 17 00:00:00 2001 From: Joel Rosdahl Date: Sun, 7 Oct 2018 21:06:08 +0200 Subject: [PATCH] Fix bugs in debug mode logging MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Need to dump log buffer as the last exit function to not lose any logs. Also, made sure to print the final result log line even if the log mode isn’t enabled. --- src/ccache.c | 3 ++- src/ccache.h | 1 + src/exitfn.c | 22 ++++++++++++++++++++-- src/stats.c | 2 +- 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/ccache.c b/src/ccache.c index e7790040d..0665582fd 100644 --- a/src/ccache.c +++ b/src/ccache.c @@ -3427,7 +3427,8 @@ ccache(int argc, char *argv[]) cc_log("Object file: %s", output_obj); - exitfn_add(dump_log_buffer_exitfn, output_obj); + // Need to dump log buffer as the last exit function to not lose any logs. + exitfn_add_last(dump_log_buffer_exitfn, output_obj); FILE *debug_text_file = NULL; if (conf->debug) { diff --git a/src/ccache.h b/src/ccache.h index bb0a4292f..1c769f825 100644 --- a/src/ccache.h +++ b/src/ccache.h @@ -228,6 +228,7 @@ void stats_write(const char *path, struct counters *counters); void exitfn_init(void); void exitfn_add_nullary(void (*function)(void)); void exitfn_add(void (*function)(void *), void *context); +void exitfn_add_last(void (*function)(void *), void *context); void exitfn_call(void); // ---------------------------------------------------------------------------- diff --git a/src/exitfn.c b/src/exitfn.c index 5c2c482cf..5be5e2201 100644 --- a/src/exitfn.c +++ b/src/exitfn.c @@ -1,4 +1,4 @@ -// Copyright (C) 2010-2016 Joel Rosdahl +// Copyright (C) 2010-2018 Joel Rosdahl // // This program is free software; you can redistribute it and/or modify it // under the terms of the GNU General Public License as published by the Free @@ -56,7 +56,7 @@ exitfn_add_nullary(void (*function)(void)) } // Add a function to be called with a context parameter when ccache exits. -// Functions are called in reverse order. +// Functions are called in LIFO order except when added via exitfn_add_last. void exitfn_add(void (*function)(void *), void *context) { @@ -67,6 +67,24 @@ exitfn_add(void (*function)(void *), void *context) exit_functions = p; } +// Add a function to be called with a context parameter when ccache exits. In +// contrast to exitfn_add, exitfn_add_last sets up the function to be called +// last. +void +exitfn_add_last(void (*function)(void *), void *context) +{ + struct exit_function *p = x_malloc(sizeof(*p)); + p->function = function; + p->context = context; + p->next = NULL; + + struct exit_function **q = &exit_functions; + while (*q) { + q = &(*q)->next; + } + *q = p; +} + // Call added functions. void exitfn_call(void) diff --git a/src/stats.c b/src/stats.c index d8b15c01f..ef6a2914e 100644 --- a/src/stats.c +++ b/src/stats.c @@ -389,7 +389,7 @@ stats_flush(void) stats_write(stats_file, counters); lockfile_release(stats_file); - if (!str_eq(conf->log_file, "")) { + if (!str_eq(conf->log_file, "") || conf->debug) { for (int i = 0; i < STATS_END; ++i) { if (counter_updates->data[stats_info[i].stat] != 0 && !(stats_info[i].flags & FLAG_NOZERO)) { -- 2.47.2