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