* doc/gdbint.texinfo (Host Conditionals): Remove
[deliverable/binutils-gdb.git] / gdb / doc / gdbint.texinfo
index c3188b0fc49844652e4dc055b1e827d8650f9f95..6e111c6ceb90882f4f569d93121e9eaa5333d714 100644 (file)
@@ -5,7 +5,7 @@
 @ifinfo
 @format
 START-INFO-DIR-ENTRY
-* Gdb-Internals: (gdbint).     The GNU debugger internals.
+* Gdb-Internals: (gdbint).     The GNU debugger's internals.
 END-INFO-DIR-ENTRY
 @end format
 @end ifinfo
@@ -13,7 +13,7 @@ END-INFO-DIR-ENTRY
 @ifinfo
 This file documents the internals of the GNU debugger GDB.
 
-Copyright (C) 1990, 1991, 1992 Free Software Foundation, Inc.
+Copyright 1990, 1991, 1992 Free Software Foundation, Inc.
 Contributed by Cygnus Support.  Written by John Gilmore.
 
 Permission is granted to make and distribute verbatim copies of
@@ -59,9 +59,9 @@ are preserved on all copies.
 
 @end titlepage
 
-@node Top, README, (dir), (dir)
-
-This file documents the internals of the GNU debugger GDB.  It is a
+@node Top
+@top
+This documents the internals of the GNU debugger, GDB.  It is a
 collection of miscellaneous information with little form at this point.
 Mostly, it is a repository into which you can put information about
 GDB as you discover it (or as you design changes to GDB).
@@ -71,6 +71,7 @@ GDB as you discover it (or as you design changes to GDB).
 * New Architectures::          Defining a New Host or Target Architecture
 * Config::                     Adding a New Configuration
 * Host::                       Adding a New Host
+* Native::                     Adding a New Native Configuration
 * Target::                     Adding a New Target
 * Languages::                  Defining New Source Languages
 * Releases::                   Configuring GDB for Release
@@ -80,21 +81,25 @@ GDB as you discover it (or as you design changes to GDB).
 * Cleanups::                   Cleanups
 * Wrapping::                   Wrapping Output Lines
 * Frames::                     Keeping track of function calls
+* Remote Stubs::               Code that runs in targets and talks to GDB
 * Coding Style::               Strunk and White for GDB maintainers
-* Host Conditionals::          Controlling what features exist in the host
-* Target Conditionals::                Controlling what features exist in the target
-* Native Conditionals::                Native Conditionals
+* Clean Design::               Frank Lloyd Wright for GDB maintainers
+* Submitting Patches::         How to get your changes into GDB releases
+* Host Conditionals::          What features exist in the host
+* Target Conditionals::                What features exist in the target
+* Native Conditionals::                Conditionals for when host and target are same
+* Obsolete Conditionals::      Conditionals that don't exist any more
 
 @end menu
 
-@node README, New Architectures, Top, Top
+@node README
 @chapter The @file{README} File
 
 Check the @file{README} file, it often has useful information that does not
 appear anywhere else in the directory.
 
 
-@node New Architectures, Config, README, Top
+@node New Architectures
 @chapter Defining a New Host or Target Architecture
 
 When building support for a new host and/or target, much of the work you
@@ -109,36 +114,74 @@ and targets.
 
 @dfn{Host} refers to attributes of the system where GDB runs.
 @dfn{Target} refers to the system where the program being debugged
-executes.   In most cases they are the same machine; unfortunately, that
-means you must add @emph{both} host and target support for new machines
-in this category.
-
-The @file{config/mh-*}, @file{xm-*.h} and @file{*-xdep.c} files are for
-host support.  Similarly, the @file{config/mt-*}, @file{tm-*.h} and
-@file{*-tdep.c} files are for target support.  The question is, what
-features or aspects of a debugging or cross-debugging environment are
-considered to be ``host'' support?
+executes.   In most cases they are the same machine, in which case
+a third type of @dfn{Native} attributes come into play.
 
 Defines and include files needed to build on the host are host support.
 Examples are tty support, system defined types, host byte order, host
 float format.
 
