diff options
| author | Bill Wendling <isanbard@gmail.com> | 2012-05-28 10:09:01 +0000 |
|---|---|---|
| committer | Bill Wendling <isanbard@gmail.com> | 2012-05-28 10:09:01 +0000 |
| commit | aa888a29eb3d3fe682ec62d26ea47ea4627636a6 (patch) | |
| tree | e6a42b68ddac3e3026bed4ece2cdb916a9a0ea78 | |
| parent | 1e039681c50faa81df9145d08bfc2418743efcba (diff) | |
| download | bcm5719-llvm-aa888a29eb3d3fe682ec62d26ea47ea4627636a6.tar.gz bcm5719-llvm-aa888a29eb3d3fe682ec62d26ea47ea4627636a6.zip | |
Add support for the GCOV_PREFIX_STRIP env variable which tries to strip off the first 'n' directories from the filename.
llvm-svn: 157574
| -rw-r--r-- | compiler-rt/lib/profile/GCDAProfiling.c | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/compiler-rt/lib/profile/GCDAProfiling.c b/compiler-rt/lib/profile/GCDAProfiling.c index 4d0c41b40c6..300985ff45d 100644 --- a/compiler-rt/lib/profile/GCDAProfiling.c +++ b/compiler-rt/lib/profile/GCDAProfiling.c @@ -67,20 +67,39 @@ static void write_string(const char *s) { } static char *mangle_filename(const char *orig_filename) { - /* TODO: handle GCOV_PREFIX_STRIP */ char *filename = 0; int prefix_len = 0; + int prefix_strip = 0; + int level = 0; + const char *fname = orig_filename, *ptr = NULL; const char *prefix = getenv("GCOV_PREFIX"); + const char *tmp = getenv("GCOV_PREFIX_STRIP"); - if (!prefix || prefix[0] != '/') /* Ignore non-absolute paths */ + if (!prefix) return strdup(orig_filename); + if (tmp) { + prefix_strip = atoi(tmp); + + /* Negative GCOV_PREFIX_STRIP values are ignored */ + if (prefix_strip < 0) + prefix_strip = 0; + } + prefix_len = strlen(prefix); filename = malloc(prefix_len + 1 + strlen(orig_filename) + 1); strcpy(filename, prefix); + if (prefix[prefix_len - 1] != '/') strcat(filename, "/"); - strcat(filename, orig_filename); + + for (ptr = fname + 1; *ptr != '\0' && level < prefix_strip; ++ptr) { + if (*ptr != '/') continue; + fname = ptr; + ++level; + } + + strcat(filename, fname); return filename; } |

