X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=gdb%2Fmacroexp.c;h=0faa07fe61635f654347cb3b305763c81a64bb88;hb=0ea5cda8612bd2233f7a2f9d1eba0b62c2e6c015;hp=d5e4e40326301b36fb1d4cfd2cc602c08d0933f5;hpb=0b30217134add051e159a192066a1e568ebd837f;p=deliverable%2Fbinutils-gdb.git diff --git a/gdb/macroexp.c b/gdb/macroexp.c index d5e4e40326..0faa07fe61 100644 --- a/gdb/macroexp.c +++ b/gdb/macroexp.c @@ -1,5 +1,5 @@ /* C preprocessor macro expansion for GDB. - Copyright (C) 2002, 2007-2012 Free Software Foundation, Inc. + Copyright (C) 2002-2014 Free Software Foundation, Inc. Contributed by Red Hat, Inc. This file is part of GDB. @@ -22,7 +22,6 @@ #include "bcache.h" #include "macrotab.h" #include "macroexp.h" -#include "gdb_assert.h" #include "c-lang.h" @@ -113,6 +112,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 @@ -326,7 +336,6 @@ get_character_constant (struct macro_buffer *tok, char *p, char *end) && p[1] == '\'')) { char *tok_start = p; - char *body_start; int char_count = 0; if (*p == '\'') @@ -336,7 +345,6 @@ get_character_constant (struct macro_buffer *tok, char *p, char *end) else gdb_assert_not_reached ("unexpected character constant"); - body_start = p; for (;;) { if (p >= end) @@ -351,8 +359,11 @@ get_character_constant (struct macro_buffer *tok, char *p, char *end) } else if (*p == '\\') { - p++; - char_count += c_parse_escape (&p, NULL); + const char *s, *o; + + s = o = ++p; + char_count += c_parse_escape (&s, NULL); + p += s - o; } else { @@ -405,8 +416,11 @@ get_string_literal (struct macro_buffer *tok, char *p, char *end) "constants.")); else if (*p == '\\') { - p++; - c_parse_escape (&p, NULL); + const char *s, *o; + + s = o = ++p; + c_parse_escape (&s, NULL); + p += s - o; } else p++; @@ -639,7 +653,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 +696,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); + + init_buffer (&buffer, len); + stringify (&buffer, str, len); + appendc (&buffer, '\0'); + + return free_buffer_return_text (&buffer); +} + /* Expanding macros! */ @@ -1410,7 +1439,7 @@ macro_expand_once (const char *source, char * -macro_expand_next (char **lexptr, +macro_expand_next (const char **lexptr, macro_lookup_ftype *lookup_func, void *lookup_baton) { @@ -1418,7 +1447,7 @@ macro_expand_next (char **lexptr, struct cleanup *back_to; /* Set up SRC to refer to the input text, pointed to by *lexptr. */ - init_shared_buffer (&src, *lexptr, strlen (*lexptr)); + init_shared_buffer (&src, (char *) *lexptr, strlen (*lexptr)); /* Set up DEST to receive the expansion, if there is one. */ init_buffer (&dest, 0);