Chapter 11.
C Preprocessor Macros
Some languages, such as C and C++, provide a way to define and invoke "preprocessor macros" which
expand into strings of tokens. gdb can evaluate expressions containing macro invocations, show the
result of macro expansion, and show a macro’s definition, including where it was defined.
You may need to compile your program specially to provide gdb with information about preproces-
sor macros. Most compilers do not include macros in their debugging information, even when you
compile with the
-g
flag. Refer to Section 6.1
Compiling for debugging
.
A program may define a macro at one point, remove that definition later, and then provide a different
definition after that. Thus, at different points in the program, a macro may have different definitions, or
have no definition at all. If there is a current stack frame, gdb uses the macros in scope at that frame’s
source code line. Otherwise, gdb uses the macros in scope at the current listing location; (refer to
Section 9.1
Printing source lines
.
At the moment, gdb does not support the
##
token-splicing operator, the
#
stringification operator, or
variable-arity macros.
Whenever gdb evaluates an expression, it always expands any macro invocations present in the ex-
pression. gdb also provides the following commands for working with macros explicitly.
macro expand
expression
macro exp
expression
Show the results of expanding all preprocessor macro invocations in
expression
. Since gdb
simply expands macros, but does not parse the result,
expression
need not be a valid expres-
sion; it can be any string of tokens.
macro expand-once
expression
macro exp1
expression
(This command is not yet implemented.)
Show the results of expanding those preprocessor macro
invocations that appear explicitly in
expression
. Macro invocations appearing in that expan-
sion are left unchanged. This command allows you to see the effect of a particular macro more
clearly, without being confused by further expansions. Since gdb simply expands macros, but
does not parse the result,
expression
need not be a valid expression; it can be any string of
tokens.
info macro
macro
Show the definition of the macro named
macro
, and describe the source location where that
definition was established.
macro define
macro replacement-list
macro define
macro
(
arglist
)
replacement-list
(This command is not yet implemented.)
Introduce a definition for a preprocessor macro named
macro
, invocations of which are replaced by the tokens given in
replacement-list
. The first
form of this command defines an "object-like" macro, which takes no arguments; the second
form defines a "function-like" macro, which takes the arguments given in
arglist
.
A definition introduced by this command is in scope in every expression evaluated in gdb, until
it is removed with the
macro undef
command, described below. The definition overrides all
Содержание ENTERPRISE LINUX 4 - DEVELOPER TOOLS GUIDE
Страница 1: ...Red Hat Enterprise Linux 4 Debugging with gdb ...
Страница 12: ...2 Chapter 1 Debugging with gdb ...
Страница 28: ...18 Chapter 4 Getting In and Out of gdb ...
Страница 34: ...24 Chapter 5 gdb Commands ...
Страница 44: ...34 Chapter 6 Running Programs Under gdb ...
Страница 68: ...58 Chapter 8 Examining the Stack ...
Страница 98: ...88 Chapter 10 Examining Data ...
Страница 112: ...102 Chapter 12 Tracepoints ...
Страница 118: ...108 Chapter 13 Debugging Programs That Use Overlays ...
Страница 138: ...128 Chapter 14 Using gdb with Different Languages ...
Страница 144: ...134 Chapter 15 Examining the Symbol Table ...
Страница 170: ...160 Chapter 19 Debugging remote programs ...
Страница 198: ...188 Chapter 21 Controlling gdb ...
Страница 204: ...194 Chapter 22 Canned Sequences of Commands ...
Страница 206: ...196 Chapter 23 Command Interpreters ...
Страница 216: ...206 Chapter 25 Using gdb under gnu Emacs ...
Страница 296: ...286 Chapter 27 gdb Annotations ...
Страница 300: ...290 Chapter 28 Reporting Bugs in gdb ...
Страница 322: ...312 Chapter 30 Using History Interactively ...
Страница 362: ...352 Appendix D gdb Remote Serial Protocol ...
Страница 380: ...370 Appendix F GNU GENERAL PUBLIC LICENSE ...
Страница 386: ...376 Appendix G GNU Free Documentation License ...
Страница 410: ......