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