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