]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Improve debuginfo cwd when using -fdebug-prefix-map
authorAnders Björklund <anders@itension.se>
Sun, 29 Nov 2015 12:52:21 +0000 (13:52 +0100)
committerAnders Björklund <anders@itension.se>
Mon, 8 Feb 2016 18:36:44 +0000 (19:36 +0100)
Support the -fdebug-prefix-map option, for relocating the debuginfo
current working directory (cwd) as recorded with CCACHE_HASHDIR.
This can be used in connection with CCACHE_BASEDIR, to get cache hits
even when generating debuginfo: the base directory can be mapped.

MANUAL.txt
ccache.c

index 9852cb372f42176e796c0f8d77aad91511615db8..aae6d2aeb2c23b5e2f32737b429359d59201d044 100644 (file)
@@ -242,6 +242,10 @@ setting key. Boolean options are indicated with ``[boolean]''
     directory. If set to the empty string (which is the default), no rewriting
     is done. See also the discussion under
     <<_compiling_in_different_directories,COMPILING IN DIFFERENT DIRECTORIES>>.
+    If using GCC*, you might want to look into the *-fdebug-prefix-map* option
+    for relocating debug info to a common prefix (mapping prefix with old=new).
+
+    * or newer versions of Clang, see: http://reviews.llvm.org/rL250094
 
 *cache_dir* (*CCACHE_DIR*)::
 
index 14df68260b97085c9d96e3159913b70745f5cc03..c9d87dd71b86910b6b4fea7276ba778eaff920b4 100644 (file)
--- a/ccache.c
+++ b/ccache.c
@@ -189,6 +189,9 @@ static bool generating_dependencies;
 /* is gcc being asked to output coverage? */
 static bool generating_coverage;
 
+/* relocating debuginfo, in the format old=new */
+static char *debug_prefix_map = NULL;
+
 /* is gcc being asked to output coverage data (.gcda) at runtime? */
 static bool profile_arcs;
 
@@ -1488,6 +1491,23 @@ calculate_common_hash(struct args *args, struct mdfour *hash)
        /* Possibly hash the current working directory. */
        if (conf->hash_dir) {
                char *cwd = gnu_getcwd();
+               if (debug_prefix_map) {
+                       char *map = debug_prefix_map;
+                       char *sep = strchr(map, '=');
+                       char *dir, *old, *new;
+                       if (sep) {
+                               old = x_strndup(map, sep - map);
+                               new = x_strdup(sep + 1);
+                               cc_log("Relocating debuginfo cwd %s, from %s to %s", cwd, old, new);
+                               if (str_startswith(cwd, old)) {
+                                       dir = format("%s%s", new, cwd + strlen(old));
+                                       free(cwd);
+                                       cwd = dir;
+                               }
+                               free(old);
+                               free(new);
+                       }
+               }
                if (cwd) {
                        hash_delimiter(hash, "cwd");
                        hash_string(hash, cwd);
@@ -2186,6 +2206,11 @@ cc_process_args(struct args *args, struct args **preprocessor_args,
                        args_add(stripped_args, argv[i]);
                        continue;
                }
+               if (str_startswith(argv[i], "-fdebug-prefix-map=")) {
+                       debug_prefix_map = x_strdup(argv[i] + 19);
+                       args_add(stripped_args, argv[i]);
+                       continue;
+               }
 
                /* Debugging is handled specially, so that we know if we can strip line
                 * number info. */
@@ -3006,6 +3031,7 @@ cc_reset(void)
        free(primary_config_path); primary_config_path = NULL;
        free(secondary_config_path); secondary_config_path = NULL;
        free(current_working_dir); current_working_dir = NULL;
+       free(debug_prefix_map); debug_prefix_map = NULL;
        free(profile_dir); profile_dir = NULL;
        free(included_pch_file); included_pch_file = NULL;
        args_free(orig_args); orig_args = NULL;