aboutsummaryrefslogtreecommitdiff
path: root/gdb/macrotab.c
diff options
context:
space:
mode:
authorTom Tromey <tromey@redhat.com>2012-05-16 20:31:10 +0000
committerTom Tromey <tromey@redhat.com>2012-05-16 20:31:10 +0000
commitabc9d0dc6edeeabbd65fedb43cf840875156da91 (patch)
tree6af9437622479beefdff726b65ee0880edb7d549 /gdb/macrotab.c
parent7537bd464b5c7aaa08b67e53f38403551ef5605d (diff)
downloadgdb-abc9d0dc6edeeabbd65fedb43cf840875156da91.zip
gdb-abc9d0dc6edeeabbd65fedb43cf840875156da91.tar.gz
gdb-abc9d0dc6edeeabbd65fedb43cf840875156da91.tar.bz2
PR macros/13205:
* macrotab.h: (macro_define_special): Declare. (enum macro_special_kind): New. (struct macro_definition) <argc, replacement>: Update comments. * macrotab.c (new_macro_definition): Unconditionally set 'argc'. (macro_define_object_internal): New function. (macro_define_object): Use it. (macro_define_special): New function. (fixup_definition): New function. (macro_lookup_definition, foreach_macro_in_scope) (foreach_macro): Use fixup_definition. * macroexp.h (macro_stringify): Declare. * macroexp.c (free_buffer_return_text): New function. (stringify): Constify "arg". (macro_stringify): New function. * dwarf2read.c (macro_start_file): Call macro_define_special. testsuite * gdb.base/macscp1.c (macscp_expr): Add comment. * gdb.base/macscp.exp: Test __FILE__ and __LINE__.
Diffstat (limited to 'gdb/macrotab.c')
-rw-r--r--gdb/macrotab.c72
1 files changed, 64 insertions, 8 deletions
diff --git a/gdb/macrotab.c b/gdb/macrotab.c
index 7428839..e65e5dc 100644
--- a/gdb/macrotab.c
+++ b/gdb/macrotab.c
@@ -28,6 +28,7 @@
#include "gdb_assert.h"
#include "bcache.h"
#include "complaints.h"
+#include "macroexp.h"
/* The macro table structure. */
@@ -565,6 +566,7 @@ new_macro_definition (struct macro_table *t,
d->table = t;
d->kind = kind;
d->replacement = macro_bcache_str (t, replacement);
+ d->argc = argc;
if (kind == macro_function_like)
{
@@ -579,7 +581,6 @@ new_macro_definition (struct macro_table *t,
/* Now bcache the array of argument pointers itself. */
d->argv = macro_bcache (t, cached_argv, cached_argv_size);
- d->argc = argc;
}
/* We don't bcache the entire definition structure because it's got
@@ -742,10 +743,12 @@ check_for_redefinition (struct macro_source_file *source, int line,
return 0;
}
+/* A helper function to define a new object-like macro. */
-void
-macro_define_object (struct macro_source_file *source, int line,
- const char *name, const char *replacement)
+static void
+macro_define_object_internal (struct macro_source_file *source, int line,
+ const char *name, const char *replacement,
+ enum macro_special_kind kind)
{
struct macro_table *t = source->table;
struct macro_key *k = NULL;
@@ -771,10 +774,28 @@ macro_define_object (struct macro_source_file *source, int line,
return;
k = new_macro_key (t, name, source, line);
- d = new_macro_definition (t, macro_object_like, 0, 0, replacement);
+ d = new_macro_definition (t, macro_object_like, kind, 0, replacement);
splay_tree_insert (t->definitions, (splay_tree_key) k, (splay_tree_value) d);
}
+void
+macro_define_object (struct macro_source_file *source, int line,
+ const char *name, const char *replacement)
+{
+ macro_define_object_internal (source, line, name, replacement,
+ macro_ordinary);
+}
+
+/* See macrotab.h. */
+
+void
+macro_define_special (struct macro_table *table)
+{
+ macro_define_object_internal (table->main_source, -1, "__FILE__", "",
+ macro_FILE);
+ macro_define_object_internal (table->main_source, -1, "__LINE__", "",
+ macro_LINE);
+}
void
macro_define_function (struct macro_source_file *source, int line,
@@ -859,6 +880,36 @@ macro_undef (struct macro_source_file *source, int line,
}
}
+/* A helper function that rewrites the definition of a special macro,
+ when needed. */
+
+static struct macro_definition *
+fixup_definition (const char *filename, int line, struct macro_definition *def)
+{
+ static char *saved_expansion;
+
+ if (saved_expansion)
+ {
+ xfree (saved_expansion);
+ saved_expansion = NULL;
+ }
+
+ if (def->kind == macro_object_like)
+ {
+ if (def->argc == macro_FILE)
+ {
+ saved_expansion = macro_stringify (filename);
+ def->replacement = saved_expansion;
+ }
+ else if (def->argc == macro_LINE)
+ {
+ saved_expansion = xstrprintf ("%d", line);
+ def->replacement = saved_expansion;
+ }
+ }
+
+ return def;
+}
struct macro_definition *
macro_lookup_definition (struct macro_source_file *source,
@@ -867,7 +918,8 @@ macro_lookup_definition (struct macro_source_file *source,
splay_tree_node n = find_definition (name, source, line);
if (n)
- return (struct macro_definition *) n->value;
+ return fixup_definition (source->filename, line,
+ (struct macro_definition *) n->value);
else
return 0;
}
@@ -910,7 +962,9 @@ foreach_macro (splay_tree_node node, void *arg)
{
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 = (struct macro_definition *) node->value;
+ struct macro_definition *def
+ = fixup_definition (key->start_file->filename, key->start_line,
+ (struct macro_definition *) node->value);
(*datum->fn) (key->name, def, key->start_file, key->start_line,
datum->user_data);
@@ -936,7 +990,9 @@ foreach_macro_in_scope (splay_tree_node node, void *info)
{
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 = (struct macro_definition *) node->value;
+ struct macro_definition *def
+ = fixup_definition (datum->file->filename, datum->line,
+ (struct macro_definition *) node->value);
/* See if this macro is defined before the passed-in line, and
extends past that line. */