Home | History | Annotate | Line # | Download | only in gas
remap.c revision 1.5
      1  1.1  christos /* Remap file names for debug info for GNU assembler.
      2  1.5  christos    Copyright (C) 2007-2016 Free Software Foundation, Inc.
      3  1.1  christos 
      4  1.1  christos    This file is part of GAS, the GNU Assembler.
      5  1.1  christos 
      6  1.1  christos    GAS is free software; you can redistribute it and/or modify
      7  1.1  christos    it under the terms of the GNU General Public License as published by
      8  1.1  christos    the Free Software Foundation; either version 3, or (at your option)
      9  1.1  christos    any later version.
     10  1.1  christos 
     11  1.1  christos    GAS is distributed in the hope that it will be useful,
     12  1.1  christos    but WITHOUT ANY WARRANTY; without even the implied warranty of
     13  1.1  christos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     14  1.1  christos    GNU General Public License for more details.
     15  1.1  christos 
     16  1.1  christos    You should have received a copy of the GNU General Public License
     17  1.1  christos    along with GAS; see the file COPYING.  If not, write to the Free
     18  1.1  christos    Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
     19  1.1  christos    02110-1301, USA.  */
     20  1.1  christos 
     21  1.1  christos #include "as.h"
     22  1.1  christos #include "filenames.h"
     23  1.1  christos 
     24  1.1  christos /* Structure recording the mapping from source file and directory
     25  1.1  christos    names at compile time to those to be embedded in debug
     26  1.1  christos    information.  */
     27  1.1  christos typedef struct debug_prefix_map
     28  1.1  christos {
     29  1.1  christos   const char *old_prefix;
     30  1.1  christos   const char *new_prefix;
     31  1.1  christos   size_t old_len;
     32  1.1  christos   size_t new_len;
     33  1.1  christos   struct debug_prefix_map *next;
     34  1.1  christos } debug_prefix_map;
     35  1.1  christos 
     36  1.1  christos /* Linked list of such structures.  */
     37  1.1  christos debug_prefix_map *debug_prefix_maps;
     38  1.1  christos 
     39  1.1  christos 
     40  1.1  christos /* Record a debug file prefix mapping.  ARG is the argument to
     41  1.1  christos    -fdebug-prefix-map and must be of the form OLD=NEW.  */
     42  1.1  christos 
     43  1.1  christos void
     44  1.1  christos add_debug_prefix_map (const char *arg)
     45  1.1  christos {
     46  1.1  christos   debug_prefix_map *map;
     47  1.1  christos   const char *p;
     48  1.1  christos   char *o;
     49  1.1  christos 
     50  1.1  christos   p = strchr (arg, '=');
     51  1.1  christos   if (!p)
     52  1.1  christos     {
     53  1.1  christos       as_fatal (_("invalid argument '%s' to -fdebug-prefix-map"), arg);
     54  1.1  christos       return;
     55  1.1  christos     }
     56  1.5  christos   map = XNEW (debug_prefix_map);
     57  1.1  christos   o = xstrdup (arg);
     58  1.1  christos   map->old_prefix = o;
     59  1.1  christos   map->old_len = p - arg;
     60  1.1  christos   o[map->old_len] = 0;
     61  1.1  christos   p++;
     62  1.1  christos   map->new_prefix = xstrdup (p);
     63  1.1  christos   map->new_len = strlen (p);
     64  1.1  christos   map->next = debug_prefix_maps;
     65  1.1  christos   debug_prefix_maps = map;
     66  1.1  christos }
     67  1.1  christos 
     68  1.1  christos /* Perform user-specified mapping of debug filename prefixes.  Returns
     69  1.1  christos    a newly allocated buffer containing the name corresponding to FILENAME.
     70  1.1  christos    It is the caller's responsibility to free the buffer.  */
     71  1.1  christos 
     72  1.1  christos const char *
     73  1.1  christos remap_debug_filename (const char *filename)
     74  1.1  christos {
     75  1.1  christos   debug_prefix_map *map;
     76  1.1  christos 
     77  1.1  christos   for (map = debug_prefix_maps; map; map = map->next)
     78  1.1  christos     if (filename_ncmp (filename, map->old_prefix, map->old_len) == 0)
     79  1.1  christos       break;
     80  1.1  christos   if (!map)
     81  1.1  christos     return xstrdup (filename);
     82  1.5  christos   const char *name = filename + map->old_len;
     83  1.5  christos   size_t name_len = strlen (name) + 1;
     84  1.5  christos   char *s = (char *) xmalloc (name_len + map->new_len);
     85  1.1  christos   memcpy (s, map->new_prefix, map->new_len);
     86  1.1  christos   memcpy (s + map->new_len, name, name_len);
     87  1.1  christos   return s;
     88  1.1  christos }
     89