gdb/macroexp.h - gdb

Data types defined

Macros defined

Source code

  1. /* Interface to C preprocessor macro expansion for GDB.
  2.    Copyright (C) 2002-2015 Free Software Foundation, Inc.
  3.    Contributed by Red Hat, Inc.

  4.    This file is part of GDB.

  5.    This program is free software; you can redistribute it and/or modify
  6.    it under the terms of the GNU General Public License as published by
  7.    the Free Software Foundation; either version 3 of the License, or
  8.    (at your option) any later version.

  9.    This program is distributed in the hope that it will be useful,
  10.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.    GNU General Public License for more details.

  13.    You should have received a copy of the GNU General Public License
  14.    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */


  15. #ifndef MACROEXP_H
  16. #define MACROEXP_H

  17. /* A function for looking up preprocessor macro definitions.  Return
  18.    the preprocessor definition of NAME in scope according to BATON, or
  19.    zero if NAME is not defined as a preprocessor macro.

  20.    The caller must not free or modify the definition returned.  It is
  21.    probably unwise for the caller to hold pointers to it for very
  22.    long; it probably lives in some objfile's obstacks.  */
  23. typedef struct macro_definition *(macro_lookup_ftype) (const char *name,
  24.                                                        void *baton);


  25. /* Expand any preprocessor macros in SOURCE, and return the expanded
  26.    text.  Use LOOKUP_FUNC and LOOKUP_FUNC_BATON to find identifiers'
  27.    preprocessor definitions.  SOURCE is a null-terminated string.  The
  28.    result is a null-terminated string, allocated using xmalloc; it is
  29.    the caller's responsibility to free it.  */
  30. char *macro_expand (const char *source,
  31.                     macro_lookup_ftype *lookup_func,
  32.                     void *lookup_func_baton);


  33. /* Expand all preprocessor macro references that appear explicitly in
  34.    SOURCE, but do not expand any new macro references introduced by
  35.    that first level of expansion.  Use LOOKUP_FUNC and
  36.    LOOKUP_FUNC_BATON to find identifiers' preprocessor definitions.
  37.    SOURCE is a null-terminated string.  The result is a
  38.    null-terminated string, allocated using xmalloc; it is the caller's
  39.    responsibility to free it.  */
  40. char *macro_expand_once (const char *source,
  41.                          macro_lookup_ftype *lookup_func,
  42.                          void *lookup_func_baton);


  43. /* If the null-terminated string pointed to by *LEXPTR begins with a
  44.    macro invocation, return the result of expanding that invocation as
  45.    a null-terminated string, and set *LEXPTR to the next character
  46.    after the invocation.  The result is completely expanded; it
  47.    contains no further macro invocations.

  48.    Otherwise, if *LEXPTR does not start with a macro invocation,
  49.    return zero, and leave *LEXPTR unchanged.

  50.    Use LOOKUP_FUNC and LOOKUP_BATON to find macro definitions.

  51.    If this function returns a string, the caller is responsible for
  52.    freeing it, using xfree.

  53.    We need this expand-one-token-at-a-time interface in order to
  54.    accomodate GDB's C expression parser, which may not consume the
  55.    entire string.  When the user enters a command like

  56.       (gdb) break *func+20 if x == 5

  57.    the parser is expected to consume `func+20', and then stop when it
  58.    sees the "if".  But of course, "if" appearing in a character string
  59.    or as part of a larger identifier doesn't count.  So you pretty
  60.    much have to do tokenization to find the end of the string that
  61.    needs to be macro-expanded.  Our C/C++ tokenizer isn't really
  62.    designed to be called by anything but the yacc parser engine.  */
  63. char *macro_expand_next (const char **lexptr,
  64.                          macro_lookup_ftype *lookup_func,
  65.                          void *lookup_baton);

  66. /* Functions to classify characters according to cpp rules.  */

  67. int macro_is_whitespace (int c);
  68. int macro_is_identifier_nondigit (int c);
  69. int macro_is_digit (int c);


  70. /* Stringify STR according to C rules and return an xmalloc'd pointer
  71.    to the result.  */

  72. char *macro_stringify (const char *str);

  73. #endif /* MACROEXP_H */