From f4e94537f362b29bf7413481bd6b1b4568b386f2 Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Sun, 27 Jul 2014 07:22:47 +0000 Subject: * libgcov-driver.c (struct gcov_filename_aux): Rename ... (struct gcov_filename): ... here. Include buffer and max length fields. (gcov_max_filename): Remove. (gi_filename): Remove. (gcov_exit_compute_summary): Compute max filename here. (gcov_exit_merge_gcda): Add filename parm, adjust. (gcov_exit_merge_summary): Likewise. (gcov_exit_dump_gcov): Adjust for struct gcov_filename changes. (gcov_exit): Likewise. (__gcov_init): Don't calculate max length here. * libgcov_util.c (max_filename_len): Remove. (read_gcda_file): Don't calculate max length here. (gcov_read_profile_dir): Don't propagate here. * libgcov-driver-system.c (alloc_filename_struct): Adjust for struct gcov_filename changes. (gcov_exit_open_gcda_file): Likewise. git-svn-id: https://gcc.gnu.org/svn/gcc/trunk@213092 138bc75d-0d04-0410-961f-82ee72b054a4 --- libgcc/libgcov-driver-system.c | 105 ++++++++++++++++++----------------------- 1 file changed, 46 insertions(+), 59 deletions(-) (limited to 'libgcc/libgcov-driver-system.c') diff --git a/libgcc/libgcov-driver-system.c b/libgcc/libgcov-driver-system.c index 1bb7402813f..2f59f800262 100644 --- a/libgcc/libgcov-driver-system.c +++ b/libgcc/libgcov-driver-system.c @@ -83,118 +83,105 @@ create_file_directory (char *filename) } static void -allocate_filename_struct (struct gcov_filename_aux *gf) +allocate_filename_struct (struct gcov_filename *gf) { const char *gcov_prefix; - int gcov_prefix_strip = 0; size_t prefix_length; - char *gi_filename_up; + int strip = 0; - gcc_assert (gf); { /* Check if the level of dirs to strip off specified. */ char *tmp = getenv("GCOV_PREFIX_STRIP"); if (tmp) { - gcov_prefix_strip = atoi (tmp); + strip = atoi (tmp); /* Do not consider negative values. */ - if (gcov_prefix_strip < 0) - gcov_prefix_strip = 0; + if (strip < 0) + strip = 0; } } + gf->strip = strip; /* Get file name relocation prefix. Non-absolute values are ignored. */ gcov_prefix = getenv("GCOV_PREFIX"); - if (gcov_prefix) - { - prefix_length = strlen(gcov_prefix); - - /* Remove an unnecessary trailing '/' */ - if (IS_DIR_SEPARATOR (gcov_prefix[prefix_length - 1])) - prefix_length--; - } - else - prefix_length = 0; + prefix_length = gcov_prefix ? strlen (gcov_prefix) : 0; + + /* Remove an unnecessary trailing '/' */ + if (prefix_length && IS_DIR_SEPARATOR (gcov_prefix[prefix_length - 1])) + prefix_length--; /* If no prefix was specified and a prefix stip, then we assume relative. */ - if (gcov_prefix_strip != 0 && prefix_length == 0) + if (!prefix_length && gf->strip) { gcov_prefix = "."; prefix_length = 1; } - /* Allocate and initialize the filename scratch space plus one. */ - gi_filename = (char *) xmalloc (prefix_length + gcov_max_filename + 2); - if (prefix_length) - memcpy (gi_filename, gcov_prefix, prefix_length); - gi_filename_up = gi_filename + prefix_length; + gf->prefix = prefix_length; - gf->gi_filename_up = gi_filename_up; - gf->prefix_length = prefix_length; - gf->gcov_prefix_strip = gcov_prefix_strip; + /* Allocate and initialize the filename scratch space. */ + gf->filename = (char *) xmalloc (gf->max_length + prefix_length + 2); + if (prefix_length) + memcpy (gf->filename, gcov_prefix, prefix_length); } /* Open a gcda file specified by GI_FILENAME. Return -1 on error. Return 0 on success. */ static int -gcov_exit_open_gcda_file (struct gcov_info *gi_ptr, struct gcov_filename_aux *gf) +gcov_exit_open_gcda_file (struct gcov_info *gi_ptr, + struct gcov_filename *gf) { - int gcov_prefix_strip; - size_t prefix_length; - char *gi_filename_up; - const char *fname, *s; + const char *fname = gi_ptr->filename; + char *dst = gf->filename + gf->prefix; - gcov_prefix_strip = gf->gcov_prefix_strip; - gi_filename_up = gf->gi_filename_up; - prefix_length = gf->prefix_length; fname = gi_ptr->filename; - /* Avoid to add multiple drive letters into combined path. */ - if (prefix_length != 0 && HAS_DRIVE_SPEC(fname)) - fname += 2; - /* Build relocated filename, stripping off leading directories from the initial filename if requested. */ - if (gcov_prefix_strip > 0) + if (gf->strip > 0) { - int level = 0; + const char *probe = fname; + int level; - s = fname; - if (IS_DIR_SEPARATOR(*s)) - ++s; + /* Remove a leading separator, without counting it. */ + if (IS_DIR_SEPARATOR (*probe)) + probe++; - /* Skip selected directory levels. */ - for (; (*s != '\0') && (level < gcov_prefix_strip); s++) - if (IS_DIR_SEPARATOR(*s)) + /* Skip selected directory levels. If we fall off the end, we + keep the final part. */ + for (level = gf->strip; *probe && level; probe++) + if (IS_DIR_SEPARATOR (*probe)) { - fname = s; - level++; + fname = probe; + level--; } } /* Update complete filename with stripped original. */ - if (prefix_length != 0 && !IS_DIR_SEPARATOR (*fname)) + if (gf->prefix) { - /* If prefix is given, add directory separator. */ - strcpy (gi_filename_up, "/"); - strcpy (gi_filename_up + 1, fname); + /* Avoid to add multiple drive letters into combined path. */ + if (HAS_DRIVE_SPEC(fname)) + fname += 2; + + if (!IS_DIR_SEPARATOR (*fname)) + *dst++ = '/'; } - else - strcpy (gi_filename_up, fname); + strcpy (dst, fname); - if (!gcov_open (gi_filename)) + if (!gcov_open (gf->filename)) { /* Open failed likely due to missed directory. Create directory and retry to open file. */ - if (create_file_directory (gi_filename)) + if (create_file_directory (gf->filename)) { - fprintf (stderr, "profiling:%s:Skip\n", gi_filename); + fprintf (stderr, "profiling:%s:Skip\n", gf->filename); return -1; } - if (!gcov_open (gi_filename)) + if (!gcov_open (gf->filename)) { - fprintf (stderr, "profiling:%s:Cannot open\n", gi_filename); + fprintf (stderr, "profiling:%s:Cannot open\n", gf->filename); return -1; } } -- cgit v1.2.3