gdb: add target_ops::supports_displaced_step
[deliverable/binutils-gdb.git] / gdb / macroexp.h
1 /* Interface to C preprocessor macro expansion for GDB.
2 Copyright (C) 2002-2020 Free Software Foundation, Inc.
3 Contributed by Red Hat, Inc.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20
21 #ifndef MACROEXP_H
22 #define MACROEXP_H
23
24 /* A function for looking up preprocessor macro definitions. Return
25 the preprocessor definition of NAME in scope according to BATON, or
26 zero if NAME is not defined as a preprocessor macro.
27
28 The caller must not free or modify the definition returned. It is
29 probably unwise for the caller to hold pointers to it for very
30 long; it probably lives in some objfile's obstacks. */
31 typedef struct macro_definition *(macro_lookup_ftype) (const char *name,
32 void *baton);
33
34
35 /* Expand any preprocessor macros in SOURCE, and return the expanded
36 text. Use LOOKUP_FUNC and LOOKUP_FUNC_BATON to find identifiers'
37 preprocessor definitions. SOURCE is a null-terminated string. The
38 result is a null-terminated string, allocated using xmalloc; it is
39 the caller's responsibility to free it. */
40 gdb::unique_xmalloc_ptr<char> macro_expand (const char *source,
41 macro_lookup_ftype *lookup_func,
42 void *lookup_func_baton);
43
44
45 /* Expand all preprocessor macro references that appear explicitly in
46 SOURCE, but do not expand any new macro references introduced by
47 that first level of expansion. Use LOOKUP_FUNC and
48 LOOKUP_FUNC_BATON to find identifiers' preprocessor definitions.
49 SOURCE is a null-terminated string. The result is a
50 null-terminated string, allocated using xmalloc; it is the caller's
51 responsibility to free it. */
52 gdb::unique_xmalloc_ptr<char> macro_expand_once (const char *source,
53 macro_lookup_ftype *lookup_func,
54 void *lookup_func_baton);
55
56
57 /* If the null-terminated string pointed to by *LEXPTR begins with a
58 macro invocation, return the result of expanding that invocation as
59 a null-terminated string, and set *LEXPTR to the next character
60 after the invocation. The result is completely expanded; it
61 contains no further macro invocations.
62
63 Otherwise, if *LEXPTR does not start with a macro invocation,
64 return zero, and leave *LEXPTR unchanged.
65
66 Use LOOKUP_FUNC and LOOKUP_BATON to find macro definitions.
67
68 If this function returns a string, the caller is responsible for
69 freeing it, using xfree.
70
71 We need this expand-one-token-at-a-time interface in order to
72 accomodate GDB's C expression parser, which may not consume the
73 entire string. When the user enters a command like
74
75 (gdb) break *func+20 if x == 5
76
77 the parser is expected to consume `func+20', and then stop when it
78 sees the "if". But of course, "if" appearing in a character string
79 or as part of a larger identifier doesn't count. So you pretty
80 much have to do tokenization to find the end of the string that
81 needs to be macro-expanded. Our C/C++ tokenizer isn't really
82 designed to be called by anything but the yacc parser engine. */
83 char *macro_expand_next (const char **lexptr,
84 macro_lookup_ftype *lookup_func,
85 void *lookup_baton);
86
87 /* Functions to classify characters according to cpp rules. */
88
89 int macro_is_whitespace (int c);
90 int macro_is_identifier_nondigit (int c);
91 int macro_is_digit (int c);
92
93
94 /* Stringify STR according to C rules and return an xmalloc'd pointer
95 to the result. */
96
97 char *macro_stringify (const char *str);
98
99 #endif /* MACROEXP_H */
This page took 0.03085 seconds and 4 git commands to generate.