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