Coverage Report

Created: 2025-06-24 06:45

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