home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / prgramer / unix / info / gdb.i04 (.txt) < prev    next >
GNU Info File  |  1993-06-12  |  52KB  |  965 lines

  1. This is Info file gdb.info, produced by Makeinfo-1.47 from the input
  2. file gdb-all.tex.
  3. START-INFO-DIR-ENTRY
  4. * Gdb: (gdb).                   The GNU debugger.
  5. END-INFO-DIR-ENTRY
  6.    This file documents the GNU debugger GDB.
  7.    This is Edition 4.06, October 1992, of `Debugging with GDB: the GNU
  8. Source-Level Debugger' for GDB Version 4.7.
  9.    Copyright (C) 1988, 1989, 1990, 1991, 1992 Free Software Foundation,
  10.    Permission is granted to make and distribute verbatim copies of this
  11. manual provided the copyright notice and this permission notice are
  12. preserved on all copies.
  13.    Permission is granted to copy and distribute modified versions of
  14. this manual under the conditions for verbatim copying, provided also
  15. that the section entitled "GNU General Public License" is included
  16. exactly as in the original, and provided that the entire resulting
  17. derived work is distributed under the terms of a permission notice
  18. identical to this one.
  19.    Permission is granted to copy and distribute translations of this
  20. manual into another language, under the above conditions for modified
  21. versions, except that the section entitled "GNU General Public License"
  22. may be included in a translation approved by the Free Software
  23. Foundation instead of in the original English.
  24. File: gdb.info,  Node: Languages,  Next: Symbols,  Prev: Data,  Up: Top
  25. Using GDB with Different Languages
  26. **********************************
  27.    Although programming languages generally have common aspects, they
  28. are rarely expressed in the same manner.  For instance, in ANSI C,
  29. dereferencing a pointer `p' is accomplished by `*p', but in Modula-2,
  30. it is accomplished by `p^'.  Values can also be represented (and
  31. displayed) differently.  Hex numbers in C are written like `0x1ae',
  32. while in Modula-2 they appear as `1AEH'.
  33.    Language-specific information is built into GDB for some languages,
  34. allowing you to express operations like the above in your program's
  35. native language, and allowing GDB to output values in a manner
  36. consistent with the syntax of your program's native language.  The
  37. language you use to build expressions, called the "working language",
  38. can be selected manually, or GDB can set it automatically.
  39. * Menu:
  40. * Setting::                     Switching between source languages
  41. * Show::                        Displaying the language
  42. * Checks::                      Type and Range checks
  43. * Support::                     Supported languages
  44. File: gdb.info,  Node: Setting,  Next: Show,  Up: Languages
  45. Switching between source languages
  46. ==================================
  47.    There are two ways to control the working language--either have GDB
  48. set it automatically, or select it manually yourself.  You can use the
  49. `set language' command for either purpose.  On startup, GDB defaults to
  50. setting the language automatically.
  51. * Menu:
  52. * Manually::                    Setting the working language manually
  53. * Automatically::               Having GDB infer the source language
  54. File: gdb.info,  Node: Manually,  Next: Automatically,  Up: Setting
  55. Setting the working language
  56. ----------------------------
  57.    To set the language, issue the command `set language LANG', where
  58. LANG is the name of a language: `c' or `modula-2'. For a list of the
  59. supported languages, type `set language'.
  60.    Setting the language manually prevents GDB from updating the working
  61. language automatically.  This can lead to confusion if you try to debug
  62. a program when the working language is not the same as the source
  63. language, when an expression is acceptable to both languages--but means
  64. different things.  For instance, if the current source file were
  65. written in C, and GDB was parsing Modula-2, a command such as:
  66.      print a = b + c
  67. might not have the effect you intended.  In C, this means to add `b'
  68. and `c' and place the result in `a'.  The result printed would be the
  69. value of `a'.  In Modula-2, this means to compare `a' to the result of
  70. `b+c', yielding a `BOOLEAN' value.
  71.    If you allow GDB to set the language automatically, then you can
  72. count on expressions evaluating the same way in your debugging session
  73. and in your program.
  74. File: gdb.info,  Node: Automatically,  Prev: Manually,  Up: Setting
  75. Having GDB infer the source language
  76. ------------------------------------
  77.    To have GDB set the working language automatically, use `set
  78. language local' or `set language auto'.  GDB then infers the language
  79. that a program was written in by looking at the name of its source
  80. files, and examining their extensions:
  81. `*.mod'
  82.      Modula-2 source file
  83. `*.c'
  84.      C source file
  85. `*.C'
  86. `*.cc'
  87.      C++ source file
  88.    This information is recorded for each function or procedure in a
  89. source file.  When your program stops in a frame (usually by
  90. encountering a breakpoint), GDB sets the working language to the
  91. language recorded for the function in that frame.  If the language for
  92. a frame is unknown (that is, if the function or block corresponding to
  93. the frame was defined in a source file that does not have a recognized
  94. extension), the current working language is not changed, and GDB issues
  95. a warning.
  96.    This may not seem necessary for most programs, which are written
  97. entirely in one source language.  However, program modules and libraries
  98. written in one source language can be used by a main program written in
  99. a different source language.  Using `set language auto' in this case
  100. frees you from having to set the working language manually.
  101. File: gdb.info,  Node: Show,  Next: Checks,  Prev: Setting,  Up: Languages
  102. Displaying the language
  103. =======================
  104.    The following commands will help you find out which language is the
  105. working language, and also what language source files were written in.
  106. `show language'
  107.      Display the current working language.  This is the language you
  108.      can use with commands such as `print' to build and compute
  109.      expressions that may involve variables in your program.
  110. `info frame'
  111.      Among the other information listed here (*note Information about a
  112.      Frame: Frame Info.) is the source language for this frame.  This
  113.      is the language that will become the working language if you ever
  114.      use an identifier that is in this frame.
  115. `info source'
  116.      Among the other information listed here (*note Examining the
  117.      Symbol Table: Symbols.) is the source language of this source file.
  118. File: gdb.info,  Node: Checks,  Next: Support,  Prev: Show,  Up: Languages
  119. Type and range Checking
  120. =======================
  121.      *Warning:* In this release, the GDB commands for type and range
  122.      checking are included, but they do not yet have any effect.  This
  123.      section documents the intended facilities.
  124.    Some languages are designed to guard you against making seemingly
  125. common errors through a series of compile- and run-time checks.  These
  126. include checking the type of arguments to functions and operators, and
  127. making sure mathematical overflows are caught at run time.  Checks such
  128. as these help to ensure a program's correctness once it has been
  129. compiled by eliminating type mismatches, and providing active checks
  130. for range errors when your program is running.
  131.    GDB can check for conditions like the above if you wish. Although
  132. GDB will not check the statements in your program, it can check
  133. expressions entered directly into GDB for evaluation via the `print'
  134. command, for example.  As with the working language, GDB can also
  135. decide whether or not to check automatically based on your program's
  136. source language.  *Note Supported Languages: Support, for the default
  137. settings of supported languages.
  138. * Menu:
  139. * Type Checking::               An overview of type checking
  140. * Range Checking::              An overview of range checking
  141. File: gdb.info,  Node: Type Checking,  Next: Range Checking,  Up: Checks
  142. An overview of type checking
  143. ----------------------------
  144.    Some languages, such as Modula-2, are strongly typed, meaning that
  145. the arguments to operators and functions have to be of the correct type,
  146. otherwise an error occurs.  These checks prevent type mismatch errors
  147. from ever causing any run-time problems.  For example,
  148.      1 + 2 => 3
  149.      error--> 1 + 2.3
  150.    The second example fails because the `CARDINAL' 1 is not
  151. type-compatible with the `REAL' 2.3.
  152.    For expressions you use in GDB commands, you can tell the GDB type
  153. checker to skip checking; to treat any mismatches as errors and abandon
  154. the expression; or only issue warnings when type mismatches occur, but
  155. evaluate the expression anyway.  When you choose the last of these, GDB
  156. evaluates expressions like the second example above, but also issues a
  157. warning.
  158.    Even though you may turn type checking off, other type-based reasons
  159. may prevent GDB from evaluating an expression.  For instance, GDB does
  160. not know how to add an `int' and a `struct foo'.  These particular type
  161. errors have nothing to do with the language in use, and usually arise
  162. from expressions, such as the one described above, which make little
  163. sense to evaluate anyway.
  164.    Each language defines to what degree it is strict about type.  For
  165. instance, both Modula-2 and C require the arguments to arithmetical
  166. operators to be numbers.  In C, enumerated types and pointers can be
  167. represented as numbers, so that they are valid arguments to mathematical
  168. operators.  *Note Supported Languages: Support, for further details on
  169. specific languages.
  170.    GDB provides some additional commands for controlling the type
  171. checker:
  172. `set check type auto'
  173.      Set type checking on or off based on the current working language.
  174.      *Note Supported Languages: Support, for the default settings for
  175.      each language.
  176. `set check type on'
  177. `set check type off'
  178.      Set type checking on or off, overriding the default setting for the
  179.      current working language.  Issue a warning if the setting does not
  180.      match the language's default.  If any type mismatches occur in
  181.      evaluating an expression while typechecking is on, GDB prints a
  182.      message and aborts evaluation of the expression.
  183. `set check type warn'
  184.      Cause the type checker to issue warnings, but to always attempt to
  185.      evaluate the expression.  Evaluating the expression may still be
  186.      impossible for other reasons.  For example, GDB cannot add numbers
  187.      and structures.
  188. `show type'
  189.      Show the current setting of the type checker, and whether or not
  190.      GDB is setting it automatically.
  191. File: gdb.info,  Node: Range Checking,  Prev: Type Checking,  Up: Checks
  192. An overview of Range Checking
  193. -----------------------------
  194.    In some languages (such as Modula-2), it is an error to exceed the
  195. bounds of a type; this is enforced with run-time checks.  Such range
  196. checking is meant to ensure program correctness by making sure
  197. computations do not overflow, or indices on an array element access do
  198. not exceed the bounds of the array.
  199.    For expressions you use in GDB commands, you can tell GDB to ignore
  200. range errors; to always treat them as errors and abandon the
  201. expression; or to issue warnings when a range error occurs but evaluate
  202. the expression anyway.
  203.    A range error can result from numerical overflow, from exceeding an
  204. array index bound, or when you type in a constant that is not a member
  205. of any type.  Some languages, however, do not treat overflows as an
  206. error.  In many implementations of C, mathematical overflow causes the
  207. result to "wrap around" to lower values--for example, if M is the
  208. largest integer value, and S is the smallest, then
  209.      M + 1 => S
  210.    This, too, is specific to individual languages, and in some cases
  211. specific to individual compilers or machines.  *Note  Supported
  212. Languages: Support, for further details on specific languages.
  213.    GDB provides some additional commands for controlling the range
  214. checker:
  215. `set check range auto'
  216.      Set range checking on or off based on the current working language.
  217.      *Note Supported Languages: Support, for the default settings for
  218.      each language.
  219. `set check range on'
  220. `set check range off'
  221.      Set range checking on or off, overriding the default setting for
  222.      the current working language.  A warning is issued if the setting
  223.      does not match the language's default.  If a range error occurs,
  224.      then a message is printed and evaluation of the expression is
  225.      aborted.
  226. `set check range warn'
  227.      Output messages when the GDB range checker detects a range error,
  228.      but attempt to evaluate the expression anyway.  Evaluating the
  229.      expression may still be impossible for other reasons, such as
  230.      accessing memory that the process does not own (a typical example
  231.      from many UNIX systems).
  232. `show range'
  233.      Show the current setting of the range checker, and whether or not
  234.      it is being set automatically by GDB.
  235. File: gdb.info,  Node: Support,  Prev: Checks,  Up: Languages
  236. Supported Languages
  237. ===================
  238.    GDB 4 supports C, C++, and Modula-2.  Some GDB features may be used
  239. in expressions regardless of the language you use: the GDB `@' and `::'
  240. operators, and the `{type}addr' construct (*note Expressions:
  241. Expressions.) can be used with the constructs of any of the supported
  242. languages.
  243.    The following sections detail to what degree each of these source
  244. languages is supported by GDB.  These sections are not meant to be
  245. language tutorials or references, but serve only as a reference guide
  246. to what the GDB expression parser will accept, and what input and
  247. output formats should look like for different languages. There are many
  248. good books written on each of these languages; please look to these for
  249. a language reference or tutorial.
  250. * Menu:
  251. * C::                           C and C++
  252. * Modula-2::                    Modula-2
  253. File: gdb.info,  Node: C,  Next: Modula-2,  Up: Support
  254. C and C++
  255. ---------
  256.    Since C and C++ are so closely related, many features of GDB apply
  257. to both languages.  Whenever this is the case, we discuss both languages
  258. together.
  259.    The C++ debugging facilities are jointly implemented by the GNU C++
  260. compiler and GDB.  Therefore, to debug your C++ code effectively, you
  261. must compile your C++ programs with the GNU C++ compiler, `g++'.
  262. * Menu:
  263. * C Operators::                 C and C++ Operators
  264. * C Constants::                 C and C++ Constants
  265. * Cplusplus expressions::       C++ Expressions
  266. * C Defaults::                  Default settings for C and C++
  267. * C Checks::                    C and C++ Type and Range Checks
  268. * Debugging C::                 GDB and C
  269. * Debugging C plus plus::       Special features for C++
  270. File: gdb.info,  Node: C Operators,  Next: C Constants,  Up: C
  271. C and C++ Operators
  272. ...................
  273.    Operators must be defined on values of specific types.  For instance,
  274. `+' is defined on numbers, but not on structures.  Operators are often
  275. defined on groups of types.
  276.    For the purposes of C and C++, the following definitions hold:
  277.    * *Integral types* include `int' with any of its storage-class
  278.      specifiers, `char', and `enum's.
  279.    * *Floating-point types* include `float' and `double'.
  280.    * *Pointer types* include all types defined as `(TYPE *)'.
  281.    * *Scalar types* include all of the above.
  282. The following operators are supported.  They are listed here in order
  283. of increasing precedence:
  284.      The comma or sequencing operator.  Expressions in a
  285.      comma-separated list are evaluated from left to right, with the
  286.      result of the entire expression being the last expression
  287.      evaluated.
  288.      Assignment.  The value of an assignment expression is the value
  289.      assigned.  Defined on scalar types.
  290. `OP='
  291.      Used in an expression of the form `A OP= B', and translated to
  292.      `A = A OP B'. `OP=' and `=' have the same precendence. OP is any
  293.      one of the operators `|', `^', `&', `<<', `>>', `+', `-', `*',
  294.      `/', `%'.
  295.      The ternary operator.  `A ? B : C' can be thought of as:  if A
  296.      then B else C.  A should be of an integral type.
  297.      Logical OR.  Defined on integral types.
  298.      Logical AND.  Defined on integral types.
  299.      Bitwise OR.  Defined on integral types.
  300.      Bitwise exclusive-OR.  Defined on integral types.
  301.      Bitwise AND.  Defined on integral types.
  302. `==, !='
  303.      Equality and inequality.  Defined on scalar types.  The value of
  304.      these expressions is 0 for false and non-zero for true.
  305. `<, >, <=, >='
  306.      Less than, greater than, less than or equal, greater than or equal.
  307.      Defined on scalar types.  The value of these expressions is 0 for
  308.      false and non-zero for true.
  309. `<<, >>'
  310.      left shift, and right shift.  Defined on integral types.
  311.      The GDB "artificial array" operator (*note Expressions:
  312.      Expressions.).
  313. `+, -'
  314.      Addition and subtraction.  Defined on integral types,
  315.      floating-point types and pointer types.
  316. `*, /, %'
  317.      Multiplication, division, and modulus.  Multiplication and
  318.      division are defined on integral and floating-point types. 
  319.      Modulus is defined on integral types.
  320. `++, --'
  321.      Increment and decrement.  When appearing before a variable, the
  322.      operation is performed before the variable is used in an
  323.      expression; when appearing after it, the variable's value is used
  324.      before the operation takes place.
  325.      Pointer dereferencing.  Defined on pointer types.  Same precedence
  326.      as `++'.
  327.      Address operator.  Defined on variables.  Same precedence as `++'.
  328.      For debugging C++, GDB implements a use of `&' beyond what's
  329.      allowed in the C++ language itself: you can use `&(&REF)' (or, if
  330.      you prefer, simply `&&REF' to examine the address where a C++
  331.      reference variable (declared with `&REF') is stored.
  332.      Negative.  Defined on integral and floating-point types.  Same
  333.      precedence as `++'.
  334.      Logical negation.  Defined on integral types.  Same precedence as
  335.      `++'.
  336.      Bitwise complement operator.  Defined on integral types.  Same
  337.      precedence as `++'.
  338. `., ->'
  339.      Structure member, and pointer-to-structure member.  For
  340.      convenience, GDB regards the two as equivalent, choosing whether
  341.      to dereference a pointer based on the stored type information.
  342.      Defined on `struct's and `union's.
  343.      Array indexing.  `A[I]' is defined as `*(A+I)'.  Same precedence
  344.      as `->'.
  345.      Function parameter list.  Same precedence as `->'.
  346.      C++ scope resolution operator.  Defined on `struct', `union', and
  347.      `class' types.
  348.      The GDB scope operator (*note Expressions: Expressions.). Same
  349.      precedence as `::', above.
  350. File: gdb.info,  Node: C Constants,  Next: Cplusplus expressions,  Prev: C Operators,  Up: C
  351. C and C++ Constants
  352. ...................
  353.    GDB allows you to express the constants of C and C++ in the
  354. following ways:
  355.    * Integer constants are a sequence of digits.  Octal constants are
  356.      specified by a leading `0' (ie. zero), and hexadecimal constants by
  357.      a leading `0x' or `0X'.  Constants may also end with a letter `l',
  358.      specifying that the constant should be treated as a `long' value.
  359.    * Floating point constants are a sequence of digits, followed by a
  360.      decimal point, followed by a sequence of digits, and optionally
  361.      followed by an exponent.  An exponent is of the form:
  362.      `e[[+]|-]NNN', where NNN is another sequence of digits.  The `+'
  363.      is optional for positive exponents.
  364.    * Enumerated constants consist of enumerated identifiers, or their
  365.      integral equivalents.
  366.    * Character constants are a single character surrounded by single
  367.      quotes (`''), or a number--the ordinal value of the corresponding
  368.      character (usually its ASCII value).  Within quotes, the single
  369.      character may be represented by a letter or by "escape sequences",
  370.      which are of the form `\NNN', where NNN is the octal representation
  371.      of the character's ordinal value; or of the form `\X', where `X'
  372.      is a predefined special character--for example, `\n' for newline.
  373.    * String constants are a sequence of character constants surrounded
  374.      by double quotes (`"').
  375.    * Pointer constants are an integral value.
  376. File: gdb.info,  Node: Cplusplus expressions,  Next: C Defaults,  Prev: C Constants,  Up: C
  377. C++ Expressions
  378. ...............
  379.    GDB's expression handling has a number of extensions to interpret a
  380. significant subset of C++ expressions.
  381.      *Warning:* Most of these extensions depend on the use of additional
  382.      debugging information in the symbol table, and thus require a rich,
  383.      extendable object code format.  In particular, if your system uses
  384.      a.out, MIPS ECOFF, RS/6000 XCOFF, or Sun ELF with stabs extensions
  385.      to the symbol table, these facilities are all available. Where the
  386.      object code format is standard COFF, on the other hand, most of
  387.      the C++ support in GDB will *not* work, nor can it. For the
  388.      standard SVr4 debugging format, DWARF in ELF, the standard is
  389.      still evolving, so the C++ support in GDB is still fragile; when
  390.      this debugging format stabilizes, however, C++ support will also
  391.      be available on systems that use it.
  392.   1. Member function calls are allowed; you can use expressions like
  393.           count = aml->GetOriginal(x, y)
  394.   2. While a member function is active (in the selected stack frame),
  395.      your expressions have the same namespace available as the member
  396.      function; that is, GDB allows implicit references to the class
  397.      instance pointer `this' following the same rules as C++.
  398.   3. You can call overloaded functions; GDB will resolve the function
  399.      call to the right definition, with one restriction--you must use
  400.      arguments of the type required by the function that you want to
  401.      call. GDB will not perform conversions requiring constructors or
  402.      user-defined type operators.
  403.   4. GDB understands variables declared as C++ references; you can use
  404.      them in expressions just as you do in C++ source--they are
  405.      automatically dereferenced.
  406.      In the parameter list shown when GDB displays a frame, the values
  407.      of reference variables are not displayed (unlike other variables);
  408.      this avoids clutter, since references are often used for large
  409.      structures. The *address* of a reference variable is always shown,
  410.      unless you have specified `set print address off'.
  411.   5. GDB supports the C++ name resolution operator `::'--your
  412.      expressions can use it just as expressions in your program do. 
  413.      Since one scope may be defined in another, you can use `::'
  414.      repeatedly if necessary, for example in an expression like
  415.      `SCOPE1::SCOPE2::NAME'.  GDB also allows resolving name scope by
  416.      reference to source files, in both C and C++ debugging (*note
  417.      Program Variables: Variables.).
  418. File: gdb.info,  Node: C Defaults,  Next: C Checks,  Prev: Cplusplus expressions,  Up: C
  419. C and C++ Defaults
  420. ..................
  421.    If you allow GDB to set type and range checking automatically, they
  422. both default to `off' whenever the working language changes to C or
  423. C++.  This happens regardless of whether you, or GDB, selected the
  424. working language.
  425.    If you allow GDB to set the language automatically, it sets the
  426. working language to C or C++ on entering code compiled from a source
  427. file whose name ends with `.c', `.C', or `.cc'. *Note Having GDB infer
  428. the source language: Automatically, for further details.
  429. File: gdb.info,  Node: C Checks,  Next: Debugging C,  Prev: C Defaults,  Up: C
  430. C and C++ Type and Range Checks
  431. ...............................
  432.      *Warning:* in this release, GDB does not yet perform type or range
  433.      checking.
  434.    By default, when GDB parses C or C++ expressions, type checking is
  435. not used.  However, if you turn type checking on, GDB will consider two
  436. variables type equivalent if:
  437.    * The two variables are structured and have the same structure,
  438.      union, or enumerated tag.
  439.    * Two two variables have the same type name, or types that have been
  440.      declared equivalent through `typedef'.
  441.    Range checking, if turned on, is done on mathematical operations. 
  442. Array indices are not checked, since they are often used to index a
  443. pointer that is not itself an array.
  444. File: gdb.info,  Node: Debugging C,  Next: Debugging C plus plus,  Prev: C Checks,  Up: C
  445. GDB and C
  446. .........
  447.    The `set print union' and `show print union' commands apply to the
  448. `union' type.  When set to `on', any `union' that is inside a `struct'
  449. or `class' will also be printed. Otherwise, it will appear as `{...}'.
  450.    The `@' operator aids in the debugging of dynamic arrays, formed
  451. with pointers and a memory allocation function.  (*note Expressions:
  452. Expressions.)
  453. File: gdb.info,  Node: Debugging C plus plus,  Prev: Debugging C,  Up: C
  454. GDB Features for C++
  455. ....................
  456.    Some GDB commands are particularly useful with C++, and some are
  457. designed specifically for use with C++.  Here is a summary:
  458. `breakpoint menus'
  459.      When you want a breakpoint in a function whose name is overloaded,
  460.      GDB's breakpoint menus help you specify which function definition
  461.      you want.  *Note Breakpoint Menus::.
  462. `rbreak REGEX'
  463.      Setting breakpoints using regular expressions is helpful for
  464.      setting breakpoints on overloaded functions that are not members
  465.      of any special classes. *Note Setting Breakpoints: Set Breaks.
  466. `catch EXCEPTIONS'
  467. `info catch'
  468.      Debug C++ exception handling using these commands.  *Note
  469.      Breakpoints and Exceptions: Exception Handling.
  470. `ptype TYPENAME'
  471.      Print inheritance relationships as well as other information for
  472.      type TYPENAME. *Note Examining the Symbol Table: Symbols.
  473. `set print demangle'
  474. `show print demangle'
  475. `set print asm-demangle'
  476. `show print asm-demangle'
  477.      Control whether C++ symbols display in their source form, both when
  478.      displaying code as C++ source and when displaying disassemblies.
  479.      *Note Print Settings: Print Settings.
  480. `set print object'
  481. `show print object'
  482.      Choose whether to print derived (actual) or declared types of
  483.      objects. *Note Print Settings: Print Settings.
  484. `set print vtbl'
  485. `show print vtbl'
  486.      Control the format for printing virtual function tables. *Note
  487.      Print Settings: Print Settings.
  488. `Overloaded symbol names'
  489.      You can specify a particular definition of an overloaded symbol,
  490.      using the same notation that's used to declare such symbols in
  491.      C++: type `SYMBOL(TYPES)' rather than just SYMBOL.  You can also
  492.      use GDB's command-line word completion facilities to list the
  493.      available choices, or to finish the type list for you. *Note
  494.      Command Completion: Completion, for details on how to do this.
  495. File: gdb.info,  Node: Modula-2,  Prev: C,  Up: Support
  496. Modula-2
  497. --------
  498.    The extensions made to GDB to support Modula-2 support output from
  499. the GNU Modula-2 compiler (which is currently being developed). Other
  500. Modula-2 compilers are not currently supported, and attempting to debug
  501. executables produced by them will most likely result in an error as GDB
  502. reads in the executable's symbol table.
  503. * Menu:
  504. * M2 Operators::                Built-in operators
  505. * Built-In Func/Proc::           Built-in Functions and Procedures
  506. * M2 Constants::                Modula-2 Constants
  507. * M2 Defaults::                 Default settings for Modula-2
  508. * Deviations::                  Deviations from standard Modula-2
  509. * M2 Checks::                   Modula-2 Type and Range Checks
  510. * M2 Scope::                    The scope operators `::' and `.'
  511. * GDB/M2::                      GDB and Modula-2
  512. File: gdb.info,  Node: M2 Operators,  Next: Built-In Func/Proc,  Up: Modula-2
  513. Operators
  514. .........
  515.    Operators must be defined on values of specific types.  For instance,
  516. `+' is defined on numbers, but not on structures.  Operators are often
  517. defined on groups of types.  For the purposes of Modula-2, the
  518. following definitions hold:
  519.    * *Integral types* consist of `INTEGER', `CARDINAL', and their
  520.      subranges.
  521.    * *Character types* consist of `CHAR' and its subranges.
  522.    * *Floating-point types* consist of `REAL'.
  523.    * *Pointer types* consist of anything declared as `POINTER TO TYPE'.
  524.    * *Scalar types* consist of all of the above.
  525.    * *Set types* consist of `SET's and `BITSET's.
  526.    * *Boolean types* consist of `BOOLEAN'.
  527. The following operators are supported, and appear in order of
  528. increasing precedence:
  529.      Function argument or array index separator.
  530.      Assignment.  The value of VAR `:=' VALUE is VALUE.
  531. `<, >'
  532.      Less than, greater than on integral, floating-point, or enumerated
  533.      types.
  534. `<=, >='
  535.      Less than, greater than, less than or equal to, greater than or
  536.      equal to on integral, floating-point and enumerated types, or set
  537.      inclusion on set types.  Same precedence as `<'.
  538. `=, <>, #'
  539.      Equality and two ways of expressing inequality, valid on scalar
  540.      types. Same precedence as `<'.  In GDB scripts, only `<>' is
  541.      available for inequality, since `#' conflicts with the script
  542.      comment character.
  543.      Set membership.  Defined on set types and the types of their
  544.      members. Same precedence as `<'.
  545.      Boolean disjunction.  Defined on boolean types.
  546. `AND, &'
  547.      Boolean conjuction.  Defined on boolean types.
  548.      The GDB "artificial array" operator (*note Expressions:
  549.      Expressions.).
  550. `+, -'
  551.      Addition and subtraction on integral and floating-point types, or
  552.      union and difference on set types.
  553.      Multiplication on integral and floating-point types, or set
  554.      intersection on set types.
  555.      Division on floating-point types, or symmetric set difference on
  556.      set types.  Same precedence as `*'.
  557. `DIV, MOD'
  558.      Integer division and remainder.  Defined on integral types.  Same
  559.      precedence as `*'.
  560.      Negative. Defined on `INTEGER's and `REAL's.
  561.      Pointer dereferencing.  Defined on pointer types.
  562. `NOT'
  563.      Boolean negation.  Defined on boolean types.  Same precedence as
  564.      `^'.
  565.      `RECORD' field selector.  Defined on `RECORD's.  Same precedence
  566.      as `^'.
  567.      Array indexing.  Defined on `ARRAY's.  Same precedence as `^'.
  568.      Procedure argument list.  Defined on `PROCEDURE's.  Same precedence
  569.      as `^'.
  570. `::, .'
  571.      GDB and Modula-2 scope operators.
  572.      *Warning:* Sets and their operations are not yet supported, so GDB
  573.      will treat the use of the operator `IN', or the use of operators
  574.      `+', `-', `*', `/', `=', , `<>', `#', `<=', and `>=' on sets as an
  575.      error.
  576. File: gdb.info,  Node: Built-In Func/Proc,  Next: M2 Constants,  Prev: M2 Operators,  Up: Modula-2
  577. Built-in Functions and Procedures
  578. .................................
  579.    Modula-2 also makes available several built-in procedures and
  580. functions. In describing these, the following metavariables are used:
  581.      represents an `ARRAY' variable.
  582.      represents a `CHAR' constant or variable.
  583.      represents a variable or constant of integral type.
  584.      represents an identifier that belongs to a set.  Generally used in
  585.      the same function with the metavariable S.  The type of S should
  586.      be `SET OF MTYPE' (where MTYPE is the type of M.
  587.      represents a variable or constant of integral or floating-point
  588.      type.
  589.      represents a variable or constant of floating-point type.
  590.      represents a type.
  591.      represents a variable.
  592.      represents a variable or constant of one of many types.  See the
  593.      explanation of the function for details.
  594.    All Modula-2 built-in procedures also return a result, described
  595. below.
  596. `ABS(N)'
  597.      Returns the absolute value of N.
  598. `CAP(C)'
  599.      If C is a lower case letter, it returns its upper case equivalent,
  600.      otherwise it returns its argument
  601. `CHR(I)'
  602.      Returns the character whose ordinal value is I.
  603. `DEC(V)'
  604.      Decrements the value in the variable V.  Returns the new value.
  605. `DEC(V,I)'
  606.      Decrements the value in the variable V by I.  Returns the new
  607.      value.
  608. `EXCL(M,S)'
  609.      Removes the element M from the set S.  Returns the new set.
  610. `FLOAT(I)'
  611.      Returns the floating point equivalent of the integer I.
  612. `HIGH(A)'
  613.      Returns the index of the last member of A.
  614. `INC(V)'
  615.      Increments the value in the variable V.  Returns the new value.
  616. `INC(V,I)'
  617.      Increments the value in the variable V by I.  Returns the new
  618.      value.
  619. `INCL(M,S)'
  620.      Adds the element M to the set S if it is not already there. 
  621.      Returns the new set.
  622. `MAX(T)'
  623.      Returns the maximum value of the type T.
  624. `MIN(T)'
  625.      Returns the minimum value of the type T.
  626. `ODD(I)'
  627.      Returns boolean TRUE if I is an odd number.
  628. `ORD(X)'
  629.      Returns the ordinal value of its argument.  For example, the
  630.      ordinal value of a character is its ASCII value (on machines
  631.      supporting the ASCII character set).  X must be of an ordered
  632.      type, which include integral, character and enumerated types.
  633. `SIZE(X)'
  634.      Returns the size of its argument.  X can be a variable or a type.
  635. `TRUNC(R)'
  636.      Returns the integral part of R.
  637. `VAL(T,I)'
  638.      Returns the member of the type T whose ordinal value is I.
  639.      *Warning:*  Sets and their operations are not yet supported, so
  640.      GDB will treat the use of procedures `INCL' and `EXCL' as an error.
  641. File: gdb.info,  Node: M2 Constants,  Next: M2 Defaults,  Prev: Built-In Func/Proc,  Up: Modula-2
  642. Constants
  643. .........
  644.    GDB allows you to express the constants of Modula-2 in the following
  645. ways:
  646.    * Integer constants are simply a sequence of digits.  When used in an
  647.      expression, a constant is interpreted to be type-compatible with
  648.      the rest of the expression.  Hexadecimal integers are specified by
  649.      a trailing `H', and octal integers by a trailing `B'.
  650.    * Floating point constants appear as a sequence of digits, followed
  651.      by a decimal point and another sequence of digits.  An optional
  652.      exponent can then be specified, in the form `E[+|-]NNN', where
  653.      `[+|-]NNN' is the desired exponent.  All of the digits of the
  654.      floating point constant must be valid decimal (base 10) digits.
  655.    * Character constants consist of a single character enclosed by a
  656.      pair of like quotes, either single (`'') or double (`"').  They may
  657.      also be expressed by their ordinal value (their ASCII value,
  658.      usually) followed by a `C'.
  659.    * String constants consist of a sequence of characters enclosed by a
  660.      pair of like quotes, either single (`'') or double (`"'). Escape
  661.      sequences in the style of C are also allowed.  *Note C and C++
  662.      Constants: C Constants, for a brief explanation of escape
  663.      sequences.
  664.    * Enumerated constants consist of an enumerated identifier.
  665.    * Boolean constants consist of the identifiers `TRUE' and `FALSE'.
  666.    * Pointer constants consist of integral values only.
  667.    * Set constants are not yet supported.
  668. File: gdb.info,  Node: M2 Defaults,  Next: Deviations,  Prev: M2 Constants,  Up: Modula-2
  669. Modula-2 Defaults
  670. .................
  671.    If type and range checking are set automatically by GDB, they both
  672. default to `on' whenever the working language changes to Modula-2. 
  673. This happens regardless of whether you, or GDB, selected the working
  674. language.
  675.    If you allow GDB to set the language automatically, then entering
  676. code compiled from a file whose name ends with `.mod' will set the
  677. working language to Modula-2. *Note Having GDB set the language
  678. automatically: Automatically, for further details.
  679. File: gdb.info,  Node: Deviations,  Next: M2 Checks,  Prev: M2 Defaults,  Up: Modula-2
  680. Deviations from Standard Modula-2
  681. .................................
  682.    A few changes have been made to make Modula-2 programs easier to
  683. debug. This is done primarily via loosening its type strictness:
  684.    * Unlike in standard Modula-2, pointer constants can be formed by
  685.      integers.  This allows you to modify pointer variables during
  686.      debugging.  (In standard Modula-2, the actual address contained in
  687.      a pointer variable is hidden from you; it can only be modified
  688.      through direct assignment to another pointer variable or
  689.      expression that returned a pointer.)
  690.    * C escape sequences can be used in strings and characters to
  691.      represent non-printable characters.  GDB will print out strings
  692.      with these escape sequences embedded.  Single non-printable
  693.      characters are printed using the `CHR(NNN)' format.
  694.    * The assignment operator (`:=') returns the value of its right-hand
  695.      argument.
  696.    * All built-in procedures both modify *and* return their argument.
  697. File: gdb.info,  Node: M2 Checks,  Next: M2 Scope,  Prev: Deviations,  Up: Modula-2
  698. Modula-2 Type and Range Checks
  699. ..............................
  700.      *Warning:* in this release, GDB does not yet perform type or range
  701.      checking.
  702.    GDB considers two Modula-2 variables type equivalent if:
  703.    * They are of types that have been declared equivalent via a `TYPE
  704.      T1 = T2' statement
  705.    * They have been declared on the same line.  (Note:  This is true of
  706.      the GNU Modula-2 compiler, but it may not be true of other
  707.      compilers.)
  708.    As long as type checking is enabled, any attempt to combine variables
  709. whose types are not equivalent is an error.
  710.    Range checking is done on all mathematical operations, assignment,
  711. array index bounds, and all built-in functions and procedures.
  712. File: gdb.info,  Node: M2 Scope,  Next: GDB/M2,  Prev: M2 Checks,  Up: Modula-2
  713. The scope operators `::' and `.'
  714. ................................
  715.    There are a few subtle differences between the Modula-2 scope
  716. operator (`.') and the GDB scope operator (`::').  The two have similar
  717. syntax:
  718.      MODULE . ID
  719.      SCOPE :: ID
  720. where SCOPE is the name of a module or a procedure, MODULE the name of
  721. a module, and ID is any declared identifier within your program, except
  722. another module.
  723.    Using the `::' operator makes GDB search the scope specified by
  724. SCOPE for the identifier ID.  If it is not found in the specified
  725. scope, then GDB will search all scopes enclosing the one specified by
  726. SCOPE.
  727.    Using the `.' operator makes GDB search the current scope for the
  728. identifier specified by ID that was imported from the definition module
  729. specified by MODULE.  With this operator, it is an error if the
  730. identifier ID was not imported from definition module MODULE, or if ID
  731. is not an identifier in MODULE.
  732. File: gdb.info,  Node: GDB/M2,  Prev: M2 Scope,  Up: Modula-2
  733. GDB and Modula-2
  734. ................
  735.    Some GDB commands have little use when debugging Modula-2 programs.
  736. Five subcommands of `set print' and `show print' apply specifically to
  737. C and C++: `vtbl', `demangle', `asm-demangle', `object', and `union'. 
  738. The first four apply to C++, and the last to C's `union' type, which
  739. has no direct analogue in Modula-2.
  740.    The `@' operator (*note Expressions: Expressions.), while available
  741. while using any language, is not useful with Modula-2.  Its intent is
  742. to aid the debugging of "dynamic arrays", which cannot be created in
  743. Modula-2 as they can in C or C++.  However, because an address can be
  744. specified by an integral constant, the construct `{TYPE}ADREXP' is
  745. still useful.  (*note Expressions: Expressions.)
  746.    In GDB scripts, the Modula-2 inequality operator `#' is interpreted
  747. as the beginning of a comment.  Use `<>' instead.
  748. File: gdb.info,  Node: Symbols,  Next: Altering,  Prev: Languages,  Up: Top
  749. Examining the Symbol Table
  750. **************************
  751.    The commands described in this section allow you to inquire about the
  752. symbols (names of variables, functions and types) defined in your
  753. program.  This information is inherent in the text of your program and
  754. does not change as your program executes.  GDB finds it in your
  755. program's symbol table, in the file indicated when you started GDB
  756. (*note Choosing Files: File Options.), or by one of the file-management
  757. commands (*note Commands to Specify Files: Files.).
  758.    Occasionally, you may need to refer to symbols that contain unusual
  759. characters, which GDB ordinarily treats as word delimiters.  The most
  760. frequent case is in referring to static variables in other source files
  761. (*note Program Variables: Variables.).  File names are recorded in
  762. object files as debugging symbols, but GDB would ordinarily parse a
  763. typical file name, like `foo.c', as the three words `foo' `.' `c'.  To
  764. allow GDB to recognize `foo.c' as a single symbol, enclose it in single
  765. quotes; for example,
  766.      p 'foo.c'::x
  767. looks up the value of `x' in the scope of the file `foo.c'.
  768. `info address SYMBOL'
  769.      Describe where the data for SYMBOL is stored.  For a register
  770.      variable, this says which register it is kept in.  For a
  771.      non-register local variable, this prints the stack-frame offset at
  772.      which the variable is always stored.
  773.      Note the contrast with `print &SYMBOL', which does not work at all
  774.      for a register variables, and for a stack local variable prints
  775.      the exact address of the current instantiation of the variable.
  776. `whatis EXP'
  777.      Print the data type of expression EXP.  EXP is not actually
  778.      evaluated, and any side-effecting operations (such as assignments
  779.      or function calls) inside it do not take place. *Note Expressions:
  780.      Expressions.
  781. `whatis'
  782.      Print the data type of `$', the last value in the value history.
  783. `ptype TYPENAME'
  784.      Print a description of data type TYPENAME.  TYPENAME may be the
  785.      name of a type, or for C code it may have the form `struct
  786.      STRUCT-TAG', `union UNION-TAG' or `enum ENUM-TAG'.
  787. `ptype EXP'
  788. `ptype'
  789.      Print a description of the type of expression EXP.  `ptype'
  790.      differs from `whatis' by printing a detailed description, instead
  791.      of just the name of the type.  For example, if your program
  792.      declares a variable as
  793.           struct complex {double real; double imag;} v;
  794.      compare the output of the two commands:
  795.           (gdb) whatis v
  796.           type = struct complex
  797.           (gdb) ptype v
  798.           type = struct complex {
  799.               double real;
  800.               double imag;
  801.           }
  802.      As with `whatis', using `ptype' without an argument refers to the
  803.      type of `$', the last value in the value history.
  804. `info types REGEXP'
  805. `info types'
  806.      Print a brief description of all types whose name matches REGEXP
  807.      (or all types in your program, if you supply no argument).  Each
  808.      complete typename is matched as though it were a complete line;
  809.      thus, `i type value' gives information on all types in your
  810.      program whose name includes the string `value', but `i type
  811.      ^value$' gives information only on types whose complete name is
  812.      `value'.
  813.      This command differs from `ptype' in two ways: first, like
  814.      `whatis', it does not print a detailed description; second, it
  815.      lists all source files where a type is defined.
  816. `info source'
  817.      Show the name of the current source file--that is, the source file
  818.      for the function containing the current point of execution--and
  819.      the language it was written in.
  820. `info sources'
  821.      Print the names of all source files in your program for which
  822.      there is debugging information, organized into two lists: files
  823.      whose symbols have already been read, and files whose symbols will
  824.      be read when needed.
  825. `info functions'
  826.      Print the names and data types of all defined functions.
  827. `info functions REGEXP'
  828.      Print the names and data types of all defined functions whose
  829.      names contain a match for regular expression REGEXP. Thus, `info
  830.      fun step' finds all functions whose names include `step'; `info
  831.      fun ^step' finds those whose names start with `step'.
  832. `info variables'
  833.      Print the names and data types of all variables that are declared
  834.      outside of functions (i.e., excluding local variables).
  835. `info variables REGEXP'
  836.      Print the names and data types of all variables (except for local
  837.      variables) whose names contain a match for regular expression
  838.      REGEXP.
  839. `maint print symbols FILENAME'
  840. `maint print psymbols FILENAME'
  841. `maint print msymbols FILENAME'
  842.      Write a dump of debugging symbol data into the file FILENAME.
  843.      These commands are used to debug the GDB symbol-reading code.  Only
  844.      symbols with debugging data are included.  If you use `maint print
  845.      symbols', GDB includes all the symbols for which it has already
  846.      collected full details: that is, FILENAME reflects symbols for
  847.      only those files whose symbols GDB has read.  You can use the
  848.      command `info sources' to find out which files these are.  If you
  849.      use `maint print psymbols' instead, the dump shows information
  850.      about symbols that GDB only knows partially--that is, symbols
  851.      defined in files that GDB has skimmed, but not yet read
  852.      completely.  Finally, `maint print msymbols' dumps just the
  853.      minimal symbol information required for each object file from
  854.      which GDB has read some symbols. The description of `symbol-file'
  855.      explains how GDB reads symbols; both `info source' and
  856.      `symbol-file' are described in *Note Commands to Specify Files:
  857.      Files.
  858. File: gdb.info,  Node: Altering,  Next: GDB Files,  Prev: Symbols,  Up: Top
  859. Altering Execution
  860. ******************
  861.    Once you think you have found an error in your program, you might
  862. want to find out for certain whether correcting the apparent error
  863. would lead to correct results in the rest of the run.  You can find the
  864. answer by experiment, using the GDB features for altering execution of
  865. the program.
  866.    For example, you can store new values into variables or memory
  867. locations, give your program a signal, restart it at a different
  868. address, or even return prematurely from a function to its caller.
  869. * Menu:
  870. * Assignment::                  Assignment to Variables
  871. * Jumping::                     Continuing at a Different Address
  872. * Signaling::                   Giving your program a Signal
  873. * Returning::                   Returning from a Function
  874. * Calling::                     Calling your Program's Functions
  875. * Patching::                    Patching your Program
  876. File: gdb.info,  Node: Assignment,  Next: Jumping,  Up: Altering
  877. Assignment to Variables
  878. =======================
  879.    To alter the value of a variable, evaluate an assignment expression.
  880. *Note Expressions: Expressions.  For example,
  881.      print x=4
  882. stores the value 4 into the variable `x', and then prints the value of
  883. the assignment expression (which is 4). *Note Using GDB with Different
  884. Languages: Languages, for more information on operators in supported
  885. languages.
  886.    If you are not interested in seeing the value of the assignment, use
  887. the `set' command instead of the `print' command.  `set' is really the
  888. same as `print' except that the expression's value is not printed and
  889. is not put in the value history (*note Value History: Value History.). 
  890. The expression is evaluated only for its effects.
  891.    If the beginning of the argument string of the `set' command appears
  892. identical to a `set' subcommand, use the `set variable' command instead
  893. of just `set'.  This command is identical to `set' except for its lack
  894. of subcommands.  For example, a program might well have a variable
  895. `width'--which leads to an error if we try to set a new value with just
  896. `set width=13', as we might if `set width' did not happen to be a GDB
  897. command:
  898.      (gdb) whatis width
  899.      type = double
  900.      (gdb) p width
  901.      $4 = 13
  902.      (gdb) set width=47
  903.      Invalid syntax in expression.
  904. The invalid expression, of course, is `=47'.  What we can do in order
  905. to actually set our program's variable `width' is
  906.      (gdb) set var width=47
  907.    GDB allows more implicit conversions in assignments than C; you can
  908. freely store an integer value into a pointer variable or vice versa,
  909. and any structure can be converted to any other structure that is the
  910. same length or shorter.
  911.    To store values into arbitrary places in memory, use the `{...}'
  912. construct to generate a value of specified type at a specified address
  913. (*note Expressions: Expressions.).  For example, `{int}0x83040' refers
  914. to memory location `0x83040' as an integer (which implies a certain size
  915. and representation in memory), and
  916.      set {int}0x83040 = 4
  917. stores the value 4 into that memory location.
  918. File: gdb.info,  Node: Jumping,  Next: Signaling,  Prev: Assignment,  Up: Altering
  919. Continuing at a Different Address
  920. =================================
  921.    Ordinarily, when you continue your program, you do so at the place
  922. where it stopped, with the `continue' command.  You can instead
  923. continue at an address of your own choosing, with the following
  924. commands:
  925. `jump LINESPEC'
  926.      Resume execution at line LINESPEC.  Execution will stop
  927.      immediately if there is a breakpoint there.  *Note Printing Source
  928.      Lines: List, for a description of the different forms of LINESPEC.
  929.      The `jump' command does not change the current stack frame, or the
  930.      stack pointer, or the contents of any memory location or any
  931.      register other than the program counter.  If line LINESPEC is in a
  932.      different function from the one currently executing, the results
  933.      may be bizarre if the two functions expect different patterns of
  934.      arguments or of local variables.  For this reason, the `jump'
  935.      command requests confirmation if the specified line is not in the
  936.      function currently executing.  However, even bizarre results are
  937.      predictable if you are well acquainted with the machine-language
  938.      code of your program.
  939. `jump *ADDRESS'
  940.      Resume execution at the instruction at address ADDRESS.
  941.    You can get much the same effect as the `jump' command by storing a
  942. new value into the register `$pc'.  The difference is that this does
  943. not start your program running; it only changes the address where it
  944. *will* run when it is continued.  For example,
  945.      set $pc = 0x485
  946. causes the next `continue' command or stepping command to execute at
  947. address `0x485', rather than at the address where your program stopped.
  948. *Note Continuing and Stepping: Continuing and Stepping.
  949.    The most common occasion to use the `jump' command is to back up,
  950. perhaps with more breakpoints set, over a portion of a program that has
  951. already executed, in order to examine its execution in more detail.
  952. File: gdb.info,  Node: Signaling,  Next: Returning,  Prev: Jumping,  Up: Altering
  953. Giving your program a Signal
  954. ============================
  955. `signal SIGNALNUM'
  956.      Resume execution where your program stopped, but give it
  957.      immediately the signal number SIGNALNUM.
  958.      Alternatively, if SIGNALNUM is zero, continue execution without
  959.      giving a signal.  This is useful when your program stopped on
  960.      account of a signal and would ordinary see the signal when resumed
  961.      with the `continue' command; `signal 0' causes it to resume
  962.      without a signal.
  963.      `signal' does not repeat when you press RET a second time after
  964.      executing the command.
  965.