⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gdbint.texinfo

📁 早期freebsd实现
💻 TEXINFO
📖 第 1 页 / 共 5 页
字号:
\input texinfo@setfilename gdbint.info@c $Id: gdbint.texinfo,v 1.41 1992/10/21 21:11:55 gnu Exp $@ifinfo@formatSTART-INFO-DIR-ENTRY* Gdb-Internals: (gdbint).	The GNU debugger's internals.END-INFO-DIR-ENTRY@end format@end ifinfo@ifinfoThis file documents the internals of the GNU debugger GDB.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 ofthis manual provided the copyright notice and this permission noticeare preserved on all copies.@ignorePermission is granted to process this file through Tex and print theresults, provided the printed document carries copying permissionnotice identical to this one except for the removal of this paragraph(this paragraph not being relevant to the printed manual).@end ignorePermission is granted to copy or distribute modified versions of thismanual under the terms of the GPL (for which purpose this text may beregarded as a program in the language TeX).@end ifinfo@setchapternewpage off@settitle GDB Internals@titlepage@title{Working in GDB}@subtitle{A guide to the internals of the GNU debugger}@author John Gilmore@author Cygnus Support@page@tex\def\$#1${{#1}}  % Kluge: collect RCS revision info without $...$\xdef\manvers{\$Revision: 1.41 $}  % For use in headers, footers too{\parskip=0pt\hfill Cygnus Support\par\hfill \manvers\par\hfill \TeX{}info \texinfoversion\par}@end tex@vskip 0pt plus 1filllCopyright @copyright{} 1990, 1991, 1992 Free Software Foundation, Inc.Permission is granted to make and distribute verbatim copies ofthis manual provided the copyright notice and this permission noticeare preserved on all copies.@end titlepage@node Top@topThis documents the internals of the GNU debugger, GDB.  It is acollection of miscellaneous information with little form at this point.Mostly, it is a repository into which you can put information aboutGDB as you discover it (or as you design changes to GDB).@menu* README::			The README File* 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* Partial Symbol Tables::	How GDB reads symbols quickly at startup* BFD support for GDB::		How BFD and GDB interface* Symbol Reading::		Defining New Symbol Readers* Cleanups::			Cleanups* Wrapping::			Wrapping Output Lines* Frames::			Keeping track of function calls* Coding Style::		Strunk and White for GDB maintainers* 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@chapter The @file{README} FileCheck the @file{README} file, it often has useful information that does notappear anywhere else in the directory.@node New Architectures@chapter Defining a New Host or Target ArchitectureWhen building support for a new host and/or target, much of the work youneed to do is handled by specifying configuration files;@pxref{Config,,Adding a New Configuration}.  Further work can bedivided into ``host-dependent'' (@pxref{Host,,Adding a New Host}) and``target-dependent'' (@pxref{Target,,Adding a New Target}).  Thefollowing discussion is meant to explain the difference between hostsand targets.@heading What is considered ``host-dependent'' versus ``target-dependent''?@dfn{Host} refers to attributes of the system where GDB runs.@dfn{Target} refers to the system where the program being debuggedexecutes.   In most cases they are the same machine, in which casea 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, hostfloat format.Defines and information needed to handle the target format are targetdependent.  Examples are the stack frame format, instruction set,breakpoint instruction, registers, and how to set up and tear down the stackto 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 thehost and target are not the same, doing a fork to start the targetprocess is a bad idea.  The various macros needed for finding theregisters in the @code{upage}, running @code{ptrace}, and such are all in thenative-dependent files.Another example of native-dependent code is support for featuresthat 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.When you want to make GDB work ``native'' on a particularmachine, you have to include all three kinds of information.The dependent information in GDB is organized into files by namingconventions.  Host-Dependent Files@table @file@item	config/*.mhSets Makefile parameters@item	xm-*.hGlobal #include's and #define's and definitions@item	*-xdep.cGlobal variables and functions@end tableNative-Dependent Files@table @file@item	config/*.mhSets Makefile parameters (for @emph{both} host and native)@item	nm-*.h#include's and #define's and definitions.  This fileis only included by the small number of modules that need it,so beware of doing feature-test #define's from its macros.@item	*-nat.cglobal variables and functions@end tableTarget-Dependent Files@table @file@item	config/*.mtSets Makefile parameters@item	tm-*.hGlobal #include's and #define's and definitions@item	*-tdep.cGlobal variables and functions@end tableAt this writing, most supported hosts have had their host and nativedependencies sorted out properly.  There are a few stragglers, whichcan be recognized by the absence of NATDEPFILES lines in their@file{config/*.mh}.@node Config@chapter Adding a New ConfigurationMost of the work in making GDB compile on a new machine is in specifyingthe configuration of the machine.  This is done in a dizzying variety ofheader files and configuration scripts, which we hope to make moresensible soon.  Let's say your new host is called an @var{xxx} (e.g.@samp{sun4}), and its full three-part configuration name is@code{@var{xarch}-@var{xvend}-@var{xos}} (e.g.  @samp{sparc-sun-sunos4}).  Inparticular:In the top level directory, edit @file{config.sub} and add @var{xarch},@var{xvend}, and @var{xos} to the lists of supported architectures,vendors, and operating systems near the bottom of the file.  Also, add@var{xxx} as an alias that maps to@code{@var{xarch}-@var{xvend}-@var{xos}}.  You can test your changes byrunning@example./config.sub @var{xxx}@end example@noindentand@example./config.sub @code{@var{xarch}-@var{xvend}-@var{xos}}@end example@noindentwhich should both respond with @code{@var{xarch}-@var{xvend}-@var{xos}}and no error messages.Now, go to the @file{bfd} directory and create a new file @file{bfd/hosts/h-@var{xxx}.h}.  Examine theother @file{h-*.h} files as templates, and create one that brings in theright include files for your system, and defines any host-specificmacros 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.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 yourfile @file{h-@var{xxx}.h} to be linked to @file{sysdep.h} at configurationtime.  When creating the line that recognizes your configuration,only match the fields that you really need to match; e.g. don't matchmatch the architecture or manufacturer if the OS is sufficientto 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/@var{xxx}.mh}, which includes the required lines.It's possible that the @file{libiberty} and @file{readline} directorieswon't need any changes for your configuration, but if they do, you canchange the @file{configure.in} file there to recognize your system andmap to an @file{mh-@var{xxx}} file.  Then add @file{mh-@var{xxx}}to the @file{config/} subdirectory, to set any makefile variables youneed.  The only current options in there are things like @samp{-DSYSV}.(This @file{mh-@var{xxx}} naming convention differs from elsewherein GDB, by historical accident.  It should be cleaned up so that allsuch 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}to @var{xxx}, and (unless your desired target is already available) alsoset @code{gdb_target} to something appropriate (for instance,@var{xxx}).  To handle new hosts, modify the segment after the comment@samp{# per-host}; to handle new targets, modify after @samp{#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-, native-, andtarget-dependent @file{.h} and @file{.c} files used for yourconfiguration; the next two chapters discuss those.@node Host@chapter Adding a New HostOnce you have specified a new configuration for your host(@pxref{Config,,Adding a New Configuration}), there are three remainingpieces to making GDB work on a new machine.  First, you have to make ithost on the new machine (compile there, handle that machine's terminalsproperly, etc).  If you will be cross-debugging to some other kind ofsystem 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, symbolfiles, 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:@table @file@item gdb/config/mh-@var{xxx}Specifies Makefile fragments needed when hosting on machine @var{xxx}.In particular, this lists the required machine-dependent object files,by defining @samp{XDEPFILES=@dots{}}.  Alsospecifies the header file which describes host @var{xxx}, by defining@samp{XM_FILE= xm-@var{xxx}.h}.  You can also define @samp{CC},@samp{REGEX} and @samp{REGEX1}, @samp{SYSV_DEFINE}, @samp{XM_CFLAGS},@samp{XM_ADD_FILES}, @samp{XM_CLIBS}, @samp{XM_CDEPS},etc.; see @file{Makefile.in}.@item gdb/xm-@var{xxx}.h(@file{xm.h} is a link to this file, created by configure).Contains C macro definitions describing the host system environment,such as byte order, host C compiler and library, ptrace support,and core file structure.  Crib from existing @file{xm-*.h} filesto create a new one.@item gdb/@var{xxx}-xdep.cContains any miscellaneous C code required for this machineas a host.  On many machines it doesn't exist at all.  If it doesexist, put @file{@var{xxx}-xdep.o} into the @code{XDEPFILES} linein @file{gdb/config/mh-@var{xxx}}.@end table@subheading Generic Host Support FilesThere are some ``generic'' versions of routines that can be used byvarious systems.  These can be customized in various ways by macrosdefined in your @file{xm-@var{xxx}.h} file.  If these routines work forthe @var{xxx} host, you can just include the generic file's name (with@samp{.o}, not @samp{.c}) in @code{XDEPFILES}.  Otherwise, if your machine needs custom support routines, you will needto 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}.@table @file@item ser-bsd.cThis contains serial line support for Berkeley-derived Unix systems.@item ser-go32.cThis contains serial line support for 32-bit programs running under DOSusing the GO32 execution environment.@item ser-termios.cThis contains serial line support for System V-derived Unix systems.@end tableNow, you are now ready to try configuring GDB to compile using your systemas its host.  From the top level (above @file{bfd}, @file{gdb}, etc), do:@example./configure @var{xxx} +target=vxworks960@end exampleThis will configure your system to cross-compile for VxWorks onthe Intel 960, which is probably not what you really want, but it'sa test case that works at this stage.  (You haven't set up to beable to debug programs that run @emph{on} @var{xxx} yet.)If this succeeds, you can try building it all with:@examplemake@end exampleRepeat until the program configures, compiles, links, and runs.When run, it won't be able to do much (unless you have a VxWorks/960board on your network) but you will know that the host support ispretty well done.Good luck!  Comments and suggestions about this section are particularlywelcome; send them to @samp{bug-gdb@@prep.ai.mit.edu}.@node Native@chapter Adding a New Native ConfigurationIf you are making GDB run native on the @var{xxx} machine, you haveplenty more work to do.  Several files control GDB's configuration fornative support:@table @file@item gdb/config/@var{xxx}.mhSpecifies 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{}}.  Alsospecifies 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.Code that needs these definitions will have to @code{#include "nm.h"}explicitly, since it is not included by @file{defs.h}.@item gdb/@var{xxx}-nat.cContains any miscellaneous C code required for this native supportof this machine.  On some machines it doesn't exist at all.@end table@subheading Generic Native Support FilesThere are some ``generic'' versions of routines that can be used byvarious systems.  These can be customized in various ways by macrosdefined in your @file{nm-@var{xxx}.h} file.  If these routines work forthe @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 needto 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.cThis contains the @emph{target_ops vector} that supports Unix childprocesses on systems which use ptrace and wait to control the child.@item procfs.cThis contains the @emph{target_ops vector} that supports Unix childprocesses on systems which use /proc to control the child.@item fork-child.cThis does the low-level grunge that uses Unix system callsto do a "fork and exec" to start up a child process.@item infptrace.cThis is the low level interface to inferior processes for systemsusing the Unix @code{ptrace} call in a vanilla way.@item coredep.c::fetch_core_registers()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 shoulduse @code{coredep.c}, and should just provide @code{fetch_core_registers} in@code{@var{xxx}-nat.c} (or @code{REGISTER_U_ADDR} in @code{nm-@var{xxx}.h}).@item coredep.c::register_addr()If your @code{nm-@var{xxx}.h} file defines the macro@code{REGISTER_U_ADDR(addr, blockend, regno)}, it should be defined toset @code{addr} to the offset within the @samp{user}struct of GDB register number @code{regno}.  @code{blockend} is theoffset within the ``upage'' of @code{u.u_ar0}.If @code{REGISTER_U_ADDR} is defined,@file{coredep.c} will define the @code{register_addr()} function and usethe macro in it.  If you do not define @code{REGISTER_U_ADDR}, but youare using the standard @code{fetch_core_registers()}, you will need todefine your own version of @code{register_addr()}, put it into your@code{@var{xxx}-nat.c} file, and be sure @code{@var{xxx}-nat.o} is inthe @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 tableWhen making GDB run native on a new operating system,to make it possible to debugcore files, you will need to either write specific code for parsing yourOS's core files, or customize @file{bfd/trad-core.c}.  First, usewhatever @code{#include} files your machine uses to define the struct ofregisters that is accessible (possibly in the u-area) in a core file(rather than @file{machine/reg.h}), and an include file that defines whateverheader exists on a core file (e.g. the u-area or a @samp{struct core}).  Thenmodify @code{trad_unix_core_file_p()} to use these values to set up thesection information for the data segment, stack segment, any othersegments in the core file (perhaps shared library contents or controlinformation), ``registers'' segment, and if there are two discontiguoussets of registers (e.g.  integer and float), the ``reg2'' segment.  Thissection information basically delimits areas in the core file in astandard way, which the section-reading routines in BFD know how to seekaround 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{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,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -