summaryrefslogtreecommitdiff
path: root/gdb/macrotab.c
diff options
context:
space:
mode:
authorJim Blandy <jimb@codesourcery.com>2007-09-22 01:09:19 +0000
committerJim Blandy <jimb@codesourcery.com>2007-09-22 01:09:19 +0000
commitdb3c3b206dbb6841f8b39eacc2ccea3bc1500497 (patch)
tree0f9ef08a69a92c237ab25900efdc6bbff5b5f110 /gdb/macrotab.c
parent252627e9a5ec1a6c07ac9db231dc6def124f97c4 (diff)
downloadgdb-db3c3b206dbb6841f8b39eacc2ccea3bc1500497.tar.gz
* macrotab.h (new_macro_table): Document that removing information
from an obstack/bcache-managed macro table leaks memory. * macrotab.c (macro_free, macro_bcache_free): Instead of asserting that data is never freed in obstack/bcache-managed macro tables, just leak the storage. (macro_undef): If we're undefining a macro at exactly the same source location that we defined it, simply remove the definition altogether.
Diffstat (limited to 'gdb/macrotab.c')
-rw-r--r--gdb/macrotab.c66
1 files changed, 46 insertions, 20 deletions
diff --git a/gdb/macrotab.c b/gdb/macrotab.c
index 65bf8fd382a..78fa2bb7315 100644
--- a/gdb/macrotab.c
+++ b/gdb/macrotab.c
@@ -87,8 +87,14 @@ macro_alloc (int size, struct macro_table *t)
static void
macro_free (void *object, struct macro_table *t)
{
- gdb_assert (! t->obstack);
- xfree (object);
+ if (t->obstack)
+ /* There are cases where we need to remove entries from a macro
+ table, even when reading debugging information. This should be
+ rare, and there's no easy way to free arbitrary data from an
+ obstack, so we just leak it. */
+ ;
+ else
+ xfree (object);
}
@@ -120,12 +126,18 @@ macro_bcache_str (struct macro_table *t, const char *s)
/* Free a possibly bcached object OBJ. That is, if the macro table T
- has a bcache, it's an error; otherwise, xfree OBJ. */
+ has a bcache, do nothing; otherwise, xfree OBJ. */
static void
macro_bcache_free (struct macro_table *t, void *obj)
{
- gdb_assert (! t->bcache);
- xfree (obj);
+ if (t->bcache)
+ /* There are cases where we need to remove entries from a macro
+ table, even when reading debugging information. This should be
+ rare, and there's no easy way to free data from a bcache, so we
+ just leak it. */
+ ;
+ else
+ xfree (obj);
}
@@ -781,25 +793,39 @@ macro_undef (struct macro_source_file *source, int line,
if (n)
{
- /* This function is the only place a macro's end-of-scope
- location gets set to anything other than "end of the
- compilation unit" (i.e., end_file is zero). So if this macro
- already has its end-of-scope set, then we're probably seeing
- a second #undefinition for the same #definition. */
struct macro_key *key = (struct macro_key *) n->key;
- if (key->end_file)
+ /* If we're removing a definition at exactly the same point that
+ we defined it, then just delete the entry altogether. GCC
+ 4.1.2 will generate DWARF that says to do this if you pass it
+ arguments like '-DFOO -UFOO -DFOO=2'. */
+ if (source == key->start_file
+ && line == key->start_line)
+ splay_tree_remove (source->table->definitions, n->key);
+
+ else
{
- complaint (&symfile_complaints,
- _("macro '%s' is #undefined twice, at %s:%d and %s:%d"), name,
- source->filename, line, key->end_file->filename,
- key->end_line);
- }
+ /* This function is the only place a macro's end-of-scope
+ location gets set to anything other than "end of the
+ compilation unit" (i.e., end_file is zero). So if this
+ macro already has its end-of-scope set, then we're
+ probably seeing a second #undefinition for the same
+ #definition. */
+ if (key->end_file)
+ {
+ complaint (&symfile_complaints,
+ _("macro '%s' is #undefined twice,"
+ " at %s:%d and %s:%d"),
+ name,
+ source->filename, line,
+ key->end_file->filename, key->end_line);
+ }
- /* Whatever the case, wipe out the old ending point, and
- make this the ending point. */
- key->end_file = source;
- key->end_line = line;
+ /* Whether or not we've seen a prior #undefinition, wipe out
+ the old ending point, and make this the ending point. */
+ key->end_file = source;
+ key->end_line = line;
+ }
}
else
{