OSDN Git Service

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