home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 9 / FreshFishVol9-CD2.bin / bbs / gnu / gdb-4.14-src.lha / gdb-4.14 / gdb / gdb.info-5 < prev    next >
Encoding:
GNU Info File  |  1995-03-04  |  49.3 KB  |  1,265 lines

  1. This is Info file ./gdb.info, produced by Makeinfo-1.55 from the input
  2. file gdb.texinfo.
  3.  
  4. START-INFO-DIR-ENTRY
  5. * Gdb: (gdb).                     The GNU debugger.
  6. END-INFO-DIR-ENTRY
  7.    This file documents the GNU debugger GDB.
  8.  
  9.    This is Edition 4.12, January 1994, of `Debugging with GDB: the GNU
  10. Source-Level Debugger' for GDB Version 4.14.
  11.  
  12.    Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995 Free
  13. Software Foundation, Inc.
  14.  
  15.    Permission is granted to make and distribute verbatim copies of this
  16. manual provided the copyright notice and this permission notice are
  17. preserved on all copies.
  18.  
  19.    Permission is granted to copy and distribute modified versions of
  20. this manual under the conditions for verbatim copying, provided also
  21. that the entire resulting derived work is distributed under the terms
  22. of a permission notice identical to this one.
  23.  
  24.    Permission is granted to copy and distribute translations of this
  25. manual into another language, under the above conditions for modified
  26. versions.
  27.  
  28. 
  29. File: gdb.info,  Node: Built-In Func/Proc,  Next: M2 Constants,  Prev: M2 Operators,  Up: Modula-2
  30.  
  31. Built-in functions and procedures
  32. .................................
  33.  
  34.    Modula-2 also makes available several built-in procedures and
  35. functions.  In describing these, the following metavariables are used:
  36.  
  37. A
  38.      represents an `ARRAY' variable.
  39.  
  40. C
  41.      represents a `CHAR' constant or variable.
  42.  
  43. I
  44.      represents a variable or constant of integral type.
  45.  
  46. M
  47.      represents an identifier that belongs to a set.  Generally used in
  48.      the same function with the metavariable S.  The type of S should
  49.      be `SET OF MTYPE' (where MTYPE is the type of M).
  50.  
  51. N
  52.      represents a variable or constant of integral or floating-point
  53.      type.
  54.  
  55. R
  56.      represents a variable or constant of floating-point type.
  57.  
  58. T
  59.      represents a type.
  60.  
  61. V
  62.      represents a variable.
  63.  
  64. X
  65.      represents a variable or constant of one of many types.  See the
  66.      explanation of the function for details.
  67.  
  68.    All Modula-2 built-in procedures also return a result, described
  69. below.
  70.  
  71. `ABS(N)'
  72.      Returns the absolute value of N.
  73.  
  74. `CAP(C)'
  75.      If C is a lower case letter, it returns its upper case equivalent,
  76.      otherwise it returns its argument
  77.  
  78. `CHR(I)'
  79.      Returns the character whose ordinal value is I.
  80.  
  81. `DEC(V)'
  82.      Decrements the value in the variable V.  Returns the new value.
  83.  
  84. `DEC(V,I)'
  85.      Decrements the value in the variable V by I.  Returns the new
  86.      value.
  87.  
  88. `EXCL(M,S)'
  89.      Removes the element M from the set S.  Returns the new set.
  90.  
  91. `FLOAT(I)'
  92.      Returns the floating point equivalent of the integer I.
  93.  
  94. `HIGH(A)'
  95.      Returns the index of the last member of A.
  96.  
  97. `INC(V)'
  98.      Increments the value in the variable V.  Returns the new value.
  99.  
  100. `INC(V,I)'
  101.      Increments the value in the variable V by I.  Returns the new
  102.      value.
  103.  
  104. `INCL(M,S)'
  105.      Adds the element M to the set S if it is not already there.
  106.      Returns the new set.
  107.  
  108. `MAX(T)'
  109.      Returns the maximum value of the type T.
  110.  
  111. `MIN(T)'
  112.      Returns the minimum value of the type T.
  113.  
  114. `ODD(I)'
  115.      Returns boolean TRUE if I is an odd number.
  116.  
  117. `ORD(X)'
  118.      Returns the ordinal value of its argument.  For example, the
  119.      ordinal value of a character is its ASCII value (on machines
  120.      supporting the ASCII character set).  X must be of an ordered
  121.      type, which include integral, character and enumerated types.
  122.  
  123. `SIZE(X)'
  124.      Returns the size of its argument.  X can be a variable or a type.
  125.  
  126. `TRUNC(R)'
  127.      Returns the integral part of R.
  128.  
  129. `VAL(T,I)'
  130.      Returns the member of the type T whose ordinal value is I.
  131.  
  132.      *Warning:*  Sets and their operations are not yet supported, so
  133.      GDB treats the use of procedures `INCL' and `EXCL' as an error.
  134.  
  135. 
  136. File: gdb.info,  Node: M2 Constants,  Next: M2 Defaults,  Prev: Built-In Func/Proc,  Up: Modula-2
  137.  
  138. Constants
  139. .........
  140.  
  141.    GDB allows you to express the constants of Modula-2 in the following
  142. ways:
  143.  
  144.    * Integer constants are simply a sequence of digits.  When used in an
  145.      expression, a constant is interpreted to be type-compatible with
  146.      the rest of the expression.  Hexadecimal integers are specified by
  147.      a trailing `H', and octal integers by a trailing `B'.
  148.  
  149.    * Floating point constants appear as a sequence of digits, followed
  150.      by a decimal point and another sequence of digits.  An optional
  151.      exponent can then be specified, in the form `E[+|-]NNN', where
  152.      `[+|-]NNN' is the desired exponent.  All of the digits of the
  153.      floating point constant must be valid decimal (base 10) digits.
  154.  
  155.    * Character constants consist of a single character enclosed by a
  156.      pair of like quotes, either single (`'') or double (`"').  They may
  157.      also be expressed by their ordinal value (their ASCII value,
  158.      usually) followed by a `C'.
  159.  
  160.    * String constants consist of a sequence of characters enclosed by a
  161.      pair of like quotes, either single (`'') or double (`"').  Escape
  162.      sequences in the style of C are also allowed.  *Note C and C++
  163.      constants: C Constants, for a brief explanation of escape
  164.      sequences.
  165.  
  166.    * Enumerated constants consist of an enumerated identifier.
  167.  
  168.    * Boolean constants consist of the identifiers `TRUE' and `FALSE'.
  169.  
  170.    * Pointer constants consist of integral values only.
  171.  
  172.    * Set constants are not yet supported.
  173.  
  174. 
  175. File: gdb.info,  Node: M2 Defaults,  Next: Deviations,  Prev: M2 Constants,  Up: Modula-2
  176.  
  177. Modula-2 defaults
  178. .................
  179.  
  180.    If type and range checking are set automatically by GDB, they both
  181. default to `on' whenever the working language changes to Modula-2.
  182. This happens regardless of whether you, or GDB, selected the working
  183. language.
  184.  
  185.    If you allow GDB to set the language automatically, then entering
  186. code compiled from a file whose name ends with `.mod' sets the working
  187. language to Modula-2. *Note Having GDB set the language automatically:
  188. Automatically, for further details.
  189.  
  190. 
  191. File: gdb.info,  Node: Deviations,  Next: M2 Checks,  Prev: M2 Defaults,  Up: Modula-2
  192.  
  193. Deviations from standard Modula-2
  194. .................................
  195.  
  196.    A few changes have been made to make Modula-2 programs easier to
  197. debug.  This is done primarily via loosening its type strictness:
  198.  
  199.    * Unlike in standard Modula-2, pointer constants can be formed by
  200.      integers.  This allows you to modify pointer variables during
  201.      debugging.  (In standard Modula-2, the actual address contained in
  202.      a pointer variable is hidden from you; it can only be modified
  203.      through direct assignment to another pointer variable or
  204.      expression that returned a pointer.)
  205.  
  206.    * C escape sequences can be used in strings and characters to
  207.      represent non-printable characters.  GDB prints out strings with
  208.      these escape sequences embedded.  Single non-printable characters
  209.      are printed using the `CHR(NNN)' format.
  210.  
  211.    * The assignment operator (`:=') returns the value of its right-hand
  212.      argument.
  213.  
  214.    * All built-in procedures both modify *and* return their argument.
  215.  
  216. 
  217. File: gdb.info,  Node: M2 Checks,  Next: M2 Scope,  Prev: Deviations,  Up: Modula-2
  218.  
  219. Modula-2 type and range checks
  220. ..............................
  221.  
  222.      *Warning:* in this release, GDB does not yet perform type or range
  223.      checking.
  224.  
  225.    GDB considers two Modula-2 variables type equivalent if:
  226.  
  227.    * They are of types that have been declared equivalent via a `TYPE
  228.      T1 = T2' statement
  229.  
  230.    * They have been declared on the same line.  (Note:  This is true of
  231.      the GNU Modula-2 compiler, but it may not be true of other
  232.      compilers.)
  233.  
  234.    As long as type checking is enabled, any attempt to combine variables
  235. whose types are not equivalent is an error.
  236.  
  237.    Range checking is done on all mathematical operations, assignment,
  238. array index bounds, and all built-in functions and procedures.
  239.  
  240. 
  241. File: gdb.info,  Node: M2 Scope,  Next: GDB/M2,  Prev: M2 Checks,  Up: Modula-2
  242.  
  243. The scope operators `::' and `.'
  244. ................................
  245.  
  246.    There are a few subtle differences between the Modula-2 scope
  247. operator (`.') and the GDB scope operator (`::').  The two have similar
  248. syntax:
  249.  
  250.  
  251.      MODULE . ID
  252.      SCOPE :: ID
  253.  
  254. where SCOPE is the name of a module or a procedure, MODULE the name of
  255. a module, and ID is any declared identifier within your program, except
  256. another module.
  257.  
  258.    Using the `::' operator makes GDB search the scope specified by
  259. SCOPE for the identifier ID.  If it is not found in the specified
  260. scope, then GDB searches all scopes enclosing the one specified by
  261. SCOPE.
  262.  
  263.    Using the `.' operator makes GDB search the current scope for the
  264. identifier specified by ID that was imported from the definition module
  265. specified by MODULE.  With this operator, it is an error if the
  266. identifier ID was not imported from definition module MODULE, or if ID
  267. is not an identifier in MODULE.
  268.  
  269. 
  270. File: gdb.info,  Node: GDB/M2,  Prev: M2 Scope,  Up: Modula-2
  271.  
  272. GDB and Modula-2
  273. ................
  274.  
  275.    Some GDB commands have little use when debugging Modula-2 programs.
  276. Five subcommands of `set print' and `show print' apply specifically to
  277. C and C++: `vtbl', `demangle', `asm-demangle', `object', and `union'.
  278. The first four apply to C++, and the last to the C `union' type, which
  279. has no direct analogue in Modula-2.
  280.  
  281.    The `@' operator (*note Expressions: Expressions.), while available
  282. while using any language, is not useful with Modula-2.  Its intent is
  283. to aid the debugging of "dynamic arrays", which cannot be created in
  284. Modula-2 as they can in C or C++.  However, because an address can be
  285. specified by an integral constant, the construct `{TYPE}ADREXP' is
  286. still useful.  (*note Expressions: Expressions.)
  287.  
  288.    In GDB scripts, the Modula-2 inequality operator `#' is interpreted
  289. as the beginning of a comment.  Use `<>' instead.
  290.  
  291. 
  292. File: gdb.info,  Node: Symbols,  Next: Altering,  Prev: Languages,  Up: Top
  293.  
  294. Examining the Symbol Table
  295. **************************
  296.  
  297.    The commands described in this section allow you to inquire about the
  298. symbols (names of variables, functions and types) defined in your
  299. program.  This information is inherent in the text of your program and
  300. does not change as your program executes.  GDB finds it in your
  301. program's symbol table, in the file indicated when you started GDB
  302. (*note Choosing files: File Options.), or by one of the file-management
  303. commands (*note Commands to specify files: Files.).
  304.  
  305.    Occasionally, you may need to refer to symbols that contain unusual
  306. characters, which GDB ordinarily treats as word delimiters.  The most
  307. frequent case is in referring to static variables in other source files
  308. (*note Program variables: Variables.).  File names are recorded in
  309. object files as debugging symbols, but GDB would ordinarily parse a
  310. typical file name, like `foo.c', as the three words `foo' `.' `c'.  To
  311. allow GDB to recognize `foo.c' as a single symbol, enclose it in single
  312. quotes; for example,
  313.  
  314.      p 'foo.c'::x
  315.  
  316. looks up the value of `x' in the scope of the file `foo.c'.
  317.  
  318. `info address SYMBOL'
  319.      Describe where the data for SYMBOL is stored.  For a register
  320.      variable, this says which register it is kept in.  For a
  321.      non-register local variable, this prints the stack-frame offset at
  322.      which the variable is always stored.
  323.  
  324.      Note the contrast with `print &SYMBOL', which does not work at all
  325.      for a register variable, and for a stack local variable prints the
  326.      exact address of the current instantiation of the variable.
  327.  
  328. `whatis EXP'
  329.      Print the data type of expression EXP.  EXP is not actually
  330.      evaluated, and any side-effecting operations (such as assignments
  331.      or function calls) inside it do not take place.  *Note
  332.      Expressions: Expressions.
  333.  
  334. `whatis'
  335.      Print the data type of `$', the last value in the value history.
  336.  
  337. `ptype TYPENAME'
  338.      Print a description of data type TYPENAME.  TYPENAME may be the
  339.      name of a type, or for C code it may have the form `class
  340.      CLASS-NAME', `struct STRUCT-TAG', `union UNION-TAG' or `enum
  341.      ENUM-TAG'.
  342.  
  343. `ptype EXP'
  344. `ptype'
  345.      Print a description of the type of expression EXP.  `ptype'
  346.      differs from `whatis' by printing a detailed description, instead
  347.      of just the name of the type.
  348.  
  349.      For example, for this variable declaration:
  350.  
  351.           struct complex {double real; double imag;} v;
  352.  
  353.      the two commands give this output:
  354.  
  355.           (gdb) whatis v
  356.           type = struct complex
  357.           (gdb) ptype v
  358.           type = struct complex {
  359.               double real;
  360.               double imag;
  361.           }
  362.  
  363.      As with `whatis', using `ptype' without an argument refers to the
  364.      type of `$', the last value in the value history.
  365.  
  366. `info types REGEXP'
  367. `info types'
  368.      Print a brief description of all types whose name matches REGEXP
  369.      (or all types in your program, if you supply no argument).  Each
  370.      complete typename is matched as though it were a complete line;
  371.      thus, `i type value' gives information on all types in your
  372.      program whose name includes the string `value', but `i type
  373.      ^value$' gives information only on types whose complete name is
  374.      `value'.
  375.  
  376.      This command differs from `ptype' in two ways: first, like
  377.      `whatis', it does not print a detailed description; second, it
  378.      lists all source files where a type is defined.
  379.  
  380. `info source'
  381.      Show the name of the current source file--that is, the source file
  382.      for the function containing the current point of execution--and
  383.      the language it was written in.
  384.  
  385. `info sources'
  386.      Print the names of all source files in your program for which
  387.      there is debugging information, organized into two lists: files
  388.      whose symbols have already been read, and files whose symbols will
  389.      be read when needed.
  390.  
  391. `info functions'
  392.      Print the names and data types of all defined functions.
  393.  
  394. `info functions REGEXP'
  395.      Print the names and data types of all defined functions whose
  396.      names contain a match for regular expression REGEXP.  Thus, `info
  397.      fun step' finds all functions whose names include `step'; `info
  398.      fun ^step' finds those whose names start with `step'.
  399.  
  400. `info variables'
  401.      Print the names and data types of all variables that are declared
  402.      outside of functions (i.e., excluding local variables).
  403.  
  404. `info variables REGEXP'
  405.      Print the names and data types of all variables (except for local
  406.      variables) whose names contain a match for regular expression
  407.      REGEXP.
  408.  
  409. `maint print symbols FILENAME'
  410. `maint print psymbols FILENAME'
  411. `maint print msymbols FILENAME'
  412.      Write a dump of debugging symbol data into the file FILENAME.
  413.      These commands are used to debug the GDB symbol-reading code.  Only
  414.      symbols with debugging data are included.  If you use `maint print
  415.      symbols', GDB includes all the symbols for which it has already
  416.      collected full details: that is, FILENAME reflects symbols for
  417.      only those files whose symbols GDB has read.  You can use the
  418.      command `info sources' to find out which files these are.  If you
  419.      use `maint print psymbols' instead, the dump shows information
  420.      about symbols that GDB only knows partially--that is, symbols
  421.      defined in files that GDB has skimmed, but not yet read
  422.      completely.  Finally, `maint print msymbols' dumps just the
  423.      minimal symbol information required for each object file from
  424.      which GDB has read some symbols.  *Note Commands to specify files:
  425.      Files, for a discussion of how GDB reads symbols (in the
  426.      description of `symbol-file').
  427.  
  428. 
  429. File: gdb.info,  Node: Altering,  Next: GDB Files,  Prev: Symbols,  Up: Top
  430.  
  431. Altering Execution
  432. ******************
  433.  
  434.    Once you think you have found an error in your program, you might
  435. want to find out for certain whether correcting the apparent error
  436. would lead to correct results in the rest of the run.  You can find the
  437. answer by experiment, using the GDB features for altering execution of
  438. the program.
  439.  
  440.    For example, you can store new values into variables or memory
  441. locations, give your program a signal, restart it at a different
  442. address, or even return prematurely from a function to its caller.
  443.  
  444. * Menu:
  445.  
  446. * Assignment::                  Assignment to variables
  447. * Jumping::                     Continuing at a different address
  448.  
  449. * Signaling::                   Giving your program a signal
  450.  
  451. * Returning::                   Returning from a function
  452. * Calling::                     Calling your program's functions
  453. * Patching::                    Patching your program
  454.  
  455. 
  456. File: gdb.info,  Node: Assignment,  Next: Jumping,  Up: Altering
  457.  
  458. Assignment to variables
  459. =======================
  460.  
  461.    To alter the value of a variable, evaluate an assignment expression.
  462. *Note Expressions: Expressions.  For example,
  463.  
  464.      print x=4
  465.  
  466. stores the value 4 into the variable `x', and then prints the value of
  467. the assignment expression (which is 4).  *Note Using GDB with Different
  468. Languages: Languages, for more information on operators in supported
  469. languages.
  470.  
  471.    If you are not interested in seeing the value of the assignment, use
  472. the `set' command instead of the `print' command.  `set' is really the
  473. same as `print' except that the expression's value is not printed and
  474. is not put in the value history (*note Value history: Value History.).
  475. The expression is evaluated only for its effects.
  476.  
  477.    If the beginning of the argument string of the `set' command appears
  478. identical to a `set' subcommand, use the `set variable' command instead
  479. of just `set'.  This command is identical to `set' except for its lack
  480. of subcommands.  For example, if your program has a variable `width',
  481. you get an error if you try to set a new value with just `set width=13',
  482. because GDB has the command `set width':
  483.  
  484.      (gdb) whatis width
  485.      type = double
  486.      (gdb) p width
  487.      $4 = 13
  488.      (gdb) set width=47
  489.      Invalid syntax in expression.
  490.  
  491. The invalid expression, of course, is `=47'.  In order to actually set
  492. the program's variable `width', use
  493.  
  494.      (gdb) set var width=47
  495.  
  496.    GDB allows more implicit conversions in assignments than C; you can
  497. freely store an integer value into a pointer variable or vice versa,
  498. and you can convert any structure to any other structure that is the
  499. same length or shorter.
  500.  
  501.    To store values into arbitrary places in memory, use the `{...}'
  502. construct to generate a value of specified type at a specified address
  503. (*note Expressions: Expressions.).  For example, `{int}0x83040' refers
  504. to memory location `0x83040' as an integer (which implies a certain size
  505. and representation in memory), and
  506.  
  507.      set {int}0x83040 = 4
  508.  
  509. stores the value 4 into that memory location.
  510.  
  511. 
  512. File: gdb.info,  Node: Jumping,  Next: Signaling,  Prev: Assignment,  Up: Altering
  513.  
  514. Continuing at a different address
  515. =================================
  516.  
  517.    Ordinarily, when you continue your program, you do so at the place
  518. where it stopped, with the `continue' command.  You can instead
  519. continue at an address of your own choosing, with the following
  520. commands:
  521.  
  522. `jump LINESPEC'
  523.      Resume execution at line LINESPEC.  Execution stops again
  524.      immediately if there is a breakpoint there.  *Note Printing source
  525.      lines: List, for a description of the different forms of LINESPEC.
  526.  
  527.      The `jump' command does not change the current stack frame, or the
  528.      stack pointer, or the contents of any memory location or any
  529.      register other than the program counter.  If line LINESPEC is in a
  530.      different function from the one currently executing, the results
  531.      may be bizarre if the two functions expect different patterns of
  532.      arguments or of local variables.  For this reason, the `jump'
  533.      command requests confirmation if the specified line is not in the
  534.      function currently executing.  However, even bizarre results are
  535.      predictable if you are well acquainted with the machine-language
  536.      code of your program.
  537.  
  538. `jump *ADDRESS'
  539.      Resume execution at the instruction at address ADDRESS.
  540.  
  541.    You can get much the same effect as the `jump' command by storing a
  542. new value into the register `$pc'.  The difference is that this does
  543. not start your program running; it only changes the address where it
  544. *will* run when you continue.  For example,
  545.  
  546.      set $pc = 0x485
  547.  
  548. makes the next `continue' command or stepping command execute at
  549. address `0x485', rather than at the address where your program stopped.
  550. *Note Continuing and stepping: Continuing and Stepping.
  551.  
  552.    The most common occasion to use the `jump' command is to back up,
  553. perhaps with more breakpoints set, over a portion of a program that has
  554. already executed, in order to examine its execution in more detail.
  555.  
  556. 
  557. File: gdb.info,  Node: Signaling,  Next: Returning,  Prev: Jumping,  Up: Altering
  558.  
  559. Giving your program a signal
  560. ============================
  561.  
  562. `signal SIGNAL'
  563.      Resume execution where your program stopped, but immediately give
  564.      it the signal SIGNAL.  SIGNAL can be the name or the number of a
  565.      signal.  For example, on many systems `signal 2' and `signal
  566.      SIGINT' are both ways of sending an interrupt signal.
  567.  
  568.      Alternatively, if SIGNAL is zero, continue execution without
  569.      giving a signal.  This is useful when your program stopped on
  570.      account of a signal and would ordinary see the signal when resumed
  571.      with the `continue' command; `signal 0' causes it to resume
  572.      without a signal.
  573.  
  574.      `signal' does not repeat when you press RET a second time after
  575.      executing the command.
  576.  
  577.    Invoking the `signal' command is not the same as invoking the `kill'
  578. utility from the shell.  Sending a signal with `kill' causes GDB to
  579. decide what to do with the signal depending on the signal handling
  580. tables (*note Signals::.).  The `signal' command passes the signal
  581. directly to your program.
  582.  
  583. 
  584. File: gdb.info,  Node: Returning,  Next: Calling,  Prev: Signaling,  Up: Altering
  585.  
  586. Returning from a function
  587. =========================
  588.  
  589. `return'
  590. `return EXPRESSION'
  591.      You can cancel execution of a function call with the `return'
  592.      command.  If you give an EXPRESSION argument, its value is used as
  593.      the function's return value.
  594.  
  595.    When you use `return', GDB discards the selected stack frame (and
  596. all frames within it).  You can think of this as making the discarded
  597. frame return prematurely.  If you wish to specify a value to be
  598. returned, give that value as the argument to `return'.
  599.  
  600.    This pops the selected stack frame (*note Selecting a frame:
  601. Selection.), and any other frames inside of it, leaving its caller as
  602. the innermost remaining frame.  That frame becomes selected.  The
  603. specified value is stored in the registers used for returning values of
  604. functions.
  605.  
  606.    The `return' command does not resume execution; it leaves the
  607. program stopped in the state that would exist if the function had just
  608. returned.  In contrast, the `finish' command (*note Continuing and
  609. stepping: Continuing and Stepping.) resumes execution until the
  610. selected stack frame returns naturally.
  611.  
  612. 
  613. File: gdb.info,  Node: Calling,  Next: Patching,  Prev: Returning,  Up: Altering
  614.  
  615. Calling program functions
  616. =========================
  617.  
  618. `call EXPR'
  619.      Evaluate the expression EXPR without displaying `void' returned
  620.      values.
  621.  
  622.    You can use this variant of the `print' command if you want to
  623. execute a function from your program, but without cluttering the output
  624. with `void' returned values.  The result is printed and saved in the
  625. value history, if it is not void.
  626.  
  627. 
  628. File: gdb.info,  Node: Patching,  Prev: Calling,  Up: Altering
  629.  
  630. Patching programs
  631. =================
  632.  
  633.    By default, GDB opens the file containing your program's executable
  634. code (or the corefile) read-only.  This prevents accidental alterations
  635. to machine code; but it also prevents you from intentionally patching
  636. your program's binary.
  637.  
  638.    If you'd like to be able to patch the binary, you can specify that
  639. explicitly with the `set write' command.  For example, you might want
  640. to turn on internal debugging flags, or even to make emergency repairs.
  641.  
  642. `set write on'
  643. `set write off'
  644.      If you specify `set write on', GDB opens executable and core files
  645.      for both reading and writing; if you specify `set write off' (the
  646.      default), GDB opens them read-only.
  647.  
  648.      If you have already loaded a file, you must load it again (using
  649.      the `exec-file' or `core-file' command) after changing `set
  650.      write', for your new setting to take effect.
  651.  
  652. `show write'
  653.      Display whether executable files and core files are opened for
  654.      writing as well as reading.
  655.  
  656. 
  657. File: gdb.info,  Node: GDB Files,  Next: Targets,  Prev: Altering,  Up: Top
  658.  
  659. GDB Files
  660. *********
  661.  
  662.    GDB needs to know the file name of the program to be debugged, both
  663. in order to read its symbol table and in order to start your program.
  664. To debug a core dump of a previous run, you must also tell GDB the name
  665. of the core dump file.
  666.  
  667. * Menu:
  668.  
  669. * Files::                       Commands to specify files
  670. * Symbol Errors::               Errors reading symbol files
  671.  
  672. 
  673. File: gdb.info,  Node: Files,  Next: Symbol Errors,  Up: GDB Files
  674.  
  675. Commands to specify files
  676. =========================
  677.  
  678.    The usual way to specify executable and core dump file names is with
  679. the command arguments given when you start GDB (*note Getting In and
  680. Out of GDB: Invocation..
  681.  
  682.    Occasionally it is necessary to change to a different file during a
  683. GDB session.  Or you may run GDB and forget to specify a file you want
  684. to use.  In these situations the GDB commands to specify new files are
  685. useful.
  686.  
  687. `file FILENAME'
  688.      Use FILENAME as the program to be debugged.  It is read for its
  689.      symbols and for the contents of pure memory.  It is also the
  690.      program executed when you use the `run' command.  If you do not
  691.      specify a directory and the file is not found in the GDB working
  692.      directory, GDB uses the environment variable `PATH' as a list of
  693.      directories to search, just as the shell does when looking for a
  694.      program to run.  You can change the value of this variable, for
  695.      both GDB and your program, using the `path' command.
  696.  
  697.      On systems with memory-mapped files, an auxiliary file
  698.      `FILENAME.syms' may hold symbol table information for FILENAME.
  699.      If so, GDB maps in the symbol table from `FILENAME.syms', starting
  700.      up more quickly.  See the descriptions of the options `-mapped'
  701.      and `-readnow' (available on the command line, and with the
  702.      commands `file', `symbol-file', or `add-symbol-file'), for more
  703.      information.
  704.  
  705. `file'
  706.      `file' with no argument makes GDB discard any information it has
  707.      on both executable file and the symbol table.
  708.  
  709. `exec-file [ FILENAME ]'
  710.      Specify that the program to be run (but not the symbol table) is
  711.      found in FILENAME.  GDB searches the environment variable `PATH'
  712.      if necessary to locate your program.  Omitting FILENAME means to
  713.      discard information on the executable file.
  714.  
  715. `symbol-file [ FILENAME ]'
  716.      Read symbol table information from file FILENAME.  `PATH' is
  717.      searched when necessary.  Use the `file' command to get both symbol
  718.      table and program to run from the same file.
  719.  
  720.      `symbol-file' with no argument clears out GDB information on your
  721.      program's symbol table.
  722.  
  723.      The `symbol-file' command causes GDB to forget the contents of its
  724.      convenience variables, the value history, and all breakpoints and
  725.      auto-display expressions.  This is because they may contain
  726.      pointers to the internal data recording symbols and data types,
  727.      which are part of the old symbol table data being discarded inside
  728.      GDB.
  729.  
  730.      `symbol-file' does not repeat if you press RET again after
  731.      executing it once.
  732.  
  733.      When GDB is configured for a particular environment, it
  734.      understands debugging information in whatever format is the
  735.      standard generated for that environment; you may use either a GNU
  736.      compiler, or other compilers that adhere to the local conventions.
  737.      Best results are usually obtained from GNU compilers; for
  738.      example, using `gcc' you can generate debugging information for
  739.      optimized code.
  740.  
  741.      On some kinds of object files, the `symbol-file' command does not
  742.      normally read the symbol table in full right away.  Instead, it
  743.      scans the symbol table quickly to find which source files and
  744.      which symbols are present.  The details are read later, one source
  745.      file at a time, as they are needed.
  746.  
  747.      The purpose of this two-stage reading strategy is to make GDB
  748.      start up faster.  For the most part, it is invisible except for
  749.      occasional pauses while the symbol table details for a particular
  750.      source file are being read.  (The `set verbose' command can turn
  751.      these pauses into messages if desired.  *Note Optional warnings
  752.      and messages: Messages/Warnings.)
  753.  
  754.      We have not implemented the two-stage strategy for COFF yet.  When
  755.      the symbol table is stored in COFF format, `symbol-file' reads the
  756.      symbol table data in full right away.
  757.  
  758. `symbol-file FILENAME [ -readnow ] [ -mapped ]'
  759. `file FILENAME [ -readnow ] [ -mapped ]'
  760.      You can override the GDB two-stage strategy for reading symbol
  761.      tables by using the `-readnow' option with any of the commands that
  762.      load symbol table information, if you want to be sure GDB has the
  763.      entire symbol table available.
  764.  
  765.      If memory-mapped files are available on your system through the
  766.      `mmap' system call, you can use another option, `-mapped', to
  767.      cause GDB to write the symbols for your program into a reusable
  768.      file.  Future GDB debugging sessions map in symbol information
  769.      from this auxiliary symbol file (if the program has not changed),
  770.      rather than spending time reading the symbol table from the
  771.      executable program.  Using the `-mapped' option has the same
  772.      effect as starting GDB with the `-mapped' command-line option.
  773.  
  774.      You can use both options together, to make sure the auxiliary
  775.      symbol file has all the symbol information for your program.
  776.  
  777.      The auxiliary symbol file for a program called MYPROG is called
  778.      `MYPROG.syms'.  Once this file exists (so long as it is newer than
  779.      the corresponding executable), GDB always attempts to use it when
  780.      you debug MYPROG; no special options or commands are needed.
  781.  
  782.      The `.syms' file is specific to the host machine where you run
  783.      GDB.  It holds an exact image of the internal GDB symbol table.
  784.      It cannot be shared across multiple host platforms.
  785.  
  786. `core-file [ FILENAME ]'
  787.      Specify the whereabouts of a core dump file to be used as the
  788.      "contents of memory".  Traditionally, core files contain only some
  789.      parts of the address space of the process that generated them; GDB
  790.      can access the executable file itself for other parts.
  791.  
  792.      `core-file' with no argument specifies that no core file is to be
  793.      used.
  794.  
  795.      Note that the core file is ignored when your program is actually
  796.      running under GDB.  So, if you have been running your program and
  797.      you wish to debug a core file instead, you must kill the
  798.      subprocess in which the program is running.  To do this, use the
  799.      `kill' command (*note Killing the child process: Kill Process.).
  800.  
  801. `load FILENAME'
  802.      Depending on what remote debugging facilities are configured into
  803.      GDB, the `load' command may be available.  Where it exists, it is
  804.      meant to make FILENAME (an executable) available for debugging on
  805.      the remote system--by downloading, or dynamic linking, for example.
  806.      `load' also records the FILENAME symbol table in GDB, like the
  807.      `add-symbol-file' command.
  808.  
  809.      If your GDB does not have a `load' command, attempting to execute
  810.      it gets the error message "`You can't do that when your target is
  811.      ...'"
  812.  
  813.      The file is loaded at whatever address is specified in the
  814.      executable.  For some object file formats, you can specify the
  815.      load address when you link the program; for other formats, like
  816.      a.out, the object file format specifies a fixed address.
  817.  
  818.      On VxWorks, `load' links FILENAME dynamically on the current
  819.      target system as well as adding its symbols in GDB.
  820.  
  821.      With the Nindy interface to an Intel 960 board, `load' downloads
  822.      FILENAME to the 960 as well as adding its symbols in GDB.
  823.  
  824.      When you select remote debugging to a Hitachi SH, H8/300, or
  825.      H8/500 board (*note GDB and Hitachi Microprocessors: Hitachi
  826.      Remote.), the `load' command downloads your program to the Hitachi
  827.      board and also opens it as the current executable target for GDB
  828.      on your host (like the `file' command).
  829.  
  830.      `load' does not repeat if you press RET again after using it.
  831.  
  832. `add-symbol-file FILENAME ADDRESS'
  833. `add-symbol-file FILENAME ADDRESS [ -readnow ] [ -mapped ]'
  834.      The `add-symbol-file' command reads additional symbol table
  835.      information from the file FILENAME.  You would use this command
  836.      when FILENAME has been dynamically loaded (by some other means)
  837.      into the program that is running.  ADDRESS should be the memory
  838.      address at which the file has been loaded; GDB cannot figure this
  839.      out for itself.  You can specify ADDRESS as an expression.
  840.  
  841.      The symbol table of the file FILENAME is added to the symbol table
  842.      originally read with the `symbol-file' command.  You can use the
  843.      `add-symbol-file' command any number of times; the new symbol data
  844.      thus read keeps adding to the old.  To discard all old symbol data
  845.      instead, use the `symbol-file' command.
  846.  
  847.      `add-symbol-file' does not repeat if you press RET after using it.
  848.  
  849.      You can use the `-mapped' and `-readnow' options just as with the
  850.      `symbol-file' command, to change how GDB manages the symbol table
  851.      information for FILENAME.
  852.  
  853. `info files'
  854. `info target'
  855.      `info files' and `info target' are synonymous; both print the
  856.      current target (*note Specifying a Debugging Target: Targets.),
  857.      including the names of the executable and core dump files
  858.      currently in use by GDB, and the files from which symbols were
  859.      loaded.  The command `help target' lists all possible targets
  860.      rather than current ones.
  861.  
  862.    All file-specifying commands allow both absolute and relative file
  863. names as arguments.  GDB always converts the file name to an absolute
  864. file name and remembers it that way.
  865.  
  866.    GDB supports SunOS, SVr4, Irix 5, and IBM RS/6000 shared libraries.
  867. G{No Value For "DBN"} automatically loads symbol definitions from
  868. shared libraries when you use the `run' command, or when you examine a
  869. core file.  (Before you issue the `run' command, GDB does not understand
  870. references to a function in a shared library, however--unless you are
  871. debugging a core file).
  872.  
  873. `info share'
  874. `info sharedlibrary'
  875.      Print the names of the shared libraries which are currently loaded.
  876.  
  877. `sharedlibrary REGEX'
  878. `share REGEX'
  879.      This is an obsolescent command; you can use it to explicitly load
  880.      shared object library symbols for files matching a Unix regular
  881.      expression, but as with files loaded automatically, it only loads
  882.      shared libraries required by your program for a core file or after
  883.      typing `run'.  If REGEX is omitted all shared libraries required
  884.      by your program are loaded.
  885.  
  886. 
  887. File: gdb.info,  Node: Symbol Errors,  Prev: Files,  Up: GDB Files
  888.  
  889. Errors reading symbol files
  890. ===========================
  891.  
  892.    While reading a symbol file, GDB occasionally encounters problems,
  893. such as symbol types it does not recognize, or known bugs in compiler
  894. output.  By default, GDB does not notify you of such problems, since
  895. they are relatively common and primarily of interest to people
  896. debugging compilers.  If you are interested in seeing information about
  897. ill-constructed symbol tables, you can either ask GDB to print only one
  898. message about each such type of problem, no matter how many times the
  899. problem occurs; or you can ask GDB to print more messages, to see how
  900. many times the problems occur, with the `set complaints' command (*note
  901. Optional warnings and messages: Messages/Warnings.).
  902.  
  903.    The messages currently printed, and their meanings, include:
  904.  
  905. `inner block not inside outer block in SYMBOL'
  906.      The symbol information shows where symbol scopes begin and end
  907.      (such as at the start of a function or a block of statements).
  908.      This error indicates that an inner scope block is not fully
  909.      contained in its outer scope blocks.
  910.  
  911.      GDB circumvents the problem by treating the inner block as if it
  912.      had the same scope as the outer block.  In the error message,
  913.      SYMBOL may be shown as "`(don't know)'" if the outer block is not a
  914.      function.
  915.  
  916. `block at ADDRESS out of order'
  917.      The symbol information for symbol scope blocks should occur in
  918.      order of increasing addresses.  This error indicates that it does
  919.      not do so.
  920.  
  921.      GDB does not circumvent this problem, and has trouble locating
  922.      symbols in the source file whose symbols it is reading.  (You can
  923.      often determine what source file is affected by specifying `set
  924.      verbose on'.  *Note Optional warnings and messages:
  925.      Messages/Warnings.)
  926.  
  927. `bad block start address patched'
  928.      The symbol information for a symbol scope block has a start address
  929.      smaller than the address of the preceding source line.  This is
  930.      known to occur in the SunOS 4.1.1 (and earlier) C compiler.
  931.  
  932.      GDB circumvents the problem by treating the symbol scope block as
  933.      starting on the previous source line.
  934.  
  935. `bad string table offset in symbol N'
  936.      Symbol number N contains a pointer into the string table which is
  937.      larger than the size of the string table.
  938.  
  939.      GDB circumvents the problem by considering the symbol to have the
  940.      name `foo', which may cause other problems if many symbols end up
  941.      with this name.
  942.  
  943. `unknown symbol type `0xNN''
  944.      The symbol information contains new data types that GDB does not
  945.      yet know how to read.  `0xNN' is the symbol type of the
  946.      misunderstood information, in hexadecimal.
  947.  
  948.      GDB circumvents the error by ignoring this symbol information.
  949.      This usually allows you to debug your program, though certain
  950.      symbols are not accessible.  If you encounter such a problem and
  951.      feel like debugging it, you can debug `gdb' with itself,
  952.      breakpoint on `complain', then go up to the function
  953.      `read_dbx_symtab' and examine `*bufp' to see the symbol.
  954.  
  955. `stub type has NULL name'
  956.      GDB could not find the full definition for a struct or class.
  957.  
  958. `const/volatile indicator missing (ok if using g++ v1.x), got...'
  959.      The symbol information for a C++ member function is missing some
  960.      information that recent versions of the compiler should have output
  961.      for it.
  962.  
  963. `info mismatch between compiler and debugger'
  964.      GDB could not parse a type specification output by the compiler.
  965.  
  966. 
  967. File: gdb.info,  Node: Targets,  Next: Controlling GDB,  Prev: GDB Files,  Up: Top
  968.  
  969. Specifying a Debugging Target
  970. *****************************
  971.  
  972.    A "target" is the execution environment occupied by your program.
  973. Often, GDB runs in the same host environment as your program; in that
  974. case, the debugging target is specified as a side effect when you use
  975. the `file' or `core' commands.  When you need more flexibility--for
  976. example, running GDB on a physically separate host, or controlling a
  977. standalone system over a serial port or a realtime system over a TCP/IP
  978. connection--you can use the `target' command to specify one of the
  979. target types configured for GDB (*note Commands for managing targets:
  980. Target Commands.).
  981.  
  982. * Menu:
  983.  
  984. * Active Targets::              Active targets
  985. * Target Commands::             Commands for managing targets
  986. * Remote::                      Remote debugging
  987.  
  988. 
  989. File: gdb.info,  Node: Active Targets,  Next: Target Commands,  Up: Targets
  990.  
  991. Active targets
  992. ==============
  993.  
  994.    There are three classes of targets: processes, core files, and
  995. executable files.  GDB can work concurrently on up to three active
  996. targets, one in each class.  This allows you to (for example) start a
  997. process and inspect its activity without abandoning your work on a core
  998. file.
  999.  
  1000.    For example, if you execute `gdb a.out', then the executable file
  1001. `a.out' is the only active target.  If you designate a core file as
  1002. well--presumably from a prior run that crashed and coredumped--then GDB
  1003. has two active targets and uses them in tandem, looking first in the
  1004. corefile target, then in the executable file, to satisfy requests for
  1005. memory addresses.  (Typically, these two classes of target are
  1006. complementary, since core files contain only a program's read-write
  1007. memory--variables and so on--plus machine status, while executable
  1008. files contain only the program text and initialized data.)
  1009.  
  1010.    When you type `run', your executable file becomes an active process
  1011. target as well.  When a process target is active, all GDB commands
  1012. requesting memory addresses refer to that target; addresses in an
  1013. active core file or executable file target are obscured while the
  1014. process target is active.
  1015.  
  1016.    Use the `core-file' and `exec-file' commands to select a new core
  1017. file or executable target (*note Commands to specify files: Files.).
  1018. To specify as a target a process that is already running, use the
  1019. `attach' command (*note Debugging an already-running process: Attach.).
  1020.  
  1021. 
  1022. File: gdb.info,  Node: Target Commands,  Next: Remote,  Prev: Active Targets,  Up: Targets
  1023.  
  1024. Commands for managing targets
  1025. =============================
  1026.  
  1027. `target TYPE PARAMETERS'
  1028.      Connects the GDB host environment to a target machine or process.
  1029.      A target is typically a protocol for talking to debugging
  1030.      facilities.  You use the argument TYPE to specify the type or
  1031.      protocol of the target machine.
  1032.  
  1033.      Further PARAMETERS are interpreted by the target protocol, but
  1034.      typically include things like device names or host names to connect
  1035.      with, process numbers, and baud rates.
  1036.  
  1037.      The `target' command does not repeat if you press RET again after
  1038.      executing the command.
  1039.  
  1040. `help target'
  1041.      Displays the names of all targets available.  To display targets
  1042.      currently selected, use either `info target' or `info files'
  1043.      (*note Commands to specify files: Files.).
  1044.  
  1045. `help target NAME'
  1046.      Describe a particular target, including any parameters necessary to
  1047.      select it.
  1048.  
  1049.    Here are some common targets (available, or not, depending on the GDB
  1050. configuration):
  1051.  
  1052. `target exec PROGRAM'
  1053.      An executable file.  `target exec PROGRAM' is the same as
  1054.      `exec-file PROGRAM'.
  1055.  
  1056. `target core FILENAME'
  1057.      A core dump file.  `target core FILENAME' is the same as
  1058.      `core-file FILENAME'.
  1059.  
  1060. `target remote DEV'
  1061.      Remote serial target in GDB-specific protocol.  The argument DEV
  1062.      specifies what serial device to use for the connection (e.g.
  1063.      `/dev/ttya'). *Note Remote debugging: Remote.
  1064.  
  1065. `target sim'
  1066.      CPU simulator.  *Note Simulated CPU Target: Simulator.
  1067.  
  1068. `target udi KEYWORD'
  1069.      Remote AMD29K target, using the AMD UDI protocol.  The KEYWORD
  1070.      argument specifies which 29K board or simulator to use.  *Note The
  1071.      UDI protocol for AMD29K: UDI29K Remote.
  1072.  
  1073. `target amd-eb DEV SPEED PROG'
  1074.      Remote PC-resident AMD EB29K board, attached over serial lines.
  1075.      dEV is the serial device, as for `target remote'; SPEED allows you
  1076.      to specify the linespeed; and PROG is the name of the program to
  1077.      be debugged, as it appears to DOS on the PC.  *Note The EBMON
  1078.      protocol for AMD29K: EB29K Remote.
  1079.  
  1080. `target hms'
  1081.      A Hitachi SH, H8/300, or H8/500 board, attached via serial line to
  1082.      your host.  Use special commands `device' and `speed' to control
  1083.      the serial line and the communications speed used.  *Note GDB and
  1084.      Hitachi Microprocessors: Hitachi Remote.
  1085.  
  1086. `target nindy DEVICENAME'
  1087.      An Intel 960 board controlled by a Nindy Monitor.  DEVICENAME is
  1088.      the name of the serial device to use for the connection, e.g.
  1089.      `/dev/ttya'.  *Note GDB with a remote i960 (Nindy): i960-Nindy
  1090.      Remote.
  1091.  
  1092. `target st2000 DEV SPEED'
  1093.      A Tandem ST2000 phone switch, running Tandem's STDBUG protocol.
  1094.      dEV is the name of the device attached to the ST2000 serial line;
  1095.      SPEED is the communication line speed.  The arguments are not used
  1096.      if GDB is configured to connect to the ST2000 using TCP or Telnet.
  1097.      *Note GDB with a Tandem ST2000: ST2000 Remote.
  1098.  
  1099. `target vxworks MACHINENAME'
  1100.      A VxWorks system, attached via TCP/IP.  The argument MACHINENAME
  1101.      is the target system's machine name or IP address.  *Note GDB and
  1102.      VxWorks: VxWorks Remote.
  1103.  
  1104.    Different targets are available on different configurations of GDB;
  1105. your configuration may have more or fewer targets.
  1106.  
  1107. 
  1108. File: gdb.info,  Node: Remote,  Prev: Target Commands,  Up: Targets
  1109.  
  1110. Remote debugging
  1111. ================
  1112.  
  1113.    If you are trying to debug a program running on a machine that
  1114. cannot run GDB in the usual way, it is often useful to use remote
  1115. debugging.  For example, you might use remote debugging on an operating
  1116. system kernel, or on a small system which does not have a general
  1117. purpose operating system powerful enough to run a full-featured
  1118. debugger.
  1119.  
  1120.    Some configurations of GDB have special serial or TCP/IP interfaces
  1121. to make this work with particular debugging targets.  In addition, GDB
  1122. comes with a generic serial protocol (specific to GDB, but not specific
  1123. to any particular target system) which you can use if you write the
  1124. remote stubs--the code that runs on the remote system to communicate
  1125. with GDB.
  1126.  
  1127.    Other remote targets may be available in your configuration of GDB;
  1128. use `help target' to list them.
  1129.  
  1130. * Menu:
  1131.  
  1132.  
  1133. * Remote Serial::               GDB remote serial protocol
  1134.  
  1135. * i960-Nindy Remote::        GDB with a remote i960 (Nindy)
  1136.  
  1137. * UDI29K Remote::               The UDI protocol for AMD29K
  1138. * EB29K Remote::        The EBMON protocol for AMD29K
  1139.  
  1140. * VxWorks Remote::        GDB and VxWorks
  1141.  
  1142. * ST2000 Remote::               GDB with a Tandem ST2000
  1143.  
  1144. * Hitachi Remote::              GDB and Hitachi Microprocessors
  1145.  
  1146. * MIPS Remote::            GDB and MIPS boards
  1147.  
  1148. * Simulator::                   Simulated CPU target
  1149.  
  1150. 
  1151. File: gdb.info,  Node: Remote Serial,  Next: i960-Nindy Remote,  Up: Remote
  1152.  
  1153. The GDB remote serial protocol
  1154. ------------------------------
  1155.  
  1156.    To debug a program running on another machine (the debugging
  1157. "target" machine), you must first arrange for all the usual
  1158. prerequisites for the program to run by itself.  For example, for a C
  1159. program, you need
  1160.  
  1161.   1. A startup routine to set up the C runtime environment; these
  1162.      usually have a name like `crt0'.  The startup routine may be
  1163.      supplied by your hardware supplier, or you may have to write your
  1164.      own.
  1165.  
  1166.   2. You probably need a C subroutine library to support your program's
  1167.      subroutine calls, notably managing input and output.
  1168.  
  1169.   3. A way of getting your program to the other machine--for example, a
  1170.      download program.  These are often supplied by the hardware
  1171.      manufacturer, but you may have to write your own from hardware
  1172.      documentation.
  1173.  
  1174.    The next step is to arrange for your program to use a serial port to
  1175. communicate with the machine where GDB is running (the "host" machine).
  1176. In general terms, the scheme looks like this:
  1177.  
  1178. *On the host,*
  1179.      GDB already understands how to use this protocol; when everything
  1180.      else is set up, you can simply use the `target remote' command
  1181.      (*note Specifying a Debugging Target: Targets.).
  1182.  
  1183. *On the target,*
  1184.      you must link with your program a few special-purpose subroutines
  1185.      that implement the GDB remote serial protocol.  The file
  1186.      containing these subroutines is called  a "debugging stub".
  1187.  
  1188.      On certain remote targets, you can use an auxiliary program
  1189.      `gdbserver' instead of linking a stub into your program.  *Note
  1190.      Using the `gdbserver' program: Server, for details.
  1191.  
  1192.    The debugging stub is specific to the architecture of the remote
  1193. machine; for example, use `sparc-stub.c' to debug programs on SPARC
  1194. boards.
  1195.  
  1196.    These working remote stubs are distributed with GDB:
  1197.  
  1198. `sparc-stub.c'
  1199.      For SPARC architectures.
  1200.  
  1201. `m68k-stub.c'
  1202.      For Motorola 680x0 architectures.
  1203.  
  1204. `i386-stub.c'
  1205.      For Intel 386 and compatible architectures.
  1206.  
  1207.    The `README' file in the GDB distribution may list other recently
  1208. added stubs.
  1209.  
  1210. * Menu:
  1211.  
  1212. * Stub Contents::       What the stub can do for you
  1213. * Bootstrapping::       What you must do for the stub
  1214. * Debug Session::       Putting it all together
  1215. * Protocol::            Outline of the communication protocol
  1216.  
  1217. * Server::        Using the `gdbserver' program
  1218.  
  1219. 
  1220. File: gdb.info,  Node: Stub Contents,  Next: Bootstrapping,  Up: Remote Serial
  1221.  
  1222. What the stub can do for you
  1223. ............................
  1224.  
  1225.    The debugging stub for your architecture supplies these three
  1226. subroutines:
  1227.  
  1228. `set_debug_traps'
  1229.      This routine arranges for `handle_exception' to run when your
  1230.      program stops.  You must call this subroutine explicitly near the
  1231.      beginning of your program.
  1232.  
  1233. `handle_exception'
  1234.      This is the central workhorse, but your program never calls it
  1235.      explicitly--the setup code arranges for `handle_exception' to run
  1236.      when a trap is triggered.
  1237.  
  1238.      `handle_exception' takes control when your program stops during
  1239.      execution (for example, on a breakpoint), and mediates
  1240.      communications with GDB on the host machine.  This is where the
  1241.      communications protocol is implemented; `handle_exception' acts as
  1242.      the GDB representative on the target machine; it begins by sending
  1243.      summary information on the state of your program, then continues
  1244.      to execute, retrieving and transmitting any information GDB needs,
  1245.      until you execute a GDB command that makes your program resume; at
  1246.      that point, `handle_exception' returns control to your own code on
  1247.      the target machine.
  1248.  
  1249. `breakpoint'
  1250.      Use this auxiliary subroutine to make your program contain a
  1251.      breakpoint.  Depending on the particular situation, this may be
  1252.      the only way for GDB to get control.  For instance, if your target
  1253.      machine has some sort of interrupt button, you won't need to call
  1254.      this; pressing the interrupt button transfers control to
  1255.      `handle_exception'--in effect, to GDB.  On some machines, simply
  1256.      receiving characters on the serial port may also trigger a trap;
  1257.      again, in that situation, you don't need to call `breakpoint' from
  1258.      your own program--simply running `target remote' from the host GDB
  1259.      session gets control.
  1260.  
  1261.      Call `breakpoint' if none of these is true, or if you simply want
  1262.      to make certain your program stops at a predetermined point for the
  1263.      start of your debugging session.
  1264.  
  1265.