]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Add debugging option of printing unify output
authorAnders F Björklund <anders.f.bjorklund@gmail.com>
Tue, 28 Mar 2017 05:21:34 +0000 (07:21 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Wed, 19 Jul 2017 19:58:31 +0000 (21:58 +0200)
ccache.c
ccache.h
unify.c

index edd53e47c2ae770e2b91a81e5bbc373543ed1aa2..631eba6f7f170711180ac98b8a62874fc735120d 100644 (file)
--- 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();
index e611b58df81fcca1c46bbe2f6f65aca884011817..b2829074a8bcf4b75ce8f9397a3cadca661d05db 100644 (file)
--- 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 7c54e9f88c05a5c0880eb445cfa18307a728c54a..1a594f140ec3f4be1276317c679b075e2d3a565b 100644 (file)
--- 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;