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