]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/doc/gdbint.texinfo
Reorder contents; reorganize new-host, new-target, and new-config
[thirdparty/binutils-gdb.git] / gdb / doc / gdbint.texinfo
1 \input texinfo
2 @setfilename gdbint.info
3 @c $Id$
4 @ifinfo
5 This file documents the internals of the GNU debugger GDB.
6
7 Copyright (C) 1990, 1991 Free Software Foundation, Inc.
8 Contributed by Cygnus Support. Written by John Gilmore.
9
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.
13
14 @ignore
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).
19
20 @end ignore
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).
24 @end ifinfo
25
26 @setchapternewpage off
27 @settitle GDB Internals
28 @titlepage
29 @title{Working in GDB}
30 @subtitle{A guide to the internals of the GNU debugger}
31 @author John Gilmore
32 @author Cygnus Support
33 @page
34 @tex
35 \def\$#1${{#1}} % Kluge: collect RCS revision info without $...$
36 \xdef\manvers{\$Revision$} % For use in headers, footers too
37 {\parskip=0pt
38 \hfill Cygnus Support\par
39 \hfill \manvers\par
40 \hfill \TeX{}info \texinfoversion\par
41 }
42 @end tex
43
44 @vskip 0pt plus 1filll
45 Copyright @copyright{} 1990, 1991 Free Software Foundation, Inc.
46
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.
50
51 @end titlepage
52
53 @node Top, README, (dir), (dir)
54
55 @menu
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
65 * Cleanups:: Cleanups
66 * Wrapping:: Wrapping Output Lines
67
68 @end menu
69
70 @node README, New Architectures, Top, Top
71 @chapter The @file{README} File
72
73 Check the @file{README} file, it often has useful information that does not
74 appear anywhere else in the directory.
75
76
77 @node New Architectures, Config, README, Top
78 @chapter Defining a New Host or Target Architecture
79
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
86 and targets.
87
88 @heading What is considered ``host-dependent'' versus ``target-dependent''?
89
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?
95
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
98 float format.
99
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.
104
105 @c FIXME so what kinds of things are target support?
106
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
112 duplicated code.
113
114
115 @node Config, Host, New Architectures, Top
116 @chapter Adding a New Configuration
117
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
124 particular:
125
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
131 running
132
133 @example
134 ./config.sub @var{xxx}
135 @end example
136 @noindent
137 and
138 @example
139 ./config.sub @code{@var{xarch}-@var{xvend}-@var{xos}}
140 @end example
141 @noindent
142 which should both respond with @code{@var{xarch}-@var{xvend}-@var{xos}}
143 and no error messages.
144
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
148
149 @example
150 #if HOST_SYS==@var{xxx}_SYS
151 #include <sys/h-@var{xxx}.h>
152 #endif
153 @end example
154
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.
159
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:
165
166 @example
167 HDEFINES=-DHOST_SYS=@var{xxx}_SYS
168 @end example
169
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.)
173
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}.
180
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{#
189 per-target}.
190 @c Would it be simpler to just use different per-host and per-target
191 @c *scripts*, and call them from {configure} ?
192
193 Then fold your changes into the @code{configure} script by using the
194 @code{+template} option, and specifying @code{configure} itself as the
195 template:
196 @example
197 configure +template=configure
198 @end example
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!)
202
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.
206
207
208 @node Host, Target, Config, Top
209 @chapter Adding a New Host
210
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.
217
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}.
221
222 Add a file @file{gdb/xconfig/@var{xxx}} which specifies whatever object
223 files are needed as the makefile macro @samp{XDEPFILES=@dots{}}. In the
224 same file, specify the header file to describe @var{xxx} as
225 @samp{XM_FILE= xm-@var{xxx}.h}. You can also define @samp{CC},
226 @samp{REGEX} and @samp{REGEX1}, @samp{SYSV_DEFINE}, @samp{XM_CFLAGS},
227 etc. in there; see @file{Makefile.in}.
228
229 Create @file{gdb/xm-@var{xxx}.h} with the appropriate @code{#define}s
230 for your system (crib from existing @file{xm-*.h} files).
231
232 There are some ``generic'' versions of routines that can be used by
233 various host systems. These can be customized in various ways by macros
234 defined in your @file{xm-@var{xxx}.h} file. If these routines work for
235 the @var{xxx} host, you can just include the generic file's name (with
236 @samp{.o}, not @samp{.c}) in @code{XDEPFILES}.
237
238 Otherwise, if your machine needs custom support routines, you will need
239 to write routines that perform the same functions as the generic file.
240 Put them into @code{@var{xxx}-xdep.c}, and put @code{@var{xxx}-xdep.o}
241 into @code{XDEPFILES}.
242
243 @subheading Generic Host Support Files
244
245 @table @code
246
247 @item infptrace.c
248 @code{ptrace} support.
249
250 @item coredep.c:fetch_core_registers()
251 Support for reading registers out of a core file. This routine calls
252 @code{register_addr(}), see below.
253
254 @item coredep.c:register_addr()
255 If your @code{xm-@var{xxx}.h} file defines the macro
256 @code{REGISTER_U_ADDR(reg)} to be the offset within the @samp{user}
257 struct of a register (represented as a GDB register number),
258 @file{coredep.c} will define the @code{register_addr()} function and use
259 the macro in it. If you do not define @code{REGISTER_U_ADDR}, but you
260 are using the standard @code{fetch_core_registers()}, you will need to
261 define your own version of @code{register_addr()}, put it into your
262 @code{@var{xxx}-xdep.c} file, and be sure @code{@var{xxx}-xdep.o} is in
263 the @code{XDEPFILES} list. If you have your own
264 @code{fetch_core_registers()}, you may not need a separate
265 @code{register_addr()}. Many custom @code{fetch_core_registers()}
266 implementations simply locate the registers themselves.@refill
267 @end table
268
269 Object files needed when the target system is an @var{xxx} are listed
270 in the file @file{tconfig/@var{xxx}}, in the makefile macro
271 @samp{TDEPFILES = }@dots{}. The header file that defines the target
272 system should be called @file{tm-@var{xxx}.h}, and should be specified
273 as the value of @samp{TM_FILE} in @file{tconfig/@var{xxx}}. You can
274 also define @samp{TM_CFLAGS}, @samp{TM_CLIBS}, and @samp{TM_CDEPS} in
275 there; see @file{Makefile.in}.
276
277 Now, from the top level (above @file{bfd}, @file{gdb}, etc), run:
278
279 @example
280 ./configure -template=./configure
281 @end example
282
283 This will rebuild all your configure scripts, using the new
284 @file{configure.in} files that you modified. (You can also run this command
285 at any subdirectory level.) You are now ready to try configuring
286 GDB to compile for your system. Do:
287
288 @example
289 ./configure @var{xxx} +target=vxworks960
290 @end example
291
292 This will configure your system to cross-compile for VxWorks on
293 the Intel 960, which is probably not what you really want, but it's
294 a test case that works at this stage. (You haven't set up to be
295 able to debug programs that run @emph{on} @var{xxx} yet.)
296
297 If this succeeds, you can try building it all with:
298
299 @example
300 make
301 @end example
302
303 Good luck! Comments and suggestions about this section are particularly
304 welcome; send them to @samp{bug-gdb@@prep.ai.mit.edu}.
305
306 When hosting GDB on a new operating system, to make it possible to debug
307 core files, you will need to either write specific code for parsing your
308 OS's core files, or customize @file{bfd/trad-core.c}. First, use
309 whatever @code{#include} files your machine uses to define the struct of
310 registers that is accessible (possibly in the u-area) in a core file
311 (rather than @file{machine/reg.h}), and an include file that defines whatever
312 header exists on a core file (e.g. the u-area or a @samp{struct core}). Then
313 modify @code{trad_unix_core_file_p()} to use these values to set up the
314 section information for the data segment, stack segment, any other
315 segments in the core file (perhaps shared library contents or control
316 information), ``registers'' segment, and if there are two discontiguous
317 sets of registers (e.g. integer and float), the ``reg2'' segment. This
318 section information basically delimits areas in the core file in a
319 standard way, which the section-reading routines in BFD know how to seek
320 around in.
321
322 Then back in GDB, you need a matching routine called @code{fetch_core_registers()}.
323 If you can use the generic one, it's in @file{core-dep.c}; if not, it's in
324 your @file{@var{xxx}-xdep.c} file. It will be passed a char pointer
325 to the entire ``registers'' segment, its length, and a zero; or a char
326 pointer to the entire ``regs2'' segment, its length, and a 2. The
327 routine should suck out the supplied register values and install them into
328 GDB's ``registers'' array. (@xref{New Architectures}
329 for more info about this.)
330
331
332 @node Target, Languages, Host, Top
333 @chapter Adding a New Target
334
335 For a new target called @var{ttt}, first specify the configuration as
336 described in @ref{Config,,Adding a New Configuration}. If your new
337 target is the same as your new host, you've probably already done that.
338
339 Add a file @file{gdb/tconfig/@var{ttt}} which specifies whatever object
340 files are needed as the makefile macro @samp{TDEPFILES=@dots{}}. In the
341 same file, specify the header file to describe @var{ttt} as
342 @samp{TM_FILE= tm-@var{ttt}.h}. You can also define @samp{CC},
343 @samp{REGEX} and @samp{REGEX1}, @samp{SYSV_DEFINE}, @samp{XM_CFLAGS},
344 etc. in there; see @file{Makefile.in}.
345
346 Create @file{gdb/tm-@var{ttt}.h} with the appropriate @code{#define}s
347 for your system (crib from existing @file{tm-*.h} files).
348
349 When adding support for a new target machine, there are various areas
350 of support that might need change, or might be OK.
351
352 The file @file{exec.c} defines functions for accessing files that are
353 executable on the target system. These functions open and examine an
354 exec file, extract data from one, write data to one, print information
355 about one, etc. Now that executable files are handled with BFD, every
356 target should be able to use the generic exec.c rather than its
357 own custom code.
358
359 If you are using an existing object file format (a.out or COFF),
360 there is probably little to be done. See @file{bfd/doc/bfd.texinfo}
361 for more information on writing new a.out or COFF versions.
362
363 If you need to add a new object file format, you are beyond the scope
364 of this document right now. Look at the structure of the a.out
365 and COFF support, build a transfer vector (@code{xvec}) for your new format,
366 and start populating it with routines. Add it to the list in
367 @file{bfd/targets.c}.
368
369 If you are adding a new existing CPU chip (e.g. m68k family), you'll
370 need to define an @file{@var{xarch}-opcode.h} file, a
371 @file{tm-@var{xarch}.h} file that gives the basic layout of the chip
372 (registers, stack, etc), probably an @file{@var{xarch}-tdep.c} file that
373 has support routines for @file{tm-@var{xarch}.h}, etc.
374
375 If you are adding a new operating system for an existing CPU chip, add a
376 @file{tm-@var{xos}.h} file that describes the operating system
377 facilities that are unusual (extra symbol table info; the breakpoint
378 instruction needed; etc). Then write a
379 @file{tm-@var{xarch}-@var{xos}.h} that just @code{#include}s
380 @file{tm-@var{xarch}.h} and @file{tm-@var{xos}.h}. (Now that we have
381 three-part configuration names, this will probably get revised to
382 separate the @var{xos} configuration from the @var{xarch}
383 configuration.)
384
385
386 @node Languages, Releases, Target, Top
387 @chapter Adding a Source Language to GDB
388
389 To add other languages to GDB's expression parser, follow the following steps:
390
391 @table @emph
392 @item Create the expression parser.
393
394 This should reside in a file @file{@var{lang}-exp.y}. Routines for building
395 parsed expressions into a @samp{union exp_element} list are in @file{parse.c}.
396
397 Since we can't depend upon everyone having Bison, the following lines
398 @emph{must} be included at the top of the YACC parser:
399
400 @example
401 #define yyparse @var{lang}_parse
402 #define yylex @var{lang}_lex
403 #define yyerror @var{lang}_error
404 #define yylval @var{lang}_lval
405 #define yychar @var{lang}_char
406 #define yydebug @var{lang}_debug
407 #define yypact @var{lang}_pact
408 #define yyr1 @var{lang}_r1
409 #define yyr2 @var{lang}_r2
410 #define yydef @var{lang}_def
411 #define yychk @var{lang}_chk
412 #define yypgo @var{lang}_pgo
413 #define yyact @var{lang}_act
414 #define yyexca @var{lang}_exca
415 @end example
416
417 This will prevent name conflicts between the various parsers.
418
419 @item Add any evaluation routines, if necessary
420
421 If you need new opcodes (that represent the operations of the language),
422 add them to the enumerated type in @file{expression.h}. Add support
423 code for these operations in @code{eval.c:evaluate_subexp()}. Add cases
424 for new opcodes in two functions from @file{parse.c}:
425 @code{prefixify_subexp()} and @code{length_of_subexp()}. These compute
426 the number of @code{exp_element}s that a given operation takes up.
427
428 @item Update some existing code
429
430 Add an enumerated identifier for your language to the enumerated type
431 @code{enum language} in @file{defs.h}.
432
433 Update the routines in @file{language.c} so your language is included. These
434 routines include type predicates and such, which (in some cases) are
435 language dependent. If your language does not appear in the switch
436 statement, an error is reported.
437
438 Also included in @file{language.c} is the code that updates the variable
439 @code{current_language}, and the routines that translate the
440 @code{language_@var{lang}} enumerated identifier into a printable
441 string.
442
443 Update the function @code{_initialize_language} to include your language. This
444 function picks the default language upon startup, so is dependent upon
445 which languages that GDB is built for.
446
447 Update @code{symfile.c} and/or symbol-reading code so that the language of
448 each symtab (source file) is set properly. This is used to determine the
449 language to use at each stack frame level. Currently, the language
450 is set based upon the extension of the source file. If the language
451 can be better inferred from the symbol information, please set the
452 language of the symtab in the symbol-reading code.
453
454 Add helper code to @code{expprint.c:print_subexp()} to handle any new
455 expression opcodes you have added to @file{expression.h}. Also, add the
456 printed representations of your operators to @code{op_print_tab}.
457
458 @item Add a place of call
459
460 Add a call to @code{@var{lang}_parse()} and @code{@var{lang}_error} in
461 @code{parse.c:parse_exp_1()}.
462
463 @item Use macros to trim code
464
465 The user has the option of building GDB for some or all of the
466 languages. If the user decides to build GDB for the language
467 @var{lang}, then every file dependent on @file{language.h} will have the
468 macro @code{_LANG_@var{lang}} defined in it. Use @code{#ifdef}s to
469 leave out large routines that the user won't need if he or she is not
470 using your language.
471
472 Note that you do not need to do this in your YACC parser, since if GDB
473 is not build for @var{lang}, then @file{@var{lang}-exp.tab.o} (the
474 compiled form of your parser) is not linked into GDB at all.
475
476 See the file @file{configure.in} for how GDB is configured for different
477 languages.
478
479 @item Edit @file{Makefile.in}
480
481 Add dependencies in @file{Makefile.in}. Make sure you update the macro
482 variables such as @code{HFILES} and @code{OBJS}, otherwise your code may
483 not get linked in, or, worse yet, it may not get @code{tar}red into the
484 distribution!
485 @end table
486
487
488 @node Releases, BFD support for GDB, Languages, Top
489 @chapter Configuring GDB for Release
490
491 GDB should be released after doing @samp{./configure none} in the top
492 level directory. This will leave a makefile there, but no @file{tm-*}
493 or @file{xm-*} files. The makefile is needed, for example, for
494 @samp{make gdb.tar.Z}@dots{} If you have @file{tm-*} or @file{xm-*}
495 files in the main source directory, C's include rules cause them to be
496 used in preference to @file{tm-*} and @file{xm-*} files in the
497 subdirectories where the user will actually configure and build the
498 binaries.
499
500 @samp{./configure none} is also a good way to rebuild the top level @file{Makefile}
501 after changing @file{Makefile.in}, @file{alldeps.mak}, etc.
502
503 @subheading TEMPORARY RELEASE PROCEDURE FOR DOCUMENTATION
504
505 @file{gdb.texinfo} is currently marked up using the texinfo-2 macros,
506 which are not yet a default for anything (but we have to start using
507 them sometime).
508
509 For making paper, the only thing this implies is the right generation of
510 @file{texinfo.tex} needs to be included in the distribution.
511
512 For making info files, however, rather than duplicating the texinfo2
513 distribution, generate @file{gdb-all.texinfo} locally, and include the files
514 @file{gdb.info*} in the distribution. Note the plural; @code{makeinfo} will
515 split the document into one overall file and five or so included files.
516
517
518 @node BFD support for GDB, Symbol Reading, Releases, Top
519 @chapter Binary File Descriptor Library Support for GDB
520
521 BFD provides support for GDB in several ways:
522
523 @table @emph
524 @item identifying executable and core files
525 BFD will identify a variety of file types, including a.out, coff, and
526 several variants thereof, as well as several kinds of core files.
527
528 @item access to sections of files
529 BFD parses the file headers to determine the names, virtual addresses,
530 sizes, and file locations of all the various named sections in files
531 (such as the text section or the data section). GDB simply calls
532 BFD to read or write section X at byte offset Y for length Z.
533
534 @item specialized core file support
535 BFD provides routines to determine the failing command name stored
536 in a core file, the signal with which the program failed, and whether
537 a core file matches (i.e. could be a core dump of) a particular executable
538 file.
539
540 @item locating the symbol information
541 GDB uses an internal interface of BFD to determine where to find the
542 symbol information in an executable file or symbol-file. GDB itself
543 handles the reading of symbols, since BFD does not ``understand'' debug
544 symbols, but GDB uses BFD's cached information to find the symbols,
545 string table, etc.
546 @end table
547
548 @c The interface for symbol reading is described in @ref{Symbol Reading}.
549
550
551 @node Symbol Reading, Cleanups, BFD support for GDB, Top
552 @chapter Symbol Reading
553
554 GDB reads symbols from "symbol files". The usual symbol file is the
555 file containing the program which gdb is debugging. GDB can be directed
556 to use a different file for symbols (with the ``symbol-file''
557 command), and it can also read more symbols via the ``add-file'' and ``load''
558 commands, or while reading symbols from shared libraries.
559
560 Symbol files are initially opened by @file{symfile.c} using the BFD
561 library. BFD identifies the type of the file by examining its header.
562 @code{symfile_init} then uses this identification to locate a
563 set of symbol-reading functions.
564
565 Symbol reading modules identify themselves to GDB by calling
566 @code{add_symtab_fns} during their module initialization. The argument
567 to @code{add_symtab_fns} is a @code{struct sym_fns} which contains
568 the name (or name prefix) of the symbol format, the length of the prefix,
569 and pointers to four functions. These functions are called at various
570 times to process symbol-files whose identification matches the specified
571 prefix.
572
573 The functions supplied by each module are:
574
575 @table @code
576 @item @var{xxx}_symfile_init(struct sym_fns *sf)
577
578 Called from @code{symbol_file_add} when we are about to read a new
579 symbol file. This function should clean up any internal state
580 (possibly resulting from half-read previous files, for example)
581 and prepare to read a new symbol file. Note that the symbol file
582 which we are reading might be a new "main" symbol file, or might
583 be a secondary symbol file whose symbols are being added to the
584 existing symbol table.
585
586 The argument to @code{@var{xxx}_symfile_init} is a newly allocated
587 @code{struct sym_fns} whose @code{bfd} field contains the BFD
588 for the new symbol file being read. Its @code{private} field
589 has been zeroed, and can be modified as desired. Typically,
590 a struct of private information will be @code{malloc}'d, and
591 a pointer to it will be placed in the @code{private} field.
592
593 There is no result from @code{@var{xxx}_symfile_init}, but it can call
594 @code{error} if it detects an unavoidable problem.
595
596 @item @var{xxx}_new_init()
597
598 Called from @code{symbol_file_add} when discarding existing symbols.
599 This function need only handle
600 the symbol-reading module's internal state; the symbol table data
601 structures visible to the rest of GDB will be discarded by
602 @code{symbol_file_add}. It has no arguments and no result.
603 It may be called after @code{@var{xxx}_symfile_init}, if a new symbol
604 table is being read, or may be called alone if all symbols are
605 simply being discarded.
606
607 @item @var{xxx}_symfile_read(struct sym_fns *sf, CORE_ADDR addr, int mainline)
608
609 Called from @code{symbol_file_add} to actually read the symbols from a
610 symbol-file into a set of psymtabs or symtabs.
611
612 @code{sf} points to the struct sym_fns originally passed to
613 @code{@var{xxx}_sym_init} for possible initialization. @code{addr} is the
614 offset between the file's specified start address and its true address
615 in memory. @code{mainline} is 1 if this is the main symbol table being
616 read, and 0 if a secondary symbol file (e.g. shared library or
617 dynamically loaded file) is being read.@refill
618 @end table
619
620 In addition, if a symbol-reading module creates psymtabs when
621 @var{xxx}_symfile_read is called, these psymtabs will contain a pointer to
622 a function @code{@var{xxx}_psymtab_to_symtab}, which can be called from
623 any point in the GDB symbol-handling code.
624
625 @table @code
626 @item @var{xxx}_psymtab_to_symtab (struct partial_symtab *pst)
627
628 Called from @code{psymtab_to_symtab} (or the PSYMTAB_TO_SYMTAB
629 macro) if the psymtab has not already been read in and had its
630 @code{pst->symtab} pointer set. The argument is the psymtab
631 to be fleshed-out into a symtab. Upon return, pst->readin
632 should have been set to 1, and pst->symtab should contain a
633 pointer to the new corresponding symtab, or zero if there
634 were no symbols in that part of the symbol file.
635 @end table
636
637
638 @node Cleanups, Wrapping, Symbol Reading, Top
639 @chapter Cleanups
640
641 Cleanups are a structured way to deal with things that need to be done
642 later. When your code does something (like @code{malloc} some memory, or open
643 a file) that needs to be undone later (e.g. free the memory or close
644 the file), it can make a cleanup. The cleanup will be done at some
645 future point: when the command is finished, when an error occurs, or
646 when your code decides it's time to do cleanups.
647
648 You can also discard cleanups, that is, throw them away without doing
649 what they say. This is only done if you ask that it be done.
650
651 Syntax:
652
653 @table @code
654 @item @var{old_chain} = make_cleanup (@var{function}, @var{arg});
655 Make a cleanup which will cause @var{function} to be called with @var{arg}
656 (a @code{char *}) later. The result, @var{old_chain}, is a handle that can be
657 passed to @code{do_cleanups} or @code{discard_cleanups} later. Unless you are
658 going to call @code{do_cleanups} or @code{discard_cleanups} yourself,
659 you can ignore the result from @code{make_cleanup}.
660
661
662 @item do_cleanups (@var{old_chain});
663 Perform all cleanups done since @code{make_cleanup} returned @var{old_chain}.
664 E.g.:
665 @example
666 make_cleanup (a, 0);
667 old = make_cleanup (b, 0);
668 do_cleanups (old);
669 @end example
670 @noindent
671 will call @code{b()} but will not call @code{a()}. The cleanup that calls @code{a()} will remain
672 in the cleanup chain, and will be done later unless otherwise discarded.@refill
673
674 @item discard_cleanups (@var{old_chain});
675 Same as @code{do_cleanups} except that it just removes the cleanups from the
676 chain and does not call the specified functions.
677
678 @end table
679
680 Some functions, e.g. @code{fputs_filtered()} or @code{error()}, specify that they
681 ``should not be called when cleanups are not in place''. This means
682 that any actions you need to reverse in the case of an error or
683 interruption must be on the cleanup chain before you call these functions,
684 since they might never return to your code (they @samp{longjmp} instead).
685
686
687 @node Wrapping, , Cleanups, Top
688 @chapter Wrapping Output Lines
689
690 Output that goes through @code{printf_filtered} or @code{fputs_filtered} or
691 @code{fputs_demangled} needs only to have calls to @code{wrap_here} added
692 in places that would be good breaking points. The utility routines
693 will take care of actually wrapping if the line width is exceeded.
694
695 The argument to @code{wrap_here} is an indentation string which is printed
696 @emph{only} if the line breaks there. This argument is saved away and used
697 later. It must remain valid until the next call to @code{wrap_here} or
698 until a newline has been printed through the @code{*_filtered} functions.
699 Don't pass in a local variable and then return!
700
701 It is usually best to call @code{wrap_here()} after printing a comma or space.
702 If you call it before printing a space, make sure that your indentation
703 properly accounts for the leading space that will print if the line wraps
704 there.
705
706 Any function or set of functions that produce filtered output must finish
707 by printing a newline, to flush the wrap buffer, before switching to
708 unfiltered (``@code{printf}'') output. Symbol reading routines that print
709 warnings are a good example.
710
711
712 @contents
713 @bye
714