/* C preprocessor macro tables for GDB.
- Copyright (C) 2002-2013 Free Software Foundation, Inc.
+ Copyright (C) 2002-2017 Free Software Foundation, Inc.
Contributed by Red Hat, Inc.
This file is part of GDB.
#include "symfile.h"
#include "objfiles.h"
#include "macrotab.h"
-#include "gdb_assert.h"
#include "bcache.h"
#include "complaints.h"
#include "macroexp.h"
#inclusion tree; everything else is #included from here. */
struct macro_source_file *main_source;
- /* Compilation directory for all files of this macro table. It is allocated
- on objfile's obstack. */
- const char *comp_dir;
+ /* Backlink to containing compilation unit, or NULL if there isn't one. */
+ struct compunit_symtab *compunit_symtab;
/* True if macros in this table can be redefined without issuing an
error. */
static const char *
macro_bcache_str (struct macro_table *t, const char *s)
{
- return macro_bcache (t, s, strlen (s) + 1);
+ return (const char *) macro_bcache (t, s, strlen (s) + 1);
}
struct macro_source_file *file,
int line)
{
- struct macro_key *k = macro_alloc (sizeof (*k), t);
+ struct macro_key *k = (struct macro_key *) macro_alloc (sizeof (*k), t);
memset (k, 0, sizeof (*k));
k->table = t;
const char *filename)
{
/* Get space for the source file structure itself. */
- struct macro_source_file *f = macro_alloc (sizeof (*f), t);
+ struct macro_source_file *f
+ = (struct macro_source_file *) macro_alloc (sizeof (*f), t);
memset (f, 0, sizeof (*f));
f->table = t;
int line,
const char *included)
{
- struct macro_source_file *new;
+ struct macro_source_file *newobj;
struct macro_source_file **link;
/* Find the right position in SOURCE's `includes' list for the new
/* At this point, we know that LINE is an unused line number, and
*LINK points to the entry an #inclusion at that line should
precede. */
- new = new_source_file (source->table, included);
- new->included_by = source;
- new->included_at_line = line;
- new->next_included = *link;
- *link = new;
+ newobj = new_source_file (source->table, included);
+ newobj->included_by = source;
+ newobj->included_at_line = line;
+ newobj->next_included = *link;
+ *link = newobj;
- return new;
+ return newobj;
}
int argc, const char **argv,
const char *replacement)
{
- struct macro_definition *d = macro_alloc (sizeof (*d), t);
+ struct macro_definition *d
+ = (struct macro_definition *) macro_alloc (sizeof (*d), t);
memset (d, 0, sizeof (*d));
d->table = t;
int cached_argv_size = argc * sizeof (*cached_argv);
/* Bcache all the arguments. */
- cached_argv = alloca (cached_argv_size);
+ cached_argv = (const char **) alloca (cached_argv_size);
for (i = 0; i < argc; i++)
cached_argv[i] = macro_bcache_str (t, argv[i]);
/* Now bcache the array of argument pointers itself. */
- d->argv = macro_bcache (t, cached_argv, cached_argv_size);
+ d->argv = ((const char * const *)
+ macro_bcache (t, cached_argv, cached_argv_size));
}
/* We don't bcache the entire definition structure because it's got
the FILE and LINE fields. */
struct macro_for_each_data
{
- macro_callback_fn fn;
- void *user_data;
+ gdb::function_view<macro_callback_fn> fn;
struct macro_source_file *file;
int line;
};
(struct macro_definition *) node->value);
xfree (key_fullname);
- (*datum->fn) (key->name, def, key->start_file, key->start_line,
- datum->user_data);
+ datum->fn (key->name, def, key->start_file, key->start_line);
return 0;
}
/* Call FN for every macro in TABLE. */
void
-macro_for_each (struct macro_table *table, macro_callback_fn fn,
- void *user_data)
+macro_for_each (struct macro_table *table,
+ gdb::function_view<macro_callback_fn> fn)
{
struct macro_for_each_data datum;
datum.fn = fn;
- datum.user_data = user_data;
datum.file = NULL;
datum.line = 0;
splay_tree_foreach (table->definitions, foreach_macro, &datum);
&& (!key->end_file
|| compare_locations (key->end_file, key->end_line,
datum->file, datum->line) >= 0))
- (*datum->fn) (key->name, def, key->start_file, key->start_line,
- datum->user_data);
+ datum->fn (key->name, def, key->start_file, key->start_line);
return 0;
}
/* Call FN for every macro is visible in SCOPE. */
void
macro_for_each_in_scope (struct macro_source_file *file, int line,
- macro_callback_fn fn, void *user_data)
+ gdb::function_view<macro_callback_fn> fn)
{
struct macro_for_each_data datum;
datum.fn = fn;
- datum.user_data = user_data;
datum.file = file;
datum.line = line;
splay_tree_foreach (file->table->definitions,
struct macro_table *
new_macro_table (struct obstack *obstack, struct bcache *b,
- const char *comp_dir)
+ struct compunit_symtab *cust)
{
struct macro_table *t;
/* First, get storage for the `struct macro_table' itself. */
if (obstack)
- t = obstack_alloc (obstack, sizeof (*t));
+ t = XOBNEW (obstack, struct macro_table);
else
- t = xmalloc (sizeof (*t));
+ t = XNEW (struct macro_table);
memset (t, 0, sizeof (*t));
t->obstack = obstack;
t->bcache = b;
t->main_source = NULL;
- t->comp_dir = comp_dir;
+ t->compunit_symtab = cust;
t->redef_ok = 0;
t->definitions = (splay_tree_new_with_allocator
(macro_tree_compare,
char *
macro_source_fullname (struct macro_source_file *file)
{
- if (file->table->comp_dir == NULL || IS_ABSOLUTE_PATH (file->filename))
+ const char *comp_dir = NULL;
+
+ if (file->table->compunit_symtab != NULL)
+ comp_dir = COMPUNIT_DIRNAME (file->table->compunit_symtab);
+
+ if (comp_dir == NULL || IS_ABSOLUTE_PATH (file->filename))
return xstrdup (file->filename);
- return concat (file->table->comp_dir, SLASH_STRING, file->filename, NULL);
+ return concat (comp_dir, SLASH_STRING, file->filename, (char *) NULL);
}