aboutsummaryrefslogtreecommitdiff
path: root/gdb/macroexp.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/macroexp.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/macroexp.c')
-rw-r--r--gdb/macroexp.c28
1 files changed, 27 insertions, 1 deletions
diff --git a/gdb/macroexp.c b/gdb/macroexp.c
index d5e4e40..22b904e 100644
--- a/gdb/macroexp.c
+++ b/gdb/macroexp.c
@@ -113,6 +113,17 @@ free_buffer (struct macro_buffer *b)
xfree (b->text);
}
+/* Like free_buffer, but return the text as an xstrdup()d string.
+ This only exists to try to make the API relatively clean. */
+
+static char *
+free_buffer_return_text (struct macro_buffer *b)
+{
+ gdb_assert (! b->shared);
+ gdb_assert (b->size);
+ /* Nothing to do. */
+ return b->text;
+}
/* A cleanup function for macro buffers. */
static void
@@ -639,7 +650,7 @@ append_tokens_without_splicing (struct macro_buffer *dest,
stringify; it is LEN bytes long. */
static void
-stringify (struct macro_buffer *dest, char *arg, int len)
+stringify (struct macro_buffer *dest, const char *arg, int len)
{
/* Trim initial whitespace from ARG. */
while (len > 0 && macro_is_whitespace (*arg))
@@ -682,6 +693,21 @@ stringify (struct macro_buffer *dest, char *arg, int len)
dest->last_token = dest->len;
}
+/* See macroexp.h. */
+
+char *
+macro_stringify (const char *str)
+{
+ struct macro_buffer buffer;
+ int len = strlen (str);
+ char *result;
+
+ init_buffer (&buffer, len);
+ stringify (&buffer, str, len);
+
+ return free_buffer_return_text (&buffer);
+}
+
/* Expanding macros! */