home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / prgramer / unix / info / gdb.i05 (.txt) < prev    next >
GNU Info File  |  1993-06-12  |  52KB  |  927 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: Returning,  Next: Calling,  Prev: Signaling,  Up: Altering
  25. Returning from a Function
  26. =========================
  27. `return'
  28. `return EXPRESSION'
  29.      You can cancel execution of a function call with the `return'
  30.      command.  If you give an EXPRESSION argument, its value is used as
  31.      the function's return value.
  32.    When you use `return', GDB discards the selected stack frame (and
  33. all frames within it).  You can think of this as making the discarded
  34. frame return prematurely.  If you wish to specify a value to be
  35. returned, give that value as the argument to `return'.
  36.    This pops the selected stack frame (*note Selecting a Frame:
  37. Selection.), and any other frames inside of it, leaving its caller as
  38. the innermost remaining frame.  That frame becomes selected.  The
  39. specified value is stored in the registers used for returning values of
  40. functions.
  41.    The `return' command does not resume execution; it leaves the
  42. program stopped in the state that would exist if the function had just
  43. returned.  In contrast, the `finish' command (*note Continuing and
  44. Stepping: Continuing and Stepping.) resumes execution until the
  45. selected stack frame returns naturally.
  46. File: gdb.info,  Node: Calling,  Next: Patching,  Prev: Returning,  Up: Altering
  47. Calling your Program's Functions
  48. ================================
  49. `call EXPR'
  50.      Evaluate the expression EXPR without displaying `void' returned
  51.      values.
  52.    You can use this variant of the `print' command if you want to
  53. execute a function from your program, but without cluttering the output
  54. with `void' returned values.  The result is printed and saved in the
  55. value history, if it is not void.
  56. File: gdb.info,  Node: Patching,  Prev: Calling,  Up: Altering
  57. Patching your Program
  58. =====================
  59.    By default, GDB opens the file containing your program's executable
  60. code (or the corefile) read-only.  This prevents accidental alterations
  61. to machine code; but it also prevents you from intentionally patching
  62. your program's binary.
  63.    If you'd like to be able to patch the binary, you can specify that
  64. explicitly with the `set write' command.  For example, you might want
  65. to turn on internal debugging flags, or even to make emergency repairs.
  66. `set write on'
  67. `set write off'
  68.      If you specify `set write on', GDB will open executable and core
  69.      files for both reading and writing; if you specify `set write off'
  70.      (the default), GDB will open them read-only.
  71.      If you have already loaded a file, you must load it again (using
  72.      the `exec-file' or `core-file' command) after changing `set
  73.      write', for your new setting to take effect.
  74. `show write'
  75.      Display whether executable files and core files will be opened for
  76.      writing as well as reading.
  77. File: gdb.info,  Node: GDB Files,  Next: Targets,  Prev: Altering,  Up: Top
  78. GDB's Files
  79. ***********
  80.    GDB needs to know the file name of the program to be debugged, both
  81. in order to read its symbol table and in order to start your program.
  82. To debug a core dump of a previous run, GDB must be told the file name
  83. of the core dump.
  84. * Menu:
  85. * Files::                       Commands to Specify Files
  86. * Symbol Errors::               Errors Reading Symbol Files
  87. File: gdb.info,  Node: Files,  Next: Symbol Errors,  Up: GDB Files
  88. Commands to Specify Files
  89. =========================
  90.    The usual way to specify executable and core dump file names is with
  91. the command arguments given when you start GDB, (*note Getting In and
  92. Out of GDB: Invocation..
  93.    Occasionally it is necessary to change to a different file during a
  94. GDB session.  Or you may run GDB and forget to specify a file you want
  95. to use.  In these situations the GDB commands to specify new files are
  96. useful.
  97. `file FILENAME'
  98.      Use FILENAME as the program to be debugged.  It is read for its
  99.      symbols and for the contents of pure memory.  It is also the
  100.      program executed when you use the `run' command.  If you do not
  101.      specify a directory and the file is not found in GDB's working
  102.      directory, GDB uses the environment variable `PATH' as a list of
  103.      directories to search, just as the shell does when looking for a
  104.      program to run.  You can change the value of this variable, for
  105.      both GDB and your program, using the `path' command.
  106.      On systems with memory-mapped files, an auxiliary symbol table file
  107.      `FILENAME.syms' may be available for FILENAME.  If it is, GDB will
  108.      map in the symbol table from `FILENAME.syms', starting up more
  109.      quickly.  See the descriptions of the options `-mapped' and
  110.      `-readnow' (available on the command line, and with the commands
  111.      `file', `symbol-file', or `add-symbol-file'), for more information.
  112. `file'
  113.      `file' with no argument makes GDB discard any information it has
  114.      on both executable file and the symbol table.
  115. `exec-file [ FILENAME ]'
  116.      Specify that the program to be run (but not the symbol table) is
  117.      found in FILENAME.  GDB will search the environment variable `PATH'
  118.      if necessary to locate your program.  Omitting FILENAME means to
  119.      discard information on the executable file.
  120. `symbol-file [ FILENAME ]'
  121.      Read symbol table information from file FILENAME.  `PATH' is
  122.      searched when necessary.  Use the `file' command to get both symbol
  123.      table and program to run from the same file.
  124.      `symbol-file' with no argument clears out GDB's information on your
  125.      program's symbol table.
  126.      The `symbol-file' command causes GDB to forget the contents of its
  127.      convenience variables, the value history, and all breakpoints and
  128.      auto-display expressions.  This is because they may contain
  129.      pointers to the internal data recording symbols and data types,
  130.      which are part of the old symbol table data being discarded inside
  131.      GDB.
  132.      `symbol-file' will not repeat if you press RET again after
  133.      executing it once.
  134.      When GDB is configured for a particular environment, it will
  135.      understand debugging information in whatever format is the standard
  136.      generated for that environment; you may use either a GNU compiler,
  137.      or other compilers that adhere to the local conventions.  Best
  138.      results are usually obtained from GNU compilers; for example,
  139.      using `gcc' you can generate debugging information for optimized
  140.      code.
  141.      On some kinds of object files, the `symbol-file' command does not
  142.      normally read the symbol table in full right away.  Instead, it
  143.      scans the symbol table quickly to find which source files and
  144.      which symbols are present.  The details are read later, one source
  145.      file at a time, as they are needed.
  146.      The purpose of this two-stage reading strategy is to make GDB
  147.      start up faster.  For the most part, it is invisible except for
  148.      occasional pauses while the symbol table details for a particular
  149.      source file are being read.  (The `set verbose' command can turn
  150.      these pauses into messages if desired. *Note Optional Warnings and
  151.      Messages: Messages/Warnings.)
  152.      When the symbol table is stored in COFF format, `symbol-file' does
  153.      read the symbol table data in full right away.  We have not
  154.      implemented the two-stage strategy for COFF yet.
  155. `symbol-file FILENAME [ -readnow ] [ -mapped ]'
  156. `file FILENAME [ -readnow ] [ -mapped ]'
  157.      You can override the GDB two-stage strategy for reading symbol
  158.      tables by using the `-readnow' option with any of the commands that
  159.      load symbol table information, if you want to be sure GDB has the
  160.      entire symbol table available.
  161.      If memory-mapped files are available on your system through the
  162.      `mmap' system call, you can use another option, `-mapped', to
  163.      cause GDB to write the symbols for your program into a reusable
  164.      file.  Future GDB debugging sessions will map in symbol information
  165.      from this auxiliary symbol file (if the program hasn't changed),
  166.      rather than spending time reading the symbol table from the
  167.      executable program.  Using the `-mapped' option has the same
  168.      effect as starting GDB with the `-mapped' command-line option.
  169.      You can use both options together, to make sure the auxiliary
  170.      symbol file has all the symbol information for your program.
  171.      The `.syms' file is specific to the host machine on which GDB is
  172.      run. It holds an exact image of GDB's internal symbol table.  It
  173.      cannot be shared across multiple host platforms.
  174.      The auxiliary symbol file for a program called MYPROG is called
  175.      `MYPROG.syms'.  Once this file exists (so long as it is newer than
  176.      the corresponding executable), GDB will always attempt to use it
  177.      when you debug MYPROG; no special options or commands are needed.
  178. `core-file [ FILENAME ]'
  179.      Specify the whereabouts of a core dump file to be used as the
  180.      "contents of memory".  Traditionally, core files contain only some
  181.      parts of the address space of the process that generated them; GDB
  182.      can access the executable file itself for other parts.
  183.      `core-file' with no argument specifies that no core file is to be
  184.      used.
  185.      Note that the core file is ignored when your program is actually
  186.      running under GDB.  So, if you have been running your program and
  187.      you wish to debug a core file instead, you must kill the
  188.      subprocess in which the program is running.  To do this, use the
  189.      `kill' command (*note Killing the Child Process: Kill Process.).
  190. `load FILENAME'
  191.      Depending on what remote debugging facilities are configured into
  192.      GDB, the `load' command may be available.  Where it exists, it is
  193.      meant to make FILENAME (an executable) available for debugging on
  194.      the remote system--by downloading, or dynamic linking, for example.
  195.      `load' also records FILENAME's symbol table in GDB, like the
  196.      `add-symbol-file' command.
  197.      If `load' is not available on your GDB, attempting to execute it
  198.      gets the error message "`You can't do that when your target is
  199.      ...'"
  200.      On VxWorks, `load' will dynamically link FILENAME on the current
  201.      target system as well as adding its symbols in GDB.
  202.      With the Nindy interface to an Intel 960 board, `load' will
  203.      download FILENAME to the 960 as well as adding its symbols in GDB.
  204.      When you select remote debugging to a Hitachi H8/300 board (*note
  205.      GDB and the Hitachi H8/300: Hitachi H8/300 Remote.), the `load'
  206.      command downloads your program to the H8/300 and also opens it as
  207.      the current executable target for GDB on your host (like the
  208.      `file' command).
  209.      `load' will not repeat if you press RET again after using it.
  210. `add-symbol-file FILENAME ADDRESS'
  211. `add-symbol-file FILENAME ADDRESS [ -readnow ] [ -mapped ]'
  212.      The `add-symbol-file' command reads additional symbol table
  213.      information from the file FILENAME.  You would use this command
  214.      when FILENAME has been dynamically loaded (by some other means)
  215.      into the program that is running.  ADDRESS should be the memory
  216.      address at which the file has been loaded; GDB cannot figure this
  217.      out for itself.
  218.      The symbol table of the file FILENAME is added to the symbol table
  219.      originally read with the `symbol-file' command.  You can use the
  220.      `add-symbol-file' command any number of times; the new symbol data
  221.      thus read keeps adding to the old.  To discard all old symbol data
  222.      instead, use the `symbol-file' command.
  223.      `add-symbol-file' will not repeat if you press RET after using it.
  224.      You can use the `-mapped' and `-readnow' options just as with the
  225.      `symbol-file' command, to change how GDB manages the symbol table
  226.      information for FILENAME.
  227. `info files'
  228. `info target'
  229.      `info files' and `info target' are synonymous; both print the
  230.      current targets (*note Specifying a Debugging Target: Targets.),
  231.      including the names of the executable and core dump files
  232.      currently in use by GDB, and the files from which symbols were
  233.      loaded.  The command `help targets' lists all possible targets
  234.      rather than current ones.
  235.    All file-specifying commands allow both absolute and relative file
  236. names as arguments.  GDB always converts the file name to an absolute
  237. path name and remembers it that way.
  238.    GDB supports SunOS, SVR4, and IBM RS/6000 shared libraries. GDB
  239. automatically loads symbol definitions from shared libraries when you
  240. use the `run' command, or when you examine a core file. (Before you
  241. issue the `run' command, GDB will not understand references to a
  242. function in a shared library, however--unless you are debugging a core
  243. file).
  244. `info share'
  245. `info sharedlibrary'
  246.      Print the names of the shared libraries which are currently loaded.
  247. `sharedlibrary REGEX'
  248. `share REGEX'
  249.      This is an obsolescent command; you can use it to explicitly load
  250.      shared object library symbols for files matching a UNIX regular
  251.      expression, but as with files loaded automatically, it will only
  252.      load shared libraries required by your program for a core file or
  253.      after typing `run'.  If REGEX is omitted all shared libraries
  254.      required by your program are loaded.
  255. File: gdb.info,  Node: Symbol Errors,  Prev: Files,  Up: GDB Files
  256. Errors Reading Symbol Files
  257. ===========================
  258.    While reading a symbol file, GDB will occasionally encounter
  259. problems, such as symbol types it does not recognize, or known bugs in
  260. compiler output.  By default, GDB does not notify you of such problems,
  261. since they are relatively common and primarily of interest to people
  262. debugging compilers.  If you are interested in seeing information about
  263. ill-constructed symbol tables, you can either ask GDB to print only one
  264. message about each such type of problem, no matter how many times the
  265. problem occurs; or you can ask GDB to print more messages, to see how
  266. many times the problems occur, with the `set complaints' command (*note
  267. Optional Warnings and Messages: Messages/Warnings.).
  268.    The messages currently printed, and their meanings, are:
  269. `inner block not inside outer block in SYMBOL'
  270.      The symbol information shows where symbol scopes begin and end
  271.      (such as at the start of a function or a block of statements). 
  272.      This error indicates that an inner scope block is not fully
  273.      contained in its outer scope blocks.
  274.      GDB circumvents the problem by treating the inner block as if it
  275.      had the same scope as the outer block.  In the error message,
  276.      SYMBOL may be shown as "`(don't know)'" if the outer block is not a
  277.      function.
  278. `block at ADDRESS out of order'
  279.      The symbol information for symbol scope blocks should occur in
  280.      order of increasing addresses.  This error indicates that it does
  281.      not do so.
  282.      GDB does not circumvent this problem, and will have trouble
  283.      locating symbols in the source file whose symbols being read. 
  284.      (You can often determine what source file is affected by
  285.      specifying `set verbose on'.  *Note Optional Warnings and
  286.      Messages: Messages/Warnings.)
  287. `bad block start address patched'
  288.      The symbol information for a symbol scope block has a start address
  289.      smaller than the address of the preceding source line.  This is
  290.      known to occur in the SunOS 4.1.1 (and earlier) C compiler.
  291.      GDB circumvents the problem by treating the symbol scope block as
  292.      starting on the previous source line.
  293. `bad string table offset in symbol N'
  294.      Symbol number N contains a pointer into the string table which is
  295.      larger than the size of the string table.
  296.      GDB circumvents the problem by considering the symbol to have the
  297.      name `foo', which may cause other problems if many symbols end up
  298.      with this name.
  299. `unknown symbol type `0xNN''
  300.      The symbol information contains new data types that GDB does not
  301.      yet know how to read.  `0xNN' is the symbol type of the
  302.      misunderstood information, in hexadecimal.
  303.      GDB circumvents the error by ignoring this symbol information. 
  304.      This will usually allow your program to be debugged, though
  305.      certain symbols will not be accessible.  If you encounter such a
  306.      problem and feel like debugging it, you can debug `gdb' with
  307.      itself, breakpoint on `complain', then go up to the function
  308.      `read_dbx_symtab' and examine `*bufp' to see the symbol.
  309. `stub type has NULL name'
  310.      GDB could not find the full definition for a struct or class.
  311. `const/volatile indicator missing (ok if using g++ v1.x), got...'
  312.      The symbol information for a C++ member function is missing some
  313.      information that recent versions of the compiler should have output
  314.      for it.
  315. `info mismatch between compiler and debugger'
  316.      GDB could not parse a type specification output by the compiler.
  317. File: gdb.info,  Node: Targets,  Next: Controlling GDB,  Prev: GDB Files,  Up: Top
  318. Specifying a Debugging Target
  319. *****************************
  320.    A "target" is the execution environment occupied by your program.
  321. Often, GDB runs in the same host environment as your program; in that
  322. case, the debugging target is specified as a side effect when you use
  323. the `file' or `core' commands.  When you need more flexibility--for
  324. example, running GDB on a physically separate host, or controlling a
  325. standalone system over a serial port or a realtime system over a TCP/IP
  326. connection--you can use the `target' command to specify one of the
  327. target types configured for GDB (*note Commands for Managing Targets:
  328. Target Commands.).
  329. * Menu:
  330. * Active Targets::              Active Targets
  331. * Target Commands::             Commands for Managing Targets
  332. * Remote::                      Remote Debugging
  333. File: gdb.info,  Node: Active Targets,  Next: Target Commands,  Up: Targets
  334. Active Targets
  335. ==============
  336.    There are three classes of targets: processes, core files, and
  337. executable files.  GDB can work concurrently on up to three active
  338. targets, one in each class.  This allows you to (for example) start a
  339. process and inspect its activity without abandoning your work on a core
  340. file.
  341.    If, for example, you execute `gdb a.out', then the executable file
  342. `a.out' is the only active target.  If you designate a core file as
  343. well--presumably from a prior run that crashed and coredumped--then GDB
  344. has two active targets and will use them in tandem, looking first in
  345. the corefile target, then in the executable file, to satisfy requests
  346. for memory addresses.  (Typically, these two classes of target are
  347. complementary, since core files contain only a program's read-write
  348. memory--variables and so on--plus machine status, while executable
  349. files contain only the program text and initialized data.)
  350.    When you type `run', your executable file becomes an active process
  351. target as well.  When a process target is active, all GDB commands
  352. requesting memory addresses refer to that target; addresses in an
  353. active core file or executable file target are obscured while the
  354. process target is active.
  355.    Use the `core-file' and `exec-file' commands to select a new core
  356. file or executable target (*note Commands to Specify Files: Files.). 
  357. To specify as a target a process that is already running, use the
  358. `attach' command (*note Debugging an Already-Running Process: Attach..).
  359. File: gdb.info,  Node: Target Commands,  Next: Remote,  Prev: Active Targets,  Up: Targets
  360. Commands for Managing Targets
  361. =============================
  362. `target TYPE PARAMETERS'
  363.      Connects the GDB host environment to a target machine or process. 
  364.      A target is typically a protocol for talking to debugging
  365.      facilities.  You use the argument TYPE to specify the type or
  366.      protocol of the target machine.
  367.      Further PARAMETERS are interpreted by the target protocol, but
  368.      typically include things like device names or host names to connect
  369.      with, process numbers, and baud rates.
  370.      The `target' command will not repeat if you press RET again after
  371.      executing the command.
  372. `help target'
  373.      Displays the names of all targets available.  To display targets
  374.      currently selected, use either `info target' or `info files'
  375.      (*note Commands to Specify Files: Files.).
  376. `help target NAME'
  377.      Describe a particular target, including any parameters necessary to
  378.      select it.
  379.    Here are some common targets (available, or not, depending on the GDB
  380. configuration):
  381. `target exec PROG'
  382.      An executable file.  `target exec PROG' is the same as `exec-file
  383.      PROG'.
  384. `target core FILENAME'
  385.      A core dump file.  `target core FILENAME' is the same as
  386.      `core-file FILENAME'.
  387. `target remote DEV'
  388.      Remote serial target in GDB-specific protocol.  The argument DEV
  389.      specifies what serial device to use for the connection (e.g.
  390.      `/dev/ttya'). *Note Remote Debugging: Remote.
  391. `target amd-eb DEV SPEED PROG'
  392.      Remote PC-resident AMD EB29K board, attached over serial lines.
  393.      DEV is the serial device, as for `target remote'; SPEED allows you
  394.      to specify the linespeed; and PROG is the name of the program to
  395.      be debugged, as it appears to DOS on the PC. *Note GDB with a
  396.      Remote EB29K: EB29K Remote.
  397. `target hms'
  398.      A Hitachi H8/300 board, attached via serial line to your host.  Use
  399.      special commands `device' and `speed' to control the serial line
  400.      and the communications speed used. *Note GDB and the Hitachi
  401.      H8/300: Hitachi H8/300 Remote.
  402. `target nindy DEVICENAME'
  403.      An Intel 960 board controlled by a Nindy Monitor.  DEVICENAME is
  404.      the name of the serial device to use for the connection, e.g.
  405.      `/dev/ttya'.  *Note GDB with a Remote i960 (Nindy): i960-Nindy
  406.      Remote.
  407. `target st2000 DEV SPEED'
  408.      A Tandem ST2000 phone switch, running Tandem's STDBUG protocol. 
  409.      DEV is the name of the device attached to the ST2000 serial line;
  410.      SPEED is the communication line speed.  The arguments are not used
  411.      if GDB is configured to connect to the ST2000 using TCP or Telnet.
  412.      *Note GDB with a Tandem ST2000: ST2000 Remote.
  413. `target vxworks MACHINENAME'
  414.      A VxWorks system, attached via TCP/IP.  The argument MACHINENAME
  415.      is the target system's machine name or IP address. *Note GDB and
  416.      VxWorks: VxWorks Remote.
  417.    Different targets are available on different configurations of GDB;
  418. your configuration may have more or fewer targets.
  419. File: gdb.info,  Node: Remote,  Prev: Target Commands,  Up: Targets
  420. Remote Debugging
  421. ================
  422.    If you are trying to debug a program running on a machine that
  423. cannot run GDB in the usual way, it is often useful to use remote
  424. debugging.  For example, you might use remote debugging on an operating
  425. system kernel, or on a small system which does not have a general
  426. purpose operating system powerful enough to run a full-featured
  427. debugger.
  428.    Some configurations of GDB have special serial or TCP/IP interfaces
  429. to make this work with particular debugging targets.  In addition, GDB
  430. comes with a generic serial protocol (specific to GDB, but not specific
  431. to any particular target system) which you can use if you write the
  432. remote stubs--the code that will run on the remote system to
  433. communicate with GDB.
  434.    Other remote targets may be available in your configuration of GDB;
  435. use `help targets' to list them.
  436. * Menu:
  437. * Remote Serial::               GDB remote serial protocol
  438. * i960-Nindy Remote::        GDB with a remote i960 (Nindy)
  439. * EB29K Remote::        GDB with a remote EB29K
  440. * VxWorks Remote::        GDB and VxWorks
  441. * ST2000 Remote::               GDB with a Tandem ST2000
  442. * Hitachi H8/300 Remote::       GDB and the Hitachi H8/300
  443. File: gdb.info,  Node: Remote Serial,  Next: i960-Nindy Remote,  Up: Remote
  444. The GDB remote serial protocol
  445. ------------------------------
  446.    To debug a program running on another machine (the debugging
  447. "target" machine), you must first arrange for all the usual
  448. prerequisites for the program to run by itself.  For example, for a C
  449. program, you need
  450.   1. A startup routine to set up the C runtime environment; these
  451.      usually have a name like `crt0'.  The startup routine may be
  452.      supplied by your hardware supplier, or you may have to write your
  453.      own.
  454.   2. You probably need a C subroutine library to support your program's
  455.      subroutine calls, notably managing input and output.
  456.   3. A way of getting your program to the other machine--for example, a
  457.      download program.  These are often supplied by the hardware
  458.      manufacturer, but you may have to write your own from hardware
  459.      documentation.
  460.    The next step is to arrange for your program to use a serial port to
  461. communicate with the machine where GDB is running (the "host" machine).
  462.  In general terms, the scheme looks like this:
  463. *On the host,*
  464.      GDB already understands how to use this protocol; when everything
  465.      else is set up, you can simply use the `target remote' command
  466.      (*note Specifying a Debugging Target: Targets.).
  467. *On the target,*
  468.      you must link with your program a few special-purpose subroutines
  469.      that implement the GDB remote serial protocol.  The file
  470.      containing these subroutines is called  a "debugging stub".
  471.    The debugging stub is specific to the architecture of the remote
  472. machine; for example, use `sparc-stub.c' to debug programs on SPARC
  473. boards.
  474.    These working remote stubs are distributed with GDB:
  475. `sparc-stub.c'
  476.      For SPARC architectures.
  477. `m68k-stub.c'
  478.      For Motorola 680x0 architectures.
  479. `i386-stub.c'
  480.      For Intel 386 and compatible architectures.
  481.    The `README' file in the GDB distribution may list other recently
  482. added stubs.
  483. * Menu:
  484. * stub contents::       What the stub can do for you
  485. * bootstrapping::       What you must do for the stub
  486. * debug session::       Putting it all together
  487. * protocol::            Outline of the communication protocol
  488. File: gdb.info,  Node: stub contents,  Next: bootstrapping,  Up: Remote Serial
  489. What the stub can do for you
  490. ............................
  491.    The debugging stub for your architecture supplies these three
  492. subroutines:
  493. `set_debug_traps'
  494.      This routine arranges to transfer control to `handle_exception'
  495.      when your program stops.  You must call this subroutine explicitly
  496.      near the beginning of your program.
  497. `handle_exception'
  498.      This is the central workhorse, but your program never calls it
  499.      explicitly--the setup code arranges for `handle_exception' to run
  500.      when a trap is triggered.
  501.      `handle_exception' takes control when your program stops during
  502.      execution (for example, on a breakpoint), and mediates
  503.      communications with GDB on the host machine.  This is where the
  504.      communications protocol is implemented; `handle_exception' acts as
  505.      the GDB representative on the target machine; it begins by sending
  506.      summary information on the state of your program, then continues
  507.      to execute, retrieving and transmitting any information GDB needs,
  508.      until you execute a GDB command that makes your program resume; at
  509.      that point, `handle_exception' returns control to your own code on
  510.      the target machine.
  511. `breakpoint'
  512.      Use this auxiliary subroutine to make your program contain a
  513.      breakpoint.  Depending on the particular situation, this may be
  514.      the only way for GDB to get control.  For instance, if your target
  515.      machine has some sort of interrupt button, you won't need to call
  516.      this; pressing the interrupt button will transfer control to
  517.      `handle_exception'--in efect, to GDB.  On some machines, simply
  518.      receiving characters on the serial port may also trigger a trap;
  519.      again, in that situation, you don't need to call `breakpoint' from
  520.      your own program--simply running `target remote' from the host GDB
  521.      session will get control.
  522.      Call `breakpoint' if none of these is true, or if you simply want
  523.      to make certain your program stops at a predetermined point for the
  524.      start of your debugging session.
  525. File: gdb.info,  Node: bootstrapping,  Next: debug session,  Prev: stub contents,  Up: Remote Serial
  526. What you must do for the stub
  527. .............................
  528.    The debugging stubs that come with GDB are set up for a particular
  529. chip architecture, but they have no information about the rest of your
  530. debugging target machine.  To allow the stub to work, you must supply
  531. these special low-level subroutines:
  532. `int getDebugChar()'
  533.      Write this subroutine to read a single character from the serial
  534.      port. It may be identical to `getchar' for your target system; a
  535.      different name is used to allow you to distinguish the two if you
  536.      wish.
  537. `void putDebugChar(int)'
  538.      Write this subroutine to write a single character to the serial
  539.      port. It may be identical to `putchar' for your target system; a
  540.      different name is used to allow you to distinguish the two if you
  541.      wish.
  542. `void flush_i_cache()'
  543.      Write this subroutine to flush the instruction cache, if any, on
  544.      your target machine.  If there is no instruction cache, this
  545.      subroutine may be a no-op.
  546.      On target machines that have instruction caches, GDB requires this
  547.      function to make certain that the state of your program is stable.
  548. You must also make sure this library routine is available:
  549. `void *memset(void *, int, int)'
  550.      This is the standard library function `memset' that sets an area of
  551.      memory to a known value.  If you have one of the free versions of
  552.      `libc.a', `memset' can be found there; otherwise, you must either
  553.      obtain it from your hardware manufacturer, or write your own.
  554.    If you do not use the GNU C compiler, you may need other standard
  555. library subroutines as well; this will vary from one stub to another,
  556. but in general the stubs are likely to use any of the common library
  557. subroutines which `gcc' generates as inline code.
  558. File: gdb.info,  Node: debug session,  Next: protocol,  Prev: bootstrapping,  Up: Remote Serial
  559. Putting it all together
  560. .......................
  561.    In summary, when your program is ready to debug, you must follow
  562. these steps.
  563.   1. Make sure you have the supporting low-level routines:
  564.      `getDebugChar', `putDebugChar', `flush_i_cache', `memset'.
  565.   2. Insert these lines near the top of your program:
  566.           set_debug_traps();
  567.           breakpoint();
  568.   3. Compile and link together: your program, the GDB debugging stub for
  569.      your target architecture, and the supporting subroutines.
  570.   4. Make sure you have a serial connection between your target machine
  571.      and the GDB host, and identify the serial port used for this on
  572.      the host.
  573.   5. Download your program to your target machine (or get it there by
  574.      whatever means the manufacturer provides), and start it.
  575.   6. To start remote debugging, run GDB on the host machine, and specify
  576.      as an executable file the program that is running in the remote
  577.      machine. This tells GDB how to find your program's symbols and the
  578.      contents of its pure text.
  579.      Then establish communication using the `target remote' command.
  580.      Its argument is the name of the device you're using to control the
  581.      target machine.  For example:
  582.           target remote /dev/ttyb
  583.      if the serial line is connected to the device named `/dev/ttyb'.
  584.    Now you can use all the usual commands to examine and change data
  585. and to step and continue the remote program.
  586.    To resume the remote program and stop debugging it, use the `detach'
  587. command.
  588. File: gdb.info,  Node: protocol,  Prev: debug session,  Up: Remote Serial
  589. Outline of the communication protocol
  590. .....................................
  591.    The stub files provided with GDB implement the target side of the
  592. communication protocol, and the GDB side is implemented in the GDB
  593. source file `remote.c'.  Normally, you can simply allow these
  594. subroutines to communicate, and ignore the details.  (If you're
  595. implementing your own stub file, you can still ignore the details: start
  596. with one of the existing stub files.  `sparc-stub.c' is the best
  597. organized, and therefore the easiest to read.)
  598.    However, there may be occasions when you need to know something about
  599. the protocol--for example, if there is only one serial port to your
  600. target machine, you might want your program to do something special if
  601. it recognizes a packet meant for GDB.
  602.    All GDB commands and responses (other than acknowledgements, which
  603. are single characters) are sent as a packet which includes a checksum. 
  604. A packet is introduced with the character `$', and ends with the
  605. character `#' followed by a two-digit checksum:
  606.      $PACKET INFO#CHECKSUM
  607. CHECKSUM is computed as the modulo 256 sum of the PACKET INFO
  608. characters.
  609.    When either the host or the target machine receives a packet, the
  610. first response expected is an acknowledgement: a single character,
  611. either `+' (to indicate the package was received correctly) or `-' (to
  612. request retransmission).
  613.    The host (GDB) sends commands, and the target (the debugging stub
  614. incorporated in your program) sends data in response.  The target also
  615. sends data when your program stops.
  616.    Command packets are distinguished by their first character, which
  617. identifies the kind of command.
  618.    These are the commands currently supported:
  619.      Requests the values of CPU registers.
  620.      Sets the values of CPU registers.
  621. `mADDR,COUNT'
  622.      Read COUNT bytes at location ADDR.
  623. `MADDR,COUNT:...'
  624.      Write COUNT bytes at location ADDR.
  625. `cADDR'
  626.      Resume execution at the current address (or at ADDR if supplied).
  627. `sADDR'
  628.      Step the target program for one instruction, from either the
  629.      current program counter or from ADDR if supplied.
  630.      Kill the target program.
  631.      Report the most recent signal.  To allow you to take advantage of
  632.      the GDB signal handling commands, one of the functions of the
  633.      debugging stub is to report CPU traps as the corresponding POSIX
  634.      signal values.
  635.    If you have trouble with the serial connection, you can use the
  636. command `set remotedebug'.  This makes GDB report on all packets sent
  637. back and forth across the serial line to the remote machine.  The
  638. packet-debugging information is printed on the GDB standard output
  639. stream.  `set remotedebug off' turns it off, and `show remotedebug'
  640. will show you its current state.
  641. File: gdb.info,  Node: i960-Nindy Remote,  Next: EB29K Remote,  Prev: Remote Serial,  Up: Remote
  642. GDB with a Remote i960 (Nindy)
  643. ------------------------------
  644.    "Nindy" is a ROM Monitor program for Intel 960 target systems.  When
  645. GDB is configured to control a remote Intel 960 using Nindy, you can
  646. tell GDB how to connect to the 960 in several ways:
  647.    * Through command line options specifying serial port, version of the
  648.      Nindy protocol, and communications speed;
  649.    * By responding to a prompt on startup;
  650.    * By using the `target' command at any point during your GDB
  651.      session.  *Note Commands for Managing Targets: Target Commands.
  652. * Menu:
  653. * Nindy Startup::               Startup with Nindy
  654. * Nindy Options::               Options for Nindy
  655. * Nindy reset::                 Nindy Reset Command
  656. File: gdb.info,  Node: Nindy Startup,  Next: Nindy Options,  Up: i960-Nindy Remote
  657. Startup with Nindy
  658. ..................
  659.    If you simply start `gdb' without using any command-line options,
  660. you are prompted for what serial port to use, *before* you reach the
  661. ordinary GDB prompt:
  662.      Attach /dev/ttyNN -- specify NN, or "quit" to quit:
  663. Respond to the prompt with whatever suffix (after `/dev/tty')
  664. identifies the serial port you want to use.  You can, if you choose,
  665. simply start up with no Nindy connection by responding to the prompt
  666. with an empty line.  If you do this, and later wish to attach to Nindy,
  667. use `target' (*note Commands for Managing Targets: Target Commands.).
  668. File: gdb.info,  Node: Nindy Options,  Next: Nindy reset,  Prev: Nindy Startup,  Up: i960-Nindy Remote
  669. Options for Nindy
  670. .................
  671.    These are the startup options for beginning your GDB session with a
  672. Nindy-960 board attached:
  673. `-r PORT'
  674.      Specify the serial port name of a serial interface to be used to
  675.      connect to the target system.  This option is only available when
  676.      GDB is configured for the Intel 960 target architecture.  You may
  677.      specify PORT as any of: a full pathname (e.g. `-r /dev/ttya'), a
  678.      device name in `/dev' (e.g. `-r ttya'), or simply the unique
  679.      suffix for a specific `tty' (e.g. `-r a').
  680.      (An uppercase letter "O", not a zero.)  Specify that GDB should use
  681.      the "old" Nindy monitor protocol to connect to the target system.
  682.      This option is only available when GDB is configured for the Intel
  683.      960 target architecture.
  684.           *Warning:* if you specify `-O', but are actually trying to
  685.           connect to a target system that expects the newer protocol,
  686.           the connection will fail, appearing to be a speed mismatch. 
  687.           GDB will repeatedly attempt to reconnect at several different
  688.           line speeds.  You can abort this process with an interrupt.
  689. `-brk'
  690.      Specify that GDB should first send a `BREAK' signal to the target
  691.      system, in an attempt to reset it, before connecting to a Nindy
  692.      target.
  693.           *Warning:* Many target systems do not have the hardware that
  694.           this requires; it only works with a few boards.
  695.    The standard `-b' option controls the line speed used on the serial
  696. port.
  697. File: gdb.info,  Node: Nindy reset,  Prev: Nindy Options,  Up: i960-Nindy Remote
  698. Nindy Reset Command
  699. ...................
  700. `reset'
  701.      For a Nindy target, this command sends a "break" to the remote
  702.      target system; this is only useful if the target has been equipped
  703.      with a circuit to perform a hard reset (or some other interesting
  704.      action) when a break is detected.
  705. File: gdb.info,  Node: EB29K Remote,  Next: VxWorks Remote,  Prev: i960-Nindy Remote,  Up: Remote
  706. GDB with a Remote EB29K
  707. -----------------------
  708.    To use GDB from a Unix system to run programs on AMD's EB29K board
  709. in a PC, you must first connect a serial cable between the PC and a
  710. serial port on the Unix system.  In the following, we assume you've
  711. hooked the cable between the PC's `COM1' port and `/dev/ttya' on the
  712. Unix system.
  713. * Menu:
  714. * Comms (EB29K)::               Communications Setup
  715. * gdb-EB29K::                   EB29K cross-debugging
  716. * Remote Log::                  Remote Log
  717. File: gdb.info,  Node: Comms (EB29K),  Next: gdb-EB29K,  Up: EB29K Remote
  718. Communications Setup
  719. ....................
  720.    The next step is to set up the PC's port, by doing something like the
  721. following in DOS on the PC:
  722.      C:\> MODE com1:9600,n,8,1,none
  723. This example--run on an MS DOS 4.0 system--sets the PC port to 9600
  724. bps, no parity, eight data bits, one stop bit, and no "retry" action;
  725. you must match the communications parameters when establishing the Unix
  726. end of the connection as well.
  727.    To give control of the PC to the Unix side of the serial line, type
  728. the following at the DOS console:
  729.      C:\> CTTY com1
  730. (Later, if you wish to return control to the DOS console, you can use
  731. the command `CTTY con'--but you must send it over the device that had
  732. control, in our example over the `COM1' serial line).
  733.    From the Unix host, use a communications program such as `tip' or
  734. `cu' to communicate with the PC; for example,
  735.      cu -s 9600 -l /dev/ttya
  736. The `cu' options shown specify, respectively, the linespeed and the
  737. serial port to use.  If you use `tip' instead, your command line may
  738. look something like the following:
  739.      tip -9600 /dev/ttya
  740. Your system may define a different name where our example uses
  741. `/dev/ttya' as the argument to `tip'.  The communications parameters,
  742. including which port to use, are associated with the `tip' argument in
  743. the "remote" descriptions file--normally the system table `/etc/remote'.
  744.    Using the `tip' or `cu' connection, change the DOS working directory
  745. to the directory containing a copy of your 29K program, then start the
  746. PC program `EBMON' (an EB29K control program supplied with your board
  747. by AMD).  You should see an initial display from `EBMON' similar to the
  748. one that follows, ending with the `EBMON' prompt `#'--
  749.      C:\> G:
  750.      
  751.      G:\> CD \usr\joe\work29k
  752.      
  753.      G:\USR\JOE\WORK29K> EBMON
  754.      Am29000 PC Coprocessor Board Monitor, version 3.0-18
  755.      Copyright 1990 Advanced Micro Devices, Inc.
  756.      Written by Gibbons and Associates, Inc.
  757.      
  758.      Enter '?' or 'H' for help
  759.      
  760.      PC Coprocessor Type   = EB29K
  761.      I/O Base              = 0x208
  762.      Memory Base           = 0xd0000
  763.      
  764.      Data Memory Size      = 2048KB
  765.      Available I-RAM Range = 0x8000 to 0x1fffff
  766.      Available D-RAM Range = 0x80002000 to 0x801fffff
  767.      
  768.      PageSize              = 0x400
  769.      Register Stack Size   = 0x800
  770.      Memory Stack Size     = 0x1800
  771.      
  772.      CPU PRL               = 0x3
  773.      Am29027 Available     = No
  774.      Byte Write Available  = Yes
  775.      
  776.      # ~.
  777.    Then exit the `cu' or `tip' program (done in the example by typing
  778. `~.' at the `EBMON' prompt).  `EBMON' will keep running, ready for GDB
  779. to take over.
  780.    For this example, we've assumed what is probably the most convenient
  781. way to make sure the same 29K program is on both the PC and the Unix
  782. system: a PC/NFS connection that establishes "drive `G:'" on the PC as
  783. a file system on the Unix host.  If you do not have PC/NFS or something
  784. similar connecting the two systems, you must arrange some other
  785. way--perhaps floppy-disk transfer--of getting the 29K program from the
  786. Unix system to the PC; GDB will *not* download it over the serial line.
  787. File: gdb.info,  Node: gdb-EB29K,  Next: Remote Log,  Prev: Comms (EB29K),  Up: EB29K Remote
  788. EB29K cross-debugging
  789. .....................
  790.    Finally, `cd' to the directory containing an image of your 29K
  791. program on the Unix system, and start GDB--specifying as argument the
  792. name of your 29K program:
  793.      cd /usr/joe/work29k
  794.      gdb myfoo
  795.    Now you can use the `target' command:
  796.      target amd-eb /dev/ttya 9600 MYFOO
  797. In this example, we've assumed your program is in a file called
  798. `myfoo'.  Note that the filename given as the last argument to `target
  799. amd-eb' should be the name of the program as it appears to DOS. In our
  800. example this is simply `MYFOO', but in general it can include a DOS
  801. path, and depending on your transfer mechanism may not resemble the
  802. name on the Unix side.
  803.    At this point, you can set any breakpoints you wish; when you are
  804. ready to see your program run on the 29K board, use the GDB command
  805. `run'.
  806.    To stop debugging the remote program, use the GDB `detach' command.
  807.    To return control of the PC to its console, use `tip' or `cu' once
  808. again, after your GDB session has concluded, to attach to `EBMON'.  You
  809. can then type the command `q' to shut down `EBMON', returning control
  810. to the DOS command-line interpreter. Type `CTTY con' to return command
  811. input to the main DOS console, and type `~.' to leave `tip' or `cu'.
  812. File: gdb.info,  Node: Remote Log,  Prev: gdb-EB29K,  Up: EB29K Remote
  813. Remote Log
  814. ..........
  815.    The `target amd-eb' command creates a file `eb.log' in the current
  816. working directory, to help debug problems with the connection. `eb.log'
  817. records all the output from `EBMON', including echoes of the commands
  818. sent to it.  Running `tail -f' on this file in another window often
  819. helps to understand trouble with `EBMON', or unexpected events on the
  820. PC side of the connection.
  821. File: gdb.info,  Node: ST2000 Remote,  Next: Hitachi H8/300 Remote,  Prev: VxWorks Remote,  Up: Remote
  822. GDB with a Tandem ST2000
  823. ------------------------
  824.    To connect your ST2000 to the host system, see the manufacturer's
  825. manual.  Once the ST2000 is physically attached, you can run
  826.      target st2000 DEV SPEED
  827. to establish it as your debugging environment.
  828.    The `load' and `attach' commands are *not* defined for this target;
  829. you must load your program into the ST2000 as you normally would for
  830. standalone operation.  GDB will read debugging information (such as
  831. symbols) from a separate, debugging version of the program available on
  832. your host computer.
  833.    These auxiliary GDB commands are available to help you with the
  834. ST2000 environment:
  835. `st2000 COMMAND'
  836.      Send a COMMAND to the STDBUG monitor.  See the manufacturer's
  837.      manual for available commands.
  838. `connect'
  839.      Connect the controlling terminal to the STDBUG command monitor. 
  840.      When you are done interacting with STDBUG, typing either of two
  841.      character sequences will get you back to the GDB command prompt:
  842.      `RET~.' (Return, followed by tilde and period) or `RET~C-d'
  843.      (Return, followed by tilde and control-D).
  844. File: gdb.info,  Node: VxWorks Remote,  Next: ST2000 Remote,  Prev: EB29K Remote,  Up: Remote
  845. GDB and VxWorks
  846. ---------------
  847.    GDB enables developers to spawn and debug tasks running on networked
  848. VxWorks targets from a Unix host.  Already-running tasks spawned from
  849. the VxWorks shell can also be debugged.  GDB uses code that runs on
  850. both the UNIX host and on the VxWorks target.  The program `gdb' is
  851. installed and executed on the UNIX host.
  852.    The following information on connecting to VxWorks was current when
  853. this manual was produced; newer releases of VxWorks may use revised
  854. procedures.
  855.    The remote debugging interface (RDB) routines are installed and
  856. executed on the VxWorks target.  These routines are included in the
  857. VxWorks library `rdb.a' and are incorporated into the system image when
  858. source-level debugging is enabled in the VxWorks configuration.
  859.    If you wish, you can define `INCLUDE_RDB' in the VxWorks
  860. configuration file `configAll.h' to include the RDB interface routines
  861. and spawn the source debugging task `tRdbTask' when VxWorks is booted. 
  862. For more information on configuring and remaking VxWorks, see the
  863. manufacturer's manual.
  864.    Once you have included the RDB interface in your VxWorks system image
  865. and set your Unix execution search path to find GDB, you are ready to
  866. run GDB.  From your UNIX host, type:
  867.      % gdb
  868.    GDB will come up showing the prompt:
  869.      (gdb)
  870. * Menu:
  871. * VxWorks connection::          Connecting to VxWorks
  872. * VxWorks download::            VxWorks Download
  873. * VxWorks attach::              Running Tasks
  874. File: gdb.info,  Node: VxWorks connection,  Next: VxWorks download,  Up: VxWorks Remote
  875. Connecting to VxWorks
  876. .....................
  877.    The GDB command `target' lets you connect to a VxWorks target on the
  878. network.  To connect to a target whose host name is "`tt'", type:
  879.      (gdb) target vxworks tt
  880.    GDB will display a message similar to the following:
  881.      Attaching remote machine across net... Success!
  882.    GDB will then attempt to read the symbol tables of any object modules
  883. loaded into the VxWorks target since it was last booted.  GDB locates
  884. these files by searching the directories listed in the command search
  885. path (*note Your Program's Environment: Environment.); if it fails to
  886. find an object file, it will display a message such as:
  887.      prog.o: No such file or directory.
  888.    This will cause the `target' command to abort.  When this happens,
  889. you should add the appropriate directory to the search path, with the
  890. GDB command `path', and execute the `target' command again.
  891. File: gdb.info,  Node: VxWorks download,  Next: VxWorks attach,  Prev: VxWorks connection,  Up: VxWorks Remote
  892. VxWorks Download
  893. ................
  894.    If you have connected to the VxWorks target and you want to debug an
  895. object that has not yet been loaded, you can use the GDB `load' command
  896. to download a file from UNIX to VxWorks incrementally.  The object file
  897. given as an argument to the `load' command is actually opened twice:
  898. first by the VxWorks target in order to download the code, then by GDB
  899. in order to read the symbol table.  This can lead to problems if the
  900. current working directories on the two systems differ. It is simplest
  901. to set the working directory on both systems to the directory in which
  902. the object file resides, and then to reference the file by its name,
  903. without any path.  Thus, to load a program `prog.o', residing in
  904. `wherever/vw/demo/rdb', on VxWorks type:
  905.      -> cd "wherever/vw/demo/rdb"
  906.    On GDB type:
  907.      (gdb) cd wherever/vw/demo/rdb
  908.      (gdb) load prog.o
  909.    GDB will display a response similar to the following:
  910.      Reading symbol data from wherever/vw/demo/rdb/prog.o... done.
  911.    You can also use the `load' command to reload an object module after
  912. editing and recompiling the corresponding source file.  Note that this
  913. will cause GDB to delete all currently-defined breakpoints,
  914. auto-displays, and convenience variables, and to clear the value
  915. history.  (This is necessary in order to preserve the integrity of
  916. debugger data structures that reference the target system's symbol
  917. table.)
  918. File: gdb.info,  Node: VxWorks attach,  Prev: VxWorks download,  Up: VxWorks Remote
  919. Running Tasks
  920. .............
  921.    You can also attach to an existing task using the `attach' command as
  922. follows:
  923.      (gdb) attach TASK
  924. where TASK is the VxWorks hexadecimal task ID.  The task can be running
  925. or suspended when you attach to it.  If running, it will be suspended at
  926. the time of attachment.
  927.