d8299584e0de482ae9c6d4fb90e1417e9665d8f4
[deliverable/binutils-gdb.git] / gdb / doc / gdbint.texinfo
1 \input texinfo
2 @setfilename gdbint.info
3
4 @ifinfo
5 @format
6 START-INFO-DIR-ENTRY
7 * Gdb-Internals: (gdbint). The GNU debugger's internals.
8 END-INFO-DIR-ENTRY
9 @end format
10 @end ifinfo
11
12 @ifinfo
13 This file documents the internals of the GNU debugger GDB.
14
15 Copyright 1990-1999 Free Software Foundation, Inc.
16 Contributed by Cygnus Solutions. Written by John Gilmore.
17 Second Edition by Stan Shebs.
18
19 Permission is granted to make and distribute verbatim copies of this
20 manual provided the copyright notice and this permission notice are
21 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 notice
26 identical to this one except for the removal of this paragraph (this
27 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
38 @titlepage
39 @title{GDB Internals}
40 @subtitle{A guide to the internals of the GNU debugger}
41 @author John Gilmore
42 @author Cygnus Solutions
43 @author Second Edition:
44 @author Stan Shebs
45 @author Cygnus Solutions
46 @page
47 @tex
48 \def\$#1${{#1}} % Kluge: collect RCS revision info without $...$
49 \xdef\manvers{\$Revision$} % For use in headers, footers too
50 {\parskip=0pt
51 \hfill Cygnus Solutions\par
52 \hfill \manvers\par
53 \hfill \TeX{}info \texinfoversion\par
54 }
55 @end tex
56
57 @vskip 0pt plus 1filll
58 Copyright @copyright{} 1990-1999 Free Software Foundation, Inc.
59
60 Permission is granted to make and distribute verbatim copies of
61 this manual provided the copyright notice and this permission notice
62 are preserved on all copies.
63
64 @end titlepage
65
66 @node Top
67 @c Perhaps this should be the title of the document (but only for info,
68 @c not for TeX). Existing GNU manuals seem inconsistent on this point.
69 @top Scope of this Document
70
71 This document documents the internals of the GNU debugger, GDB. It
72 includes description of GDB's key algorithms and operations, as well
73 as the mechanisms that adapt GDB to specific hosts and targets.
74
75 @menu
76 * Requirements::
77 * Overall Structure::
78 * Algorithms::
79 * User Interface::
80 * Symbol Handling::
81 * Language Support::
82 * Host Definition::
83 * Target Architecture Definition::
84 * Target Vector Definition::
85 * Native Debugging::
86 * Support Libraries::
87 * Coding::
88 * Porting GDB::
89 * Hints::
90 @end menu
91
92 @node Requirements
93
94 @chapter Requirements
95
96 Before diving into the internals, you should understand the formal
97 requirements and other expectations for GDB. Although some of these may
98 seem obvious, there have been proposals for GDB that have run counter to
99 these requirements.
100
101 First of all, GDB is a debugger. It's not designed to be a front panel
102 for embedded systems. It's not a text editor. It's not a shell. It's
103 not a programming environment.
104
105 GDB is an interactive tool. Although a batch mode is available, GDB's
106 primary role is to interact with a human programmer.
107
108 GDB should be responsive to the user. A programmer hot on the trail of
109 a nasty bug, and operating under a looming deadline, is going to be very
110 impatient of everything, including the response time to debugger
111 commands.
112
113 GDB should be relatively permissive, such as for expressions. While the
114 compiler should be picky (or have the option to be made picky), since
115 source code lives for a long time usually, the programmer doing
116 debugging shouldn't be spending time figuring out to mollify the
117 debugger.
118
119 GDB will be called upon to deal with really large programs. Executable
120 sizes of 50 to 100 megabytes occur regularly, and we've heard reports of
121 programs approaching 1 gigabyte in size.
122
123 GDB should be able to run everywhere. No other debugger is available
124 for even half as many configurations as GDB supports.
125
126
127 @node Overall Structure
128
129 @chapter Overall Structure
130
131 GDB consists of three major subsystems: user interface, symbol handling
132 (the ``symbol side''), and target system handling (the ``target side'').
133
134 Ther user interface consists of several actual interfaces, plus
135 supporting code.
136
137 The symbol side consists of object file readers, debugging info
138 interpreters, symbol table management, source language expression
139 parsing, type and value printing.
140
141 The target side consists of execution control, stack frame analysis, and
142 physical target manipulation.
143
144 The target side/symbol side division is not formal, and there are a
145 number of exceptions. For instance, core file support involves symbolic
146 elements (the basic core file reader is in BFD) and target elements (it
147 supplies the contents of memory and the values of registers). Instead,
148 this division is useful for understanding how the minor subsystems
149 should fit together.
150
151 @section The Symbol Side
152
153 The symbolic side of GDB can be thought of as ``everything you can do in
154 GDB without having a live program running''. For instance, you can look
155 at the types of variables, and evaluate many kinds of expressions.
156
157 @section The Target Side
158
159 The target side of GDB is the ``bits and bytes manipulator''. Although
160 it may make reference to symbolic info here and there, most of the
161 target side will run with only a stripped executable available -- or
162 even no executable at all, in remote debugging cases.
163
164 Operations such as disassembly, stack frame crawls, and register
165 display, are able to work with no symbolic info at all. In some cases,
166 such as disassembly, GDB will use symbolic info to present addresses
167 relative to symbols rather than as raw numbers, but it will work either
168 way.
169
170 @section Configurations
171
172 @dfn{Host} refers to attributes of the system where GDB runs.
173 @dfn{Target} refers to the system where the program being debugged
174 executes. In most cases they are the same machine, in which case a
175 third type of @dfn{Native} attributes come into play.
176
177 Defines and include files needed to build on the host are host support.
178 Examples are tty support, system defined types, host byte order, host
179 float format.
180
181 Defines and information needed to handle the target format are target
182 dependent. Examples are the stack frame format, instruction set,
183 breakpoint instruction, registers, and how to set up and tear down the stack
184 to call a function.
185
186 Information that is only needed when the host and target are the same,
187 is native dependent. One example is Unix child process support; if the
188 host and target are not the same, doing a fork to start the target
189 process is a bad idea. The various macros needed for finding the
190 registers in the @code{upage}, running @code{ptrace}, and such are all
191 in the native-dependent files.
192
193 Another example of native-dependent code is support for features that
194 are really part of the target environment, but which require
195 @code{#include} files that are only available on the host system. Core
196 file handling and @code{setjmp} handling are two common cases.
197
198 When you want to make GDB work ``native'' on a particular machine, you
199 have to include all three kinds of information.
200
201
202 @node Algorithms
203
204 @chapter Algorithms
205
206 GDB uses a number of debugging-specific algorithms. They are often not
207 very complicated, but get lost in the thicket of special cases and
208 real-world issues. This chapter describes the basic algorithms and
209 mentions some of the specific target definitions that they use.
210
211 @section Frames
212
213 A frame is a construct that GDB uses to keep track of calling and called
214 functions.
215
216 @code{FRAME_FP} in the machine description has no meaning to the
217 machine-independent part of GDB, except that it is used when setting up
218 a new frame from scratch, as follows:
219
220 @example
221 create_new_frame (read_register (FP_REGNUM), read_pc ()));
222 @end example
223
224 Other than that, all the meaning imparted to @code{FP_REGNUM} is
225 imparted by the machine-dependent code. So, @code{FP_REGNUM} can have
226 any value that is convenient for the code that creates new frames.
227 (@code{create_new_frame} calls @code{INIT_EXTRA_FRAME_INFO} if it is
228 defined; that is where you should use the @code{FP_REGNUM} value, if
229 your frames are nonstandard.)
230
231 Given a GDB frame, define @code{FRAME_CHAIN} to determine the address of
232 the calling function's frame. This will be used to create a new GDB
233 frame struct, and then @code{INIT_EXTRA_FRAME_INFO} and
234 @code{INIT_FRAME_PC} will be called for the new frame.
235
236 @section Breakpoint Handling
237
238 In general, a breakpoint is a user-designated location in the program
239 where the user wants to regain control if program execution ever reaches
240 that location.
241
242 There are two main ways to implement breakpoints; either as ``hardware''
243 breakpoints or as ``software'' breakpoints.
244
245 Hardware breakpoints are sometimes available as a builtin debugging
246 features with some chips. Typically these work by having dedicated
247 register into which the breakpoint address may be stored. If the PC
248 ever matches a value in a breakpoint registers, the CPU raises an
249 exception and reports it to GDB. Another possibility is when an
250 emulator is in use; many emulators include circuitry that watches the
251 address lines coming out from the processor, and force it to stop if the
252 address matches a breakpoint's address. A third possibility is that the
253 target already has the ability to do breakpoints somehow; for instance,
254 a ROM monitor may do its own software breakpoints. So although these
255 are not literally ``hardware breakpoints'', from GDB's point of view
256 they work the same; GDB need not do nothing more than set the breakpoint
257 and wait for something to happen.
258
259 Since they depend on hardware resources, hardware breakpoints may be
260 limited in number; when the user asks for more, GDB will start trying to
261 set software breakpoints.
262
263 Software breakpoints require GDB to do somewhat more work. The basic
264 theory is that GDB will replace a program instruction a trap, illegal
265 divide, or some other instruction that will cause an exception, and then
266 when it's encountered, GDB will take the exception and stop the program.
267 When the user says to continue, GDB will restore the original
268 instruction, single-step, re-insert the trap, and continue on.
269
270 Since it literally overwrites the program being tested, the program area
271 must be writeable, so this technique won't work on programs in ROM. It
272 can also distort the behavior of programs that examine themselves,
273 although the situation would be highly unusual.
274
275 Also, the software breakpoint instruction should be the smallest size of
276 instruction, so it doesn't overwrite an instruction that might be a jump
277 target, and cause disaster when the program jumps into the middle of the
278 breakpoint instruction. (Strictly speaking, the breakpoint must be no
279 larger than the smallest interval between instructions that may be jump
280 targets; perhaps there is an architecture where only even-numbered
281 instructions may jumped to.) Note that it's possible for an instruction
282 set not to have any instructions usable for a software breakpoint,
283 although in practice only the ARC has failed to define such an
284 instruction.
285
286 The basic definition of the software breakpoint is the macro
287 @code{BREAKPOINT}.
288
289 Basic breakpoint object handling is in @file{breakpoint.c}. However,
290 much of the interesting breakpoint action is in @file{infrun.c}.
291
292 @section Single Stepping
293
294 @section Signal Handling
295
296 @section Thread Handling
297
298 @section Inferior Function Calls
299
300 @section Longjmp Support
301
302 GDB has support for figuring out that the target is doing a
303 @code{longjmp} and for stopping at the target of the jump, if we are
304 stepping. This is done with a few specialized internal breakpoints,
305 which are visible in the @code{maint info breakpoint} command.
306
307 To make this work, you need to define a macro called
308 @code{GET_LONGJMP_TARGET}, which will examine the @code{jmp_buf}
309 structure and extract the longjmp target address. Since @code{jmp_buf}
310 is target specific, you will need to define it in the appropriate
311 @file{tm-@var{xyz}.h} file. Look in @file{tm-sun4os4.h} and
312 @file{sparc-tdep.c} for examples of how to do this.
313
314 @node User Interface
315
316 @chapter User Interface
317
318 GDB has several user interfaces. Although the command-line interface
319 is the most common and most familiar, there are others.
320
321 @section Command Interpreter
322
323 The command interpreter in GDB is fairly simple. It is designed to
324 allow for the set of commands to be augmented dynamically, and also
325 has a recursive subcommand capability, where the first argument to
326 a command may itself direct a lookup on a different command list.
327
328 For instance, the @code{set} command just starts a lookup on the
329 @code{setlist} command list, while @code{set thread} recurses
330 to the @code{set_thread_cmd_list}.
331
332 To add commands in general, use @code{add_cmd}. @code{add_com} adds to
333 the main command list, and should be used for those commands. The usual
334 place to add commands is in the @code{_initialize_@var{xyz}} routines at the
335 ends of most source files.
336
337 @section Console Printing
338
339 @section TUI
340
341 @section libgdb
342
343 @code{libgdb} was an abortive project of years ago. The theory was to
344 provide an API to GDB's functionality.
345
346 @node Symbol Handling
347
348 @chapter Symbol Handling
349
350 Symbols are a key part of GDB's operation. Symbols include variables,
351 functions, and types.
352
353 @section Symbol Reading
354
355 GDB reads symbols from ``symbol files''. The usual symbol file is the
356 file containing the program which GDB is debugging. GDB can be directed
357 to use a different file for symbols (with the @code{symbol-file}
358 command), and it can also read more symbols via the ``add-file'' and
359 ``load'' commands, or while reading symbols from shared libraries.
360
361 Symbol files are initially opened by code in @file{symfile.c} using the
362 BFD library. BFD identifies the type of the file by examining its
363 header. @code{symfile_init} then uses this identification to locate a
364 set of symbol-reading functions.
365
366 Symbol reading modules identify themselves to GDB by calling
367 @code{add_symtab_fns} during their module initialization. The argument
368 to @code{add_symtab_fns} is a @code{struct sym_fns} which contains the
369 name (or name prefix) of the symbol format, the length of the prefix,
370 and pointers to four functions. These functions are called at various
371 times to process symbol-files whose identification matches the specified
372 prefix.
373
374 The functions supplied by each module are:
375
376 @table @code
377 @item @var{xyz}_symfile_init(struct sym_fns *sf)
378
379 Called from @code{symbol_file_add} when we are about to read a new
380 symbol file. This function should clean up any internal state (possibly
381 resulting from half-read previous files, for example) and prepare to
382 read a new symbol file. Note that the symbol file which we are reading
383 might be a new "main" symbol file, or might be a secondary symbol file
384 whose symbols are being added to the existing symbol table.
385
386 The argument to @code{@var{xyz}_symfile_init} is a newly allocated
387 @code{struct sym_fns} whose @code{bfd} field contains the BFD for the
388 new symbol file being read. Its @code{private} field has been zeroed,
389 and can be modified as desired. Typically, a struct of private
390 information will be @code{malloc}'d, and a pointer to it will be placed
391 in the @code{private} field.
392
393 There is no result from @code{@var{xyz}_symfile_init}, but it can call
394 @code{error} if it detects an unavoidable problem.
395
396 @item @var{xyz}_new_init()
397
398 Called from @code{symbol_file_add} when discarding existing symbols.
399 This function need only handle the symbol-reading module's internal
400 state; the symbol table data structures visible to the rest of GDB will
401 be discarded by @code{symbol_file_add}. It has no arguments and no
402 result. It may be called after @code{@var{xyz}_symfile_init}, if a new
403 symbol table is being read, or may be called alone if all symbols are
404 simply being discarded.
405
406 @item @var{xyz}_symfile_read(struct sym_fns *sf, CORE_ADDR addr, int mainline)
407
408 Called from @code{symbol_file_add} to actually read the symbols from a
409 symbol-file into a set of psymtabs or symtabs.
410
411 @code{sf} points to the struct sym_fns originally passed to
412 @code{@var{xyz}_sym_init} for possible initialization. @code{addr} is
413 the offset between the file's specified start address and its true
414 address in memory. @code{mainline} is 1 if this is the main symbol
415 table being read, and 0 if a secondary symbol file (e.g. shared library
416 or dynamically loaded file) is being read.@refill
417 @end table
418
419 In addition, if a symbol-reading module creates psymtabs when
420 @var{xyz}_symfile_read is called, these psymtabs will contain a pointer
421 to a function @code{@var{xyz}_psymtab_to_symtab}, which can be called
422 from any point in the GDB symbol-handling code.
423
424 @table @code
425 @item @var{xyz}_psymtab_to_symtab (struct partial_symtab *pst)
426
427 Called from @code{psymtab_to_symtab} (or the PSYMTAB_TO_SYMTAB macro) if
428 the psymtab has not already been read in and had its @code{pst->symtab}
429 pointer set. The argument is the psymtab to be fleshed-out into a
430 symtab. Upon return, pst->readin should have been set to 1, and
431 pst->symtab should contain a pointer to the new corresponding symtab, or
432 zero if there were no symbols in that part of the symbol file.
433 @end table
434
435 @section Partial Symbol Tables
436
437 GDB has three types of symbol tables.
438
439 @itemize @bullet
440
441 @item full symbol tables (symtabs). These contain the main information
442 about symbols and addresses.
443
444 @item partial symbol tables (psymtabs). These contain enough
445 information to know when to read the corresponding part of the full
446 symbol table.
447
448 @item minimal symbol tables (msymtabs). These contain information
449 gleaned from non-debugging symbols.
450
451 @end itemize
452
453 This section describes partial symbol tables.
454
455 A psymtab is constructed by doing a very quick pass over an executable
456 file's debugging information. Small amounts of information are
457 extracted -- enough to identify which parts of the symbol table will
458 need to be re-read and fully digested later, when the user needs the
459 information. The speed of this pass causes GDB to start up very
460 quickly. Later, as the detailed rereading occurs, it occurs in small
461 pieces, at various times, and the delay therefrom is mostly invisible to
462 the user.
463 @c (@xref{Symbol Reading}.)
464
465 The symbols that show up in a file's psymtab should be, roughly, those
466 visible to the debugger's user when the program is not running code from
467 that file. These include external symbols and types, static symbols and
468 types, and enum values declared at file scope.
469
470 The psymtab also contains the range of instruction addresses that the
471 full symbol table would represent.
472
473 The idea is that there are only two ways for the user (or much of the
474 code in the debugger) to reference a symbol:
475
476 @itemize @bullet
477
478 @item by its address
479 (e.g. execution stops at some address which is inside a function in this
480 file). The address will be noticed to be in the range of this psymtab,
481 and the full symtab will be read in. @code{find_pc_function},
482 @code{find_pc_line}, and other @code{find_pc_@dots{}} functions handle
483 this.
484
485 @item by its name
486 (e.g. the user asks to print a variable, or set a breakpoint on a
487 function). Global names and file-scope names will be found in the
488 psymtab, which will cause the symtab to be pulled in. Local names will
489 have to be qualified by a global name, or a file-scope name, in which
490 case we will have already read in the symtab as we evaluated the
491 qualifier. Or, a local symbol can be referenced when we are "in" a
492 local scope, in which case the first case applies. @code{lookup_symbol}
493 does most of the work here.
494
495 @end itemize
496
497 The only reason that psymtabs exist is to cause a symtab to be read in
498 at the right moment. Any symbol that can be elided from a psymtab,
499 while still causing that to happen, should not appear in it. Since
500 psymtabs don't have the idea of scope, you can't put local symbols in
501 them anyway. Psymtabs don't have the idea of the type of a symbol,
502 either, so types need not appear, unless they will be referenced by
503 name.
504
505 It is a bug for GDB to behave one way when only a psymtab has been read,
506 and another way if the corresponding symtab has been read in. Such bugs
507 are typically caused by a psymtab that does not contain all the visible
508 symbols, or which has the wrong instruction address ranges.
509
510 The psymtab for a particular section of a symbol-file (objfile) could be
511 thrown away after the symtab has been read in. The symtab should always
512 be searched before the psymtab, so the psymtab will never be used (in a
513 bug-free environment). Currently, psymtabs are allocated on an obstack,
514 and all the psymbols themselves are allocated in a pair of large arrays
515 on an obstack, so there is little to be gained by trying to free them
516 unless you want to do a lot more work.
517
518 @section Types
519
520 Fundamental Types (e.g., FT_VOID, FT_BOOLEAN).
521
522 These are the fundamental types that GDB uses internally. Fundamental
523 types from the various debugging formats (stabs, ELF, etc) are mapped
524 into one of these. They are basically a union of all fundamental types
525 that gdb knows about for all the languages that GDB knows about.
526
527 Type Codes (e.g., TYPE_CODE_PTR, TYPE_CODE_ARRAY).
528
529 Each time GDB builds an internal type, it marks it with one of these
530 types. The type may be a fundamental type, such as TYPE_CODE_INT, or a
531 derived type, such as TYPE_CODE_PTR which is a pointer to another type.
532 Typically, several FT_* types map to one TYPE_CODE_* type, and are
533 distinguished by other members of the type struct, such as whether the
534 type is signed or unsigned, and how many bits it uses.
535
536 Builtin Types (e.g., builtin_type_void, builtin_type_char).
537
538 These are instances of type structs that roughly correspond to
539 fundamental types and are created as global types for GDB to use for
540 various ugly historical reasons. We eventually want to eliminate these.
541 Note for example that builtin_type_int initialized in gdbtypes.c is
542 basically the same as a TYPE_CODE_INT type that is initialized in
543 c-lang.c for an FT_INTEGER fundamental type. The difference is that the
544 builtin_type is not associated with any particular objfile, and only one
545 instance exists, while c-lang.c builds as many TYPE_CODE_INT types as
546 needed, with each one associated with some particular objfile.
547
548 @section Object File Formats
549
550 @subsection a.out
551
552 The @file{a.out} format is the original file format for Unix. It
553 consists of three sections: text, data, and bss, which are for program
554 code, initialized data, and uninitialized data, respectively.
555
556 The @file{a.out} format is so simple that it doesn't have any reserved
557 place for debugging information. (Hey, the original Unix hackers used
558 @file{adb}, which is a machine-language debugger.) The only debugging
559 format for @file{a.out} is stabs, which is encoded as a set of normal
560 symbols with distinctive attributes.
561
562 The basic @file{a.out} reader is in @file{dbxread.c}.
563
564 @subsection COFF
565
566 The COFF format was introduced with System V Release 3 (SVR3) Unix.
567 COFF files may have multiple sections, each prefixed by a header. The
568 number of sections is limited.
569
570 The COFF specification includes support for debugging. Although this
571 was a step forward, the debugging information was woefully limited. For
572 instance, it was not possible to represent code that came from an
573 included file.
574
575 The COFF reader is in @file{coffread.c}.
576
577 @subsection ECOFF
578
579 ECOFF is an extended COFF originally introduced for Mips and Alpha
580 workstations.
581
582 The basic ECOFF reader is in @file{mipsread.c}.
583
584 @subsection XCOFF
585
586 The IBM RS/6000 running AIX uses an object file format called XCOFF.
587 The COFF sections, symbols, and line numbers are used, but debugging
588 symbols are dbx-style stabs whose strings are located in the
589 @samp{.debug} section (rather than the string table). For more
590 information, see @xref{Top,,,stabs,The Stabs Debugging Format}.
591
592 The shared library scheme has a clean interface for figuring out what
593 shared libraries are in use, but the catch is that everything which
594 refers to addresses (symbol tables and breakpoints at least) needs to be
595 relocated for both shared libraries and the main executable. At least
596 using the standard mechanism this can only be done once the program has
597 been run (or the core file has been read).
598
599 @subsection PE
600
601 Windows 95 and NT use the PE (Portable Executable) format for their
602 executables. PE is basically COFF with additional headers.
603
604 While BFD includes special PE support, GDB needs only the basic
605 COFF reader.
606
607 @subsection ELF
608
609 The ELF format came with System V Release 4 (SVR4) Unix. ELF is similar
610 to COFF in being organized into a number of sections, but it removes
611 many of COFF's limitations.
612
613 The basic ELF reader is in @file{elfread.c}.
614
615 @subsection SOM
616
617 SOM is HP's object file and debug format (not to be confused with IBM's
618 SOM, which is a cross-language ABI).
619
620 The SOM reader is in @file{hpread.c}.
621
622 @subsection Other File Formats
623
624 Other file formats that have been supported by GDB include Netware
625 Loadable Modules (@file{nlmread.c}.
626
627 @section Debugging File Formats
628
629 This section describes characteristics of debugging information that
630 are independent of the object file format.
631
632 @subsection stabs
633
634 @code{stabs} started out as special symbols within the @code{a.out}
635 format. Since then, it has been encapsulated into other file
636 formats, such as COFF and ELF.
637
638 While @file{dbxread.c} does some of the basic stab processing,
639 including for encapsulated versions, @file{stabsread.c} does
640 the real work.
641
642 @subsection COFF
643
644 The basic COFF definition includes debugging information. The level
645 of support is minimal and non-extensible, and is not often used.
646
647 @subsection Mips debug (Third Eye)
648
649 ECOFF includes a definition of a special debug format.
650
651 The file @file{mdebugread.c} implements reading for this format.
652
653 @subsection DWARF 1
654
655 DWARF 1 is a debugging format that was originally designed to be
656 used with ELF in SVR4 systems.
657
658 @c CHILL_PRODUCER
659 @c GCC_PRODUCER
660 @c GPLUS_PRODUCER
661 @c LCC_PRODUCER
662 @c If defined, these are the producer strings in a DWARF 1 file. All of
663 @c these have reasonable defaults already.
664
665 The DWARF 1 reader is in @file{dwarfread.c}.
666
667 @subsection DWARF 2
668
669 DWARF 2 is an improved but incompatible version of DWARF 1.
670
671 The DWARF 2 reader is in @file{dwarf2read.c}.
672
673 @subsection SOM
674
675 Like COFF, the SOM definition includes debugging information.
676
677 @section Adding a New Symbol Reader to GDB
678
679 If you are using an existing object file format (a.out, COFF, ELF, etc),
680 there is probably little to be done.
681
682 If you need to add a new object file format, you must first add it to
683 BFD. This is beyond the scope of this document.
684
685 You must then arrange for the BFD code to provide access to the
686 debugging symbols. Generally GDB will have to call swapping routines
687 from BFD and a few other BFD internal routines to locate the debugging
688 information. As much as possible, GDB should not depend on the BFD
689 internal data structures.
690
691 For some targets (e.g., COFF), there is a special transfer vector used
692 to call swapping routines, since the external data structures on various
693 platforms have different sizes and layouts. Specialized routines that
694 will only ever be implemented by one object file format may be called
695 directly. This interface should be described in a file
696 @file{bfd/libxyz.h}, which is included by GDB.
697
698
699 @node Language Support
700
701 @chapter Language Support
702
703 GDB's language support is mainly driven by the symbol reader, although
704 it is possible for the user to set the source language manually.
705
706 GDB chooses the source language by looking at the extension of the file
707 recorded in the debug info; @code{.c} means C, @code{.f} means Fortran,
708 etc. It may also use a special-purpose language identifier if the debug
709 format supports it, such as DWARF.
710
711 @section Adding a Source Language to GDB
712
713 To add other languages to GDB's expression parser, follow the following
714 steps:
715
716 @table @emph
717 @item Create the expression parser.
718
719 This should reside in a file @file{@var{lang}-exp.y}. Routines for
720 building parsed expressions into a @samp{union exp_element} list are in
721 @file{parse.c}.
722
723 Since we can't depend upon everyone having Bison, and YACC produces
724 parsers that define a bunch of global names, the following lines
725 @emph{must} be included at the top of the YACC parser, to prevent the
726 various parsers from defining the same global names:
727
728 @example
729 #define yyparse @var{lang}_parse
730 #define yylex @var{lang}_lex
731 #define yyerror @var{lang}_error
732 #define yylval @var{lang}_lval
733 #define yychar @var{lang}_char
734 #define yydebug @var{lang}_debug
735 #define yypact @var{lang}_pact
736 #define yyr1 @var{lang}_r1
737 #define yyr2 @var{lang}_r2
738 #define yydef @var{lang}_def
739 #define yychk @var{lang}_chk
740 #define yypgo @var{lang}_pgo
741 #define yyact @var{lang}_act
742 #define yyexca @var{lang}_exca
743 #define yyerrflag @var{lang}_errflag
744 #define yynerrs @var{lang}_nerrs
745 @end example
746
747 At the bottom of your parser, define a @code{struct language_defn} and
748 initialize it with the right values for your language. Define an
749 @code{initialize_@var{lang}} routine and have it call
750 @samp{add_language(@var{lang}_language_defn)} to tell the rest of GDB
751 that your language exists. You'll need some other supporting variables
752 and functions, which will be used via pointers from your
753 @code{@var{lang}_language_defn}. See the declaration of @code{struct
754 language_defn} in @file{language.h}, and the other @file{*-exp.y} files,
755 for more information.
756
757 @item Add any evaluation routines, if necessary
758
759 If you need new opcodes (that represent the operations of the language),
760 add them to the enumerated type in @file{expression.h}. Add support
761 code for these operations in @code{eval.c:evaluate_subexp()}. Add cases
762 for new opcodes in two functions from @file{parse.c}:
763 @code{prefixify_subexp()} and @code{length_of_subexp()}. These compute
764 the number of @code{exp_element}s that a given operation takes up.
765
766 @item Update some existing code
767
768 Add an enumerated identifier for your language to the enumerated type
769 @code{enum language} in @file{defs.h}.
770
771 Update the routines in @file{language.c} so your language is included.
772 These routines include type predicates and such, which (in some cases)
773 are language dependent. If your language does not appear in the switch
774 statement, an error is reported.
775
776 Also included in @file{language.c} is the code that updates the variable
777 @code{current_language}, and the routines that translate the
778 @code{language_@var{lang}} enumerated identifier into a printable
779 string.
780
781 Update the function @code{_initialize_language} to include your
782 language. This function picks the default language upon startup, so is
783 dependent upon which languages that GDB is built for.
784
785 Update @code{allocate_symtab} in @file{symfile.c} and/or symbol-reading
786 code so that the language of each symtab (source file) is set properly.
787 This is used to determine the language to use at each stack frame level.
788 Currently, the language is set based upon the extension of the source
789 file. If the language can be better inferred from the symbol
790 information, please set the language of the symtab in the symbol-reading
791 code.
792
793 Add helper code to @code{expprint.c:print_subexp()} to handle any new
794 expression opcodes you have added to @file{expression.h}. Also, add the
795 printed representations of your operators to @code{op_print_tab}.
796
797 @item Add a place of call
798
799 Add a call to @code{@var{lang}_parse()} and @code{@var{lang}_error} in
800 @code{parse.c:parse_exp_1()}.
801
802 @item Use macros to trim code
803
804 The user has the option of building GDB for some or all of the
805 languages. If the user decides to build GDB for the language
806 @var{lang}, then every file dependent on @file{language.h} will have the
807 macro @code{_LANG_@var{lang}} defined in it. Use @code{#ifdef}s to
808 leave out large routines that the user won't need if he or she is not
809 using your language.
810
811 Note that you do not need to do this in your YACC parser, since if GDB
812 is not build for @var{lang}, then @file{@var{lang}-exp.tab.o} (the
813 compiled form of your parser) is not linked into GDB at all.
814
815 See the file @file{configure.in} for how GDB is configured for different
816 languages.
817
818 @item Edit @file{Makefile.in}
819
820 Add dependencies in @file{Makefile.in}. Make sure you update the macro
821 variables such as @code{HFILES} and @code{OBJS}, otherwise your code may
822 not get linked in, or, worse yet, it may not get @code{tar}red into the
823 distribution!
824
825 @end table
826
827
828 @node Host Definition
829
830 @chapter Host Definition
831
832 With the advent of autoconf, it's rarely necessary to have host
833 definition machinery anymore.
834
835 @section Adding a New Host
836
837 Most of GDB's host configuration support happens via autoconf. It
838 should be rare to need new host-specific definitions. GDB still uses
839 the host-specific definitions and files listed below, but these mostly
840 exist for historical reasons, and should eventually disappear.
841
842 Several files control GDB's configuration for host systems:
843
844 @table @file
845
846 @item gdb/config/@var{arch}/@var{xyz}.mh
847 Specifies Makefile fragments needed when hosting on machine @var{xyz}.
848 In particular, this lists the required machine-dependent object files,
849 by defining @samp{XDEPFILES=@dots{}}. Also specifies the header file
850 which describes host @var{xyz}, by defining @code{XM_FILE=
851 xm-@var{xyz}.h}. You can also define @code{CC}, @code{SYSV_DEFINE},
852 @code{XM_CFLAGS}, @code{XM_ADD_FILES}, @code{XM_CLIBS}, @code{XM_CDEPS},
853 etc.; see @file{Makefile.in}.
854
855 @item gdb/config/@var{arch}/xm-@var{xyz}.h
856 (@file{xm.h} is a link to this file, created by configure). Contains C
857 macro definitions describing the host system environment, such as byte
858 order, host C compiler and library.
859
860 @item gdb/@var{xyz}-xdep.c
861 Contains any miscellaneous C code required for this machine as a host.
862 On most machines it doesn't exist at all. If it does exist, put
863 @file{@var{xyz}-xdep.o} into the @code{XDEPFILES} line in
864 @file{gdb/config/@var{arch}/@var{xyz}.mh}.
865
866 @end table
867
868 @subheading Generic Host Support Files
869
870 There are some ``generic'' versions of routines that can be used by
871 various systems. These can be customized in various ways by macros
872 defined in your @file{xm-@var{xyz}.h} file. If these routines work for
873 the @var{xyz} host, you can just include the generic file's name (with
874 @samp{.o}, not @samp{.c}) in @code{XDEPFILES}.
875
876 Otherwise, if your machine needs custom support routines, you will need
877 to write routines that perform the same functions as the generic file.
878 Put them into @code{@var{xyz}-xdep.c}, and put @code{@var{xyz}-xdep.o}
879 into @code{XDEPFILES}.
880
881 @table @file
882
883 @item ser-unix.c
884 This contains serial line support for Unix systems. This is always
885 included, via the makefile variable @code{SER_HARDWIRE}; override this
886 variable in the @file{.mh} file to avoid it.
887
888 @item ser-go32.c
889 This contains serial line support for 32-bit programs running under DOS,
890 using the GO32 execution environment.
891
892 @item ser-tcp.c
893 This contains generic TCP support using sockets.
894
895 @end table
896
897 @section Host Conditionals
898
899 When GDB is configured and compiled, various macros are defined or left
900 undefined, to control compilation based on the attributes of the host
901 system. These macros and their meanings (or if the meaning is not
902 documented here, then one of the source files where they are used is
903 indicated) are:
904
905 @table @code
906
907 @item GDBINIT_FILENAME
908 The default name of GDB's initialization file (normally @file{.gdbinit}).
909
910 @item MEM_FNS_DECLARED
911 Your host config file defines this if it includes declarations of
912 @code{memcpy} and @code{memset}. Define this to avoid conflicts between
913 the native include files and the declarations in @file{defs.h}.
914
915 @item NO_SYS_FILE
916 Define this if your system does not have a @code{<sys/file.h>}.
917
918 @item SIGWINCH_HANDLER
919 If your host defines @code{SIGWINCH}, you can define this to be the name
920 of a function to be called if @code{SIGWINCH} is received.
921
922 @item SIGWINCH_HANDLER_BODY
923 Define this to expand into code that will define the function named by
924 the expansion of @code{SIGWINCH_HANDLER}.
925
926 @item ALIGN_STACK_ON_STARTUP
927 Define this if your system is of a sort that will crash in
928 @code{tgetent} if the stack happens not to be longword-aligned when
929 @code{main} is called. This is a rare situation, but is known to occur
930 on several different types of systems.
931
932 @item CRLF_SOURCE_FILES
933 Define this if host files use @code{\r\n} rather than @code{\n} as a
934 line terminator. This will cause source file listings to omit @code{\r}
935 characters when printing and it will allow \r\n line endings of files
936 which are "sourced" by gdb. It must be possible to open files in binary
937 mode using @code{O_BINARY} or, for fopen, @code{"rb"}.
938
939 @item DEFAULT_PROMPT
940 The default value of the prompt string (normally @code{"(gdb) "}).
941
942 @item DEV_TTY
943 The name of the generic TTY device, defaults to @code{"/dev/tty"}.
944
945 @item FCLOSE_PROVIDED
946 Define this if the system declares @code{fclose} in the headers included
947 in @code{defs.h}. This isn't needed unless your compiler is unusually
948 anal.
949
950 @item FOPEN_RB
951 Define this if binary files are opened the same way as text files.
952
953 @item GETENV_PROVIDED
954 Define this if the system declares @code{getenv} in its headers included
955 in @code{defs.h}. This isn't needed unless your compiler is unusually
956 anal.
957
958 @item HAVE_MMAP
959 In some cases, use the system call @code{mmap} for reading symbol
960 tables. For some machines this allows for sharing and quick updates.
961
962 @item HAVE_SIGSETMASK
963 Define this if the host system has job control, but does not define
964 @code{sigsetmask()}. Currently, this is only true of the RS/6000.
965
966 @item HAVE_TERMIO
967 Define this if the host system has @code{termio.h}.
968
969 @item HOST_BYTE_ORDER
970 The ordering of bytes in the host. This must be defined to be either
971 @code{BIG_ENDIAN} or @code{LITTLE_ENDIAN}.
972
973 @item INT_MAX
974 @item INT_MIN
975 @item LONG_MAX
976 @item UINT_MAX
977 @item ULONG_MAX
978 Values for host-side constants.
979
980 @item ISATTY
981 Substitute for isatty, if not available.
982
983 @item LONGEST
984 This is the longest integer type available on the host. If not defined,
985 it will default to @code{long long} or @code{long}, depending on
986 @code{CC_HAS_LONG_LONG}.
987
988 @item CC_HAS_LONG_LONG
989 Define this if the host C compiler supports ``long long''. This is set
990 by the configure script.
991
992 @item PRINTF_HAS_LONG_LONG
993 Define this if the host can handle printing of long long integers via
994 the printf format directive ``ll''. This is set by the configure script.
995
996 @item HAVE_LONG_DOUBLE
997 Define this if the host C compiler supports ``long double''. This is
998 set by the configure script.
999
1000 @item PRINTF_HAS_LONG_DOUBLE
1001 Define this if the host can handle printing of long double float-point
1002 numbers via the printf format directive ``Lg''. This is set by the
1003 configure script.
1004
1005 @item SCANF_HAS_LONG_DOUBLE
1006 Define this if the host can handle the parsing of long double
1007 float-point numbers via the scanf format directive directive
1008 ``Lg''. This is set by the configure script.
1009
1010 @item LSEEK_NOT_LINEAR
1011 Define this if @code{lseek (n)} does not necessarily move to byte number
1012 @code{n} in the file. This is only used when reading source files. It
1013 is normally faster to define @code{CRLF_SOURCE_FILES} when possible.
1014
1015 @item L_SET
1016 This macro is used as the argument to lseek (or, most commonly,
1017 bfd_seek). FIXME, should be replaced by SEEK_SET instead, which is the
1018 POSIX equivalent.
1019
1020 @item MALLOC_INCOMPATIBLE
1021 Define this if the system's prototype for @code{malloc} differs from the
1022 @sc{ANSI} definition.
1023
1024 @item MMAP_BASE_ADDRESS
1025 When using HAVE_MMAP, the first mapping should go at this address.
1026
1027 @item MMAP_INCREMENT
1028 when using HAVE_MMAP, this is the increment between mappings.
1029
1030 @item NEED_POSIX_SETPGID
1031 Define this to use the POSIX version of @code{setpgid} to determine
1032 whether job control is available.
1033
1034 @item NORETURN
1035 If defined, this should be one or more tokens, such as @code{volatile},
1036 that can be used in both the declaration and definition of functions to
1037 indicate that they never return. The default is already set correctly
1038 if compiling with GCC. This will almost never need to be defined.
1039
1040 @item ATTR_NORETURN
1041 If defined, this should be one or more tokens, such as
1042 @code{__attribute__ ((noreturn))}, that can be used in the declarations
1043 of functions to indicate that they never return. The default is already
1044 set correctly if compiling with GCC. This will almost never need to be
1045 defined.
1046
1047 @item USE_GENERIC_DUMMY_FRAMES
1048 Define this to 1 if the target is using the generic inferior function
1049 call code. See @code{blockframe.c} for more information.
1050
1051 @item USE_MMALLOC
1052 GDB will use the @code{mmalloc} library for memory allocation for symbol
1053 reading if this symbol is defined. Be careful defining it since there
1054 are systems on which @code{mmalloc} does not work for some reason. One
1055 example is the DECstation, where its RPC library can't cope with our
1056 redefinition of @code{malloc} to call @code{mmalloc}. When defining
1057 @code{USE_MMALLOC}, you will also have to set @code{MMALLOC} in the
1058 Makefile, to point to the mmalloc library. This define is set when you
1059 configure with --with-mmalloc.
1060
1061 @item NO_MMCHECK
1062 Define this if you are using @code{mmalloc}, but don't want the overhead
1063 of checking the heap with @code{mmcheck}. Note that on some systems,
1064 the C runtime makes calls to malloc prior to calling @code{main}, and if
1065 @code{free} is ever called with these pointers after calling
1066 @code{mmcheck} to enable checking, a memory corruption abort is certain
1067 to occur. These systems can still use mmalloc, but must define
1068 NO_MMCHECK.
1069
1070 @item MMCHECK_FORCE
1071 Define this to 1 if the C runtime allocates memory prior to
1072 @code{mmcheck} being called, but that memory is never freed so we don't
1073 have to worry about it triggering a memory corruption abort. The
1074 default is 0, which means that @code{mmcheck} will only install the heap
1075 checking functions if there has not yet been any memory allocation
1076 calls, and if it fails to install the functions, gdb will issue a
1077 warning. This is currently defined if you configure using
1078 --with-mmalloc.
1079
1080 @item NO_SIGINTERRUPT
1081 Define this to indicate that siginterrupt() is not available.
1082
1083 @item R_OK
1084 Define if this is not in a system .h file.
1085
1086 @item SEEK_CUR
1087 @item SEEK_SET
1088 Define these to appropriate value for the system lseek(), if not already
1089 defined.
1090
1091 @item STOP_SIGNAL
1092 This is the signal for stopping GDB. Defaults to SIGTSTP. (Only
1093 redefined for the Convex.)
1094
1095 @item USE_O_NOCTTY
1096 Define this if the interior's tty should be opened with the O_NOCTTY
1097 flag. (FIXME: This should be a native-only flag, but @file{inflow.c} is
1098 always linked in.)
1099
1100 @item USG
1101 Means that System V (prior to SVR4) include files are in use. (FIXME:
1102 This symbol is abused in @file{infrun.c}, @file{regex.c},
1103 @file{remote-nindy.c}, and @file{utils.c} for other things, at the
1104 moment.)
1105
1106 @item lint
1107 Define this to help placate lint in some situations.
1108
1109 @item volatile
1110 Define this to override the defaults of @code{__volatile__} or
1111 @code{/**/}.
1112
1113 @end table
1114
1115
1116 @node Target Architecture Definition
1117
1118 @chapter Target Architecture Definition
1119
1120 GDB's target architecture defines what sort of machine-language programs
1121 GDB can work with, and how it works with them.
1122
1123 At present, the target architecture definition consists of a number of C
1124 macros.
1125
1126 @section Registers and Memory
1127
1128 GDB's model of the target machine is rather simple. GDB assumes the
1129 machine includes a bank of registers and a block of memory. Each
1130 register may have a different size.
1131
1132 GDB does not have a magical way to match up with the compiler's idea of
1133 which registers are which; however, it is critical that they do match up
1134 accurately. The only way to make this work is to get accurate
1135 information about the order that the compiler uses, and to reflect that
1136 in the @code{REGISTER_NAME} and related macros.
1137
1138 GDB can handle big-endian, little-endian, and bi-endian architectures.
1139
1140 @section Frame Interpretation
1141
1142 @section Inferior Call Setup
1143
1144 @section Compiler Characteristics
1145
1146 @section Target Conditionals
1147
1148 This section describes the macros that you can use to define the target
1149 machine.
1150
1151 @table @code
1152
1153 @item ADDITIONAL_OPTIONS
1154 @item ADDITIONAL_OPTION_CASES
1155 @item ADDITIONAL_OPTION_HANDLER
1156 @item ADDITIONAL_OPTION_HELP
1157 These are a set of macros that allow the addition of additional command
1158 line options to GDB. They are currently used only for the unsupported
1159 i960 Nindy target, and should not be used in any other configuration.
1160
1161 @item ADDR_BITS_REMOVE (addr)
1162 If a raw machine address includes any bits that are not really part of
1163 the address, then define this macro to expand into an expression that
1164 zeros those bits in @var{addr}. For example, the two low-order bits of
1165 a Motorola 88K address may be used by some kernels for their own
1166 purposes, since addresses must always be 4-byte aligned, and so are of
1167 no use for addressing. Those bits should be filtered out with an
1168 expression such as @code{((addr) & ~3)}.
1169
1170 @item BEFORE_MAIN_LOOP_HOOK
1171 Define this to expand into any code that you want to execute before the
1172 main loop starts. Although this is not, strictly speaking, a target
1173 conditional, that is how it is currently being used. Note that if a
1174 configuration were to define it one way for a host and a different way
1175 for the target, GDB will probably not compile, let alone run correctly.
1176 This is currently used only for the unsupported i960 Nindy target, and
1177 should not be used in any other configuration.
1178
1179 @item BELIEVE_PCC_PROMOTION
1180 Define if the compiler promotes a short or char parameter to an int, but
1181 still reports the parameter as its original type, rather than the
1182 promoted type.
1183
1184 @item BELIEVE_PCC_PROMOTION_TYPE
1185 Define this if GDB should believe the type of a short argument when
1186 compiled by pcc, but look within a full int space to get its value.
1187 Only defined for Sun-3 at present.
1188
1189 @item BITS_BIG_ENDIAN
1190 Define this if the numbering of bits in the targets does *not* match the
1191 endianness of the target byte order. A value of 1 means that the bits
1192 are numbered in a big-endian order, 0 means little-endian.
1193
1194 @item BREAKPOINT
1195 This is the character array initializer for the bit pattern to put into
1196 memory where a breakpoint is set. Although it's common to use a trap
1197 instruction for a breakpoint, it's not required; for instance, the bit
1198 pattern could be an invalid instruction. The breakpoint must be no
1199 longer than the shortest instruction of the architecture.
1200
1201 @var{BREAKPOINT} has been deprecated in favour of
1202 @var{BREAKPOINT_FROM_PC}.
1203
1204 @item BIG_BREAKPOINT
1205 @item LITTLE_BREAKPOINT
1206 Similar to BREAKPOINT, but used for bi-endian targets.
1207
1208 @var{BIG_BREAKPOINT} and @var{LITTLE_BREAKPOINT} have been deprecated in
1209 favour of @var{BREAKPOINT_FROM_PC}.
1210
1211 @item REMOTE_BREAKPOINT
1212 @item LITTLE_REMOTE_BREAKPOINT
1213 @item BIG_REMOTE_BREAKPOINT
1214 Similar to BREAKPOINT, but used for remote targets.
1215
1216 @var{BIG_REMOTE_BREAKPOINT} and @var{LITTLE_REMOTE_BREAKPOINT} have been
1217 deprecated in favour of @var{BREAKPOINT_FROM_PC}.
1218
1219 @item BREAKPOINT_FROM_PC (pcptr, lenptr)
1220
1221 Use the program counter to determine the contents and size of a
1222 breakpoint instruction. It returns a pointer to a string of bytes that
1223 encode a breakpoint instruction, stores the length of the string to
1224 *lenptr, and adjusts pc (if necessary) to point to the actual memory
1225 location where the breakpoint should be inserted.
1226
1227 Although it is common to use a trap instruction for a breakpoint, it's
1228 not required; for instance, the bit pattern could be an invalid
1229 instruction. The breakpoint must be no longer than the shortest
1230 instruction of the architecture.
1231
1232 Replaces all the other @var{BREAKPOINT} macros.
1233
1234 @item CALL_DUMMY_P
1235 A C expresson that is non-zero when the target suports inferior function
1236 calls.
1237
1238 @item CALL_DUMMY_WORDS
1239 Pointer to an array of @var{LONGEST} words of data containing
1240 host-byte-ordered @var{REGISTER_BYTES} sized values that partially
1241 specify the sequence of instructions needed for an inferior function
1242 call.
1243
1244 Should be deprecated in favour of a macro that uses target-byte-ordered
1245 data.
1246
1247 @item SIZEOF_CALL_DUMMY_WORDS
1248 The size of @var{CALL_DUMMY_WORDS}. When @var{CALL_DUMMY_P} this must
1249 return a positive value. See also @var{CALL_DUMMY_LENGTH}.
1250
1251 @item CALL_DUMMY
1252 A static initializer for @var{CALL_DUMMY_WORDS}. Deprecated.
1253
1254 @item CALL_DUMMY_LOCATION
1255 inferior.h
1256
1257 @item CALL_DUMMY_STACK_ADJUST
1258 Stack adjustment needed when performing an inferior function call.
1259
1260 Should be deprecated in favor of something like @var{STACK_ALIGN}.
1261
1262 @item CALL_DUMMY_STACK_ADJUST_P
1263 Predicate for use of @var{CALL_DUMMY_STACK_ADJUST}.
1264
1265 Should be deprecated in favor of something like @var{STACK_ALIGN}.
1266
1267 @item CANNOT_FETCH_REGISTER (regno)
1268 A C expression that should be nonzero if @var{regno} cannot be fetched
1269 from an inferior process. This is only relevant if
1270 @code{FETCH_INFERIOR_REGISTERS} is not defined.
1271
1272 @item CANNOT_STORE_REGISTER (regno)
1273 A C expression that should be nonzero if @var{regno} should not be
1274 written to the target. This is often the case for program counters,
1275 status words, and other special registers. If this is not defined, GDB
1276 will assume that all registers may be written.
1277
1278 @item DO_DEFERRED_STORES
1279 @item CLEAR_DEFERRED_STORES
1280 Define this to execute any deferred stores of registers into the inferior,
1281 and to cancel any deferred stores.
1282
1283 Currently only implemented correctly for native Sparc configurations?
1284
1285 @item CPLUS_MARKER
1286 Define this to expand into the character that G++ uses to distinguish
1287 compiler-generated identifiers from programmer-specified identifiers.
1288 By default, this expands into @code{'$'}. Most System V targets should
1289 define this to @code{'.'}.
1290
1291 @item DBX_PARM_SYMBOL_CLASS
1292 Hook for the @code{SYMBOL_CLASS} of a parameter when decoding DBX symbol
1293 information. In the i960, parameters can be stored as locals or as
1294 args, depending on the type of the debug record.
1295
1296 @item DECR_PC_AFTER_BREAK
1297 Define this to be the amount by which to decrement the PC after the
1298 program encounters a breakpoint. This is often the number of bytes in
1299 BREAKPOINT, though not always. For most targets this value will be 0.
1300
1301 @item DECR_PC_AFTER_HW_BREAK
1302 Similarly, for hardware breakpoints.
1303
1304 @item DISABLE_UNSETTABLE_BREAK addr
1305 If defined, this should evaluate to 1 if @var{addr} is in a shared
1306 library in which breakpoints cannot be set and so should be disabled.
1307
1308 @item DO_REGISTERS_INFO
1309 If defined, use this to print the value of a register or all registers.
1310
1311 @item END_OF_TEXT_DEFAULT
1312 This is an expression that should designate the end of the text section
1313 (? FIXME ?)
1314
1315 @item EXTRACT_RETURN_VALUE(type,regbuf,valbuf)
1316 Define this to extract a function's return value of type @var{type} from
1317 the raw register state @var{regbuf} and copy that, in virtual format,
1318 into @var{valbuf}.
1319
1320 @item EXTRACT_STRUCT_VALUE_ADDRESS(regbuf)
1321 Define this to extract from an array @var{regbuf} containing the (raw)
1322 register state, the address in which a function should return its
1323 structure value, as a CORE_ADDR (or an expression that can be used as
1324 one).
1325
1326 @item FLOAT_INFO
1327 If defined, then the `info float' command will print information about
1328 the processor's floating point unit.
1329
1330 @item FP_REGNUM
1331 The number of the frame pointer register.
1332
1333 @item FRAMELESS_FUNCTION_INVOCATION(fi)
1334 Define this to an expression that returns 1 if the function invocation
1335 represented by @var{fi} does not have a stack frame associated with it.
1336 Otherwise return 0.
1337
1338 @item FRAME_ARGS_ADDRESS_CORRECT
1339 stack.c
1340
1341 @item FRAME_CHAIN(frame)
1342 Given @var{frame}, return a pointer to the calling frame.
1343
1344 @item FRAME_CHAIN_COMBINE(chain,frame)
1345 Define this to take the frame chain pointer and the frame's nominal
1346 address and produce the nominal address of the caller's frame.
1347 Presently only defined for HP PA.
1348
1349 @item FRAME_CHAIN_VALID(chain,thisframe)
1350
1351 Define this to be an expression that returns zero if the given frame is
1352 an outermost frame, with no caller, and nonzero otherwise. Three common
1353 definitions are available. @code{default_frame_chain_valid} (the
1354 default) is nonzero if the chain pointer is nonzero and given frame's PC
1355 is not inside the startup file (such as @file{crt0.o}).
1356 @code{alternate_frame_chain_valid} is nonzero if the chain pointer is
1357 nonzero and the given frame's PC is not in @code{main()} or a known
1358 entry point function (such as @code{_start()}).
1359
1360 @item FRAME_INIT_SAVED_REGS(frame)
1361 See @file{frame.h}. Determines the address of all registers in the
1362 current stack frame storing each in @code{frame->saved_regs}. Space for
1363 @code{frame->saved_regs} shall be allocated by
1364 @code{FRAME_INIT_SAVED_REGS} using either
1365 @code{frame_saved_regs_zalloc} or @code{frame_obstack_alloc}.
1366
1367 @var{FRAME_FIND_SAVED_REGS} and @var{EXTRA_FRAME_INFO} are deprecated.
1368
1369 @item FRAME_NUM_ARGS (fi)
1370 For the frame described by @var{fi} return the number of arguments that
1371 are being passed. If the number of arguments is not known, return
1372 @code{-1}.
1373
1374 @item FRAME_SAVED_PC(frame)
1375 Given @var{frame}, return the pc saved there. That is, the return
1376 address.
1377
1378 @item FUNCTION_EPILOGUE_SIZE
1379 For some COFF targets, the @code{x_sym.x_misc.x_fsize} field of the
1380 function end symbol is 0. For such targets, you must define
1381 @code{FUNCTION_EPILOGUE_SIZE} to expand into the standard size of a
1382 function's epilogue.
1383
1384 @item GCC_COMPILED_FLAG_SYMBOL
1385 @item GCC2_COMPILED_FLAG_SYMBOL
1386 If defined, these are the names of the symbols that GDB will look for to
1387 detect that GCC compiled the file. The default symbols are
1388 @code{gcc_compiled.} and @code{gcc2_compiled.}, respectively. (Currently
1389 only defined for the Delta 68.)
1390
1391 @item GDB_TARGET_IS_HPPA
1392 This determines whether horrible kludge code in dbxread.c and
1393 partial-stab.h is used to mangle multiple-symbol-table files from
1394 HPPA's. This should all be ripped out, and a scheme like elfread.c
1395 used.
1396
1397 @item GDB_TARGET_IS_MACH386
1398 @item GDB_TARGET_IS_SUN3
1399 @item GDB_TARGET_IS_SUN386
1400 Kludges that should go away.
1401
1402 @item GET_LONGJMP_TARGET
1403 For most machines, this is a target-dependent parameter. On the
1404 DECstation and the Iris, this is a native-dependent parameter, since
1405 <setjmp.h> is needed to define it.
1406
1407 This macro determines the target PC address that longjmp() will jump to,
1408 assuming that we have just stopped at a longjmp breakpoint. It takes a
1409 CORE_ADDR * as argument, and stores the target PC value through this
1410 pointer. It examines the current state of the machine as needed.
1411
1412 @item GET_SAVED_REGISTER
1413 Define this if you need to supply your own definition for the function
1414 @code{get_saved_register}.
1415
1416 @item HAVE_REGISTER_WINDOWS
1417 Define this if the target has register windows.
1418 @item REGISTER_IN_WINDOW_P (regnum)
1419 Define this to be an expression that is 1 if the given register is in
1420 the window.
1421
1422 @item IBM6000_TARGET
1423 Shows that we are configured for an IBM RS/6000 target. This
1424 conditional should be eliminated (FIXME) and replaced by
1425 feature-specific macros. It was introduced in haste and we are
1426 repenting at leisure.
1427
1428 @item IEEE_FLOAT
1429 Define this if the target system uses IEEE-format floating point numbers.
1430
1431 @item INIT_EXTRA_FRAME_INFO (fromleaf, frame)
1432 If additional information about the frame is required this should be
1433 stored in @code{frame->extra_info}. Space for @code{frame->extra_info}
1434 is allocated using @code{frame_obstack_alloc}.
1435
1436 @item INIT_FRAME_PC (fromleaf, prev)
1437 This is a C statement that sets the pc of the frame pointed to by
1438 @var{prev}. [By default...]
1439
1440 @item INNER_THAN (lhs,rhs)
1441 Returns non-zero if stack address @var{lhs} is inner than (nearer to the
1442 stack top) stack address @var{rhs}. Define this as @code{lhs < rhs} if
1443 the target's stack grows downward in memory, or @code{lhs > rsh} if the
1444 stack grows upward.
1445
1446 @item IN_SIGTRAMP (pc, name)
1447 Define this to return true if the given @var{pc} and/or @var{name}
1448 indicates that the current function is a sigtramp.
1449
1450 @item SIGTRAMP_START (pc)
1451 @item SIGTRAMP_END (pc)
1452 Define these to be the start and end address of the sigtramp for the
1453 given @var{pc}. On machines where the address is just a compile time
1454 constant, the macro expansion will typically just ignore the supplied
1455 @var{pc}.
1456
1457 @item IN_SOLIB_CALL_TRAMPOLINE pc name
1458 Define this to evaluate to nonzero if the program is stopped in the
1459 trampoline that connects to a shared library.
1460
1461 @item IN_SOLIB_RETURN_TRAMPOLINE pc name
1462 Define this to evaluate to nonzero if the program is stopped in the
1463 trampoline that returns from a shared library.
1464
1465 @item IS_TRAPPED_INTERNALVAR (name)
1466 This is an ugly hook to allow the specification of special actions that
1467 should occur as a side-effect of setting the value of a variable
1468 internal to GDB. Currently only used by the h8500. Note that this
1469 could be either a host or target conditional.
1470
1471 @item NEED_TEXT_START_END
1472 Define this if GDB should determine the start and end addresses of the
1473 text section. (Seems dubious.)
1474
1475 @item NO_HIF_SUPPORT
1476 (Specific to the a29k.)
1477
1478 @item SOFTWARE_SINGLE_STEP_P
1479 Define this as 1 if the target does not have a hardware single-step
1480 mechanism. The macro @code{SOFTWARE_SINGLE_STEP} must also be defined.
1481
1482 @item SOFTWARE_SINGLE_STEP(signal,insert_breapoints_p)
1483 A function that inserts or removes (dependant on
1484 @var{insert_breapoints_p}) breakpoints at each possible destinations of
1485 the next instruction. See @code{sparc-tdep.c} and @code{rs6000-tdep.c}
1486 for examples.
1487
1488 @item PCC_SOL_BROKEN
1489 (Used only in the Convex target.)
1490
1491 @item PC_IN_CALL_DUMMY
1492 inferior.h
1493
1494 @item PC_LOAD_SEGMENT
1495 If defined, print information about the load segment for the program
1496 counter. (Defined only for the RS/6000.)
1497
1498 @item PC_REGNUM
1499 If the program counter is kept in a register, then define this macro to
1500 be the number of that register. This need be defined only if
1501 @code{TARGET_WRITE_PC} is not defined.
1502
1503 @item NPC_REGNUM
1504 The number of the ``next program counter'' register, if defined.
1505
1506 @item NNPC_REGNUM
1507 The number of the ``next next program counter'' register, if defined.
1508 Currently, this is only defined for the Motorola 88K.
1509
1510 @item PRINT_REGISTER_HOOK (regno)
1511 If defined, this must be a function that prints the contents of the
1512 given register to standard output.
1513
1514 @item PRINT_TYPELESS_INTEGER
1515 This is an obscure substitute for @code{print_longest} that seems to
1516 have been defined for the Convex target.
1517
1518 @item PROCESS_LINENUMBER_HOOK
1519 A hook defined for XCOFF reading.
1520
1521 @item PROLOGUE_FIRSTLINE_OVERLAP
1522 (Only used in unsupported Convex configuration.)
1523
1524 @item PS_REGNUM
1525 If defined, this is the number of the processor status register. (This
1526 definition is only used in generic code when parsing "$ps".)
1527
1528 @item POP_FRAME
1529 Used in @samp{call_function_by_hand} to remove an artificial stack
1530 frame.
1531
1532 @item PUSH_ARGUMENTS (nargs, args, sp, struct_return, struct_addr)
1533 Define this to push arguments onto the stack for inferior function
1534 call. Return the updated stack pointer value.
1535
1536 @item PUSH_DUMMY_FRAME
1537 Used in @samp{call_function_by_hand} to create an artificial stack frame.
1538
1539 @item REGISTER_BYTES
1540 The total amount of space needed to store GDB's copy of the machine's
1541 register state.
1542
1543 @item REGISTER_NAME(i)
1544 Return the name of register @var{i} as a string. May return @var{NULL}
1545 or @var{NUL} to indicate that register @var{i} is not valid.
1546
1547 @item REGISTER_NAMES
1548 Deprecated in favor of @var{REGISTER_NAME}.
1549
1550 @item REG_STRUCT_HAS_ADDR (gcc_p, type)
1551 Define this to return 1 if the given type will be passed by pointer
1552 rather than directly.
1553
1554 @item SDB_REG_TO_REGNUM
1555 Define this to convert sdb register numbers into GDB regnums. If not
1556 defined, no conversion will be done.
1557
1558 @item SHIFT_INST_REGS
1559 (Only used for m88k targets.)
1560
1561 @item SKIP_PROLOGUE (pc)
1562 A C expression that returns the address of the ``real'' code beyond the
1563 function entry prologue found at @var{pc}.
1564
1565 @item SKIP_PROLOGUE_FRAMELESS_P
1566 A C expression that should behave similarly, but that can stop as soon
1567 as the function is known to have a frame. If not defined,
1568 @code{SKIP_PROLOGUE} will be used instead.
1569
1570 @item SKIP_TRAMPOLINE_CODE (pc)
1571 If the target machine has trampoline code that sits between callers and
1572 the functions being called, then define this macro to return a new PC
1573 that is at the start of the real function.
1574
1575 @item SP_REGNUM
1576 Define this to be the number of the register that serves as the stack
1577 pointer.
1578
1579 @item STAB_REG_TO_REGNUM
1580 Define this to convert stab register numbers (as gotten from `r'
1581 declarations) into GDB regnums. If not defined, no conversion will be
1582 done.
1583
1584 @item STACK_ALIGN (addr)
1585 Define this to adjust the address to the alignment required for the
1586 processor's stack.
1587
1588 @item STEP_SKIPS_DELAY (addr)
1589 Define this to return true if the address is of an instruction with a
1590 delay slot. If a breakpoint has been placed in the instruction's delay
1591 slot, GDB will single-step over that instruction before resuming
1592 normally. Currently only defined for the Mips.
1593
1594 @item STORE_RETURN_VALUE (type, valbuf)
1595 A C expression that stores a function return value of type @var{type},
1596 where @var{valbuf} is the address of the value to be stored.
1597
1598 @item SUN_FIXED_LBRAC_BUG
1599 (Used only for Sun-3 and Sun-4 targets.)
1600
1601 @item SYMBOL_RELOADING_DEFAULT
1602 The default value of the `symbol-reloading' variable. (Never defined in
1603 current sources.)
1604
1605 @item TARGET_BYTE_ORDER_DEFAULT
1606 The ordering of bytes in the target. This must be either
1607 @code{BIG_ENDIAN} or @code{LITTLE_ENDIAN}. This macro replaces
1608 @var{TARGET_BYTE_ORDER} which is deprecated.
1609
1610 @item TARGET_BYTE_ORDER_SELECTABLE_P
1611 Non-zero if the target has both @code{BIG_ENDIAN} and
1612 @code{LITTLE_ENDIAN} variants. This macro replaces
1613 @var{TARGET_BYTE_ORDER_SELECTABLE} which is deprecated.
1614
1615 @item TARGET_CHAR_BIT
1616 Number of bits in a char; defaults to 8.
1617
1618 @item TARGET_COMPLEX_BIT
1619 Number of bits in a complex number; defaults to @code{2 * TARGET_FLOAT_BIT}.
1620
1621 @item TARGET_DOUBLE_BIT
1622 Number of bits in a double float; defaults to @code{8 * TARGET_CHAR_BIT}.
1623
1624 @item TARGET_DOUBLE_COMPLEX_BIT
1625 Number of bits in a double complex; defaults to @code{2 * TARGET_DOUBLE_BIT}.
1626
1627 @item TARGET_FLOAT_BIT
1628 Number of bits in a float; defaults to @code{4 * TARGET_CHAR_BIT}.
1629
1630 @item TARGET_INT_BIT
1631 Number of bits in an integer; defaults to @code{4 * TARGET_CHAR_BIT}.
1632
1633 @item TARGET_LONG_BIT
1634 Number of bits in a long integer; defaults to @code{4 * TARGET_CHAR_BIT}.
1635
1636 @item TARGET_LONG_DOUBLE_BIT
1637 Number of bits in a long double float;
1638 defaults to @code{2 * TARGET_DOUBLE_BIT}.
1639
1640 @item TARGET_LONG_LONG_BIT
1641 Number of bits in a long long integer; defaults to @code{2 * TARGET_LONG_BIT}.
1642
1643 @item TARGET_PTR_BIT
1644 Number of bits in a pointer; defaults to @code{TARGET_INT_BIT}.
1645
1646 @item TARGET_SHORT_BIT
1647 Number of bits in a short integer; defaults to @code{2 * TARGET_CHAR_BIT}.
1648
1649 @item TARGET_READ_PC
1650 @item TARGET_WRITE_PC (val, pid)
1651 @item TARGET_READ_SP
1652 @item TARGET_WRITE_SP
1653 @item TARGET_READ_FP
1654 @item TARGET_WRITE_FP
1655 These change the behavior of @code{read_pc}, @code{write_pc},
1656 @code{read_sp}, @code{write_sp}, @code{read_fp} and @code{write_fp}.
1657 For most targets, these may be left undefined. GDB will call the read
1658 and write register functions with the relevant @code{_REGNUM} argument.
1659
1660 These macros are useful when a target keeps one of these registers in a
1661 hard to get at place; for example, part in a segment register and part
1662 in an ordinary register.
1663
1664 @item TARGET_VIRTUAL_FRAME_POINTER(pc,regp,offsetp)
1665 Returns a @code{(register, offset)} pair representing the virtual
1666 frame pointer in use at the code address @code{"pc"}. If virtual
1667 frame pointers are not used, a default definition simply returns
1668 @code{FP_REGNUM}, with an offset of zero.
1669
1670 @item USE_STRUCT_CONVENTION (gcc_p, type)
1671 If defined, this must be an expression that is nonzero if a value of the
1672 given @var{type} being returned from a function must have space
1673 allocated for it on the stack. @var{gcc_p} is true if the function
1674 being considered is known to have been compiled by GCC; this is helpful
1675 for systems where GCC is known to use different calling convention than
1676 other compilers.
1677
1678 @item VARIABLES_INSIDE_BLOCK (desc, gcc_p)
1679 For dbx-style debugging information, if the compiler puts variable
1680 declarations inside LBRAC/RBRAC blocks, this should be defined to be
1681 nonzero. @var{desc} is the value of @code{n_desc} from the
1682 @code{N_RBRAC} symbol, and @var{gcc_p} is true if GDB has noticed the
1683 presence of either the @code{GCC_COMPILED_SYMBOL} or the
1684 @code{GCC2_COMPILED_SYMBOL}. By default, this is 0.
1685
1686 @item OS9K_VARIABLES_INSIDE_BLOCK (desc, gcc_p)
1687 Similarly, for OS/9000. Defaults to 1.
1688
1689 @end table
1690
1691 Motorola M68K target conditionals.
1692
1693 @table @code
1694
1695 @item BPT_VECTOR
1696 Define this to be the 4-bit location of the breakpoint trap vector. If
1697 not defined, it will default to @code{0xf}.
1698
1699 @item REMOTE_BPT_VECTOR
1700 Defaults to @code{1}.
1701
1702 @end table
1703
1704 @section Adding a New Target
1705
1706 The following files define a target to GDB:
1707
1708 @table @file
1709
1710 @item gdb/config/@var{arch}/@var{ttt}.mt
1711 Contains a Makefile fragment specific to this target. Specifies what
1712 object files are needed for target @var{ttt}, by defining
1713 @samp{TDEPFILES=@dots{}}. Also specifies the header file which
1714 describes @var{ttt}, by defining @samp{TM_FILE= tm-@var{ttt}.h}. You
1715 can also define @samp{TM_CFLAGS}, @samp{TM_CLIBS}, @samp{TM_CDEPS}, but
1716 these are now deprecated and may go away in future versions of GDB.
1717
1718 @item gdb/config/@var{arch}/tm-@var{ttt}.h
1719 (@file{tm.h} is a link to this file, created by configure). Contains
1720 macro definitions about the target machine's registers, stack frame
1721 format and instructions.
1722
1723 @item gdb/@var{ttt}-tdep.c
1724 Contains any miscellaneous code required for this target machine. On
1725 some machines it doesn't exist at all. Sometimes the macros in
1726 @file{tm-@var{ttt}.h} become very complicated, so they are implemented
1727 as functions here instead, and the macro is simply defined to call the
1728 function. This is vastly preferable, since it is easier to understand
1729 and debug.
1730
1731 @item gdb/config/@var{arch}/tm-@var{arch}.h
1732 This often exists to describe the basic layout of the target machine's
1733 processor chip (registers, stack, etc). If used, it is included by
1734 @file{tm-@var{ttt}.h}. It can be shared among many targets that use the
1735 same processor.
1736
1737 @item gdb/@var{arch}-tdep.c
1738 Similarly, there are often common subroutines that are shared by all
1739 target machines that use this particular architecture.
1740
1741 @end table
1742
1743 If you are adding a new operating system for an existing CPU chip, add a
1744 @file{config/tm-@var{os}.h} file that describes the operating system
1745 facilities that are unusual (extra symbol table info; the breakpoint
1746 instruction needed; etc). Then write a @file{@var{arch}/tm-@var{os}.h}
1747 that just @code{#include}s @file{tm-@var{arch}.h} and
1748 @file{config/tm-@var{os}.h}.
1749
1750
1751 @node Target Vector Definition
1752
1753 @chapter Target Vector Definition
1754
1755 The target vector defines the interface between GDB's abstract handling
1756 of target systems, and the nitty-gritty code that actually exercises
1757 control over a process or a serial port. GDB includes some 30-40
1758 different target vectors; however, each configuration of GDB includes
1759 only a few of them.
1760
1761 @section File Targets
1762
1763 Both executables and core files have target vectors.
1764
1765 @section Standard Protocol and Remote Stubs
1766
1767 GDB's file @file{remote.c} talks a serial protocol to code that runs in
1768 the target system. GDB provides several sample ``stubs'' that can be
1769 integrated into target programs or operating systems for this purpose;
1770 they are named @file{*-stub.c}.
1771
1772 The GDB user's manual describes how to put such a stub into your target
1773 code. What follows is a discussion of integrating the SPARC stub into a
1774 complicated operating system (rather than a simple program), by Stu
1775 Grossman, the author of this stub.
1776
1777 The trap handling code in the stub assumes the following upon entry to
1778 trap_low:
1779
1780 @enumerate
1781
1782 @item %l1 and %l2 contain pc and npc respectively at the time of the trap
1783
1784 @item traps are disabled
1785
1786 @item you are in the correct trap window
1787
1788 @end enumerate
1789
1790 As long as your trap handler can guarantee those conditions, then there
1791 is no reason why you shouldn't be able to `share' traps with the stub.
1792 The stub has no requirement that it be jumped to directly from the
1793 hardware trap vector. That is why it calls @code{exceptionHandler()},
1794 which is provided by the external environment. For instance, this could
1795 setup the hardware traps to actually execute code which calls the stub
1796 first, and then transfers to its own trap handler.
1797
1798 For the most point, there probably won't be much of an issue with
1799 `sharing' traps, as the traps we use are usually not used by the kernel,
1800 and often indicate unrecoverable error conditions. Anyway, this is all
1801 controlled by a table, and is trivial to modify. The most important
1802 trap for us is for @code{ta 1}. Without that, we can't single step or
1803 do breakpoints. Everything else is unnecessary for the proper operation
1804 of the debugger/stub.
1805
1806 From reading the stub, it's probably not obvious how breakpoints work.
1807 They are simply done by deposit/examine operations from GDB.
1808
1809 @section ROM Monitor Interface
1810
1811 @section Custom Protocols
1812
1813 @section Transport Layer
1814
1815 @section Builtin Simulator
1816
1817
1818 @node Native Debugging
1819
1820 @chapter Native Debugging
1821
1822 Several files control GDB's configuration for native support:
1823
1824 @table @file
1825
1826 @item gdb/config/@var{arch}/@var{xyz}.mh
1827 Specifies Makefile fragments needed when hosting @emph{or native} on
1828 machine @var{xyz}. In particular, this lists the required
1829 native-dependent object files, by defining @samp{NATDEPFILES=@dots{}}.
1830 Also specifies the header file which describes native support on
1831 @var{xyz}, by defining @samp{NAT_FILE= nm-@var{xyz}.h}. You can also
1832 define @samp{NAT_CFLAGS}, @samp{NAT_ADD_FILES}, @samp{NAT_CLIBS},
1833 @samp{NAT_CDEPS}, etc.; see @file{Makefile.in}.
1834
1835 @item gdb/config/@var{arch}/nm-@var{xyz}.h
1836 (@file{nm.h} is a link to this file, created by configure). Contains C
1837 macro definitions describing the native system environment, such as
1838 child process control and core file support.
1839
1840 @item gdb/@var{xyz}-nat.c
1841 Contains any miscellaneous C code required for this native support of
1842 this machine. On some machines it doesn't exist at all.
1843
1844 @end table
1845
1846 There are some ``generic'' versions of routines that can be used by
1847 various systems. These can be customized in various ways by macros
1848 defined in your @file{nm-@var{xyz}.h} file. If these routines work for
1849 the @var{xyz} host, you can just include the generic file's name (with
1850 @samp{.o}, not @samp{.c}) in @code{NATDEPFILES}.
1851
1852 Otherwise, if your machine needs custom support routines, you will need
1853 to write routines that perform the same functions as the generic file.
1854 Put them into @code{@var{xyz}-nat.c}, and put @code{@var{xyz}-nat.o}
1855 into @code{NATDEPFILES}.
1856
1857 @table @file
1858
1859 @item inftarg.c
1860 This contains the @emph{target_ops vector} that supports Unix child
1861 processes on systems which use ptrace and wait to control the child.
1862
1863 @item procfs.c
1864 This contains the @emph{target_ops vector} that supports Unix child
1865 processes on systems which use /proc to control the child.
1866
1867 @item fork-child.c
1868 This does the low-level grunge that uses Unix system calls to do a "fork
1869 and exec" to start up a child process.
1870
1871 @item infptrace.c
1872 This is the low level interface to inferior processes for systems using
1873 the Unix @code{ptrace} call in a vanilla way.
1874
1875 @end table
1876
1877 @section Native core file Support
1878
1879 @table @file
1880
1881 @item core-aout.c::fetch_core_registers()
1882 Support for reading registers out of a core file. This routine calls
1883 @code{register_addr()}, see below. Now that BFD is used to read core
1884 files, virtually all machines should use @code{core-aout.c}, and should
1885 just provide @code{fetch_core_registers} in @code{@var{xyz}-nat.c} (or
1886 @code{REGISTER_U_ADDR} in @code{nm-@var{xyz}.h}).
1887
1888 @item core-aout.c::register_addr()
1889 If your @code{nm-@var{xyz}.h} file defines the macro
1890 @code{REGISTER_U_ADDR(addr, blockend, regno)}, it should be defined to
1891 set @code{addr} to the offset within the @samp{user} struct of GDB
1892 register number @code{regno}. @code{blockend} is the offset within the
1893 ``upage'' of @code{u.u_ar0}. If @code{REGISTER_U_ADDR} is defined,
1894 @file{core-aout.c} will define the @code{register_addr()} function and
1895 use the macro in it. If you do not define @code{REGISTER_U_ADDR}, but
1896 you are using the standard @code{fetch_core_registers()}, you will need
1897 to define your own version of @code{register_addr()}, put it into your
1898 @code{@var{xyz}-nat.c} file, and be sure @code{@var{xyz}-nat.o} is in
1899 the @code{NATDEPFILES} list. If you have your own
1900 @code{fetch_core_registers()}, you may not need a separate
1901 @code{register_addr()}. Many custom @code{fetch_core_registers()}
1902 implementations simply locate the registers themselves.@refill
1903
1904 @end table
1905
1906 When making GDB run native on a new operating system, to make it
1907 possible to debug core files, you will need to either write specific
1908 code for parsing your OS's core files, or customize
1909 @file{bfd/trad-core.c}. First, use whatever @code{#include} files your
1910 machine uses to define the struct of registers that is accessible
1911 (possibly in the u-area) in a core file (rather than
1912 @file{machine/reg.h}), and an include file that defines whatever header
1913 exists on a core file (e.g. the u-area or a @samp{struct core}). Then
1914 modify @code{trad_unix_core_file_p()} to use these values to set up the
1915 section information for the data segment, stack segment, any other
1916 segments in the core file (perhaps shared library contents or control
1917 information), ``registers'' segment, and if there are two discontiguous
1918 sets of registers (e.g. integer and float), the ``reg2'' segment. This
1919 section information basically delimits areas in the core file in a
1920 standard way, which the section-reading routines in BFD know how to seek
1921 around in.
1922
1923 Then back in GDB, you need a matching routine called
1924 @code{fetch_core_registers()}. If you can use the generic one, it's in
1925 @file{core-aout.c}; if not, it's in your @file{@var{xyz}-nat.c} file.
1926 It will be passed a char pointer to the entire ``registers'' segment,
1927 its length, and a zero; or a char pointer to the entire ``regs2''
1928 segment, its length, and a 2. The routine should suck out the supplied
1929 register values and install them into GDB's ``registers'' array.
1930
1931 If your system uses @file{/proc} to control processes, and uses ELF
1932 format core files, then you may be able to use the same routines for
1933 reading the registers out of processes and out of core files.
1934
1935 @section ptrace
1936
1937 @section /proc
1938
1939 @section win32
1940
1941 @section shared libraries
1942
1943 @section Native Conditionals
1944
1945 When GDB is configured and compiled, various macros are defined or left
1946 undefined, to control compilation when the host and target systems are
1947 the same. These macros should be defined (or left undefined) in
1948 @file{nm-@var{system}.h}.
1949
1950 @table @code
1951
1952 @item ATTACH_DETACH
1953 If defined, then GDB will include support for the @code{attach} and
1954 @code{detach} commands.
1955
1956 @item CHILD_PREPARE_TO_STORE
1957 If the machine stores all registers at once in the child process, then
1958 define this to ensure that all values are correct. This usually entails
1959 a read from the child.
1960
1961 [Note that this is incorrectly defined in @file{xm-@var{system}.h} files
1962 currently.]
1963
1964 @item FETCH_INFERIOR_REGISTERS
1965 Define this if the native-dependent code will provide its own routines
1966 @code{fetch_inferior_registers} and @code{store_inferior_registers} in
1967 @file{@var{HOST}-nat.c}. If this symbol is @emph{not} defined, and
1968 @file{infptrace.c} is included in this configuration, the default
1969 routines in @file{infptrace.c} are used for these functions.
1970
1971 @item FILES_INFO_HOOK
1972 (Only defined for Convex.)
1973
1974 @item FP0_REGNUM
1975 This macro is normally defined to be the number of the first floating
1976 point register, if the machine has such registers. As such, it would
1977 appear only in target-specific code. However, /proc support uses this
1978 to decide whether floats are in use on this target.
1979
1980 @item GET_LONGJMP_TARGET
1981 For most machines, this is a target-dependent parameter. On the
1982 DECstation and the Iris, this is a native-dependent parameter, since
1983 <setjmp.h> is needed to define it.
1984
1985 This macro determines the target PC address that longjmp() will jump to,
1986 assuming that we have just stopped at a longjmp breakpoint. It takes a
1987 CORE_ADDR * as argument, and stores the target PC value through this
1988 pointer. It examines the current state of the machine as needed.
1989
1990 @item KERNEL_U_ADDR
1991 Define this to the address of the @code{u} structure (the ``user
1992 struct'', also known as the ``u-page'') in kernel virtual memory. GDB
1993 needs to know this so that it can subtract this address from absolute
1994 addresses in the upage, that are obtained via ptrace or from core files.
1995 On systems that don't need this value, set it to zero.
1996
1997 @item KERNEL_U_ADDR_BSD
1998 Define this to cause GDB to determine the address of @code{u} at
1999 runtime, by using Berkeley-style @code{nlist} on the kernel's image in
2000 the root directory.
2001
2002 @item KERNEL_U_ADDR_HPUX
2003 Define this to cause GDB to determine the address of @code{u} at
2004 runtime, by using HP-style @code{nlist} on the kernel's image in the
2005 root directory.
2006
2007 @item ONE_PROCESS_WRITETEXT
2008 Define this to be able to, when a breakpoint insertion fails, warn the
2009 user that another process may be running with the same executable.
2010
2011 @item PROC_NAME_FMT
2012 Defines the format for the name of a @file{/proc} device. Should be
2013 defined in @file{nm.h} @emph{only} in order to override the default
2014 definition in @file{procfs.c}.
2015
2016 @item PTRACE_FP_BUG
2017 mach386-xdep.c
2018
2019 @item PTRACE_ARG3_TYPE
2020 The type of the third argument to the @code{ptrace} system call, if it
2021 exists and is different from @code{int}.
2022
2023 @item REGISTER_U_ADDR
2024 Defines the offset of the registers in the ``u area''.
2025
2026 @item SHELL_COMMAND_CONCAT
2027 If defined, is a string to prefix on the shell command used to start the
2028 inferior.
2029
2030 @item SHELL_FILE
2031 If defined, this is the name of the shell to use to run the inferior.
2032 Defaults to @code{"/bin/sh"}.
2033
2034 @item SOLIB_ADD (filename, from_tty, targ)
2035 Define this to expand into an expression that will cause the symbols in
2036 @var{filename} to be added to GDB's symbol table.
2037
2038 @item SOLIB_CREATE_INFERIOR_HOOK
2039 Define this to expand into any shared-library-relocation code that you
2040 want to be run just after the child process has been forked.
2041
2042 @item START_INFERIOR_TRAPS_EXPECTED
2043 When starting an inferior, GDB normally expects to trap twice; once when
2044 the shell execs, and once when the program itself execs. If the actual
2045 number of traps is something other than 2, then define this macro to
2046 expand into the number expected.
2047
2048 @item SVR4_SHARED_LIBS
2049 Define this to indicate that SVR4-style shared libraries are in use.
2050
2051 @item USE_PROC_FS
2052 This determines whether small routines in @file{*-tdep.c}, which
2053 translate register values between GDB's internal representation and the
2054 /proc representation, are compiled.
2055
2056 @item U_REGS_OFFSET
2057 This is the offset of the registers in the upage. It need only be
2058 defined if the generic ptrace register access routines in
2059 @file{infptrace.c} are being used (that is, @file{infptrace.c} is
2060 configured in, and @code{FETCH_INFERIOR_REGISTERS} is not defined). If
2061 the default value from @file{infptrace.c} is good enough, leave it
2062 undefined.
2063
2064 The default value means that u.u_ar0 @emph{points to} the location of
2065 the registers. I'm guessing that @code{#define U_REGS_OFFSET 0} means
2066 that u.u_ar0 @emph{is} the location of the registers.
2067
2068 @item CLEAR_SOLIB
2069 objfiles.c
2070
2071 @item DEBUG_PTRACE
2072 Define this to debug ptrace calls.
2073
2074 @end table
2075
2076
2077 @node Support Libraries
2078
2079 @chapter Support Libraries
2080
2081 @section BFD
2082
2083 BFD provides support for GDB in several ways:
2084
2085 @table @emph
2086
2087 @item identifying executable and core files
2088 BFD will identify a variety of file types, including a.out, coff, and
2089 several variants thereof, as well as several kinds of core files.
2090
2091 @item access to sections of files
2092 BFD parses the file headers to determine the names, virtual addresses,
2093 sizes, and file locations of all the various named sections in files
2094 (such as the text section or the data section). GDB simply calls BFD to
2095 read or write section X at byte offset Y for length Z.
2096
2097 @item specialized core file support
2098 BFD provides routines to determine the failing command name stored in a
2099 core file, the signal with which the program failed, and whether a core
2100 file matches (i.e. could be a core dump of) a particular executable
2101 file.
2102
2103 @item locating the symbol information
2104 GDB uses an internal interface of BFD to determine where to find the
2105 symbol information in an executable file or symbol-file. GDB itself
2106 handles the reading of symbols, since BFD does not ``understand'' debug
2107 symbols, but GDB uses BFD's cached information to find the symbols,
2108 string table, etc.
2109
2110 @end table
2111
2112 @section opcodes
2113
2114 The opcodes library provides GDB's disassembler. (It's a separate
2115 library because it's also used in binutils, for @file{objdump}).
2116
2117 @section readline
2118
2119 @section mmalloc
2120
2121 @section libiberty
2122
2123 @section gnu-regex
2124
2125 Regex conditionals.
2126
2127 @table @code
2128
2129 @item C_ALLOCA
2130
2131 @item NFAILURES
2132
2133 @item RE_NREGS
2134
2135 @item SIGN_EXTEND_CHAR
2136
2137 @item SWITCH_ENUM_BUG
2138
2139 @item SYNTAX_TABLE
2140
2141 @item Sword
2142
2143 @item sparc
2144
2145 @end table
2146
2147 @section include
2148
2149 @node Coding
2150
2151 @chapter Coding
2152
2153 This chapter covers topics that are lower-level than the major
2154 algorithms of GDB.
2155
2156 @section Cleanups
2157
2158 Cleanups are a structured way to deal with things that need to be done
2159 later. When your code does something (like @code{malloc} some memory,
2160 or open a file) that needs to be undone later (e.g. free the memory or
2161 close the file), it can make a cleanup. The cleanup will be done at
2162 some future point: when the command is finished, when an error occurs,
2163 or when your code decides it's time to do cleanups.
2164
2165 You can also discard cleanups, that is, throw them away without doing
2166 what they say. This is only done if you ask that it be done.
2167
2168 Syntax:
2169
2170 @table @code
2171
2172 @item struct cleanup *@var{old_chain};
2173 Declare a variable which will hold a cleanup chain handle.
2174
2175 @item @var{old_chain} = make_cleanup (@var{function}, @var{arg});
2176 Make a cleanup which will cause @var{function} to be called with
2177 @var{arg} (a @code{char *}) later. The result, @var{old_chain}, is a
2178 handle that can be passed to @code{do_cleanups} or
2179 @code{discard_cleanups} later. Unless you are going to call
2180 @code{do_cleanups} or @code{discard_cleanups} yourself, you can ignore
2181 the result from @code{make_cleanup}.
2182
2183 @item do_cleanups (@var{old_chain});
2184 Perform all cleanups done since @code{make_cleanup} returned
2185 @var{old_chain}. E.g.:
2186 @example
2187 make_cleanup (a, 0);
2188 old = make_cleanup (b, 0);
2189 do_cleanups (old);
2190 @end example
2191 @noindent
2192 will call @code{b()} but will not call @code{a()}. The cleanup that
2193 calls @code{a()} will remain in the cleanup chain, and will be done
2194 later unless otherwise discarded.@refill
2195
2196 @item discard_cleanups (@var{old_chain});
2197 Same as @code{do_cleanups} except that it just removes the cleanups from
2198 the chain and does not call the specified functions.
2199
2200 @end table
2201
2202 Some functions, e.g. @code{fputs_filtered()} or @code{error()}, specify
2203 that they ``should not be called when cleanups are not in place''. This
2204 means that any actions you need to reverse in the case of an error or
2205 interruption must be on the cleanup chain before you call these
2206 functions, since they might never return to your code (they
2207 @samp{longjmp} instead).
2208
2209 @section Wrapping Output Lines
2210
2211 Output that goes through @code{printf_filtered} or @code{fputs_filtered}
2212 or @code{fputs_demangled} needs only to have calls to @code{wrap_here}
2213 added in places that would be good breaking points. The utility
2214 routines will take care of actually wrapping if the line width is
2215 exceeded.
2216
2217 The argument to @code{wrap_here} is an indentation string which is
2218 printed @emph{only} if the line breaks there. This argument is saved
2219 away and used later. It must remain valid until the next call to
2220 @code{wrap_here} or until a newline has been printed through the
2221 @code{*_filtered} functions. Don't pass in a local variable and then
2222 return!
2223
2224 It is usually best to call @code{wrap_here()} after printing a comma or
2225 space. If you call it before printing a space, make sure that your
2226 indentation properly accounts for the leading space that will print if
2227 the line wraps there.
2228
2229 Any function or set of functions that produce filtered output must
2230 finish by printing a newline, to flush the wrap buffer, before switching
2231 to unfiltered (``@code{printf}'') output. Symbol reading routines that
2232 print warnings are a good example.
2233
2234 @section GDB Coding Standards
2235
2236 GDB follows the GNU coding standards, as described in
2237 @file{etc/standards.texi}. This file is also available for anonymous
2238 FTP from GNU archive sites. GDB takes a strict interpretation of the
2239 standard; in general, when the GNU standard recommends a practice but
2240 does not require it, GDB requires it.
2241
2242 GDB follows an additional set of coding standards specific to GDB,
2243 as described in the following sections.
2244
2245 You can configure with @samp{--enable-build-warnings} to get GCC to
2246 check on a number of these rules. GDB sources ought not to engender any
2247 complaints, unless they are caused by bogus host systems. (The exact
2248 set of enabled warnings is currently @samp{-Wall -Wpointer-arith
2249 -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations}.
2250
2251 @subsection Formatting
2252
2253 The standard GNU recommendations for formatting must be followed
2254 strictly.
2255
2256 Note that while in a definition, the function's name must be in column
2257 zero; in a function declaration, the name must be on the same line as
2258 the return type.
2259
2260 In addition, there must be a space between a function or macro name and
2261 the opening parenthesis of its argument list (except for macro
2262 definitions, as required by C). There must not be a space after an open
2263 paren/bracket or before a close paren/bracket.
2264
2265 While additional whitespace is generally helpful for reading, do not use
2266 more than one blank line to separate blocks, and avoid adding whitespace
2267 after the end of a program line (as of 1/99, some 600 lines had whitespace
2268 after the semicolon). Excess whitespace causes difficulties for diff and
2269 patch.
2270
2271 @subsection Comments
2272
2273 The standard GNU requirements on comments must be followed strictly.
2274
2275 Block comments must appear in the following form, with no `/*'- or
2276 '*/'-only lines, and no leading `*':
2277
2278 @example @code
2279 /* Wait for control to return from inferior to debugger. If inferior
2280 gets a signal, we may decide to start it up again instead of
2281 returning. That is why there is a loop in this function. When
2282 this function actually returns it means the inferior should be left
2283 stopped and GDB should read more commands. */
2284 @end example
2285
2286 (Note that this format is encouraged by Emacs; tabbing for a multi-line
2287 comment works correctly, and M-Q fills the block consistently.)
2288
2289 Put a blank line between the block comments preceding function or
2290 variable definitions, and the definition itself.
2291
2292 In general, put function-body comments on lines by themselves, rather
2293 than trying to fit them into the 20 characters left at the end of a
2294 line, since either the comment or the code will inevitably get longer
2295 than will fit, and then somebody will have to move it anyhow.
2296
2297 @subsection C Usage
2298
2299 Code must not depend on the sizes of C data types, the format of the
2300 host's floating point numbers, the alignment of anything, or the order
2301 of evaluation of expressions.
2302
2303 Use functions freely. There are only a handful of compute-bound areas
2304 in GDB that might be affected by the overhead of a function call, mainly
2305 in symbol reading. Most of GDB's performance is limited by the target
2306 interface (whether serial line or system call).
2307
2308 However, use functions with moderation. A thousand one-line functions
2309 are just as hard to understand as a single thousand-line function.
2310
2311 @subsection Function Prototypes
2312
2313 Prototypes must be used to @emph{declare} functions but never to
2314 @emph{define} them. Prototypes for GDB functions must include both the
2315 argument type and name, with the name matching that used in the actual
2316 function definition.
2317
2318 For the sake of compatibility with pre-ANSI compilers, define prototypes
2319 with the @code{PARAMS} macro:
2320
2321 @example @code
2322 extern int memory_remove_breakpoint PARAMS ((CORE_ADDR addr,
2323 char *contents_cache));
2324 @end example
2325
2326 Note the double parentheses around the parameter types. This allows an
2327 arbitrary number of parameters to be described, without freaking out the
2328 C preprocessor. When the function has no parameters, it should be
2329 described like:
2330
2331 @example @code
2332 extern void noprocess PARAMS ((void));
2333 @end example
2334
2335 The @code{PARAMS} macro expands to its argument in ANSI C, or to a
2336 simple @code{()} in traditional C.
2337
2338 All external functions should have a @code{PARAMS} declaration in a
2339 header file that callers include, except for @code{_initialize_*}
2340 functions, which must be external so that @file{init.c} construction
2341 works, but shouldn't be visible to random source files.
2342
2343 All static functions must be declared in a block near the top of the
2344 source file.
2345
2346 @subsection Clean Design
2347
2348 In addition to getting the syntax right, there's the little question of
2349 semantics. Some things are done in certain ways in GDB because long
2350 experience has shown that the more obvious ways caused various kinds of
2351 trouble.
2352
2353 You can't assume the byte order of anything that comes from a target
2354 (including @var{value}s, object files, and instructions). Such things
2355 must be byte-swapped using @code{SWAP_TARGET_AND_HOST} in GDB, or one of
2356 the swap routines defined in @file{bfd.h}, such as @code{bfd_get_32}.
2357
2358 You can't assume that you know what interface is being used to talk to
2359 the target system. All references to the target must go through the
2360 current @code{target_ops} vector.
2361
2362 You can't assume that the host and target machines are the same machine
2363 (except in the ``native'' support modules). In particular, you can't
2364 assume that the target machine's header files will be available on the
2365 host machine. Target code must bring along its own header files --
2366 written from scratch or explicitly donated by their owner, to avoid
2367 copyright problems.
2368
2369 Insertion of new @code{#ifdef}'s will be frowned upon. It's much better
2370 to write the code portably than to conditionalize it for various
2371 systems.
2372
2373 New @code{#ifdef}'s which test for specific compilers or manufacturers
2374 or operating systems are unacceptable. All @code{#ifdef}'s should test
2375 for features. The information about which configurations contain which
2376 features should be segregated into the configuration files. Experience
2377 has proven far too often that a feature unique to one particular system
2378 often creeps into other systems; and that a conditional based on some
2379 predefined macro for your current system will become worthless over
2380 time, as new versions of your system come out that behave differently
2381 with regard to this feature.
2382
2383 Adding code that handles specific architectures, operating systems,
2384 target interfaces, or hosts, is not acceptable in generic code. If a
2385 hook is needed at that point, invent a generic hook and define it for
2386 your configuration, with something like:
2387
2388 @example
2389 #ifdef WRANGLE_SIGNALS
2390 WRANGLE_SIGNALS (signo);
2391 #endif
2392 @end example
2393
2394 In your host, target, or native configuration file, as appropriate,
2395 define @code{WRANGLE_SIGNALS} to do the machine-dependent thing. Take a
2396 bit of care in defining the hook, so that it can be used by other ports
2397 in the future, if they need a hook in the same place.
2398
2399 If the hook is not defined, the code should do whatever "most" machines
2400 want. Using @code{#ifdef}, as above, is the preferred way to do this,
2401 but sometimes that gets convoluted, in which case use
2402
2403 @example
2404 #ifndef SPECIAL_FOO_HANDLING
2405 #define SPECIAL_FOO_HANDLING(pc, sp) (0)
2406 #endif
2407 @end example
2408
2409 where the macro is used or in an appropriate header file.
2410
2411 Whether to include a @dfn{small} hook, a hook around the exact pieces of
2412 code which are system-dependent, or whether to replace a whole function
2413 with a hook depends on the case. A good example of this dilemma can be
2414 found in @code{get_saved_register}. All machines that GDB 2.8 ran on
2415 just needed the @code{FRAME_FIND_SAVED_REGS} hook to find the saved
2416 registers. Then the SPARC and Pyramid came along, and
2417 @code{HAVE_REGISTER_WINDOWS} and @code{REGISTER_IN_WINDOW_P} were
2418 introduced. Then the 29k and 88k required the @code{GET_SAVED_REGISTER}
2419 hook. The first three are examples of small hooks; the latter replaces
2420 a whole function. In this specific case, it is useful to have both
2421 kinds; it would be a bad idea to replace all the uses of the small hooks
2422 with @code{GET_SAVED_REGISTER}, since that would result in much
2423 duplicated code. Other times, duplicating a few lines of code here or
2424 there is much cleaner than introducing a large number of small hooks.
2425
2426 Another way to generalize GDB along a particular interface is with an
2427 attribute struct. For example, GDB has been generalized to handle
2428 multiple kinds of remote interfaces -- not by #ifdef's everywhere, but
2429 by defining the "target_ops" structure and having a current target (as
2430 well as a stack of targets below it, for memory references). Whenever
2431 something needs to be done that depends on which remote interface we are
2432 using, a flag in the current target_ops structure is tested (e.g.
2433 `target_has_stack'), or a function is called through a pointer in the
2434 current target_ops structure. In this way, when a new remote interface
2435 is added, only one module needs to be touched -- the one that actually
2436 implements the new remote interface. Other examples of
2437 attribute-structs are BFD access to multiple kinds of object file
2438 formats, or GDB's access to multiple source languages.
2439
2440 Please avoid duplicating code. For example, in GDB 3.x all the code
2441 interfacing between @code{ptrace} and the rest of GDB was duplicated in
2442 @file{*-dep.c}, and so changing something was very painful. In GDB 4.x,
2443 these have all been consolidated into @file{infptrace.c}.
2444 @file{infptrace.c} can deal with variations between systems the same way
2445 any system-independent file would (hooks, #if defined, etc.), and
2446 machines which are radically different don't need to use infptrace.c at
2447 all.
2448
2449
2450 @node Porting GDB
2451
2452 @chapter Porting GDB
2453
2454 Most of the work in making GDB compile on a new machine is in specifying
2455 the configuration of the machine. This is done in a dizzying variety of
2456 header files and configuration scripts, which we hope to make more
2457 sensible soon. Let's say your new host is called an @var{xyz} (e.g.
2458 @samp{sun4}), and its full three-part configuration name is
2459 @code{@var{arch}-@var{xvend}-@var{xos}} (e.g. @samp{sparc-sun-sunos4}).
2460 In particular:
2461
2462 In the top level directory, edit @file{config.sub} and add @var{arch},
2463 @var{xvend}, and @var{xos} to the lists of supported architectures,
2464 vendors, and operating systems near the bottom of the file. Also, add
2465 @var{xyz} as an alias that maps to
2466 @code{@var{arch}-@var{xvend}-@var{xos}}. You can test your changes by
2467 running
2468
2469 @example
2470 ./config.sub @var{xyz}
2471 @end example
2472 @noindent
2473 and
2474 @example
2475 ./config.sub @code{@var{arch}-@var{xvend}-@var{xos}}
2476 @end example
2477 @noindent
2478 which should both respond with @code{@var{arch}-@var{xvend}-@var{xos}}
2479 and no error messages.
2480
2481 You need to port BFD, if that hasn't been done already. Porting BFD is
2482 beyond the scope of this manual.
2483
2484 To configure GDB itself, edit @file{gdb/configure.host} to recognize
2485 your system and set @code{gdb_host} to @var{xyz}, and (unless your
2486 desired target is already available) also edit @file{gdb/configure.tgt},
2487 setting @code{gdb_target} to something appropriate (for instance,
2488 @var{xyz}).
2489
2490 Finally, you'll need to specify and define GDB's host-, native-, and
2491 target-dependent @file{.h} and @file{.c} files used for your
2492 configuration.
2493
2494 @section Configuring GDB for Release
2495
2496 From the top level directory (containing @file{gdb}, @file{bfd},
2497 @file{libiberty}, and so on):
2498 @example
2499 make -f Makefile.in gdb.tar.gz
2500 @end example
2501
2502 This will properly configure, clean, rebuild any files that are
2503 distributed pre-built (e.g. @file{c-exp.tab.c} or @file{refcard.ps}),
2504 and will then make a tarfile. (If the top level directory has already
2505 been configured, you can just do @code{make gdb.tar.gz} instead.)
2506
2507 This procedure requires:
2508 @itemize @bullet
2509 @item symbolic links
2510 @item @code{makeinfo} (texinfo2 level)
2511 @item @TeX{}
2512 @item @code{dvips}
2513 @item @code{yacc} or @code{bison}
2514 @end itemize
2515 @noindent
2516 @dots{} and the usual slew of utilities (@code{sed}, @code{tar}, etc.).
2517
2518 @subheading TEMPORARY RELEASE PROCEDURE FOR DOCUMENTATION
2519
2520 @file{gdb.texinfo} is currently marked up using the texinfo-2 macros,
2521 which are not yet a default for anything (but we have to start using
2522 them sometime).
2523
2524 For making paper, the only thing this implies is the right generation of
2525 @file{texinfo.tex} needs to be included in the distribution.
2526
2527 For making info files, however, rather than duplicating the texinfo2
2528 distribution, generate @file{gdb-all.texinfo} locally, and include the
2529 files @file{gdb.info*} in the distribution. Note the plural;
2530 @code{makeinfo} will split the document into one overall file and five
2531 or so included files.
2532
2533 @node Hints
2534
2535 @chapter Hints
2536
2537 Check the @file{README} file, it often has useful information that does not
2538 appear anywhere else in the directory.
2539
2540 @menu
2541 * Getting Started:: Getting started working on GDB
2542 * Debugging GDB:: Debugging GDB with itself
2543 @end menu
2544
2545 @node Getting Started,,, Hints
2546
2547 @section Getting Started
2548
2549 GDB is a large and complicated program, and if you first starting to
2550 work on it, it can be hard to know where to start. Fortunately, if you
2551 know how to go about it, there are ways to figure out what is going on.
2552
2553 This manual, the GDB Internals manual, has information which applies
2554 generally to many parts of GDB.
2555
2556 Information about particular functions or data structures are located in
2557 comments with those functions or data structures. If you run across a
2558 function or a global variable which does not have a comment correctly
2559 explaining what is does, this can be thought of as a bug in GDB; feel
2560 free to submit a bug report, with a suggested comment if you can figure
2561 out what the comment should say. If you find a comment which is
2562 actually wrong, be especially sure to report that.
2563
2564 Comments explaining the function of macros defined in host, target, or
2565 native dependent files can be in several places. Sometimes they are
2566 repeated every place the macro is defined. Sometimes they are where the
2567 macro is used. Sometimes there is a header file which supplies a
2568 default definition of the macro, and the comment is there. This manual
2569 also documents all the available macros.
2570 @c (@pxref{Host Conditionals}, @pxref{Target
2571 @c Conditionals}, @pxref{Native Conditionals}, and @pxref{Obsolete
2572 @c Conditionals})
2573
2574 Start with the header files. Once you some idea of how GDB's internal
2575 symbol tables are stored (see @file{symtab.h}, @file{gdbtypes.h}), you
2576 will find it much easier to understand the code which uses and creates
2577 those symbol tables.
2578
2579 You may wish to process the information you are getting somehow, to
2580 enhance your understanding of it. Summarize it, translate it to another
2581 language, add some (perhaps trivial or non-useful) feature to GDB, use
2582 the code to predict what a test case would do and write the test case
2583 and verify your prediction, etc. If you are reading code and your eyes
2584 are starting to glaze over, this is a sign you need to use a more active
2585 approach.
2586
2587 Once you have a part of GDB to start with, you can find more
2588 specifically the part you are looking for by stepping through each
2589 function with the @code{next} command. Do not use @code{step} or you
2590 will quickly get distracted; when the function you are stepping through
2591 calls another function try only to get a big-picture understanding
2592 (perhaps using the comment at the beginning of the function being
2593 called) of what it does. This way you can identify which of the
2594 functions being called by the function you are stepping through is the
2595 one which you are interested in. You may need to examine the data
2596 structures generated at each stage, with reference to the comments in
2597 the header files explaining what the data structures are supposed to
2598 look like.
2599
2600 Of course, this same technique can be used if you are just reading the
2601 code, rather than actually stepping through it. The same general
2602 principle applies---when the code you are looking at calls something
2603 else, just try to understand generally what the code being called does,
2604 rather than worrying about all its details.
2605
2606 A good place to start when tracking down some particular area is with a
2607 command which invokes that feature. Suppose you want to know how
2608 single-stepping works. As a GDB user, you know that the @code{step}
2609 command invokes single-stepping. The command is invoked via command
2610 tables (see @file{command.h}); by convention the function which actually
2611 performs the command is formed by taking the name of the command and
2612 adding @samp{_command}, or in the case of an @code{info} subcommand,
2613 @samp{_info}. For example, the @code{step} command invokes the
2614 @code{step_command} function and the @code{info display} command invokes
2615 @code{display_info}. When this convention is not followed, you might
2616 have to use @code{grep} or @kbd{M-x tags-search} in emacs, or run GDB on
2617 itself and set a breakpoint in @code{execute_command}.
2618
2619 If all of the above fail, it may be appropriate to ask for information
2620 on @code{bug-gdb}. But @emph{never} post a generic question like ``I was
2621 wondering if anyone could give me some tips about understanding
2622 GDB''---if we had some magic secret we would put it in this manual.
2623 Suggestions for improving the manual are always welcome, of course.
2624
2625 @node Debugging GDB,,,Hints
2626
2627 @section Debugging GDB with itself
2628
2629 If GDB is limping on your machine, this is the preferred way to get it
2630 fully functional. Be warned that in some ancient Unix systems, like
2631 Ultrix 4.2, a program can't be running in one process while it is being
2632 debugged in another. Rather than typing the command @code{@w{./gdb
2633 ./gdb}}, which works on Suns and such, you can copy @file{gdb} to
2634 @file{gdb2} and then type @code{@w{./gdb ./gdb2}}.
2635
2636 When you run GDB in the GDB source directory, it will read a
2637 @file{.gdbinit} file that sets up some simple things to make debugging
2638 gdb easier. The @code{info} command, when executed without a subcommand
2639 in a GDB being debugged by gdb, will pop you back up to the top level
2640 gdb. See @file{.gdbinit} for details.
2641
2642 If you use emacs, you will probably want to do a @code{make TAGS} after
2643 you configure your distribution; this will put the machine dependent
2644 routines for your local machine where they will be accessed first by
2645 @kbd{M-.}
2646
2647 Also, make sure that you've either compiled GDB with your local cc, or
2648 have run @code{fixincludes} if you are compiling with gcc.
2649
2650 @section Submitting Patches
2651
2652 Thanks for thinking of offering your changes back to the community of
2653 GDB users. In general we like to get well designed enhancements.
2654 Thanks also for checking in advance about the best way to transfer the
2655 changes.
2656
2657 The GDB maintainers will only install ``cleanly designed'' patches. You
2658 may not always agree on what is clean design.
2659 @c @pxref{Coding Style}, @pxref{Clean Design}.
2660
2661 If the maintainers don't have time to put the patch in when it arrives,
2662 or if there is any question about a patch, it goes into a large queue
2663 with everyone else's patches and bug reports.
2664
2665 The legal issue is that to incorporate substantial changes requires a
2666 copyright assignment from you and/or your employer, granting ownership
2667 of the changes to the Free Software Foundation. You can get the
2668 standard document for doing this by sending mail to
2669 @code{gnu@@prep.ai.mit.edu} and asking for it. I recommend that people
2670 write in "All programs owned by the Free Software Foundation" as "NAME
2671 OF PROGRAM", so that changes in many programs (not just GDB, but GAS,
2672 Emacs, GCC, etc) can be contributed with only one piece of legalese
2673 pushed through the bureacracy and filed with the FSF. I can't start
2674 merging changes until this paperwork is received by the FSF (their
2675 rules, which I follow since I maintain it for them).
2676
2677 Technically, the easiest way to receive changes is to receive each
2678 feature as a small context diff or unidiff, suitable for "patch".
2679 Each message sent to me should include the changes to C code and
2680 header files for a single feature, plus ChangeLog entries for each
2681 directory where files were modified, and diffs for any changes needed
2682 to the manuals (gdb/doc/gdb.texi or gdb/doc/gdbint.texi). If there
2683 are a lot of changes for a single feature, they can be split down
2684 into multiple messages.
2685
2686 In this way, if I read and like the feature, I can add it to the
2687 sources with a single patch command, do some testing, and check it in.
2688 If you leave out the ChangeLog, I have to write one. If you leave
2689 out the doc, I have to puzzle out what needs documenting. Etc.
2690
2691 The reason to send each change in a separate message is that I will
2692 not install some of the changes. They'll be returned to you with
2693 questions or comments. If I'm doing my job, my message back to you
2694 will say what you have to fix in order to make the change acceptable.
2695 The reason to have separate messages for separate features is so
2696 that other changes (which I @emph{am} willing to accept) can be installed
2697 while one or more changes are being reworked. If multiple features
2698 are sent in a single message, I tend to not put in the effort to sort
2699 out the acceptable changes from the unacceptable, so none of the
2700 features get installed until all are acceptable.
2701
2702 If this sounds painful or authoritarian, well, it is. But I get a lot
2703 of bug reports and a lot of patches, and most of them don't get
2704 installed because I don't have the time to finish the job that the bug
2705 reporter or the contributor could have done. Patches that arrive
2706 complete, working, and well designed, tend to get installed on the day
2707 they arrive. The others go into a queue and get installed if and when
2708 I scan back over the queue -- which can literally take months
2709 sometimes. It's in both our interests to make patch installation easy
2710 -- you get your changes installed, and I make some forward progress on
2711 GDB in a normal 12-hour day (instead of them having to wait until I
2712 have a 14-hour or 16-hour day to spend cleaning up patches before I
2713 can install them).
2714
2715 Please send patches directly to the GDB maintainers at
2716 @code{gdb-patches@@cygnus.com}.
2717
2718 @section Obsolete Conditionals
2719
2720 Fragments of old code in GDB sometimes reference or set the following
2721 configuration macros. They should not be used by new code, and old uses
2722 should be removed as those parts of the debugger are otherwise touched.
2723
2724 @table @code
2725
2726 @item STACK_END_ADDR
2727 This macro used to define where the end of the stack appeared, for use
2728 in interpreting core file formats that don't record this address in the
2729 core file itself. This information is now configured in BFD, and GDB
2730 gets the info portably from there. The values in GDB's configuration
2731 files should be moved into BFD configuration files (if needed there),
2732 and deleted from all of GDB's config files.
2733
2734 Any @file{@var{foo}-xdep.c} file that references STACK_END_ADDR
2735 is so old that it has never been converted to use BFD. Now that's old!
2736
2737 @item PYRAMID_CONTROL_FRAME_DEBUGGING
2738 pyr-xdep.c
2739 @item PYRAMID_CORE
2740 pyr-xdep.c
2741 @item PYRAMID_PTRACE
2742 pyr-xdep.c
2743
2744 @item REG_STACK_SEGMENT
2745 exec.c
2746
2747 @end table
2748
2749
2750 @contents
2751 @bye
This page took 0.094846 seconds and 4 git commands to generate.