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.
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) {
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);
// ----------------------------------------------------------------------------
-// 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
}
// 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)
{
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)
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)) {