1 |
578 |
markom |
This is ./gdb.info, produced by makeinfo version 4.0 from gdb.texinfo.
|
2 |
|
|
|
3 |
|
|
INFO-DIR-SECTION Programming & development tools.
|
4 |
|
|
START-INFO-DIR-ENTRY
|
5 |
|
|
* Gdb: (gdb). The GNU debugger.
|
6 |
|
|
END-INFO-DIR-ENTRY
|
7 |
|
|
|
8 |
|
|
This file documents the GNU debugger GDB.
|
9 |
|
|
|
10 |
|
|
This is the Ninth Edition, April 2001, of `Debugging with GDB: the
|
11 |
|
|
GNU Source-Level Debugger' for GDB Version 20010707.
|
12 |
|
|
|
13 |
|
|
Copyright (C)
|
14 |
|
|
1988,1989,1990,1991,1992,1993,1994,1995,1996,1998,1999,2000,2001
|
15 |
|
|
Free Software Foundation, Inc.
|
16 |
|
|
|
17 |
|
|
Permission is granted to copy, distribute and/or modify this document
|
18 |
|
|
under the terms of the GNU Free Documentation License, Version 1.1 or
|
19 |
|
|
any later version published by the Free Software Foundation; with the
|
20 |
|
|
Invariant Sections being "A Sample GDB Session" and "Free Software",
|
21 |
|
|
with the Front-Cover texts being "A GNU Manual," and with the
|
22 |
|
|
Back-Cover Texts as in (a) below.
|
23 |
|
|
|
24 |
|
|
(a) The FSF's Back-Cover Text is: "You have freedom to copy and
|
25 |
|
|
modify this GNU Manual, like GNU software. Copies published by the Free
|
26 |
|
|
Software Foundation raise funds for GNU development."
|
27 |
|
|
|
28 |
|
|
|
29 |
|
|
File: gdb.info, Node: Tracepoint Actions, Next: Listing Tracepoints, Prev: Tracepoint Passcounts, Up: Set Tracepoints
|
30 |
|
|
|
31 |
|
|
Tracepoint Action Lists
|
32 |
|
|
-----------------------
|
33 |
|
|
|
34 |
|
|
`actions [NUM]'
|
35 |
|
|
This command will prompt for a list of actions to be taken when the
|
36 |
|
|
tracepoint is hit. If the tracepoint number NUM is not specified,
|
37 |
|
|
this command sets the actions for the one that was most recently
|
38 |
|
|
defined (so that you can define a tracepoint and then say
|
39 |
|
|
`actions' without bothering about its number). You specify the
|
40 |
|
|
actions themselves on the following lines, one action at a time,
|
41 |
|
|
and terminate the actions list with a line containing just `end'.
|
42 |
|
|
So far, the only defined actions are `collect' and
|
43 |
|
|
`while-stepping'.
|
44 |
|
|
|
45 |
|
|
To remove all actions from a tracepoint, type `actions NUM' and
|
46 |
|
|
follow it immediately with `end'.
|
47 |
|
|
|
48 |
|
|
(gdb) collect DATA // collect some data
|
49 |
|
|
|
50 |
|
|
(gdb) while-stepping 5 // single-step 5 times and collect data
|
51 |
|
|
|
52 |
|
|
(gdb) end // signals the end of actions.
|
53 |
|
|
|
54 |
|
|
In the following example, the action list begins with `collect'
|
55 |
|
|
commands indicating the things to be collected when the tracepoint
|
56 |
|
|
is hit. Then, in order to single-step and collect additional data
|
57 |
|
|
following the tracepoint, a `while-stepping' command is used,
|
58 |
|
|
followed by the list of things to be collected while stepping. The
|
59 |
|
|
`while-stepping' command is terminated by its own separate `end'
|
60 |
|
|
command. Lastly, the action list is terminated by an `end'
|
61 |
|
|
command.
|
62 |
|
|
|
63 |
|
|
(gdb) trace foo
|
64 |
|
|
(gdb) actions
|
65 |
|
|
Enter actions for tracepoint 1, one per line:
|
66 |
|
|
> collect bar,baz
|
67 |
|
|
> collect $regs
|
68 |
|
|
> while-stepping 12
|
69 |
|
|
> collect $fp, $sp
|
70 |
|
|
> end
|
71 |
|
|
end
|
72 |
|
|
|
73 |
|
|
`collect EXPR1, EXPR2, ...'
|
74 |
|
|
Collect values of the given expressions when the tracepoint is hit.
|
75 |
|
|
This command accepts a comma-separated list of any valid
|
76 |
|
|
expressions. In addition to global, static, or local variables,
|
77 |
|
|
the following special arguments are supported:
|
78 |
|
|
|
79 |
|
|
`$regs'
|
80 |
|
|
collect all registers
|
81 |
|
|
|
82 |
|
|
`$args'
|
83 |
|
|
collect all function arguments
|
84 |
|
|
|
85 |
|
|
`$locals'
|
86 |
|
|
collect all local variables.
|
87 |
|
|
|
88 |
|
|
You can give several consecutive `collect' commands, each one with
|
89 |
|
|
a single argument, or one `collect' command with several arguments
|
90 |
|
|
separated by commas: the effect is the same.
|
91 |
|
|
|
92 |
|
|
The command `info scope' (*note info scope: Symbols.) is
|
93 |
|
|
particularly useful for figuring out what data to collect.
|
94 |
|
|
|
95 |
|
|
`while-stepping N'
|
96 |
|
|
Perform N single-step traces after the tracepoint, collecting new
|
97 |
|
|
data at each step. The `while-stepping' command is followed by
|
98 |
|
|
the list of what to collect while stepping (followed by its own
|
99 |
|
|
`end' command):
|
100 |
|
|
|
101 |
|
|
> while-stepping 12
|
102 |
|
|
> collect $regs, myglobal
|
103 |
|
|
> end
|
104 |
|
|
>
|
105 |
|
|
|
106 |
|
|
You may abbreviate `while-stepping' as `ws' or `stepping'.
|
107 |
|
|
|
108 |
|
|
|
109 |
|
|
File: gdb.info, Node: Listing Tracepoints, Next: Starting and Stopping Trace Experiment, Prev: Tracepoint Actions, Up: Set Tracepoints
|
110 |
|
|
|
111 |
|
|
Listing Tracepoints
|
112 |
|
|
-------------------
|
113 |
|
|
|
114 |
|
|
`info tracepoints [NUM]'
|
115 |
|
|
Display information the tracepoint NUM. If you don't specify a
|
116 |
|
|
tracepoint number displays information about all the tracepoints
|
117 |
|
|
defined so far. For each tracepoint, the following information is
|
118 |
|
|
shown:
|
119 |
|
|
|
120 |
|
|
* its number
|
121 |
|
|
|
122 |
|
|
* whether it is enabled or disabled
|
123 |
|
|
|
124 |
|
|
* its address
|
125 |
|
|
|
126 |
|
|
* its passcount as given by the `passcount N' command
|
127 |
|
|
|
128 |
|
|
* its step count as given by the `while-stepping N' command
|
129 |
|
|
|
130 |
|
|
* where in the source files is the tracepoint set
|
131 |
|
|
|
132 |
|
|
* its action list as given by the `actions' command
|
133 |
|
|
|
134 |
|
|
(gdb) info trace
|
135 |
|
|
Num Enb Address PassC StepC What
|
136 |
|
|
1 y 0x002117c4 0 0
|
137 |
|
|
2 y 0x0020dc64 0 0 in gdb_test at gdb_test.c:375
|
138 |
|
|
3 y 0x0020b1f4 0 0 in collect_data at ../foo.c:1741
|
139 |
|
|
(gdb)
|
140 |
|
|
|
141 |
|
|
This command can be abbreviated `info tp'.
|
142 |
|
|
|
143 |
|
|
|
144 |
|
|
File: gdb.info, Node: Starting and Stopping Trace Experiment, Prev: Listing Tracepoints, Up: Set Tracepoints
|
145 |
|
|
|
146 |
|
|
Starting and Stopping Trace Experiment
|
147 |
|
|
--------------------------------------
|
148 |
|
|
|
149 |
|
|
`tstart'
|
150 |
|
|
This command takes no arguments. It starts the trace experiment,
|
151 |
|
|
and begins collecting data. This has the side effect of
|
152 |
|
|
discarding all the data collected in the trace buffer during the
|
153 |
|
|
previous trace experiment.
|
154 |
|
|
|
155 |
|
|
`tstop'
|
156 |
|
|
This command takes no arguments. It ends the trace experiment, and
|
157 |
|
|
stops collecting data.
|
158 |
|
|
|
159 |
|
|
*Note:* a trace experiment and data collection may stop
|
160 |
|
|
automatically if any tracepoint's passcount is reached (*note
|
161 |
|
|
Tracepoint Passcounts::), or if the trace buffer becomes full.
|
162 |
|
|
|
163 |
|
|
`tstatus'
|
164 |
|
|
This command displays the status of the current trace data
|
165 |
|
|
collection.
|
166 |
|
|
|
167 |
|
|
Here is an example of the commands we described so far:
|
168 |
|
|
|
169 |
|
|
(gdb) trace gdb_c_test
|
170 |
|
|
(gdb) actions
|
171 |
|
|
Enter actions for tracepoint #1, one per line.
|
172 |
|
|
> collect $regs,$locals,$args
|
173 |
|
|
> while-stepping 11
|
174 |
|
|
> collect $regs
|
175 |
|
|
> end
|
176 |
|
|
> end
|
177 |
|
|
(gdb) tstart
|
178 |
|
|
[time passes ...]
|
179 |
|
|
(gdb) tstop
|
180 |
|
|
|
181 |
|
|
|
182 |
|
|
File: gdb.info, Node: Analyze Collected Data, Next: Tracepoint Variables, Prev: Set Tracepoints, Up: Tracepoints
|
183 |
|
|
|
184 |
|
|
Using the collected data
|
185 |
|
|
========================
|
186 |
|
|
|
187 |
|
|
After the tracepoint experiment ends, you use GDB commands for
|
188 |
|
|
examining the trace data. The basic idea is that each tracepoint
|
189 |
|
|
collects a trace "snapshot" every time it is hit and another snapshot
|
190 |
|
|
every time it single-steps. All these snapshots are consecutively
|
191 |
|
|
numbered from zero and go into a buffer, and you can examine them
|
192 |
|
|
later. The way you examine them is to "focus" on a specific trace
|
193 |
|
|
snapshot. When the remote stub is focused on a trace snapshot, it will
|
194 |
|
|
respond to all GDB requests for memory and registers by reading from
|
195 |
|
|
the buffer which belongs to that snapshot, rather than from _real_
|
196 |
|
|
memory or registers of the program being debugged. This means that
|
197 |
|
|
*all* GDB commands (`print', `info registers', `backtrace', etc.) will
|
198 |
|
|
behave as if we were currently debugging the program state as it was
|
199 |
|
|
when the tracepoint occurred. Any requests for data that are not in
|
200 |
|
|
the buffer will fail.
|
201 |
|
|
|
202 |
|
|
* Menu:
|
203 |
|
|
|
204 |
|
|
* tfind:: How to select a trace snapshot
|
205 |
|
|
* tdump:: How to display all data for a snapshot
|
206 |
|
|
* save-tracepoints:: How to save tracepoints for a future run
|
207 |
|
|
|
208 |
|
|
|
209 |
|
|
File: gdb.info, Node: tfind, Next: tdump, Up: Analyze Collected Data
|
210 |
|
|
|
211 |
|
|
`tfind N'
|
212 |
|
|
---------
|
213 |
|
|
|
214 |
|
|
The basic command for selecting a trace snapshot from the buffer is
|
215 |
|
|
`tfind N', which finds trace snapshot number N, counting from zero. If
|
216 |
|
|
no argument N is given, the next snapshot is selected.
|
217 |
|
|
|
218 |
|
|
Here are the various forms of using the `tfind' command.
|
219 |
|
|
|
220 |
|
|
`tfind start'
|
221 |
|
|
Find the first snapshot in the buffer. This is a synonym for
|
222 |
|
|
`tfind 0' (since 0 is the number of the first snapshot).
|
223 |
|
|
|
224 |
|
|
`tfind none'
|
225 |
|
|
Stop debugging trace snapshots, resume _live_ debugging.
|
226 |
|
|
|
227 |
|
|
`tfind end'
|
228 |
|
|
Same as `tfind none'.
|
229 |
|
|
|
230 |
|
|
`tfind'
|
231 |
|
|
No argument means find the next trace snapshot.
|
232 |
|
|
|
233 |
|
|
`tfind -'
|
234 |
|
|
Find the previous trace snapshot before the current one. This
|
235 |
|
|
permits retracing earlier steps.
|
236 |
|
|
|
237 |
|
|
`tfind tracepoint NUM'
|
238 |
|
|
Find the next snapshot associated with tracepoint NUM. Search
|
239 |
|
|
proceeds forward from the last examined trace snapshot. If no
|
240 |
|
|
argument NUM is given, it means find the next snapshot collected
|
241 |
|
|
for the same tracepoint as the current snapshot.
|
242 |
|
|
|
243 |
|
|
`tfind pc ADDR'
|
244 |
|
|
Find the next snapshot associated with the value ADDR of the
|
245 |
|
|
program counter. Search proceeds forward from the last examined
|
246 |
|
|
trace snapshot. If no argument ADDR is given, it means find the
|
247 |
|
|
next snapshot with the same value of PC as the current snapshot.
|
248 |
|
|
|
249 |
|
|
`tfind outside ADDR1, ADDR2'
|
250 |
|
|
Find the next snapshot whose PC is outside the given range of
|
251 |
|
|
addresses.
|
252 |
|
|
|
253 |
|
|
`tfind range ADDR1, ADDR2'
|
254 |
|
|
Find the next snapshot whose PC is between ADDR1 and ADDR2.
|
255 |
|
|
|
256 |
|
|
`tfind line [FILE:]N'
|
257 |
|
|
Find the next snapshot associated with the source line N. If the
|
258 |
|
|
optional argument FILE is given, refer to line N in that source
|
259 |
|
|
file. Search proceeds forward from the last examined trace
|
260 |
|
|
snapshot. If no argument N is given, it means find the next line
|
261 |
|
|
other than the one currently being examined; thus saying `tfind
|
262 |
|
|
line' repeatedly can appear to have the same effect as stepping
|
263 |
|
|
from line to line in a _live_ debugging session.
|
264 |
|
|
|
265 |
|
|
The default arguments for the `tfind' commands are specifically
|
266 |
|
|
designed to make it easy to scan through the trace buffer. For
|
267 |
|
|
instance, `tfind' with no argument selects the next trace snapshot, and
|
268 |
|
|
`tfind -' with no argument selects the previous trace snapshot. So, by
|
269 |
|
|
giving one `tfind' command, and then simply hitting repeatedly
|
270 |
|
|
you can examine all the trace snapshots in order. Or, by saying `tfind
|
271 |
|
|
-' and then hitting repeatedly you can examine the snapshots in
|
272 |
|
|
reverse order. The `tfind line' command with no argument selects the
|
273 |
|
|
snapshot for the next source line executed. The `tfind pc' command with
|
274 |
|
|
no argument selects the next snapshot with the same program counter
|
275 |
|
|
(PC) as the current frame. The `tfind tracepoint' command with no
|
276 |
|
|
argument selects the next trace snapshot collected by the same
|
277 |
|
|
tracepoint as the current one.
|
278 |
|
|
|
279 |
|
|
In addition to letting you scan through the trace buffer manually,
|
280 |
|
|
these commands make it easy to construct GDB scripts that scan through
|
281 |
|
|
the trace buffer and print out whatever collected data you are
|
282 |
|
|
interested in. Thus, if we want to examine the PC, FP, and SP
|
283 |
|
|
registers from each trace frame in the buffer, we can say this:
|
284 |
|
|
|
285 |
|
|
(gdb) tfind start
|
286 |
|
|
(gdb) while ($trace_frame != -1)
|
287 |
|
|
> printf "Frame %d, PC = %08X, SP = %08X, FP = %08X\n", \
|
288 |
|
|
$trace_frame, $pc, $sp, $fp
|
289 |
|
|
> tfind
|
290 |
|
|
> end
|
291 |
|
|
|
292 |
|
|
Frame 0, PC = 0020DC64, SP = 0030BF3C, FP = 0030BF44
|
293 |
|
|
Frame 1, PC = 0020DC6C, SP = 0030BF38, FP = 0030BF44
|
294 |
|
|
Frame 2, PC = 0020DC70, SP = 0030BF34, FP = 0030BF44
|
295 |
|
|
Frame 3, PC = 0020DC74, SP = 0030BF30, FP = 0030BF44
|
296 |
|
|
Frame 4, PC = 0020DC78, SP = 0030BF2C, FP = 0030BF44
|
297 |
|
|
Frame 5, PC = 0020DC7C, SP = 0030BF28, FP = 0030BF44
|
298 |
|
|
Frame 6, PC = 0020DC80, SP = 0030BF24, FP = 0030BF44
|
299 |
|
|
Frame 7, PC = 0020DC84, SP = 0030BF20, FP = 0030BF44
|
300 |
|
|
Frame 8, PC = 0020DC88, SP = 0030BF1C, FP = 0030BF44
|
301 |
|
|
Frame 9, PC = 0020DC8E, SP = 0030BF18, FP = 0030BF44
|
302 |
|
|
Frame 10, PC = 00203F6C, SP = 0030BE3C, FP = 0030BF14
|
303 |
|
|
|
304 |
|
|
Or, if we want to examine the variable `X' at each source line in
|
305 |
|
|
the buffer:
|
306 |
|
|
|
307 |
|
|
(gdb) tfind start
|
308 |
|
|
(gdb) while ($trace_frame != -1)
|
309 |
|
|
> printf "Frame %d, X == %d\n", $trace_frame, X
|
310 |
|
|
> tfind line
|
311 |
|
|
> end
|
312 |
|
|
|
313 |
|
|
Frame 0, X = 1
|
314 |
|
|
Frame 7, X = 2
|
315 |
|
|
Frame 13, X = 255
|
316 |
|
|
|
317 |
|
|
|
318 |
|
|
File: gdb.info, Node: tdump, Next: save-tracepoints, Prev: tfind, Up: Analyze Collected Data
|
319 |
|
|
|
320 |
|
|
`tdump'
|
321 |
|
|
-------
|
322 |
|
|
|
323 |
|
|
This command takes no arguments. It prints all the data collected at
|
324 |
|
|
the current trace snapshot.
|
325 |
|
|
|
326 |
|
|
(gdb) trace 444
|
327 |
|
|
(gdb) actions
|
328 |
|
|
Enter actions for tracepoint #2, one per line:
|
329 |
|
|
> collect $regs, $locals, $args, gdb_long_test
|
330 |
|
|
> end
|
331 |
|
|
|
332 |
|
|
(gdb) tstart
|
333 |
|
|
|
334 |
|
|
(gdb) tfind line 444
|
335 |
|
|
#0 gdb_test (p1=0x11, p2=0x22, p3=0x33, p4=0x44, p5=0x55, p6=0x66)
|
336 |
|
|
at gdb_test.c:444
|
337 |
|
|
444 printp( "%s: arguments = 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X\n", )
|
338 |
|
|
|
339 |
|
|
(gdb) tdump
|
340 |
|
|
Data collected at tracepoint 2, trace frame 1:
|
341 |
|
|
d0 0xc4aa0085 -995491707
|
342 |
|
|
d1 0x18 24
|
343 |
|
|
d2 0x80 128
|
344 |
|
|
d3 0x33 51
|
345 |
|
|
d4 0x71aea3d 119204413
|
346 |
|
|
d5 0x22 34
|
347 |
|
|
d6 0xe0 224
|
348 |
|
|
d7 0x380035 3670069
|
349 |
|
|
a0 0x19e24a 1696330
|
350 |
|
|
a1 0x3000668 50333288
|
351 |
|
|
a2 0x100 256
|
352 |
|
|
a3 0x322000 3284992
|
353 |
|
|
a4 0x3000698 50333336
|
354 |
|
|
a5 0x1ad3cc 1758156
|
355 |
|
|
fp 0x30bf3c 0x30bf3c
|
356 |
|
|
sp 0x30bf34 0x30bf34
|
357 |
|
|
ps 0x0 0
|
358 |
|
|
pc 0x20b2c8 0x20b2c8
|
359 |
|
|
fpcontrol 0x0 0
|
360 |
|
|
fpstatus 0x0 0
|
361 |
|
|
fpiaddr 0x0 0
|
362 |
|
|
p = 0x20e5b4 "gdb-test"
|
363 |
|
|
p1 = (void *) 0x11
|
364 |
|
|
p2 = (void *) 0x22
|
365 |
|
|
p3 = (void *) 0x33
|
366 |
|
|
p4 = (void *) 0x44
|
367 |
|
|
p5 = (void *) 0x55
|
368 |
|
|
p6 = (void *) 0x66
|
369 |
|
|
gdb_long_test = 17 '\021'
|
370 |
|
|
|
371 |
|
|
(gdb)
|
372 |
|
|
|
373 |
|
|
|
374 |
|
|
File: gdb.info, Node: save-tracepoints, Prev: tdump, Up: Analyze Collected Data
|
375 |
|
|
|
376 |
|
|
`save-tracepoints FILENAME'
|
377 |
|
|
---------------------------
|
378 |
|
|
|
379 |
|
|
This command saves all current tracepoint definitions together with
|
380 |
|
|
their actions and passcounts, into a file `FILENAME' suitable for use
|
381 |
|
|
in a later debugging session. To read the saved tracepoint
|
382 |
|
|
definitions, use the `source' command (*note Command Files::).
|
383 |
|
|
|
384 |
|
|
|
385 |
|
|
File: gdb.info, Node: Tracepoint Variables, Prev: Analyze Collected Data, Up: Tracepoints
|
386 |
|
|
|
387 |
|
|
Convenience Variables for Tracepoints
|
388 |
|
|
=====================================
|
389 |
|
|
|
390 |
|
|
`(int) $trace_frame'
|
391 |
|
|
The current trace snapshot (a.k.a. "frame") number, or -1 if no
|
392 |
|
|
snapshot is selected.
|
393 |
|
|
|
394 |
|
|
`(int) $tracepoint'
|
395 |
|
|
The tracepoint for the current trace snapshot.
|
396 |
|
|
|
397 |
|
|
`(int) $trace_line'
|
398 |
|
|
The line number for the current trace snapshot.
|
399 |
|
|
|
400 |
|
|
`(char []) $trace_file'
|
401 |
|
|
The source file for the current trace snapshot.
|
402 |
|
|
|
403 |
|
|
`(char []) $trace_func'
|
404 |
|
|
The name of the function containing `$tracepoint'.
|
405 |
|
|
|
406 |
|
|
Note: `$trace_file' is not suitable for use in `printf', use
|
407 |
|
|
`output' instead.
|
408 |
|
|
|
409 |
|
|
Here's a simple example of using these convenience variables for
|
410 |
|
|
stepping through all the trace snapshots and printing some of their
|
411 |
|
|
data.
|
412 |
|
|
|
413 |
|
|
(gdb) tfind start
|
414 |
|
|
|
415 |
|
|
(gdb) while $trace_frame != -1
|
416 |
|
|
> output $trace_file
|
417 |
|
|
> printf ", line %d (tracepoint #%d)\n", $trace_line, $tracepoint
|
418 |
|
|
> tfind
|
419 |
|
|
> end
|
420 |
|
|
|
421 |
|
|
|
422 |
|
|
File: gdb.info, Node: Languages, Next: Symbols, Prev: Tracepoints, Up: Top
|
423 |
|
|
|
424 |
|
|
Using GDB with Different Languages
|
425 |
|
|
**********************************
|
426 |
|
|
|
427 |
|
|
Although programming languages generally have common aspects, they
|
428 |
|
|
are rarely expressed in the same manner. For instance, in ANSI C,
|
429 |
|
|
dereferencing a pointer `p' is accomplished by `*p', but in Modula-2,
|
430 |
|
|
it is accomplished by `p^'. Values can also be represented (and
|
431 |
|
|
displayed) differently. Hex numbers in C appear as `0x1ae', while in
|
432 |
|
|
Modula-2 they appear as `1AEH'.
|
433 |
|
|
|
434 |
|
|
Language-specific information is built into GDB for some languages,
|
435 |
|
|
allowing you to express operations like the above in your program's
|
436 |
|
|
native language, and allowing GDB to output values in a manner
|
437 |
|
|
consistent with the syntax of your program's native language. The
|
438 |
|
|
language you use to build expressions is called the "working language".
|
439 |
|
|
|
440 |
|
|
* Menu:
|
441 |
|
|
|
442 |
|
|
* Setting:: Switching between source languages
|
443 |
|
|
* Show:: Displaying the language
|
444 |
|
|
* Checks:: Type and range checks
|
445 |
|
|
* Support:: Supported languages
|
446 |
|
|
|
447 |
|
|
|
448 |
|
|
File: gdb.info, Node: Setting, Next: Show, Up: Languages
|
449 |
|
|
|
450 |
|
|
Switching between source languages
|
451 |
|
|
==================================
|
452 |
|
|
|
453 |
|
|
There are two ways to control the working language--either have GDB
|
454 |
|
|
set it automatically, or select it manually yourself. You can use the
|
455 |
|
|
`set language' command for either purpose. On startup, GDB defaults to
|
456 |
|
|
setting the language automatically. The working language is used to
|
457 |
|
|
determine how expressions you type are interpreted, how values are
|
458 |
|
|
printed, etc.
|
459 |
|
|
|
460 |
|
|
In addition to the working language, every source file that GDB
|
461 |
|
|
knows about has its own working language. For some object file
|
462 |
|
|
formats, the compiler might indicate which language a particular source
|
463 |
|
|
file is in. However, most of the time GDB infers the language from the
|
464 |
|
|
name of the file. The language of a source file controls whether C++
|
465 |
|
|
names are demangled--this way `backtrace' can show each frame
|
466 |
|
|
appropriately for its own language. There is no way to set the
|
467 |
|
|
language of a source file from within GDB, but you can set the language
|
468 |
|
|
associated with a filename extension. *Note Displaying the language:
|
469 |
|
|
Show.
|
470 |
|
|
|
471 |
|
|
This is most commonly a problem when you use a program, such as
|
472 |
|
|
`cfront' or `f2c', that generates C but is written in another language.
|
473 |
|
|
In that case, make the program use `#line' directives in its C output;
|
474 |
|
|
that way GDB will know the correct language of the source code of the
|
475 |
|
|
original program, and will display that source code, not the generated
|
476 |
|
|
C code.
|
477 |
|
|
|
478 |
|
|
* Menu:
|
479 |
|
|
|
480 |
|
|
* Filenames:: Filename extensions and languages.
|
481 |
|
|
* Manually:: Setting the working language manually
|
482 |
|
|
* Automatically:: Having GDB infer the source language
|
483 |
|
|
|
484 |
|
|
|
485 |
|
|
File: gdb.info, Node: Filenames, Next: Manually, Up: Setting
|
486 |
|
|
|
487 |
|
|
List of filename extensions and languages
|
488 |
|
|
-----------------------------------------
|
489 |
|
|
|
490 |
|
|
If a source file name ends in one of the following extensions, then
|
491 |
|
|
GDB infers that its language is the one indicated.
|
492 |
|
|
|
493 |
|
|
`.c'
|
494 |
|
|
C source file
|
495 |
|
|
|
496 |
|
|
`.C'
|
497 |
|
|
`.cc'
|
498 |
|
|
`.cp'
|
499 |
|
|
`.cpp'
|
500 |
|
|
`.cxx'
|
501 |
|
|
`.c++'
|
502 |
|
|
C++ source file
|
503 |
|
|
|
504 |
|
|
`.f'
|
505 |
|
|
`.F'
|
506 |
|
|
Fortran source file
|
507 |
|
|
|
508 |
|
|
`.ch'
|
509 |
|
|
`.c186'
|
510 |
|
|
`.c286'
|
511 |
|
|
CHILL source file
|
512 |
|
|
|
513 |
|
|
`.mod'
|
514 |
|
|
Modula-2 source file
|
515 |
|
|
|
516 |
|
|
`.s'
|
517 |
|
|
`.S'
|
518 |
|
|
Assembler source file. This actually behaves almost like C, but
|
519 |
|
|
GDB does not skip over function prologues when stepping.
|
520 |
|
|
|
521 |
|
|
In addition, you may set the language associated with a filename
|
522 |
|
|
extension. *Note Displaying the language: Show.
|
523 |
|
|
|
524 |
|
|
|
525 |
|
|
File: gdb.info, Node: Manually, Next: Automatically, Prev: Filenames, Up: Setting
|
526 |
|
|
|
527 |
|
|
Setting the working language
|
528 |
|
|
----------------------------
|
529 |
|
|
|
530 |
|
|
If you allow GDB to set the language automatically, expressions are
|
531 |
|
|
interpreted the same way in your debugging session and your program.
|
532 |
|
|
|
533 |
|
|
If you wish, you may set the language manually. To do this, issue
|
534 |
|
|
the command `set language LANG', where LANG is the name of a language,
|
535 |
|
|
such as `c' or `modula-2'. For a list of the supported languages, type
|
536 |
|
|
`set language'.
|
537 |
|
|
|
538 |
|
|
Setting the language manually prevents GDB from updating the working
|
539 |
|
|
language automatically. This can lead to confusion if you try to debug
|
540 |
|
|
a program when the working language is not the same as the source
|
541 |
|
|
language, when an expression is acceptable to both languages--but means
|
542 |
|
|
different things. For instance, if the current source file were
|
543 |
|
|
written in C, and GDB was parsing Modula-2, a command such as:
|
544 |
|
|
|
545 |
|
|
print a = b + c
|
546 |
|
|
|
547 |
|
|
might not have the effect you intended. In C, this means to add `b'
|
548 |
|
|
and `c' and place the result in `a'. The result printed would be the
|
549 |
|
|
value of `a'. In Modula-2, this means to compare `a' to the result of
|
550 |
|
|
`b+c', yielding a `BOOLEAN' value.
|
551 |
|
|
|
552 |
|
|
|
553 |
|
|
File: gdb.info, Node: Automatically, Prev: Manually, Up: Setting
|
554 |
|
|
|
555 |
|
|
Having GDB infer the source language
|
556 |
|
|
------------------------------------
|
557 |
|
|
|
558 |
|
|
To have GDB set the working language automatically, use `set
|
559 |
|
|
language local' or `set language auto'. GDB then infers the working
|
560 |
|
|
language. That is, when your program stops in a frame (usually by
|
561 |
|
|
encountering a breakpoint), GDB sets the working language to the
|
562 |
|
|
language recorded for the function in that frame. If the language for
|
563 |
|
|
a frame is unknown (that is, if the function or block corresponding to
|
564 |
|
|
the frame was defined in a source file that does not have a recognized
|
565 |
|
|
extension), the current working language is not changed, and GDB issues
|
566 |
|
|
a warning.
|
567 |
|
|
|
568 |
|
|
This may not seem necessary for most programs, which are written
|
569 |
|
|
entirely in one source language. However, program modules and libraries
|
570 |
|
|
written in one source language can be used by a main program written in
|
571 |
|
|
a different source language. Using `set language auto' in this case
|
572 |
|
|
frees you from having to set the working language manually.
|
573 |
|
|
|
574 |
|
|
|
575 |
|
|
File: gdb.info, Node: Show, Next: Checks, Prev: Setting, Up: Languages
|
576 |
|
|
|
577 |
|
|
Displaying the language
|
578 |
|
|
=======================
|
579 |
|
|
|
580 |
|
|
The following commands help you find out which language is the
|
581 |
|
|
working language, and also what language source files were written in.
|
582 |
|
|
|
583 |
|
|
`show language'
|
584 |
|
|
Display the current working language. This is the language you
|
585 |
|
|
can use with commands such as `print' to build and compute
|
586 |
|
|
expressions that may involve variables in your program.
|
587 |
|
|
|
588 |
|
|
`info frame'
|
589 |
|
|
Display the source language for this frame. This language becomes
|
590 |
|
|
the working language if you use an identifier from this frame.
|
591 |
|
|
*Note Information about a frame: Frame Info, to identify the other
|
592 |
|
|
information listed here.
|
593 |
|
|
|
594 |
|
|
`info source'
|
595 |
|
|
Display the source language of this source file. *Note Examining
|
596 |
|
|
the Symbol Table: Symbols, to identify the other information
|
597 |
|
|
listed here.
|
598 |
|
|
|
599 |
|
|
In unusual circumstances, you may have source files with extensions
|
600 |
|
|
not in the standard list. You can then set the extension associated
|
601 |
|
|
with a language explicitly:
|
602 |
|
|
|
603 |
|
|
`set extension-language .EXT LANGUAGE'
|
604 |
|
|
Set source files with extension .EXT to be assumed to be in the
|
605 |
|
|
source language LANGUAGE.
|
606 |
|
|
|
607 |
|
|
`info extensions'
|
608 |
|
|
List all the filename extensions and the associated languages.
|
609 |
|
|
|
610 |
|
|
|
611 |
|
|
File: gdb.info, Node: Checks, Next: Support, Prev: Show, Up: Languages
|
612 |
|
|
|
613 |
|
|
Type and range checking
|
614 |
|
|
=======================
|
615 |
|
|
|
616 |
|
|
_Warning:_ In this release, the GDB commands for type and range
|
617 |
|
|
checking are included, but they do not yet have any effect. This
|
618 |
|
|
section documents the intended facilities.
|
619 |
|
|
|
620 |
|
|
Some languages are designed to guard you against making seemingly
|
621 |
|
|
common errors through a series of compile- and run-time checks. These
|
622 |
|
|
include checking the type of arguments to functions and operators, and
|
623 |
|
|
making sure mathematical overflows are caught at run time. Checks such
|
624 |
|
|
as these help to ensure a program's correctness once it has been
|
625 |
|
|
compiled by eliminating type mismatches, and providing active checks
|
626 |
|
|
for range errors when your program is running.
|
627 |
|
|
|
628 |
|
|
GDB can check for conditions like the above if you wish. Although
|
629 |
|
|
GDB does not check the statements in your program, it can check
|
630 |
|
|
expressions entered directly into GDB for evaluation via the `print'
|
631 |
|
|
command, for example. As with the working language, GDB can also
|
632 |
|
|
decide whether or not to check automatically based on your program's
|
633 |
|
|
source language. *Note Supported languages: Support, for the default
|
634 |
|
|
settings of supported languages.
|
635 |
|
|
|
636 |
|
|
* Menu:
|
637 |
|
|
|
638 |
|
|
* Type Checking:: An overview of type checking
|
639 |
|
|
* Range Checking:: An overview of range checking
|
640 |
|
|
|
641 |
|
|
|
642 |
|
|
File: gdb.info, Node: Type Checking, Next: Range Checking, Up: Checks
|
643 |
|
|
|
644 |
|
|
An overview of type checking
|
645 |
|
|
----------------------------
|
646 |
|
|
|
647 |
|
|
Some languages, such as Modula-2, are strongly typed, meaning that
|
648 |
|
|
the arguments to operators and functions have to be of the correct type,
|
649 |
|
|
otherwise an error occurs. These checks prevent type mismatch errors
|
650 |
|
|
from ever causing any run-time problems. For example,
|
651 |
|
|
|
652 |
|
|
1 + 2 => 3
|
653 |
|
|
but
|
654 |
|
|
error--> 1 + 2.3
|
655 |
|
|
|
656 |
|
|
The second example fails because the `CARDINAL' 1 is not
|
657 |
|
|
type-compatible with the `REAL' 2.3.
|
658 |
|
|
|
659 |
|
|
For the expressions you use in GDB commands, you can tell the GDB
|
660 |
|
|
type checker to skip checking; to treat any mismatches as errors and
|
661 |
|
|
abandon the expression; or to only issue warnings when type mismatches
|
662 |
|
|
occur, but evaluate the expression anyway. When you choose the last of
|
663 |
|
|
these, GDB evaluates expressions like the second example above, but
|
664 |
|
|
also issues a warning.
|
665 |
|
|
|
666 |
|
|
Even if you turn type checking off, there may be other reasons
|
667 |
|
|
related to type that prevent GDB from evaluating an expression. For
|
668 |
|
|
instance, GDB does not know how to add an `int' and a `struct foo'.
|
669 |
|
|
These particular type errors have nothing to do with the language in
|
670 |
|
|
use, and usually arise from expressions, such as the one described
|
671 |
|
|
above, which make little sense to evaluate anyway.
|
672 |
|
|
|
673 |
|
|
Each language defines to what degree it is strict about type. For
|
674 |
|
|
instance, both Modula-2 and C require the arguments to arithmetical
|
675 |
|
|
operators to be numbers. In C, enumerated types and pointers can be
|
676 |
|
|
represented as numbers, so that they are valid arguments to mathematical
|
677 |
|
|
operators. *Note Supported languages: Support, for further details on
|
678 |
|
|
specific languages.
|
679 |
|
|
|
680 |
|
|
GDB provides some additional commands for controlling the type
|
681 |
|
|
checker:
|
682 |
|
|
|
683 |
|
|
`set check type auto'
|
684 |
|
|
Set type checking on or off based on the current working language.
|
685 |
|
|
*Note Supported languages: Support, for the default settings for
|
686 |
|
|
each language.
|
687 |
|
|
|
688 |
|
|
`set check type on'
|
689 |
|
|
`set check type off'
|
690 |
|
|
Set type checking on or off, overriding the default setting for the
|
691 |
|
|
current working language. Issue a warning if the setting does not
|
692 |
|
|
match the language default. If any type mismatches occur in
|
693 |
|
|
evaluating an expression while type checking is on, GDB prints a
|
694 |
|
|
message and aborts evaluation of the expression.
|
695 |
|
|
|
696 |
|
|
`set check type warn'
|
697 |
|
|
Cause the type checker to issue warnings, but to always attempt to
|
698 |
|
|
evaluate the expression. Evaluating the expression may still be
|
699 |
|
|
impossible for other reasons. For example, GDB cannot add numbers
|
700 |
|
|
and structures.
|
701 |
|
|
|
702 |
|
|
`show type'
|
703 |
|
|
Show the current setting of the type checker, and whether or not
|
704 |
|
|
GDB is setting it automatically.
|
705 |
|
|
|
706 |
|
|
|
707 |
|
|
File: gdb.info, Node: Range Checking, Prev: Type Checking, Up: Checks
|
708 |
|
|
|
709 |
|
|
An overview of range checking
|
710 |
|
|
-----------------------------
|
711 |
|
|
|
712 |
|
|
In some languages (such as Modula-2), it is an error to exceed the
|
713 |
|
|
bounds of a type; this is enforced with run-time checks. Such range
|
714 |
|
|
checking is meant to ensure program correctness by making sure
|
715 |
|
|
computations do not overflow, or indices on an array element access do
|
716 |
|
|
not exceed the bounds of the array.
|
717 |
|
|
|
718 |
|
|
For expressions you use in GDB commands, you can tell GDB to treat
|
719 |
|
|
range errors in one of three ways: ignore them, always treat them as
|
720 |
|
|
errors and abandon the expression, or issue warnings but evaluate the
|
721 |
|
|
expression anyway.
|
722 |
|
|
|
723 |
|
|
A range error can result from numerical overflow, from exceeding an
|
724 |
|
|
array index bound, or when you type a constant that is not a member of
|
725 |
|
|
any type. Some languages, however, do not treat overflows as an error.
|
726 |
|
|
In many implementations of C, mathematical overflow causes the result
|
727 |
|
|
to "wrap around" to lower values--for example, if M is the largest
|
728 |
|
|
integer value, and S is the smallest, then
|
729 |
|
|
|
730 |
|
|
M + 1 => S
|
731 |
|
|
|
732 |
|
|
This, too, is specific to individual languages, and in some cases
|
733 |
|
|
specific to individual compilers or machines. *Note Supported
|
734 |
|
|
languages: Support, for further details on specific languages.
|
735 |
|
|
|
736 |
|
|
GDB provides some additional commands for controlling the range
|
737 |
|
|
checker:
|
738 |
|
|
|
739 |
|
|
`set check range auto'
|
740 |
|
|
Set range checking on or off based on the current working language.
|
741 |
|
|
*Note Supported languages: Support, for the default settings for
|
742 |
|
|
each language.
|
743 |
|
|
|
744 |
|
|
`set check range on'
|
745 |
|
|
`set check range off'
|
746 |
|
|
Set range checking on or off, overriding the default setting for
|
747 |
|
|
the current working language. A warning is issued if the setting
|
748 |
|
|
does not match the language default. If a range error occurs and
|
749 |
|
|
range checking is on, then a message is printed and evaluation of
|
750 |
|
|
the expression is aborted.
|
751 |
|
|
|
752 |
|
|
`set check range warn'
|
753 |
|
|
Output messages when the GDB range checker detects a range error,
|
754 |
|
|
but attempt to evaluate the expression anyway. Evaluating the
|
755 |
|
|
expression may still be impossible for other reasons, such as
|
756 |
|
|
accessing memory that the process does not own (a typical example
|
757 |
|
|
from many Unix systems).
|
758 |
|
|
|
759 |
|
|
`show range'
|
760 |
|
|
Show the current setting of the range checker, and whether or not
|
761 |
|
|
it is being set automatically by GDB.
|
762 |
|
|
|
763 |
|
|
|
764 |
|
|
File: gdb.info, Node: Support, Prev: Checks, Up: Languages
|
765 |
|
|
|
766 |
|
|
Supported languages
|
767 |
|
|
===================
|
768 |
|
|
|
769 |
|
|
GDB supports C, C++, Fortran, Java, Chill, assembly, and Modula-2.
|
770 |
|
|
Some GDB features may be used in expressions regardless of the language
|
771 |
|
|
you use: the GDB `@' and `::' operators, and the `{type}addr' construct
|
772 |
|
|
(*note Expressions: Expressions.) can be used with the constructs of
|
773 |
|
|
any supported language.
|
774 |
|
|
|
775 |
|
|
The following sections detail to what degree each source language is
|
776 |
|
|
supported by GDB. These sections are not meant to be language
|
777 |
|
|
tutorials or references, but serve only as a reference guide to what the
|
778 |
|
|
GDB expression parser accepts, and what input and output formats should
|
779 |
|
|
look like for different languages. There are many good books written
|
780 |
|
|
on each of these languages; please look to these for a language
|
781 |
|
|
reference or tutorial.
|
782 |
|
|
|
783 |
|
|
* Menu:
|
784 |
|
|
|
785 |
|
|
* C:: C and C++
|
786 |
|
|
* Modula-2:: Modula-2
|
787 |
|
|
* Chill:: Chill
|
788 |
|
|
|
789 |
|
|
|
790 |
|
|
File: gdb.info, Node: C, Next: Modula-2, Up: Support
|
791 |
|
|
|
792 |
|
|
C and C++
|
793 |
|
|
---------
|
794 |
|
|
|
795 |
|
|
Since C and C++ are so closely related, many features of GDB apply
|
796 |
|
|
to both languages. Whenever this is the case, we discuss those
|
797 |
|
|
languages together.
|
798 |
|
|
|
799 |
|
|
The C++ debugging facilities are jointly implemented by the C++
|
800 |
|
|
compiler and GDB. Therefore, to debug your C++ code effectively, you
|
801 |
|
|
must compile your C++ programs with a supported C++ compiler, such as
|
802 |
|
|
GNU `g++', or the HP ANSI C++ compiler (`aCC').
|
803 |
|
|
|
804 |
|
|
For best results when using GNU C++, use the stabs debugging format.
|
805 |
|
|
You can select that format explicitly with the `g++' command-line
|
806 |
|
|
options `-gstabs' or `-gstabs+'. See *Note Options for Debugging Your
|
807 |
|
|
Program or GNU CC: (gcc.info)Debugging Options, for more information.
|
808 |
|
|
|
809 |
|
|
* Menu:
|
810 |
|
|
|
811 |
|
|
* C Operators:: C and C++ operators
|
812 |
|
|
* C Constants:: C and C++ constants
|
813 |
|
|
* C plus plus expressions:: C++ expressions
|
814 |
|
|
* C Defaults:: Default settings for C and C++
|
815 |
|
|
* C Checks:: C and C++ type and range checks
|
816 |
|
|
* Debugging C:: GDB and C
|
817 |
|
|
* Debugging C plus plus:: GDB features for C++
|
818 |
|
|
|
819 |
|
|
|
820 |
|
|
File: gdb.info, Node: C Operators, Next: C Constants, Up: C
|
821 |
|
|
|
822 |
|
|
C and C++ operators
|
823 |
|
|
...................
|
824 |
|
|
|
825 |
|
|
Operators must be defined on values of specific types. For instance,
|
826 |
|
|
`+' is defined on numbers, but not on structures. Operators are often
|
827 |
|
|
defined on groups of types.
|
828 |
|
|
|
829 |
|
|
For the purposes of C and C++, the following definitions hold:
|
830 |
|
|
|
831 |
|
|
* _Integral types_ include `int' with any of its storage-class
|
832 |
|
|
specifiers; `char'; `enum'; and, for C++, `bool'.
|
833 |
|
|
|
834 |
|
|
* _Floating-point types_ include `float', `double', and `long
|
835 |
|
|
double' (if supported by the target platform).
|
836 |
|
|
|
837 |
|
|
* _Pointer types_ include all types defined as `(TYPE *)'.
|
838 |
|
|
|
839 |
|
|
* _Scalar types_ include all of the above.
|
840 |
|
|
|
841 |
|
|
|
842 |
|
|
The following operators are supported. They are listed here in order
|
843 |
|
|
of increasing precedence:
|
844 |
|
|
|
845 |
|
|
`,'
|
846 |
|
|
The comma or sequencing operator. Expressions in a
|
847 |
|
|
comma-separated list are evaluated from left to right, with the
|
848 |
|
|
result of the entire expression being the last expression
|
849 |
|
|
evaluated.
|
850 |
|
|
|
851 |
|
|
`='
|
852 |
|
|
Assignment. The value of an assignment expression is the value
|
853 |
|
|
assigned. Defined on scalar types.
|
854 |
|
|
|
855 |
|
|
`OP='
|
856 |
|
|
Used in an expression of the form `A OP= B', and translated to
|
857 |
|
|
`A = A OP B'. `OP=' and `=' have the same precedence. OP is any
|
858 |
|
|
one of the operators `|', `^', `&', `<<', `>>', `+', `-', `*',
|
859 |
|
|
`/', `%'.
|
860 |
|
|
|
861 |
|
|
`?:'
|
862 |
|
|
The ternary operator. `A ? B : C' can be thought of as: if A
|
863 |
|
|
then B else C. A should be of an integral type.
|
864 |
|
|
|
865 |
|
|
`||'
|
866 |
|
|
Logical OR. Defined on integral types.
|
867 |
|
|
|
868 |
|
|
`&&'
|
869 |
|
|
Logical AND. Defined on integral types.
|
870 |
|
|
|
871 |
|
|
`|'
|
872 |
|
|
Bitwise OR. Defined on integral types.
|
873 |
|
|
|
874 |
|
|
`^'
|
875 |
|
|
Bitwise exclusive-OR. Defined on integral types.
|
876 |
|
|
|
877 |
|
|
`&'
|
878 |
|
|
Bitwise AND. Defined on integral types.
|
879 |
|
|
|
880 |
|
|
`==, !='
|
881 |
|
|
Equality and inequality. Defined on scalar types. The value of
|
882 |
|
|
these expressions is 0 for false and non-zero for true.
|
883 |
|
|
|
884 |
|
|
`<, >, <=, >='
|
885 |
|
|
Less than, greater than, less than or equal, greater than or equal.
|
886 |
|
|
Defined on scalar types. The value of these expressions is 0 for
|
887 |
|
|
false and non-zero for true.
|
888 |
|
|
|
889 |
|
|
`<<, >>'
|
890 |
|
|
left shift, and right shift. Defined on integral types.
|
891 |
|
|
|
892 |
|
|
`@'
|
893 |
|
|
The GDB "artificial array" operator (*note Expressions:
|
894 |
|
|
Expressions.).
|
895 |
|
|
|
896 |
|
|
`+, -'
|
897 |
|
|
Addition and subtraction. Defined on integral types,
|
898 |
|
|
floating-point types and pointer types.
|
899 |
|
|
|
900 |
|
|
`*, /, %'
|
901 |
|
|
Multiplication, division, and modulus. Multiplication and
|
902 |
|
|
division are defined on integral and floating-point types.
|
903 |
|
|
Modulus is defined on integral types.
|
904 |
|
|
|
905 |
|
|
`++, --'
|
906 |
|
|
Increment and decrement. When appearing before a variable, the
|
907 |
|
|
operation is performed before the variable is used in an
|
908 |
|
|
expression; when appearing after it, the variable's value is used
|
909 |
|
|
before the operation takes place.
|
910 |
|
|
|
911 |
|
|
`*'
|
912 |
|
|
Pointer dereferencing. Defined on pointer types. Same precedence
|
913 |
|
|
as `++'.
|
914 |
|
|
|
915 |
|
|
`&'
|
916 |
|
|
Address operator. Defined on variables. Same precedence as `++'.
|
917 |
|
|
|
918 |
|
|
For debugging C++, GDB implements a use of `&' beyond what is
|
919 |
|
|
allowed in the C++ language itself: you can use `&(&REF)' (or, if
|
920 |
|
|
you prefer, simply `&&REF') to examine the address where a C++
|
921 |
|
|
reference variable (declared with `&REF') is stored.
|
922 |
|
|
|
923 |
|
|
`-'
|
924 |
|
|
Negative. Defined on integral and floating-point types. Same
|
925 |
|
|
precedence as `++'.
|
926 |
|
|
|
927 |
|
|
`!'
|
928 |
|
|
Logical negation. Defined on integral types. Same precedence as
|
929 |
|
|
`++'.
|
930 |
|
|
|
931 |
|
|
`~'
|
932 |
|
|
Bitwise complement operator. Defined on integral types. Same
|
933 |
|
|
precedence as `++'.
|
934 |
|
|
|
935 |
|
|
`., ->'
|
936 |
|
|
Structure member, and pointer-to-structure member. For
|
937 |
|
|
convenience, GDB regards the two as equivalent, choosing whether
|
938 |
|
|
to dereference a pointer based on the stored type information.
|
939 |
|
|
Defined on `struct' and `union' data.
|
940 |
|
|
|
941 |
|
|
`.*, ->*'
|
942 |
|
|
Dereferences of pointers to members.
|
943 |
|
|
|
944 |
|
|
`[]'
|
945 |
|
|
Array indexing. `A[I]' is defined as `*(A+I)'. Same precedence
|
946 |
|
|
as `->'.
|
947 |
|
|
|
948 |
|
|
`()'
|
949 |
|
|
Function parameter list. Same precedence as `->'.
|
950 |
|
|
|
951 |
|
|
`::'
|
952 |
|
|
C++ scope resolution operator. Defined on `struct', `union', and
|
953 |
|
|
`class' types.
|
954 |
|
|
|
955 |
|
|
`::'
|
956 |
|
|
Doubled colons also represent the GDB scope operator (*note
|
957 |
|
|
Expressions: Expressions.). Same precedence as `::', above.
|
958 |
|
|
|
959 |
|
|
If an operator is redefined in the user code, GDB usually attempts
|
960 |
|
|
to invoke the redefined version instead of using the operator's
|
961 |
|
|
predefined meaning.
|
962 |
|
|
|
963 |
|
|
* Menu:
|
964 |
|
|
|
965 |
|
|
* C Constants::
|
966 |
|
|
|
967 |
|
|
|
968 |
|
|
File: gdb.info, Node: C Constants, Next: C plus plus expressions, Prev: C Operators, Up: C
|
969 |
|
|
|
970 |
|
|
C and C++ constants
|
971 |
|
|
...................
|
972 |
|
|
|
973 |
|
|
GDB allows you to express the constants of C and C++ in the
|
974 |
|
|
following ways:
|
975 |
|
|
|
976 |
|
|
* Integer constants are a sequence of digits. Octal constants are
|
977 |
|
|
specified by a leading `0' (i.e. zero), and hexadecimal constants
|
978 |
|
|
by a leading `0x' or `0X'. Constants may also end with a letter
|
979 |
|
|
`l', specifying that the constant should be treated as a `long'
|
980 |
|
|
value.
|
981 |
|
|
|
982 |
|
|
* Floating point constants are a sequence of digits, followed by a
|
983 |
|
|
decimal point, followed by a sequence of digits, and optionally
|
984 |
|
|
followed by an exponent. An exponent is of the form:
|
985 |
|
|
`e[[+]|-]NNN', where NNN is another sequence of digits. The `+'
|
986 |
|
|
is optional for positive exponents. A floating-point constant may
|
987 |
|
|
also end with a letter `f' or `F', specifying that the constant
|
988 |
|
|
should be treated as being of the `float' (as opposed to the
|
989 |
|
|
default `double') type; or with a letter `l' or `L', which
|
990 |
|
|
specifies a `long double' constant.
|
991 |
|
|
|
992 |
|
|
* Enumerated constants consist of enumerated identifiers, or their
|
993 |
|
|
integral equivalents.
|
994 |
|
|
|
995 |
|
|
* Character constants are a single character surrounded by single
|
996 |
|
|
quotes (`''), or a number--the ordinal value of the corresponding
|
997 |
|
|
character (usually its ASCII value). Within quotes, the single
|
998 |
|
|
character may be represented by a letter or by "escape sequences",
|
999 |
|
|
which are of the form `\NNN', where NNN is the octal representation
|
1000 |
|
|
of the character's ordinal value; or of the form `\X', where `X'
|
1001 |
|
|
is a predefined special character--for example, `\n' for newline.
|
1002 |
|
|
|
1003 |
|
|
* String constants are a sequence of character constants surrounded
|
1004 |
|
|
by double quotes (`"'). Any valid character constant (as described
|
1005 |
|
|
above) may appear. Double quotes within the string must be
|
1006 |
|
|
preceded by a backslash, so for instance `"a\"b'c"' is a string of
|
1007 |
|
|
five characters.
|
1008 |
|
|
|
1009 |
|
|
* Pointer constants are an integral value. You can also write
|
1010 |
|
|
pointers to constants using the C operator `&'.
|
1011 |
|
|
|
1012 |
|
|
* Array constants are comma-separated lists surrounded by braces `{'
|
1013 |
|
|
and `}'; for example, `{1,2,3}' is a three-element array of
|
1014 |
|
|
integers, `{{1,2}, {3,4}, {5,6}}' is a three-by-two array, and
|
1015 |
|
|
`{&"hi", &"there", &"fred"}' is a three-element array of pointers.
|
1016 |
|
|
|
1017 |
|
|
* Menu:
|
1018 |
|
|
|
1019 |
|
|
* C plus plus expressions::
|
1020 |
|
|
* C Defaults::
|
1021 |
|
|
* C Checks::
|
1022 |
|
|
|
1023 |
|
|
* Debugging C::
|
1024 |
|
|
|
1025 |
|
|
|
1026 |
|
|
File: gdb.info, Node: C plus plus expressions, Next: C Defaults, Prev: C Constants, Up: C
|
1027 |
|
|
|
1028 |
|
|
C++ expressions
|
1029 |
|
|
...............
|
1030 |
|
|
|
1031 |
|
|
GDB expression handling can interpret most C++ expressions.
|
1032 |
|
|
|
1033 |
|
|
_Warning:_ GDB can only debug C++ code if you use the proper
|
1034 |
|
|
compiler. Typically, C++ debugging depends on the use of
|
1035 |
|
|
additional debugging information in the symbol table, and thus
|
1036 |
|
|
requires special support. In particular, if your compiler
|
1037 |
|
|
generates a.out, MIPS ECOFF, RS/6000 XCOFF, or ELF with stabs
|
1038 |
|
|
extensions to the symbol table, these facilities are all
|
1039 |
|
|
available. (With GNU CC, you can use the `-gstabs' option to
|
1040 |
|
|
request stabs debugging extensions explicitly.) Where the object
|
1041 |
|
|
code format is standard COFF or DWARF in ELF, on the other hand,
|
1042 |
|
|
most of the C++ support in GDB does _not_ work.
|
1043 |
|
|
|
1044 |
|
|
1. Member function calls are allowed; you can use expressions like
|
1045 |
|
|
|
1046 |
|
|
count = aml->GetOriginal(x, y)
|
1047 |
|
|
|
1048 |
|
|
2. While a member function is active (in the selected stack frame),
|
1049 |
|
|
your expressions have the same namespace available as the member
|
1050 |
|
|
function; that is, GDB allows implicit references to the class
|
1051 |
|
|
instance pointer `this' following the same rules as C++.
|
1052 |
|
|
|
1053 |
|
|
3. You can call overloaded functions; GDB resolves the function call
|
1054 |
|
|
to the right definition, with some restrictions. GDB does not
|
1055 |
|
|
perform overload resolution involving user-defined type
|
1056 |
|
|
conversions, calls to constructors, or instantiations of templates
|
1057 |
|
|
that do not exist in the program. It also cannot handle ellipsis
|
1058 |
|
|
argument lists or default arguments.
|
1059 |
|
|
|
1060 |
|
|
It does perform integral conversions and promotions, floating-point
|
1061 |
|
|
promotions, arithmetic conversions, pointer conversions,
|
1062 |
|
|
conversions of class objects to base classes, and standard
|
1063 |
|
|
conversions such as those of functions or arrays to pointers; it
|
1064 |
|
|
requires an exact match on the number of function arguments.
|
1065 |
|
|
|
1066 |
|
|
Overload resolution is always performed, unless you have specified
|
1067 |
|
|
`set overload-resolution off'. *Note GDB features for C++:
|
1068 |
|
|
Debugging C plus plus.
|
1069 |
|
|
|
1070 |
|
|
You must specify `set overload-resolution off' in order to use an
|
1071 |
|
|
explicit function signature to call an overloaded function, as in
|
1072 |
|
|
p 'foo(char,int)'('x', 13)
|
1073 |
|
|
|
1074 |
|
|
The GDB command-completion facility can simplify this; see *Note
|
1075 |
|
|
Command completion: Completion.
|
1076 |
|
|
|
1077 |
|
|
4. GDB understands variables declared as C++ references; you can use
|
1078 |
|
|
them in expressions just as you do in C++ source--they are
|
1079 |
|
|
automatically dereferenced.
|
1080 |
|
|
|
1081 |
|
|
In the parameter list shown when GDB displays a frame, the values
|
1082 |
|
|
of reference variables are not displayed (unlike other variables);
|
1083 |
|
|
this avoids clutter, since references are often used for large
|
1084 |
|
|
structures. The _address_ of a reference variable is always
|
1085 |
|
|
shown, unless you have specified `set print address off'.
|
1086 |
|
|
|
1087 |
|
|
5. GDB supports the C++ name resolution operator `::'--your
|
1088 |
|
|
expressions can use it just as expressions in your program do.
|
1089 |
|
|
Since one scope may be defined in another, you can use `::'
|
1090 |
|
|
repeatedly if necessary, for example in an expression like
|
1091 |
|
|
`SCOPE1::SCOPE2::NAME'. GDB also allows resolving name scope by
|
1092 |
|
|
reference to source files, in both C and C++ debugging (*note
|
1093 |
|
|
Program variables: Variables.).
|
1094 |
|
|
|
1095 |
|
|
In addition, when used with HP's C++ compiler, GDB supports calling
|
1096 |
|
|
virtual functions correctly, printing out virtual bases of objects,
|
1097 |
|
|
calling functions in a base subobject, casting objects, and invoking
|
1098 |
|
|
user-defined operators.
|
1099 |
|
|
|
1100 |
|
|
|
1101 |
|
|
File: gdb.info, Node: C Defaults, Next: C Checks, Prev: C plus plus expressions, Up: C
|
1102 |
|
|
|
1103 |
|
|
C and C++ defaults
|
1104 |
|
|
..................
|
1105 |
|
|
|
1106 |
|
|
If you allow GDB to set type and range checking automatically, they
|
1107 |
|
|
both default to `off' whenever the working language changes to C or
|
1108 |
|
|
C++. This happens regardless of whether you or GDB selects the working
|
1109 |
|
|
language.
|
1110 |
|
|
|
1111 |
|
|
If you allow GDB to set the language automatically, it recognizes
|
1112 |
|
|
source files whose names end with `.c', `.C', or `.cc', etc, and when
|
1113 |
|
|
GDB enters code compiled from one of these files, it sets the working
|
1114 |
|
|
language to C or C++. *Note Having GDB infer the source language:
|
1115 |
|
|
Automatically, for further details.
|
1116 |
|
|
|
1117 |
|
|
|
1118 |
|
|
File: gdb.info, Node: C Checks, Next: Debugging C, Prev: C Defaults, Up: C
|
1119 |
|
|
|
1120 |
|
|
C and C++ type and range checks
|
1121 |
|
|
...............................
|
1122 |
|
|
|
1123 |
|
|
By default, when GDB parses C or C++ expressions, type checking is
|
1124 |
|
|
not used. However, if you turn type checking on, GDB considers two
|
1125 |
|
|
variables type equivalent if:
|
1126 |
|
|
|
1127 |
|
|
* The two variables are structured and have the same structure,
|
1128 |
|
|
union, or enumerated tag.
|
1129 |
|
|
|
1130 |
|
|
* The two variables have the same type name, or types that have been
|
1131 |
|
|
declared equivalent through `typedef'.
|
1132 |
|
|
|
1133 |
|
|
|
1134 |
|
|
Range checking, if turned on, is done on mathematical operations.
|
1135 |
|
|
Array indices are not checked, since they are often used to index a
|
1136 |
|
|
pointer that is not itself an array.
|
1137 |
|
|
|
1138 |
|
|
|
1139 |
|
|
File: gdb.info, Node: Debugging C, Next: Debugging C plus plus, Prev: C Checks, Up: C
|
1140 |
|
|
|
1141 |
|
|
GDB and C
|
1142 |
|
|
.........
|
1143 |
|
|
|
1144 |
|
|
The `set print union' and `show print union' commands apply to the
|
1145 |
|
|
`union' type. When set to `on', any `union' that is inside a `struct'
|
1146 |
|
|
or `class' is also printed. Otherwise, it appears as `{...}'.
|
1147 |
|
|
|
1148 |
|
|
The `@' operator aids in the debugging of dynamic arrays, formed
|
1149 |
|
|
with pointers and a memory allocation function. *Note Expressions:
|
1150 |
|
|
Expressions.
|
1151 |
|
|
|
1152 |
|
|
* Menu:
|
1153 |
|
|
|
1154 |
|
|
* Debugging C plus plus::
|
1155 |
|
|
|
1156 |
|
|
|
1157 |
|
|
File: gdb.info, Node: Debugging C plus plus, Prev: Debugging C, Up: C
|
1158 |
|
|
|
1159 |
|
|
GDB features for C++
|
1160 |
|
|
....................
|
1161 |
|
|
|
1162 |
|
|
Some GDB commands are particularly useful with C++, and some are
|
1163 |
|
|
designed specifically for use with C++. Here is a summary:
|
1164 |
|
|
|
1165 |
|
|
`breakpoint menus'
|
1166 |
|
|
When you want a breakpoint in a function whose name is overloaded,
|
1167 |
|
|
GDB breakpoint menus help you specify which function definition
|
1168 |
|
|
you want. *Note Breakpoint menus: Breakpoint Menus.
|
1169 |
|
|
|
1170 |
|
|
`rbreak REGEX'
|
1171 |
|
|
Setting breakpoints using regular expressions is helpful for
|
1172 |
|
|
setting breakpoints on overloaded functions that are not members
|
1173 |
|
|
of any special classes. *Note Setting breakpoints: Set Breaks.
|
1174 |
|
|
|
1175 |
|
|
`catch throw'
|
1176 |
|
|
`catch catch'
|
1177 |
|
|
Debug C++ exception handling using these commands. *Note Setting
|
1178 |
|
|
catchpoints: Set Catchpoints.
|
1179 |
|
|
|
1180 |
|
|
`ptype TYPENAME'
|
1181 |
|
|
Print inheritance relationships as well as other information for
|
1182 |
|
|
type TYPENAME. *Note Examining the Symbol Table: Symbols.
|
1183 |
|
|
|
1184 |
|
|
`set print demangle'
|
1185 |
|
|
`show print demangle'
|
1186 |
|
|
`set print asm-demangle'
|
1187 |
|
|
`show print asm-demangle'
|
1188 |
|
|
Control whether C++ symbols display in their source form, both when
|
1189 |
|
|
displaying code as C++ source and when displaying disassemblies.
|
1190 |
|
|
*Note Print settings: Print Settings.
|
1191 |
|
|
|
1192 |
|
|
`set print object'
|
1193 |
|
|
`show print object'
|
1194 |
|
|
Choose whether to print derived (actual) or declared types of
|
1195 |
|
|
objects. *Note Print settings: Print Settings.
|
1196 |
|
|
|
1197 |
|
|
`set print vtbl'
|
1198 |
|
|
`show print vtbl'
|
1199 |
|
|
Control the format for printing virtual function tables. *Note
|
1200 |
|
|
Print settings: Print Settings. (The `vtbl' commands do not work
|
1201 |
|
|
on programs compiled with the HP ANSI C++ compiler (`aCC').)
|
1202 |
|
|
|
1203 |
|
|
`set overload-resolution on'
|
1204 |
|
|
Enable overload resolution for C++ expression evaluation. The
|
1205 |
|
|
default is on. For overloaded functions, GDB evaluates the
|
1206 |
|
|
arguments and searches for a function whose signature matches the
|
1207 |
|
|
argument types, using the standard C++ conversion rules (see *Note
|
1208 |
|
|
C++ expressions: C plus plus expressions, for details). If it
|
1209 |
|
|
cannot find a match, it emits a message.
|
1210 |
|
|
|
1211 |
|
|
`set overload-resolution off'
|
1212 |
|
|
Disable overload resolution for C++ expression evaluation. For
|
1213 |
|
|
overloaded functions that are not class member functions, GDB
|
1214 |
|
|
chooses the first function of the specified name that it finds in
|
1215 |
|
|
the symbol table, whether or not its arguments are of the correct
|
1216 |
|
|
type. For overloaded functions that are class member functions,
|
1217 |
|
|
GDB searches for a function whose signature _exactly_ matches the
|
1218 |
|
|
argument types.
|
1219 |
|
|
|
1220 |
|
|
`Overloaded symbol names'
|
1221 |
|
|
You can specify a particular definition of an overloaded symbol,
|
1222 |
|
|
using the same notation that is used to declare such symbols in
|
1223 |
|
|
C++: type `SYMBOL(TYPES)' rather than just SYMBOL. You can also
|
1224 |
|
|
use the GDB command-line word completion facilities to list the
|
1225 |
|
|
available choices, or to finish the type list for you. *Note
|
1226 |
|
|
Command completion: Completion, for details on how to do this.
|
1227 |
|
|
|
1228 |
|
|
|
1229 |
|
|
File: gdb.info, Node: Modula-2, Next: Chill, Prev: C, Up: Support
|
1230 |
|
|
|
1231 |
|
|
Modula-2
|
1232 |
|
|
--------
|
1233 |
|
|
|
1234 |
|
|
The extensions made to GDB to support Modula-2 only support output
|
1235 |
|
|
from the GNU Modula-2 compiler (which is currently being developed).
|
1236 |
|
|
Other Modula-2 compilers are not currently supported, and attempting to
|
1237 |
|
|
debug executables produced by them is most likely to give an error as
|
1238 |
|
|
GDB reads in the executable's symbol table.
|
1239 |
|
|
|
1240 |
|
|
* Menu:
|
1241 |
|
|
|
1242 |
|
|
* M2 Operators:: Built-in operators
|
1243 |
|
|
* Built-In Func/Proc:: Built-in functions and procedures
|
1244 |
|
|
* M2 Constants:: Modula-2 constants
|
1245 |
|
|
* M2 Defaults:: Default settings for Modula-2
|
1246 |
|
|
* Deviations:: Deviations from standard Modula-2
|
1247 |
|
|
* M2 Checks:: Modula-2 type and range checks
|
1248 |
|
|
* M2 Scope:: The scope operators `::' and `.'
|
1249 |
|
|
* GDB/M2:: GDB and Modula-2
|
1250 |
|
|
|
1251 |
|
|
|
1252 |
|
|
File: gdb.info, Node: M2 Operators, Next: Built-In Func/Proc, Up: Modula-2
|
1253 |
|
|
|
1254 |
|
|
Operators
|
1255 |
|
|
.........
|
1256 |
|
|
|
1257 |
|
|
Operators must be defined on values of specific types. For instance,
|
1258 |
|
|
`+' is defined on numbers, but not on structures. Operators are often
|
1259 |
|
|
defined on groups of types. For the purposes of Modula-2, the
|
1260 |
|
|
following definitions hold:
|
1261 |
|
|
|
1262 |
|
|
* _Integral types_ consist of `INTEGER', `CARDINAL', and their
|
1263 |
|
|
subranges.
|
1264 |
|
|
|
1265 |
|
|
* _Character types_ consist of `CHAR' and its subranges.
|
1266 |
|
|
|
1267 |
|
|
* _Floating-point types_ consist of `REAL'.
|
1268 |
|
|
|
1269 |
|
|
* _Pointer types_ consist of anything declared as `POINTER TO TYPE'.
|
1270 |
|
|
|
1271 |
|
|
* _Scalar types_ consist of all of the above.
|
1272 |
|
|
|
1273 |
|
|
* _Set types_ consist of `SET' and `BITSET' types.
|
1274 |
|
|
|
1275 |
|
|
* _Boolean types_ consist of `BOOLEAN'.
|
1276 |
|
|
|
1277 |
|
|
The following operators are supported, and appear in order of
|
1278 |
|
|
increasing precedence:
|
1279 |
|
|
|
1280 |
|
|
`,'
|
1281 |
|
|
Function argument or array index separator.
|
1282 |
|
|
|
1283 |
|
|
`:='
|
1284 |
|
|
Assignment. The value of VAR `:=' VALUE is VALUE.
|
1285 |
|
|
|
1286 |
|
|
`<, >'
|
1287 |
|
|
Less than, greater than on integral, floating-point, or enumerated
|
1288 |
|
|
types.
|
1289 |
|
|
|
1290 |
|
|
`<=, >='
|
1291 |
|
|
Less than or equal to, greater than or equal to on integral,
|
1292 |
|
|
floating-point and enumerated types, or set inclusion on set
|
1293 |
|
|
types. Same precedence as `<'.
|
1294 |
|
|
|
1295 |
|
|
`=, <>, #'
|
1296 |
|
|
Equality and two ways of expressing inequality, valid on scalar
|
1297 |
|
|
types. Same precedence as `<'. In GDB scripts, only `<>' is
|
1298 |
|
|
available for inequality, since `#' conflicts with the script
|
1299 |
|
|
comment character.
|
1300 |
|
|
|
1301 |
|
|
`IN'
|
1302 |
|
|
Set membership. Defined on set types and the types of their
|
1303 |
|
|
members. Same precedence as `<'.
|
1304 |
|
|
|
1305 |
|
|
`OR'
|
1306 |
|
|
Boolean disjunction. Defined on boolean types.
|
1307 |
|
|
|
1308 |
|
|
`AND, &'
|
1309 |
|
|
Boolean conjunction. Defined on boolean types.
|
1310 |
|
|
|
1311 |
|
|
`@'
|
1312 |
|
|
The GDB "artificial array" operator (*note Expressions:
|
1313 |
|
|
Expressions.).
|
1314 |
|
|
|
1315 |
|
|
`+, -'
|
1316 |
|
|
Addition and subtraction on integral and floating-point types, or
|
1317 |
|
|
union and difference on set types.
|
1318 |
|
|
|
1319 |
|
|
`*'
|
1320 |
|
|
Multiplication on integral and floating-point types, or set
|
1321 |
|
|
intersection on set types.
|
1322 |
|
|
|
1323 |
|
|
`/'
|
1324 |
|
|
Division on floating-point types, or symmetric set difference on
|
1325 |
|
|
set types. Same precedence as `*'.
|
1326 |
|
|
|
1327 |
|
|
`DIV, MOD'
|
1328 |
|
|
Integer division and remainder. Defined on integral types. Same
|
1329 |
|
|
precedence as `*'.
|
1330 |
|
|
|
1331 |
|
|
`-'
|
1332 |
|
|
Negative. Defined on `INTEGER' and `REAL' data.
|
1333 |
|
|
|
1334 |
|
|
`^'
|
1335 |
|
|
Pointer dereferencing. Defined on pointer types.
|
1336 |
|
|
|
1337 |
|
|
`NOT'
|
1338 |
|
|
Boolean negation. Defined on boolean types. Same precedence as
|
1339 |
|
|
`^'.
|
1340 |
|
|
|
1341 |
|
|
`.'
|
1342 |
|
|
`RECORD' field selector. Defined on `RECORD' data. Same
|
1343 |
|
|
precedence as `^'.
|
1344 |
|
|
|
1345 |
|
|
`[]'
|
1346 |
|
|
Array indexing. Defined on `ARRAY' data. Same precedence as `^'.
|
1347 |
|
|
|
1348 |
|
|
`()'
|
1349 |
|
|
Procedure argument list. Defined on `PROCEDURE' objects. Same
|
1350 |
|
|
precedence as `^'.
|
1351 |
|
|
|
1352 |
|
|
`::, .'
|
1353 |
|
|
GDB and Modula-2 scope operators.
|
1354 |
|
|
|
1355 |
|
|
_Warning:_ Sets and their operations are not yet supported, so GDB
|
1356 |
|
|
treats the use of the operator `IN', or the use of operators `+',
|
1357 |
|
|
`-', `*', `/', `=', , `<>', `#', `<=', and `>=' on sets as an
|
1358 |
|
|
error.
|
1359 |
|
|
|