-Unix child process support is considered an aspect of the host.  Since
-when you fork on the host you are still on the host, the various macros
-needed for finding the registers in the upage, running @code{ptrace}, and such
-are all in the host-dependent files.
+Defines and information needed to handle the target format are target
+dependent.  Examples are the stack frame format, instruction set,
+breakpoint instruction, registers, and how to set up and tear down the stack
+to call a function.
+
+Information that is only needed when the host and target are the same,
+is native dependent.  One example is Unix child process support; if the
+host and target are not the same, doing a fork to start the target
+process is a bad idea.  The various macros needed for finding the
+registers in the @code{upage}, running @code{ptrace}, and such are all in the
+native-dependent files.
+
+Another example of native-dependent code is support for features
+that are really part of the target environment, but which require 
+@code{#include} files that are only available on the host system.
+Core file handling and @code{setjmp} handling are two common cases.
 
-@c FIXME so what kinds of things are target support?
+When you want to make GDB work ``native'' on a particular
+machine, you have to include all three kinds of information.
 
-This is still somewhat of a grey area; I (John Gilmore) didn't do the
-@file{xm-*} and @file{tm-*} split for gdb (it was done by Jim Kingdon)
-so I have had to figure out the grounds on which it was split, and make
-my own choices as I evolve it.  I have moved many things out of the xdep
-files actually, partly as a result of BFD and partly by removing
-duplicated code.
+The dependent information in GDB is organized into files by naming
+conventions.  
+
+Host-Dependent Files
+@table @file
+@item  config/*.mh
+Sets Makefile parameters
+@item  xm-*.h
+Global #include's and #define's and definitions
+@item  *-xdep.c
+Global variables and functions
+@end table
+
+Native-Dependent Files
+@table @file
+@item  config/*.mh
+Sets Makefile parameters (for @emph{both} host and native)
+@item  nm-*.h
+#include's and #define's and definitions.  This file
+is only included by the small number of modules that need it,
+so beware of doing feature-test #define's from its macros.
+@item  *-nat.c
+global variables and functions
+@end table
+
+Target-Dependent Files
+@table @file
+@item  config/*.mt
+Sets Makefile parameters
+@item  tm-*.h
+Global #include's and #define's and definitions
+@item  *-tdep.c
+Global variables and functions
+@end table
 
+At this writing, most supported hosts have had their host and native
+dependencies sorted out properly.  There are a few stragglers, which
+can be recognized by the absence of NATDEPFILES lines in their
+@file{config/*.mh}.
 
-@node Config, Host, New Architectures, Top
+@node Config
 @chapter Adding a New Configuration
 
 Most of the work in making GDB compile on a new machine is in specifying
@@ -172,21 +215,23 @@ Now, go to the @file{bfd} directory and
 create a new file @file{bfd/hosts/h-@var{xxx}.h}.  Examine the
 other @file{h-*.h} files as templates, and create one that brings in the
 right include files for your system, and defines any host-specific
-macros needed by GDB.
+macros needed by BFD, the Binutils, GNU LD, or the Opcodes directories.
+(They all share the bfd @file{hosts} directory and the @file{configure.host}
+file.)
 
-Then edit @file{bfd/configure.in}.  Add shell script code to recognize your
+Then edit @file{bfd/configure.host}.  Add a line to recognize your
 @code{@var{xarch}-@var{xvend}-@var{xos}} configuration, and set
 @code{my_host} to @var{xxx} when you recognize it.  This will cause your
 file @file{h-@var{xxx}.h} to be linked to @file{sysdep.h} at configuration
-time.
+time.  When creating the line that recognizes your configuration,
+only match the fields that you really need to match; e.g. don't match
+match the architecture or manufacturer if the OS is sufficient
+to distinguish the configuration that your @file{h-@var{xxx}.h} file supports.
+Don't match the manufacturer name unless you really need to.
+This should make future ports easier.
 
 Also, if this host requires any changes to the Makefile, create a file
-@file{bfd/config/mh-@var{xxx}}, which includes the required lines.
-
-(If you have the binary utilities and/or GNU ld in the same tree,
-you'll also have to edit @file{binutils/configure.in} or
-@file{ld/configure.in} to match what you've done in the @file{bfd}
-directory.)
+@file{bfd/config/@var{xxx}.mh}, which includes the required lines.
 
 It's possible that the @file{libiberty} and @file{readline} directories
 won't need any changes for your configuration, but if they do, you can
@@ -194,6 +239,9 @@ change the @file{configure.in} file there to recognize your system and
 map to an @file{mh-@var{xxx}} file.  Then add @file{mh-@var{xxx}}
 to the @file{config/} subdirectory, to set any makefile variables you
 need.  The only current options in there are things like @samp{-DSYSV}.
+(This @file{mh-@var{xxx}} naming convention differs from elsewhere
+in GDB, by historical accident.  It should be cleaned up so that all
+such files are called @file{@var{xxx}.mh}.)
 
 Aha!  Now to configure GDB itself!  Edit
 @file{gdb/configure.in} to recognize your system and set @code{gdb_host}
@@ -205,16 +253,16 @@ per-target}.
 @c Would it be simpler to just use different per-host and per-target
 @c *scripts*, and call them from {configure} ?
 
-Finally, you'll need to specify and define GDB's host- and
+Finally, you'll need to specify and define GDB's host-, native-, and
 target-dependent @file{.h} and @file{.c} files used for your
 configuration; the next two chapters discuss those.
 
 
-@node Host, Target, Config, Top
+@node Host
 @chapter Adding a New Host
 
 Once you have specified a new configuration for your host
-(@pxref{Config,,Adding a New Configuration}), there are two remaining
+(@pxref{Config,,Adding a New Configuration}), there are three remaining
 pieces to making GDB work on a new machine.  First, you have to make it
 host on the new machine (compile there, handle that machine's terminals
 properly, etc).  If you will be cross-debugging to some other kind of
@@ -222,7 +270,8 @@ system that's already supported, you are done.
 
 If you want to use GDB to debug programs that run on the new machine,
 you have to get it to understand the machine's object files, symbol
-files, and interfaces to processes.  @pxref{Target,,Adding a New Target}
+files, and interfaces to processes; @pxref{Target,,Adding a New Target}
+and @pxref{Native,,Adding a New Native Configuration}
 
 Several files control GDB's configuration for host systems:
 
@@ -246,11 +295,15 @@ to create a new one.
 
 @item gdb/@var{xxx}-xdep.c
 Contains any miscellaneous C code required for this machine
-as a host.  On some machines it doesn't exist at all.
+as a host.  On many machines it doesn't exist at all.  If it does
+exist, put @file{@var{xxx}-xdep.o} into the @code{XDEPFILES} line
+in @file{gdb/config/mh-@var{xxx}}.
 @end table
 
+@subheading Generic Host Support Files
+
 There are some ``generic'' versions of routines that can be used by
-various host systems.  These can be customized in various ways by macros
+various systems.  These can be customized in various ways by macros
 defined in your @file{xm-@var{xxx}.h} file.  If these routines work for
 the @var{xxx} host, you can just include the generic file's name (with
 @samp{.o}, not @samp{.c}) in @code{XDEPFILES}.  
@@ -258,12 +311,103 @@ the @var{xxx} host, you can just include the generic file's name (with
 Otherwise, if your machine needs custom support routines, you will need
 to write routines that perform the same functions as the generic file.
 Put them into @code{@var{xxx}-xdep.c}, and put @code{@var{xxx}-xdep.o}
-into @code{XDEPFILES}.  
+into @code{XDEPFILES}.
 
-@subheading Generic Host Support Files
+@table @file
+@item ser-bsd.c
+This contains serial line support for Berkeley-derived Unix systems.
+
+@item ser-go32.c
+This contains serial line support for 32-bit programs running under DOS
+using the GO32 execution environment.
+
+@item ser-termios.c
+This contains serial line support for System V-derived Unix systems.
+@end table
+
+Now, you are now ready to try configuring GDB to compile using your system
+as its host.  From the top level (above @file{bfd}, @file{gdb}, etc), do:
+
+@example
+./configure @var{xxx} +target=vxworks960
+@end example
+
+This will configure your system to cross-compile for VxWorks on
+the Intel 960, which is probably not what you really want, but it's
+a test case that works at this stage.  (You haven't set up to be
+able to debug programs that run @emph{on} @var{xxx} yet.)
+
+If this succeeds, you can try building it all with:
+
+@example
+make
+@end example
+
+Repeat until the program configures, compiles, links, and runs.
+When run, it won't be able to do much (unless you have a VxWorks/960
+board on your network) but you will know that the host support is
+pretty well done.
+
+Good luck!  Comments and suggestions about this section are particularly
+welcome; send them to @samp{bug-gdb@@prep.ai.mit.edu}.
+
+@node Native
+@chapter Adding a New Native Configuration
+
+If you are making GDB run native on the @var{xxx} machine, you have
+plenty more work to do.  Several files control GDB's configuration for
+native support:
+
+@table @file
+@item gdb/config/@var{xxx}.mh
+Specifies Makefile fragments needed when hosting @emph{or native}
+on machine @var{xxx}.
+In particular, this lists the required native-dependent object files,
+by defining @samp{NATDEPFILES=@dots{}}.  Also
+specifies the header file which describes native support on @var{xxx},
+by defining @samp{NM_FILE= nm-@var{xxx}.h}.
+You can also define @samp{NAT_CFLAGS},
+@samp{NAT_ADD_FILES}, @samp{NAT_CLIBS}, @samp{NAT_CDEPS},
+etc.; see @file{Makefile.in}.
+
+@item gdb/nm-@var{xxx}.h
+(@file{nm.h} is a link to this file, created by configure).
+Contains C macro definitions describing the native system environment,
+such as child process control and core file support.
+Crib from existing @file{nm-*.h} files to create a new one.
+
+@item gdb/@var{xxx}-nat.c
+Contains any miscellaneous C code required for this native support
+of this machine.  On some machines it doesn't exist at all.
+@end table
+
+@subheading Generic Native Support Files
+
+There are some ``generic'' versions of routines that can be used by
+various systems.  These can be customized in various ways by macros
+defined in your @file{nm-@var{xxx}.h} file.  If these routines work for
+the @var{xxx} host, you can just include the generic file's name (with
+@samp{.o}, not @samp{.c}) in @code{NATDEPFILES}.  
+
+Otherwise, if your machine needs custom support routines, you will need
+to write routines that perform the same functions as the generic file.
+Put them into @code{@var{xxx}-nat.c}, and put @code{@var{xxx}-nat.o}
+into @code{NATDEPFILES}.  
 
 @table @file
 
+@item inftarg.c
+This contains the @emph{target_ops vector} that supports Unix child
+processes on systems which use ptrace and wait to control the child.
+
+@item procfs.c
+This contains the @emph{target_ops vector} that supports Unix child
+processes on systems which use /proc to control the child.
+
+@item fork-child.c
+This does the low-level grunge that uses Unix system calls
+to do a "fork and exec" to start up a child process.
+
 @item infptrace.c
 This is the low level interface to inferior processes for systems
 using the Unix @code{ptrace} call in a vanilla way.
@@ -273,10 +417,10 @@ Support for reading registers out of a core file.  This routine calls
 @code{register_addr()}, see below.
 Now that BFD is used to read core files, virtually all machines should
 use @code{coredep.c}, and should just provide @code{fetch_core_registers} in
-@code{@var{xxx}-xdep.c} (or @code{REGISTER_U_ADDR} in @code{xm-@var{xxx}.h}).
+@code{@var{xxx}-nat.c} (or @code{REGISTER_U_ADDR} in @code{nm-@var{xxx}.h}).
 
 @item coredep.c::register_addr()
-If your @code{xm-@var{xxx}.h} file defines the macro
+If your @code{nm-@var{xxx}.h} file defines the macro
 @code{REGISTER_U_ADDR(addr, blockend, regno)}, it should be defined to
 set @code{addr} to the offset within the @samp{user}
 struct of GDB register number @code{regno}.  @code{blockend} is the
@@ -286,43 +430,15 @@ If @code{REGISTER_U_ADDR} is defined,
 the macro in it.  If you do not define @code{REGISTER_U_ADDR}, but you
 are using the standard @code{fetch_core_registers()}, you will need to
 define your own version of @code{register_addr()}, put it into your
-@code{@var{xxx}-xdep.c} file, and be sure @code{@var{xxx}-xdep.o} is in
-the @code{XDEPFILES} list.  If you have your own
+@code{@var{xxx}-nat.c} file, and be sure @code{@var{xxx}-nat.o} is in
+the @code{NATDEPFILES} list.  If you have your own
 @code{fetch_core_registers()}, you may not need a separate
 @code{register_addr()}.  Many custom @code{fetch_core_registers()}
 implementations simply locate the registers themselves.@refill
 @end table
 
-Object files needed when the target system is an @var{xxx} are listed
-in the file @file{config/mt-@var{xxx}}, in the makefile macro
-@samp{TDEPFILES = }@dots{}.  The header file that defines the target
-system should be called @file{tm-@var{xxx}.h}, and should be specified
-as the value of @samp{TM_FILE} in @file{config/mt-@var{xxx}}.  You can
-also define @samp{TM_CFLAGS}, @samp{TM_CLIBS}, and @samp{TM_CDEPS} in
-there; see @file{Makefile.in}.
-
-Now, you are now ready to try configuring GDB to compile for your system.
-From the top level (above @file{bfd}, @file{gdb}, etc), do:
-
-@example
-./configure @var{xxx} +target=vxworks960
-@end example
-
-This will configure your system to cross-compile for VxWorks on
-the Intel 960, which is probably not what you really want, but it's
-a test case that works at this stage.  (You haven't set up to be
-able to debug programs that run @emph{on} @var{xxx} yet.)
-
-If this succeeds, you can try building it all with:
-
-@example
-make
-@end example
-
-Good luck!  Comments and suggestions about this section are particularly
-welcome; send them to @samp{bug-gdb@@prep.ai.mit.edu}.
-
-When hosting GDB on a new operating system, to make it possible to debug
+When making GDB run native on a new operating system,
+to make it possible to debug
 core files, you will need to either write specific code for parsing your
 OS's core files, or customize @file{bfd/trad-core.c}.  First, use
 whatever @code{#include} files your machine uses to define the struct of
@@ -340,7 +456,7 @@ around in.
 
 Then back in GDB, you need a matching routine called
 @code{fetch_core_registers()}.  If you can use the generic one, it's in
-@file{core-dep.c}; if not, it's in your @file{@var{xxx}-xdep.c} file.
+@file{coredep.c}; if not, it's in your @file{@var{xxx}-nat.c} file.
 It will be passed a char pointer to the entire ``registers'' segment,
 its length, and a zero; or a char pointer to the entire ``regs2''
 segment, its length, and a 2.  The routine should suck out the supplied
@@ -348,8 +464,11 @@ register values and install them into GDB's ``registers'' array.
 (@xref{New Architectures,,Defining a New Host or Target Architecture},
 for more info about this.)
 
+If your system uses @file{/proc} to control processes, and uses ELF
+format core files, then you may be able to use the same routines
+for reading the registers out of processes and out of core files.
 
-@node Target, Languages, Host, Top
+@node Target
 @chapter Adding a New Target
 
 For a new target called @var{ttt}, first specify the configuration as
@@ -359,12 +478,13 @@ target is the same as your new host, you've probably already done that.
 A variety of files specify attributes of the GDB target environment:
 
 @table @file
-@item gdb/config/mt-@var{ttt}
+@item gdb/config/@var{ttt}.mt
 Contains a Makefile fragment specific to this target.
 Specifies what object files are needed for target @var{ttt}, by
 defining @samp{TDEPFILES=@dots{}}.
 Also specifies the header file which describes @var{ttt}, by defining
 @samp{TM_FILE= tm-@var{ttt}.h}.  You can also define @samp{TM_CFLAGS},
+@samp{TM_CLIBS}, @samp{TM_CDEPS},
 and other Makefile variables here; see @file{Makefile.in}.
 
 @item gdb/tm-@var{ttt}.h
@@ -437,7 +557,7 @@ separate the @var{xos} configuration from the @var{xarch}
 configuration.)
 
 
-@node Languages, Releases, Target, Top
+@node Languages
 @chapter Adding a Source Language to GDB
 
 To add other languages to GDB's expression parser, follow the following steps:
@@ -552,7 +672,7 @@ distribution!
 @end table
 
 
-@node Releases, Partial Symbol Tables, Languages, Top
+@node Releases
 @chapter Configuring GDB for Release
 
 From the top level directory (containing @file{gdb}, @file{bfd},
@@ -592,7 +712,7 @@ distribution, generate @file{gdb-all.texinfo} locally, and include the files
 split the document into one overall file and five or so included files.
 
 
-@node Partial Symbol Tables, BFD support for GDB, Releases, Top
+@node Partial Symbol Tables
 @chapter Partial Symbol Tables
 
 GDB has three types of symbol tables.
@@ -672,7 +792,7 @@ are allocated in a pair of large arrays on an obstack, so there is
 little to be gained by trying to free them unless you want to do a lot
 more work.
 
-@node BFD support for GDB, Symbol Reading, Partial Symbol Tables, Top
+@node BFD support for GDB
 @chapter Binary File Descriptor Library Support for GDB
 
 BFD provides support for GDB in several ways:
@@ -706,7 +826,7 @@ string table, etc.
 @c Reading,,Symbol Reading}.
 
 
-@node Symbol Reading, Cleanups, BFD support for GDB, Top
+@node Symbol Reading
 @chapter Symbol Reading
 
 GDB reads symbols from "symbol files".  The usual symbol file is the
@@ -793,7 +913,7 @@ were no symbols in that part of the symbol file.
 @end table
 
 
-@node Cleanups, Wrapping, Symbol Reading, Top
+@node Cleanups
 @chapter Cleanups
 
 Cleanups are a structured way to deal with things that need to be done
@@ -809,6 +929,9 @@ what they say.  This is only done if you ask that it be done.
 Syntax:
 
 @table @code
+@item struct cleanup *@var{old_chain};
+Declare a variable which will hold a cleanup chain handle.
+
 @item @var{old_chain} = make_cleanup (@var{function}, @var{arg});
 Make a cleanup which will cause @var{function} to be called with @var{arg}
 (a @code{char *}) later.  The result, @var{old_chain}, is a handle that can be
@@ -842,7 +965,7 @@ interruption must be on the cleanup chain before you call these functions,
 since they might never return to your code (they @samp{longjmp} instead).
 
 
-@node Wrapping, Frames, Cleanups, Top
+@node Wrapping
 @chapter Wrapping Output Lines
 
 Output that goes through @code{printf_filtered} or @code{fputs_filtered} or
@@ -867,7 +990,7 @@ unfiltered (``@code{printf}'') output.  Symbol reading routines that print
 warnings are a good example.
 
 
-@node Frames, Coding Style, Wrapping, Top
+@node Frames
 @chapter Frames
 
 A frame is a construct that GDB uses to keep track of calling and called
@@ -896,7 +1019,48 @@ frame.  This will be used to create a new GDB frame struct, and then
 the new frame.
 @end table
 
-@node Coding Style, Host Conditionals, Frames, Top
+@node Remote Stubs
+@chapter Remote Stubs
+
+GDB's file @file{remote.c} talks a serial protocol to code that runs
+in the target system.  GDB provides several sample ``stubs'' that can
+be integrated into target programs or operating systems for this purpose;
+they are named @file{*-stub.c}.
+
+The GDB user's manual describes how to put such a stub into your target
+code.  What follows is a discussion of integrating the SPARC stub
+into a complicated operating system (rather than a simple program),
+by Stu Grossman, the author of this stub.
+
+The trap handling code in the stub assumes the following upon entry to
+trap_low:
+
+@enumerate
+@item %l1 and %l2 contain pc and npc respectively at the time of the trap
+@item traps are disabled
+@item you are in the correct trap window
+@end enumerate
+
+As long as your trap handler can guarantee those conditions, then there is no
+reason why you shouldn't be able to `share' traps with the stub.  The stub has
+no requirement that it be jumped to directly from the hardware trap vector.
+That is why it calls @code{exceptionHandler()}, which is provided by the external
+environment.  For instance, this could setup the hardware traps to actually
+execute code which calls the stub first, and then transfers to its own trap
+handler.
+
+For the most point, there probably won't be much of an issue with `sharing'
+traps, as the traps we use are usually not used by the kernel, and often
+indicate unrecoverable error conditions.  Anyway, this is all controlled by a
+table, and is trivial to modify.
+The most important trap for us is for @code{ta 1}.  Without that, we
+can't single step or do breakpoints.  Everything else is unnecessary
+for the proper operation of the debugger/stub.
+
+From reading the stub, it's probably not obvious how breakpoints work.  They
+are simply done by deposit/examine operations from GDB.
+
+@node Coding Style
 @chapter Coding Style
 
 GDB is generally written using the GNU coding standards, as described in
@@ -938,7 +1102,152 @@ We don't have a gcc option that will properly check that these rules
 have been followed, but it's GDB policy, and we periodically check it
 using the tools available (plus manual labor), and clean up any remnants.
 
-@node Host Conditionals, Target Conditionals, Coding Style, Top
+@node Clean Design
+@chapter Clean Design
+
+In addition to getting the syntax right, there's the little question of
+semantics.  Some things are done in certain ways in GDB because long
+experience has shown that the more obvious ways caused various kinds of
+trouble.  In particular:
+
+@table @bullet
+@item
+You can't assume the byte order of anything that comes from a
+target (including @var{value}s, object files, and instructions).  Such
+things must be byte-swapped using @code{SWAP_TARGET_AND_HOST} in GDB,
+or one of the swap routines defined in @file{bfd.h}, such as @code{bfd_get_32}.
+
+@item
+You can't assume that you know what interface is being used to talk to
+the target system.  All references to the target must go through the
+current @code{target_ops} vector.
+
+@item
+You can't assume that the host and target machines are the same machine
+(except in the ``native'' support modules).
+In particular, you can't assume that the target machine's header files
+will be available on the host machine.  Target code must bring along its
+own header files -- written from scratch or explicitly donated by their
+owner, to avoid copyright problems.
+
+@item
+Insertion of new @code{#ifdef}'s will be frowned upon.  It's much better
+to write the code portably than to conditionalize it for various systems.
+
+@item
+New @code{#ifdef}'s which test for specific compilers or manufacturers
+or operating systems are unacceptable.  All @code{#ifdef}'s should test
+for features.  The information about which configurations contain which
+features should be segregated into the configuration files.  Experience
+has proven far too often that a feature unique to one particular system
+often creeps into other systems; and that a conditional based on 
+some predefined macro for your current system will become worthless
+over time, as new versions of your system come out that behave differently
+with regard to this feature.
+
+@item
+Adding code that handles specific architectures, operating systems, target
+interfaces, or hosts, is not acceptable in generic code.  If a hook
+is needed at that point, invent a generic hook and define it for your
+configuration, with something like:
+
+@example
+#ifdef WRANGLE_SIGNALS
+   WRANGLE_SIGNALS (signo);
+#endif
+@end example
+
+In your host, target, or native configuration file, as appropriate, 
+define @code{WRANGLE_SIGNALS} to do the machine-dependent thing.  Take
+a bit of care in defining the hook, so that it can be used by other
+ports in the future, if they need a hook in the same place.
+
+@item
+@emph{Do} write code that doesn't depend on the sizes of C data types,
+the format of the host's floating point numbers, the alignment of anything,
+or the order of evaluation of expressions.  In short, follow good 
+programming practices for writing portable C code.
+
+@end table
+
+@node Submitting Patches
+@chapter Submitting Patches
+
+Thanks for thinking of offering your changes back to the community of
+GDB users.  In general we like to get well designed enhancements.
+Thanks also for checking in advance about the best way to transfer the
+changes.
+
+The two main problems with getting your patches in are,
+
+@table @bullet
+@item
+The GDB maintainers will only install "cleanly designed" patches.
+You may not always agree on what is clean design.
+@pxref{Coding Style}, @pxref{Clean Design}.
+
+@item
+If the maintainers don't have time to put the patch in when it
+arrives, or if there is any question about a patch, it
+goes into a large queue with everyone else's patches and
+bug reports.
+@end table
+
+I don't know how to get past these problems except by continuing to try.
+
+There are two issues here -- technical and legal.
+
+The legal issue is that to incorporate substantial changes requires a
+copyright assignment from you and/or your employer, granting ownership of the changes to
+the Free Software Foundation.  You can get the standard document for
+doing this by sending mail to @code{gnu@@prep.ai.mit.edu} and asking for it.
+I recommend that people write in "All programs owned by the
+Free Software Foundation" as "NAME OF PROGRAM", so that changes in
+many programs (not just GDB, but GAS, Emacs, GCC, etc) can be
+contributed with only one piece of legalese pushed through the
+bureacracy and filed with the FSF.  I can't start merging changes until
+this paperwork is received by the FSF (their rules, which I follow since
+I maintain it for them).
+
+Technically, the easiest way to receive changes is to receive each
+feature as a small context diff or unidiff, suitable for "patch".
+Each message sent to me should include the changes to C code and
+header files for a single feature, plus ChangeLog entries for each
+directory where files were modified, and diffs for any changes needed
+to the manuals (gdb/doc/gdb.texi or gdb/doc/gdbint.texi).  If there
+are a lot of changes for a single feature, they can be split down
+into multiple messages.
+
+In this way, if I read and like the feature, I can add it to the
+sources with a single patch command, do some testing, and check it in.
+If you leave out the ChangeLog, I have to write one.  If you leave
+out the doc, I have to puzzle out what needs documenting.  Etc.
+
+The reason to send each change in a separate message is that I will
+not install some of the changes.  They'll be returned to you with
+questions or comments.  If I'm doing my job, my message back to you
+will say what you have to fix in order to make the change acceptable.
+The reason to have separate messages for separate features is so
+that other changes (which I @emph{am} willing to accept) can be installed
+while one or more changes are being reworked.  If multiple features
+are sent in a single message, I tend to not put in the effort to sort
+out the acceptable changes from the unacceptable, so none of the
+features get installed until all are acceptable.
+
+If this sounds painful or authoritarian, well, it is.  But I get a lot
+of bug reports and a lot of patches, and most of them don't get
+installed because I don't have the time to finish the job that the bug
+reporter or the contributor could have done.  Patches that arrive
+complete, working, and well designed, tend to get installed on the day
+they arrive.  The others go into a queue and get installed if and when
+I scan back over the queue -- which can literally take months
+sometimes.  It's in both our interests to make patch installation easy
+-- you get your changes installed, and I make some forward progress on
+GDB in a normal 12-hour day (instead of them having to wait until I
+have a 14-hour or 16-hour day to spend cleaning up patches before I
+can install them).
+
+@node Host Conditionals
 @chapter Host Conditionals
 
 When GDB is configured and compiled, various macros are defined or left
@@ -958,7 +1267,10 @@ main.c
 @item KERNELDEBUG
 tm-hppa.h
 @item MEM_FNS_DECLARED
-defs.h
+Your host config file defines this if it includes 
+declarations of @code{memcpy} and @code{memset}.  Define this
+to avoid conflicts between the native include
+files and the declarations in @file{defs.h}.
 @item NO_SYS_FILE
 dbxread.c
 @item PYRAMID_CONTROL_FRAME_DEBUGGING
@@ -1282,8 +1594,6 @@ when using HAVE_MMAP, this is the increment between mappings.
 ser-go32.c
 @item MOTOROLA
 xm-altos.h
-@item NAMES_HAVE_UNDERSCORE
-coffread.c
 @item NBPG
 altos-xdep.c
 @item NEED_POSIX_SETPGID
@@ -1435,8 +1745,6 @@ infrun.c
 core.c
 @item SOLIB_CREATE_INFERIOR_HOOK
 infrun.c
-@item SOME_NAMES_HAVE_DOT
-minsyms.c
 @item SP_REGNUM
 parse.c
 @item STAB_REG_TO_REGNUM
@@ -1571,7 +1879,7 @@ coffread.c
 coffread.c
 @end table
 
-@node Target Conditionals, Native Conditionals, Host Conditionals, Top
+@node Target Conditionals
 @chapter Target Conditionals
 
 When GDB is configured and compiled, various macros are defined or left
@@ -1594,8 +1902,6 @@ dbxread.c
 main.c
 @item KERNELDEBUG
 tm-hppa.h
-@item MEM_FNS_DECLARED
-defs.h
 @item NO_SYS_FILE
 dbxread.c
 @item PYRAMID_CONTROL_FRAME_DEBUGGING
@@ -1885,8 +2191,6 @@ maint.c
 mips-tdep.c
 @item MOTOROLA
 xm-altos.h
-@item NAMES_HAVE_UNDERSCORE
-coffread.c
 @item NBPG
 altos-xdep.c
 @item NEED_POSIX_SETPGID
@@ -2017,8 +2321,6 @@ infrun.c
 core.c
 @item SOLIB_CREATE_INFERIOR_HOOK
 infrun.c
-@item SOME_NAMES_HAVE_DOT
-minsyms.c
 @item SP_REGNUM
 parse.c
 @item STAB_REG_TO_REGNUM
@@ -2143,21 +2445,25 @@ coffread.c
 coffread.c
 @end table
 
-@node Native Conditionals,  , Target Conditionals, Top
+@node Native Conditionals
 @chapter Native Conditionals
 
+When GDB is configured and compiled, various macros are defined or left
+undefined, to control compilation when the host and target systems
+are the same.  These macros should be defined (or left undefined)
+in @file{nm-@var{system}.h}.
 
 @table @code
 @item ATTACH_DETACH
 If defined, then gdb will include support for the @code{attach} and
 @code{detach} commands.
-commands.
 @item FETCH_INFERIOR_REGISTERS
 Define this if the native-dependent code will provide its
 own routines
 @code{fetch_inferior_registers} and @code{store_inferior_registers} in
 @file{@var{HOST}-nat.c}.
-If this symbol is @emph{not} defined, the default routines in
+If this symbol is @emph{not} defined, and @file{infptrace.c}
+is included in this configuration, the default routines in
 @file{infptrace.c} are used for these functions.
 @item GET_LONGJMP_TARGET
 For most machines, this is a target-dependent parameter.  On the DECstation
@@ -2175,13 +2481,15 @@ definition in @file{procfs.c}.
 @item REGISTER_U_ADDR
 Defines the offset of the registers in the ``u area''; @pxref{Host}.
 @item USE_PROC_FS
-This determines whether small routines that translate register values
-to GDB's internal representation (from the /proc representation), and vice
-verse, are compiled.
+This determines whether small routines in @file{*-tdep.c}, which
+translate register values
+between GDB's internal representation and the /proc representation,
+are compiled.
 @item U_REGS_OFFSET
 This is the offset of the registers in the upage.  It need only be
 defined if the generic ptrace register access routines in
 @file{infptrace.c} are being used (that is,
+@file{infptrace.c} is configured in, and
 @code{FETCH_INFERIOR_REGISTERS} is not defined).  If the default value
 from @file{infptrace.c} is good enough, leave it undefined.
 
@@ -2190,5 +2498,25 @@ registers.  I'm guessing that @code{#define U_REGS_OFFSET 0} means that
 u.u_ar0 @emph{is} the location of the registers.
 @end table
 
+@node Obsolete Conditionals
+@chapter Obsolete Conditionals
+
+Fragments of old code in GDB sometimes reference or set the following
+configuration macros.  They should not be used by new code, and
+old uses should be removed as those parts of the debugger are 
+otherwise touched.
+
+@table @code
+@item STACK_END_ADDR
+This macro used to define where the end of the stack appeared, for use
+in interpreting core file formats that don't record this address in the
+core file itself.  This information is now configured in BFD, and GDB
+gets the info portably from there.  The values in GDB's configuration
+files should be moved into BFD configuration files (if needed there),
+and deleted from all of GDB's config files.
+
+Any @file{@var{foo}-xdep.c} file that references STACK_END_ADDR
+is so old that it has never been converted to use BFD.  Now that's old!
+@end table
 @contents
 @bye
This page took 0.032267 seconds and 4 git commands to generate.