/* C preprocessor macro expansion for GDB.
- Copyright (C) 2002, 2007, 2008, 2009, 2010, 2011
- Free Software Foundation, Inc.
+ Copyright (C) 2002-2013 Free Software Foundation, Inc.
Contributed by Red Hat, Inc.
This file is part of GDB.
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
&& p[1] == '\''))
{
char *tok_start = p;
- char *body_start;
int char_count = 0;
if (*p == '\'')
else
gdb_assert_not_reached ("unexpected character constant");
- body_start = p;
for (;;)
{
if (p >= end)
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))
dest->last_token = dest->len;
}
+/* See macroexp.h. */
+
+char *
+macro_stringify (const char *str)
+{
+ struct macro_buffer buffer;
+ int len = strlen (str);
+
+ init_buffer (&buffer, len);
+ stringify (&buffer, str, len);
+ appendc (&buffer, '\0');
+
+ return free_buffer_return_text (&buffer);
+}
+
\f
/* Expanding macros! */
struct macro_buffer *argv = NULL;
struct macro_buffer substituted;
struct macro_buffer substituted_src;
- struct macro_buffer va_arg_name;
+ struct macro_buffer va_arg_name = {0};
int is_varargs = 0;
if (def->argc >= 1)