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: C Operators, Next: C Constants, Up: C
33 Operators must be defined on values of specific types. For instance,
34 `+' is defined on numbers, but not on structures. Operators are often
35 defined on groups of types.
37 For the purposes of C and C++, the following definitions hold:
39 * *Integral types* include `int' with any of its storage-class
40 specifiers; `char'; and `enum'.
42 * *Floating-point types* include `float' and `double'.
44 * *Pointer types* include all types defined as `(TYPE *)'.
46 * *Scalar types* include all of the above.
48 The following operators are supported. They are listed here in order
49 of increasing precedence:
52 The comma or sequencing operator. Expressions in a
53 comma-separated list are evaluated from left to right, with the
54 result of the entire expression being the last expression
58 Assignment. The value of an assignment expression is the value
59 assigned. Defined on scalar types.
62 Used in an expression of the form `A OP= B', and translated to
63 `A = A OP B'. `OP=' and `=' have the same precendence. OP is any
64 one of the operators `|', `^', `&', `<<', `>>', `+', `-', `*',
68 The ternary operator. `A ? B : C' can be thought of as: if A
69 then B else C. A should be of an integral type.
72 Logical OR. Defined on integral types.
75 Logical AND. Defined on integral types.
78 Bitwise OR. Defined on integral types.
81 Bitwise exclusive-OR. Defined on integral types.
84 Bitwise AND. Defined on integral types.
87 Equality and inequality. Defined on scalar types. The value of
88 these expressions is 0 for false and non-zero for true.
91 Less than, greater than, less than or equal, greater than or equal.
92 Defined on scalar types. The value of these expressions is 0 for
93 false and non-zero for true.
96 left shift, and right shift. Defined on integral types.
99 The GDB "artificial array" operator (*note Expressions:
103 Addition and subtraction. Defined on integral types,
104 floating-point types and pointer types.
107 Multiplication, division, and modulus. Multiplication and
108 division are defined on integral and floating-point types.
109 Modulus is defined on integral types.
112 Increment and decrement. When appearing before a variable, the
113 operation is performed before the variable is used in an
114 expression; when appearing after it, the variable's value is used
115 before the operation takes place.
118 Pointer dereferencing. Defined on pointer types. Same precedence
122 Address operator. Defined on variables. Same precedence as `++'.
124 For debugging C++, GDB implements a use of `&' beyond what is
125 allowed in the C++ language itself: you can use `&(&REF)' (or, if
126 you prefer, simply `&&REF') to examine the address where a C++
127 reference variable (declared with `&REF') is stored.
130 Negative. Defined on integral and floating-point types. Same
134 Logical negation. Defined on integral types. Same precedence as
138 Bitwise complement operator. Defined on integral types. Same
142 Structure member, and pointer-to-structure member. For
143 convenience, GDB regards the two as equivalent, choosing whether
144 to dereference a pointer based on the stored type information.
145 Defined on `struct' and `union' data.
148 Array indexing. `A[I]' is defined as `*(A+I)'. Same precedence
152 Function parameter list. Same precedence as `->'.
155 C++ scope resolution operator. Defined on `struct', `union', and
159 Doubled colons also represent the GDB scope operator (*note
160 Expressions: Expressions.). Same precedence as `::', above.
167 File: gdb.info, Node: C Constants, Next: Cplus expressions, Prev: C Operators, Up: C
172 GDB allows you to express the constants of C and C++ in the
175 * Integer constants are a sequence of digits. Octal constants are
176 specified by a leading `0' (i.e. zero), and hexadecimal constants
177 by a leading `0x' or `0X'. Constants may also end with a letter
178 `l', specifying that the constant should be treated as a `long'
181 * Floating point constants are a sequence of digits, followed by a
182 decimal point, followed by a sequence of digits, and optionally
183 followed by an exponent. An exponent is of the form:
184 `e[[+]|-]NNN', where NNN is another sequence of digits. The `+'
185 is optional for positive exponents.
187 * Enumerated constants consist of enumerated identifiers, or their
188 integral equivalents.
190 * Character constants are a single character surrounded by single
191 quotes (`''), or a number--the ordinal value of the corresponding
192 character (usually its ASCII value). Within quotes, the single
193 character may be represented by a letter or by "escape sequences",
194 which are of the form `\NNN', where NNN is the octal representation
195 of the character's ordinal value; or of the form `\X', where `X'
196 is a predefined special character--for example, `\n' for newline.
198 * String constants are a sequence of character constants surrounded
199 by double quotes (`"').
201 * Pointer constants are an integral value. You can also write
202 pointers to constants using the C operator `&'.
204 * Array constants are comma-separated lists surrounded by braces `{'
205 and `}'; for example, `{1,2,3}' is a three-element array of
206 integers, `{{1,2}, {3,4}, {5,6}}' is a three-by-two array, and
207 `{&"hi", &"there", &"fred"}' is a three-element array of pointers.
211 * Cplus expressions::
219 File: gdb.info, Node: Cplus expressions, Next: C Defaults, Prev: C Constants, Up: C
224 GDB expression handling can interpret most C++ expressions.
226 *Warning:* GDB can only debug C++ code if you use the proper
227 compiler. Typically, C++ debugging depends on the use of
228 additional debugging information in the symbol table, and thus
229 requires special support. In particular, if your compiler
230 generates a.out, MIPS ECOFF, RS/6000 XCOFF, or ELF with stabs
231 extensions to the symbol table, these facilities are all
232 available. (With GNU CC, you can use the `-gstabs' option to
233 request stabs debugging extensions explicitly.) Where the object
234 code format is standard COFF or DWARF in ELF, on the other hand,
235 most of the C++ support in GDB does *not* work.
237 1. Member function calls are allowed; you can use expressions like
239 count = aml->GetOriginal(x, y)
241 2. While a member function is active (in the selected stack frame),
242 your expressions have the same namespace available as the member
243 function; that is, GDB allows implicit references to the class
244 instance pointer `this' following the same rules as C++.
246 3. You can call overloaded functions; GDB resolves the function call
247 to the right definition, with one restriction--you must use
248 arguments of the type required by the function that you want to
249 call. GDB does not perform conversions requiring constructors or
250 user-defined type operators.
252 4. GDB understands variables declared as C++ references; you can use
253 them in expressions just as you do in C++ source--they are
254 automatically dereferenced.
256 In the parameter list shown when GDB displays a frame, the values
257 of reference variables are not displayed (unlike other variables);
258 this avoids clutter, since references are often used for large
259 structures. The *address* of a reference variable is always
260 shown, unless you have specified `set print address off'.
262 5. GDB supports the C++ name resolution operator `::'--your
263 expressions can use it just as expressions in your program do.
264 Since one scope may be defined in another, you can use `::'
265 repeatedly if necessary, for example in an expression like
266 `SCOPE1::SCOPE2::NAME'. GDB also allows resolving name scope by
267 reference to source files, in both C and C++ debugging (*note
268 Program variables: Variables.).
271 File: gdb.info, Node: C Defaults, Next: C Checks, Prev: Cplus expressions, Up: C
276 If you allow GDB to set type and range checking automatically, they
277 both default to `off' whenever the working language changes to C or
278 C++. This happens regardless of whether you or GDB selects the working
281 If you allow GDB to set the language automatically, it recognizes
282 source files whose names end with `.c', `.C', or `.cc', etc, and when
283 GDB enters code compiled from one of these files, it sets the working
284 language to C or C++. *Note Having GDB infer the source language:
285 Automatically, for further details.
288 File: gdb.info, Node: C Checks, Next: Debugging C, Prev: C Defaults, Up: C Constants
290 C and C++ type and range checks
291 ...............................
293 By default, when GDB parses C or C++ expressions, type checking is
294 not used. However, if you turn type checking on, GDB considers two
295 variables type equivalent if:
297 * The two variables are structured and have the same structure,
298 union, or enumerated tag.
300 * The two variables have the same type name, or types that have been
301 declared equivalent through `typedef'.
303 Range checking, if turned on, is done on mathematical operations.
304 Array indices are not checked, since they are often used to index a
305 pointer that is not itself an array.
308 File: gdb.info, Node: Debugging C, Next: Debugging C plus plus, Prev: C Checks, Up: C
313 The `set print union' and `show print union' commands apply to the
314 `union' type. When set to `on', any `union' that is inside a `struct'
315 or `class' is also printed. Otherwise, it appears as `{...}'.
317 The `@' operator aids in the debugging of dynamic arrays, formed
318 with pointers and a memory allocation function. *Note Expressions:
323 * Debugging C plus plus::
326 File: gdb.info, Node: Debugging C plus plus, Prev: Debugging C, Up: C
331 Some GDB commands are particularly useful with C++, and some are
332 designed specifically for use with C++. Here is a summary:
335 When you want a breakpoint in a function whose name is overloaded,
336 GDB breakpoint menus help you specify which function definition
337 you want. *Note Breakpoint menus: Breakpoint Menus.
340 Setting breakpoints using regular expressions is helpful for
341 setting breakpoints on overloaded functions that are not members
342 of any special classes. *Note Setting breakpoints: Set Breaks.
346 Debug C++ exception handling using these commands. *Note Setting
347 catchpoints: Set Catchpoints.
350 Print inheritance relationships as well as other information for
351 type TYPENAME. *Note Examining the Symbol Table: Symbols.
354 `show print demangle'
355 `set print asm-demangle'
356 `show print asm-demangle'
357 Control whether C++ symbols display in their source form, both when
358 displaying code as C++ source and when displaying disassemblies.
359 *Note Print settings: Print Settings.
363 Choose whether to print derived (actual) or declared types of
364 objects. *Note Print settings: Print Settings.
368 Control the format for printing virtual function tables. *Note
369 Print settings: Print Settings.
371 `Overloaded symbol names'
372 You can specify a particular definition of an overloaded symbol,
373 using the same notation that is used to declare such symbols in
374 C++: type `SYMBOL(TYPES)' rather than just SYMBOL. You can also
375 use the GDB command-line word completion facilities to list the
376 available choices, or to finish the type list for you. *Note
377 Command completion: Completion, for details on how to do this.
380 File: gdb.info, Node: Modula-2, Prev: C, Up: Support
385 The extensions made to GDB to support Modula-2 only support output
386 from the GNU Modula-2 compiler (which is currently being developed).
387 Other Modula-2 compilers are not currently supported, and attempting to
388 debug executables produced by them is most likely to give an error as
389 GDB reads in the executable's symbol table.
393 * M2 Operators:: Built-in operators
394 * Built-In Func/Proc:: Built-in functions and procedures
395 * M2 Constants:: Modula-2 constants
396 * M2 Defaults:: Default settings for Modula-2
397 * Deviations:: Deviations from standard Modula-2
398 * M2 Checks:: Modula-2 type and range checks
399 * M2 Scope:: The scope operators `::' and `.'
400 * GDB/M2:: GDB and Modula-2
403 File: gdb.info, Node: M2 Operators, Next: Built-In Func/Proc, Prev: Modula-2, Up: Modula-2
408 Operators must be defined on values of specific types. For instance,
409 `+' is defined on numbers, but not on structures. Operators are often
410 defined on groups of types. For the purposes of Modula-2, the
411 following definitions hold:
413 * *Integral types* consist of `INTEGER', `CARDINAL', and their
416 * *Character types* consist of `CHAR' and its subranges.
418 * *Floating-point types* consist of `REAL'.
420 * *Pointer types* consist of anything declared as `POINTER TO TYPE'.
422 * *Scalar types* consist of all of the above.
424 * *Set types* consist of `SET' and `BITSET' types.
426 * *Boolean types* consist of `BOOLEAN'.
428 The following operators are supported, and appear in order of
429 increasing precedence:
432 Function argument or array index separator.
435 Assignment. The value of VAR `:=' VALUE is VALUE.
438 Less than, greater than on integral, floating-point, or enumerated
442 Less than, greater than, less than or equal to, greater than or
443 equal to on integral, floating-point and enumerated types, or set
444 inclusion on set types. Same precedence as `<'.
447 Equality and two ways of expressing inequality, valid on scalar
448 types. Same precedence as `<'. In GDB scripts, only `<>' is
449 available for inequality, since `#' conflicts with the script
453 Set membership. Defined on set types and the types of their
454 members. Same precedence as `<'.
457 Boolean disjunction. Defined on boolean types.
460 Boolean conjuction. Defined on boolean types.
463 The GDB "artificial array" operator (*note Expressions:
467 Addition and subtraction on integral and floating-point types, or
468 union and difference on set types.
471 Multiplication on integral and floating-point types, or set
472 intersection on set types.
475 Division on floating-point types, or symmetric set difference on
476 set types. Same precedence as `*'.
479 Integer division and remainder. Defined on integral types. Same
483 Negative. Defined on `INTEGER' and `REAL' data.
486 Pointer dereferencing. Defined on pointer types.
489 Boolean negation. Defined on boolean types. Same precedence as
493 `RECORD' field selector. Defined on `RECORD' data. Same
497 Array indexing. Defined on `ARRAY' data. Same precedence as `^'.
500 Procedure argument list. Defined on `PROCEDURE' objects. Same
504 GDB and Modula-2 scope operators.
506 *Warning:* Sets and their operations are not yet supported, so GDB
507 treats the use of the operator `IN', or the use of operators `+',
508 `-', `*', `/', `=', , `<>', `#', `<=', and `>=' on sets as an
512 File: gdb.info, Node: Built-In Func/Proc, Next: M2 Constants, Prev: M2 Operators, Up: Modula-2
514 Built-in functions and procedures
515 .................................
517 Modula-2 also makes available several built-in procedures and
518 functions. In describing these, the following metavariables are used:
521 represents an `ARRAY' variable.
524 represents a `CHAR' constant or variable.
527 represents a variable or constant of integral type.
530 represents an identifier that belongs to a set. Generally used in
531 the same function with the metavariable S. The type of S should
532 be `SET OF MTYPE' (where MTYPE is the type of M).
535 represents a variable or constant of integral or floating-point
539 represents a variable or constant of floating-point type.
545 represents a variable.
548 represents a variable or constant of one of many types. See the
549 explanation of the function for details.
551 All Modula-2 built-in procedures also return a result, described
555 Returns the absolute value of N.
558 If C is a lower case letter, it returns its upper case equivalent,
559 otherwise it returns its argument
562 Returns the character whose ordinal value is I.
565 Decrements the value in the variable V. Returns the new value.
568 Decrements the value in the variable V by I. Returns the new
572 Removes the element M from the set S. Returns the new set.
575 Returns the floating point equivalent of the integer I.
578 Returns the index of the last member of A.
581 Increments the value in the variable V. Returns the new value.
584 Increments the value in the variable V by I. Returns the new
588 Adds the element M to the set S if it is not already there.
592 Returns the maximum value of the type T.
595 Returns the minimum value of the type T.
598 Returns boolean TRUE if I is an odd number.
601 Returns the ordinal value of its argument. For example, the
602 ordinal value of a character is its ASCII value (on machines
603 supporting the ASCII character set). X must be of an ordered
604 type, which include integral, character and enumerated types.
607 Returns the size of its argument. X can be a variable or a type.
610 Returns the integral part of R.
613 Returns the member of the type T whose ordinal value is I.
615 *Warning:* Sets and their operations are not yet supported, so
616 GDB treats the use of procedures `INCL' and `EXCL' as an error.
619 File: gdb.info, Node: M2 Constants, Next: M2 Defaults, Prev: Built-In Func/Proc, Up: Modula-2
624 GDB allows you to express the constants of Modula-2 in the following
627 * Integer constants are simply a sequence of digits. When used in an
628 expression, a constant is interpreted to be type-compatible with
629 the rest of the expression. Hexadecimal integers are specified by
630 a trailing `H', and octal integers by a trailing `B'.
632 * Floating point constants appear as a sequence of digits, followed
633 by a decimal point and another sequence of digits. An optional
634 exponent can then be specified, in the form `E[+|-]NNN', where
635 `[+|-]NNN' is the desired exponent. All of the digits of the
636 floating point constant must be valid decimal (base 10) digits.
638 * Character constants consist of a single character enclosed by a
639 pair of like quotes, either single (`'') or double (`"'). They may
640 also be expressed by their ordinal value (their ASCII value,
641 usually) followed by a `C'.
643 * String constants consist of a sequence of characters enclosed by a
644 pair of like quotes, either single (`'') or double (`"'). Escape
645 sequences in the style of C are also allowed. *Note C and C++
646 constants: C Constants, for a brief explanation of escape
649 * Enumerated constants consist of an enumerated identifier.
651 * Boolean constants consist of the identifiers `TRUE' and `FALSE'.
653 * Pointer constants consist of integral values only.
655 * Set constants are not yet supported.
658 File: gdb.info, Node: M2 Defaults, Next: Deviations, Prev: M2 Constants, Up: Modula-2
663 If type and range checking are set automatically by GDB, they both
664 default to `on' whenever the working language changes to Modula-2.
665 This happens regardless of whether you, or GDB, selected the working
668 If you allow GDB to set the language automatically, then entering
669 code compiled from a file whose name ends with `.mod' sets the working
670 language to Modula-2. *Note Having GDB set the language automatically:
671 Automatically, for further details.
674 File: gdb.info, Node: Deviations, Next: M2 Checks, Prev: M2 Defaults, Up: Modula-2
676 Deviations from standard Modula-2
677 .................................
679 A few changes have been made to make Modula-2 programs easier to
680 debug. This is done primarily via loosening its type strictness:
682 * Unlike in standard Modula-2, pointer constants can be formed by
683 integers. This allows you to modify pointer variables during
684 debugging. (In standard Modula-2, the actual address contained in
685 a pointer variable is hidden from you; it can only be modified
686 through direct assignment to another pointer variable or
687 expression that returned a pointer.)
689 * C escape sequences can be used in strings and characters to
690 represent non-printable characters. GDB prints out strings with
691 these escape sequences embedded. Single non-printable characters
692 are printed using the `CHR(NNN)' format.
694 * The assignment operator (`:=') returns the value of its right-hand
697 * All built-in procedures both modify *and* return their argument.
700 File: gdb.info, Node: M2 Checks, Next: M2 Scope, Prev: Deviations, Up: Modula-2
702 Modula-2 type and range checks
703 ..............................
705 *Warning:* in this release, GDB does not yet perform type or range
708 GDB considers two Modula-2 variables type equivalent if:
710 * They are of types that have been declared equivalent via a `TYPE
713 * They have been declared on the same line. (Note: This is true of
714 the GNU Modula-2 compiler, but it may not be true of other
717 As long as type checking is enabled, any attempt to combine variables
718 whose types are not equivalent is an error.
720 Range checking is done on all mathematical operations, assignment,
721 array index bounds, and all built-in functions and procedures.
724 File: gdb.info, Node: M2 Scope, Next: GDB/M2, Prev: M2 Checks, Up: Modula-2
726 The scope operators `::' and `.'
727 ................................
729 There are a few subtle differences between the Modula-2 scope
730 operator (`.') and the GDB scope operator (`::'). The two have similar
737 where SCOPE is the name of a module or a procedure, MODULE the name of
738 a module, and ID is any declared identifier within your program, except
741 Using the `::' operator makes GDB search the scope specified by
742 SCOPE for the identifier ID. If it is not found in the specified
743 scope, then GDB searches all scopes enclosing the one specified by
746 Using the `.' operator makes GDB search the current scope for the
747 identifier specified by ID that was imported from the definition module
748 specified by MODULE. With this operator, it is an error if the
749 identifier ID was not imported from definition module MODULE, or if ID
750 is not an identifier in MODULE.
753 File: gdb.info, Node: GDB/M2, Prev: M2 Scope, Up: Modula-2
758 Some GDB commands have little use when debugging Modula-2 programs.
759 Five subcommands of `set print' and `show print' apply specifically to
760 C and C++: `vtbl', `demangle', `asm-demangle', `object', and `union'.
761 The first four apply to C++, and the last to the C `union' type, which
762 has no direct analogue in Modula-2.
764 The `@' operator (*note Expressions: Expressions.), while available
765 while using any language, is not useful with Modula-2. Its intent is
766 to aid the debugging of "dynamic arrays", which cannot be created in
767 Modula-2 as they can in C or C++. However, because an address can be
768 specified by an integral constant, the construct `{TYPE}ADREXP' is
769 still useful. (*note Expressions: Expressions.)
771 In GDB scripts, the Modula-2 inequality operator `#' is interpreted
772 as the beginning of a comment. Use `<>' instead.
775 File: gdb.info, Node: Symbols, Next: Altering, Prev: Languages, Up: Top
777 Examining the Symbol Table
778 **************************
780 The commands described in this section allow you to inquire about the
781 symbols (names of variables, functions and types) defined in your
782 program. This information is inherent in the text of your program and
783 does not change as your program executes. GDB finds it in your
784 program's symbol table, in the file indicated when you started GDB
785 (*note Choosing files: File Options.), or by one of the file-management
786 commands (*note Commands to specify files: Files.).
788 Occasionally, you may need to refer to symbols that contain unusual
789 characters, which GDB ordinarily treats as word delimiters. The most
790 frequent case is in referring to static variables in other source files
791 (*note Program variables: Variables.). File names are recorded in
792 object files as debugging symbols, but GDB would ordinarily parse a
793 typical file name, like `foo.c', as the three words `foo' `.' `c'. To
794 allow GDB to recognize `foo.c' as a single symbol, enclose it in single
799 looks up the value of `x' in the scope of the file `foo.c'.
801 `info address SYMBOL'
802 Describe where the data for SYMBOL is stored. For a register
803 variable, this says which register it is kept in. For a
804 non-register local variable, this prints the stack-frame offset at
805 which the variable is always stored.
807 Note the contrast with `print &SYMBOL', which does not work at all
808 for a register variable, and for a stack local variable prints the
809 exact address of the current instantiation of the variable.
812 Print the data type of expression EXP. EXP is not actually
813 evaluated, and any side-effecting operations (such as assignments
814 or function calls) inside it do not take place. *Note
815 Expressions: Expressions.
818 Print the data type of `$', the last value in the value history.
821 Print a description of data type TYPENAME. TYPENAME may be the
822 name of a type, or for C code it may have the form `class
823 CLASS-NAME', `struct STRUCT-TAG', `union UNION-TAG' or `enum
828 Print a description of the type of expression EXP. `ptype'
829 differs from `whatis' by printing a detailed description, instead
830 of just the name of the type.
832 For example, for this variable declaration:
834 struct complex {double real; double imag;} v;
836 the two commands give this output:
839 type = struct complex
841 type = struct complex {
846 As with `whatis', using `ptype' without an argument refers to the
847 type of `$', the last value in the value history.
851 Print a brief description of all types whose name matches REGEXP
852 (or all types in your program, if you supply no argument). Each
853 complete typename is matched as though it were a complete line;
854 thus, `i type value' gives information on all types in your
855 program whose name includes the string `value', but `i type
856 ^value$' gives information only on types whose complete name is
859 This command differs from `ptype' in two ways: first, like
860 `whatis', it does not print a detailed description; second, it
861 lists all source files where a type is defined.
864 Show the name of the current source file--that is, the source file
865 for the function containing the current point of execution--and
866 the language it was written in.
869 Print the names of all source files in your program for which
870 there is debugging information, organized into two lists: files
871 whose symbols have already been read, and files whose symbols will
875 Print the names and data types of all defined functions.
877 `info functions REGEXP'
878 Print the names and data types of all defined functions whose
879 names contain a match for regular expression REGEXP. Thus, `info
880 fun step' finds all functions whose names include `step'; `info
881 fun ^step' finds those whose names start with `step'.
884 Print the names and data types of all variables that are declared
885 outside of functions (i.e., excluding local variables).
887 `info variables REGEXP'
888 Print the names and data types of all variables (except for local
889 variables) whose names contain a match for regular expression
892 Some systems allow individual object files that make up your
893 program to be replaced without stopping and restarting your
894 program. For example, in VxWorks you can simply recompile a
895 defective object file and keep on running. If you are running on
896 one of these systems, you can allow GDB to reload the symbols for
897 automatically relinked modules:
899 `set symbol-reloading on'
900 Replace symbol definitions for the corresponding source file
901 when an object file with a particular name is seen again.
903 `set symbol-reloading off'
904 Do not replace symbol definitions when re-encountering object
905 files of the same name. This is the default state; if you
906 are not running on a system that permits automatically
907 relinking modules, you should leave `symbol-reloading' off,
908 since otherwise GDB may discard symbols when linking large
909 programs, that may contain several modules (from different
910 directories or libraries) with the same name.
912 `show symbol-reloading'
913 Show the current `on' or `off' setting.
915 `maint print symbols FILENAME'
916 `maint print psymbols FILENAME'
917 `maint print msymbols FILENAME'
918 Write a dump of debugging symbol data into the file FILENAME.
919 These commands are used to debug the GDB symbol-reading code. Only
920 symbols with debugging data are included. If you use `maint print
921 symbols', GDB includes all the symbols for which it has already
922 collected full details: that is, FILENAME reflects symbols for
923 only those files whose symbols GDB has read. You can use the
924 command `info sources' to find out which files these are. If you
925 use `maint print psymbols' instead, the dump shows information
926 about symbols that GDB only knows partially--that is, symbols
927 defined in files that GDB has skimmed, but not yet read
928 completely. Finally, `maint print msymbols' dumps just the
929 minimal symbol information required for each object file from
930 which GDB has read some symbols. *Note Commands to specify files:
931 Files, for a discussion of how GDB reads symbols (in the
932 description of `symbol-file').
935 File: gdb.info, Node: Altering, Next: GDB Files, Prev: Symbols, Up: Top
940 Once you think you have found an error in your program, you might
941 want to find out for certain whether correcting the apparent error
942 would lead to correct results in the rest of the run. You can find the
943 answer by experiment, using the GDB features for altering execution of
946 For example, you can store new values into variables or memory
947 locations, give your program a signal, restart it at a different
948 address, or even return prematurely from a function.
952 * Assignment:: Assignment to variables
953 * Jumping:: Continuing at a different address
955 * Signaling:: Giving your program a signal
957 * Returning:: Returning from a function
958 * Calling:: Calling your program's functions
959 * Patching:: Patching your program
962 File: gdb.info, Node: Assignment, Next: Jumping, Prev: Altering, Up: Altering
964 Assignment to variables
965 =======================
967 To alter the value of a variable, evaluate an assignment expression.
968 *Note Expressions: Expressions. For example,
972 stores the value 4 into the variable `x', and then prints the value of
973 the assignment expression (which is 4). *Note Using GDB with Different
974 Languages: Languages, for more information on operators in supported
977 If you are not interested in seeing the value of the assignment, use
978 the `set' command instead of the `print' command. `set' is really the
979 same as `print' except that the expression's value is not printed and
980 is not put in the value history (*note Value history: Value History.).
981 The expression is evaluated only for its effects.
983 If the beginning of the argument string of the `set' command appears
984 identical to a `set' subcommand, use the `set variable' command instead
985 of just `set'. This command is identical to `set' except for its lack
986 of subcommands. For example, if your program has a variable `width',
987 you get an error if you try to set a new value with just `set
988 width=13', because GDB has the command `set width':
995 Invalid syntax in expression.
997 The invalid expression, of course, is `=47'. In order to actually set
998 the program's variable `width', use
1000 (gdb) set var width=47
1002 GDB allows more implicit conversions in assignments than C; you can
1003 freely store an integer value into a pointer variable or vice versa,
1004 and you can convert any structure to any other structure that is the
1005 same length or shorter.
1007 To store values into arbitrary places in memory, use the `{...}'
1008 construct to generate a value of specified type at a specified address
1009 (*note Expressions: Expressions.). For example, `{int}0x83040' refers
1010 to memory location `0x83040' as an integer (which implies a certain size
1011 and representation in memory), and
1013 set {int}0x83040 = 4
1015 stores the value 4 into that memory location.
1018 File: gdb.info, Node: Jumping, Next: Signaling, Prev: Assignment, Up: Altering
1020 Continuing at a different address
1021 =================================
1023 Ordinarily, when you continue your program, you do so at the place
1024 where it stopped, with the `continue' command. You can instead
1025 continue at an address of your own choosing, with the following
1029 Resume execution at line LINESPEC. Execution stops again
1030 immediately if there is a breakpoint there. *Note Printing source
1031 lines: List, for a description of the different forms of LINESPEC.
1032 It is common practice to use the `tbreak' command in conjunction
1033 with `jump'. *Note Setting breakpoints: Set Breaks.
1035 The `jump' command does not change the current stack frame, or the
1036 stack pointer, or the contents of any memory location or any
1037 register other than the program counter. If line LINESPEC is in a
1038 different function from the one currently executing, the results
1039 may be bizarre if the two functions expect different patterns of
1040 arguments or of local variables. For this reason, the `jump'
1041 command requests confirmation if the specified line is not in the
1042 function currently executing. However, even bizarre results are
1043 predictable if you are well acquainted with the machine-language
1044 code of your program.
1047 Resume execution at the instruction at address ADDRESS.
1049 You can get much the same effect as the `jump' command by storing a
1050 new value into the register `$pc'. The difference is that this does
1051 not start your program running; it only changes the address of where it
1052 *will* run when you continue. For example,
1056 makes the next `continue' command or stepping command execute at
1057 address `0x485', rather than at the address where your program stopped.
1058 *Note Continuing and stepping: Continuing and Stepping.
1060 The most common occasion to use the `jump' command is to back
1061 up--perhaps with more breakpoints set--over a portion of a program that
1062 has already executed, in order to examine its execution in more detail.
1065 File: gdb.info, Node: Signaling, Next: Returning, Prev: Jumping, Up: Altering
1067 Giving your program a signal
1068 ============================
1071 Resume execution where your program stopped, but immediately give
1072 it the signal SIGNAL. SIGNAL can be the name or the number of a
1073 signal. For example, on many systems `signal 2' and `signal
1074 SIGINT' are both ways of sending an interrupt signal.
1076 Alternatively, if SIGNAL is zero, continue execution without
1077 giving a signal. This is useful when your program stopped on
1078 account of a signal and would ordinary see the signal when resumed
1079 with the `continue' command; `signal 0' causes it to resume
1082 `signal' does not repeat when you press <RET> a second time after
1083 executing the command.
1085 Invoking the `signal' command is not the same as invoking the `kill'
1086 utility from the shell. Sending a signal with `kill' causes GDB to
1087 decide what to do with the signal depending on the signal handling
1088 tables (*note Signals::.). The `signal' command passes the signal
1089 directly to your program.
1092 File: gdb.info, Node: Returning, Next: Calling, Prev: Signaling, Up: Altering
1094 Returning from a function
1095 =========================
1099 You can cancel execution of a function call with the `return'
1100 command. If you give an EXPRESSION argument, its value is used as
1101 the function's return value.
1103 When you use `return', GDB discards the selected stack frame (and
1104 all frames within it). You can think of this as making the discarded
1105 frame return prematurely. If you wish to specify a value to be
1106 returned, give that value as the argument to `return'.
1108 This pops the selected stack frame (*note Selecting a frame:
1109 Selection.), and any other frames inside of it, leaving its caller as
1110 the innermost remaining frame. That frame becomes selected. The
1111 specified value is stored in the registers used for returning values of
1114 The `return' command does not resume execution; it leaves the
1115 program stopped in the state that would exist if the function had just
1116 returned. In contrast, the `finish' command (*note Continuing and
1117 stepping: Continuing and Stepping.) resumes execution until the
1118 selected stack frame returns naturally.
1121 File: gdb.info, Node: Calling, Next: Patching, Prev: Returning, Up: Altering
1123 Calling program functions
1124 =========================
1127 Evaluate the expression EXPR without displaying `void' returned
1130 You can use this variant of the `print' command if you want to
1131 execute a function from your program, but without cluttering the output
1132 with `void' returned values. If the result is not void, it is printed
1133 and saved in the value history.
1135 For the A29K, a user-controlled variable `call_scratch_address',
1136 specifies the location of a scratch area to be used when GDB calls a
1137 function in the target. This is necessary because the usual method of
1138 putting the scratch area on the stack does not work in systems that
1139 have separate instruction and data spaces.
1142 File: gdb.info, Node: Patching, Prev: Calling, Up: Altering
1147 By default, GDB opens the file containing your program's executable
1148 code (or the corefile) read-only. This prevents accidental alterations
1149 to machine code; but it also prevents you from intentionally patching
1150 your program's binary.
1152 If you'd like to be able to patch the binary, you can specify that
1153 explicitly with the `set write' command. For example, you might want
1154 to turn on internal debugging flags, or even to make emergency repairs.
1158 If you specify `set write on', GDB opens executable and core files
1159 for both reading and writing; if you specify `set write off' (the
1160 default), GDB opens them read-only.
1162 If you have already loaded a file, you must load it again (using
1163 the `exec-file' or `core-file' command) after changing `set
1164 write', for your new setting to take effect.
1167 Display whether executable files and core files are opened for
1168 writing as well as reading.
1171 File: gdb.info, Node: GDB Files, Next: Targets, Prev: Altering, Up: Top
1176 GDB needs to know the file name of the program to be debugged, both
1177 in order to read its symbol table and in order to start your program.
1178 To debug a core dump of a previous run, you must also tell GDB the name
1179 of the core dump file.
1183 * Files:: Commands to specify files
1184 * Symbol Errors:: Errors reading symbol files