2 @setfilename gdbint.info
5 This file documents the internals of the GNU debugger GDB.
7 Copyright (C) 1990, 1991 Free Software Foundation, Inc.
8 Contributed by Cygnus Support. Written by John Gilmore.
10 Permission is granted to make and distribute verbatim copies of
11 this manual provided the copyright notice and this permission notice
12 are preserved on all copies.
15 Permission is granted to process this file through Tex and print the
16 results, provided the printed document carries copying permission
17 notice identical to this one except for the removal of this paragraph
18 (this paragraph not being relevant to the printed manual).
21 Permission is granted to copy or distribute modified versions of this
22 manual under the terms of the GPL (for which purpose this text may be
23 regarded as a program in the language TeX).
26 @setchapternewpage off
27 @settitle GDB Internals
29 @title{Working in GDB}
30 @subtitle{A guide to the internals of the GNU debugger}
32 @author Cygnus Support
35 \def\$#1${{#1}} % Kluge: collect RCS revision info without $...$
36 \xdef\manvers{\$Revision$} % For use in headers, footers too
38 \hfill Cygnus Support\par
40 \hfill \TeX{}info \texinfoversion\par
44 @vskip 0pt plus 1filll
45 Copyright @copyright{} 1990, 1991 Free Software Foundation, Inc.
47 Permission is granted to make and distribute verbatim copies of
48 this manual provided the copyright notice and this permission notice
49 are preserved on all copies.
53 @node Top, README, (dir), (dir)
56 * README:: The README File
57 * New Architectures:: Defining a New Host or Target Architecture
58 * Config:: Adding a New Configuration
59 * Host:: Adding a New Host
60 * Target:: Adding a New Target
61 * Languages:: Defining New Source Languages
62 * Releases:: Configuring GDB for Release
63 * BFD support for GDB:: How BFD and GDB interface
64 * Symbol Reading:: Defining New Symbol Readers
66 * Wrapping:: Wrapping Output Lines
70 @node README, New Architectures, Top, Top
71 @chapter The @file{README} File
73 Check the @file{README} file, it often has useful information that does not
74 appear anywhere else in the directory.
77 @node New Architectures, Config, README, Top
78 @chapter Defining a New Host or Target Architecture
80 When building support for a new host and/or target, much of the work you
81 need to do is handled by specifying configuration files;
82 @pxref{Config,,Adding a New Configuration}. Further work can be
83 divided into ``host-dependent'' (@pxref{Host,,Adding a New Host}) and
84 ``target-dependent'' (@pxref{Target,,Adding a New Target}). The
85 following discussion is meant to explain the difference between hosts
88 @heading What is considered ``host-dependent'' versus ``target-dependent''?
90 The @file{xconfig/*}, @file{xm-*.h} and @file{*-xdep.c} files are for
91 host support. Similarly, the @file{tconfig/*}, @file{tm-*.h} and
92 @file{*-tdep.c} files are for target support. The question is, what
93 features or aspects of a debugging or cross-debugging environment are
94 considered to be ``host'' support?
96 Defines and include files needed to build on the host are host support.
97 Examples are tty support, system defined types, host byte order, host
100 Unix child process support is considered an aspect of the host. Since
101 when you fork on the host you are still on the host, the various macros
102 needed for finding the registers in the upage, running @code{ptrace}, and such
103 are all in the host-dependent files.
105 @c FIXME so what kinds of things are target support?
107 This is still somewhat of a grey area; I (John Gilmore) didn't do the
108 @file{xm-*} and @file{tm-*} split for gdb (it was done by Jim Kingdon)
109 so I have had to figure out the grounds on which it was split, and make
110 my own choices as I evolve it. I have moved many things out of the xdep
111 files actually, partly as a result of BFD and partly by removing
115 @node Config, Host, New Architectures, Top
116 @chapter Adding a New Configuration
118 Most of the work in making GDB compile on a new machine is in specifying
119 the configuration of the machine. This is done in a dizzying variety of
120 header files and configuration scripts, which we hope to make more
121 sensible soon. Let's say your new host is called an @var{xxx} (e.g.
122 @samp{sun4}), and its full three-part configuration name is
123 @code{@var{xarch}-@var{xvend}-@var{xos}} (e.g. @samp{sparc-sun-sunos4}). In
126 At the top level, edit @file{config.sub} and add @var{xarch},
127 @var{xvend}, and @var{xos} to the lists of supported architectures,
128 vendors, and operating systems near the bottom of the file. Also, add
129 @var{xxx} as an alias that maps to
130 @code{@var{xarch}-@var{xvend}-@var{xos}}. You can test your changes by
134 ./config.sub @var{xxx}
139 ./config.sub @code{@var{xarch}-@var{xvend}-@var{xos}}
142 which should both respond with @code{@var{xarch}-@var{xvend}-@var{xos}}
143 and no error messages.
145 Then edit @file{include/sysdep.h}. Add a new @code{#define} for
146 @samp{@var{xxx}_SYS}, with a numeric value not already in use. Add a
147 new section that says
150 #if HOST_SYS==@var{xxx}_SYS
151 #include <sys/h-@var{xxx}.h>
155 Now create a new file @file{include/sys/h-@var{xxx}.h}. Examine the
156 other @file{h-*.h} files as templates, and create one that brings in the
157 right include files for your system, and defines any host-specific
158 macros needed by GDB.
160 Now, go to the @file{bfd} directory and edit @file{bfd/configure.in}.
161 Add shell script code to recognize your
162 @code{@var{xarch}-@var{xvend}-@var{xos}} configuration, and set
163 @code{bfd_host} to @var{xxx} when you recognize it. Now create a file
164 @file{bfd/config/hmake-@var{xxx}}, which includes the line:
167 HDEFINES=-DHOST_SYS=@var{xxx}_SYS
170 (If you have the binary utilities in the same tree, you'll have to do
171 the same thing to in the @file{binutils} directory as you've done in the
172 @file{bfd} directory.)
174 It's likely that the @file{libiberty} and @file{readline} directories
175 won't need any changes for your configuration, but if they do, you can
176 change the @file{configure.in} file there to recognize your system and
177 map to an @file{hmake-@var{xxx}} file. Then add @file{hmake-@var{xxx}}
178 to the @file{config/} subdirectory, to set any makefile variables you
179 need. The only current options in there are things like @samp{-DSYSV}.
181 Aha! Now to configure GDB itself! You shouldn't edit the
182 @code{configure} script itself to add hosts or targets; instead, edit
183 the script fragments in the file @code{configure.in}. Modify
184 @file{gdb/configure.in} to recognize your system and set @code{gdb_host}
185 to @var{xxx}, and (unless your desired target is already available) also
186 set @code{gdb_target} to something appropriate (for instance,
187 @var{xxx}). To handle new hosts, modify the segment after the comment
188 @samp{# per-host}; to handle new targets, modify after @samp{#
190 @c Would it be simpler to just use different per-host and per-target
191 @c *scripts*, and call them from {configure} ?
193 Then fold your changes into the @code{configure} script by using the
194 @code{+template} option, and specifying @code{configure} itself as the
197 configure +template=configure
199 @c If "configure" is the only workable option value for +template, it's
200 @c kind of silly to insist that it be provided. If it isn't, somebody
201 @c please fill in here what are others... (then delete this comment!)
203 Finally, you'll need to specify and define the host- and
204 target-dependent files used for your configuration; the next two
205 chapters discuss those.
208 @node Host, Target, Config, Top
209 @chapter Adding a New Host
211 Once you have specified a new configuration for your host
212 (@pxref{Config,,Adding a New Configuration}), there are two remaining
213 pieces to making GDB work on a new machine. First, you have to make it
214 host on the new machine (compile there, handle that machine's terminals
215 properly, etc). If you will be cross-debugging to some other kind of
216 system that's already supported, you are done.
218 If you want to use GDB to debug programs that run on the new machine,
219 you have to get it to understand the machine's object files, symbol
220 files, and interfaces to processes. @pxref{Target}
222 Several files control GDB's configuration for host systems:
225 @item gdb/xconfig/@var{xxx}
226 Specifies what object files are needed when hosting on machine @var{xxx},
227 by defining the makefile macro @samp{XDEPFILES=@dots{}}. Also
228 specifies the header file which describes @var{xxx}, by defining
229 @samp{XM_FILE= xm-@var{xxx}.h}. You can also define @samp{CC},
230 @samp{REGEX} and @samp{REGEX1}, @samp{SYSV_DEFINE}, @samp{XM_CFLAGS},
231 @samp{XM_ADD_FILES}, @samp{XM_CLIBS}, @samp{XM_CDEPS},
232 etc.; see @file{Makefile.in}.
234 @item gdb/xm-@var{xxx}.h
235 (@file{xm.h} is a link to this file, created by configure).
236 Contains C macro definitions describing the host system environment,
237 such as byte order, host C compiler and library, ptrace support,
238 and core file structure. Crib from existing @file{xm-*.h} files
241 @item gdb/@var{xxx}-xdep.c
242 Contains any miscellaneous C code required for this machine
243 as a host. On some machines it doesn't exist at all.
246 There are some ``generic'' versions of routines that can be used by
247 various host systems. These can be customized in various ways by macros
248 defined in your @file{xm-@var{xxx}.h} file. If these routines work for
249 the @var{xxx} host, you can just include the generic file's name (with
250 @samp{.o}, not @samp{.c}) in @code{XDEPFILES}.
252 Otherwise, if your machine needs custom support routines, you will need
253 to write routines that perform the same functions as the generic file.
254 Put them into @code{@var{xxx}-xdep.c}, and put @code{@var{xxx}-xdep.o}
255 into @code{XDEPFILES}.
257 @subheading Generic Host Support Files
262 This is the low level interface to inferior processes for systems
263 using the Unix @code{ptrace} call in a vanilla way.
265 @item coredep.c::fetch_core_registers()
266 Support for reading registers out of a core file. This routine calls
267 @code{register_addr()}, see below.
268 Now that BFD is used to read core files, virtually all machines should
269 use @code{coredep.c}, and should just provide @code{fetch_core_registers} in
270 @code{@var{xxx}-xdep.c}.
272 @item coredep.c::register_addr()
273 If your @code{xm-@var{xxx}.h} file defines the macro
274 @code{REGISTER_U_ADDR(reg)} to be the offset within the @samp{user}
275 struct of a register (represented as a GDB register number),
276 @file{coredep.c} will define the @code{register_addr()} function and use
277 the macro in it. If you do not define @code{REGISTER_U_ADDR}, but you
278 are using the standard @code{fetch_core_registers()}, you will need to
279 define your own version of @code{register_addr()}, put it into your
280 @code{@var{xxx}-xdep.c} file, and be sure @code{@var{xxx}-xdep.o} is in
281 the @code{XDEPFILES} list. If you have your own
282 @code{fetch_core_registers()}, you may not need a separate
283 @code{register_addr()}. Many custom @code{fetch_core_registers()}
284 implementations simply locate the registers themselves.@refill
287 Object files needed when the target system is an @var{xxx} are listed
288 in the file @file{tconfig/@var{xxx}}, in the makefile macro
289 @samp{TDEPFILES = }@dots{}. The header file that defines the target
290 system should be called @file{tm-@var{xxx}.h}, and should be specified
291 as the value of @samp{TM_FILE} in @file{tconfig/@var{xxx}}. You can
292 also define @samp{TM_CFLAGS}, @samp{TM_CLIBS}, and @samp{TM_CDEPS} in
293 there; see @file{Makefile.in}.
295 Now, from the top level (above @file{bfd}, @file{gdb}, etc), run:
298 ./configure -template=./configure
301 This will rebuild all your configure scripts, using the new
302 @file{configure.in} files that you modified. (You can also run this command
303 at any subdirectory level.) You are now ready to try configuring
304 GDB to compile for your system. Do:
307 ./configure @var{xxx} +target=vxworks960
310 This will configure your system to cross-compile for VxWorks on
311 the Intel 960, which is probably not what you really want, but it's
312 a test case that works at this stage. (You haven't set up to be
313 able to debug programs that run @emph{on} @var{xxx} yet.)
315 If this succeeds, you can try building it all with:
321 Good luck! Comments and suggestions about this section are particularly
322 welcome; send them to @samp{bug-gdb@@prep.ai.mit.edu}.
324 When hosting GDB on a new operating system, to make it possible to debug
325 core files, you will need to either write specific code for parsing your
326 OS's core files, or customize @file{bfd/trad-core.c}. First, use
327 whatever @code{#include} files your machine uses to define the struct of
328 registers that is accessible (possibly in the u-area) in a core file
329 (rather than @file{machine/reg.h}), and an include file that defines whatever
330 header exists on a core file (e.g. the u-area or a @samp{struct core}). Then
331 modify @code{trad_unix_core_file_p()} to use these values to set up the
332 section information for the data segment, stack segment, any other
333 segments in the core file (perhaps shared library contents or control
334 information), ``registers'' segment, and if there are two discontiguous
335 sets of registers (e.g. integer and float), the ``reg2'' segment. This
336 section information basically delimits areas in the core file in a
337 standard way, which the section-reading routines in BFD know how to seek
340 Then back in GDB, you need a matching routine called @code{fetch_core_registers()}.
341 If you can use the generic one, it's in @file{core-dep.c}; if not, it's in
342 your @file{@var{xxx}-xdep.c} file. It will be passed a char pointer
343 to the entire ``registers'' segment, its length, and a zero; or a char
344 pointer to the entire ``regs2'' segment, its length, and a 2. The
345 routine should suck out the supplied register values and install them into
346 GDB's ``registers'' array. (@xref{New Architectures}
347 for more info about this.)
350 @node Target, Languages, Host, Top
351 @chapter Adding a New Target
353 For a new target called @var{ttt}, first specify the configuration as
354 described in @ref{Config,,Adding a New Configuration}. If your new
355 target is the same as your new host, you've probably already done that.
357 A variety of files specify attributes of the target environment:
360 @item gdb/tconfig/@var{ttt}
361 Specifies what object files are needed for target @var{ttt}, by
362 defining the makefile macro @samp{TDEPFILES=@dots{}}.
363 Also specifies the header file which describes @var{ttt}, by defining
364 @samp{TM_FILE= tm-@var{ttt}.h}. You can also define @samp{CC},
365 @samp{REGEX} and @samp{REGEX1}, @samp{SYSV_DEFINE}, @samp{TM_CFLAGS},
366 and other Makefile variables here; see @file{Makefile.in}.
368 @item gdb/tm-@var{ttt}.h
369 (@file{tm.h} is a link to this file, created by configure).
370 Contains macro definitions about the target machine's
371 registers, stack frame format and instructions.
372 Crib from existing @file{tm-*.h} files when building a new one.
374 @item gdb/@var{ttt}-tdep.c
375 Contains any miscellaneous code required for this target machine.
376 On some machines it doesn't exist at all. Sometimes the macros
377 in @file{tm-@var{ttt}.h} become very complicated, so they are
378 implemented as functions here instead, and the macro is simply
379 defined to call the function.
382 Defines functions for accessing files that are
383 executable on the target system. These functions open and examine an
384 exec file, extract data from one, write data to one, print information
385 about one, etc. Now that executable files are handled with BFD, every
386 target should be able to use the generic exec.c rather than its
389 @item gdb/@var{arch}-pinsn.c
390 Prints (disassembles) the target machine's instructions.
391 This file is usually shared with other target machines which use the
392 same processor, which is why it is @file{@var{arch}-pinsn.c} rather
393 than @file{@var{ttt}-pinsn.c}.
395 @item gdb/@var{arch}-opcode.h
396 Contains some large initialized
397 data structures describing the target machine's instructions.
398 This is a bit strange for a @file{.h} file, but it's OK since
399 it is only included in one place. @file{@var{arch}-opcode.h} is shared
400 between the debugger and the assembler, if the GNU assembler has been
401 ported to the target machine.
403 @item gdb/tm-@var{arch}.h
404 This often exists to describe the basic layout of the target machine's
405 processor chip (registers, stack, etc).
406 If used, it is included by @file{tm-@var{xxx}.h}. It can
407 be shared among many targets that use the same processor.
409 @item gdb/@var{arch}-tdep.c
410 Similarly, there are often common subroutines that are shared by all
411 target machines that use this particular architecture.
414 When adding support for a new target machine, there are various areas
415 of support that might need change, or might be OK.
417 If you are using an existing object file format (a.out or COFF),
418 there is probably little to be done. See @file{bfd/doc/bfd.texinfo}
419 for more information on writing new a.out or COFF versions.
421 If you need to add a new object file format, you are beyond the scope
422 of this document right now. Look at the structure of the a.out
423 and COFF support, build a transfer vector (@code{xvec}) for your new format,
424 and start populating it with routines. Add it to the list in
425 @file{bfd/targets.c}.
427 If you are adding a new operating system for an existing CPU chip, add a
428 @file{tm-@var{xos}.h} file that describes the operating system
429 facilities that are unusual (extra symbol table info; the breakpoint
430 instruction needed; etc). Then write a
431 @file{tm-@var{xarch}-@var{xos}.h} that just @code{#include}s
432 @file{tm-@var{xarch}.h} and @file{tm-@var{xos}.h}. (Now that we have
433 three-part configuration names, this will probably get revised to
434 separate the @var{xos} configuration from the @var{xarch}
438 @node Languages, Releases, Target, Top
439 @chapter Adding a Source Language to GDB
441 To add other languages to GDB's expression parser, follow the following steps:
444 @item Create the expression parser.
446 This should reside in a file @file{@var{lang}-exp.y}. Routines for building
447 parsed expressions into a @samp{union exp_element} list are in @file{parse.c}.
449 Since we can't depend upon everyone having Bison, and YACC produces
450 parsers that define a bunch of global names, the following lines
451 @emph{must} be included at the top of the YACC parser, to prevent
452 the various parsers from defining the same global names:
455 #define yyparse @var{lang}_parse
456 #define yylex @var{lang}_lex
457 #define yyerror @var{lang}_error
458 #define yylval @var{lang}_lval
459 #define yychar @var{lang}_char
460 #define yydebug @var{lang}_debug
461 #define yypact @var{lang}_pact
462 #define yyr1 @var{lang}_r1
463 #define yyr2 @var{lang}_r2
464 #define yydef @var{lang}_def
465 #define yychk @var{lang}_chk
466 #define yypgo @var{lang}_pgo
467 #define yyact @var{lang}_act
468 #define yyexca @var{lang}_exca
469 #define yyerrflag @var{lang}_errflag
470 #define yynerrs @var{lang}_nerrs
473 @item Add any evaluation routines, if necessary
475 If you need new opcodes (that represent the operations of the language),
476 add them to the enumerated type in @file{expression.h}. Add support
477 code for these operations in @code{eval.c:evaluate_subexp()}. Add cases
478 for new opcodes in two functions from @file{parse.c}:
479 @code{prefixify_subexp()} and @code{length_of_subexp()}. These compute
480 the number of @code{exp_element}s that a given operation takes up.
482 @item Update some existing code
484 Add an enumerated identifier for your language to the enumerated type
485 @code{enum language} in @file{defs.h}.
487 Update the routines in @file{language.c} so your language is included. These
488 routines include type predicates and such, which (in some cases) are
489 language dependent. If your language does not appear in the switch
490 statement, an error is reported.
492 Also included in @file{language.c} is the code that updates the variable
493 @code{current_language}, and the routines that translate the
494 @code{language_@var{lang}} enumerated identifier into a printable
497 Update the function @code{_initialize_language} to include your language. This
498 function picks the default language upon startup, so is dependent upon
499 which languages that GDB is built for.
501 Update @code{symfile.c} and/or symbol-reading code so that the language of
502 each symtab (source file) is set properly. This is used to determine the
503 language to use at each stack frame level. Currently, the language
504 is set based upon the extension of the source file. If the language
505 can be better inferred from the symbol information, please set the
506 language of the symtab in the symbol-reading code.
508 Add helper code to @code{expprint.c:print_subexp()} to handle any new
509 expression opcodes you have added to @file{expression.h}. Also, add the
510 printed representations of your operators to @code{op_print_tab}.
512 @item Add a place of call
514 Add a call to @code{@var{lang}_parse()} and @code{@var{lang}_error} in
515 @code{parse.c:parse_exp_1()}.
517 @item Use macros to trim code
519 The user has the option of building GDB for some or all of the
520 languages. If the user decides to build GDB for the language
521 @var{lang}, then every file dependent on @file{language.h} will have the
522 macro @code{_LANG_@var{lang}} defined in it. Use @code{#ifdef}s to
523 leave out large routines that the user won't need if he or she is not
526 Note that you do not need to do this in your YACC parser, since if GDB
527 is not build for @var{lang}, then @file{@var{lang}-exp.tab.o} (the
528 compiled form of your parser) is not linked into GDB at all.
530 See the file @file{configure.in} for how GDB is configured for different
533 @item Edit @file{Makefile.in}
535 Add dependencies in @file{Makefile.in}. Make sure you update the macro
536 variables such as @code{HFILES} and @code{OBJS}, otherwise your code may
537 not get linked in, or, worse yet, it may not get @code{tar}red into the
542 @node Releases, BFD support for GDB, Languages, Top
543 @chapter Configuring GDB for Release
545 GDB should be released after doing @samp{./configure none} in the top
546 level directory. This will leave a makefile there, but no @file{tm-*}
547 or @file{xm-*} files. The makefile is needed, for example, for
548 @samp{make gdb.tar.Z}@dots{} If you have @file{tm-*} or @file{xm-*}
549 files in the main source directory, C's include rules cause them to be
550 used in preference to @file{tm-*} and @file{xm-*} files in the
551 subdirectories where the user will actually configure and build the
554 @samp{./configure none} is also a good way to rebuild the top level @file{Makefile}
555 after changing @file{Makefile.in}, @file{alldeps.mak}, etc.
557 @subheading TEMPORARY RELEASE PROCEDURE FOR DOCUMENTATION
559 @file{gdb.texinfo} is currently marked up using the texinfo-2 macros,
560 which are not yet a default for anything (but we have to start using
563 For making paper, the only thing this implies is the right generation of
564 @file{texinfo.tex} needs to be included in the distribution.
566 For making info files, however, rather than duplicating the texinfo2
567 distribution, generate @file{gdb-all.texinfo} locally, and include the files
568 @file{gdb.info*} in the distribution. Note the plural; @code{makeinfo} will
569 split the document into one overall file and five or so included files.
572 @node BFD support for GDB, Symbol Reading, Releases, Top
573 @chapter Binary File Descriptor Library Support for GDB
575 BFD provides support for GDB in several ways:
578 @item identifying executable and core files
579 BFD will identify a variety of file types, including a.out, coff, and
580 several variants thereof, as well as several kinds of core files.
582 @item access to sections of files
583 BFD parses the file headers to determine the names, virtual addresses,
584 sizes, and file locations of all the various named sections in files
585 (such as the text section or the data section). GDB simply calls
586 BFD to read or write section X at byte offset Y for length Z.
588 @item specialized core file support
589 BFD provides routines to determine the failing command name stored
590 in a core file, the signal with which the program failed, and whether
591 a core file matches (i.e. could be a core dump of) a particular executable
594 @item locating the symbol information
595 GDB uses an internal interface of BFD to determine where to find the
596 symbol information in an executable file or symbol-file. GDB itself
597 handles the reading of symbols, since BFD does not ``understand'' debug
598 symbols, but GDB uses BFD's cached information to find the symbols,
602 @c The interface for symbol reading is described in @ref{Symbol Reading}.
605 @node Symbol Reading, Cleanups, BFD support for GDB, Top
606 @chapter Symbol Reading
608 GDB reads symbols from "symbol files". The usual symbol file is the
609 file containing the program which gdb is debugging. GDB can be directed
610 to use a different file for symbols (with the ``symbol-file''
611 command), and it can also read more symbols via the ``add-file'' and ``load''
612 commands, or while reading symbols from shared libraries.
614 Symbol files are initially opened by @file{symfile.c} using the BFD
615 library. BFD identifies the type of the file by examining its header.
616 @code{symfile_init} then uses this identification to locate a
617 set of symbol-reading functions.
619 Symbol reading modules identify themselves to GDB by calling
620 @code{add_symtab_fns} during their module initialization. The argument
621 to @code{add_symtab_fns} is a @code{struct sym_fns} which contains
622 the name (or name prefix) of the symbol format, the length of the prefix,
623 and pointers to four functions. These functions are called at various
624 times to process symbol-files whose identification matches the specified
627 The functions supplied by each module are:
630 @item @var{xxx}_symfile_init(struct sym_fns *sf)
632 Called from @code{symbol_file_add} when we are about to read a new
633 symbol file. This function should clean up any internal state
634 (possibly resulting from half-read previous files, for example)
635 and prepare to read a new symbol file. Note that the symbol file
636 which we are reading might be a new "main" symbol file, or might
637 be a secondary symbol file whose symbols are being added to the
638 existing symbol table.
640 The argument to @code{@var{xxx}_symfile_init} is a newly allocated
641 @code{struct sym_fns} whose @code{bfd} field contains the BFD
642 for the new symbol file being read. Its @code{private} field
643 has been zeroed, and can be modified as desired. Typically,
644 a struct of private information will be @code{malloc}'d, and
645 a pointer to it will be placed in the @code{private} field.
647 There is no result from @code{@var{xxx}_symfile_init}, but it can call
648 @code{error} if it detects an unavoidable problem.
650 @item @var{xxx}_new_init()
652 Called from @code{symbol_file_add} when discarding existing symbols.
653 This function need only handle
654 the symbol-reading module's internal state; the symbol table data
655 structures visible to the rest of GDB will be discarded by
656 @code{symbol_file_add}. It has no arguments and no result.
657 It may be called after @code{@var{xxx}_symfile_init}, if a new symbol
658 table is being read, or may be called alone if all symbols are
659 simply being discarded.
661 @item @var{xxx}_symfile_read(struct sym_fns *sf, CORE_ADDR addr, int mainline)
663 Called from @code{symbol_file_add} to actually read the symbols from a
664 symbol-file into a set of psymtabs or symtabs.
666 @code{sf} points to the struct sym_fns originally passed to
667 @code{@var{xxx}_sym_init} for possible initialization. @code{addr} is the
668 offset between the file's specified start address and its true address
669 in memory. @code{mainline} is 1 if this is the main symbol table being
670 read, and 0 if a secondary symbol file (e.g. shared library or
671 dynamically loaded file) is being read.@refill
674 In addition, if a symbol-reading module creates psymtabs when
675 @var{xxx}_symfile_read is called, these psymtabs will contain a pointer to
676 a function @code{@var{xxx}_psymtab_to_symtab}, which can be called from
677 any point in the GDB symbol-handling code.
680 @item @var{xxx}_psymtab_to_symtab (struct partial_symtab *pst)
682 Called from @code{psymtab_to_symtab} (or the PSYMTAB_TO_SYMTAB
683 macro) if the psymtab has not already been read in and had its
684 @code{pst->symtab} pointer set. The argument is the psymtab
685 to be fleshed-out into a symtab. Upon return, pst->readin
686 should have been set to 1, and pst->symtab should contain a
687 pointer to the new corresponding symtab, or zero if there
688 were no symbols in that part of the symbol file.
692 @node Cleanups, Wrapping, Symbol Reading, Top
695 Cleanups are a structured way to deal with things that need to be done
696 later. When your code does something (like @code{malloc} some memory, or open
697 a file) that needs to be undone later (e.g. free the memory or close
698 the file), it can make a cleanup. The cleanup will be done at some
699 future point: when the command is finished, when an error occurs, or
700 when your code decides it's time to do cleanups.
702 You can also discard cleanups, that is, throw them away without doing
703 what they say. This is only done if you ask that it be done.
708 @item @var{old_chain} = make_cleanup (@var{function}, @var{arg});
709 Make a cleanup which will cause @var{function} to be called with @var{arg}
710 (a @code{char *}) later. The result, @var{old_chain}, is a handle that can be
711 passed to @code{do_cleanups} or @code{discard_cleanups} later. Unless you are
712 going to call @code{do_cleanups} or @code{discard_cleanups} yourself,
713 you can ignore the result from @code{make_cleanup}.
716 @item do_cleanups (@var{old_chain});
717 Perform all cleanups done since @code{make_cleanup} returned @var{old_chain}.
721 old = make_cleanup (b, 0);
725 will call @code{b()} but will not call @code{a()}. The cleanup that calls @code{a()} will remain
726 in the cleanup chain, and will be done later unless otherwise discarded.@refill
728 @item discard_cleanups (@var{old_chain});
729 Same as @code{do_cleanups} except that it just removes the cleanups from the
730 chain and does not call the specified functions.
734 Some functions, e.g. @code{fputs_filtered()} or @code{error()}, specify that they
735 ``should not be called when cleanups are not in place''. This means
736 that any actions you need to reverse in the case of an error or
737 interruption must be on the cleanup chain before you call these functions,
738 since they might never return to your code (they @samp{longjmp} instead).
741 @node Wrapping, , Cleanups, Top
742 @chapter Wrapping Output Lines
744 Output that goes through @code{printf_filtered} or @code{fputs_filtered} or
745 @code{fputs_demangled} needs only to have calls to @code{wrap_here} added
746 in places that would be good breaking points. The utility routines
747 will take care of actually wrapping if the line width is exceeded.
749 The argument to @code{wrap_here} is an indentation string which is printed
750 @emph{only} if the line breaks there. This argument is saved away and used
751 later. It must remain valid until the next call to @code{wrap_here} or
752 until a newline has been printed through the @code{*_filtered} functions.
753 Don't pass in a local variable and then return!
755 It is usually best to call @code{wrap_here()} after printing a comma or space.
756 If you call it before printing a space, make sure that your indentation
757 properly accounts for the leading space that will print if the line wraps
760 Any function or set of functions that produce filtered output must finish
761 by printing a newline, to flush the wrap buffer, before switching to
762 unfiltered (``@code{printf}'') output. Symbol reading routines that print
763 warnings are a good example.