/* C preprocessor macro tables for GDB.
- Copyright (C) 2002-2019 Free Software Foundation, Inc.
+ Copyright (C) 2002-2020 Free Software Foundation, Inc.
Contributed by Red Hat, Inc.
This file is part of GDB.
/* The bcache we should use to hold macro names, argument names, and
definitions, or zero if we should use xmalloc. */
- struct bcache *bcache;
+ gdb::bcache *bcache;
/* The main source file for this compilation unit --- the one whose
name was given to the compiler. This is the root of the
macro_bcache (struct macro_table *t, const void *addr, int len)
{
if (t->bcache)
- return bcache (addr, len, t->bcache);
+ return t->bcache->insert (addr, len);
else
{
void *copy = xmalloc (len);
the new one? */
if (*link && line == (*link)->included_at_line)
{
- char *link_fullname, *source_fullname;
-
/* This means the compiler is emitting bogus debug info. (GCC
circa March 2002 did this.) It also means that the splay
tree ordering function, macro_tree_compare, will abort,
First, squawk. */
- link_fullname = macro_source_fullname (*link);
- source_fullname = macro_source_fullname (source);
+ std::string link_fullname = macro_source_fullname (*link);
+ std::string source_fullname = macro_source_fullname (source);
complaint (_("both `%s' and `%s' allegedly #included at %s:%d"),
- included, link_fullname, source_fullname, line);
- xfree (source_fullname);
- xfree (link_fullname);
+ included, link_fullname.c_str (), source_fullname.c_str (),
+ line);
/* Now, choose a new, unoccupied line number for this
#inclusion, after the alleged #inclusion line. */
if (! same)
{
- char *source_fullname, *found_key_fullname;
-
- source_fullname = macro_source_fullname (source);
- found_key_fullname = macro_source_fullname (found_key->start_file);
+ std::string source_fullname = macro_source_fullname (source);
+ std::string found_key_fullname
+ = macro_source_fullname (found_key->start_file);
complaint (_("macro `%s' redefined at %s:%d; "
"original definition at %s:%d"),
- name, source_fullname, line, found_key_fullname,
+ name, source_fullname.c_str (), line,
+ found_key_fullname.c_str (),
found_key->start_line);
- xfree (found_key_fullname);
- xfree (source_fullname);
}
return found_key;
#definition. */
if (key->end_file)
{
- char *source_fullname, *key_fullname;
-
- source_fullname = macro_source_fullname (source);
- key_fullname = macro_source_fullname (key->end_file);
+ std::string source_fullname = macro_source_fullname (source);
+ std::string key_fullname = macro_source_fullname (key->end_file);
complaint (_("macro '%s' is #undefined twice,"
" at %s:%d and %s:%d"),
- name, source_fullname, line, key_fullname,
+ name, source_fullname.c_str (), line,
+ key_fullname.c_str (),
key->end_line);
- xfree (key_fullname);
- xfree (source_fullname);
}
/* Whether or not we've seen a prior #undefinition, wipe out
if (n)
{
- struct macro_definition *retval;
- char *source_fullname;
-
- source_fullname = macro_source_fullname (source);
- retval = fixup_definition (source_fullname, line,
- (struct macro_definition *) n->value);
- xfree (source_fullname);
- return retval;
+ std::string source_fullname = macro_source_fullname (source);
+ return fixup_definition (source_fullname.c_str (), line,
+ (struct macro_definition *) n->value);
}
else
return 0;
struct macro_for_each_data *datum = (struct macro_for_each_data *) arg;
struct macro_key *key = (struct macro_key *) node->key;
struct macro_definition *def;
- char *key_fullname;
- key_fullname = macro_source_fullname (key->start_file);
- def = fixup_definition (key_fullname, key->start_line,
+ std::string key_fullname = macro_source_fullname (key->start_file);
+ def = fixup_definition (key_fullname.c_str (), key->start_line,
(struct macro_definition *) node->value);
- xfree (key_fullname);
datum->fn (key->name, def, key->start_file, key->start_line);
return 0;
struct macro_for_each_data *datum = (struct macro_for_each_data *) info;
struct macro_key *key = (struct macro_key *) node->key;
struct macro_definition *def;
- char *datum_fullname;
- datum_fullname = macro_source_fullname (datum->file);
- def = fixup_definition (datum_fullname, datum->line,
+ std::string datum_fullname = macro_source_fullname (datum->file);
+ def = fixup_definition (datum_fullname.c_str (), datum->line,
(struct macro_definition *) node->value);
- xfree (datum_fullname);
/* See if this macro is defined before the passed-in line, and
extends past that line. */
struct macro_table *
-new_macro_table (struct obstack *obstack, struct bcache *b,
+new_macro_table (struct obstack *obstack, gdb::bcache *b,
struct compunit_symtab *cust)
{
struct macro_table *t;
/* See macrotab.h for the comment. */
-char *
+std::string
macro_source_fullname (struct macro_source_file *file)
{
const char *comp_dir = NULL;
comp_dir = COMPUNIT_DIRNAME (file->table->compunit_symtab);
if (comp_dir == NULL || IS_ABSOLUTE_PATH (file->filename))
- return xstrdup (file->filename);
+ return file->filename;
- return concat (comp_dir, SLASH_STRING, file->filename, (char *) NULL);
+ return std::string (comp_dir) + SLASH_STRING + file->filename;
}