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