]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Fix bugs in debug mode logging
authorJoel Rosdahl <joel@rosdahl.net>
Sun, 7 Oct 2018 19:06:08 +0000 (21:06 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Sun, 7 Oct 2018 19:06:08 +0000 (21:06 +0200)
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
src/ccache.h
src/exitfn.c
src/stats.c

index e7790040daf816e3d8dad553c86b809360ee1fe9..0665582fd1382739a22344780d0fd01b1e46530d 100644 (file)
@@ -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) {
index bb0a4292fca0e61a9a6ec740d01b810db1c3f969..1c769f8251c1d9787a8d10e9169bd94ed69cea7c 100644 (file)
@@ -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);
 
 // ----------------------------------------------------------------------------
index 5c2c482cf656fc40d70f6388945a3a5b0bb9c7f3..5be5e2201ac325721024e8dfb6c2d9fd6427bd61 100644 (file)
@@ -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)
index d8b15c01fa38106d79492c5bfe347169529b020b..ef6a2914ede5a49ab43a4ea54c8035119a1e24a3 100644 (file)
@@ -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)) {