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

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