home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / prgramer / unix / info / gdbint.i01 < prev    next >
Encoding:
GNU Info File  |  1993-06-12  |  42.2 KB  |  980 lines

  1. This is Info file gdbint.info, produced by Makeinfo-1.47 from the input
  2. file gdbint.tex.
  3.  
  4. START-INFO-DIR-ENTRY
  5. * Gdb-Internals: (gdbint).    The GNU debugger's internals.
  6. END-INFO-DIR-ENTRY
  7.  
  8.    This file documents the internals of the GNU debugger GDB.
  9.  
  10.    Copyright 1990, 1991, 1992 Free Software Foundation, Inc.
  11. Contributed by Cygnus Support.  Written by John Gilmore.
  12.  
  13.    Permission is granted to make and distribute verbatim copies of this
  14. manual provided the copyright notice and this permission notice are
  15. preserved on all copies.
  16.  
  17.    Permission is granted to copy or distribute modified versions of this
  18. manual under the terms of the GPL (for which purpose this text may be
  19. regarded as a program in the language TeX).
  20.  
  21. 
  22. File: gdbint.info,  Node: Top,  Next: README,  Prev: (DIR),  Up: (DIR)
  23.  
  24.  
  25.  
  26.    This documents the internals of the GNU debugger, GDB.  It is a
  27. collection of miscellaneous information with little form at this point.
  28. Mostly, it is a repository into which you can put information about GDB
  29. as you discover it (or as you design changes to GDB).
  30.  
  31. * Menu:
  32.  
  33. * README::            The README File
  34. * New Architectures::        Defining a New Host or Target Architecture
  35. * Config::            Adding a New Configuration
  36. * Host::            Adding a New Host
  37. * Native::            Adding a New Native Configuration
  38. * Target::            Adding a New Target
  39. * Languages::            Defining New Source Languages
  40. * Releases::            Configuring GDB for Release
  41. * Partial Symbol Tables::    How GDB reads symbols quickly at startup
  42. * BFD support for GDB::        How BFD and GDB interface
  43. * Symbol Reading::        Defining New Symbol Readers
  44. * Cleanups::            Cleanups
  45. * Wrapping::            Wrapping Output Lines
  46. * Frames::            Keeping track of function calls
  47. * Coding Style::        Strunk and White for GDB maintainers
  48. * Host Conditionals::        What features exist in the host
  49. * Target Conditionals::        What features exist in the target
  50. * Native Conditionals::        Conditionals for when host and target are same
  51. * Obsolete Conditionals::    Conditionals that don't exist any more
  52.  
  53. 
  54. File: gdbint.info,  Node: README,  Next: New Architectures,  Prev: Top,  Up: Top
  55.  
  56. The `README' File
  57. *****************
  58.  
  59.    Check the `README' file, it often has useful information that does
  60. not appear anywhere else in the directory.
  61.  
  62. 
  63. File: gdbint.info,  Node: New Architectures,  Next: Config,  Prev: README,  Up: Top
  64.  
  65. Defining a New Host or Target Architecture
  66. ******************************************
  67.  
  68.    When building support for a new host and/or target, much of the work
  69. you need to do is handled by specifying configuration files; *note
  70. Adding a New Configuration: Config..  Further work can be divided into
  71. "host-dependent" (*note Adding a New Host: Host.) and
  72. "target-dependent" (*note Adding a New Target: Target.).  The following
  73. discussion is meant to explain the difference between hosts and targets.
  74.  
  75. What is considered "host-dependent" versus "target-dependent"?
  76. ==============================================================
  77.  
  78.    "Host" refers to attributes of the system where GDB runs. "Target"
  79. refers to the system where the program being debugged executes.   In
  80. most cases they are the same machine, in which case a third type of
  81. "Native" attributes come into play.
  82.  
  83.    Defines and include files needed to build on the host are host
  84. support. Examples are tty support, system defined types, host byte
  85. order, host float format.
  86.  
  87.    Defines and information needed to handle the target format are target
  88. dependent.  Examples are the stack frame format, instruction set,
  89. breakpoint instruction, registers, and how to set up and tear down the
  90. stack to call a function.
  91.  
  92.    Information that is only needed when the host and target are the
  93. same, is native dependent.  One example is Unix child process support;
  94. if the host and target are not the same, doing a fork to start the
  95. target process is a bad idea.  The various macros needed for finding the
  96. registers in the `upage', running `ptrace', and such are all in the
  97. native-dependent files.
  98.  
  99.    Another example of native-dependent code is support for features
  100. that are really part of the target environment, but which require
  101. `#include' files that are only available on the host system. Core file
  102. handling and `setjmp' handling are two common cases.
  103.  
  104.    When you want to make GDB work "native" on a particular machine, you
  105. have to include all three kinds of information.
  106.  
  107.    The dependent information in GDB is organized into files by naming
  108. conventions.
  109.  
  110.    Host-Dependent Files
  111. `config/*.mh'
  112.      Sets Makefile parameters
  113.  
  114. `xm-*.h'
  115.      Global #include's and #define's and definitions
  116.  
  117. `*-xdep.c'
  118.      Global variables and functions
  119.  
  120.    Native-Dependent Files
  121. `config/*.mh'
  122.      Sets Makefile parameters (for *both* host and native)
  123.  
  124. `nm-*.h'
  125.      #include's and #define's and definitions.  This file is only
  126.      included by the small number of modules that need it, so beware of
  127.      doing feature-test #define's from its macros.
  128.  
  129. `*-nat.c'
  130.      global variables and functions
  131.  
  132.    Target-Dependent Files
  133. `config/*.mt'
  134.      Sets Makefile parameters
  135.  
  136. `tm-*.h'
  137.      Global #include's and #define's and definitions
  138.  
  139. `*-tdep.c'
  140.      Global variables and functions
  141.  
  142.    At this writing, most supported hosts have had their host and native
  143. dependencies sorted out properly.  There are a few stragglers, which
  144. can be recognized by the absence of NATDEPFILES lines in their
  145. `config/*.mh'.
  146.  
  147. 
  148. File: gdbint.info,  Node: Config,  Next: Host,  Prev: New Architectures,  Up: Top
  149.  
  150. Adding a New Configuration
  151. **************************
  152.  
  153.    Most of the work in making GDB compile on a new machine is in
  154. specifying the configuration of the machine.  This is done in a
  155. dizzying variety of header files and configuration scripts, which we
  156. hope to make more sensible soon.  Let's say your new host is called an
  157. XXX (e.g. `sun4'), and its full three-part configuration name is
  158. `XARCH-XVEND-XOS' (e.g.  `sparc-sun-sunos4').  In particular:
  159.  
  160.    In the top level directory, edit `config.sub' and add XARCH, XVEND,
  161. and XOS to the lists of supported architectures, vendors, and operating
  162. systems near the bottom of the file.  Also, add XXX as an alias that
  163. maps to `XARCH-XVEND-XOS'.  You can test your changes by running
  164.  
  165.      ./config.sub XXX
  166.  
  167. and
  168.      ./config.sub `XARCH-XVEND-XOS'
  169.  
  170. which should both respond with `XARCH-XVEND-XOS' and no error messages.
  171.  
  172.    Now, go to the `bfd' directory and create a new file
  173. `bfd/hosts/h-XXX.h'.  Examine the other `h-*.h' files as templates, and
  174. create one that brings in the right include files for your system, and
  175. defines any host-specific macros needed by BFD, the Binutils, GNU LD,
  176. or the Opcodes directories. (They all share the bfd `hosts' directory
  177. and the `configure.host' file.)
  178.  
  179.    Then edit `bfd/configure.host'.  Add a line to recognize your
  180. `XARCH-XVEND-XOS' configuration, and set `my_host' to XXX when you
  181. recognize it.  This will cause your file `h-XXX.h' to be linked to
  182. `sysdep.h' at configuration time.  When creating the line that
  183. recognizes your configuration, only match the fields that you really
  184. need to match; e.g. don't match match the architecture or manufacturer
  185. if the OS is sufficient to distinguish the configuration that your
  186. `h-XXX.h' file supports. Don't match the manufacturer name unless you
  187. really need to. This should make future ports easier.
  188.  
  189.    Also, if this host requires any changes to the Makefile, create a
  190. file `bfd/config/XXX.mh', which includes the required lines.
  191.  
  192.    It's possible that the `libiberty' and `readline' directories won't
  193. need any changes for your configuration, but if they do, you can change
  194. the `configure.in' file there to recognize your system and map to an
  195. `mh-XXX' file.  Then add `mh-XXX' to the `config/' subdirectory, to set
  196. any makefile variables you need.  The only current options in there are
  197. things like `-DSYSV'. (This `mh-XXX' naming convention differs from
  198. elsewhere in GDB, by historical accident.  It should be cleaned up so
  199. that all such files are called `XXX.mh'.)
  200.  
  201.    Aha!  Now to configure GDB itself!  Edit `gdb/configure.in' to
  202. recognize your system and set `gdb_host' to XXX, and (unless your
  203. desired target is already available) also set `gdb_target' to something
  204. appropriate (for instance, XXX).  To handle new hosts, modify the
  205. segment after the comment `# per-host'; to handle new targets, modify
  206. after `# per-target'.
  207.  
  208.    Finally, you'll need to specify and define GDB's host-, native-, and
  209. target-dependent `.h' and `.c' files used for your configuration; the
  210. next two chapters discuss those.
  211.  
  212. 
  213. File: gdbint.info,  Node: Host,  Next: Native,  Prev: Config,  Up: Top
  214.  
  215. Adding a New Host
  216. *****************
  217.  
  218.    Once you have specified a new configuration for your host (*note
  219. Adding a New Configuration: Config.), there are three remaining pieces
  220. to making GDB work on a new machine.  First, you have to make it host
  221. on the new machine (compile there, handle that machine's terminals
  222. properly, etc).  If you will be cross-debugging to some other kind of
  223. system that's already supported, you are done.
  224.  
  225.    If you want to use GDB to debug programs that run on the new machine,
  226. you have to get it to understand the machine's object files, symbol
  227. files, and interfaces to processes; *note Adding a New Target: Target.
  228. and *note Adding a New Native Configuration: Native.
  229.  
  230.    Several files control GDB's configuration for host systems:
  231.  
  232. `gdb/config/mh-XXX'
  233.      Specifies Makefile fragments needed when hosting on machine XXX.
  234.      In particular, this lists the required machine-dependent object
  235.      files, by defining `XDEPFILES=...'.  Also specifies the header
  236.      file which describes host XXX, by defining `XM_FILE= xm-XXX.h'. 
  237.      You can also define `CC', `REGEX' and `REGEX1', `SYSV_DEFINE',
  238.      `XM_CFLAGS', `XM_ADD_FILES', `XM_CLIBS', `XM_CDEPS', etc.; see
  239.      `Makefile.in'.
  240.  
  241. `gdb/xm-XXX.h'
  242.      (`xm.h' is a link to this file, created by configure). Contains C
  243.      macro definitions describing the host system environment, such as
  244.      byte order, host C compiler and library, ptrace support, and core
  245.      file structure.  Crib from existing `xm-*.h' files to create a new
  246.      one.
  247.  
  248. `gdb/XXX-xdep.c'
  249.      Contains any miscellaneous C code required for this machine as a
  250.      host.  On many machines it doesn't exist at all.  If it does
  251.      exist, put `XXX-xdep.o' into the `XDEPFILES' line in
  252.      `gdb/config/mh-XXX'.
  253.  
  254. Generic Host Support Files
  255. --------------------------
  256.  
  257.    There are some "generic" versions of routines that can be used by
  258. various systems.  These can be customized in various ways by macros
  259. defined in your `xm-XXX.h' file.  If these routines work for the XXX
  260. host, you can just include the generic file's name (with `.o', not
  261. `.c') in `XDEPFILES'.
  262.  
  263.    Otherwise, if your machine needs custom support routines, you will
  264. need to write routines that perform the same functions as the generic
  265. file. Put them into `XXX-xdep.c', and put `XXX-xdep.o' into `XDEPFILES'.
  266.  
  267. `ser-bsd.c'
  268.      This contains serial line support for Berkeley-derived Unix
  269.      systems.
  270.  
  271. `ser-go32.c'
  272.      This contains serial line support for 32-bit programs running
  273.      under DOS using the GO32 execution environment.
  274.  
  275. `ser-termios.c'
  276.      This contains serial line support for System V-derived Unix
  277.      systems.
  278.  
  279.    Now, you are now ready to try configuring GDB to compile using your
  280. system as its host.  From the top level (above `bfd', `gdb', etc), do:
  281.  
  282.      ./configure XXX +target=vxworks960
  283.  
  284.    This will configure your system to cross-compile for VxWorks on the
  285. Intel 960, which is probably not what you really want, but it's a test
  286. case that works at this stage.  (You haven't set up to be able to debug
  287. programs that run *on* XXX yet.)
  288.  
  289.    If this succeeds, you can try building it all with:
  290.  
  291.      make
  292.  
  293.    Repeat until the program configures, compiles, links, and runs. When
  294. run, it won't be able to do much (unless you have a VxWorks/960 board
  295. on your network) but you will know that the host support is pretty well
  296. done.
  297.  
  298.    Good luck!  Comments and suggestions about this section are
  299. particularly welcome; send them to `bug-gdb@prep.ai.mit.edu'.
  300.  
  301. 
  302. File: gdbint.info,  Node: Native,  Next: Target,  Prev: Host,  Up: Top
  303.  
  304. Adding a New Native Configuration
  305. *********************************
  306.  
  307.    If you are making GDB run native on the XXX machine, you have plenty
  308. more work to do.  Several files control GDB's configuration for native
  309. support:
  310.  
  311. `gdb/config/XXX.mh'
  312.      Specifies Makefile fragments needed when hosting *or native* on
  313.      machine XXX. In particular, this lists the required
  314.      native-dependent object files, by defining `NATDEPFILES=...'.  Also
  315.      specifies the header file which describes native support on XXX,
  316.      by defining `NM_FILE= nm-XXX.h'. You can also define `NAT_CFLAGS',
  317.      `NAT_ADD_FILES', `NAT_CLIBS', `NAT_CDEPS', etc.; see `Makefile.in'.
  318.  
  319. `gdb/nm-XXX.h'
  320.      (`nm.h' is a link to this file, created by configure). Contains C
  321.      macro definitions describing the native system environment, such
  322.      as child process control and core file support. Crib from existing
  323.      `nm-*.h' files to create a new one. Code that needs these
  324.      definitions will have to `#include "nm.h"' explicitly, since it is
  325.      not included by `defs.h'.
  326.  
  327. `gdb/XXX-nat.c'
  328.      Contains any miscellaneous C code required for this native support
  329.      of this machine.  On some machines it doesn't exist at all.
  330.  
  331. Generic Native Support Files
  332. ----------------------------
  333.  
  334.    There are some "generic" versions of routines that can be used by
  335. various systems.  These can be customized in various ways by macros
  336. defined in your `nm-XXX.h' file.  If these routines work for the XXX
  337. host, you can just include the generic file's name (with `.o', not
  338. `.c') in `NATDEPFILES'.
  339.  
  340.    Otherwise, if your machine needs custom support routines, you will
  341. need to write routines that perform the same functions as the generic
  342. file. Put them into `XXX-nat.c', and put `XXX-nat.o' into `NATDEPFILES'.
  343.  
  344. `inftarg.c'
  345.      This contains the *target_ops vector* that supports Unix child
  346.      processes on systems which use ptrace and wait to control the
  347.      child.
  348.  
  349. `procfs.c'
  350.      This contains the *target_ops vector* that supports Unix child
  351.      processes on systems which use /proc to control the child.
  352.  
  353. `fork-child.c'
  354.      This does the low-level grunge that uses Unix system calls to do a
  355.      "fork and exec" to start up a child process.
  356.  
  357. `infptrace.c'
  358.      This is the low level interface to inferior processes for systems
  359.      using the Unix `ptrace' call in a vanilla way.
  360.  
  361. `coredep.c::fetch_core_registers()'
  362.      Support for reading registers out of a core file.  This routine
  363.      calls `register_addr()', see below. Now that BFD is used to read
  364.      core files, virtually all machines should use `coredep.c', and
  365.      should just provide `fetch_core_registers' in `XXX-nat.c' (or
  366.      `REGISTER_U_ADDR' in `nm-XXX.h').
  367.  
  368. `coredep.c::register_addr()'
  369.      If your `nm-XXX.h' file defines the macro `REGISTER_U_ADDR(addr,
  370.      blockend, regno)', it should be defined to set `addr' to the
  371.      offset within the `user' struct of GDB register number `regno'. 
  372.      `blockend' is the offset within the "upage" of `u.u_ar0'. If
  373.      `REGISTER_U_ADDR' is defined, `coredep.c' will define the
  374.      `register_addr()' function and use the macro in it.  If you do not
  375.      define `REGISTER_U_ADDR', but you are using the standard
  376.      `fetch_core_registers()', you will need to define your own version
  377.      of `register_addr()', put it into your `XXX-nat.c' file, and be
  378.      sure `XXX-nat.o' is in the `NATDEPFILES' list.  If you have your
  379.      own `fetch_core_registers()', you may not need a separate
  380.      `register_addr()'.  Many custom `fetch_core_registers()'
  381.      implementations simply locate the registers themselves.
  382.  
  383.    When making GDB run native on a new operating system, to make it
  384. possible to debug core files, you will need to either write specific
  385. code for parsing your OS's core files, or customize `bfd/trad-core.c'. 
  386. First, use whatever `#include' files your machine uses to define the
  387. struct of registers that is accessible (possibly in the u-area) in a
  388. core file (rather than `machine/reg.h'), and an include file that
  389. defines whatever header exists on a core file (e.g. the u-area or a
  390. `struct core').  Then modify `trad_unix_core_file_p()' to use these
  391. values to set up the section information for the data segment, stack
  392. segment, any other segments in the core file (perhaps shared library
  393. contents or control information), "registers" segment, and if there are
  394. two discontiguous sets of registers (e.g.  integer and float), the
  395. "reg2" segment.  This section information basically delimits areas in
  396. the core file in a standard way, which the section-reading routines in
  397. BFD know how to seek around in.
  398.  
  399.    Then back in GDB, you need a matching routine called
  400. `fetch_core_registers()'.  If you can use the generic one, it's in
  401. `coredep.c'; if not, it's in your `XXX-nat.c' file. It will be passed a
  402. char pointer to the entire "registers" segment, its length, and a zero;
  403. or a char pointer to the entire "regs2" segment, its length, and a 2. 
  404. The routine should suck out the supplied register values and install
  405. them into GDB's "registers" array. (*Note Defining a New Host or Target
  406. Architecture: New Architectures, for more info about this.)
  407.  
  408.    If your system uses `/proc' to control processes, and uses ELF
  409. format core files, then you may be able to use the same routines for
  410. reading the registers out of processes and out of core files.
  411.  
  412. 
  413. File: gdbint.info,  Node: Target,  Next: Languages,  Prev: Native,  Up: Top
  414.  
  415. Adding a New Target
  416. *******************
  417.  
  418.    For a new target called TTT, first specify the configuration as
  419. described in *Note Adding a New Configuration: Config.  If your new
  420. target is the same as your new host, you've probably already done that.
  421.  
  422.    A variety of files specify attributes of the GDB target environment:
  423.  
  424. `gdb/config/TTT.mt'
  425.      Contains a Makefile fragment specific to this target. Specifies
  426.      what object files are needed for target TTT, by defining
  427.      `TDEPFILES=...'. Also specifies the header file which describes
  428.      TTT, by defining `TM_FILE= tm-TTT.h'.  You can also define
  429.      `TM_CFLAGS', `TM_CLIBS', `TM_CDEPS', and other Makefile variables
  430.      here; see `Makefile.in'.
  431.  
  432. `gdb/tm-TTT.h'
  433.      (`tm.h' is a link to this file, created by configure). Contains
  434.      macro definitions about the target machine's registers, stack
  435.      frame format and instructions. Crib from existing `tm-*.h' files
  436.      when building a new one.
  437.  
  438. `gdb/TTT-tdep.c'
  439.      Contains any miscellaneous code required for this target machine.
  440.      On some machines it doesn't exist at all.  Sometimes the macros in
  441.      `tm-TTT.h' become very complicated, so they are implemented as
  442.      functions here instead, and the macro is simply defined to call
  443.      the function.
  444.  
  445. `gdb/exec.c'
  446.      Defines functions for accessing files that are executable on the
  447.      target system.  These functions open and examine an exec file,
  448.      extract data from one, write data to one, print information about
  449.      one, etc.  Now that executable files are handled with BFD, every
  450.      target should be able to use the generic exec.c rather than its
  451.      own custom code.
  452.  
  453. `gdb/ARCH-pinsn.c'
  454.      Prints (disassembles) the target machine's instructions. This file
  455.      is usually shared with other target machines which use the same
  456.      processor, which is why it is `ARCH-pinsn.c' rather than
  457.      `TTT-pinsn.c'.
  458.  
  459. `gdb/ARCH-opcode.h'
  460.      Contains some large initialized data structures describing the
  461.      target machine's instructions. This is a bit strange for a `.h'
  462.      file, but it's OK since it is only included in one place. 
  463.      `ARCH-opcode.h' is shared between the debugger and the assembler,
  464.      if the GNU assembler has been ported to the target machine.
  465.  
  466. `gdb/tm-ARCH.h'
  467.      This often exists to describe the basic layout of the target
  468.      machine's processor chip (registers, stack, etc). If used, it is
  469.      included by `tm-XXX.h'.  It can be shared among many targets that
  470.      use the same processor.
  471.  
  472. `gdb/ARCH-tdep.c'
  473.      Similarly, there are often common subroutines that are shared by
  474.      all target machines that use this particular architecture.
  475.  
  476.    When adding support for a new target machine, there are various areas
  477. of support that might need change, or might be OK.
  478.  
  479.    If you are using an existing object file format (a.out or COFF),
  480. there is probably little to be done.  See `bfd/doc/bfd.texinfo' for
  481. more information on writing new a.out or COFF versions.
  482.  
  483.    If you need to add a new object file format, you are beyond the scope
  484. of this document right now.  Look at the structure of the a.out and
  485. COFF support, build a transfer vector (`xvec') for your new format, and
  486. start populating it with routines.  Add it to the list in
  487. `bfd/targets.c'.
  488.  
  489.    If you are adding a new operating system for an existing CPU chip,
  490. add a `tm-XOS.h' file that describes the operating system facilities
  491. that are unusual (extra symbol table info; the breakpoint instruction
  492. needed; etc).  Then write a `tm-XARCH-XOS.h' that just `#include's
  493. `tm-XARCH.h' and `tm-XOS.h'.  (Now that we have three-part
  494. configuration names, this will probably get revised to separate the XOS
  495. configuration from the XARCH configuration.)
  496.  
  497. 
  498. File: gdbint.info,  Node: Languages,  Next: Releases,  Prev: Target,  Up: Top
  499.  
  500. Adding a Source Language to GDB
  501. *******************************
  502.  
  503.    To add other languages to GDB's expression parser, follow the
  504. following steps:
  505.  
  506. *Create the expression parser.*
  507.      This should reside in a file `LANG-exp.y'.  Routines for building
  508.      parsed expressions into a `union exp_element' list are in
  509.      `parse.c'.
  510.  
  511.      Since we can't depend upon everyone having Bison, and YACC produces
  512.      parsers that define a bunch of global names, the following lines
  513.      *must* be included at the top of the YACC parser, to prevent the
  514.      various parsers from defining the same global names:
  515.  
  516.           #define yyparse     LANG_parse
  517.           #define yylex     LANG_lex
  518.           #define yyerror     LANG_error
  519.           #define yylval     LANG_lval
  520.           #define yychar     LANG_char
  521.           #define yydebug     LANG_debug
  522.           #define yypact      LANG_pact
  523.           #define yyr1        LANG_r1
  524.           #define yyr2        LANG_r2
  525.           #define yydef        LANG_def
  526.           #define yychk        LANG_chk
  527.           #define yypgo        LANG_pgo
  528.           #define yyact      LANG_act
  529.           #define yyexca      LANG_exca
  530.           #define yyerrflag      LANG_errflag
  531.           #define yynerrs      LANG_nerrs
  532.  
  533.      At the bottom of your parser, define a `struct language_defn' and
  534.      initialize it with the right values for your language.  Define an
  535.      `initialize_LANG' routine and have it call
  536.      `add_language(LANG_language_defn)' to tell the rest of GDB that
  537.      your language exists.  You'll need some other supporting variables
  538.      and functions, which will be used via pointers from your
  539.      `LANG_language_defn'.  See the declaration of `struct
  540.      language_defn' in `language.h', and the other `*-exp.y' files, for
  541.      more information.
  542.  
  543. *Add any evaluation routines, if necessary*
  544.      If you need new opcodes (that represent the operations of the
  545.      language), add them to the enumerated type in `expression.h'.  Add
  546.      support code for these operations in `eval.c:evaluate_subexp()'. 
  547.      Add cases for new opcodes in two functions from `parse.c':
  548.      `prefixify_subexp()' and `length_of_subexp()'.  These compute the
  549.      number of `exp_element's that a given operation takes up.
  550.  
  551. *Update some existing code*
  552.      Add an enumerated identifier for your language to the enumerated
  553.      type `enum language' in `defs.h'.
  554.  
  555.      Update the routines in `language.c' so your language is included. 
  556.      These routines include type predicates and such, which (in some
  557.      cases) are language dependent.  If your language does not appear
  558.      in the switch statement, an error is reported.
  559.  
  560.      Also included in `language.c' is the code that updates the variable
  561.      `current_language', and the routines that translate the
  562.      `language_LANG' enumerated identifier into a printable string.
  563.  
  564.      Update the function `_initialize_language' to include your
  565.      language.  This function picks the default language upon startup,
  566.      so is dependent upon which languages that GDB is built for.
  567.  
  568.      Update `allocate_symtab' in `symfile.c' and/or symbol-reading code
  569.      so that the language of each symtab (source file) is set properly.
  570.      This is used to determine the language to use at each stack frame
  571.      level. Currently, the language is set based upon the extension of
  572.      the source file.  If the language can be better inferred from the
  573.      symbol information, please set the language of the symtab in the
  574.      symbol-reading code.
  575.  
  576.      Add helper code to `expprint.c:print_subexp()' to handle any new
  577.      expression opcodes you have added to `expression.h'.  Also, add the
  578.      printed representations of your operators to `op_print_tab'.
  579.  
  580. *Add a place of call*
  581.      Add a call to `LANG_parse()' and `LANG_error' in
  582.      `parse.c:parse_exp_1()'.
  583.  
  584. *Use macros to trim code*
  585.      The user has the option of building GDB for some or all of the
  586.      languages.  If the user decides to build GDB for the language
  587.      LANG, then every file dependent on `language.h' will have the
  588.      macro `_LANG_LANG' defined in it.  Use `#ifdef's to leave out
  589.      large routines that the user won't need if he or she is not using
  590.      your language.
  591.  
  592.      Note that you do not need to do this in your YACC parser, since if
  593.      GDB is not build for LANG, then `LANG-exp.tab.o' (the compiled
  594.      form of your parser) is not linked into GDB at all.
  595.  
  596.      See the file `configure.in' for how GDB is configured for different
  597.      languages.
  598.  
  599. *Edit `Makefile.in'*
  600.      Add dependencies in `Makefile.in'.  Make sure you update the macro
  601.      variables such as `HFILES' and `OBJS', otherwise your code may not
  602.      get linked in, or, worse yet, it may not get `tar'red into the
  603.      distribution!
  604.  
  605. 
  606. File: gdbint.info,  Node: Releases,  Next: Partial Symbol Tables,  Prev: Languages,  Up: Top
  607.  
  608. Configuring GDB for Release
  609. ***************************
  610.  
  611.    From the top level directory (containing `gdb', `bfd', `libiberty',
  612. and so on):
  613.      make -f Makefile.in gdb.tar.Z
  614.  
  615.    This will properly configure, clean, rebuild any files that are
  616. distributed pre-built (e.g. `c-exp.tab.c' or `refcard.ps'), and will
  617. then make a tarfile.  (If the top level directory has already beenn
  618. configured, you can just do `make gdb.tar.Z' instead.)
  619.  
  620.    This procedure requires:
  621.    * symbolic links
  622.  
  623.    * `makeinfo' (texinfo2 level)
  624.  
  625.    * TeX
  626.  
  627.    * `dvips'
  628.  
  629.    * `yacc' or `bison'
  630.  
  631. ... and the usual slew of utilities (`sed', `tar', etc.).
  632.  
  633. TEMPORARY RELEASE PROCEDURE FOR DOCUMENTATION
  634. ---------------------------------------------
  635.  
  636.    `gdb.texinfo' is currently marked up using the texinfo-2 macros,
  637. which are not yet a default for anything (but we have to start using
  638. them sometime).
  639.  
  640.    For making paper, the only thing this implies is the right
  641. generation of `texinfo.tex' needs to be included in the distribution.
  642.  
  643.    For making info files, however, rather than duplicating the texinfo2
  644. distribution, generate `gdb-all.texinfo' locally, and include the files
  645. `gdb.info*' in the distribution.  Note the plural; `makeinfo' will
  646. split the document into one overall file and five or so included files.
  647.  
  648. 
  649. File: gdbint.info,  Node: Partial Symbol Tables,  Next: BFD support for GDB,  Prev: Releases,  Up: Top
  650.  
  651. Partial Symbol Tables
  652. *********************
  653.  
  654.    GDB has three types of symbol tables.
  655.  
  656.    * full symbol tables (symtabs).  These contain the main information
  657.      about symbols and addresses.
  658.  
  659.    * partial symbol tables (psymtabs).  These contain enough
  660.      information to know when to read the corresponding part of the
  661.      full symbol table.
  662.  
  663.    * minimal symbol tables (msymtabs).  These contain information
  664.      gleaned from non-debugging symbols.
  665.  
  666.    This section describes partial symbol tables.
  667.  
  668.    A psymtab is constructed by doing a very quick pass over an
  669. executable file's debugging information.  Small amounts of information
  670. are extracted -- enough to identify which parts of the symbol table will
  671. need to be re-read and fully digested later, when the user needs the
  672. information.  The speed of this pass causes GDB to start up very
  673. quickly.  Later, as the detailed rereading occurs, it occurs in small
  674. pieces, at various times, and the delay therefrom is mostly invisible to
  675. the user.  (*Note Symbol Reading::.)
  676.  
  677.    The symbols that show up in a file's psymtab should be, roughly,
  678. those visible to the debugger's user when the program is not running
  679. code from that file.  These include external symbols and types, static
  680. symbols and types, and enum values declared at file scope.
  681.  
  682.    The psymtab also contains the range of instruction addresses that the
  683. full symbol table would represent.
  684.  
  685.    The idea is that there are only two ways for the user (or much of
  686. the code in the debugger) to reference a symbol:
  687.  
  688.    * by its address (e.g. execution stops at some address which is
  689.      inside a function in this file).  The address will be noticed to
  690.      be in the range of this psymtab, and the full symtab will be read
  691.      in. `find_pc_function', `find_pc_line', and other `find_pc_...'
  692.      functions handle this.
  693.  
  694.    * by its name (e.g. the user asks to print a variable, or set a
  695.      breakpoint on a function).  Global names and file-scope names will
  696.      be found in the psymtab, which will cause the symtab to be pulled
  697.      in.  Local names will have to be qualified by a global name, or a
  698.      file-scope name, in which case we will have already read in the
  699.      symtab as we evaluated the qualifier.  Or, a local symbol can be
  700.      referenced when we are "in" a local scope, in which case the first
  701.      case applies. `lookup_symbol' does most of the work here.
  702.  
  703.    The only reason that psymtabs exist is to cause a symtab to be read
  704. in at the right moment.  Any symbol that can be elided from a psymtab,
  705. while still causing that to happen, should not appear in it.  Since
  706. psymtabs don't have the idea of scope, you can't put local symbols in
  707. them anyway.  Psymtabs don't have the idea of the type of a symbol,
  708. either, so types need not appear, unless they will be referenced by
  709. name.
  710.  
  711.    It is a bug for GDB to behave one way when only a psymtab has been
  712. read, and another way if the corresponding symtab has been read in. 
  713. Such bugs are typically caused by a psymtab that does not contain all
  714. the visible symbols, or which has the wrong instruction address ranges.
  715.  
  716.    The psymtab for a particular section of a symbol-file (objfile)
  717. could be thrown away after the symtab has been read in.  The symtab
  718. should always be searched before the psymtab, so the psymtab will never
  719. be used (in a bug-free environment).  Currently, psymtabs are allocated
  720. on an obstack, and all the psymbols themselves are allocated in a pair
  721. of large arrays on an obstack, so there is little to be gained by
  722. trying to free them unless you want to do a lot more work.
  723.  
  724. 
  725. File: gdbint.info,  Node: BFD support for GDB,  Next: Symbol Reading,  Prev: Partial Symbol Tables,  Up: Top
  726.  
  727. Binary File Descriptor Library Support for GDB
  728. **********************************************
  729.  
  730.    BFD provides support for GDB in several ways:
  731.  
  732. *identifying executable and core files*
  733.      BFD will identify a variety of file types, including a.out, coff,
  734.      and several variants thereof, as well as several kinds of core
  735.      files.
  736.  
  737. *access to sections of files*
  738.      BFD parses the file headers to determine the names, virtual
  739.      addresses, sizes, and file locations of all the various named
  740.      sections in files (such as the text section or the data section). 
  741.      GDB simply calls BFD to read or write section X at byte offset Y
  742.      for length Z.
  743.  
  744. *specialized core file support*
  745.      BFD provides routines to determine the failing command name stored
  746.      in a core file, the signal with which the program failed, and
  747.      whether a core file matches (i.e. could be a core dump of) a
  748.      particular executable file.
  749.  
  750. *locating the symbol information*
  751.      GDB uses an internal interface of BFD to determine where to find
  752.      the symbol information in an executable file or symbol-file.  GDB
  753.      itself handles the reading of symbols, since BFD does not
  754.      "understand" debug symbols, but GDB uses BFD's cached information
  755.      to find the symbols, string table, etc.
  756.  
  757. 
  758. File: gdbint.info,  Node: Symbol Reading,  Next: Cleanups,  Prev: BFD support for GDB,  Up: Top
  759.  
  760. Symbol Reading
  761. **************
  762.  
  763.    GDB reads symbols from "symbol files".  The usual symbol file is the
  764. file containing the program which gdb is debugging.  GDB can be directed
  765. to use a different file for symbols (with the "symbol-file" command),
  766. and it can also read more symbols via the "add-file" and "load"
  767. commands, or while reading symbols from shared libraries.
  768.  
  769.    Symbol files are initially opened by `symfile.c' using the BFD
  770. library.  BFD identifies the type of the file by examining its header.
  771. `symfile_init' then uses this identification to locate a set of
  772. symbol-reading functions.
  773.  
  774.    Symbol reading modules identify themselves to GDB by calling
  775. `add_symtab_fns' during their module initialization.  The argument to
  776. `add_symtab_fns' is a `struct sym_fns' which contains the name (or name
  777. prefix) of the symbol format, the length of the prefix, and pointers to
  778. four functions.  These functions are called at various times to process
  779. symbol-files whose identification matches the specified prefix.
  780.  
  781.    The functions supplied by each module are:
  782.  
  783. `XXX_symfile_init(struct sym_fns *sf)'
  784.      Called from `symbol_file_add' when we are about to read a new
  785.      symbol file.  This function should clean up any internal state
  786.      (possibly resulting from half-read previous files, for example)
  787.      and prepare to read a new symbol file. Note that the symbol file
  788.      which we are reading might be a new "main" symbol file, or might
  789.      be a secondary symbol file whose symbols are being added to the
  790.      existing symbol table.
  791.  
  792.      The argument to `XXX_symfile_init' is a newly allocated `struct
  793.      sym_fns' whose `bfd' field contains the BFD for the new symbol
  794.      file being read.  Its `private' field has been zeroed, and can be
  795.      modified as desired.  Typically, a struct of private information
  796.      will be `malloc''d, and a pointer to it will be placed in the
  797.      `private' field.
  798.  
  799.      There is no result from `XXX_symfile_init', but it can call
  800.      `error' if it detects an unavoidable problem.
  801.  
  802. `XXX_new_init()'
  803.      Called from `symbol_file_add' when discarding existing symbols.
  804.      This function need only handle the symbol-reading module's
  805.      internal state; the symbol table data structures visible to the
  806.      rest of GDB will be discarded by `symbol_file_add'.  It has no
  807.      arguments and no result. It may be called after
  808.      `XXX_symfile_init', if a new symbol table is being read, or may be
  809.      called alone if all symbols are simply being discarded.
  810.  
  811. `XXX_symfile_read(struct sym_fns *sf, CORE_ADDR addr, int mainline)'
  812.      Called from `symbol_file_add' to actually read the symbols from a
  813.      symbol-file into a set of psymtabs or symtabs.
  814.  
  815.      `sf' points to the struct sym_fns originally passed to
  816.      `XXX_sym_init' for possible initialization.  `addr' is the offset
  817.      between the file's specified start address and its true address in
  818.      memory.  `mainline' is 1 if this is the main symbol table being
  819.      read, and 0 if a secondary symbol file (e.g. shared library or
  820.      dynamically loaded file) is being read.
  821.  
  822.    In addition, if a symbol-reading module creates psymtabs when
  823. XXX_symfile_read is called, these psymtabs will contain a pointer to a
  824. function `XXX_psymtab_to_symtab', which can be called from any point in
  825. the GDB symbol-handling code.
  826.  
  827. `XXX_psymtab_to_symtab (struct partial_symtab *pst)'
  828.      Called from `psymtab_to_symtab' (or the PSYMTAB_TO_SYMTAB macro)
  829.      if the psymtab has not already been read in and had its
  830.      `pst->symtab' pointer set.  The argument is the psymtab to be
  831.      fleshed-out into a symtab.  Upon return, pst->readin should have
  832.      been set to 1, and pst->symtab should contain a pointer to the new
  833.      corresponding symtab, or zero if there were no symbols in that
  834.      part of the symbol file.
  835.  
  836. 
  837. File: gdbint.info,  Node: Cleanups,  Next: Wrapping,  Prev: Symbol Reading,  Up: Top
  838.  
  839. Cleanups
  840. ********
  841.  
  842.    Cleanups are a structured way to deal with things that need to be
  843. done later.  When your code does something (like `malloc' some memory,
  844. or open a file) that needs to be undone later (e.g. free the memory or
  845. close the file), it can make a cleanup.  The cleanup will be done at
  846. some future point:  when the command is finished, when an error occurs,
  847. or when your code decides it's time to do cleanups.
  848.  
  849.    You can also discard cleanups, that is, throw them away without doing
  850. what they say.  This is only done if you ask that it be done.
  851.  
  852.    Syntax:
  853.  
  854. `OLD_CHAIN = make_cleanup (FUNCTION, ARG);'
  855.      Make a cleanup which will cause FUNCTION to be called with ARG (a
  856.      `char *') later.  The result, OLD_CHAIN, is a handle that can be
  857.      passed to `do_cleanups' or `discard_cleanups' later.  Unless you
  858.      are going to call `do_cleanups' or `discard_cleanups' yourself,
  859.      you can ignore the result from `make_cleanup'.
  860.  
  861. `do_cleanups (OLD_CHAIN);'
  862.      Perform all cleanups done since `make_cleanup' returned OLD_CHAIN.
  863.      E.g.:
  864.           make_cleanup (a, 0);
  865.           old = make_cleanup (b, 0);
  866.           do_cleanups (old);
  867.  
  868.      will call `b()' but will not call `a()'.  The cleanup that calls
  869.      `a()' will remain in the cleanup chain, and will be done later
  870.      unless otherwise discarded.
  871.  
  872. `discard_cleanups (OLD_CHAIN);'
  873.      Same as `do_cleanups' except that it just removes the cleanups
  874.      from the chain and does not call the specified functions.
  875.  
  876.    Some functions, e.g. `fputs_filtered()' or `error()', specify that
  877. they "should not be called when cleanups are not in place".  This means
  878. that any actions you need to reverse in the case of an error or
  879. interruption must be on the cleanup chain before you call these
  880. functions, since they might never return to your code (they `longjmp'
  881. instead).
  882.  
  883. 
  884. File: gdbint.info,  Node: Wrapping,  Next: Frames,  Prev: Cleanups,  Up: Top
  885.  
  886. Wrapping Output Lines
  887. *********************
  888.  
  889.    Output that goes through `printf_filtered' or `fputs_filtered' or
  890. `fputs_demangled' needs only to have calls to `wrap_here' added in
  891. places that would be good breaking points.  The utility routines will
  892. take care of actually wrapping if the line width is exceeded.
  893.  
  894.    The argument to `wrap_here' is an indentation string which is printed
  895. *only* if the line breaks there.  This argument is saved away and used
  896. later.  It must remain valid until the next call to `wrap_here' or
  897. until a newline has been printed through the `*_filtered' functions.
  898. Don't pass in a local variable and then return!
  899.  
  900.    It is usually best to call `wrap_here()' after printing a comma or
  901. space. If you call it before printing a space, make sure that your
  902. indentation properly accounts for the leading space that will print if
  903. the line wraps there.
  904.  
  905.    Any function or set of functions that produce filtered output must
  906. finish by printing a newline, to flush the wrap buffer, before
  907. switching to unfiltered ("`printf'") output.  Symbol reading routines
  908. that print warnings are a good example.
  909.  
  910. 
  911. File: gdbint.info,  Node: Frames,  Next: Coding Style,  Prev: Wrapping,  Up: Top
  912.  
  913. Frames
  914. ******
  915.  
  916.    A frame is a construct that GDB uses to keep track of calling and
  917. called functions.
  918.  
  919. `FRAME_FP'
  920.      in the machine description has no meaning to the
  921.      machine-independent part of GDB, except that it is used when
  922.      setting up a new frame from scratch, as follows:
  923.  
  924.                 create_new_frame (read_register (FP_REGNUM), read_pc ()));
  925.  
  926.      Other than that, all the meaning imparted to `FP_REGNUM' is
  927.      imparted by the machine-dependent code.  So, `FP_REGNUM' can have
  928.      any value that is convenient for the code that creates new frames.
  929.       (`create_new_frame' calls `INIT_EXTRA_FRAME_INFO' if it is
  930.      defined; that is where you should use the `FP_REGNUM' value, if
  931.      your frames are nonstandard.)
  932.  
  933. `FRAME_CHAIN'
  934.      Given a GDB frame, determine the address of the calling function's
  935.      frame.  This will be used to create a new GDB frame struct, and
  936.      then `INIT_EXTRA_FRAME_INFO' and `INIT_FRAME_PC' will be called for
  937.      the new frame.
  938.  
  939. 
  940. File: gdbint.info,  Node: Coding Style,  Next: Host Conditionals,  Prev: Frames,  Up: Top
  941.  
  942. Coding Style
  943. ************
  944.  
  945.    GDB is generally written using the GNU coding standards, as
  946. described in `standards.texi', which you can get from the Free Software
  947. Foundation.  There are some additional considerations for GDB
  948. maintainers that reflect the unique environment and style of GDB
  949. maintenance. If you follow these guidelines, GDB will be more
  950. consistent and easier to maintain.
  951.  
  952.    GDB's policy on the use of prototypes is that prototypes are used to
  953. *declare* functions but never to *define* them.  Simple macros are used
  954. in the declarations, so that a non-ANSI compiler can compile GDB
  955. without trouble.  The simple macro calls are used like this:
  956.  
  957.      extern int
  958.      memory_remove_breakpoint PARAMS ((CORE_ADDR, char *));
  959.  
  960.    Note the double parentheses around the parameter types.  This allows
  961. an arbitrary number of parameters to be described, without freaking out
  962. the C preprocessor.  When the function has no parameters, it should be
  963. described like:
  964.  
  965.      void
  966.      noprocess PARAMS ((void));
  967.  
  968.    The `PARAMS' macro expands to its argument in ANSI C, or to a simple
  969. `()' in traditional C.
  970.  
  971.    All external functions should have a `PARAMS' declaration in a
  972. header file that callers include.  All static functions should have such
  973. a declaration near the top of their source file.
  974.  
  975.    We don't have a gcc option that will properly check that these rules
  976. have been followed, but it's GDB policy, and we periodically check it
  977. using the tools available (plus manual labor), and clean up any
  978. remnants.
  979.  
  980.