mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2024-12-21 04:42:53 +08:00
82cb252432
Make it a little more obvious that remap_debug_filename returns an allocated string (that should be freed) by returning a char * rather than const char *. Free a few missed cases in dwarf2dbg.c, and free other memory allocated in dwarf2dbg.c. Also remove static initialisation of variables and initialise in dwarf2_init instead, in order to ensure gas state is saner for oss-fuzz. * remap.c (remap_debug_filename): Remove const from return. * as.h (remap_debug_filename): Update prototype. * config/obj-elf.c (obj_elf_ident): Simplify free of remap_debug_filename output. * stabs.c (stabs_generate_asm_file): Likewise. * dwarf2dbg.c (dirs, dirs_in_use, dirs_allocated, current): Don't initialise statically.. (dwarf2_init): ..do so here, along with most other static vars. (assign_file_to_slot): Don't set files_allocated until we succeed in allocating memory. (purge_generated_debug): Add bool param, free more stuff if true. (dwarf2_directive_filename): Adjust purge_generated_debug call. (process_entries): Don't free line_entry here.. (dwarf2_cleanup): ..do so here instead, new function. (dwarf2_finish): Call dwarf2_cleanup. When chaining together subseg line entries, unhook entries from old subseg list. (dwarf2_directive_loc): Free remap_debug_filename string. (out_dir_and_file_list): Likewise. (out_debug_str): Likewise.
86 lines
2.4 KiB
C
86 lines
2.4 KiB
C
/* Remap file names for debug info for GNU assembler.
|
|
Copyright (C) 2007-2022 Free Software Foundation, Inc.
|
|
|
|
This file is part of GAS, the GNU Assembler.
|
|
|
|
GAS is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 3, or (at your option)
|
|
any later version.
|
|
|
|
GAS is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with GAS; see the file COPYING. If not, write to the Free
|
|
Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
|
|
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
|
|
information. */
|
|
typedef struct debug_prefix_map
|
|
{
|
|
const char *old_prefix;
|
|
const char *new_prefix;
|
|
size_t old_len;
|
|
size_t new_len;
|
|
struct debug_prefix_map *next;
|
|
} debug_prefix_map;
|
|
|
|
/* Linked list of such structures. */
|
|
debug_prefix_map *debug_prefix_maps;
|
|
|
|
|
|
/* Record a debug file prefix mapping. ARG is the argument to
|
|
-fdebug-prefix-map and must be of the form OLD=NEW. */
|
|
|
|
void
|
|
add_debug_prefix_map (const char *arg)
|
|
{
|
|
debug_prefix_map *map;
|
|
const char *p;
|
|
char *o;
|
|
|
|
p = strchr (arg, '=');
|
|
if (!p)
|
|
{
|
|
as_fatal (_("invalid argument '%s' to -fdebug-prefix-map"), arg);
|
|
return;
|
|
}
|
|
map = XNEW (debug_prefix_map);
|
|
o = xstrdup (arg);
|
|
map->old_prefix = o;
|
|
map->old_len = p - arg;
|
|
o[map->old_len] = 0;
|
|
p++;
|
|
map->new_prefix = xstrdup (p);
|
|
map->new_len = strlen (p);
|
|
map->next = debug_prefix_maps;
|
|
debug_prefix_maps = map;
|
|
}
|
|
|
|
/* 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. */
|
|
|
|
char *
|
|
remap_debug_filename (const char *filename)
|
|
{
|
|
debug_prefix_map *map;
|
|
|
|
for (map = debug_prefix_maps; map; map = map->next)
|
|
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);
|
|
}
|