1 This is Info file ./gdb.info, produced by Makeinfo version 1.68 from
2 the input file gdb.texinfo.
5 * Gdb: (gdb). The GNU debugger.
7 This file documents the GNU debugger GDB.
9 This is the Seventh Edition, February 1999, of `Debugging with GDB:
10 the GNU Source-Level Debugger' for GDB Version 4.18.
12 Copyright (C) 1988-1999 Free Software Foundation, Inc.
14 Permission is granted to make and distribute verbatim copies of this
15 manual provided the copyright notice and this permission notice are
16 preserved on all copies.
18 Permission is granted to copy and distribute modified versions of
19 this manual under the conditions for verbatim copying, provided also
20 that the entire resulting derived work is distributed under the terms
21 of a permission notice identical to this one.
23 Permission is granted to copy and distribute translations of this
24 manual into another language, under the above conditions for modified
28 File: gdb.info, Node: Arrays, Next: Output Formats, Prev: Variables, Up: Data
33 It is often useful to print out several successive objects of the
34 same type in memory; a section of an array, or an array of dynamically
35 determined size for which only a pointer exists in the program.
37 You can do this by referring to a contiguous span of memory as an
38 "artificial array", using the binary operator `@'. The left operand of
39 `@' should be the first element of the desired array and be an
40 individual object. The right operand should be the desired length of
41 the array. The result is an array value whose elements are all of the
42 type of the left argument. The first element is actually the left
43 argument; the second element comes from bytes of memory immediately
44 following those that hold the first element, and so on. Here is an
45 example. If a program says
47 int *array = (int *) malloc (len * sizeof (int));
49 you can print the contents of `array' with
53 The left operand of `@' must reside in memory. Array values made
54 with `@' in this way behave just like other arrays in terms of
55 subscripting, and are coerced to pointers when used in expressions.
56 Artificial arrays most often appear in expressions via the value history
57 (*note Value history: Value History.), after printing one out.
59 Another way to create an artificial array is to use a cast. This
60 re-interprets a value as if it were an array. The value need not be in
62 (gdb) p/x (short[2])0x12345678
65 As a convenience, if you leave the array length out (as in
66 `(TYPE)[])VALUE') gdb calculates the size to fill the value (as
67 `sizeof(VALUE)/sizeof(TYPE)':
68 (gdb) p/x (short[])0x12345678
71 Sometimes the artificial array mechanism is not quite enough; in
72 moderately complex data structures, the elements of interest may not
73 actually be adjacent--for example, if you are interested in the values
74 of pointers in an array. One useful work-around in this situation is
75 to use a convenience variable (*note Convenience variables: Convenience
76 Vars.) as a counter in an expression that prints the first interesting
77 value, and then repeat that expression via <RET>. For instance,
78 suppose you have an array `dtab' of pointers to structures, and you are
79 interested in the values of a field `fv' in each structure. Here is an
80 example of what you might type:
89 File: gdb.info, Node: Output Formats, Next: Memory, Prev: Arrays, Up: Data
94 By default, GDB prints a value according to its data type. Sometimes
95 this is not what you want. For example, you might want to print a
96 number in hex, or a pointer in decimal. Or you might want to view data
97 in memory at a certain address as a character string or as an
98 instruction. To do these things, specify an "output format" when you
101 The simplest use of output formats is to say how to print a value
102 already computed. This is done by starting the arguments of the
103 `print' command with a slash and a format letter. The format letters
107 Regard the bits of the value as an integer, and print the integer
111 Print as integer in signed decimal.
114 Print as integer in unsigned decimal.
117 Print as integer in octal.
120 Print as integer in binary. The letter `t' stands for "two". (1)
123 Print as an address, both absolute in hexadecimal and as an offset
124 from the nearest preceding symbol. You can use this format used
125 to discover where (in what function) an unknown address is located:
128 $3 = 0x54320 <_initialize_vx+396>
131 Regard as an integer and print it as a character constant.
134 Regard the bits of the value as a floating point number and print
135 using typical floating point syntax.
137 For example, to print the program counter in hex (*note
142 Note that no space is required before the slash; this is because command
143 names in GDB cannot contain a slash.
145 To reprint the last value in the value history with a different
146 format, you can use the `print' command with just a format and no
147 expression. For example, `p/x' reprints the last value in hex.
149 ---------- Footnotes ----------
151 (1) `b' cannot be used because these format letters are also used
152 with the `x' command, where `b' stands for "byte"; *note Examining
156 File: gdb.info, Node: Memory, Next: Auto Display, Prev: Output Formats, Up: Data
161 You can use the command `x' (for "examine") to examine memory in any
162 of several formats, independently of your program's data types.
167 Use the `x' command to examine memory.
169 N, F, and U are all optional parameters that specify how much memory
170 to display and how to format it; ADDR is an expression giving the
171 address where you want to start displaying memory. If you use defaults
172 for NFU, you need not type the slash `/'. Several commands set
173 convenient defaults for ADDR.
176 The repeat count is a decimal integer; the default is 1. It
177 specifies how much memory (counting by units U) to display.
179 F, the display format
180 The display format is one of the formats used by `print', `s'
181 (null-terminated string), or `i' (machine instruction). The
182 default is `x' (hexadecimal) initially. The default changes each
183 time you use either `x' or `print'.
186 The unit size is any of
192 Halfwords (two bytes).
195 Words (four bytes). This is the initial default.
198 Giant words (eight bytes).
200 Each time you specify a unit size with `x', that size becomes the
201 default unit the next time you use `x'. (For the `s' and `i'
202 formats, the unit size is ignored and is normally not written.)
204 ADDR, starting display address
205 ADDR is the address where you want GDB to begin displaying memory.
206 The expression need not have a pointer value (though it may); it
207 is always interpreted as an integer address of a byte of memory.
208 *Note Expressions: Expressions, for more information on
209 expressions. The default for ADDR is usually just after the last
210 address examined--but several other commands also set the default
211 address: `info breakpoints' (to the address of the last breakpoint
212 listed), `info line' (to the starting address of a line), and
213 `print' (if you use it to display a value from memory).
215 For example, `x/3uh 0x54320' is a request to display three halfwords
216 (`h') of memory, formatted as unsigned decimal integers (`u'), starting
217 at address `0x54320'. `x/4xw $sp' prints the four words (`w') of
218 memory above the stack pointer (here, `$sp'; *note Registers::.) in
221 Since the letters indicating unit sizes are all distinct from the
222 letters specifying output formats, you do not have to remember whether
223 unit size or format comes first; either order works. The output
224 specifications `4xw' and `4wx' mean exactly the same thing. (However,
225 the count N must come first; `wx4' does not work.)
227 Even though the unit size U is ignored for the formats `s' and `i',
228 you might still want to use a count N; for example, `3i' specifies that
229 you want to see three machine instructions, including any operands.
230 The command `disassemble' gives an alternative way of inspecting
231 machine instructions; *note Source and machine code: Machine Code..
233 All the defaults for the arguments to `x' are designed to make it
234 easy to continue scanning memory with minimal specifications each time
235 you use `x'. For example, after you have inspected three machine
236 instructions with `x/3i ADDR', you can inspect the next seven with just
237 `x/7'. If you use <RET> to repeat the `x' command, the repeat count N
238 is used again; the other arguments default as for successive uses of
241 The addresses and contents printed by the `x' command are not saved
242 in the value history because there is often too much of them and they
243 would get in the way. Instead, GDB makes these values available for
244 subsequent use in expressions as values of the convenience variables
245 `$_' and `$__'. After an `x' command, the last address examined is
246 available for use in expressions in the convenience variable `$_'. The
247 contents of that address, as examined, are available in the convenience
250 If the `x' command has a repeat count, the address and contents saved
251 are from the last memory unit printed; this is not the same as the last
252 address printed if several units were printed on the last line of
256 File: gdb.info, Node: Auto Display, Next: Print Settings, Prev: Memory, Up: Data
261 If you find that you want to print the value of an expression
262 frequently (to see how it changes), you might want to add it to the
263 "automatic display list" so that GDB prints its value each time your
264 program stops. Each expression added to the list is given a number to
265 identify it; to remove an expression from the list, you specify that
266 number. The automatic display looks like this:
269 3: bar[5] = (struct hack *) 0x3804
271 This display shows item numbers, expressions and their current values.
272 As with displays you request manually using `x' or `print', you can
273 specify the output format you prefer; in fact, `display' decides
274 whether to use `print' or `x' depending on how elaborate your format
275 specification is--it uses `x' if you specify a unit size, or one of the
276 two formats (`i' and `s') that are only supported by `x'; otherwise it
280 Add the expression EXP to the list of expressions to display each
281 time your program stops. *Note Expressions: Expressions.
283 `display' does not repeat if you press <RET> again after using it.
286 For FMT specifying only a display format and not a size or count,
287 add the expression EXP to the auto-display list but arrange to
288 display it each time in the specified format FMT. *Note Output
289 formats: Output Formats.
292 For FMT `i' or `s', or including a unit-size or a number of units,
293 add the expression ADDR as a memory address to be examined each
294 time your program stops. Examining means in effect doing `x/FMT
295 ADDR'. *Note Examining memory: Memory.
297 For example, `display/i $pc' can be helpful, to see the machine
298 instruction about to be executed each time execution stops (`$pc' is a
299 common name for the program counter; *note Registers::.).
302 `delete display DNUMS...'
303 Remove item numbers DNUMS from the list of expressions to display.
305 `undisplay' does not repeat if you press <RET> after using it.
306 (Otherwise you would just get the error `No display number ...'.)
308 `disable display DNUMS...'
309 Disable the display of item numbers DNUMS. A disabled display
310 item is not printed automatically, but is not forgotten. It may be
313 `enable display DNUMS...'
314 Enable display of item numbers DNUMS. It becomes effective once
315 again in auto display of its expression, until you specify
319 Display the current values of the expressions on the list, just as
320 is done when your program stops.
323 Print the list of expressions previously set up to display
324 automatically, each one with its item number, but without showing
325 the values. This includes disabled expressions, which are marked
326 as such. It also includes expressions which would not be
327 displayed right now because they refer to automatic variables not
330 If a display expression refers to local variables, then it does not
331 make sense outside the lexical context for which it was set up. Such an
332 expression is disabled when execution enters a context where one of its
333 variables is not defined. For example, if you give the command
334 `display last_char' while inside a function with an argument
335 `last_char', GDB displays this argument while your program continues to
336 stop inside that function. When it stops elsewhere--where there is no
337 variable `last_char'--the display is disabled automatically. The next
338 time your program stops where `last_char' is meaningful, you can enable
339 the display expression once again.
342 File: gdb.info, Node: Print Settings, Next: Value History, Prev: Auto Display, Up: Data
347 GDB provides the following ways to control how arrays, structures,
348 and symbols are printed.
350 These settings are useful for debugging programs in any language:
353 `set print address on'
354 GDB prints memory addresses showing the location of stack traces,
355 structure values, pointer values, breakpoints, and so forth, even
356 when it also displays the contents of those addresses. The default
357 is `on'. For example, this is what a stack frame display looks
358 like with `set print address on':
361 #0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
363 530 if (lquote != def_lquote)
365 `set print address off'
366 Do not print addresses when displaying their contents. For
367 example, this is the same stack frame displayed with `set print
370 (gdb) set print addr off
372 #0 set_quotes (lq="<<", rq=">>") at input.c:530
373 530 if (lquote != def_lquote)
375 You can use `set print address off' to eliminate all machine
376 dependent displays from the GDB interface. For example, with
377 `print address off', you should get the same text for backtraces on
378 all machines--whether or not they involve pointer arguments.
381 Show whether or not addresses are to be printed.
383 When GDB prints a symbolic address, it normally prints the closest
384 earlier symbol plus an offset. If that symbol does not uniquely
385 identify the address (for example, it is a name whose scope is a single
386 source file), you may need to clarify. One way to do this is with
387 `info line', for example `info line *0x4537'. Alternately, you can set
388 GDB to print the source file and line number when it prints a symbolic
391 `set print symbol-filename on'
392 Tell GDB to print the source file name and line number of a symbol
393 in the symbolic form of an address.
395 `set print symbol-filename off'
396 Do not print source file name and line number of a symbol. This
399 `show print symbol-filename'
400 Show whether or not GDB will print the source file name and line
401 number of a symbol in the symbolic form of an address.
403 Another situation where it is helpful to show symbol filenames and
404 line numbers is when disassembling code; GDB shows you the line number
405 and source file that corresponds to each instruction.
407 Also, you may wish to see the symbolic form only if the address being
408 printed is reasonably close to the closest earlier symbol:
410 `set print max-symbolic-offset MAX-OFFSET'
411 Tell GDB to only display the symbolic form of an address if the
412 offset between the closest earlier symbol and the address is less
413 than MAX-OFFSET. The default is 0, which tells GDB to always
414 print the symbolic form of an address if any symbol precedes it.
416 `show print max-symbolic-offset'
417 Ask how large the maximum offset is that GDB prints in a symbolic
420 If you have a pointer and you are not sure where it points, try `set
421 print symbol-filename on'. Then you can determine the name and source
422 file location of the variable where it points, using `p/a POINTER'.
423 This interprets the address in symbolic form. For example, here GDB
424 shows that a variable `ptt' points at another variable `t', defined in
427 (gdb) set print symbol-filename on
429 $4 = 0xe008 <t in hi2.c>
431 *Warning:* For pointers that point to a local variable, `p/a' does
432 not show the symbol name and filename of the referent, even with
433 the appropriate `set print' options turned on.
435 Other settings control how different kinds of objects are printed:
439 Pretty print arrays. This format is more convenient to read, but
440 uses more space. The default is off.
442 `set print array off'
443 Return to compressed format for arrays.
446 Show whether compressed or pretty format is selected for displaying
449 `set print elements NUMBER-OF-ELEMENTS'
450 Set a limit on how many elements of an array GDB will print. If
451 GDB is printing a large array, it stops printing after it has
452 printed the number of elements set by the `set print elements'
453 command. This limit also applies to the display of strings.
454 Setting NUMBER-OF-ELEMENTS to zero means that the printing is
457 `show print elements'
458 Display the number of elements of a large array that GDB will
459 print. If the number is 0, then the printing is unlimited.
461 `set print null-stop'
462 Cause GDB to stop printing the characters of an array when the
463 first NULL is encountered. This is useful when large arrays
464 actually contain only short strings.
466 `set print pretty on'
467 Cause GDB to print structures in an indented format with one member
479 `set print pretty off'
480 Cause GDB to print structures in a compact format, like this:
482 $1 = {next = 0x0, flags = {sweet = 1, sour = 1}, \
485 This is the default format.
488 Show which format GDB is using to print structures.
490 `set print sevenbit-strings on'
491 Print using only seven-bit characters; if this option is set, GDB
492 displays any eight-bit characters (in strings or character values)
493 using the notation `\'NNN. This setting is best if you are
494 working in English (ASCII) and you use the high-order bit of
495 characters as a marker or "meta" bit.
497 `set print sevenbit-strings off'
498 Print full eight-bit characters. This allows the use of more
499 international character sets, and is the default.
501 `show print sevenbit-strings'
502 Show whether or not GDB is printing only seven-bit characters.
505 Tell GDB to print unions which are contained in structures. This
506 is the default setting.
508 `set print union off'
509 Tell GDB not to print unions which are contained in structures.
512 Ask GDB whether or not it will print unions which are contained in
515 For example, given the declarations
517 typedef enum {Tree, Bug} Species;
518 typedef enum {Big_tree, Acorn, Seedling} Tree_forms;
519 typedef enum {Caterpillar, Cocoon, Butterfly}
530 struct thing foo = {Tree, {Acorn}};
532 with `set print union on' in effect `p foo' would print
534 $1 = {it = Tree, form = {tree = Acorn, bug = Cocoon}}
536 and with `set print union off' in effect it would print
538 $1 = {it = Tree, form = {...}}
540 These settings are of interest when debugging C++ programs:
543 `set print demangle on'
544 Print C++ names in their source form rather than in the encoded
545 ("mangled") form passed to the assembler and linker for type-safe
546 linkage. The default is `on'.
548 `show print demangle'
549 Show whether C++ names are printed in mangled or demangled form.
551 `set print asm-demangle'
552 `set print asm-demangle on'
553 Print C++ names in their source form rather than their mangled
554 form, even in assembler code printouts such as instruction
555 disassemblies. The default is off.
557 `show print asm-demangle'
558 Show whether C++ names in assembly listings are printed in mangled
561 `set demangle-style STYLE'
562 Choose among several encoding schemes used by different compilers
563 to represent C++ names. The choices for STYLE are currently:
566 Allow GDB to choose a decoding style by inspecting your
570 Decode based on the GNU C++ compiler (`g++') encoding
571 algorithm. This is the default.
574 Decode based on the HP ANSI C++ (`aCC') encoding algorithm.
577 Decode based on the Lucid C++ compiler (`lcc') encoding
581 Decode using the algorithm in the `C++ Annotated Reference
582 Manual'. *Warning:* this setting alone is not sufficient to
583 allow debugging `cfront'-generated executables. GDB would
584 require further enhancement to permit that.
586 If you omit STYLE, you will see a list of possible formats.
588 `show demangle-style'
589 Display the encoding style currently in use for decoding C++
593 `set print object on'
594 When displaying a pointer to an object, identify the *actual*
595 (derived) type of the object rather than the *declared* type, using
596 the virtual function table.
598 `set print object off'
599 Display only the declared type of objects, without reference to the
600 virtual function table. This is the default setting.
603 Show whether actual, or declared, object types are displayed.
605 `set print static-members'
606 `set print static-members on'
607 Print static members when displaying a C++ object. The default is
610 `set print static-members off'
611 Do not print static members when displaying a C++ object.
613 `show print static-members'
614 Show whether C++ static members are printed, or not.
618 Pretty print C++ virtual function tables. The default is off.
621 Do not pretty print C++ virtual function tables.
624 Show whether C++ virtual function tables are pretty printed, or
628 File: gdb.info, Node: Value History, Next: Convenience Vars, Prev: Print Settings, Up: Data
633 Values printed by the `print' command are saved in the GDB "value
634 history". This allows you to refer to them in other expressions.
635 Values are kept until the symbol table is re-read or discarded (for
636 example with the `file' or `symbol-file' commands). When the symbol
637 table changes, the value history is discarded, since the values may
638 contain pointers back to the types defined in the symbol table.
640 The values printed are given "history numbers" by which you can
641 refer to them. These are successive integers starting with one.
642 `print' shows you the history number assigned to a value by printing
643 `$NUM = ' before the value; here NUM is the history number.
645 To refer to any previous value, use `$' followed by the value's
646 history number. The way `print' labels its output is designed to
647 remind you of this. Just `$' refers to the most recent value in the
648 history, and `$$' refers to the value before that. `$$N' refers to the
649 Nth value from the end; `$$2' is the value just prior to `$$', `$$1' is
650 equivalent to `$$', and `$$0' is equivalent to `$'.
652 For example, suppose you have just printed a pointer to a structure
653 and want to see the contents of the structure. It suffices to type
657 If you have a chain of structures where the component `next' points
658 to the next one, you can print the contents of the next one with this:
662 You can print successive links in the chain by repeating this
663 command--which you can do by just typing <RET>.
665 Note that the history records values, not expressions. If the value
666 of `x' is 4 and you type these commands:
671 then the value recorded in the value history by the `print' command
672 remains 4 even though the value of `x' has changed.
675 Print the last ten values in the value history, with their item
676 numbers. This is like `p $$9' repeated ten times, except that
677 `show values' does not change the history.
680 Print ten history values centered on history item number N.
683 Print ten history values just after the values last printed. If
684 no more values are available, `show values +' produces no display.
686 Pressing <RET> to repeat `show values N' has exactly the same effect
690 File: gdb.info, Node: Convenience Vars, Next: Registers, Prev: Value History, Up: Data
692 Convenience variables
693 =====================
695 GDB provides "convenience variables" that you can use within GDB to
696 hold on to a value and refer to it later. These variables exist
697 entirely within GDB; they are not part of your program, and setting a
698 convenience variable has no direct effect on further execution of your
699 program. That is why you can use them freely.
701 Convenience variables are prefixed with `$'. Any name preceded by
702 `$' can be used for a convenience variable, unless it is one of the
703 predefined machine-specific register names (*note Registers::.).
704 (Value history references, in contrast, are *numbers* preceded by `$'.
705 *Note Value history: Value History.)
707 You can save a value in a convenience variable with an assignment
708 expression, just as you would set a variable in your program. For
711 set $foo = *object_ptr
713 would save in `$foo' the value contained in the object pointed to by
716 Using a convenience variable for the first time creates it, but its
717 value is `void' until you assign a new value. You can alter the value
718 with another assignment at any time.
720 Convenience variables have no fixed types. You can assign a
721 convenience variable any type of value, including structures and
722 arrays, even if that variable already has a value of a different type.
723 The convenience variable, when used as an expression, has the type of
727 Print a list of convenience variables used so far, and their
728 values. Abbreviated `show con'.
730 One of the ways to use a convenience variable is as a counter to be
731 incremented or a pointer to be advanced. For example, to print a field
732 from successive elements of an array of structures:
735 print bar[$i++]->contents
737 Repeat that command by typing <RET>.
739 Some convenience variables are created automatically by GDB and given
740 values likely to be useful.
743 The variable `$_' is automatically set by the `x' command to the
744 last address examined (*note Examining memory: Memory.). Other
745 commands which provide a default address for `x' to examine also
746 set `$_' to that address; these commands include `info line' and
747 `info breakpoint'. The type of `$_' is `void *' except when set
748 by the `x' command, in which case it is a pointer to the type of
752 The variable `$__' is automatically set by the `x' command to the
753 value found in the last address examined. Its type is chosen to
754 match the format in which the data was printed.
757 The variable `$_exitcode' is automatically set to the exit code
758 when the program being debugged terminates.
761 File: gdb.info, Node: Registers, Next: Floating Point Hardware, Prev: Convenience Vars, Up: Data
766 You can refer to machine register contents, in expressions, as
767 variables with names starting with `$'. The names of registers are
768 different for each machine; use `info registers' to see the names used
772 Print the names and values of all registers except floating-point
773 registers (in the selected stack frame).
776 Print the names and values of all registers, including
777 floating-point registers.
779 `info registers REGNAME ...'
780 Print the "relativized" value of each specified register REGNAME.
781 As discussed in detail below, register values are normally
782 relative to the selected stack frame. REGNAME may be any register
783 name valid on the machine you are using, with or without the
786 GDB has four "standard" register names that are available (in
787 expressions) on most machines--whenever they do not conflict with an
788 architecture's canonical mnemonics for registers. The register names
789 `$pc' and `$sp' are used for the program counter register and the stack
790 pointer. `$fp' is used for a register that contains a pointer to the
791 current stack frame, and `$ps' is used for a register that contains the
792 processor status. For example, you could print the program counter in
797 or print the instruction to be executed next with
801 or add four to the stack pointer(1) with
805 Whenever possible, these four standard register names are available
806 on your machine even though the machine has different canonical
807 mnemonics, so long as there is no conflict. The `info registers'
808 command shows the canonical names. For example, on the SPARC, `info
809 registers' displays the processor status register as `$psr' but you can
810 also refer to it as `$ps'.
812 GDB always considers the contents of an ordinary register as an
813 integer when the register is examined in this way. Some machines have
814 special registers which can hold nothing but floating point; these
815 registers are considered to have floating point values. There is no way
816 to refer to the contents of an ordinary register as floating point value
817 (although you can *print* it as a floating point value with `print/f
820 Some registers have distinct "raw" and "virtual" data formats. This
821 means that the data format in which the register contents are saved by
822 the operating system is not the same one that your program normally
823 sees. For example, the registers of the 68881 floating point
824 coprocessor are always saved in "extended" (raw) format, but all C
825 programs expect to work with "double" (virtual) format. In such cases,
826 GDB normally works with the virtual format only (the format that makes
827 sense for your program), but the `info registers' command prints the
828 data in both formats.
830 Normally, register values are relative to the selected stack frame
831 (*note Selecting a frame: Selection.). This means that you get the
832 value that the register would contain if all stack frames farther in
833 were exited and their saved registers restored. In order to see the
834 true contents of hardware registers, you must select the innermost
835 frame (with `frame 0').
837 However, GDB must deduce where registers are saved, from the machine
838 code generated by your compiler. If some registers are not saved, or if
839 GDB is unable to locate the saved registers, the selected stack frame
842 `set rstack_high_address ADDRESS'
843 On AMD 29000 family processors, registers are saved in a separate
844 "register stack". There is no way for GDB to determine the extent
845 of this stack. Normally, GDB just assumes that the stack is "large
846 enough". This may result in GDB referencing memory locations that
847 do not exist. If necessary, you can get around this problem by
848 specifying the ending address of the register stack with the `set
849 rstack_high_address' command. The argument should be an address,
850 which you probably want to precede with `0x' to specify in
853 `show rstack_high_address'
854 Display the current limit of the register stack, on AMD 29000
857 ---------- Footnotes ----------
859 (1) This is a way of removing one word from the stack, on machines
860 where stacks grow downward in memory (most machines, nowadays). This
861 assumes that the innermost stack frame is selected; setting `$sp' is
862 not allowed when other stack frames are selected. To pop entire frames
863 off the stack, regardless of machine architecture, use `return'; *note
864 Returning from a function: Returning..
867 File: gdb.info, Node: Floating Point Hardware, Prev: Registers, Up: Data
869 Floating point hardware
870 =======================
872 Depending on the configuration, GDB may be able to give you more
873 information about the status of the floating point hardware.
876 Display hardware-dependent information about the floating point
877 unit. The exact contents and layout vary depending on the
878 floating point chip. Currently, `info float' is supported on the
879 ARM and x86 machines.
882 File: gdb.info, Node: Languages, Next: Symbols, Prev: Data, Up: Top
884 Using GDB with Different Languages
885 **********************************
887 Although programming languages generally have common aspects, they
888 are rarely expressed in the same manner. For instance, in ANSI C,
889 dereferencing a pointer `p' is accomplished by `*p', but in Modula-2,
890 it is accomplished by `p^'. Values can also be represented (and
891 displayed) differently. Hex numbers in C appear as `0x1ae', while in
892 Modula-2 they appear as `1AEH'.
894 Language-specific information is built into GDB for some languages,
895 allowing you to express operations like the above in your program's
896 native language, and allowing GDB to output values in a manner
897 consistent with the syntax of your program's native language. The
898 language you use to build expressions is called the "working language".
902 * Setting:: Switching between source languages
903 * Show:: Displaying the language
905 * Checks:: Type and range checks
907 * Support:: Supported languages
910 File: gdb.info, Node: Setting, Next: Show, Prev: Languages, Up: Languages
912 Switching between source languages
913 ==================================
915 There are two ways to control the working language--either have GDB
916 set it automatically, or select it manually yourself. You can use the
917 `set language' command for either purpose. On startup, GDB defaults to
918 setting the language automatically. The working language is used to
919 determine how expressions you type are interpreted, how values are
922 In addition to the working language, every source file that GDB
923 knows about has its own working language. For some object file
924 formats, the compiler might indicate which language a particular source
925 file is in. However, most of the time GDB infers the language from the
926 name of the file. The language of a source file controls whether C++
927 names are demangled--this way `backtrace' can show each frame
928 appropriately for its own language. There is no way to set the
929 language of a source file from within GDB.
931 This is most commonly a problem when you use a program, such as
932 `cfront' or `f2c', that generates C but is written in another language.
933 In that case, make the program use `#line' directives in its C output;
934 that way GDB will know the correct language of the source code of the
935 original program, and will display that source code, not the generated
940 * Filenames:: Filename extensions and languages.
941 * Manually:: Setting the working language manually
942 * Automatically:: Having GDB infer the source language
945 File: gdb.info, Node: Filenames, Next: Manually, Prev: Setting, Up: Setting
947 List of filename extensions and languages
948 -----------------------------------------
950 If a source file name ends in one of the following extensions, then
951 GDB infers that its language is the one indicated.
978 Assembler source file. This actually behaves almost like C, but
979 GDB does not skip over function prologues when stepping.
981 In addition, you may set the language associated with a filename
982 extension. *Note Displaying the language: Show.
985 File: gdb.info, Node: Manually, Next: Automatically, Prev: Filenames, Up: Setting
987 Setting the working language
988 ----------------------------
990 If you allow GDB to set the language automatically, expressions are
991 interpreted the same way in your debugging session and your program.
993 If you wish, you may set the language manually. To do this, issue
994 the command `set language LANG', where LANG is the name of a language,
995 such as `c' or `modula-2'. For a list of the supported languages, type
998 Setting the language manually prevents GDB from updating the working
999 language automatically. This can lead to confusion if you try to debug
1000 a program when the working language is not the same as the source
1001 language, when an expression is acceptable to both languages--but means
1002 different things. For instance, if the current source file were
1003 written in C, and GDB was parsing Modula-2, a command such as:
1007 might not have the effect you intended. In C, this means to add `b'
1008 and `c' and place the result in `a'. The result printed would be the
1009 value of `a'. In Modula-2, this means to compare `a' to the result of
1010 `b+c', yielding a `BOOLEAN' value.
1013 File: gdb.info, Node: Automatically, Prev: Manually, Up: Setting
1015 Having GDB infer the source language
1016 ------------------------------------
1018 To have GDB set the working language automatically, use `set
1019 language local' or `set language auto'. GDB then infers the working
1020 language. That is, when your program stops in a frame (usually by
1021 encountering a breakpoint), GDB sets the working language to the
1022 language recorded for the function in that frame. If the language for
1023 a frame is unknown (that is, if the function or block corresponding to
1024 the frame was defined in a source file that does not have a recognized
1025 extension), the current working language is not changed, and GDB issues
1028 This may not seem necessary for most programs, which are written
1029 entirely in one source language. However, program modules and libraries
1030 written in one source language can be used by a main program written in
1031 a different source language. Using `set language auto' in this case
1032 frees you from having to set the working language manually.
1035 File: gdb.info, Node: Show, Next: Checks, Prev: Setting, Up: Languages
1037 Displaying the language
1038 =======================
1040 The following commands help you find out which language is the
1041 working language, and also what language source files were written in.
1044 Display the current working language. This is the language you
1045 can use with commands such as `print' to build and compute
1046 expressions that may involve variables in your program.
1049 Display the source language for this frame. This language becomes
1050 the working language if you use an identifier from this frame.
1051 *Note Information about a frame: Frame Info, to identify the other
1052 information listed here.
1055 Display the source language of this source file. *Note Examining
1056 the Symbol Table: Symbols, to identify the other information
1059 In unusual circumstances, you may have source files with extensions
1060 not in the standard list. You can then set the extension associated
1061 with a language explicitly:
1063 `set extension-language .EXT LANGUAGE'
1064 Set source files with extension .EXT to be assumed to be in the
1065 source language LANGUAGE.
1068 List all the filename extensions and the associated languages.
1071 File: gdb.info, Node: Checks, Next: Support, Prev: Show, Up: Languages
1073 Type and range checking
1074 =======================
1076 *Warning:* In this release, the GDB commands for type and range
1077 checking are included, but they do not yet have any effect. This
1078 section documents the intended facilities.
1080 Some languages are designed to guard you against making seemingly
1081 common errors through a series of compile- and run-time checks. These
1082 include checking the type of arguments to functions and operators, and
1083 making sure mathematical overflows are caught at run time. Checks such
1084 as these help to ensure a program's correctness once it has been
1085 compiled by eliminating type mismatches, and providing active checks
1086 for range errors when your program is running.
1088 GDB can check for conditions like the above if you wish. Although
1089 GDB does not check the statements in your program, it can check
1090 expressions entered directly into GDB for evaluation via the `print'
1091 command, for example. As with the working language, GDB can also
1092 decide whether or not to check automatically based on your program's
1093 source language. *Note Supported languages: Support, for the default
1094 settings of supported languages.
1098 * Type Checking:: An overview of type checking
1099 * Range Checking:: An overview of range checking
1102 File: gdb.info, Node: Type Checking, Next: Range Checking, Prev: Checks, Up: Checks
1104 An overview of type checking
1105 ----------------------------
1107 Some languages, such as Modula-2, are strongly typed, meaning that
1108 the arguments to operators and functions have to be of the correct type,
1109 otherwise an error occurs. These checks prevent type mismatch errors
1110 from ever causing any run-time problems. For example,
1116 The second example fails because the `CARDINAL' 1 is not
1117 type-compatible with the `REAL' 2.3.
1119 For the expressions you use in GDB commands, you can tell the GDB
1120 type checker to skip checking; to treat any mismatches as errors and
1121 abandon the expression; or to only issue warnings when type mismatches
1122 occur, but evaluate the expression anyway. When you choose the last of
1123 these, GDB evaluates expressions like the second example above, but
1124 also issues a warning.
1126 Even if you turn type checking off, there may be other reasons
1127 related to type that prevent GDB from evaluating an expression. For
1128 instance, GDB does not know how to add an `int' and a `struct foo'.
1129 These particular type errors have nothing to do with the language in
1130 use, and usually arise from expressions, such as the one described
1131 above, which make little sense to evaluate anyway.
1133 Each language defines to what degree it is strict about type. For
1134 instance, both Modula-2 and C require the arguments to arithmetical
1135 operators to be numbers. In C, enumerated types and pointers can be
1136 represented as numbers, so that they are valid arguments to mathematical
1137 operators. *Note Supported languages: Support, for further details on
1140 GDB provides some additional commands for controlling the type
1143 `set check type auto'
1144 Set type checking on or off based on the current working language.
1145 *Note Supported languages: Support, for the default settings for
1149 `set check type off'
1150 Set type checking on or off, overriding the default setting for the
1151 current working language. Issue a warning if the setting does not
1152 match the language default. If any type mismatches occur in
1153 evaluating an expression while typechecking is on, GDB prints a
1154 message and aborts evaluation of the expression.
1156 `set check type warn'
1157 Cause the type checker to issue warnings, but to always attempt to
1158 evaluate the expression. Evaluating the expression may still be
1159 impossible for other reasons. For example, GDB cannot add numbers
1163 Show the current setting of the type checker, and whether or not
1164 GDB is setting it automatically.
1167 File: gdb.info, Node: Range Checking, Prev: Type Checking, Up: Checks
1169 An overview of range checking
1170 -----------------------------
1172 In some languages (such as Modula-2), it is an error to exceed the
1173 bounds of a type; this is enforced with run-time checks. Such range
1174 checking is meant to ensure program correctness by making sure
1175 computations do not overflow, or indices on an array element access do
1176 not exceed the bounds of the array.
1178 For expressions you use in GDB commands, you can tell GDB to treat
1179 range errors in one of three ways: ignore them, always treat them as
1180 errors and abandon the expression, or issue warnings but evaluate the
1183 A range error can result from numerical overflow, from exceeding an
1184 array index bound, or when you type a constant that is not a member of
1185 any type. Some languages, however, do not treat overflows as an error.
1186 In many implementations of C, mathematical overflow causes the result
1187 to "wrap around" to lower values--for example, if M is the largest
1188 integer value, and S is the smallest, then
1192 This, too, is specific to individual languages, and in some cases
1193 specific to individual compilers or machines. *Note Supported
1194 languages: Support, for further details on specific languages.
1196 GDB provides some additional commands for controlling the range
1199 `set check range auto'
1200 Set range checking on or off based on the current working language.
1201 *Note Supported languages: Support, for the default settings for
1204 `set check range on'
1205 `set check range off'
1206 Set range checking on or off, overriding the default setting for
1207 the current working language. A warning is issued if the setting
1208 does not match the language default. If a range error occurs,
1209 then a message is printed and evaluation of the expression is
1212 `set check range warn'
1213 Output messages when the GDB range checker detects a range error,
1214 but attempt to evaluate the expression anyway. Evaluating the
1215 expression may still be impossible for other reasons, such as
1216 accessing memory that the process does not own (a typical example
1217 from many Unix systems).
1220 Show the current setting of the range checker, and whether or not
1221 it is being set automatically by GDB.
1224 File: gdb.info, Node: Support, Prev: Checks, Up: Languages
1229 GDB supports C, C++, Fortran, Chill, assembly, and Modula-2. Some
1230 GDB features may be used in expressions regardless of the language you
1231 use: the GDB `@' and `::' operators, and the `{type}addr' construct
1232 (*note Expressions: Expressions.) can be used with the constructs of
1233 any supported language.
1235 The following sections detail to what degree each source language is
1236 supported by GDB. These sections are not meant to be language
1237 tutorials or references, but serve only as a reference guide to what the
1238 GDB expression parser accepts, and what input and output formats should
1239 look like for different languages. There are many good books written
1240 on each of these languages; please look to these for a language
1241 reference or tutorial.
1246 * Modula-2:: Modula-2
1249 File: gdb.info, Node: C, Next: Modula-2, Up: Support
1254 Since C and C++ are so closely related, many features of GDB apply
1255 to both languages. Whenever this is the case, we discuss those
1258 The C++ debugging facilities are jointly implemented by the C++
1259 compiler and GDB. Therefore, to debug your C++ code effectively, you
1260 must compile your C++ programs with a supported C++ compiler, such as
1261 GNU `g++', or the HP ANSI C++ compiler (`aCC').
1263 For best results when using GNU C++, use the stabs debugging format.
1264 You can select that format explicitly with the `g++' command-line
1265 options `-gstabs' or `-gstabs+'. See *Note Options for Debugging Your
1266 Program or GNU CC: (gcc.info)Debugging Options, for more information.
1270 * C Operators:: C and C++ operators
1271 * C Constants:: C and C++ constants
1272 * Cplus expressions:: C++ expressions
1273 * C Defaults:: Default settings for C and C++
1275 * C Checks:: C and C++ type and range checks
1277 * Debugging C:: GDB and C
1278 * Debugging C plus plus:: GDB features for C++