X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=gas%2Fremap.c;h=2af7a9e87ffdf9d1d94305aa9887e1dc5385feba;hb=8b8c7c9f49992750f66f81b4601d593a3858d98c;hp=ae078969eb468683159ba6b8c579232b02b5b465;hpb=3d6b762c68c6e19bdf387c0f1db7773fd22aab9a;p=deliverable%2Fbinutils-gdb.git diff --git a/gas/remap.c b/gas/remap.c index ae078969eb..2af7a9e87f 100644 --- a/gas/remap.c +++ b/gas/remap.c @@ -1,5 +1,5 @@ /* Remap file names for debug info for GNU assembler. - Copyright 2007 Free Software Foundation, Inc. + Copyright (C) 2007-2016 Free Software Foundation, Inc. This file is part of GAS, the GNU Assembler. @@ -19,6 +19,7 @@ 02110-1301, USA. */ #include "as.h" +#include "filenames.h" /* Structure recording the mapping from source file and directory names at compile time to those to be embedded in debug @@ -52,7 +53,7 @@ add_debug_prefix_map (const char *arg) as_fatal (_("invalid argument '%s' to -fdebug-prefix-map"), arg); return; } - map = xmalloc (sizeof (debug_prefix_map)); + map = XNEW (debug_prefix_map); o = xstrdup (arg); map->old_prefix = o; map->old_len = p - arg; @@ -64,26 +65,21 @@ add_debug_prefix_map (const char *arg) debug_prefix_maps = map; } -/* Perform user-specified mapping of debug filename prefixes. Return - the new name corresponding to FILENAME. */ +/* Perform user-specified mapping of debug filename prefixes. Returns + a newly allocated buffer containing the name corresponding to FILENAME. + It is the caller's responsibility to free the buffer. */ const char * remap_debug_filename (const char *filename) { debug_prefix_map *map; - char *s; - const char *name; - size_t name_len; for (map = debug_prefix_maps; map; map = map->next) - if (strncmp (filename, map->old_prefix, map->old_len) == 0) - break; - if (!map) - return filename; - name = filename + map->old_len; - name_len = strlen (name) + 1; - s = (char *) alloca (name_len + map->new_len); - memcpy (s, map->new_prefix, map->new_len); - memcpy (s + map->new_len, name, name_len); - return xstrdup (s); + if (filename_ncmp (filename, map->old_prefix, map->old_len) == 0) + { + const char *name = filename + map->old_len; + return concat (map->new_prefix, name, NULL); + } + + return xstrdup (filename); }