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

📄 gdbint.texinfo

📁 早期freebsd实现
💻 TEXINFO
📖 第 1 页 / 共 5 页
字号:
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 suppliedregister 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 ELFformat core files, then you may be able to use the same routinesfor reading the registers out of processes and out of core files.@node Target@chapter Adding a New TargetFor a new target called @var{ttt}, first specify the configuration asdescribed in @ref{Config,,Adding a New Configuration}.  If your newtarget 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/@var{ttt}.mtContains a Makefile fragment specific to this target.Specifies what object files are needed for target @var{ttt}, bydefining @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(@file{tm.h} is a link to this file, created by configure).Contains macro definitions about the target machine'sregisters, stack frame format and instructions.Crib from existing @file{tm-*.h} files when building a new one.@item gdb/@var{ttt}-tdep.cContains any miscellaneous code required for this target machine.On some machines it doesn't exist at all.  Sometimes the macrosin @file{tm-@var{ttt}.h} become very complicated, so they areimplemented as functions here instead, and the macro is simplydefined to call the function.@item gdb/exec.c Defines functions for accessing files that areexecutable on the target system.  These functions open and examine anexec file, extract data from one, write data to one, print informationabout one, etc.  Now that executable files are handled with BFD, everytarget should be able to use the generic exec.c rather than itsown custom code.@item gdb/@var{arch}-pinsn.cPrints (disassembles) the target machine's instructions.This file is usually shared with other target machines which use thesame processor, which is why it is @file{@var{arch}-pinsn.c} ratherthan @file{@var{ttt}-pinsn.c}.@item gdb/@var{arch}-opcode.hContains some large initializeddata structures describing the target machine's instructions.This is a bit strange for a @file{.h} file, but it's OK sinceit is only included in one place.  @file{@var{arch}-opcode.h} is sharedbetween the debugger and the assembler, if the GNU assembler has beenported to the target machine.@item gdb/tm-@var{arch}.hThis often exists to describe the basic layout of the target machine'sprocessor chip (registers, stack, etc).If used, it is included by @file{tm-@var{xxx}.h}.  It canbe shared among many targets that use the same processor.@item gdb/@var{arch}-tdep.cSimilarly, there are often common subroutines that are shared by alltarget machines that use this particular architecture.@end tableWhen adding support for a new target machine, there are various areasof support that might need change, or might be OK.If you are using an existing object file format (a.out or COFF), there is probably little to be done.  See @file{bfd/doc/bfd.texinfo}for more information on writing new a.out or COFF versions.If you need to add a new object file format, you are beyond the scopeof this document right now.  Look at the structure of the a.outand COFF support, build a transfer vector (@code{xvec}) for your new format,and start populating it with routines.  Add it to the list in@file{bfd/targets.c}.If you are adding a new operating system for an existing CPU chip, add a@file{tm-@var{xos}.h} file that describes the operating systemfacilities that are unusual (extra symbol table info; the breakpointinstruction needed; etc).  Then write a@file{tm-@var{xarch}-@var{xos}.h} that just @code{#include}s@file{tm-@var{xarch}.h} and @file{tm-@var{xos}.h}.  (Now that we havethree-part configuration names, this will probably get revised toseparate the @var{xos} configuration from the @var{xarch}configuration.)@node Languages@chapter Adding a Source Language to GDBTo add other languages to GDB's expression parser, follow the following steps:@table @emph@item Create the expression parser.This should reside in a file @file{@var{lang}-exp.y}.  Routines for buildingparsed expressions into a @samp{union exp_element} list are in @file{parse.c}.Since we can't depend upon everyone having Bison, and YACC producesparsers that define a bunch of global names, the following lines@emph{must} be included at the top of the YACC parser, to preventthe various parsers from defining the same global names:@example#define yyparse 	@var{lang}_parse#define yylex 	@var{lang}_lex#define yyerror 	@var{lang}_error#define yylval 	@var{lang}_lval#define yychar 	@var{lang}_char#define yydebug 	@var{lang}_debug#define yypact  	@var{lang}_pact #define yyr1		@var{lang}_r1   #define yyr2		@var{lang}_r2   #define yydef		@var{lang}_def  #define yychk		@var{lang}_chk  #define yypgo		@var{lang}_pgo  #define yyact  	@var{lang}_act  #define yyexca  	@var{lang}_exca#define yyerrflag  	@var{lang}_errflag#define yynerrs  	@var{lang}_nerrs@end exampleAt the bottom of your parser, define a @code{struct language_defn} andinitialize it with the right values for your language.  Define an@code{initialize_@var{lang}} routine and have it call@samp{add_language(@var{lang}_language_defn)} to tell the rest of GDBthat your language exists.  You'll need some other supporting variablesand functions, which will be used via pointers from your@code{@var{lang}_language_defn}.  See the declaration of @code{structlanguage_defn} in @file{language.h}, and the other @file{*-exp.y} files,for more information.@item Add any evaluation routines, if necessaryIf you need new opcodes (that represent the operations of the language),add them to the enumerated type in @file{expression.h}.  Add supportcode for these operations in @code{eval.c:evaluate_subexp()}.  Add casesfor new opcodes in two functions from @file{parse.c}:@code{prefixify_subexp()} and @code{length_of_subexp()}.  These computethe number of @code{exp_element}s that a given operation takes up.@item Update some existing codeAdd an enumerated identifier for your language to the enumerated type@code{enum language} in @file{defs.h}.Update the routines in @file{language.c} so your language is included.  Theseroutines include type predicates and such, which (in some cases) arelanguage dependent.  If your language does not appear in the switchstatement, an error is reported.Also included in @file{language.c} is the code that updates the variable@code{current_language}, and the routines that translate the@code{language_@var{lang}} enumerated identifier into a printablestring.Update the function @code{_initialize_language} to include your language.  Thisfunction picks the default language upon startup, so is dependent uponwhich languages that GDB is built for.Update @code{allocate_symtab} in @file{symfile.c} and/or symbol-readingcode so that the language of each symtab (source file) is set properly.This is used to determine the language to use at each stack frame level.Currently, the language is set based upon the extension of the sourcefile.  If the language can be better inferred from the symbolinformation, please set the language of the symtab in the symbol-readingcode.Add helper code to @code{expprint.c:print_subexp()} to handle any newexpression opcodes you have added to @file{expression.h}.  Also, add theprinted representations of your operators to @code{op_print_tab}.@item Add a place of callAdd a call to @code{@var{lang}_parse()} and @code{@var{lang}_error} in@code{parse.c:parse_exp_1()}.@item Use macros to trim codeThe user has the option of building GDB for some or all of thelanguages.  If the user decides to build GDB for the language@var{lang}, then every file dependent on @file{language.h} will have themacro @code{_LANG_@var{lang}} defined in it.  Use @code{#ifdef}s toleave out large routines that the user won't need if he or she is notusing your language.Note that you do not need to do this in your YACC parser, since if GDBis not build for @var{lang}, then @file{@var{lang}-exp.tab.o} (thecompiled form of your parser) is not linked into GDB at all.See the file @file{configure.in} for how GDB is configured for differentlanguages.@item Edit @file{Makefile.in}Add dependencies in @file{Makefile.in}.  Make sure you update the macrovariables such as @code{HFILES} and @code{OBJS}, otherwise your code maynot get linked in, or, worse yet, it may not get @code{tar}red into thedistribution!@end table@node Releases@chapter Configuring GDB for ReleaseFrom the top level directory (containing @file{gdb}, @file{bfd},@file{libiberty}, and so on):@examplemake -f Makefile.in gdb.tar.Z@end exampleThis will properly configure, clean, rebuild any files that aredistributed pre-built (e.g. @file{c-exp.tab.c} or @file{refcard.ps}),and will then make a tarfile.  (If the top level directory has alreadybeenn configured, you can just do @code{make gdb.tar.Z} instead.)This procedure requires:@itemize @bullet@item symbolic links@item @code{makeinfo} (texinfo2 level)@item @TeX{}@item @code{dvips}@item @code{yacc} or @code{bison}@end itemize@noindent@dots{} and the usual slew of utilities (@code{sed}, @code{tar}, etc.).@subheading TEMPORARY RELEASE PROCEDURE FOR DOCUMENTATION@file{gdb.texinfo} is currently marked up using the texinfo-2 macros,which are not yet a default for anything (but we have to start usingthem sometime).  For making paper, the only thing this implies is the right generation of@file{texinfo.tex} needs to be included in the distribution.For making info files, however, rather than duplicating the texinfo2distribution, generate @file{gdb-all.texinfo} locally, and include the files@file{gdb.info*} in the distribution.  Note the plural; @code{makeinfo} willsplit the document into one overall file and five or so included files.@node Partial Symbol Tables@chapter Partial Symbol TablesGDB has three types of symbol tables.@itemize @bullet@item	full symbol tables (symtabs).  These contain the maininformation about symbols and addresses.@item	partial symbol tables (psymtabs).  These contain enoughinformation to know when to read the correspondingpart of the full symbol table.@item	minimal symbol tables (msymtabs).  These contain informationgleaned from non-debugging symbols.@end itemizeThis section describes partial symbol tables.A psymtab is constructed by doing a very quick pass over an executablefile's debugging information.  Small amounts of information areextracted -- enough to identify which parts of the symbol table willneed to be re-read and fully digested later, when the user needs theinformation.  The speed of this pass causes GDB to start up veryquickly.  Later, as the detailed rereading occurs, it occurs in smallpieces, at various times, and the delay therefrom is mostly invisible tothe user.  (@xref{Symbol Reading}.)The symbols that show up in a file's psymtab should be, roughly, thosevisible to the debugger's user when the program is not running code fromthat file.  These include external symbols and types, staticsymbols and types, and enum values declared at file scope.The psymtab also contains the range of instruction addresses that thefull symbol table would represent.The idea is that there are only two ways for the user (or much ofthe code in the debugger) to reference a symbol:@itemize @bullet@item by its address(e.g. execution stops at some address which is inside a functionin this file).  The address will be noticed to be in therange of this psymtab, and the full symtab will be read in.@code{find_pc_function}, @code{find_pc_line}, and other @code{find_pc_@dots{}}functions handle this.@item by its name(e.g. the user asks to print a variable, or set a breakpoint on afunction).  Global names and file-scope names will be found in thepsymtab, which will cause the symtab to be pulled in.  Local names willhave to be qualified by a global name, or a file-scope name, in whichcase we will have already read in the symtab as we evaluated thequalifier.  Or, a local symbol can be referenced whenwe are "in" a local scope, in which case the first case applies.@code{lookup_symbol} does most of the work here.@end itemizeThe only reason that psymtabs exist is to cause a symtab to be read inat the right moment.  Any symbol that can be elided from a psymtab,while still causing that to happen, should not appear in it.  Sincepsymtabs don't have the idea of scope, you can't put local symbols inthem anyway.  Psymtabs don't have the idea of the type of a symbol,either, so types need not appear, unless they will be referenced byname.It is a bug for GDB to behave one way when only a psymtab has been read,and another way if the corresponding symtab has been read in.  Suchbugs are typically caused by a psymtab that does not contain all thevisible symbols, or which has the wrong instruction address ranges.The psymtab for a particular section of a symbol-file (objfile)could be thrown away after the symtab has been read in.  The symtabshould always be searched before the psymtab, so the psymtab willnever be used (in a bug-free environment).  Currently,psymtabs are allocated on an obstack, and all the psymbols themselvesare allocated in a pair of large arrays on an obstack, so there islittle to be gained by trying to free them unless you want to do a lotmore work.@node BFD support for GDB@chapter Binary File Descriptor Library Support for GDBBFD provides support for GDB in several ways:@table @emph@item	identifying executable and core filesBFD will identify a variety of file types, including a.out, coff, andseveral variants thereof, as well as several kinds of core files.@item	access to sections of filesBFD parses the file headers to determine the names, virtual addresses,sizes, and file locations of all the various named sections in files(such as the text section or the data section).  GDB simply callsBFD to read or write section X at byte offset Y for length Z.@item	specialized core file supportBFD provides routines to determine the failing command name storedin a core file, the signal with which the program failed, and whethera core file matches (i.e. could be a core dump of) a particular executablefile.@item	locating the symbol informationGDB uses an internal interface of BFD to determine where to find thesymbol information in an executable file or symbol-file.  GDB itselfhandles the reading of symbols, since BFD does not ``understand'' debugsymbols, but GDB uses BFD's cached information to find the symbols,string table, etc.@end table@c The interface for symbol reading is described in @ref{Symbol@c Reading,,Symbol Reading}.@node Symbol Reading@chapter Symbol ReadingGDB reads symbols from "symbol files".  The usual symbol file is thefile containing the program which gdb is debugging.  GDB can be directedto use a different file for symbols (with the ``symbol-file''command), and it can also read more symbols via the ``add-file'' and ``load''commands, or while reading symbols from shared libraries.Symbol files are initially opened by @file{symfile.c} using the BFDlibrary.  BFD identifies the type of the file by examining its header.@code{symfile_init} then uses this identification to locate aset of symbol-reading functions.Symbol reading modules identify themselves to GDB by calling@code{add_symtab_fns} during their module initialization.  The argumentto @code{add_symtab_fns} is a @code{struct sym_fns} which containsthe name (or name prefix) of the symbol format, the length of the prefix,and pointers to four functions.  These functions are called at varioustimes to process symbol-files whose identification matches the specifiedprefix.The functions supplied by each module are:@table @code@item @var{xxx}_symfile_init(struct sym_fns *sf)Called from @code{symbol_file_add} when we are about to read a newsymbol file.  This function should clean up any internal state(possibly resulting from half-read previous files, for example)and prepare to read a new symbol file. Note that the symbol filewhich we are reading might be a new "main" symbol file, or mightbe a secondary symbol file whose symbols are being added to theexisting symbol table.The argument to @code{@var{xxx}_symfile_init} is a newly allocated@code{struct sym_fns} whose @code{bfd} field contains the BFDfor the new symbol file being read.  Its @code{private} fieldhas been zeroed, and can be modified as desired.  Typically,a struct of private information will be @code{malloc}'d, anda pointer to it will be placed in the @code{private} field.There is no result from @code{@var{xxx}_symfile_init}, but it can call@code{error} if it detects an unavoidable problem.@item @var{xxx}_new_init()Called from @code{symbol_file_add} when discarding existing symbols.This function need only handle the symbol-reading module's internal state; the symbol table datastructures visible to the rest of GDB will be discarded by@code{symbol_file_add}.  It has no arguments and no result.It may be called after @code{@var{xxx}_symfile_init}, if a new symboltable is being read, or may be called alone if all symbols aresimply being discarded.@item @var{xxx}_symfile_read(struct sym_fns *sf, CORE_ADDR addr, int mainline)Called from @code{symbol_file_add} to actually read the symbols from asymbol-file into a set of psymtabs or symtabs.@code{sf} points to the struct sym_fns originally passed to@code{@var{xxx}_sym_init} for possible initialization.  @code{addr} is theoffset between the file's specified start address and its true addressin memory.  @code{mainline} is 1 if this is the main symbol table beingread, and 0 if a secondary symbol file (e.g. shared library ordynamically loaded file) is being read.@refill@end tableIn addition, if a symbol-reading module creates psymtabs when@var{xxx}_symfile_read is called, these psymtabs will contain a pointer toa function @code{@var{xxx}_psymtab_to_symtab}, which can be called fromany point in the GDB symbol-handling code.@table @code@item @var{xxx}_psymtab_to_symtab (struct partial_symtab *pst)Called from @code{psymtab_to_symtab} (or the PSYMTAB_TO_SYMTABmacro) if the psymtab has not already been read in and had its@code{pst->symtab} pointer set.  The argument is the psymtabto be fleshed-out into a symtab.  Upon return, pst->readinshould have been set to 1, and pst->symtab should contain apointer to the new corresponding symtab, or zero if therewere no symbols in that part of the symbol file.@end table@node Cleanups@chapter CleanupsCleanups are a structured way to deal with things that need to be done

⌨️ 快捷键说明

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