From: Anders Björklund Date: Sun, 29 Nov 2015 12:52:21 +0000 (+0100) Subject: Improve debuginfo cwd when using -fdebug-prefix-map X-Git-Tag: v3.3~117 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=020045d73ccf9b16656837027efab409d9de435d;p=thirdparty%2Fccache.git Improve debuginfo cwd when using -fdebug-prefix-map 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. --- diff --git a/MANUAL.txt b/MANUAL.txt index 9852cb372..aae6d2aeb 100644 --- a/MANUAL.txt +++ b/MANUAL.txt @@ -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*):: diff --git a/ccache.c b/ccache.c index 14df68260..c9d87dd71 100644 --- 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;