Red Hat ENTERPRISE LINUX 3 - DEBUGGING WITH GDB Manual page 101

Debugging with gdb
Hide thumbs Also See for ENTERPRISE LINUX 3 - DEBUGGING WITH GDB:
Table of Contents

Advertisement

Chapter 11. C Preprocessor Macros
8
{
9
#define N 28
10
printf ("Hello, world!\n");
11
#undef N
12
printf ("We're so creative.\n");
(gdb) info macro ADD
Defined at /home/jimb/gdb/macros/play/sample.c:5
#define ADD(x) (M + x)
(gdb) info macro Q
Defined at /home/jimb/gdb/macros/play/sample.h:1
included at /home/jimb/gdb/macros/play/sample.c:2
#define Q
(gdb) macro expand ADD(1)
expands to: (42 + 1)
(gdb) macro expand-once ADD(1)
expands to: once (M + 1)
(gdb)
In the example above, note that
the original text -- the invocation of
was introduced by
ADD
Once the program is running, GDB uses the macro definitions in force at the source line of the current
stack frame:
(gdb) break main
Breakpoint 1 at 0x8048370: file sample.c, line 10.
(gdb) run
Starting program: /home/jimb/gdb/macros/play/sample
Breakpoint 1, main () at sample.c:10
10
printf ("Hello, world!\n");
(gdb)
At line 10, the definition of the macro
(gdb) info macro N
Defined at /home/jimb/gdb/macros/play/sample.c:9
#define N 28
(gdb) macro expand N Q M
expands to: 28
(gdb) print N Q M
$1 = 1
(gdb)
As we step over directives that remove
definition (or lack thereof) in force at each point:
(gdb) next
Hello, world!
12
printf ("We're so creative.\n");
(gdb) info macro N
The symbol 'N' has no definition as a C/C++ preprocessor macro
at /home/jimb/gdb/macros/play/sample.c:12
(gdb) next
macro expand-once
-- but does not expand the invocation of the macro
ADD
.
at line 9 is in force:
N
42
's definition, and then give it a new definition, gdb finds the
N
expands only the macro invocation explicit in
91
, which
M

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the ENTERPRISE LINUX 3 - DEBUGGING WITH GDB and is the answer not in the manual?

Questions and answers

Table of Contents