From: Anders F Björklund Date: Tue, 28 Mar 2017 05:21:34 +0000 (+0200) Subject: Add debugging option of printing unify output X-Git-Tag: v3.4~57 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4aabc104ee3d8d67448081123f9000425a1756dc;p=thirdparty%2Fccache.git Add debugging option of printing unify output --- diff --git a/ccache.c b/ccache.c index edd53e47c..631eba6f7 100644 --- a/ccache.c +++ b/ccache.c @@ -81,6 +81,9 @@ char *secondary_config_path = NULL; // Current working directory taken from $PWD, or getcwd() if $PWD is bad. char *current_working_dir = NULL; +// Print the unified preprocessed source code format, to stdout +bool unify_print = false; + // The original argument list. static struct args *orig_args; @@ -1500,13 +1503,16 @@ get_object_name_from_cpp(struct args *args, struct mdfour *hash) } if (conf->unify) { + char *print = getenv("CCACHE_UNIFY_PRINT"); + unify_print = print != NULL ? true : false; + // When we are doing the unifying tricks we need to include the input file // name in the hash to get the warnings right. hash_delimiter(hash, "unifyfilename"); hash_string(hash, input_file); hash_delimiter(hash, "unifycpp"); - if (unify_hash(hash, path_stdout) != 0) { + if (unify_hash(hash, path_stdout, unify_print) != 0) { stats_update(STATS_ERROR); cc_log("Failed to unify %s", path_stdout); failed(); diff --git a/ccache.h b/ccache.h index e611b58df..b2829074a 100644 --- a/ccache.h +++ b/ccache.h @@ -207,7 +207,7 @@ void stats_write(const char *path, struct counters *counters); // ---------------------------------------------------------------------------- // unify.c -int unify_hash(struct mdfour *hash, const char *fname); +int unify_hash(struct mdfour *hash, const char *fname, bool print); // ---------------------------------------------------------------------------- // exitfn.c diff --git a/unify.c b/unify.c index 7c54e9f88..1a594f140 100644 --- a/unify.c +++ b/unify.c @@ -29,6 +29,8 @@ #include "ccache.h" +static bool print_unified = true; + static const char *const s_tokens[] = { "...", ">>=", "<<=", "+=", "-=", "*=", "/=", "%=", "&=", "^=", "|=", ">>", "<<", "++", "--", "->", "&&", "||", "<=", ">=", @@ -108,6 +110,9 @@ pushchar(struct mdfour *hash, unsigned char c) if (c == 0) { if (len > 0) { hash_buffer(hash, (char *)buf, len); + if (print_unified) { + printf("%.*s", (int) len, buf); + } len = 0; } hash_buffer(hash, NULL, 0); @@ -117,6 +122,9 @@ pushchar(struct mdfour *hash, unsigned char c) buf[len++] = c; if (len == 64) { hash_buffer(hash, (char *)buf, len); + if (print_unified) { + printf("%.*s", (int) len, buf); + } len = 0; } } @@ -238,7 +246,7 @@ unify(struct mdfour *hash, unsigned char *p, size_t size) // Hash a file that consists of preprocessor output, but remove any line number // information from the hash. int -unify_hash(struct mdfour *hash, const char *fname) +unify_hash(struct mdfour *hash, const char *fname, bool print) { char *data; size_t size; @@ -246,6 +254,7 @@ unify_hash(struct mdfour *hash, const char *fname) stats_update(STATS_PREPROCESSOR); return -1; } + print_unified = print; unify(hash, (unsigned char *)data, size); free(data); return 0;