Add a super-simple pseudo 'ldd'
[msysgit.git] / mingw / info / gdbint.info-1
blob4dacfbb60aa29eef50e0a31ca6d040d06ce84974
1 This is gdbint.info, produced by makeinfo version 4.8 from
2 ../.././gdb/doc/gdbint.texinfo.
4 INFO-DIR-SECTION Software development
5 START-INFO-DIR-ENTRY
6 * Gdb-Internals: (gdbint).      The GNU debugger's internals.
7 END-INFO-DIR-ENTRY
9    This file documents the internals of the GNU debugger GDB.
10 Copyright (C) 1990, 1991, 1992, 1993, 1994, 1996, 1998, 1999, 2000,
11 2001,    2002, 2003, 2004, 2005, 2006    Free Software Foundation, Inc.
12 Contributed by Cygnus Solutions.  Written by John Gilmore.  Second
13 Edition by Stan Shebs.
15    Permission is granted to copy, distribute and/or modify this document
16 under the terms of the GNU Free Documentation License, Version 1.1 or
17 any later version published by the Free Software Foundation; with no
18 Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
19 Texts.  A copy of the license is included in the section entitled "GNU
20 Free Documentation License".
22 \x1f
23 File: gdbint.info,  Node: Top,  Next: Requirements,  Up: (dir)
25 Scope of this Document
26 **********************
28 This document documents the internals of the GNU debugger, GDB.  It
29 includes description of GDB's key algorithms and operations, as well as
30 the mechanisms that adapt GDB to specific hosts and targets.
32 * Menu:
34 * Requirements::
35 * Overall Structure::
36 * Algorithms::
37 * User Interface::
38 * libgdb::
39 * Symbol Handling::
40 * Language Support::
41 * Host Definition::
42 * Target Architecture Definition::
43 * Target Descriptions::
44 * Target Vector Definition::
45 * Native Debugging::
46 * Support Libraries::
47 * Coding::
48 * Porting GDB::
49 * Versions and Branches::
50 * Start of New Year Procedure::
51 * Releasing GDB::
52 * Testsuite::
53 * Hints::
55 * GDB Observers::  GDB Currently available observers
56 * GNU Free Documentation License::  The license for this documentation
57 * Index::
59 \x1f
60 File: gdbint.info,  Node: Requirements,  Next: Overall Structure,  Prev: Top,  Up: Top
62 1 Requirements
63 **************
65 Before diving into the internals, you should understand the formal
66 requirements and other expectations for GDB.  Although some of these
67 may seem obvious, there have been proposals for GDB that have run
68 counter to these requirements.
70    First of all, GDB is a debugger.  It's not designed to be a front
71 panel for embedded systems.  It's not a text editor.  It's not a shell.
72 It's not a programming environment.
74    GDB is an interactive tool.  Although a batch mode is available,
75 GDB's primary role is to interact with a human programmer.
77    GDB should be responsive to the user.  A programmer hot on the trail
78 of a nasty bug, and operating under a looming deadline, is going to be
79 very impatient of everything, including the response time to debugger
80 commands.
82    GDB should be relatively permissive, such as for expressions.  While
83 the compiler should be picky (or have the option to be made picky),
84 since source code lives for a long time usually, the programmer doing
85 debugging shouldn't be spending time figuring out to mollify the
86 debugger.
88    GDB will be called upon to deal with really large programs.
89 Executable sizes of 50 to 100 megabytes occur regularly, and we've
90 heard reports of programs approaching 1 gigabyte in size.
92    GDB should be able to run everywhere.  No other debugger is
93 available for even half as many configurations as GDB supports.
95 \x1f
96 File: gdbint.info,  Node: Overall Structure,  Next: Algorithms,  Prev: Requirements,  Up: Top
98 2 Overall Structure
99 *******************
101 GDB consists of three major subsystems: user interface, symbol handling
102 (the "symbol side"), and target system handling (the "target side").
104    The user interface consists of several actual interfaces, plus
105 supporting code.
107    The symbol side consists of object file readers, debugging info
108 interpreters, symbol table management, source language expression
109 parsing, type and value printing.
111    The target side consists of execution control, stack frame analysis,
112 and physical target manipulation.
114    The target side/symbol side division is not formal, and there are a
115 number of exceptions.  For instance, core file support involves symbolic
116 elements (the basic core file reader is in BFD) and target elements (it
117 supplies the contents of memory and the values of registers).  Instead,
118 this division is useful for understanding how the minor subsystems
119 should fit together.
121 2.1 The Symbol Side
122 ===================
124 The symbolic side of GDB can be thought of as "everything you can do in
125 GDB without having a live program running".  For instance, you can look
126 at the types of variables, and evaluate many kinds of expressions.
128 2.2 The Target Side
129 ===================
131 The target side of GDB is the "bits and bytes manipulator".  Although
132 it may make reference to symbolic info here and there, most of the
133 target side will run with only a stripped executable available--or even
134 no executable at all, in remote debugging cases.
136    Operations such as disassembly, stack frame crawls, and register
137 display, are able to work with no symbolic info at all.  In some cases,
138 such as disassembly, GDB will use symbolic info to present addresses
139 relative to symbols rather than as raw numbers, but it will work either
140 way.
142 2.3 Configurations
143 ==================
145 "Host" refers to attributes of the system where GDB runs.  "Target"
146 refers to the system where the program being debugged executes.  In
147 most cases they are the same machine, in which case a third type of
148 "Native" attributes come into play.
150    Defines and include files needed to build on the host are host
151 support.  Examples are tty support, system defined types, host byte
152 order, host float format.
154    Defines and information needed to handle the target format are target
155 dependent.  Examples are the stack frame format, instruction set,
156 breakpoint instruction, registers, and how to set up and tear down the
157 stack to call a function.
159    Information that is only needed when the host and target are the
160 same, is native dependent.  One example is Unix child process support;
161 if the host and target are not the same, doing a fork to start the
162 target process is a bad idea.  The various macros needed for finding the
163 registers in the `upage', running `ptrace', and such are all in the
164 native-dependent files.
166    Another example of native-dependent code is support for features that
167 are really part of the target environment, but which require `#include'
168 files that are only available on the host system.  Core file handling
169 and `setjmp' handling are two common cases.
171    When you want to make GDB work "native" on a particular machine, you
172 have to include all three kinds of information.
174 2.4 Source Tree Structure
175 =========================
177 The GDB source directory has a mostly flat structure--there are only a
178 few subdirectories.  A file's name usually gives a hint as to what it
179 does; for example, `stabsread.c' reads stabs, `dwarf2read.c' reads
180 DWARF 2, etc.
182    Files that are related to some common task have names that share
183 common substrings.  For example, `*-thread.c' files deal with debugging
184 threads on various platforms; `*read.c' files deal with reading various
185 kinds of symbol and object files; `inf*.c' files deal with direct
186 control of the "inferior program" (GDB parlance for the program being
187 debugged).
189    There are several dozens of files in the `*-tdep.c' family.  `tdep'
190 stands for "target-dependent code"--each of these files implements
191 debug support for a specific target architecture (sparc, mips, etc).
192 Usually, only one of these will be used in a specific GDB configuration
193 (sometimes two, closely related).
195    Similarly, there are many `*-nat.c' files, each one for native
196 debugging on a specific system (e.g., `sparc-linux-nat.c' is for native
197 debugging of Sparc machines running the Linux kernel).
199    The few subdirectories of the source tree are:
201 `cli'
202      Code that implements "CLI", the GDB Command-Line Interpreter.
203      *Note Command Interpreter: User Interface.
205 `gdbserver'
206      Code for the GDB remote server.
208 `gdbtk'
209      Code for Insight, the GDB TK-based GUI front-end.
211 `mi'
212      The "GDB/MI", the GDB Machine Interface interpreter.
214 `signals'
215      Target signal translation code.
217 `tui'
218      Code for "TUI", the GDB Text-mode full-screen User Interface.
219      *Note TUI: User Interface.
221 \x1f
222 File: gdbint.info,  Node: Algorithms,  Next: User Interface,  Prev: Overall Structure,  Up: Top
224 3 Algorithms
225 ************
227 GDB uses a number of debugging-specific algorithms.  They are often not
228 very complicated, but get lost in the thicket of special cases and
229 real-world issues.  This chapter describes the basic algorithms and
230 mentions some of the specific target definitions that they use.
232 3.1 Frames
233 ==========
235 A frame is a construct that GDB uses to keep track of calling and
236 called functions.
238    GDB's frame model, a fresh design, was implemented with the need to
239 support DWARF's Call Frame Information in mind.  In fact, the term
240 "unwind" is taken directly from that specification.  Developers wishing
241 to learn more about unwinders, are encouraged to read the DWARF
242 specification.
244    GDB's model is that you find a frame's registers by "unwinding" them
245 from the next younger frame.  That is, `get_frame_register' which
246 returns the value of a register in frame #1 (the next-to-youngest
247 frame), is implemented by calling frame #0's `frame_register_unwind'
248 (the youngest frame).  But then the obvious question is: how do you
249 access the registers of the youngest frame itself?
251    To answer this question, GDB has the "sentinel" frame, the "-1st"
252 frame.  Unwinding registers from the sentinel frame gives you the
253 current values of the youngest real frame's registers.  If F is a
254 sentinel frame, then `get_frame_type (F) == SENTINEL_FRAME'.
256 3.2 Prologue Analysis
257 =====================
259 To produce a backtrace and allow the user to manipulate older frames'
260 variables and arguments, GDB needs to find the base addresses of older
261 frames, and discover where those frames' registers have been saved.
262 Since a frame's "callee-saves" registers get saved by younger frames if
263 and when they're reused, a frame's registers may be scattered
264 unpredictably across younger frames.  This means that changing the
265 value of a register-allocated variable in an older frame may actually
266 entail writing to a save slot in some younger frame.
268    Modern versions of GCC emit Dwarf call frame information ("CFI"),
269 which describes how to find frame base addresses and saved registers.
270 But CFI is not always available, so as a fallback GDB uses a technique
271 called "prologue analysis" to find frame sizes and saved registers.  A
272 prologue analyzer disassembles the function's machine code starting
273 from its entry point, and looks for instructions that allocate frame
274 space, save the stack pointer in a frame pointer register, save
275 registers, and so on.  Obviously, this can't be done accurately in
276 general, but it's tractable to do well enough to be very helpful.
277 Prologue analysis predates the GNU toolchain's support for CFI; at one
278 time, prologue analysis was the only mechanism GDB used for stack
279 unwinding at all, when the function calling conventions didn't specify
280 a fixed frame layout.
282    In the olden days, function prologues were generated by hand-written,
283 target-specific code in GCC, and treated as opaque and untouchable by
284 optimizers.  Looking at this code, it was usually straightforward to
285 write a prologue analyzer for GDB that would accurately understand all
286 the prologues GCC would generate.  However, over time GCC became more
287 aggressive about instruction scheduling, and began to understand more
288 about the semantics of the prologue instructions themselves; in
289 response, GDB's analyzers became more complex and fragile.  Keeping the
290 prologue analyzers working as GCC (and the instruction sets themselves)
291 evolved became a substantial task.
293    To try to address this problem, the code in `prologue-value.h' and
294 `prologue-value.c' provides a general framework for writing prologue
295 analyzers that are simpler and more robust than ad-hoc analyzers.  When
296 we analyze a prologue using the prologue-value framework, we're really
297 doing "abstract interpretation" or "pseudo-evaluation": running the
298 function's code in simulation, but using conservative approximations of
299 the values registers and memory would hold when the code actually runs.
300 For example, if our function starts with the instruction:
302      addi r1, 42     # add 42 to r1
303    we don't know exactly what value will be in `r1' after executing
304 this instruction, but we do know it'll be 42 greater than its original
305 value.
307    If we then see an instruction like:
309      addi r1, 22     # add 22 to r1
310    we still don't know what `r1's' value is, but again, we can say it
311 is now 64 greater than its original value.
313    If the next instruction were:
315      mov r2, r1      # set r2 to r1's value
316    then we can say that `r2's' value is now the original value of `r1'
317 plus 64.
319    It's common for prologues to save registers on the stack, so we'll
320 need to track the values of stack frame slots, as well as the
321 registers.  So after an instruction like this:
323      mov (fp+4), r2
324    then we'd know that the stack slot four bytes above the frame pointer
325 holds the original value of `r1' plus 64.
327    And so on.
329    Of course, this can only go so far before it gets unreasonable.  If
330 we wanted to be able to say anything about the value of `r1' after the
331 instruction:
333      xor r1, r3      # exclusive-or r1 and r3, place result in r1
334    then things would get pretty complex.  But remember, we're just doing
335 a conservative approximation; if exclusive-or instructions aren't
336 relevant to prologues, we can just say `r1''s value is now "unknown".
337 We can ignore things that are too complex, if that loss of information
338 is acceptable for our application.
340    So when we say "conservative approximation" here, what we mean is an
341 approximation that is either accurate, or marked "unknown", but never
342 inaccurate.
344    Using this framework, a prologue analyzer is simply an interpreter
345 for machine code, but one that uses conservative approximations for the
346 contents of registers and memory instead of actual values.  Starting
347 from the function's entry point, you simulate instructions up to the
348 current PC, or an instruction that you don't know how to simulate.  Now
349 you can examine the state of the registers and stack slots you've kept
350 track of.
352    * To see how large your stack frame is, just check the value of the
353      stack pointer register; if it's the original value of the SP minus
354      a constant, then that constant is the stack frame's size.  If the
355      SP's value has been marked as "unknown", then that means the
356      prologue has done something too complex for us to track, and we
357      don't know the frame size.
359    * To see where we've saved the previous frame's registers, we just
360      search the values we've tracked -- stack slots, usually, but
361      registers, too, if you want -- for something equal to the
362      register's original value.  If the calling conventions suggest a
363      standard place to save a given register, then we can check there
364      first, but really, anything that will get us back the original
365      value will probably work.
367    This does take some work.  But prologue analyzers aren't
368 quick-and-simple pattern patching to recognize a few fixed prologue
369 forms any more; they're big, hairy functions.  Along with inferior
370 function calls, prologue analysis accounts for a substantial portion of
371 the time needed to stabilize a GDB port.  So it's worthwhile to look
372 for an approach that will be easier to understand and maintain.  In the
373 approach described above:
375    * It's easier to see that the analyzer is correct: you just see
376      whether the analyzer properly (albeit conservatively) simulates
377      the effect of each instruction.
379    * It's easier to extend the analyzer: you can add support for new
380      instructions, and know that you haven't broken anything that
381      wasn't already broken before.
383    * It's orthogonal: to gather new information, you don't need to
384      complicate the code for each instruction.  As long as your domain
385      of conservative values is already detailed enough to tell you what
386      you need, then all the existing instruction simulations are
387      already gathering the right data for you.
390    The file `prologue-value.h' contains detailed comments explaining
391 the framework and how to use it.
393 3.3 Breakpoint Handling
394 =======================
396 In general, a breakpoint is a user-designated location in the program
397 where the user wants to regain control if program execution ever reaches
398 that location.
400    There are two main ways to implement breakpoints; either as
401 "hardware" breakpoints or as "software" breakpoints.
403    Hardware breakpoints are sometimes available as a builtin debugging
404 features with some chips.  Typically these work by having dedicated
405 register into which the breakpoint address may be stored.  If the PC
406 (shorthand for "program counter") ever matches a value in a breakpoint
407 registers, the CPU raises an exception and reports it to GDB.
409    Another possibility is when an emulator is in use; many emulators
410 include circuitry that watches the address lines coming out from the
411 processor, and force it to stop if the address matches a breakpoint's
412 address.
414    A third possibility is that the target already has the ability to do
415 breakpoints somehow; for instance, a ROM monitor may do its own
416 software breakpoints.  So although these are not literally "hardware
417 breakpoints", from GDB's point of view they work the same; GDB need not
418 do anything more than set the breakpoint and wait for something to
419 happen.
421    Since they depend on hardware resources, hardware breakpoints may be
422 limited in number; when the user asks for more, GDB will start trying
423 to set software breakpoints.  (On some architectures, notably the
424 32-bit x86 platforms, GDB cannot always know whether there's enough
425 hardware resources to insert all the hardware breakpoints and
426 watchpoints.  On those platforms, GDB prints an error message only when
427 the program being debugged is continued.)
429    Software breakpoints require GDB to do somewhat more work.  The
430 basic theory is that GDB will replace a program instruction with a
431 trap, illegal divide, or some other instruction that will cause an
432 exception, and then when it's encountered, GDB will take the exception
433 and stop the program.  When the user says to continue, GDB will restore
434 the original instruction, single-step, re-insert the trap, and continue
437    Since it literally overwrites the program being tested, the program
438 area must be writable, so this technique won't work on programs in ROM.
439 It can also distort the behavior of programs that examine themselves,
440 although such a situation would be highly unusual.
442    Also, the software breakpoint instruction should be the smallest
443 size of instruction, so it doesn't overwrite an instruction that might
444 be a jump target, and cause disaster when the program jumps into the
445 middle of the breakpoint instruction.  (Strictly speaking, the
446 breakpoint must be no larger than the smallest interval between
447 instructions that may be jump targets; perhaps there is an architecture
448 where only even-numbered instructions may jumped to.)  Note that it's
449 possible for an instruction set not to have any instructions usable for
450 a software breakpoint, although in practice only the ARC has failed to
451 define such an instruction.
453    The basic definition of the software breakpoint is the macro
454 `BREAKPOINT'.
456    Basic breakpoint object handling is in `breakpoint.c'.  However,
457 much of the interesting breakpoint action is in `infrun.c'.
459 `target_remove_breakpoint (BP_TGT)'
460 `target_insert_breakpoint (BP_TGT)'
461      Insert or remove a software breakpoint at address
462      `BP_TGT->placed_address'.  Returns zero for success, non-zero for
463      failure.  On input, BP_TGT contains the address of the breakpoint,
464      and is otherwise initialized to zero.  The fields of the `struct
465      bp_target_info' pointed to by BP_TGT are updated to contain other
466      information about the breakpoint on output.  The field
467      `placed_address' may be updated if the breakpoint was placed at a
468      related address; the field `shadow_contents' contains the real
469      contents of the bytes where the breakpoint has been inserted, if
470      reading memory would return the breakpoint instead of the
471      underlying memory; the field `shadow_len' is the length of memory
472      cached in `shadow_contents', if any; and the field `placed_size'
473      is optionally set and used by the target, if it could differ from
474      `shadow_len'.
476      For example, the remote target `Z0' packet does not require
477      shadowing memory, so `shadow_len' is left at zero.  However, the
478      length reported by `gdbarch_breakpoint_from_pc' is cached in
479      `placed_size', so that a matching `z0' packet can be used to
480      remove the breakpoint.
482 `target_remove_hw_breakpoint (BP_TGT)'
483 `target_insert_hw_breakpoint (BP_TGT)'
484      Insert or remove a hardware-assisted breakpoint at address
485      `BP_TGT->placed_address'.  Returns zero for success, non-zero for
486      failure.  See `target_insert_breakpoint' for a description of the
487      `struct bp_target_info' pointed to by BP_TGT; the
488      `shadow_contents' and `shadow_len' members are not used for
489      hardware breakpoints, but `placed_size' may be.
491 3.4 Single Stepping
492 ===================
494 3.5 Signal Handling
495 ===================
497 3.6 Thread Handling
498 ===================
500 3.7 Inferior Function Calls
501 ===========================
503 3.8 Longjmp Support
504 ===================
506 GDB has support for figuring out that the target is doing a `longjmp'
507 and for stopping at the target of the jump, if we are stepping.  This
508 is done with a few specialized internal breakpoints, which are visible
509 in the output of the `maint info breakpoint' command.
511    To make this work, you need to define a function called
512 `gdbarch_get_longjmp_target', which will examine the `jmp_buf'
513 structure and extract the longjmp target address.  Since `jmp_buf' is
514 target specific, you will need to define it in the appropriate
515 `tm-TARGET.h' file.  Look in `tm-sun4os4.h' and `sparc-tdep.c' for
516 examples of how to do this.
518 3.9 Watchpoints
519 ===============
521 Watchpoints are a special kind of breakpoints (*note breakpoints:
522 Algorithms.) which break when data is accessed rather than when some
523 instruction is executed.  When you have data which changes without your
524 knowing what code does that, watchpoints are the silver bullet to hunt
525 down and kill such bugs.
527    Watchpoints can be either hardware-assisted or not; the latter type
528 is known as "software watchpoints."  GDB always uses hardware-assisted
529 watchpoints if they are available, and falls back on software
530 watchpoints otherwise.  Typical situations where GDB will use software
531 watchpoints are:
533    * The watched memory region is too large for the underlying hardware
534      watchpoint support.  For example, each x86 debug register can
535      watch up to 4 bytes of memory, so trying to watch data structures
536      whose size is more than 16 bytes will cause GDB to use software
537      watchpoints.
539    * The value of the expression to be watched depends on data held in
540      registers (as opposed to memory).
542    * Too many different watchpoints requested.  (On some architectures,
543      this situation is impossible to detect until the debugged program
544      is resumed.)  Note that x86 debug registers are used both for
545      hardware breakpoints and for watchpoints, so setting too many
546      hardware breakpoints might cause watchpoint insertion to fail.
548    * No hardware-assisted watchpoints provided by the target
549      implementation.
551    Software watchpoints are very slow, since GDB needs to single-step
552 the program being debugged and test the value of the watched
553 expression(s) after each instruction.  The rest of this section is
554 mostly irrelevant for software watchpoints.
556    When the inferior stops, GDB tries to establish, among other
557 possible reasons, whether it stopped due to a watchpoint being hit.  It
558 first uses `STOPPED_BY_WATCHPOINT' to see if any watchpoint was hit.
559 If not, all watchpoint checking is skipped.
561    Then GDB calls `target_stopped_data_address' exactly once.  This
562 method returns the address of the watchpoint which triggered, if the
563 target can determine it.  If the triggered address is available, GDB
564 compares the address returned by this method with each watched memory
565 address in each active watchpoint.  For data-read and data-access
566 watchpoints, GDB announces every watchpoint that watches the triggered
567 address as being hit.  For this reason, data-read and data-access
568 watchpoints _require_ that the triggered address be available; if not,
569 read and access watchpoints will never be considered hit.  For
570 data-write watchpoints, if the triggered address is available, GDB
571 considers only those watchpoints which match that address; otherwise,
572 GDB considers all data-write watchpoints.  For each data-write
573 watchpoint that GDB considers, it evaluates the expression whose value
574 is being watched, and tests whether the watched value has changed.
575 Watchpoints whose watched values have changed are announced as hit.
577    GDB uses several macros and primitives to support hardware
578 watchpoints:
580 `TARGET_HAS_HARDWARE_WATCHPOINTS'
581      If defined, the target supports hardware watchpoints.
583 `TARGET_CAN_USE_HARDWARE_WATCHPOINT (TYPE, COUNT, OTHER)'
584      Return the number of hardware watchpoints of type TYPE that are
585      possible to be set.  The value is positive if COUNT watchpoints of
586      this type can be set, zero if setting watchpoints of this type is
587      not supported, and negative if COUNT is more than the maximum
588      number of watchpoints of type TYPE that can be set.  OTHER is
589      non-zero if other types of watchpoints are currently enabled (there
590      are architectures which cannot set watchpoints of different types
591      at the same time).
593 `TARGET_REGION_OK_FOR_HW_WATCHPOINT (ADDR, LEN)'
594      Return non-zero if hardware watchpoints can be used to watch a
595      region whose address is ADDR and whose length in bytes is LEN.
597 `target_insert_watchpoint (ADDR, LEN, TYPE)'
598 `target_remove_watchpoint (ADDR, LEN, TYPE)'
599      Insert or remove a hardware watchpoint starting at ADDR, for LEN
600      bytes.  TYPE is the watchpoint type, one of the possible values of
601      the enumerated data type `target_hw_bp_type', defined by
602      `breakpoint.h' as follows:
604            enum target_hw_bp_type
605              {
606                hw_write   = 0, /* Common (write) HW watchpoint */
607                hw_read    = 1, /* Read    HW watchpoint */
608                hw_access  = 2, /* Access (read or write) HW watchpoint */
609                hw_execute = 3  /* Execute HW breakpoint */
610              };
612      These two macros should return 0 for success, non-zero for failure.
614 `target_stopped_data_address (ADDR_P)'
615      If the inferior has some watchpoint that triggered, place the
616      address associated with the watchpoint at the location pointed to
617      by ADDR_P and return non-zero.  Otherwise, return zero.  This is
618      required for data-read and data-access watchpoints.  It is not
619      required for data-write watchpoints, but GDB uses it to improve
620      handling of those also.
622      GDB will only call this method once per watchpoint stop,
623      immediately after calling `STOPPED_BY_WATCHPOINT'.  If the
624      target's watchpoint indication is sticky, i.e., stays set after
625      resuming, this method should clear it.  For instance, the x86 debug
626      control register has sticky triggered flags.
628 `HAVE_STEPPABLE_WATCHPOINT'
629      If defined to a non-zero value, it is not necessary to disable a
630      watchpoint to step over it.    Like
631      `gdbarch_have_nonsteppable_watchpoint', this is usually set when
632      watchpoints trigger at the instruction which will perform an
633      interesting read or write.  It should be set if there is a
634      temporary disable bit which allows the processor to step over the
635      interesting instruction without raising the watchpoint exception
636      again.
638 `int gdbarch_have_nonsteppable_watchpoint (GDBARCH)'
639      If it returns a non-zero value, GDB should disable a watchpoint to
640      step the inferior over it.  This is usually set when watchpoints
641      trigger at the instruction which will perform an interesting read
642      or write.
644 `HAVE_CONTINUABLE_WATCHPOINT'
645      If defined to a non-zero value, it is possible to continue the
646      inferior after a watchpoint has been hit.  This is usually set
647      when watchpoints trigger at the instruction following an
648      interesting read or write.
650 `CANNOT_STEP_HW_WATCHPOINTS'
651      If this is defined to a non-zero value, GDB will remove all
652      watchpoints before stepping the inferior.
654 `STOPPED_BY_WATCHPOINT (WAIT_STATUS)'
655      Return non-zero if stopped by a watchpoint.  WAIT_STATUS is of the
656      type `struct target_waitstatus', defined by `target.h'.  Normally,
657      this macro is defined to invoke the function pointed to by the
658      `to_stopped_by_watchpoint' member of the structure (of the type
659      `target_ops', defined on `target.h') that describes the
660      target-specific operations; `to_stopped_by_watchpoint' ignores the
661      WAIT_STATUS argument.
663      GDB does not require the non-zero value returned by
664      `STOPPED_BY_WATCHPOINT' to be 100% correct, so if a target cannot
665      determine for sure whether the inferior stopped due to a
666      watchpoint, it could return non-zero "just in case".
668 3.9.1 Watchpoints and Threads
669 -----------------------------
671 GDB only supports process-wide watchpoints, which trigger in all
672 threads.  GDB uses the thread ID to make watchpoints act as if they
673 were thread-specific, but it cannot set hardware watchpoints that only
674 trigger in a specific thread.  Therefore, even if the target supports
675 threads, per-thread debug registers, and watchpoints which only affect
676 a single thread, it should set the per-thread debug registers for all
677 threads to the same value.  On GNU/Linux native targets, this is
678 accomplished by using `ALL_LWPS' in `target_insert_watchpoint' and
679 `target_remove_watchpoint' and by using `linux_set_new_thread' to
680 register a handler for newly created threads.
682    GDB's GNU/Linux support only reports a single event at a time,
683 although multiple events can trigger simultaneously for multi-threaded
684 programs.  When multiple events occur, `linux-nat.c' queues subsequent
685 events and returns them the next time the program is resumed.  This
686 means that `STOPPED_BY_WATCHPOINT' and `target_stopped_data_address'
687 only need to consult the current thread's state--the thread indicated
688 by `inferior_ptid'.  If two threads have hit watchpoints
689 simultaneously, those routines will be called a second time for the
690 second thread.
692 3.9.2 x86 Watchpoints
693 ---------------------
695 The 32-bit Intel x86 (a.k.a. ia32) processors feature special debug
696 registers designed to facilitate debugging.  GDB provides a generic
697 library of functions that x86-based ports can use to implement support
698 for watchpoints and hardware-assisted breakpoints.  This subsection
699 documents the x86 watchpoint facilities in GDB.
701    To use the generic x86 watchpoint support, a port should do the
702 following:
704    * Define the macro `I386_USE_GENERIC_WATCHPOINTS' somewhere in the
705      target-dependent headers.
707    * Include the `config/i386/nm-i386.h' header file _after_ defining
708      `I386_USE_GENERIC_WATCHPOINTS'.
710    * Add `i386-nat.o' to the value of the Make variable `NATDEPFILES'
711      (*note NATDEPFILES: Native Debugging.) or `TDEPFILES' (*note
712      TDEPFILES: Target Architecture Definition.).
714    * Provide implementations for the `I386_DR_LOW_*' macros described
715      below.  Typically, each macro should call a target-specific
716      function which does the real work.
718    The x86 watchpoint support works by maintaining mirror images of the
719 debug registers.  Values are copied between the mirror images and the
720 real debug registers via a set of macros which each target needs to
721 provide:
723 `I386_DR_LOW_SET_CONTROL (VAL)'
724      Set the Debug Control (DR7) register to the value VAL.
726 `I386_DR_LOW_SET_ADDR (IDX, ADDR)'
727      Put the address ADDR into the debug register number IDX.
729 `I386_DR_LOW_RESET_ADDR (IDX)'
730      Reset (i.e. zero out) the address stored in the debug register
731      number IDX.
733 `I386_DR_LOW_GET_STATUS'
734      Return the value of the Debug Status (DR6) register.  This value is
735      used immediately after it is returned by `I386_DR_LOW_GET_STATUS',
736      so as to support per-thread status register values.
738    For each one of the 4 debug registers (whose indices are from 0 to 3)
739 that store addresses, a reference count is maintained by GDB, to allow
740 sharing of debug registers by several watchpoints.  This allows users
741 to define several watchpoints that watch the same expression, but with
742 different conditions and/or commands, without wasting debug registers
743 which are in short supply.  GDB maintains the reference counts
744 internally, targets don't have to do anything to use this feature.
746    The x86 debug registers can each watch a region that is 1, 2, or 4
747 bytes long.  The ia32 architecture requires that each watched region be
748 appropriately aligned: 2-byte region on 2-byte boundary, 4-byte region
749 on 4-byte boundary.  However, the x86 watchpoint support in GDB can
750 watch unaligned regions and regions larger than 4 bytes (up to 16
751 bytes) by allocating several debug registers to watch a single region.
752 This allocation of several registers per a watched region is also done
753 automatically without target code intervention.
755    The generic x86 watchpoint support provides the following API for the
756 GDB's application code:
758 `i386_region_ok_for_watchpoint (ADDR, LEN)'
759      The macro `TARGET_REGION_OK_FOR_HW_WATCHPOINT' is set to call this
760      function.  It counts the number of debug registers required to
761      watch a given region, and returns a non-zero value if that number
762      is less than 4, the number of debug registers available to x86
763      processors.
765 `i386_stopped_data_address (ADDR_P)'
766      The target function `target_stopped_data_address' is set to call
767      this function.  This function examines the breakpoint condition
768      bits in the DR6 Debug Status register, as returned by the
769      `I386_DR_LOW_GET_STATUS' macro, and returns the address associated
770      with the first bit that is set in DR6.
772 `i386_stopped_by_watchpoint (void)'
773      The macro `STOPPED_BY_WATCHPOINT' is set to call this function.
774      The argument passed to `STOPPED_BY_WATCHPOINT' is ignored.  This
775      function examines the breakpoint condition bits in the DR6 Debug
776      Status register, as returned by the `I386_DR_LOW_GET_STATUS'
777      macro, and returns true if any bit is set.  Otherwise, false is
778      returned.
780 `i386_insert_watchpoint (ADDR, LEN, TYPE)'
781 `i386_remove_watchpoint (ADDR, LEN, TYPE)'
782      Insert or remove a watchpoint.  The macros
783      `target_insert_watchpoint' and `target_remove_watchpoint' are set
784      to call these functions.  `i386_insert_watchpoint' first looks for
785      a debug register which is already set to watch the same region for
786      the same access types; if found, it just increments the reference
787      count of that debug register, thus implementing debug register
788      sharing between watchpoints.  If no such register is found, the
789      function looks for a vacant debug register, sets its mirrored
790      value to ADDR, sets the mirrored value of DR7 Debug Control
791      register as appropriate for the LEN and TYPE parameters, and then
792      passes the new values of the debug register and DR7 to the
793      inferior by calling `I386_DR_LOW_SET_ADDR' and
794      `I386_DR_LOW_SET_CONTROL'.  If more than one debug register is
795      required to cover the given region, the above process is repeated
796      for each debug register.
798      `i386_remove_watchpoint' does the opposite: it resets the address
799      in the mirrored value of the debug register and its read/write and
800      length bits in the mirrored value of DR7, then passes these new
801      values to the inferior via `I386_DR_LOW_RESET_ADDR' and
802      `I386_DR_LOW_SET_CONTROL'.  If a register is shared by several
803      watchpoints, each time a `i386_remove_watchpoint' is called, it
804      decrements the reference count, and only calls
805      `I386_DR_LOW_RESET_ADDR' and `I386_DR_LOW_SET_CONTROL' when the
806      count goes to zero.
808 `i386_insert_hw_breakpoint (BP_TGT)'
809 `i386_remove_hw_breakpoint (BP_TGT)'
810      These functions insert and remove hardware-assisted breakpoints.
811      The macros `target_insert_hw_breakpoint' and
812      `target_remove_hw_breakpoint' are set to call these functions.
813      The argument is a `struct bp_target_info *', as described in the
814      documentation for `target_insert_breakpoint'.  These functions
815      work like `i386_insert_watchpoint' and `i386_remove_watchpoint',
816      respectively, except that they set up the debug registers to watch
817      instruction execution, and each hardware-assisted breakpoint
818      always requires exactly one debug register.
820 `i386_stopped_by_hwbp (void)'
821      This function returns non-zero if the inferior has some watchpoint
822      or hardware breakpoint that triggered.  It works like
823      `i386_stopped_data_address', except that it doesn't record the
824      address whose watchpoint triggered.
826 `i386_cleanup_dregs (void)'
827      This function clears all the reference counts, addresses, and
828      control bits in the mirror images of the debug registers.  It
829      doesn't affect the actual debug registers in the inferior process.
831 *Notes:*
832   1. x86 processors support setting watchpoints on I/O reads or writes.
833      However, since no target supports this (as of March 2001), and
834      since `enum target_hw_bp_type' doesn't even have an enumeration
835      for I/O watchpoints, this feature is not yet available to GDB
836      running on x86.
838   2. x86 processors can enable watchpoints locally, for the current task
839      only, or globally, for all the tasks.  For each debug register,
840      there's a bit in the DR7 Debug Control register that determines
841      whether the associated address is watched locally or globally.  The
842      current implementation of x86 watchpoint support in GDB always
843      sets watchpoints to be locally enabled, since global watchpoints
844      might interfere with the underlying OS and are probably
845      unavailable in many platforms.
847 3.10 Checkpoints
848 ================
850 In the abstract, a checkpoint is a point in the execution history of
851 the program, which the user may wish to return to at some later time.
853    Internally, a checkpoint is a saved copy of the program state,
854 including whatever information is required in order to restore the
855 program to that state at a later time.  This can be expected to include
856 the state of registers and memory, and may include external state such
857 as the state of open files and devices.
859    There are a number of ways in which checkpoints may be implemented
860 in gdb, e.g. as corefiles, as forked processes, and as some opaque
861 method implemented on the target side.
863    A corefile can be used to save an image of target memory and register
864 state, which can in principle be restored later -- but corefiles do not
865 typically include information about external entities such as open
866 files.  Currently this method is not implemented in gdb.
868    A forked process can save the state of user memory and registers, as
869 well as some subset of external (kernel) state.  This method is used to
870 implement checkpoints on Linux, and in principle might be used on other
871 systems.
873    Some targets, e.g. simulators, might have their own built-in method
874 for saving checkpoints, and gdb might be able to take advantage of that
875 capability without necessarily knowing any details of how it is done.
877 3.11 Observing changes in GDB internals
878 =======================================
880 In order to function properly, several modules need to be notified when
881 some changes occur in the GDB internals.  Traditionally, these modules
882 have relied on several paradigms, the most common ones being hooks and
883 gdb-events.  Unfortunately, none of these paradigms was versatile
884 enough to become the standard notification mechanism in GDB.  The fact
885 that they only supported one "client" was also a strong limitation.
887    A new paradigm, based on the Observer pattern of the `Design
888 Patterns' book, has therefore been implemented.  The goal was to provide
889 a new interface overcoming the issues with the notification mechanisms
890 previously available.  This new interface needed to be strongly typed,
891 easy to extend, and versatile enough to be used as the standard
892 interface when adding new notifications.
894    See *Note GDB Observers:: for a brief description of the observers
895 currently implemented in GDB. The rationale for the current
896 implementation is also briefly discussed.
898 \x1f
899 File: gdbint.info,  Node: User Interface,  Next: libgdb,  Prev: Algorithms,  Up: Top
901 4 User Interface
902 ****************
904 GDB has several user interfaces.  Although the command-line interface
905 is the most common and most familiar, there are others.
907 4.1 Command Interpreter
908 =======================
910 The command interpreter in GDB is fairly simple.  It is designed to
911 allow for the set of commands to be augmented dynamically, and also has
912 a recursive subcommand capability, where the first argument to a
913 command may itself direct a lookup on a different command list.
915    For instance, the `set' command just starts a lookup on the
916 `setlist' command list, while `set thread' recurses to the
917 `set_thread_cmd_list'.
919    To add commands in general, use `add_cmd'.  `add_com' adds to the
920 main command list, and should be used for those commands.  The usual
921 place to add commands is in the `_initialize_XYZ' routines at the ends
922 of most source files.
924    To add paired `set' and `show' commands, use `add_setshow_cmd' or
925 `add_setshow_cmd_full'.  The former is a slightly simpler interface
926 which is useful when you don't need to further modify the new command
927 structures, while the latter returns the new command structures for
928 manipulation.
930    Before removing commands from the command set it is a good idea to
931 deprecate them for some time.  Use `deprecate_cmd' on commands or
932 aliases to set the deprecated flag.  `deprecate_cmd' takes a `struct
933 cmd_list_element' as it's first argument.  You can use the return value
934 from `add_com' or `add_cmd' to deprecate the command immediately after
935 it is created.
937    The first time a command is used the user will be warned and offered
938 a replacement (if one exists). Note that the replacement string passed
939 to `deprecate_cmd' should be the full name of the command, i.e., the
940 entire string the user should type at the command line.
942 4.2 UI-Independent Output--the `ui_out' Functions
943 =================================================
945 The `ui_out' functions present an abstraction level for the GDB output
946 code.  They hide the specifics of different user interfaces supported
947 by GDB, and thus free the programmer from the need to write several
948 versions of the same code, one each for every UI, to produce output.
950 4.2.1 Overview and Terminology
951 ------------------------------
953 In general, execution of each GDB command produces some sort of output,
954 and can even generate an input request.
956    Output can be generated for the following purposes:
958    * to display a _result_ of an operation;
960    * to convey _info_ or produce side-effects of a requested operation;
962    * to provide a _notification_ of an asynchronous event (including
963      progress indication of a prolonged asynchronous operation);
965    * to display _error messages_ (including warnings);
967    * to show _debug data_;
969    * to _query_ or prompt a user for input (a special case).
971 This section mainly concentrates on how to build result output,
972 although some of it also applies to other kinds of output.
974    Generation of output that displays the results of an operation
975 involves one or more of the following:
977    * output of the actual data
979    * formatting the output as appropriate for console output, to make it
980      easily readable by humans
982    * machine oriented formatting-a more terse formatting to allow for
983      easy parsing by programs which read GDB's output
985    * annotation, whose purpose is to help legacy GUIs to identify
986      interesting parts in the output
988    The `ui_out' routines take care of the first three aspects.
989 Annotations are provided by separate annotation routines.  Note that use
990 of annotations for an interface between a GUI and GDB is deprecated.
992    Output can be in the form of a single item, which we call a "field";
993 a "list" consisting of identical fields; a "tuple" consisting of
994 non-identical fields; or a "table", which is a tuple consisting of a
995 header and a body.  In a BNF-like form:
997 `<table> ==>'
998      `<header> <body>'
1000 `<header> ==>'
1001      `{ <column> }'
1003 `<column> ==>'
1004      `<width> <alignment> <title>'
1006 `<body> ==>'
1007      `{<row>}'
1009 4.2.2 General Conventions
1010 -------------------------
1012 Most `ui_out' routines are of type `void', the exceptions are
1013 `ui_out_stream_new' (which returns a pointer to the newly created
1014 object) and the `make_cleanup' routines.
1016    The first parameter is always the `ui_out' vector object, a pointer
1017 to a `struct ui_out'.
1019    The FORMAT parameter is like in `printf' family of functions.  When
1020 it is present, there must also be a variable list of arguments
1021 sufficient used to satisfy the `%' specifiers in the supplied format.
1023    When a character string argument is not used in a `ui_out' function
1024 call, a `NULL' pointer has to be supplied instead.
1026 4.2.3 Table, Tuple and List Functions
1027 -------------------------------------
1029 This section introduces `ui_out' routines for building lists, tuples
1030 and tables.  The routines to output the actual data items (fields) are
1031 presented in the next section.
1033    To recap: A "tuple" is a sequence of "fields", each field containing
1034 information about an object; a "list" is a sequence of fields where
1035 each field describes an identical object.
1037    Use the "table" functions when your output consists of a list of
1038 rows (tuples) and the console output should include a heading.  Use this
1039 even when you are listing just one object but you still want the header.
1041    Tables can not be nested.  Tuples and lists can be nested up to a
1042 maximum of five levels.
1044    The overall structure of the table output code is something like
1045 this:
1047        ui_out_table_begin
1048          ui_out_table_header
1049          ...
1050          ui_out_table_body
1051            ui_out_tuple_begin
1052              ui_out_field_*
1053              ...
1054            ui_out_tuple_end
1055            ...
1056        ui_out_table_end
1058    Here is the description of table-, tuple- and list-related `ui_out'
1059 functions:
1061  -- Function: void ui_out_table_begin (struct ui_out *UIOUT, int
1062           NBROFCOLS, int NR_ROWS, const char *TBLID)
1063      The function `ui_out_table_begin' marks the beginning of the output
1064      of a table.  It should always be called before any other `ui_out'
1065      function for a given table.  NBROFCOLS is the number of columns in
1066      the table. NR_ROWS is the number of rows in the table.  TBLID is
1067      an optional string identifying the table.  The string pointed to
1068      by TBLID is copied by the implementation of `ui_out_table_begin',
1069      so the application can free the string if it was `malloc'ed.
1071      The companion function `ui_out_table_end', described below, marks
1072      the end of the table's output.
1074  -- Function: void ui_out_table_header (struct ui_out *UIOUT, int
1075           WIDTH, enum ui_align ALIGNMENT, const char *COLHDR)
1076      `ui_out_table_header' provides the header information for a single
1077      table column.  You call this function several times, one each for
1078      every column of the table, after `ui_out_table_begin', but before
1079      `ui_out_table_body'.
1081      The value of WIDTH gives the column width in characters.  The
1082      value of ALIGNMENT is one of `left', `center', and `right', and it
1083      specifies how to align the header: left-justify, center, or
1084      right-justify it.  COLHDR points to a string that specifies the
1085      column header; the implementation copies that string, so column
1086      header strings in `malloc'ed storage can be freed after the call.
1088  -- Function: void ui_out_table_body (struct ui_out *UIOUT)
1089      This function delimits the table header from the table body.
1091  -- Function: void ui_out_table_end (struct ui_out *UIOUT)
1092      This function signals the end of a table's output.  It should be
1093      called after the table body has been produced by the list and
1094      field output functions.
1096      There should be exactly one call to `ui_out_table_end' for each
1097      call to `ui_out_table_begin', otherwise the `ui_out' functions
1098      will signal an internal error.
1100    The output of the tuples that represent the table rows must follow
1101 the call to `ui_out_table_body' and precede the call to
1102 `ui_out_table_end'.  You build a tuple by calling `ui_out_tuple_begin'
1103 and `ui_out_tuple_end', with suitable calls to functions which actually
1104 output fields between them.
1106  -- Function: void ui_out_tuple_begin (struct ui_out *UIOUT, const char
1107           *ID)
1108      This function marks the beginning of a tuple output.  ID points to
1109      an optional string that identifies the tuple; it is copied by the
1110      implementation, and so strings in `malloc'ed storage can be freed
1111      after the call.
1113  -- Function: void ui_out_tuple_end (struct ui_out *UIOUT)
1114      This function signals an end of a tuple output.  There should be
1115      exactly one call to `ui_out_tuple_end' for each call to
1116      `ui_out_tuple_begin', otherwise an internal GDB error will be
1117      signaled.
1119  -- Function: struct cleanup *make_cleanup_ui_out_tuple_begin_end
1120           (struct ui_out *UIOUT, const char *ID)
1121      This function first opens the tuple and then establishes a cleanup
1122      (*note Cleanups: Coding.) to close the tuple.  It provides a
1123      convenient and correct implementation of the non-portable(1) code
1124      sequence:
1125           struct cleanup *old_cleanup;
1126           ui_out_tuple_begin (uiout, "...");
1127           old_cleanup = make_cleanup ((void(*)(void *)) ui_out_tuple_end,
1128                                       uiout);
1130  -- Function: void ui_out_list_begin (struct ui_out *UIOUT, const char
1131           *ID)
1132      This function marks the beginning of a list output.  ID points to
1133      an optional string that identifies the list; it is copied by the
1134      implementation, and so strings in `malloc'ed storage can be freed
1135      after the call.
1137  -- Function: void ui_out_list_end (struct ui_out *UIOUT)
1138      This function signals an end of a list output.  There should be
1139      exactly one call to `ui_out_list_end' for each call to
1140      `ui_out_list_begin', otherwise an internal GDB error will be
1141      signaled.
1143  -- Function: struct cleanup *make_cleanup_ui_out_list_begin_end
1144           (struct ui_out *UIOUT, const char *ID)
1145      Similar to `make_cleanup_ui_out_tuple_begin_end', this function
1146      opens a list and then establishes cleanup (*note Cleanups: Coding.)
1147      that will close the list.
1149 4.2.4 Item Output Functions
1150 ---------------------------
1152 The functions described below produce output for the actual data items,
1153 or fields, which contain information about the object.
1155    Choose the appropriate function accordingly to your particular needs.
1157  -- Function: void ui_out_field_fmt (struct ui_out *UIOUT, char
1158           *FLDNAME, char *FORMAT, ...)
1159      This is the most general output function.  It produces the
1160      representation of the data in the variable-length argument list
1161      according to formatting specifications in FORMAT, a `printf'-like
1162      format string.  The optional argument FLDNAME supplies the name of
1163      the field.  The data items themselves are supplied as additional
1164      arguments after FORMAT.
1166      This generic function should be used only when it is not possible
1167      to use one of the specialized versions (see below).
1169  -- Function: void ui_out_field_int (struct ui_out *UIOUT, const char
1170           *FLDNAME, int VALUE)
1171      This function outputs a value of an `int' variable.  It uses the
1172      `"%d"' output conversion specification.  FLDNAME specifies the
1173      name of the field.
1175  -- Function: void ui_out_field_fmt_int (struct ui_out *UIOUT, int
1176           WIDTH, enum ui_align ALIGNMENT, const char *FLDNAME, int
1177           VALUE)
1178      This function outputs a value of an `int' variable.  It differs
1179      from `ui_out_field_int' in that the caller specifies the desired
1180      WIDTH and ALIGNMENT of the output.  FLDNAME specifies the name of
1181      the field.
1183  -- Function: void ui_out_field_core_addr (struct ui_out *UIOUT, const
1184           char *FLDNAME, CORE_ADDR ADDRESS)
1185      This function outputs an address.
1187  -- Function: void ui_out_field_string (struct ui_out *UIOUT, const
1188           char *FLDNAME, const char *STRING)
1189      This function outputs a string using the `"%s"' conversion
1190      specification.
1192    Sometimes, there's a need to compose your output piece by piece using
1193 functions that operate on a stream, such as `value_print' or
1194 `fprintf_symbol_filtered'.  These functions accept an argument of the
1195 type `struct ui_file *', a pointer to a `ui_file' object used to store
1196 the data stream used for the output.  When you use one of these
1197 functions, you need a way to pass their results stored in a `ui_file'
1198 object to the `ui_out' functions.  To this end, you first create a
1199 `ui_stream' object by calling `ui_out_stream_new', pass the `stream'
1200 member of that `ui_stream' object to `value_print' and similar
1201 functions, and finally call `ui_out_field_stream' to output the field
1202 you constructed.  When the `ui_stream' object is no longer needed, you
1203 should destroy it and free its memory by calling `ui_out_stream_delete'.
1205  -- Function: struct ui_stream *ui_out_stream_new (struct ui_out *UIOUT)
1206      This function creates a new `ui_stream' object which uses the same
1207      output methods as the `ui_out' object whose pointer is passed in
1208      UIOUT.  It returns a pointer to the newly created `ui_stream'
1209      object.
1211  -- Function: void ui_out_stream_delete (struct ui_stream *STREAMBUF)
1212      This functions destroys a `ui_stream' object specified by
1213      STREAMBUF.
1215  -- Function: void ui_out_field_stream (struct ui_out *UIOUT, const
1216           char *FIELDNAME, struct ui_stream *STREAMBUF)
1217      This function consumes all the data accumulated in
1218      `streambuf->stream' and outputs it like `ui_out_field_string'
1219      does.  After a call to `ui_out_field_stream', the accumulated data
1220      no longer exists, but the stream is still valid and may be used
1221      for producing more fields.
1223    *Important:* If there is any chance that your code could bail out
1224 before completing output generation and reaching the point where
1225 `ui_out_stream_delete' is called, it is necessary to set up a cleanup,
1226 to avoid leaking memory and other resources.  Here's a skeleton code to
1227 do that:
1229       struct ui_stream *mybuf = ui_out_stream_new (uiout);
1230       struct cleanup *old = make_cleanup (ui_out_stream_delete, mybuf);
1231       ...
1232       do_cleanups (old);
1234    If the function already has the old cleanup chain set (for other
1235 kinds of cleanups), you just have to add your cleanup to it:
1237        mybuf = ui_out_stream_new (uiout);
1238        make_cleanup (ui_out_stream_delete, mybuf);
1240    Note that with cleanups in place, you should not call
1241 `ui_out_stream_delete' directly, or you would attempt to free the same
1242 buffer twice.
1244 4.2.5 Utility Output Functions
1245 ------------------------------
1247  -- Function: void ui_out_field_skip (struct ui_out *UIOUT, const char
1248           *FLDNAME)
1249      This function skips a field in a table.  Use it if you have to
1250      leave an empty field without disrupting the table alignment.  The
1251      argument FLDNAME specifies a name for the (missing) filed.
1253  -- Function: void ui_out_text (struct ui_out *UIOUT, const char
1254           *STRING)
1255      This function outputs the text in STRING in a way that makes it
1256      easy to be read by humans.  For example, the console
1257      implementation of this method filters the text through a built-in
1258      pager, to prevent it from scrolling off the visible portion of the
1259      screen.
1261      Use this function for printing relatively long chunks of text
1262      around the actual field data: the text it produces is not aligned
1263      according to the table's format.  Use `ui_out_field_string' to
1264      output a string field, and use `ui_out_message', described below,
1265      to output short messages.
1267  -- Function: void ui_out_spaces (struct ui_out *UIOUT, int NSPACES)
1268      This function outputs NSPACES spaces.  It is handy to align the
1269      text produced by `ui_out_text' with the rest of the table or list.
1271  -- Function: void ui_out_message (struct ui_out *UIOUT, int VERBOSITY,
1272           const char *FORMAT, ...)
1273      This function produces a formatted message, provided that the
1274      current verbosity level is at least as large as given by
1275      VERBOSITY.  The current verbosity level is specified by the user
1276      with the `set verbositylevel' command.(2)
1278  -- Function: void ui_out_wrap_hint (struct ui_out *UIOUT, char *INDENT)
1279      This function gives the console output filter (a paging filter) a
1280      hint of where to break lines which are too long.  Ignored for all
1281      other output consumers.  INDENT, if non-`NULL', is the string to
1282      be printed to indent the wrapped text on the next line; it must
1283      remain accessible until the next call to `ui_out_wrap_hint', or
1284      until an explicit newline is produced by one of the other
1285      functions.  If INDENT is `NULL', the wrapped text will not be
1286      indented.
1288  -- Function: void ui_out_flush (struct ui_out *UIOUT)
1289      This function flushes whatever output has been accumulated so far,
1290      if the UI buffers output.
1292 4.2.6 Examples of Use of `ui_out' functions
1293 -------------------------------------------
1295 This section gives some practical examples of using the `ui_out'
1296 functions to generalize the old console-oriented code in GDB.  The
1297 examples all come from functions defined on the `breakpoints.c' file.
1299    This example, from the `breakpoint_1' function, shows how to produce
1300 a table.
1302    The original code was:
1304       if (!found_a_breakpoint++)
1305         {
1306           annotate_breakpoints_headers ();
1308           annotate_field (0);
1309           printf_filtered ("Num ");
1310           annotate_field (1);
1311           printf_filtered ("Type           ");
1312           annotate_field (2);
1313           printf_filtered ("Disp ");
1314           annotate_field (3);
1315           printf_filtered ("Enb ");
1316           if (addressprint)
1317             {
1318               annotate_field (4);
1319               printf_filtered ("Address    ");
1320             }
1321           annotate_field (5);
1322           printf_filtered ("What\n");
1324           annotate_breakpoints_table ();
1325         }
1327    Here's the new version:
1329        nr_printable_breakpoints = ...;
1331        if (addressprint)
1332          ui_out_table_begin (ui, 6, nr_printable_breakpoints, "BreakpointTable");
1333        else
1334          ui_out_table_begin (ui, 5, nr_printable_breakpoints, "BreakpointTable");
1336        if (nr_printable_breakpoints > 0)
1337          annotate_breakpoints_headers ();
1338        if (nr_printable_breakpoints > 0)
1339          annotate_field (0);
1340        ui_out_table_header (uiout, 3, ui_left, "number", "Num");                /* 1 */
1341        if (nr_printable_breakpoints > 0)
1342          annotate_field (1);
1343        ui_out_table_header (uiout, 14, ui_left, "type", "Type");                /* 2 */
1344        if (nr_printable_breakpoints > 0)
1345          annotate_field (2);
1346        ui_out_table_header (uiout, 4, ui_left, "disp", "Disp");         /* 3 */
1347        if (nr_printable_breakpoints > 0)
1348          annotate_field (3);
1349        ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb");       /* 4 */
1350        if (addressprint)
1351          {
1352           if (nr_printable_breakpoints > 0)
1353             annotate_field (4);
1354           if (gdbarch_addr_bit (current_gdbarch) <= 32)
1355             ui_out_table_header (uiout, 10, ui_left, "addr", "Address");/* 5 */
1356           else
1357             ui_out_table_header (uiout, 18, ui_left, "addr", "Address");/* 5 */
1358          }
1359        if (nr_printable_breakpoints > 0)
1360          annotate_field (5);
1361        ui_out_table_header (uiout, 40, ui_noalign, "what", "What");     /* 6 */
1362        ui_out_table_body (uiout);
1363        if (nr_printable_breakpoints > 0)
1364          annotate_breakpoints_table ();
1366    This example, from the `print_one_breakpoint' function, shows how to
1367 produce the actual data for the table whose structure was defined in
1368 the above example.  The original code was:
1370         annotate_record ();
1371         annotate_field (0);
1372         printf_filtered ("%-3d ", b->number);
1373         annotate_field (1);
1374         if ((int)b->type > (sizeof(bptypes)/sizeof(bptypes[0]))
1375             || ((int) b->type != bptypes[(int) b->type].type))
1376           internal_error ("bptypes table does not describe type #%d.",
1377                           (int)b->type);
1378         printf_filtered ("%-14s ", bptypes[(int)b->type].description);
1379         annotate_field (2);
1380         printf_filtered ("%-4s ", bpdisps[(int)b->disposition]);
1381         annotate_field (3);
1382         printf_filtered ("%-3c ", bpenables[(int)b->enable]);
1383         ...
1385    This is the new version:
1387         annotate_record ();
1388         ui_out_tuple_begin (uiout, "bkpt");
1389         annotate_field (0);
1390         ui_out_field_int (uiout, "number", b->number);
1391         annotate_field (1);
1392         if (((int) b->type > (sizeof (bptypes) / sizeof (bptypes[0])))
1393             || ((int) b->type != bptypes[(int) b->type].type))
1394           internal_error ("bptypes table does not describe type #%d.",
1395                           (int) b->type);
1396         ui_out_field_string (uiout, "type", bptypes[(int)b->type].description);
1397         annotate_field (2);
1398         ui_out_field_string (uiout, "disp", bpdisps[(int)b->disposition]);
1399         annotate_field (3);
1400         ui_out_field_fmt (uiout, "enabled", "%c", bpenables[(int)b->enable]);
1401         ...
1403    This example, also from `print_one_breakpoint', shows how to produce
1404 a complicated output field using the `print_expression' functions which
1405 requires a stream to be passed.  It also shows how to automate stream
1406 destruction with cleanups.  The original code was:
1408          annotate_field (5);
1409          print_expression (b->exp, gdb_stdout);
1411    The new version is:
1413        struct ui_stream *stb = ui_out_stream_new (uiout);
1414        struct cleanup *old_chain = make_cleanup_ui_out_stream_delete (stb);
1415        ...
1416        annotate_field (5);
1417        print_expression (b->exp, stb->stream);
1418        ui_out_field_stream (uiout, "what", local_stream);
1420    This example, also from `print_one_breakpoint', shows how to use
1421 `ui_out_text' and `ui_out_field_string'.  The original code was:
1423        annotate_field (5);
1424        if (b->dll_pathname == NULL)
1425          printf_filtered ("<any library> ");
1426        else
1427          printf_filtered ("library \"%s\" ", b->dll_pathname);
1429    It became:
1431        annotate_field (5);
1432        if (b->dll_pathname == NULL)
1433          {
1434            ui_out_field_string (uiout, "what", "<any library>");
1435            ui_out_spaces (uiout, 1);
1436          }
1437        else
1438          {
1439            ui_out_text (uiout, "library \"");
1440            ui_out_field_string (uiout, "what", b->dll_pathname);
1441            ui_out_text (uiout, "\" ");
1442          }
1444    The following example from `print_one_breakpoint' shows how to use
1445 `ui_out_field_int' and `ui_out_spaces'.  The original code was:
1447        annotate_field (5);
1448        if (b->forked_inferior_pid != 0)
1449          printf_filtered ("process %d ", b->forked_inferior_pid);
1451    It became:
1453        annotate_field (5);
1454        if (b->forked_inferior_pid != 0)
1455          {
1456            ui_out_text (uiout, "process ");
1457            ui_out_field_int (uiout, "what", b->forked_inferior_pid);
1458            ui_out_spaces (uiout, 1);
1459          }
1461    Here's an example of using `ui_out_field_string'.  The original code
1462 was:
1464        annotate_field (5);
1465        if (b->exec_pathname != NULL)
1466          printf_filtered ("program \"%s\" ", b->exec_pathname);
1468    It became:
1470        annotate_field (5);
1471        if (b->exec_pathname != NULL)
1472          {
1473            ui_out_text (uiout, "program \"");
1474            ui_out_field_string (uiout, "what", b->exec_pathname);
1475            ui_out_text (uiout, "\" ");
1476          }
1478    Finally, here's an example of printing an address.  The original
1479 code:
1481        annotate_field (4);
1482        printf_filtered ("%s ",
1483              hex_string_custom ((unsigned long) b->address, 8));
1485    It became:
1487        annotate_field (4);
1488        ui_out_field_core_addr (uiout, "Address", b->address);
1490 4.3 Console Printing
1491 ====================
1493 4.4 TUI
1494 =======
1496 ---------- Footnotes ----------
1498    (1) The function cast is not portable ISO C.
1500    (2) As of this writing (April 2001), setting verbosity level is not
1501 yet implemented, and is always returned as zero.  So calling
1502 `ui_out_message' with a VERBOSITY argument more than zero will cause
1503 the message to never be printed.
1505 \x1f
1506 File: gdbint.info,  Node: libgdb,  Next: Symbol Handling,  Prev: User Interface,  Up: Top
1508 5 libgdb
1509 ********
1511 5.1 libgdb 1.0
1512 ==============
1514 `libgdb' 1.0 was an abortive project of years ago.  The theory was to
1515 provide an API to GDB's functionality.
1517 5.2 libgdb 2.0
1518 ==============
1520 `libgdb' 2.0 is an ongoing effort to update GDB so that is better able
1521 to support graphical and other environments.
1523    Since `libgdb' development is on-going, its architecture is still
1524 evolving.  The following components have so far been identified:
1526    * Observer - `gdb-events.h'.
1528    * Builder - `ui-out.h'
1530    * Event Loop - `event-loop.h'
1532    * Library - `gdb.h'
1534    The model that ties these components together is described below.
1536 5.3 The `libgdb' Model
1537 ======================
1539 A client of `libgdb' interacts with the library in two ways.
1541    * As an observer (using `gdb-events') receiving notifications from
1542      `libgdb' of any internal state changes (break point changes, run
1543      state, etc).
1545    * As a client querying `libgdb' (using the `ui-out' builder) to
1546      obtain various status values from GDB.
1548    Since `libgdb' could have multiple clients (e.g., a GUI supporting
1549 the existing GDB CLI), those clients must co-operate when controlling
1550 `libgdb'.  In particular, a client must ensure that `libgdb' is idle
1551 (i.e. no other client is using `libgdb') before responding to a
1552 `gdb-event' by making a query.
1554 5.4 CLI support
1555 ===============
1557 At present GDB's CLI is very much entangled in with the core of
1558 `libgdb'.  Consequently, a client wishing to include the CLI in their
1559 interface needs to carefully co-ordinate its own and the CLI's
1560 requirements.
1562    It is suggested that the client set `libgdb' up to be bi-modal
1563 (alternate between CLI and client query modes).  The notes below sketch
1564 out the theory:
1566    * The client registers itself as an observer of `libgdb'.
1568    * The client create and install `cli-out' builder using its own
1569      versions of the `ui-file' `gdb_stderr', `gdb_stdtarg' and
1570      `gdb_stdout' streams.
1572    * The client creates a separate custom `ui-out' builder that is only
1573      used while making direct queries to `libgdb'.
1575    When the client receives input intended for the CLI, it simply
1576 passes it along.  Since the `cli-out' builder is installed by default,
1577 all the CLI output in response to that command is routed (pronounced
1578 rooted) through to the client controlled `gdb_stdout' et. al. streams.
1579 At the same time, the client is kept abreast of internal changes by
1580 virtue of being a `libgdb' observer.
1582    The only restriction on the client is that it must wait until
1583 `libgdb' becomes idle before initiating any queries (using the client's
1584 custom builder).
1586 5.5 `libgdb' components
1587 =======================
1589 Observer - `gdb-events.h'
1590 -------------------------
1592 `gdb-events' provides the client with a very raw mechanism that can be
1593 used to implement an observer.  At present it only allows for one
1594 observer and that observer must, internally, handle the need to delay
1595 the processing of any event notifications until after `libgdb' has
1596 finished the current command.
1598 Builder - `ui-out.h'
1599 --------------------
1601 `ui-out' provides the infrastructure necessary for a client to create a
1602 builder.  That builder is then passed down to `libgdb' when doing any
1603 queries.
1605 Event Loop - `event-loop.h'
1606 ---------------------------
1608 `event-loop', currently non-re-entrant, provides a simple event loop.
1609 A client would need to either plug its self into this loop or,
1610 implement a new event-loop that GDB would use.
1612    The event-loop will eventually be made re-entrant.  This is so that
1613 GDB can better handle the problem of some commands blocking instead of
1614 returning.
1616 Library - `gdb.h'
1617 -----------------
1619 `libgdb' is the most obvious component of this system.  It provides the
1620 query interface.  Each function is parameterized by a `ui-out' builder.
1621 The result of the query is constructed using that builder before the
1622 query function returns.
1624 \x1f
1625 File: gdbint.info,  Node: Symbol Handling,  Next: Language Support,  Prev: libgdb,  Up: Top
1627 6 Symbol Handling
1628 *****************
1630 Symbols are a key part of GDB's operation.  Symbols include variables,
1631 functions, and types.
1633 6.1 Symbol Reading
1634 ==================
1636 GDB reads symbols from "symbol files".  The usual symbol file is the
1637 file containing the program which GDB is debugging.  GDB can be
1638 directed to use a different file for symbols (with the `symbol-file'
1639 command), and it can also read more symbols via the `add-file' and
1640 `load' commands, or while reading symbols from shared libraries.
1642    Symbol files are initially opened by code in `symfile.c' using the
1643 BFD library (*note Support Libraries::).  BFD identifies the type of
1644 the file by examining its header.  `find_sym_fns' then uses this
1645 identification to locate a set of symbol-reading functions.
1647    Symbol-reading modules identify themselves to GDB by calling
1648 `add_symtab_fns' during their module initialization.  The argument to
1649 `add_symtab_fns' is a `struct sym_fns' which contains the name (or name
1650 prefix) of the symbol format, the length of the prefix, and pointers to
1651 four functions.  These functions are called at various times to process
1652 symbol files whose identification matches the specified prefix.
1654    The functions supplied by each module are:
1656 `XYZ_symfile_init(struct sym_fns *sf)'
1657      Called from `symbol_file_add' when we are about to read a new
1658      symbol file.  This function should clean up any internal state
1659      (possibly resulting from half-read previous files, for example)
1660      and prepare to read a new symbol file.  Note that the symbol file
1661      which we are reading might be a new "main" symbol file, or might
1662      be a secondary symbol file whose symbols are being added to the
1663      existing symbol table.
1665      The argument to `XYZ_symfile_init' is a newly allocated `struct
1666      sym_fns' whose `bfd' field contains the BFD for the new symbol
1667      file being read.  Its `private' field has been zeroed, and can be
1668      modified as desired.  Typically, a struct of private information
1669      will be `malloc''d, and a pointer to it will be placed in the
1670      `private' field.
1672      There is no result from `XYZ_symfile_init', but it can call
1673      `error' if it detects an unavoidable problem.
1675 `XYZ_new_init()'
1676      Called from `symbol_file_add' when discarding existing symbols.
1677      This function needs only handle the symbol-reading module's
1678      internal state; the symbol table data structures visible to the
1679      rest of GDB will be discarded by `symbol_file_add'.  It has no
1680      arguments and no result.  It may be called after
1681      `XYZ_symfile_init', if a new symbol table is being read, or may be
1682      called alone if all symbols are simply being discarded.
1684 `XYZ_symfile_read(struct sym_fns *sf, CORE_ADDR addr, int mainline)'
1685      Called from `symbol_file_add' to actually read the symbols from a
1686      symbol-file into a set of psymtabs or symtabs.
1688      `sf' points to the `struct sym_fns' originally passed to
1689      `XYZ_sym_init' for possible initialization.  `addr' is the offset
1690      between the file's specified start address and its true address in
1691      memory.  `mainline' is 1 if this is the main symbol table being
1692      read, and 0 if a secondary symbol file (e.g., shared library or
1693      dynamically loaded file) is being read.
1695    In addition, if a symbol-reading module creates psymtabs when
1696 XYZ_symfile_read is called, these psymtabs will contain a pointer to a
1697 function `XYZ_psymtab_to_symtab', which can be called from any point in
1698 the GDB symbol-handling code.
1700 `XYZ_psymtab_to_symtab (struct partial_symtab *pst)'
1701      Called from `psymtab_to_symtab' (or the `PSYMTAB_TO_SYMTAB' macro)
1702      if the psymtab has not already been read in and had its
1703      `pst->symtab' pointer set.  The argument is the psymtab to be
1704      fleshed-out into a symtab.  Upon return, `pst->readin' should have
1705      been set to 1, and `pst->symtab' should contain a pointer to the
1706      new corresponding symtab, or zero if there were no symbols in that
1707      part of the symbol file.
1709 6.2 Partial Symbol Tables
1710 =========================
1712 GDB has three types of symbol tables:
1714    * Full symbol tables ("symtabs").  These contain the main
1715      information about symbols and addresses.
1717    * Partial symbol tables ("psymtabs").  These contain enough
1718      information to know when to read the corresponding part of the full
1719      symbol table.
1721    * Minimal symbol tables ("msymtabs").  These contain information
1722      gleaned from non-debugging symbols.
1724    This section describes partial symbol tables.
1726    A psymtab is constructed by doing a very quick pass over an
1727 executable file's debugging information.  Small amounts of information
1728 are extracted--enough to identify which parts of the symbol table will
1729 need to be re-read and fully digested later, when the user needs the
1730 information.  The speed of this pass causes GDB to start up very
1731 quickly.  Later, as the detailed rereading occurs, it occurs in small
1732 pieces, at various times, and the delay therefrom is mostly invisible to
1733 the user.
1735    The symbols that show up in a file's psymtab should be, roughly,
1736 those visible to the debugger's user when the program is not running
1737 code from that file.  These include external symbols and types, static
1738 symbols and types, and `enum' values declared at file scope.
1740    The psymtab also contains the range of instruction addresses that the
1741 full symbol table would represent.
1743    The idea is that there are only two ways for the user (or much of the
1744 code in the debugger) to reference a symbol:
1746    * By its address (e.g., execution stops at some address which is
1747      inside a function in this file).  The address will be noticed to
1748      be in the range of this psymtab, and the full symtab will be read
1749      in.  `find_pc_function', `find_pc_line', and other `find_pc_...'
1750      functions handle this.
1752    * By its name (e.g., the user asks to print a variable, or set a
1753      breakpoint on a function).  Global names and file-scope names will
1754      be found in the psymtab, which will cause the symtab to be pulled
1755      in.  Local names will have to be qualified by a global name, or a
1756      file-scope name, in which case we will have already read in the
1757      symtab as we evaluated the qualifier.  Or, a local symbol can be
1758      referenced when we are "in" a local scope, in which case the first
1759      case applies.  `lookup_symbol' does most of the work here.
1761    The only reason that psymtabs exist is to cause a symtab to be read
1762 in at the right moment.  Any symbol that can be elided from a psymtab,
1763 while still causing that to happen, should not appear in it.  Since
1764 psymtabs don't have the idea of scope, you can't put local symbols in
1765 them anyway.  Psymtabs don't have the idea of the type of a symbol,
1766 either, so types need not appear, unless they will be referenced by
1767 name.
1769    It is a bug for GDB to behave one way when only a psymtab has been
1770 read, and another way if the corresponding symtab has been read in.
1771 Such bugs are typically caused by a psymtab that does not contain all
1772 the visible symbols, or which has the wrong instruction address ranges.
1774    The psymtab for a particular section of a symbol file (objfile)
1775 could be thrown away after the symtab has been read in.  The symtab
1776 should always be searched before the psymtab, so the psymtab will never
1777 be used (in a bug-free environment).  Currently, psymtabs are allocated
1778 on an obstack, and all the psymbols themselves are allocated in a pair
1779 of large arrays on an obstack, so there is little to be gained by
1780 trying to free them unless you want to do a lot more work.
1782 6.3 Types
1783 =========
1785 Fundamental Types (e.g., `FT_VOID', `FT_BOOLEAN').
1786 --------------------------------------------------
1788 These are the fundamental types that GDB uses internally.  Fundamental
1789 types from the various debugging formats (stabs, ELF, etc) are mapped
1790 into one of these.  They are basically a union of all fundamental types
1791 that GDB knows about for all the languages that GDB knows about.
1793 Type Codes (e.g., `TYPE_CODE_PTR', `TYPE_CODE_ARRAY').
1794 ------------------------------------------------------
1796 Each time GDB builds an internal type, it marks it with one of these
1797 types.  The type may be a fundamental type, such as `TYPE_CODE_INT', or
1798 a derived type, such as `TYPE_CODE_PTR' which is a pointer to another
1799 type.  Typically, several `FT_*' types map to one `TYPE_CODE_*' type,
1800 and are distinguished by other members of the type struct, such as
1801 whether the type is signed or unsigned, and how many bits it uses.
1803 Builtin Types (e.g., `builtin_type_void', `builtin_type_char').
1804 ---------------------------------------------------------------
1806 These are instances of type structs that roughly correspond to
1807 fundamental types and are created as global types for GDB to use for
1808 various ugly historical reasons.  We eventually want to eliminate
1809 these.  Note for example that `builtin_type_int' initialized in
1810 `gdbtypes.c' is basically the same as a `TYPE_CODE_INT' type that is
1811 initialized in `c-lang.c' for an `FT_INTEGER' fundamental type.  The
1812 difference is that the `builtin_type' is not associated with any
1813 particular objfile, and only one instance exists, while `c-lang.c'
1814 builds as many `TYPE_CODE_INT' types as needed, with each one
1815 associated with some particular objfile.
1817 6.4 Object File Formats
1818 =======================
1820 6.4.1 a.out
1821 -----------
1823 The `a.out' format is the original file format for Unix.  It consists
1824 of three sections: `text', `data', and `bss', which are for program
1825 code, initialized data, and uninitialized data, respectively.
1827    The `a.out' format is so simple that it doesn't have any reserved
1828 place for debugging information.  (Hey, the original Unix hackers used
1829 `adb', which is a machine-language debugger!)  The only debugging
1830 format for `a.out' is stabs, which is encoded as a set of normal
1831 symbols with distinctive attributes.
1833    The basic `a.out' reader is in `dbxread.c'.
1835 6.4.2 COFF
1836 ----------
1838 The COFF format was introduced with System V Release 3 (SVR3) Unix.
1839 COFF files may have multiple sections, each prefixed by a header.  The
1840 number of sections is limited.
1842    The COFF specification includes support for debugging.  Although this
1843 was a step forward, the debugging information was woefully limited.  For
1844 instance, it was not possible to represent code that came from an
1845 included file.
1847    The COFF reader is in `coffread.c'.
1849 6.4.3 ECOFF
1850 -----------
1852 ECOFF is an extended COFF originally introduced for Mips and Alpha
1853 workstations.
1855    The basic ECOFF reader is in `mipsread.c'.
1857 6.4.4 XCOFF
1858 -----------
1860 The IBM RS/6000 running AIX uses an object file format called XCOFF.
1861 The COFF sections, symbols, and line numbers are used, but debugging
1862 symbols are `dbx'-style stabs whose strings are located in the `.debug'
1863 section (rather than the string table).  For more information, see
1864 *Note Top: (stabs)Top.
1866    The shared library scheme has a clean interface for figuring out what
1867 shared libraries are in use, but the catch is that everything which
1868 refers to addresses (symbol tables and breakpoints at least) needs to be
1869 relocated for both shared libraries and the main executable.  At least
1870 using the standard mechanism this can only be done once the program has
1871 been run (or the core file has been read).
1873 6.4.5 PE
1874 --------
1876 Windows 95 and NT use the PE ("Portable Executable") format for their
1877 executables.  PE is basically COFF with additional headers.
1879    While BFD includes special PE support, GDB needs only the basic COFF
1880 reader.
1882 6.4.6 ELF
1883 ---------
1885 The ELF format came with System V Release 4 (SVR4) Unix.  ELF is similar
1886 to COFF in being organized into a number of sections, but it removes
1887 many of COFF's limitations.
1889    The basic ELF reader is in `elfread.c'.
1891 6.4.7 SOM
1892 ---------
1894 SOM is HP's object file and debug format (not to be confused with IBM's
1895 SOM, which is a cross-language ABI).
1897    The SOM reader is in `somread.c'.
1899 6.5 Debugging File Formats
1900 ==========================
1902 This section describes characteristics of debugging information that
1903 are independent of the object file format.
1905 6.5.1 stabs
1906 -----------
1908 `stabs' started out as special symbols within the `a.out' format.
1909 Since then, it has been encapsulated into other file formats, such as
1910 COFF and ELF.
1912    While `dbxread.c' does some of the basic stab processing, including
1913 for encapsulated versions, `stabsread.c' does the real work.
1915 6.5.2 COFF
1916 ----------
1918 The basic COFF definition includes debugging information.  The level of
1919 support is minimal and non-extensible, and is not often used.
1921 6.5.3 Mips debug (Third Eye)
1922 ----------------------------
1924 ECOFF includes a definition of a special debug format.
1926    The file `mdebugread.c' implements reading for this format.
1928 6.5.4 DWARF 2
1929 -------------
1931 DWARF 2 is an improved but incompatible version of DWARF 1.
1933    The DWARF 2 reader is in `dwarf2read.c'.
1935 6.5.5 SOM
1936 ---------
1938 Like COFF, the SOM definition includes debugging information.
1940 6.6 Adding a New Symbol Reader to GDB
1941 =====================================
1943 If you are using an existing object file format (`a.out', COFF, ELF,
1944 etc), there is probably little to be done.
1946    If you need to add a new object file format, you must first add it to
1947 BFD.  This is beyond the scope of this document.
1949    You must then arrange for the BFD code to provide access to the
1950 debugging symbols.  Generally GDB will have to call swapping routines
1951 from BFD and a few other BFD internal routines to locate the debugging
1952 information.  As much as possible, GDB should not depend on the BFD
1953 internal data structures.
1955    For some targets (e.g., COFF), there is a special transfer vector
1956 used to call swapping routines, since the external data structures on
1957 various platforms have different sizes and layouts.  Specialized
1958 routines that will only ever be implemented by one object file format
1959 may be called directly.  This interface should be described in a file
1960 `bfd/libXYZ.h', which is included by GDB.
1962 6.7 Memory Management for Symbol Files
1963 ======================================
1965 Most memory associated with a loaded symbol file is stored on its
1966 `objfile_obstack'.  This includes symbols, types, namespace data, and
1967 other information produced by the symbol readers.
1969    Because this data lives on the objfile's obstack, it is automatically
1970 released when the objfile is unloaded or reloaded.  Therefore one
1971 objfile must not reference symbol or type data from another objfile;
1972 they could be unloaded at different times.
1974    User convenience variables, et cetera, have associated types.
1975 Normally these types live in the associated objfile.  However, when the
1976 objfile is unloaded, those types are deep copied to global memory, so
1977 that the values of the user variables and history items are not lost.
1979 \x1f
1980 File: gdbint.info,  Node: Language Support,  Next: Host Definition,  Prev: Symbol Handling,  Up: Top
1982 7 Language Support
1983 ******************
1985 GDB's language support is mainly driven by the symbol reader, although
1986 it is possible for the user to set the source language manually.
1988    GDB chooses the source language by looking at the extension of the
1989 file recorded in the debug info; `.c' means C, `.f' means Fortran, etc.
1990 It may also use a special-purpose language identifier if the debug
1991 format supports it, like with DWARF.
1993 7.1 Adding a Source Language to GDB
1994 ===================================
1996 To add other languages to GDB's expression parser, follow the following
1997 steps:
1999 _Create the expression parser._
2000      This should reside in a file `LANG-exp.y'.  Routines for building
2001      parsed expressions into a `union exp_element' list are in
2002      `parse.c'.
2004      Since we can't depend upon everyone having Bison, and YACC produces
2005      parsers that define a bunch of global names, the following lines
2006      *must* be included at the top of the YACC parser, to prevent the
2007      various parsers from defining the same global names:
2009           #define yyparse         LANG_parse
2010           #define yylex           LANG_lex
2011           #define yyerror         LANG_error
2012           #define yylval          LANG_lval
2013           #define yychar          LANG_char
2014           #define yydebug         LANG_debug
2015           #define yypact          LANG_pact
2016           #define yyr1            LANG_r1
2017           #define yyr2            LANG_r2
2018           #define yydef           LANG_def
2019           #define yychk           LANG_chk
2020           #define yypgo           LANG_pgo
2021           #define yyact           LANG_act
2022           #define yyexca          LANG_exca
2023           #define yyerrflag       LANG_errflag
2024           #define yynerrs         LANG_nerrs
2026      At the bottom of your parser, define a `struct language_defn' and
2027      initialize it with the right values for your language.  Define an
2028      `initialize_LANG' routine and have it call
2029      `add_language(LANG_language_defn)' to tell the rest of GDB that
2030      your language exists.  You'll need some other supporting variables
2031      and functions, which will be used via pointers from your
2032      `LANG_language_defn'.  See the declaration of `struct
2033      language_defn' in `language.h', and the other `*-exp.y' files, for
2034      more information.
2036 _Add any evaluation routines, if necessary_
2037      If you need new opcodes (that represent the operations of the
2038      language), add them to the enumerated type in `expression.h'.  Add
2039      support code for these operations in the `evaluate_subexp' function
2040      defined in the file `eval.c'.  Add cases for new opcodes in two
2041      functions from `parse.c': `prefixify_subexp' and
2042      `length_of_subexp'.  These compute the number of `exp_element's
2043      that a given operation takes up.
2045 _Update some existing code_
2046      Add an enumerated identifier for your language to the enumerated
2047      type `enum language' in `defs.h'.
2049      Update the routines in `language.c' so your language is included.
2050      These routines include type predicates and such, which (in some
2051      cases) are language dependent.  If your language does not appear
2052      in the switch statement, an error is reported.
2054      Also included in `language.c' is the code that updates the variable
2055      `current_language', and the routines that translate the
2056      `language_LANG' enumerated identifier into a printable string.
2058      Update the function `_initialize_language' to include your
2059      language.  This function picks the default language upon startup,
2060      so is dependent upon which languages that GDB is built for.
2062      Update `allocate_symtab' in `symfile.c' and/or symbol-reading code
2063      so that the language of each symtab (source file) is set properly.
2064      This is used to determine the language to use at each stack frame
2065      level.  Currently, the language is set based upon the extension of
2066      the source file.  If the language can be better inferred from the
2067      symbol information, please set the language of the symtab in the
2068      symbol-reading code.
2070      Add helper code to `print_subexp' (in `expprint.c') to handle any
2071      new expression opcodes you have added to `expression.h'.  Also,
2072      add the printed representations of your operators to
2073      `op_print_tab'.
2075 _Add a place of call_
2076      Add a call to `LANG_parse()' and `LANG_error' in `parse_exp_1'
2077      (defined in `parse.c').
2079 _Use macros to trim code_
2080      The user has the option of building GDB for some or all of the
2081      languages.  If the user decides to build GDB for the language
2082      LANG, then every file dependent on `language.h' will have the
2083      macro `_LANG_LANG' defined in it.  Use `#ifdef's to leave out
2084      large routines that the user won't need if he or she is not using
2085      your language.
2087      Note that you do not need to do this in your YACC parser, since if
2088      GDB is not build for LANG, then `LANG-exp.tab.o' (the compiled
2089      form of your parser) is not linked into GDB at all.
2091      See the file `configure.in' for how GDB is configured for
2092      different languages.
2094 _Edit `Makefile.in'_
2095      Add dependencies in `Makefile.in'.  Make sure you update the macro
2096      variables such as `HFILES' and `OBJS', otherwise your code may not
2097      get linked in, or, worse yet, it may not get `tar'red into the
2098      distribution!
2100 \x1f
2101 File: gdbint.info,  Node: Host Definition,  Next: Target Architecture Definition,  Prev: Language Support,  Up: Top
2103 8 Host Definition
2104 *****************
2106 With the advent of Autoconf, it's rarely necessary to have host
2107 definition machinery anymore.  The following information is provided,
2108 mainly, as an historical reference.
2110 8.1 Adding a New Host
2111 =====================
2113 GDB's host configuration support normally happens via Autoconf.  New
2114 host-specific definitions should not be needed.  Older hosts GDB still
2115 use the host-specific definitions and files listed below, but these
2116 mostly exist for historical reasons, and will eventually disappear.
2118 `gdb/config/ARCH/XYZ.mh'
2119      This file once contained both host and native configuration
2120      information (*note Native Debugging::) for the machine XYZ.  The
2121      host configuration information is now handed by Autoconf.
2123      Host configuration information included a definition of
2124      `XM_FILE=xm-XYZ.h' and possibly definitions for `CC',
2125      `SYSV_DEFINE', `XM_CFLAGS', `XM_ADD_FILES', `XM_CLIBS',
2126      `XM_CDEPS', etc.; see `Makefile.in'.
2128      New host only configurations do not need this file.
2130 `gdb/config/ARCH/xm-XYZ.h'
2131      This file once contained definitions and includes required when
2132      hosting gdb on machine XYZ.  Those definitions and includes are now
2133      handled by Autoconf.
2135      New host and native configurations do not need this file.
2137      _Maintainer's note: Some hosts continue to use the `xm-xyz.h' file
2138      to define the macros HOST_FLOAT_FORMAT, HOST_DOUBLE_FORMAT and
2139      HOST_LONG_DOUBLE_FORMAT.  That code also needs to be replaced with
2140      either an Autoconf or run-time test._
2143 Generic Host Support Files
2144 --------------------------
2146 There are some "generic" versions of routines that can be used by
2147 various systems.  These can be customized in various ways by macros
2148 defined in your `xm-XYZ.h' file.  If these routines work for the XYZ
2149 host, you can just include the generic file's name (with `.o', not
2150 `.c') in `XDEPFILES'.
2152    Otherwise, if your machine needs custom support routines, you will
2153 need to write routines that perform the same functions as the generic
2154 file.  Put them into `XYZ-xdep.c', and put `XYZ-xdep.o' into
2155 `XDEPFILES'.
2157 `ser-unix.c'
2158      This contains serial line support for Unix systems.  This is always
2159      included, via the makefile variable `SER_HARDWIRE'; override this
2160      variable in the `.mh' file to avoid it.
2162 `ser-go32.c'
2163      This contains serial line support for 32-bit programs running
2164      under DOS, using the DJGPP (a.k.a. GO32) execution environment.
2166 `ser-tcp.c'
2167      This contains generic TCP support using sockets.
2169 8.2 Host Conditionals
2170 =====================
2172 When GDB is configured and compiled, various macros are defined or left
2173 undefined, to control compilation based on the attributes of the host
2174 system.  These macros and their meanings (or if the meaning is not
2175 documented here, then one of the source files where they are used is
2176 indicated) are:
2178 `GDBINIT_FILENAME'
2179      The default name of GDB's initialization file (normally
2180      `.gdbinit').
2182 `NO_STD_REGS'
2183      This macro is deprecated.
2185 `SIGWINCH_HANDLER'
2186      If your host defines `SIGWINCH', you can define this to be the name
2187      of a function to be called if `SIGWINCH' is received.
2189 `SIGWINCH_HANDLER_BODY'
2190      Define this to expand into code that will define the function
2191      named by the expansion of `SIGWINCH_HANDLER'.
2193 `CRLF_SOURCE_FILES'
2194      Define this if host files use `\r\n' rather than `\n' as a line
2195      terminator.  This will cause source file listings to omit `\r'
2196      characters when printing and it will allow `\r\n' line endings of
2197      files which are "sourced" by gdb.  It must be possible to open
2198      files in binary mode using `O_BINARY' or, for fopen, `"rb"'.
2200 `DEFAULT_PROMPT'
2201      The default value of the prompt string (normally `"(gdb) "').
2203 `DEV_TTY'
2204      The name of the generic TTY device, defaults to `"/dev/tty"'.
2206 `FOPEN_RB'
2207      Define this if binary files are opened the same way as text files.
2209 `HAVE_MMAP'
2210      In some cases, use the system call `mmap' for reading symbol
2211      tables.  For some machines this allows for sharing and quick
2212      updates.
2214 `HAVE_TERMIO'
2215      Define this if the host system has `termio.h'.
2217 `INT_MAX'
2218 `INT_MIN'
2219 `LONG_MAX'
2220 `UINT_MAX'
2221 `ULONG_MAX'
2222      Values for host-side constants.
2224 `ISATTY'
2225      Substitute for isatty, if not available.
2227 `LONGEST'
2228      This is the longest integer type available on the host.  If not
2229      defined, it will default to `long long' or `long', depending on
2230      `CC_HAS_LONG_LONG'.
2232 `CC_HAS_LONG_LONG'
2233      Define this if the host C compiler supports `long long'.  This is
2234      set by the `configure' script.
2236 `PRINTF_HAS_LONG_LONG'
2237      Define this if the host can handle printing of long long integers
2238      via the printf format conversion specifier `ll'.  This is set by
2239      the `configure' script.
2241 `HAVE_LONG_DOUBLE'
2242      Define this if the host C compiler supports `long double'.  This is
2243      set by the `configure' script.
2245 `PRINTF_HAS_LONG_DOUBLE'
2246      Define this if the host can handle printing of long double
2247      float-point numbers via the printf format conversion specifier
2248      `Lg'.  This is set by the `configure' script.
2250 `SCANF_HAS_LONG_DOUBLE'
2251      Define this if the host can handle the parsing of long double
2252      float-point numbers via the scanf format conversion specifier
2253      `Lg'.  This is set by the `configure' script.
2255 `LSEEK_NOT_LINEAR'
2256      Define this if `lseek (n)' does not necessarily move to byte number
2257      `n' in the file.  This is only used when reading source files.  It
2258      is normally faster to define `CRLF_SOURCE_FILES' when possible.
2260 `L_SET'
2261      This macro is used as the argument to `lseek' (or, most commonly,
2262      `bfd_seek').  FIXME, should be replaced by SEEK_SET instead, which
2263      is the POSIX equivalent.
2265 `NORETURN'
2266      If defined, this should be one or more tokens, such as `volatile',
2267      that can be used in both the declaration and definition of
2268      functions to indicate that they never return.  The default is
2269      already set correctly if compiling with GCC.  This will almost
2270      never need to be defined.
2272 `ATTR_NORETURN'
2273      If defined, this should be one or more tokens, such as
2274      `__attribute__ ((noreturn))', that can be used in the declarations
2275      of functions to indicate that they never return.  The default is
2276      already set correctly if compiling with GCC.  This will almost
2277      never need to be defined.
2279 `SEEK_CUR'
2280 `SEEK_SET'
2281      Define these to appropriate value for the system `lseek', if not
2282      already defined.
2284 `STOP_SIGNAL'
2285      This is the signal for stopping GDB.  Defaults to `SIGTSTP'.
2286      (Only redefined for the Convex.)
2288 `USG'
2289      Means that System V (prior to SVR4) include files are in use.
2290      (FIXME: This symbol is abused in `infrun.c', `regex.c', and
2291      `utils.c' for other things, at the moment.)
2293 `lint'
2294      Define this to help placate `lint' in some situations.
2296 `volatile'
2297      Define this to override the defaults of `__volatile__' or `/**/'.
2299 \x1f
2300 File: gdbint.info,  Node: Target Architecture Definition,  Next: Target Descriptions,  Prev: Host Definition,  Up: Top
2302 9 Target Architecture Definition
2303 ********************************
2305 GDB's target architecture defines what sort of machine-language
2306 programs GDB can work with, and how it works with them.
2308    The target architecture object is implemented as the C structure
2309 `struct gdbarch *'.  The structure, and its methods, are generated
2310 using the Bourne shell script `gdbarch.sh'.
2312 * Menu:
2314 * OS ABI Variant Handling::
2315 * Initialize New Architecture::
2316 * Registers and Memory::
2317 * Pointers and Addresses::
2318 * Address Classes::
2319 * Raw and Virtual Registers::
2320 * Register and Memory Data::
2321 * Frame Interpretation::
2322 * Inferior Call Setup::
2323 * Compiler Characteristics::
2324 * Target Conditionals::
2325 * Adding a New Target::
2327 \x1f
2328 File: gdbint.info,  Node: OS ABI Variant Handling,  Next: Initialize New Architecture,  Up: Target Architecture Definition
2330 9.1 Operating System ABI Variant Handling
2331 =========================================
2333 GDB provides a mechanism for handling variations in OS ABIs.  An OS ABI
2334 variant may have influence over any number of variables in the target
2335 architecture definition.  There are two major components in the OS ABI
2336 mechanism: sniffers and handlers.
2338    A "sniffer" examines a file matching a BFD architecture/flavour pair
2339 (the architecture may be wildcarded) in an attempt to determine the OS
2340 ABI of that file.  Sniffers with a wildcarded architecture are
2341 considered to be "generic", while sniffers for a specific architecture
2342 are considered to be "specific".  A match from a specific sniffer
2343 overrides a match from a generic sniffer.  Multiple sniffers for an
2344 architecture/flavour may exist, in order to differentiate between two
2345 different operating systems which use the same basic file format.  The
2346 OS ABI framework provides a generic sniffer for ELF-format files which
2347 examines the `EI_OSABI' field of the ELF header, as well as note
2348 sections known to be used by several operating systems.
2350    A "handler" is used to fine-tune the `gdbarch' structure for the
2351 selected OS ABI.  There may be only one handler for a given OS ABI for
2352 each BFD architecture.
2354    The following OS ABI variants are defined in `defs.h':
2356 `GDB_OSABI_UNINITIALIZED'
2357      Used for struct gdbarch_info if ABI is still uninitialized.
2359 `GDB_OSABI_UNKNOWN'
2360      The ABI of the inferior is unknown.  The default `gdbarch'
2361      settings for the architecture will be used.
2363 `GDB_OSABI_SVR4'
2364      UNIX System V Release 4.
2366 `GDB_OSABI_HURD'
2367      GNU using the Hurd kernel.
2369 `GDB_OSABI_SOLARIS'
2370      Sun Solaris.
2372 `GDB_OSABI_OSF1'
2373      OSF/1, including Digital UNIX and Compaq Tru64 UNIX.
2375 `GDB_OSABI_LINUX'
2376      GNU using the Linux kernel.
2378 `GDB_OSABI_FREEBSD_AOUT'
2379      FreeBSD using the `a.out' executable format.
2381 `GDB_OSABI_FREEBSD_ELF'
2382      FreeBSD using the ELF executable format.
2384 `GDB_OSABI_NETBSD_AOUT'
2385      NetBSD using the `a.out' executable format.
2387 `GDB_OSABI_NETBSD_ELF'
2388      NetBSD using the ELF executable format.
2390 `GDB_OSABI_OPENBSD_ELF'
2391      OpenBSD using the ELF executable format.
2393 `GDB_OSABI_WINCE'
2394      Windows CE.
2396 `GDB_OSABI_GO32'
2397      DJGPP.
2399 `GDB_OSABI_IRIX'
2400      Irix.
2402 `GDB_OSABI_INTERIX'
2403      Interix (Posix layer for MS-Windows systems).
2405 `GDB_OSABI_HPUX_ELF'
2406      HP/UX using the ELF executable format.
2408 `GDB_OSABI_HPUX_SOM'
2409      HP/UX using the SOM executable format.
2411 `GDB_OSABI_QNXNTO'
2412      QNX Neutrino.
2414 `GDB_OSABI_CYGWIN'
2415      Cygwin.
2417 `GDB_OSABI_AIX'
2418      AIX.
2421    Here are the functions that make up the OS ABI framework:
2423  -- Function: const char *gdbarch_osabi_name (enum gdb_osabi OSABI)
2424      Return the name of the OS ABI corresponding to OSABI.
2426  -- Function: void gdbarch_register_osabi (enum bfd_architecture ARCH,
2427           unsigned long MACHINE, enum gdb_osabi OSABI, void
2428           (*INIT_OSABI)(struct gdbarch_info INFO, struct gdbarch
2429           *GDBARCH))
2430      Register the OS ABI handler specified by INIT_OSABI for the
2431      architecture, machine type and OS ABI specified by ARCH, MACHINE
2432      and OSABI.  In most cases, a value of zero for the machine type,
2433      which implies the architecture's default machine type, will
2434      suffice.
2436  -- Function: void gdbarch_register_osabi_sniffer (enum
2437           bfd_architecture ARCH, enum bfd_flavour FLAVOUR, enum
2438           gdb_osabi (*SNIFFER)(bfd *ABFD))
2439      Register the OS ABI file sniffer specified by SNIFFER for the BFD
2440      architecture/flavour pair specified by ARCH and FLAVOUR.  If ARCH
2441      is `bfd_arch_unknown', the sniffer is considered to be generic,
2442      and is allowed to examine FLAVOUR-flavoured files for any
2443      architecture.
2445  -- Function: enum gdb_osabi gdbarch_lookup_osabi (bfd *ABFD)
2446      Examine the file described by ABFD to determine its OS ABI.  The
2447      value `GDB_OSABI_UNKNOWN' is returned if the OS ABI cannot be
2448      determined.
2450  -- Function: void gdbarch_init_osabi (struct gdbarch info INFO, struct
2451           gdbarch *GDBARCH, enum gdb_osabi OSABI)
2452      Invoke the OS ABI handler corresponding to OSABI to fine-tune the
2453      `gdbarch' structure specified by GDBARCH.  If a handler
2454      corresponding to OSABI has not been registered for GDBARCH's
2455      architecture, a warning will be issued and the debugging session
2456      will continue with the defaults already established for GDBARCH.
2458  -- Function: void generic_elf_osabi_sniff_abi_tag_sections (bfd *ABFD,
2459           asection *SECT, void *OBJ)
2460      Helper routine for ELF file sniffers.  Examine the file described
2461      by ABFD and look at ABI tag note sections to determine the OS ABI
2462      from the note.  This function should be called via
2463      `bfd_map_over_sections'.
2465 \x1f
2466 File: gdbint.info,  Node: Initialize New Architecture,  Next: Registers and Memory,  Prev: OS ABI Variant Handling,  Up: Target Architecture Definition
2468 9.2 Initializing a New Architecture
2469 ===================================
2471 Each `gdbarch' is associated with a single BFD architecture, via a
2472 `bfd_arch_ARCH' constant.  The `gdbarch' is registered by a call to
2473 `register_gdbarch_init', usually from the file's `_initialize_FILENAME'
2474 routine, which will be automatically called during GDB startup.  The
2475 arguments are a BFD architecture constant and an initialization
2476 function.
2478    The initialization function has this type:
2480      static struct gdbarch *
2481      ARCH_gdbarch_init (struct gdbarch_info INFO,
2482                               struct gdbarch_list *ARCHES)
2484    The INFO argument contains parameters used to select the correct
2485 architecture, and ARCHES is a list of architectures which have already
2486 been created with the same `bfd_arch_ARCH' value.
2488    The initialization function should first make sure that INFO is
2489 acceptable, and return `NULL' if it is not.  Then, it should search
2490 through ARCHES for an exact match to INFO, and return one if found.
2491 Lastly, if no exact match was found, it should create a new
2492 architecture based on INFO and return it.
2494    Only information in INFO should be used to choose the new
2495 architecture.  Historically, INFO could be sparse, and defaults would
2496 be collected from the first element on ARCHES.  However, GDB now fills
2497 in INFO more thoroughly, so new `gdbarch' initialization functions
2498 should not take defaults from ARCHES.
2500 \x1f
2501 File: gdbint.info,  Node: Registers and Memory,  Next: Pointers and Addresses,  Prev: Initialize New Architecture,  Up: Target Architecture Definition
2503 9.3 Registers and Memory
2504 ========================
2506 GDB's model of the target machine is rather simple.  GDB assumes the
2507 machine includes a bank of registers and a block of memory.  Each
2508 register may have a different size.
2510    GDB does not have a magical way to match up with the compiler's idea
2511 of which registers are which; however, it is critical that they do
2512 match up accurately.  The only way to make this work is to get accurate
2513 information about the order that the compiler uses, and to reflect that
2514 in the `gdbarch_register_name' and related functions.
2516    GDB can handle big-endian, little-endian, and bi-endian
2517 architectures.
2519 \x1f
2520 File: gdbint.info,  Node: Pointers and Addresses,  Next: Address Classes,  Prev: Registers and Memory,  Up: Target Architecture Definition
2522 9.4 Pointers Are Not Always Addresses
2523 =====================================
2525 On almost all 32-bit architectures, the representation of a pointer is
2526 indistinguishable from the representation of some fixed-length number
2527 whose value is the byte address of the object pointed to.  On such
2528 machines, the words "pointer" and "address" can be used interchangeably.
2529 However, architectures with smaller word sizes are often cramped for
2530 address space, so they may choose a pointer representation that breaks
2531 this identity, and allows a larger code address space.
2533    For example, the Renesas D10V is a 16-bit VLIW processor whose
2534 instructions are 32 bits long(1).  If the D10V used ordinary byte
2535 addresses to refer to code locations, then the processor would only be
2536 able to address 64kb of instructions.  However, since instructions must
2537 be aligned on four-byte boundaries, the low two bits of any valid
2538 instruction's byte address are always zero--byte addresses waste two
2539 bits.  So instead of byte addresses, the D10V uses word addresses--byte
2540 addresses shifted right two bits--to refer to code.  Thus, the D10V can
2541 use 16-bit words to address 256kb of code space.
2543    However, this means that code pointers and data pointers have
2544 different forms on the D10V.  The 16-bit word `0xC020' refers to byte
2545 address `0xC020' when used as a data address, but refers to byte address
2546 `0x30080' when used as a code address.
2548    (The D10V also uses separate code and data address spaces, which also
2549 affects the correspondence between pointers and addresses, but we're
2550 going to ignore that here; this example is already too long.)
2552    To cope with architectures like this--the D10V is not the only
2553 one!--GDB tries to distinguish between "addresses", which are byte
2554 numbers, and "pointers", which are the target's representation of an
2555 address of a particular type of data.  In the example above, `0xC020'
2556 is the pointer, which refers to one of the addresses `0xC020' or
2557 `0x30080', depending on the type imposed upon it.  GDB provides
2558 functions for turning a pointer into an address and vice versa, in the
2559 appropriate way for the current architecture.
2561    Unfortunately, since addresses and pointers are identical on almost
2562 all processors, this distinction tends to bit-rot pretty quickly.  Thus,
2563 each time you port GDB to an architecture which does distinguish
2564 between pointers and addresses, you'll probably need to clean up some
2565 architecture-independent code.
2567    Here are functions which convert between pointers and addresses:
2569  -- Function: CORE_ADDR extract_typed_address (void *BUF, struct type
2570           *TYPE)
2571      Treat the bytes at BUF as a pointer or reference of type TYPE, and
2572      return the address it represents, in a manner appropriate for the
2573      current architecture.  This yields an address GDB can use to read
2574      target memory, disassemble, etc.  Note that BUF refers to a buffer
2575      in GDB's memory, not the inferior's.
2577      For example, if the current architecture is the Intel x86, this
2578      function extracts a little-endian integer of the appropriate
2579      length from BUF and returns it.  However, if the current
2580      architecture is the D10V, this function will return a 16-bit
2581      integer extracted from BUF, multiplied by four if TYPE is a
2582      pointer to a function.
2584      If TYPE is not a pointer or reference type, then this function
2585      will signal an internal error.
2587  -- Function: CORE_ADDR store_typed_address (void *BUF, struct type
2588           *TYPE, CORE_ADDR ADDR)
2589      Store the address ADDR in BUF, in the proper format for a pointer
2590      of type TYPE in the current architecture.  Note that BUF refers to
2591      a buffer in GDB's memory, not the inferior's.
2593      For example, if the current architecture is the Intel x86, this
2594      function stores ADDR unmodified as a little-endian integer of the
2595      appropriate length in BUF.  However, if the current architecture
2596      is the D10V, this function divides ADDR by four if TYPE is a
2597      pointer to a function, and then stores it in BUF.
2599      If TYPE is not a pointer or reference type, then this function
2600      will signal an internal error.
2602  -- Function: CORE_ADDR value_as_address (struct value *VAL)
2603      Assuming that VAL is a pointer, return the address it represents,
2604      as appropriate for the current architecture.
2606      This function actually works on integral values, as well as
2607      pointers.  For pointers, it performs architecture-specific
2608      conversions as described above for `extract_typed_address'.
2610  -- Function: CORE_ADDR value_from_pointer (struct type *TYPE,
2611           CORE_ADDR ADDR)
2612      Create and return a value representing a pointer of type TYPE to
2613      the address ADDR, as appropriate for the current architecture.
2614      This function performs architecture-specific conversions as
2615      described above for `store_typed_address'.
2617    Here are two functions which architectures can define to indicate the
2618 relationship between pointers and addresses.  These have default
2619 definitions, appropriate for architectures on which all pointers are
2620 simple unsigned byte addresses.
2622  -- Function: CORE_ADDR gdbarch_pointer_to_address (struct gdbarch
2623           *CURRENT_GDBARCH, struct type *TYPE, char *BUF)
2624      Assume that BUF holds a pointer of type TYPE, in the appropriate
2625      format for the current architecture.  Return the byte address the
2626      pointer refers to.
2628      This function may safely assume that TYPE is either a pointer or a
2629      C++ reference type.
2631  -- Function: void gdbarch_address_to_pointer (struct gdbarch
2632           *CURRENT_GDBARCH, struct type *TYPE, char *BUF, CORE_ADDR
2633           ADDR)
2634      Store in BUF a pointer of type TYPE representing the address ADDR,
2635      in the appropriate format for the current architecture.
2637      This function may safely assume that TYPE is either a pointer or a
2638      C++ reference type.
2640    ---------- Footnotes ----------
2642    (1) Some D10V instructions are actually pairs of 16-bit
2643 sub-instructions.  However, since you can't jump into the middle of
2644 such a pair, code addresses can only refer to full 32 bit instructions,
2645 which is what matters in this explanation.
2647 \x1f
2648 File: gdbint.info,  Node: Address Classes,  Next: Raw and Virtual Registers,  Prev: Pointers and Addresses,  Up: Target Architecture Definition
2650 9.5 Address Classes
2651 ===================
2653 Sometimes information about different kinds of addresses is available
2654 via the debug information.  For example, some programming environments
2655 define addresses of several different sizes.  If the debug information
2656 distinguishes these kinds of address classes through either the size
2657 info (e.g, `DW_AT_byte_size' in DWARF 2) or through an explicit address
2658 class attribute (e.g, `DW_AT_address_class' in DWARF 2), the following
2659 macros should be defined in order to disambiguate these types within
2660 GDB as well as provide the added information to a GDB user when
2661 printing type expressions.
2663  -- Function: int gdbarch_address_class_type_flags (struct gdbarch
2664           *CURRENT_GDBARCH, int BYTE_SIZE, int DWARF2_ADDR_CLASS)
2665      Returns the type flags needed to construct a pointer type whose
2666      size is BYTE_SIZE and whose address class is DWARF2_ADDR_CLASS.
2667      This function is normally called from within a symbol reader.  See
2668      `dwarf2read.c'.
2670  -- Function: char *gdbarch_address_class_type_flags_to_name (struct
2671           gdbarch *CURRENT_GDBARCH, int TYPE_FLAGS)
2672      Given the type flags representing an address class qualifier,
2673      return its name.
2675  -- Function: int gdbarch_address_class_name_to_type_flags (struct
2676           gdbarch *CURRENT_GDBARCH, int NAME, int *vartype_flags_ptr)
2677      Given an address qualifier name, set the `int' referenced by
2678      TYPE_FLAGS_PTR to the type flags for that address class qualifier.
2680    Since the need for address classes is rather rare, none of the
2681 address class functions are defined by default.  Predicate functions
2682 are provided to detect when they are defined.
2684    Consider a hypothetical architecture in which addresses are normally
2685 32-bits wide, but 16-bit addresses are also supported.  Furthermore,
2686 suppose that the DWARF 2 information for this architecture simply uses
2687 a `DW_AT_byte_size' value of 2 to indicate the use of one of these
2688 "short" pointers.  The following functions could be defined to
2689 implement the address class functions:
2691      somearch_address_class_type_flags (int byte_size,
2692                                         int dwarf2_addr_class)
2693      {
2694        if (byte_size == 2)
2695          return TYPE_FLAG_ADDRESS_CLASS_1;
2696        else
2697          return 0;
2698      }
2700      static char *
2701      somearch_address_class_type_flags_to_name (int type_flags)
2702      {
2703        if (type_flags & TYPE_FLAG_ADDRESS_CLASS_1)
2704          return "short";
2705        else
2706          return NULL;
2707      }
2709      int
2710      somearch_address_class_name_to_type_flags (char *name,
2711                                                 int *type_flags_ptr)
2712      {
2713        if (strcmp (name, "short") == 0)
2714          {
2715            *type_flags_ptr = TYPE_FLAG_ADDRESS_CLASS_1;
2716            return 1;
2717          }
2718        else
2719          return 0;
2720      }
2722    The qualifier `@short' is used in GDB's type expressions to indicate
2723 the presence of one of these "short" pointers.  E.g, if the debug
2724 information indicates that `short_ptr_var' is one of these short
2725 pointers, GDB might show the following behavior:
2727      (gdb) ptype short_ptr_var
2728      type = int * @short
2730 \x1f
2731 File: gdbint.info,  Node: Raw and Virtual Registers,  Next: Register and Memory Data,  Prev: Address Classes,  Up: Target Architecture Definition
2733 9.6 Raw and Virtual Register Representations
2734 ============================================
2736 _Maintainer note: This section is pretty much obsolete.  The
2737 functionality described here has largely been replaced by
2738 pseudo-registers and the mechanisms described in *Note Using Different
2739 Register and Memory Data Representations: Target Architecture
2740 Definition.  See also Bug Tracking Database
2741 (http://www.gnu.org/software/gdb/bugs/) and ARI Index
2742 (http://sources.redhat.com/gdb/current/ari/) for more up-to-date
2743 information._
2745    Some architectures use one representation for a value when it lives
2746 in a register, but use a different representation when it lives in
2747 memory.  In GDB's terminology, the "raw" representation is the one used
2748 in the target registers, and the "virtual" representation is the one
2749 used in memory, and within GDB `struct value' objects.
2751    _Maintainer note: Notice that the same mechanism is being used to
2752 both convert a register to a `struct value' and alternative register
2753 forms._
2755    For almost all data types on almost all architectures, the virtual
2756 and raw representations are identical, and no special handling is
2757 needed.  However, they do occasionally differ.  For example:
2759    * The x86 architecture supports an 80-bit `long double' type.
2760      However, when we store those values in memory, they occupy twelve
2761      bytes: the floating-point number occupies the first ten, and the
2762      final two bytes are unused.  This keeps the values aligned on
2763      four-byte boundaries, allowing more efficient access.  Thus, the
2764      x86 80-bit floating-point type is the raw representation, and the
2765      twelve-byte loosely-packed arrangement is the virtual
2766      representation.
2768    * Some 64-bit MIPS targets present 32-bit registers to GDB as 64-bit
2769      registers, with garbage in their upper bits.  GDB ignores the top
2770      32 bits.  Thus, the 64-bit form, with garbage in the upper 32
2771      bits, is the raw representation, and the trimmed 32-bit
2772      representation is the virtual representation.
2774    In general, the raw representation is determined by the
2775 architecture, or GDB's interface to the architecture, while the virtual
2776 representation can be chosen for GDB's convenience.  GDB's register
2777 file, `registers', holds the register contents in raw format, and the
2778 GDB remote protocol transmits register values in raw format.
2780    Your architecture may define the following macros to request
2781 conversions between the raw and virtual format:
2783  -- Target Macro: int REGISTER_CONVERTIBLE (int REG)
2784      Return non-zero if register number REG's value needs different raw
2785      and virtual formats.
2787      You should not use `REGISTER_CONVERT_TO_VIRTUAL' for a register
2788      unless this macro returns a non-zero value for that register.
2790  -- Target Macro: int DEPRECATED_REGISTER_RAW_SIZE (int REG)
2791      The size of register number REG's raw value.  This is the number
2792      of bytes the register will occupy in `registers', or in a GDB
2793      remote protocol packet.
2795  -- Target Macro: int DEPRECATED_REGISTER_VIRTUAL_SIZE (int REG)
2796      The size of register number REG's value, in its virtual format.
2797      This is the size a `struct value''s buffer will have, holding that
2798      register's value.
2800  -- Target Macro: struct type *DEPRECATED_REGISTER_VIRTUAL_TYPE (int
2801           REG)
2802      This is the type of the virtual representation of register number
2803      REG.  Note that there is no need for a macro giving a type for the
2804      register's raw form; once the register's value has been obtained,
2805      GDB always uses the virtual form.
2807  -- Target Macro: void REGISTER_CONVERT_TO_VIRTUAL (int REG, struct
2808           type *TYPE, char *FROM, char *TO)
2809      Convert the value of register number REG to TYPE, which should
2810      always be `DEPRECATED_REGISTER_VIRTUAL_TYPE (REG)'.  The buffer at
2811      FROM holds the register's value in raw format; the macro should
2812      convert the value to virtual format, and place it at TO.
2814      Note that `REGISTER_CONVERT_TO_VIRTUAL' and
2815      `REGISTER_CONVERT_TO_RAW' take their REG and TYPE arguments in
2816      different orders.
2818      You should only use `REGISTER_CONVERT_TO_VIRTUAL' with registers
2819      for which the `REGISTER_CONVERTIBLE' macro returns a non-zero
2820      value.
2822  -- Target Macro: void REGISTER_CONVERT_TO_RAW (struct type *TYPE, int
2823           REG, char *FROM, char *TO)
2824      Convert the value of register number REG to TYPE, which should
2825      always be `DEPRECATED_REGISTER_VIRTUAL_TYPE (REG)'.  The buffer at
2826      FROM holds the register's value in raw format; the macro should
2827      convert the value to virtual format, and place it at TO.
2829      Note that REGISTER_CONVERT_TO_VIRTUAL and REGISTER_CONVERT_TO_RAW
2830      take their REG and TYPE arguments in different orders.
2832 \x1f
2833 File: gdbint.info,  Node: Register and Memory Data,  Next: Frame Interpretation,  Prev: Raw and Virtual Registers,  Up: Target Architecture Definition
2835 9.7 Using Different Register and Memory Data Representations
2836 ============================================================
2838 _Maintainer's note: The way GDB manipulates registers is undergoing
2839 significant change.  Many of the macros and functions referred to in
2840 this section are likely to be subject to further revision.  See A.R.
2841 Index (http://sources.redhat.com/gdb/current/ari/) and Bug Tracking
2842 Database (http://www.gnu.org/software/gdb/bugs) for further
2843 information.  cagney/2002-05-06._
2845    Some architectures can represent a data object in a register using a
2846 form that is different to the objects more normal memory representation.
2847 For example:
2849    * The Alpha architecture can represent 32 bit integer values in
2850      floating-point registers.
2852    * The x86 architecture supports 80-bit floating-point registers.  The
2853      `long double' data type occupies 96 bits in memory but only 80 bits
2854      when stored in a register.
2857    In general, the register representation of a data type is determined
2858 by the architecture, or GDB's interface to the architecture, while the
2859 memory representation is determined by the Application Binary Interface.
2861    For almost all data types on almost all architectures, the two
2862 representations are identical, and no special handling is needed.
2863 However, they do occasionally differ.  Your architecture may define the
2864 following macros to request conversions between the register and memory
2865 representations of a data type:
2867  -- Function: int gdbarch_convert_register_p (struct gdbarch *GDBARCH,
2868           int REG)
2869      Return non-zero if the representation of a data value stored in
2870      this register may be different to the representation of that same
2871      data value when stored in memory.
2873      When non-zero, the macros `gdbarch_register_to_value' and
2874      `value_to_register' are used to perform any necessary conversion.
2876      This function should return zero for the register's native type,
2877      when no conversion is necessary.
2879  -- Function: void gdbarch_register_to_value (struct gdbarch *GDBARCH,
2880           int REG, struct type *TYPE, char *FROM, char *TO)
2881      Convert the value of register number REG to a data object of type
2882      TYPE.  The buffer at FROM holds the register's value in raw
2883      format; the converted value should be placed in the buffer at TO.
2885      Note that `gdbarch_register_to_value' and
2886      `gdbarch_value_to_register' take their REG and TYPE arguments in
2887      different orders.
2889      You should only use `gdbarch_register_to_value' with registers for
2890      which the `gdbarch_convert_register_p' function returns a non-zero
2891      value.
2893  -- Function: void gdbarch_value_to_register (struct gdbarch *GDBARCH,
2894           struct type *TYPE, int REG, char *FROM, char *TO)
2895      Convert a data value of type TYPE to register number REG' raw
2896      format.
2898      Note that `gdbarch_register_to_value' and
2899      `gdbarch_value_to_register' take their REG and TYPE arguments in
2900      different orders.
2902      You should only use `gdbarch_value_to_register' with registers for
2903      which the `gdbarch_convert_register_p' function returns a non-zero
2904      value.
2906  -- Target Macro: void REGISTER_CONVERT_TO_TYPE (int REGNUM, struct
2907           type *TYPE, char *BUF)
2908      See `mips-tdep.c'.  It does not do what you want.
2910 \x1f
2911 File: gdbint.info,  Node: Frame Interpretation,  Next: Inferior Call Setup,  Prev: Register and Memory Data,  Up: Target Architecture Definition
2913 9.8 Frame Interpretation
2914 ========================
2916 \x1f
2917 File: gdbint.info,  Node: Inferior Call Setup,  Next: Compiler Characteristics,  Prev: Frame Interpretation,  Up: Target Architecture Definition
2919 9.9 Inferior Call Setup
2920 =======================
2922 \x1f
2923 File: gdbint.info,  Node: Compiler Characteristics,  Next: Target Conditionals,  Prev: Inferior Call Setup,  Up: Target Architecture Definition
2925 9.10 Compiler Characteristics
2926 =============================
2928 \x1f
2929 File: gdbint.info,  Node: Target Conditionals,  Next: Adding a New Target,  Prev: Compiler Characteristics,  Up: Target Architecture Definition
2931 9.11 Target Conditionals
2932 ========================
2934 This section describes the macros and functions that you can use to
2935 define the target machine.
2937 `CORE_ADDR gdbarch_addr_bits_remove (GDBARCH, ADDR)'
2938      If a raw machine instruction address includes any bits that are not
2939      really part of the address, then this function is used to zero
2940      those bits in ADDR.  This is only used for addresses of
2941      instructions, and even then not in all contexts.
2943      For example, the two low-order bits of the PC on the
2944      Hewlett-Packard PA 2.0 architecture contain the privilege level of
2945      the corresponding instruction.  Since instructions must always be
2946      aligned on four-byte boundaries, the processor masks out these
2947      bits to generate the actual address of the instruction.
2948      `gdbarch_addr_bits_remove' would then for example look like that:
2949           arch_addr_bits_remove (CORE_ADDR addr)
2950           {
2951             return (addr &= ~0x3);
2952           }
2954 `int address_class_name_to_type_flags (GDBARCH, NAME, TYPE_FLAGS_PTR)'
2955      If NAME is a valid address class qualifier name, set the `int'
2956      referenced by TYPE_FLAGS_PTR to the mask representing the qualifier
2957      and return 1.  If NAME is not a valid address class qualifier name,
2958      return 0.
2960      The value for TYPE_FLAGS_PTR should be one of
2961      `TYPE_FLAG_ADDRESS_CLASS_1', `TYPE_FLAG_ADDRESS_CLASS_2', or
2962      possibly some combination of these values or'd together.  *Note
2963      Address Classes: Target Architecture Definition.
2965 `int address_class_name_to_type_flags_p (GDBARCH)'
2966      Predicate which indicates whether
2967      `address_class_name_to_type_flags' has been defined.
2969 `int gdbarch_address_class_type_flags (GDBARCH, BYTE_SIZE, DWARF2_ADDR_CLASS)'
2970      Given a pointers byte size (as described by the debug information)
2971      and the possible `DW_AT_address_class' value, return the type flags
2972      used by GDB to represent this address class.  The value returned
2973      should be one of `TYPE_FLAG_ADDRESS_CLASS_1',
2974      `TYPE_FLAG_ADDRESS_CLASS_2', or possibly some combination of these
2975      values or'd together.  *Note Address Classes: Target Architecture
2976      Definition.
2978 `int gdbarch_address_class_type_flags_p (GDBARCH)'
2979      Predicate which indicates whether
2980      `gdbarch_address_class_type_flags_p' has been defined.
2982 `const char *gdbarch_address_class_type_flags_to_name (GDBARCH, TYPE_FLAGS)'
2983      Return the name of the address class qualifier associated with the
2984      type flags given by TYPE_FLAGS.
2986 `int gdbarch_address_class_type_flags_to_name_p (GDBARCH)'
2987      Predicate which indicates whether
2988      `gdbarch_address_class_type_flags_to_name' has been defined.
2989      *Note Address Classes: Target Architecture Definition.
2991 `void gdbarch_address_to_pointer (GDBARCH, TYPE, BUF, ADDR)'
2992      Store in BUF a pointer of type TYPE representing the address ADDR,
2993      in the appropriate format for the current architecture.  This
2994      function may safely assume that TYPE is either a pointer or a C++
2995      reference type.  *Note Pointers Are Not Always Addresses: Target
2996      Architecture Definition.
2998 `int gdbarch_believe_pcc_promotion (GDBARCH)'
2999      Used to notify if the compiler promotes a `short' or `char'
3000      parameter to an `int', but still reports the parameter as its
3001      original type, rather than the promoted type.
3003 `gdbarch_bits_big_endian (GDBARCH)'
3004      This is used if the numbering of bits in the targets does *not*
3005      match the endianness of the target byte order.  A value of 1 means
3006      that the bits are numbered in a big-endian bit order, 0 means
3007      little-endian.
3009 `set_gdbarch_bits_big_endian (GDBARCH, BITS_BIG_ENDIAN)'
3010      Calling set_gdbarch_bits_big_endian with a value of 1 indicates
3011      that the bits in the target are numbered in a big-endian bit
3012      order, 0 indicates little-endian.
3014 `BREAKPOINT'
3015      This is the character array initializer for the bit pattern to put
3016      into memory where a breakpoint is set.  Although it's common to
3017      use a trap instruction for a breakpoint, it's not required; for
3018      instance, the bit pattern could be an invalid instruction.  The
3019      breakpoint must be no longer than the shortest instruction of the
3020      architecture.
3022      `BREAKPOINT' has been deprecated in favor of
3023      `gdbarch_breakpoint_from_pc'.
3025 `BIG_BREAKPOINT'
3026 `LITTLE_BREAKPOINT'
3027      Similar to BREAKPOINT, but used for bi-endian targets.
3029      `BIG_BREAKPOINT' and `LITTLE_BREAKPOINT' have been deprecated in
3030      favor of `gdbarch_breakpoint_from_pc'.
3032 `const gdb_byte *gdbarch_breakpoint_from_pc (GDBARCH, PCPTR, LENPTR)'
3033      Use the program counter to determine the contents and size of a
3034      breakpoint instruction.  It returns a pointer to a string of bytes
3035      that encode a breakpoint instruction, stores the length of the
3036      string to `*LENPTR', and adjusts the program counter (if
3037      necessary) to point to the actual memory location where the
3038      breakpoint should be inserted.
3040      Although it is common to use a trap instruction for a breakpoint,
3041      it's not required; for instance, the bit pattern could be an
3042      invalid instruction.  The breakpoint must be no longer than the
3043      shortest instruction of the architecture.
3045      Replaces all the other BREAKPOINT macros.
3047 `int gdbarch_memory_insert_breakpoint (GDBARCH, BP_TGT)'
3048 `gdbarch_memory_remove_breakpoint (GDBARCH, BP_TGT)'
3049      Insert or remove memory based breakpoints.  Reasonable defaults
3050      (`default_memory_insert_breakpoint' and
3051      `default_memory_remove_breakpoint' respectively) have been
3052      provided so that it is not necessary to set these for most
3053      architectures.  Architectures which may want to set
3054      `gdbarch_memory_insert_breakpoint' and
3055      `gdbarch_memory_remove_breakpoint' will likely have instructions
3056      that are oddly sized or are not stored in a conventional manner.
3058      It may also be desirable (from an efficiency standpoint) to define
3059      custom breakpoint insertion and removal routines if
3060      `gdbarch_breakpoint_from_pc' needs to read the target's memory for
3061      some reason.
3063 `CORE_ADDR gdbarch_adjust_breakpoint_address (GDBARCH, BPADDR)'
3064      Given an address at which a breakpoint is desired, return a
3065      breakpoint address adjusted to account for architectural
3066      constraints on breakpoint placement.  This method is not needed by
3067      most targets.
3069      The FR-V target (see `frv-tdep.c') requires this method.  The FR-V
3070      is a VLIW architecture in which a number of RISC-like instructions
3071      are grouped (packed) together into an aggregate instruction or
3072      instruction bundle.  When the processor executes one of these
3073      bundles, the component instructions are executed in parallel.
3075      In the course of optimization, the compiler may group instructions
3076      from distinct source statements into the same bundle.  The line
3077      number information associated with one of the latter statements
3078      will likely refer to some instruction other than the first one in
3079      the bundle.  So, if the user attempts to place a breakpoint on one
3080      of these latter statements, GDB must be careful to _not_ place the
3081      break instruction on any instruction other than the first one in
3082      the bundle.  (Remember though that the instructions within a
3083      bundle execute in parallel, so the _first_ instruction is the
3084      instruction at the lowest address and has nothing to do with
3085      execution order.)
3087      The FR-V's `gdbarch_adjust_breakpoint_address' method will adjust a
3088      breakpoint's address by scanning backwards for the beginning of
3089      the bundle, returning the address of the bundle.
3091      Since the adjustment of a breakpoint may significantly alter a
3092      user's expectation, GDB prints a warning when an adjusted
3093      breakpoint is initially set and each time that that breakpoint is
3094      hit.
3096 `int gdbarch_call_dummy_location (GDBARCH)'
3097      See the file `inferior.h'.
3099      This method has been replaced by `gdbarch_push_dummy_code' (*note
3100      gdbarch_push_dummy_code::).
3102 `int gdbarch_cannot_fetch_register (GDBARCH, REGUM)'
3103      This function should return nonzero if REGNO cannot be fetched
3104      from an inferior process.  This is only relevant if
3105      `FETCH_INFERIOR_REGISTERS' is not defined.
3107 `int gdbarch_cannot_store_register (GDBARCH, REGNUM)'
3108      This function should return nonzero if REGNO should not be written
3109      to the target.  This is often the case for program counters,
3110      status words, and other special registers.  This function returns
3111      0 as default so that GDB will assume that all registers may be
3112      written.
3114 `int gdbarch_convert_register_p (GDBARCH, REGNUM, struct type *TYPE)'
3115      Return non-zero if register REGNUM represents data values of type
3116      TYPE in a non-standard form.  *Note Using Different Register and
3117      Memory Data Representations: Target Architecture Definition.
3119 `CORE_ADDR gdbarch_decr_pc_after_break (GDBARCH)'
3120      This function shall return the amount by which to decrement the PC
3121      after the program encounters a breakpoint.  This is often the
3122      number of bytes in `BREAKPOINT', though not always.  For most
3123      targets this value will be 0.
3125 `DISABLE_UNSETTABLE_BREAK (ADDR)'
3126      If defined, this should evaluate to 1 if ADDR is in a shared
3127      library in which breakpoints cannot be set and so should be
3128      disabled.
3130 `void gdbarch_print_float_info (GDBARCH, FILE, FRAME, ARGS)'
3131      If defined, then the `info float' command will print information
3132      about the processor's floating point unit.
3134 `void gdbarch_print_registers_info (GDBARCH, FRAME, REGNUM, ALL)'
3135      If defined, pretty print the value of the register REGNUM for the
3136      specified FRAME.  If the value of REGNUM is -1, pretty print
3137      either all registers (ALL is non zero) or a select subset of
3138      registers (ALL is zero).
3140      The default method prints one register per line, and if ALL is
3141      zero omits floating-point registers.
3143 `int gdbarch_print_vector_info (GDBARCH, FILE, FRAME, ARGS)'
3144      If defined, then the `info vector' command will call this function
3145      to print information about the processor's vector unit.
3147      By default, the `info vector' command will print all vector
3148      registers (the register's type having the vector attribute).
3150 `int gdbarch_dwarf_reg_to_regnum (GDBARCH, DWARF_REGNR)'
3151      Convert DWARF register number DWARF_REGNR into GDB regnum.  If not
3152      defined, no conversion will be performed.
3154 `int gdbarch_dwarf2_reg_to_regnum (GDBARCH, DWARF2_REGNR)'
3155      Convert DWARF2 register number DWARF2_REGNR into GDB regnum.  If
3156      not defined, no conversion will be performed.
3158 `int gdbarch_ecoff_reg_to_regnum (GDBARCH, ECOFF_REGNR)'
3159      Convert ECOFF register number  ECOFF_REGNR into GDB regnum.  If
3160      not defined, no conversion will be performed.
3162 `DEPRECATED_FP_REGNUM'
3163      If the virtual frame pointer is kept in a register, then define
3164      this macro to be the number (greater than or equal to zero) of
3165      that register.
3167      This should only need to be defined if `DEPRECATED_TARGET_READ_FP'
3168      is not defined.
3170 `DEPRECATED_FRAMELESS_FUNCTION_INVOCATION(FI)'
3171      Define this to an expression that returns 1 if the function
3172      invocation represented by FI does not have a stack frame
3173      associated with it.  Otherwise return 0.
3175 `CORE_ADDR frame_align (GDBARCH, ADDRESS)'
3176      Define this to adjust ADDRESS so that it meets the alignment
3177      requirements for the start of a new stack frame.  A stack frame's
3178      alignment requirements are typically stronger than a target
3179      processors stack alignment requirements.
3181      This function is used to ensure that, when creating a dummy frame,
3182      both the initial stack pointer and (if needed) the address of the
3183      return value are correctly aligned.
3185      This function always adjusts the address in the direction of stack
3186      growth.
3188      By default, no frame based stack alignment is performed.
3190 `int gdbarch_frame_red_zone_size (GDBARCH)'
3191      The number of bytes, beyond the innermost-stack-address, reserved
3192      by the ABI.  A function is permitted to use this scratch area
3193      (instead of allocating extra stack space).
3195      When performing an inferior function call, to ensure that it does
3196      not modify this area, GDB adjusts the innermost-stack-address by
3197      GDBARCH_FRAME_RED_ZONE_SIZE bytes before pushing parameters onto
3198      the stack.
3200      By default, zero bytes are allocated.  The value must be aligned
3201      (*note frame_align::).
3203      The AMD64 (nee x86-64) ABI documentation refers to the _red zone_
3204      when describing this scratch area.  
3206 `DEPRECATED_FRAME_CHAIN(FRAME)'
3207      Given FRAME, return a pointer to the calling frame.
3209 `DEPRECATED_FRAME_CHAIN_VALID(CHAIN, THISFRAME)'
3210      Define this to be an expression that returns zero if the given
3211      frame is an outermost frame, with no caller, and nonzero
3212      otherwise.  Most normal situations can be handled without defining
3213      this macro, including `NULL' chain pointers, dummy frames, and
3214      frames whose PC values are inside the startup file (e.g.
3215      `crt0.o'), inside `main', or inside `_start'.
3217 `DEPRECATED_FRAME_INIT_SAVED_REGS(FRAME)'
3218      See `frame.h'.  Determines the address of all registers in the
3219      current stack frame storing each in `frame->saved_regs'.  Space for
3220      `frame->saved_regs' shall be allocated by
3221      `DEPRECATED_FRAME_INIT_SAVED_REGS' using `frame_saved_regs_zalloc'.
3223      `FRAME_FIND_SAVED_REGS' is deprecated.
3225 `int gdbarch_frame_num_args (GDBARCH, FRAME)'
3226      For the frame described by FRAME return the number of arguments
3227      that are being passed.  If the number of arguments is not known,
3228      return `-1'.
3230 `DEPRECATED_FRAME_SAVED_PC(FRAME)'
3231      Given FRAME, return the pc saved there.  This is the return
3232      address.
3234      This method is deprecated. *Note gdbarch_unwind_pc::.
3236 `CORE_ADDR gdbarch_unwind_pc (NEXT_FRAME)'
3237      Return the instruction address, in NEXT_FRAME's caller, at which
3238      execution will resume after NEXT_FRAME returns.  This is commonly
3239      referred to as the return address.
3241      The implementation, which must be frame agnostic (work with any
3242      frame), is typically no more than:
3244           ULONGEST pc;
3245           pc = frame_unwind_register_unsigned (next_frame, S390_PC_REGNUM);
3246           return gdbarch_addr_bits_remove (gdbarch, pc);
3248      *Note DEPRECATED_FRAME_SAVED_PC::, which this method replaces.
3250 `CORE_ADDR gdbarch_unwind_sp (GDBARCH, NEXT_FRAME)'
3251      Return the frame's inner most stack address.  This is commonly
3252      referred to as the frame's "stack pointer".
3254      The implementation, which must be frame agnostic (work with any
3255      frame), is typically no more than:
3257           ULONGEST sp;
3258           sp = frame_unwind_register_unsigned (next_frame, S390_SP_REGNUM);
3259           return gdbarch_addr_bits_remove (gdbarch, sp);
3261      *Note TARGET_READ_SP::, which this method replaces.
3263 `FUNCTION_EPILOGUE_SIZE'
3264      For some COFF targets, the `x_sym.x_misc.x_fsize' field of the
3265      function end symbol is 0.  For such targets, you must define
3266      `FUNCTION_EPILOGUE_SIZE' to expand into the standard size of a
3267      function's epilogue.
3269 `DEPRECATED_FUNCTION_START_OFFSET'
3270      An integer, giving the offset in bytes from a function's address
3271      (as used in the values of symbols, function pointers, etc.), and
3272      the function's first genuine instruction.
3274      This is zero on almost all machines: the function's address is
3275      usually the address of its first instruction.  However, on the
3276      VAX, for example, each function starts with two bytes containing a
3277      bitmask indicating which registers to save upon entry to the
3278      function.  The VAX `call' instructions check this value, and save
3279      the appropriate registers automatically.  Thus, since the offset
3280      from the function's address to its first instruction is two bytes,
3281      `DEPRECATED_FUNCTION_START_OFFSET' would be 2 on the VAX.
3283 `GCC_COMPILED_FLAG_SYMBOL'
3284 `GCC2_COMPILED_FLAG_SYMBOL'
3285      If defined, these are the names of the symbols that GDB will look
3286      for to detect that GCC compiled the file.  The default symbols are
3287      `gcc_compiled.' and `gcc2_compiled.', respectively.  (Currently
3288      only defined for the Delta 68.)
3290 `gdbarch_get_longjmp_target'
3291      For most machines, this is a target-dependent parameter.  On the
3292      DECstation and the Iris, this is a native-dependent parameter,
3293      since the header file `setjmp.h' is needed to define it.
3295      This macro determines the target PC address that `longjmp' will
3296      jump to, assuming that we have just stopped at a `longjmp'
3297      breakpoint.  It takes a `CORE_ADDR *' as argument, and stores the
3298      target PC value through this pointer.  It examines the current
3299      state of the machine as needed.
3301 `DEPRECATED_IBM6000_TARGET'
3302      Shows that we are configured for an IBM RS/6000 system.  This
3303      conditional should be eliminated (FIXME) and replaced by
3304      feature-specific macros.  It was introduced in a haste and we are
3305      repenting at leisure.
3307 `I386_USE_GENERIC_WATCHPOINTS'
3308      An x86-based target can define this to use the generic x86
3309      watchpoint support; see *Note I386_USE_GENERIC_WATCHPOINTS:
3310      Algorithms.
3312 `int gdbarch_inner_than (GDBARCH, LHS, RHS)'
3313      Returns non-zero if stack address LHS is inner than (nearer to the
3314      stack top) stack address RHS.  Let the function return `lhs < rhs'
3315      if the target's stack grows downward in memory, or `lhs > rsh' if
3316      the stack grows upward.
3318 `gdbarch_in_function_epilogue_p (GDBARCH, ADDR)'
3319      Returns non-zero if the given ADDR is in the epilogue of a
3320      function.  The epilogue of a function is defined as the part of a
3321      function where the stack frame of the function already has been
3322      destroyed up to the final `return from function call' instruction.
3324 `int gdbarch_in_solib_return_trampoline (GDBARCH, PC, NAME)'
3325      Define this function to return nonzero if the program is stopped
3326      in the trampoline that returns from a shared library.
3328 `IN_SOLIB_DYNSYM_RESOLVE_CODE (PC)'
3329      Define this to return nonzero if the program is stopped in the
3330      dynamic linker.
3332 `SKIP_SOLIB_RESOLVER (PC)'
3333      Define this to evaluate to the (nonzero) address at which execution
3334      should continue to get past the dynamic linker's symbol resolution
3335      function.  A zero value indicates that it is not important or
3336      necessary to set a breakpoint to get through the dynamic linker
3337      and that single stepping will suffice.
3339 `CORE_ADDR gdbarch_integer_to_address (GDBARCH, TYPE, BUF)'
3340      Define this when the architecture needs to handle non-pointer to
3341      address conversions specially.  Converts that value to an address
3342      according to the current architectures conventions.
3344      _Pragmatics: When the user copies a well defined expression from
3345      their source code and passes it, as a parameter, to GDB's `print'
3346      command, they should get the same value as would have been
3347      computed by the target program.  Any deviation from this rule can
3348      cause major confusion and annoyance, and needs to be justified
3349      carefully.  In other words, GDB doesn't really have the freedom to
3350      do these conversions in clever and useful ways.  It has, however,
3351      been pointed out that users aren't complaining about how GDB casts
3352      integers to pointers; they are complaining that they can't take an
3353      address from a disassembly listing and give it to `x/i'.  Adding
3354      an architecture method like `gdbarch_integer_to_address' certainly
3355      makes it possible for GDB to "get it right" in all circumstances._
3357      *Note Pointers Are Not Always Addresses: Target Architecture
3358      Definition.
3360 `CORE_ADDR gdbarch_pointer_to_address (GDBARCH, TYPE, BUF)'
3361      Assume that BUF holds a pointer of type TYPE, in the appropriate
3362      format for the current architecture.  Return the byte address the
3363      pointer refers to.  *Note Pointers Are Not Always Addresses:
3364      Target Architecture Definition.
3366 `void gdbarch_register_to_value(GDBARCH, FRAME, REGNUM, TYPE, FUR)'
3367      Convert the raw contents of register REGNUM into a value of type
3368      TYPE.  *Note Using Different Register and Memory Data
3369      Representations: Target Architecture Definition.
3371 `register_reggroup_p (GDBARCH, REGNUM, REGGROUP)'
3372      Return non-zero if register REGNUM is a member of the register
3373      group REGGROUP.
3375      By default, registers are grouped as follows:
3377     `float_reggroup'
3378           Any register with a valid name and a floating-point type.
3380     `vector_reggroup'
3381           Any register with a valid name and a vector type.
3383     `general_reggroup'
3384           Any register with a valid name and a type other than vector or
3385           floating-point.  `float_reggroup'.
3387     `save_reggroup'
3388     `restore_reggroup'
3389     `all_reggroup'
3390           Any register with a valid name.
3392 `DEPRECATED_REGISTER_VIRTUAL_SIZE (REG)'
3393      Return the virtual size of REG; defaults to the size of the
3394      register's virtual type.  Return the virtual size of REG.  *Note
3395      Raw and Virtual Register Representations: Target Architecture
3396      Definition.
3398 `DEPRECATED_REGISTER_VIRTUAL_TYPE (REG)'
3399      Return the virtual type of REG.  *Note Raw and Virtual Register
3400      Representations: Target Architecture Definition.
3402 `struct type *register_type (GDBARCH, REG)'
3403      If defined, return the type of register REG.  This function
3404      supersedes `DEPRECATED_REGISTER_VIRTUAL_TYPE'.  *Note Raw and
3405      Virtual Register Representations: Target Architecture Definition.
3407 `REGISTER_CONVERT_TO_VIRTUAL(REG, TYPE, FROM, TO)'
3408      Convert the value of register REG from its raw form to its virtual
3409      form.  *Note Raw and Virtual Register Representations: Target
3410      Architecture Definition.
3412 `REGISTER_CONVERT_TO_RAW(TYPE, REG, FROM, TO)'
3413      Convert the value of register REG from its virtual form to its raw
3414      form.  *Note Raw and Virtual Register Representations: Target
3415      Architecture Definition.
3417 `const struct regset *regset_from_core_section (struct gdbarch * GDBARCH, const char * SECT_NAME, size_t SECT_SIZE)'
3418      Return the appropriate register set for a core file section with
3419      name SECT_NAME and size SECT_SIZE.
3421 `SOFTWARE_SINGLE_STEP_P()'
3422      Define this as 1 if the target does not have a hardware single-step
3423      mechanism.  The macro `SOFTWARE_SINGLE_STEP' must also be defined.
3425 `SOFTWARE_SINGLE_STEP(SIGNAL, INSERT_BREAKPOINTS_P)'
3426      A function that inserts or removes (depending on
3427      INSERT_BREAKPOINTS_P) breakpoints at each possible destinations of
3428      the next instruction. See `sparc-tdep.c' and `rs6000-tdep.c' for
3429      examples.
3431 `set_gdbarch_sofun_address_maybe_missing (GDBARCH, SET)'
3432      Somebody clever observed that, the more actual addresses you have
3433      in the debug information, the more time the linker has to spend
3434      relocating them.  So whenever there's some other way the debugger
3435      could find the address it needs, you should omit it from the debug
3436      info, to make linking faster.
3438      Calling `set_gdbarch_sofun_address_maybe_missing' with a non-zero
3439      argument SET indicates that a particular set of hacks of this sort
3440      are in use, affecting `N_SO' and `N_FUN' entries in stabs-format
3441      debugging information.  `N_SO' stabs mark the beginning and ending
3442      addresses of compilation units in the text segment.  `N_FUN' stabs
3443      mark the starts and ends of functions.
3445      In this case, GDB assumes two things:
3447         * `N_FUN' stabs have an address of zero.  Instead of using those
3448           addresses, you should find the address where the function
3449           starts by taking the function name from the stab, and then
3450           looking that up in the minsyms (the linker/assembler symbol
3451           table).  In other words, the stab has the name, and the
3452           linker/assembler symbol table is the only place that carries
3453           the address.
3455         * `N_SO' stabs have an address of zero, too.  You just look at
3456           the `N_FUN' stabs that appear before and after the `N_SO'
3457           stab, and guess the starting and ending addresses of the
3458           compilation unit from them.
3460 `int gdbarch_pc_regnum (GDBARCH)'
3461      If the program counter is kept in a register, then let this
3462      function return the number (greater than or equal to zero) of that
3463      register.
3465      This should only need to be defined if `gdbarch_read_pc' and
3466      `gdbarch_write_pc' are not defined.
3468 `int gdbarch_stabs_argument_has_addr (GDBARCH, TYPE)'
3469      Define this function to return nonzero if a function argument of
3470      type TYPE is passed by reference instead of value.
3472 `PROCESS_LINENUMBER_HOOK'
3473      A hook defined for XCOFF reading.
3475 `gdbarch_ps_regnum (GDBARCH'
3476      If defined, this function returns the number of the processor
3477      status register.  (This definition is only used in generic code
3478      when parsing "$ps".)
3480 `CORE_ADDR gdbarch_push_dummy_call (GDBARCH, FUNCTION, REGCACHE, BP_ADDR, NARGS, ARGS, SP, STRUCT_RETURN, STRUCT_ADDR)'
3481      Define this to push the dummy frame's call to the inferior
3482      function onto the stack.  In addition to pushing NARGS, the code
3483      should push STRUCT_ADDR (when STRUCT_RETURN is non-zero), and the
3484      return address (BP_ADDR).
3486      FUNCTION is a pointer to a `struct value'; on architectures that
3487      use function descriptors, this contains the function descriptor
3488      value.
3490      Returns the updated top-of-stack pointer.
3492      This method replaces `DEPRECATED_PUSH_ARGUMENTS'.
3494 `CORE_ADDR gdbarch_push_dummy_code (GDBARCH, SP, FUNADDR, USING_GCC, ARGS, NARGS, VALUE_TYPE, REAL_PC, BP_ADDR, REGCACHE)'
3495      Given a stack based call dummy, push the instruction sequence
3496      (including space for a breakpoint) to which the called function
3497      should return.
3499      Set BP_ADDR to the address at which the breakpoint instruction
3500      should be inserted, REAL_PC to the resume address when starting
3501      the call sequence, and return the updated inner-most stack address.
3503      By default, the stack is grown sufficient to hold a frame-aligned
3504      (*note frame_align::) breakpoint, BP_ADDR is set to the address
3505      reserved for that breakpoint, and REAL_PC set to FUNADDR.
3507      This method replaces `gdbarch_call_dummy_location (GDBARCH)' and
3508      `DEPRECATED_REGISTER_SIZE'.
3510 `const char *gdbarch_register_name (GDBARCH, REGNR)'
3511      Return the name of register REGNR as a string.  May return `NULL'
3512      to indicate that REGNR is not a valid register.
3514 `SAVE_DUMMY_FRAME_TOS (SP)'
3515      Used in `call_function_by_hand' to notify the target dependent
3516      code of the top-of-stack value that will be passed to the inferior
3517      code.  This is the value of the `SP' after both the dummy frame
3518      and space for parameters/results have been allocated on the stack.
3519      *Note gdbarch_unwind_dummy_id::.
3521 `int gdbarch_sdb_reg_to_regnum (GDBARCH, SDB_REGNR)'
3522      Use this function to convert sdb register SDB_REGNR into GDB
3523      regnum.  If not defined, no conversion will be done.
3525 `enum return_value_convention gdbarch_return_value (struct gdbarch *GDBARCH, struct type *VALTYPE, struct regcache *REGCACHE, void *READBUF, const void *WRITEBUF)'
3526      Given a function with a return-value of type RETTYPE, return which
3527      return-value convention that function would use.
3529      GDB currently recognizes two function return-value conventions:
3530      `RETURN_VALUE_REGISTER_CONVENTION' where the return value is found
3531      in registers; and `RETURN_VALUE_STRUCT_CONVENTION' where the return
3532      value is found in memory and the address of that memory location is
3533      passed in as the function's first parameter.
3535      If the register convention is being used, and WRITEBUF is
3536      non-`NULL', also copy the return-value in WRITEBUF into REGCACHE.
3538      If the register convention is being used, and READBUF is
3539      non-`NULL', also copy the return value from REGCACHE into READBUF
3540      (REGCACHE contains a copy of the registers from the just returned
3541      function).
3543      _Maintainer note: This method replaces separate predicate, extract,
3544      store methods.  By having only one method, the logic needed to
3545      determine the return-value convention need only be implemented in
3546      one place.  If GDB were written in an OO language, this method
3547      would instead return an object that knew how to perform the
3548      register return-value extract and store._
3550      _Maintainer note: This method does not take a GCC_P parameter, and
3551      such a parameter should not be added.  If an architecture that
3552      requires per-compiler or per-function information be identified,
3553      then the replacement of RETTYPE with `struct value' FUNCTION
3554      should be pursued._
3556      _Maintainer note: The REGCACHE parameter limits this methods to
3557      the inner most frame.  While replacing REGCACHE with a `struct
3558      frame_info' FRAME parameter would remove that limitation there has
3559      yet to be a demonstrated need for such a change._
3561 `void gdbarch_skip_permanent_breakpoint (GDBARCH, REGCACHE)'
3562      Advance the inferior's PC past a permanent breakpoint.  GDB
3563      normally steps over a breakpoint by removing it, stepping one
3564      instruction, and re-inserting the breakpoint.  However, permanent
3565      breakpoints are hardwired into the inferior, and can't be removed,
3566      so this strategy doesn't work.  Calling
3567      `gdbarch_skip_permanent_breakpoint' adjusts the processor's state
3568      so that execution will resume just after the breakpoint.  This
3569      function does the right thing even when the breakpoint is in the
3570      delay slot of a branch or jump.
3572 `CORE_ADDR gdbarch_skip_prologue (GDBARCH, IP)'
3573      A function that returns the address of the "real" code beyond the
3574      function entry prologue found at IP.
3576 `CORE_ADDR gdbarch_skip_trampoline_code (GDBARCH, FRAME, PC)'
3577      If the target machine has trampoline code that sits between
3578      callers and the functions being called, then define this function
3579      to return a new PC that is at the start of the real function.
3581 `int gdbarch_sp_regnum (GDBARCH)'
3582      If the stack-pointer is kept in a register, then use this function
3583      to return the number (greater than or equal to zero) of that
3584      register, or -1 if there is no such register.
3586 `int gdbarch_stab_reg_to_regnum (GDBARCH, STAB_REGNR)'
3587      Use this function to convert stab register STAB_REGNR into GDB
3588      regnum.  If not defined, no conversion will be done.
3590 `SYMBOL_RELOADING_DEFAULT'
3591      The default value of the "symbol-reloading" variable.  (Never
3592      defined in current sources.)
3594 `TARGET_CHAR_BIT'
3595      Number of bits in a char; defaults to 8.
3597 `int gdbarch_char_signed (GDBARCH)'
3598      Non-zero if `char' is normally signed on this architecture; zero if
3599      it should be unsigned.
3601      The ISO C standard requires the compiler to treat `char' as
3602      equivalent to either `signed char' or `unsigned char'; any
3603      character in the standard execution set is supposed to be positive.
3604      Most compilers treat `char' as signed, but `char' is unsigned on
3605      the IBM S/390, RS6000, and PowerPC targets.
3607 `int gdbarch_double_bit (GDBARCH)'
3608      Number of bits in a double float; defaults to
3609      `8 * TARGET_CHAR_BIT'.
3611 `int gdbarch_float_bit (GDBARCH)'
3612      Number of bits in a float; defaults to `4 * TARGET_CHAR_BIT'.
3614 `int gdbarch_int_bit (GDBARCH)'
3615      Number of bits in an integer; defaults to `4 * TARGET_CHAR_BIT'.
3617 `int gdbarch_long_bit (GDBARCH)'
3618      Number of bits in a long integer; defaults to
3619      `4 * TARGET_CHAR_BIT'.
3621 `int gdbarch_long_double_bit (GDBARCH)'
3622      Number of bits in a long double float; defaults to
3623      `2 * gdbarch_double_bit (GDBARCH)'.
3625 `int gdbarch_long_long_bit (GDBARCH)'
3626      Number of bits in a long long integer; defaults to
3627      `2 * gdbarch_long_bit (GDBARCH)'.
3629 `int gdbarch_ptr_bit (GDBARCH)'
3630      Number of bits in a pointer; defaults to
3631      `gdbarch_int_bit (GDBARCH)'.
3633 `int gdbarch_short_bit (GDBARCH)'
3634      Number of bits in a short integer; defaults to
3635      `2 * TARGET_CHAR_BIT'.
3637 `CORE_ADDR gdbarch_read_pc (GDBARCH, REGCACHE)'
3638 `gdbarch_write_pc (GDBARCH, REGCACHE, VAL)'
3639 `TARGET_READ_SP'
3640 `TARGET_READ_FP'
3641      These change the behavior of `gdbarch_read_pc',
3642      `gdbarch_write_pc', and `read_sp'.  For most targets, these may be
3643      left undefined.  GDB will call the read and write register
3644      functions with the relevant `_REGNUM' argument.
3646      These macros and functions are useful when a target keeps one of
3647      these registers in a hard to get at place; for example, part in a
3648      segment register and part in an ordinary register.
3650      *Note gdbarch_unwind_sp::, which replaces `TARGET_READ_SP'.
3652 `void gdbarch_virtual_frame_pointer (GDBARCH, PC, FRAME_REGNUM, FRAME_OFFSET)'
3653      Returns a `(register, offset)' pair representing the virtual frame
3654      pointer in use at the code address PC.  If virtual frame pointers
3655      are not used, a default definition simply returns
3656      `DEPRECATED_FP_REGNUM', with an offset of zero.
3658 `TARGET_HAS_HARDWARE_WATCHPOINTS'
3659      If non-zero, the target has support for hardware-assisted
3660      watchpoints.  *Note watchpoints: Algorithms, for more details and
3661      other related macros.
3663 `int gdbarch_print_insn (GDBARCH, VMA, INFO)'
3664      This is the function used by GDB to print an assembly instruction.
3665      It prints the instruction at address VMA in debugged memory and
3666      returns the length of the instruction, in bytes.  If a target
3667      doesn't define its own printing routine, it defaults to an
3668      accessor function for the global pointer
3669      `deprecated_tm_print_insn'.  This usually points to a function in
3670      the `opcodes' library (*note Opcodes: Support Libraries.).  INFO
3671      is a structure (of type `disassemble_info') defined in
3672      `include/dis-asm.h' used to pass information to the instruction
3673      decoding routine.
3675 `frame_id gdbarch_unwind_dummy_id (GDBARCH, FRAME)'
3676      Given FRAME return a `struct frame_id' that uniquely identifies an
3677      inferior function call's dummy frame.  The value returned must
3678      match the dummy frame stack value previously saved using
3679      `SAVE_DUMMY_FRAME_TOS'.  *Note SAVE_DUMMY_FRAME_TOS::.
3681 `DEPRECATED_USE_STRUCT_CONVENTION (GCC_P, TYPE)'
3682      If defined, this must be an expression that is nonzero if a value
3683      of the given TYPE being returned from a function must have space
3684      allocated for it on the stack.  GCC_P is true if the function
3685      being considered is known to have been compiled by GCC; this is
3686      helpful for systems where GCC is known to use different calling
3687      convention than other compilers.
3689      This method has been deprecated in favour of `gdbarch_return_value'
3690      (*note gdbarch_return_value::).
3692 `void gdbarch_value_to_register (GDBARCH, FRAME, TYPE, BUF)'
3693      Convert a value of type TYPE into the raw contents of a register.
3694      *Note Using Different Register and Memory Data Representations:
3695      Target Architecture Definition.
3698    Motorola M68K target conditionals.
3700 `BPT_VECTOR'
3701      Define this to be the 4-bit location of the breakpoint trap
3702      vector.  If not defined, it will default to `0xf'.
3704 `REMOTE_BPT_VECTOR'
3705      Defaults to `1'.
3707 `const char *gdbarch_name_of_malloc (GDBARCH)'
3708      A string containing the name of the function to call in order to
3709      allocate some memory in the inferior. The default value is
3710      "malloc".
3713 \x1f
3714 File: gdbint.info,  Node: Adding a New Target,  Prev: Target Conditionals,  Up: Target Architecture Definition
3716 9.12 Adding a New Target
3717 ========================
3719 The following files add a target to GDB:
3721 `gdb/config/ARCH/TTT.mt'
3722      Contains a Makefile fragment specific to this target.  Specifies
3723      what object files are needed for target TTT, by defining
3724      `TDEPFILES=...' and `TDEPLIBS=...'.  Also specifies the header
3725      file which describes TTT, by defining `TM_FILE= tm-TTT.h'.
3727      You can also define `TM_CFLAGS', `TM_CLIBS', `TM_CDEPS', but these
3728      are now deprecated, replaced by autoconf, and may go away in
3729      future versions of GDB.
3731 `gdb/TTT-tdep.c'
3732      Contains any miscellaneous code required for this target machine.
3733      On some machines it doesn't exist at all.  Sometimes the macros in
3734      `tm-TTT.h' become very complicated, so they are implemented as
3735      functions here instead, and the macro is simply defined to call the
3736      function.  This is vastly preferable, since it is easier to
3737      understand and debug.
3739 `gdb/ARCH-tdep.c'
3740 `gdb/ARCH-tdep.h'
3741      This often exists to describe the basic layout of the target
3742      machine's processor chip (registers, stack, etc.).  If used, it is
3743      included by `TTT-tdep.h'.  It can be shared among many targets
3744      that use the same processor.
3746 `gdb/config/ARCH/tm-TTT.h'
3747      (`tm.h' is a link to this file, created by `configure').  Contains
3748      macro definitions about the target machine's registers, stack frame
3749      format and instructions.
3751      New targets do not need this file and should not create it.
3753 `gdb/config/ARCH/tm-ARCH.h'
3754      This often exists to describe the basic layout of the target
3755      machine's processor chip (registers, stack, etc.).  If used, it is
3756      included by `tm-TTT.h'.  It can be shared among many targets that
3757      use the same processor.
3759      New targets do not need this file and should not create it.
3762    If you are adding a new operating system for an existing CPU chip,
3763 add a `config/tm-OS.h' file that describes the operating system
3764 facilities that are unusual (extra symbol table info; the breakpoint
3765 instruction needed; etc.).  Then write a `ARCH/tm-OS.h' that just
3766 `#include's `tm-ARCH.h' and `config/tm-OS.h'.
3768 \x1f
3769 File: gdbint.info,  Node: Target Descriptions,  Next: Target Vector Definition,  Prev: Target Architecture Definition,  Up: Top
3771 10 Target Descriptions
3772 **********************
3774 The target architecture definition (*note Target Architecture
3775 Definition::) contains GDB's hard-coded knowledge about an
3776 architecture.  For some platforms, it is handy to have more flexible
3777 knowledge about a specific instance of the architecture--for instance,
3778 a processor or development board.  "Target descriptions" provide a
3779 mechanism for the user to tell GDB more about what their target
3780 supports, or for the target to tell GDB directly.
3782    For details on writing, automatically supplying, and manually
3783 selecting target descriptions, see *Note Target Descriptions:
3784 (gdb)Target Descriptions.  This section will cover some related topics
3785 about the GDB internals.
3787 * Menu:
3789 * Target Descriptions Implementation::
3790 * Adding Target Described Register Support::
3792 \x1f
3793 File: gdbint.info,  Node: Target Descriptions Implementation,  Next: Adding Target Described Register Support,  Up: Target Descriptions
3795 10.1 Target Descriptions Implementation
3796 =======================================
3798 Before GDB connects to a new target, or runs a new program on an
3799 existing target, it discards any existing target description and
3800 reverts to a default gdbarch.  Then, after connecting, it looks for a
3801 new target description by calling `target_find_description'.
3803    A description may come from a user specified file (XML), the remote
3804 `qXfer:features:read' packet (also XML), or from any custom
3805 `to_read_description' routine in the target vector.  For instance, the
3806 remote target supports guessing whether a MIPS target is 32-bit or
3807 64-bit based on the size of the `g' packet.
3809    If any target description is found, GDB creates a new gdbarch
3810 incorporating the description by calling `gdbarch_update_p'.  Any
3811 `<architecture>' element is handled first, to determine which
3812 architecture's gdbarch initialization routine is called to create the
3813 new architecture.  Then the initialization routine is called, and has a
3814 chance to adjust the constructed architecture based on the contents of
3815 the target description.  For instance, it can recognize any properties
3816 set by a `to_read_description' routine.  Also see *Note Adding Target
3817 Described Register Support::.
3819 \x1f
3820 File: gdbint.info,  Node: Adding Target Described Register Support,  Prev: Target Descriptions Implementation,  Up: Target Descriptions
3822 10.2 Adding Target Described Register Support
3823 =============================================
3825 Target descriptions can report additional registers specific to an
3826 instance of the target.  But it takes a little work in the architecture
3827 specific routines to support this.
3829    A target description must either have no registers or a complete
3830 set--this avoids complexity in trying to merge standard registers with
3831 the target defined registers.  It is the architecture's responsibility
3832 to validate that a description with registers has everything it needs.
3833 To keep architecture code simple, the same mechanism is used to assign
3834 fixed internal register numbers to standard registers.
3836    If `tdesc_has_registers' returns 1, the description contains
3837 registers.  The architecture's `gdbarch_init' routine should:
3839    * Call `tdesc_data_alloc' to allocate storage, early, before
3840      searching for a matching gdbarch or allocating a new one.
3842    * Use `tdesc_find_feature' to locate standard features by name.
3844    * Use `tdesc_numbered_register' and `tdesc_numbered_register_choices'
3845      to locate the expected registers in the standard features.
3847    * Return `NULL' if a required feature is missing, or if any standard
3848      feature is missing expected registers.  This will produce a
3849      warning that the description was incomplete.
3851    * Free the allocated data before returning, unless
3852      `tdesc_use_registers' is called.
3854    * Call `set_gdbarch_num_regs' as usual, with a number higher than any
3855      fixed number passed to `tdesc_numbered_register'.
3857    * Call `tdesc_use_registers' after creating a new gdbarch, before
3858      returning it.
3861    After `tdesc_use_registers' has been called, the architecture's
3862 `register_name', `register_type', and `register_reggroup_p' routines
3863 will not be called; that information will be taken from the target
3864 description.  `num_regs' may be increased to account for any additional
3865 registers in the description.
3867    Pseudo-registers require some extra care:
3869    * Using `tdesc_numbered_register' allows the architecture to give
3870      constant register numbers to standard architectural registers, e.g.
3871      as an `enum' in `ARCH-tdep.h'.  But because pseudo-registers are
3872      always numbered above `num_regs', which may be increased by the
3873      description, constant numbers can not be used for pseudos.  They
3874      must be numbered relative to `num_regs' instead.
3876    * The description will not describe pseudo-registers, so the
3877      architecture must call `set_tdesc_pseudo_register_name',
3878      `set_tdesc_pseudo_register_type', and
3879      `set_tdesc_pseudo_register_reggroup_p' to supply routines
3880      describing pseudo registers.  These routines will be passed
3881      internal register numbers, so the same routines used for the
3882      gdbarch equivalents are usually suitable.
3885 \x1f
3886 File: gdbint.info,  Node: Target Vector Definition,  Next: Native Debugging,  Prev: Target Descriptions,  Up: Top
3888 11 Target Vector Definition
3889 ***************************
3891 The target vector defines the interface between GDB's abstract handling
3892 of target systems, and the nitty-gritty code that actually exercises
3893 control over a process or a serial port.  GDB includes some 30-40
3894 different target vectors; however, each configuration of GDB includes
3895 only a few of them.
3897 * Menu:
3899 * Managing Execution State::
3900 * Existing Targets::
3902 \x1f
3903 File: gdbint.info,  Node: Managing Execution State,  Next: Existing Targets,  Up: Target Vector Definition
3905 11.1 Managing Execution State
3906 =============================
3908 A target vector can be completely inactive (not pushed on the target
3909 stack), active but not running (pushed, but not connected to a fully
3910 manifested inferior), or completely active (pushed, with an accessible
3911 inferior).  Most targets are only completely inactive or completely
3912 active, but some support persistent connections to a target even when
3913 the target has exited or not yet started.
3915    For example, connecting to the simulator using `target sim' does not
3916 create a running program.  Neither registers nor memory are accessible
3917 until `run'.  Similarly, after `kill', the program can not continue
3918 executing.  But in both cases GDB remains connected to the simulator,
3919 and target-specific commands are directed to the simulator.
3921    A target which only supports complete activation should push itself
3922 onto the stack in its `to_open' routine (by calling `push_target'), and
3923 unpush itself from the stack in its `to_mourn_inferior' routine (by
3924 calling `unpush_target').
3926    A target which supports both partial and complete activation should
3927 still call `push_target' in `to_open', but not call `unpush_target' in
3928 `to_mourn_inferior'.  Instead, it should call either
3929 `target_mark_running' or `target_mark_exited' in its `to_open',
3930 depending on whether the target is fully active after connection.  It
3931 should also call `target_mark_running' any time the inferior becomes
3932 fully active (e.g. in `to_create_inferior' and `to_attach'), and
3933 `target_mark_exited' when the inferior becomes inactive (in
3934 `to_mourn_inferior').  The target should also make sure to call
3935 `target_mourn_inferior' from its `to_kill', to return the target to
3936 inactive state.
3938 \x1f
3939 File: gdbint.info,  Node: Existing Targets,  Prev: Managing Execution State,  Up: Target Vector Definition
3941 11.2 Existing Targets
3942 =====================
3944 11.2.1 File Targets
3945 -------------------
3947 Both executables and core files have target vectors.
3949 11.2.2 Standard Protocol and Remote Stubs
3950 -----------------------------------------
3952 GDB's file `remote.c' talks a serial protocol to code that runs in the
3953 target system.  GDB provides several sample "stubs" that can be
3954 integrated into target programs or operating systems for this purpose;
3955 they are named `*-stub.c'.
3957    The GDB user's manual describes how to put such a stub into your
3958 target code.  What follows is a discussion of integrating the SPARC
3959 stub into a complicated operating system (rather than a simple
3960 program), by Stu Grossman, the author of this stub.
3962    The trap handling code in the stub assumes the following upon entry
3963 to `trap_low':
3965   1. %l1 and %l2 contain pc and npc respectively at the time of the
3966      trap;
3968   2. traps are disabled;
3970   3. you are in the correct trap window.
3972    As long as your trap handler can guarantee those conditions, then
3973 there is no reason why you shouldn't be able to "share" traps with the
3974 stub.  The stub has no requirement that it be jumped to directly from
3975 the hardware trap vector.  That is why it calls `exceptionHandler()',
3976 which is provided by the external environment.  For instance, this could
3977 set up the hardware traps to actually execute code which calls the stub
3978 first, and then transfers to its own trap handler.
3980    For the most point, there probably won't be much of an issue with
3981 "sharing" traps, as the traps we use are usually not used by the kernel,
3982 and often indicate unrecoverable error conditions.  Anyway, this is all
3983 controlled by a table, and is trivial to modify.  The most important
3984 trap for us is for `ta 1'.  Without that, we can't single step or do
3985 breakpoints.  Everything else is unnecessary for the proper operation
3986 of the debugger/stub.
3988    From reading the stub, it's probably not obvious how breakpoints
3989 work.  They are simply done by deposit/examine operations from GDB.
3991 11.2.3 ROM Monitor Interface
3992 ----------------------------
3994 11.2.4 Custom Protocols
3995 -----------------------
3997 11.2.5 Transport Layer
3998 ----------------------
4000 11.2.6 Builtin Simulator
4001 ------------------------
4003 \x1f
4004 File: gdbint.info,  Node: Native Debugging,  Next: Support Libraries,  Prev: Target Vector Definition,  Up: Top
4006 12 Native Debugging
4007 *******************
4009 Several files control GDB's configuration for native support:
4011 `gdb/config/ARCH/XYZ.mh'
4012      Specifies Makefile fragments needed by a _native_ configuration on
4013      machine XYZ.  In particular, this lists the required
4014      native-dependent object files, by defining `NATDEPFILES=...'.
4015      Also specifies the header file which describes native support on
4016      XYZ, by defining `NAT_FILE= nm-XYZ.h'.  You can also define
4017      `NAT_CFLAGS', `NAT_ADD_FILES', `NAT_CLIBS', `NAT_CDEPS', etc.; see
4018      `Makefile.in'.
4020      _Maintainer's note: The `.mh' suffix is because this file
4021      originally contained `Makefile' fragments for hosting GDB on
4022      machine XYZ.  While the file is no longer used for this purpose,
4023      the `.mh' suffix remains.  Perhaps someone will eventually rename
4024      these fragments so that they have a `.mn' suffix._
4026 `gdb/config/ARCH/nm-XYZ.h'
4027      (`nm.h' is a link to this file, created by `configure').  Contains
4028      C macro definitions describing the native system environment, such
4029      as child process control and core file support.
4031 `gdb/XYZ-nat.c'
4032      Contains any miscellaneous C code required for this native support
4033      of this machine.  On some machines it doesn't exist at all.
4035    There are some "generic" versions of routines that can be used by
4036 various systems.  These can be customized in various ways by macros
4037 defined in your `nm-XYZ.h' file.  If these routines work for the XYZ
4038 host, you can just include the generic file's name (with `.o', not
4039 `.c') in `NATDEPFILES'.
4041    Otherwise, if your machine needs custom support routines, you will
4042 need to write routines that perform the same functions as the generic
4043 file.  Put them into `XYZ-nat.c', and put `XYZ-nat.o' into
4044 `NATDEPFILES'.
4046 `inftarg.c'
4047      This contains the _target_ops vector_ that supports Unix child
4048      processes on systems which use ptrace and wait to control the
4049      child.
4051 `procfs.c'
4052      This contains the _target_ops vector_ that supports Unix child
4053      processes on systems which use /proc to control the child.
4055 `fork-child.c'
4056      This does the low-level grunge that uses Unix system calls to do a
4057      "fork and exec" to start up a child process.
4059 `infptrace.c'
4060      This is the low level interface to inferior processes for systems
4061      using the Unix `ptrace' call in a vanilla way.
4063 12.1 Native core file Support
4064 =============================
4066 `core-aout.c::fetch_core_registers()'
4067      Support for reading registers out of a core file.  This routine
4068      calls `register_addr()', see below.  Now that BFD is used to read
4069      core files, virtually all machines should use `core-aout.c', and
4070      should just provide `fetch_core_registers' in `XYZ-nat.c' (or
4071      `REGISTER_U_ADDR' in `nm-XYZ.h').
4073 `core-aout.c::register_addr()'
4074      If your `nm-XYZ.h' file defines the macro `REGISTER_U_ADDR(addr,
4075      blockend, regno)', it should be defined to set `addr' to the
4076      offset within the `user' struct of GDB register number `regno'.
4077      `blockend' is the offset within the "upage" of `u.u_ar0'.  If
4078      `REGISTER_U_ADDR' is defined, `core-aout.c' will define the
4079      `register_addr()' function and use the macro in it.  If you do not
4080      define `REGISTER_U_ADDR', but you are using the standard
4081      `fetch_core_registers()', you will need to define your own version
4082      of `register_addr()', put it into your `XYZ-nat.c' file, and be
4083      sure `XYZ-nat.o' is in the `NATDEPFILES' list.  If you have your
4084      own `fetch_core_registers()', you may not need a separate
4085      `register_addr()'.  Many custom `fetch_core_registers()'
4086      implementations simply locate the registers themselves.
4088    When making GDB run native on a new operating system, to make it
4089 possible to debug core files, you will need to either write specific
4090 code for parsing your OS's core files, or customize `bfd/trad-core.c'.
4091 First, use whatever `#include' files your machine uses to define the
4092 struct of registers that is accessible (possibly in the u-area) in a
4093 core file (rather than `machine/reg.h'), and an include file that
4094 defines whatever header exists on a core file (e.g., the u-area or a
4095 `struct core').  Then modify `trad_unix_core_file_p' to use these
4096 values to set up the section information for the data segment, stack
4097 segment, any other segments in the core file (perhaps shared library
4098 contents or control information), "registers" segment, and if there are
4099 two discontiguous sets of registers (e.g., integer and float), the
4100 "reg2" segment.  This section information basically delimits areas in
4101 the core file in a standard way, which the section-reading routines in
4102 BFD know how to seek around in.
4104    Then back in GDB, you need a matching routine called
4105 `fetch_core_registers'.  If you can use the generic one, it's in
4106 `core-aout.c'; if not, it's in your `XYZ-nat.c' file.  It will be
4107 passed a char pointer to the entire "registers" segment, its length,
4108 and a zero; or a char pointer to the entire "regs2" segment, its
4109 length, and a 2.  The routine should suck out the supplied register
4110 values and install them into GDB's "registers" array.
4112    If your system uses `/proc' to control processes, and uses ELF
4113 format core files, then you may be able to use the same routines for
4114 reading the registers out of processes and out of core files.
4116 12.2 ptrace
4117 ===========
4119 12.3 /proc
4120 ==========
4122 12.4 win32
4123 ==========
4125 12.5 shared libraries
4126 =====================
4128 12.6 Native Conditionals
4129 ========================
4131 When GDB is configured and compiled, various macros are defined or left
4132 undefined, to control compilation when the host and target systems are
4133 the same.  These macros should be defined (or left undefined) in
4134 `nm-SYSTEM.h'.
4136 `CHILD_PREPARE_TO_STORE'
4137      If the machine stores all registers at once in the child process,
4138      then define this to ensure that all values are correct.  This
4139      usually entails a read from the child.
4141      [Note that this is incorrectly defined in `xm-SYSTEM.h' files
4142      currently.]
4144 `FETCH_INFERIOR_REGISTERS'
4145      Define this if the native-dependent code will provide its own
4146      routines `fetch_inferior_registers' and `store_inferior_registers'
4147      in `HOST-nat.c'.  If this symbol is _not_ defined, and
4148      `infptrace.c' is included in this configuration, the default
4149      routines in `infptrace.c' are used for these functions.
4151 `int gdbarch_fp0_regnum (GDBARCH)'
4152      This functions normally returns the number of the first floating
4153      point register, if the machine has such registers.  As such, it
4154      would appear only in target-specific code.  However, `/proc'
4155      support uses this to decide whether floats are in use on this
4156      target.
4158 `int gdbarch_get_longjmp_target (GDBARCH)'
4159      For most machines, this is a target-dependent parameter.  On the
4160      DECstation and the Iris, this is a native-dependent parameter,
4161      since `setjmp.h' is needed to define it.
4163      This function determines the target PC address that `longjmp' will
4164      jump to, assuming that we have just stopped at a longjmp
4165      breakpoint.  It takes a `CORE_ADDR *' as argument, and stores the
4166      target PC value through this pointer.  It examines the current
4167      state of the machine as needed.
4169 `I386_USE_GENERIC_WATCHPOINTS'
4170      An x86-based machine can define this to use the generic x86
4171      watchpoint support; see *Note I386_USE_GENERIC_WATCHPOINTS:
4172      Algorithms.
4174 `ONE_PROCESS_WRITETEXT'
4175      Define this to be able to, when a breakpoint insertion fails, warn
4176      the user that another process may be running with the same
4177      executable.
4179 `PROC_NAME_FMT'
4180      Defines the format for the name of a `/proc' device.  Should be
4181      defined in `nm.h' _only_ in order to override the default
4182      definition in `procfs.c'.
4184 `SOLIB_ADD (FILENAME, FROM_TTY, TARG, READSYMS)'
4185      Define this to expand into an expression that will cause the
4186      symbols in FILENAME to be added to GDB's symbol table. If READSYMS
4187      is zero symbols are not read but any necessary low level
4188      processing for FILENAME is still done.
4190 `SOLIB_CREATE_INFERIOR_HOOK'
4191      Define this to expand into any shared-library-relocation code that
4192      you want to be run just after the child process has been forked.
4194 `START_INFERIOR_TRAPS_EXPECTED'
4195      When starting an inferior, GDB normally expects to trap twice;
4196      once when the shell execs, and once when the program itself execs.
4197      If the actual number of traps is something other than 2, then
4198      define this macro to expand into the number expected.
4201 \x1f
4202 File: gdbint.info,  Node: Support Libraries,  Next: Coding,  Prev: Native Debugging,  Up: Top
4204 13 Support Libraries
4205 ********************
4207 13.1 BFD
4208 ========
4210 BFD provides support for GDB in several ways:
4212 _identifying executable and core files_
4213      BFD will identify a variety of file types, including a.out, coff,
4214      and several variants thereof, as well as several kinds of core
4215      files.
4217 _access to sections of files_
4218      BFD parses the file headers to determine the names, virtual
4219      addresses, sizes, and file locations of all the various named
4220      sections in files (such as the text section or the data section).
4221      GDB simply calls BFD to read or write section X at byte offset Y
4222      for length Z.
4224 _specialized core file support_
4225      BFD provides routines to determine the failing command name stored
4226      in a core file, the signal with which the program failed, and
4227      whether a core file matches (i.e. could be a core dump of) a
4228      particular executable file.
4230 _locating the symbol information_
4231      GDB uses an internal interface of BFD to determine where to find
4232      the symbol information in an executable file or symbol-file.  GDB
4233      itself handles the reading of symbols, since BFD does not
4234      "understand" debug symbols, but GDB uses BFD's cached information
4235      to find the symbols, string table, etc.
4237 13.2 opcodes
4238 ============
4240 The opcodes library provides GDB's disassembler.  (It's a separate
4241 library because it's also used in binutils, for `objdump').
4243 13.3 readline
4244 =============
4246 The `readline' library provides a set of functions for use by
4247 applications that allow users to edit command lines as they are typed
4250 13.4 libiberty
4251 ==============
4253 The `libiberty' library provides a set of functions and features that
4254 integrate and improve on functionality found in modern operating
4255 systems.  Broadly speaking, such features can be divided into three
4256 groups: supplemental functions (functions that may be missing in some
4257 environments and operating systems), replacement functions (providing a
4258 uniform and easier to use interface for commonly used standard
4259 functions), and extensions (which provide additional functionality
4260 beyond standard functions).
4262    GDB uses various features provided by the `libiberty' library, for
4263 instance the C++ demangler, the IEEE floating format support functions,
4264 the input options parser `getopt', the `obstack' extension, and other
4265 functions.
4267 13.4.1 `obstacks' in GDB
4268 ------------------------
4270 The obstack mechanism provides a convenient way to allocate and free
4271 chunks of memory.  Each obstack is a pool of memory that is managed
4272 like a stack.  Objects (of any nature, size and alignment) are
4273 allocated and freed in a LIFO fashion on an obstack (see `libiberty''s
4274 documentation for a more detailed explanation of `obstacks').
4276    The most noticeable use of the `obstacks' in GDB is in object files.
4277 There is an obstack associated with each internal representation of an
4278 object file.  Lots of things get allocated on these `obstacks':
4279 dictionary entries, blocks, blockvectors, symbols, minimal symbols,
4280 types, vectors of fundamental types, class fields of types, object
4281 files section lists, object files section offset lists, line tables,
4282 symbol tables, partial symbol tables, string tables, symbol table
4283 private data, macros tables, debug information sections and entries,
4284 import and export lists (som), unwind information (hppa), dwarf2
4285 location expressions data.  Plus various strings such as directory
4286 names strings, debug format strings, names of types.
4288    An essential and convenient property of all data on `obstacks' is
4289 that memory for it gets allocated (with `obstack_alloc') at various
4290 times during a debugging session, but it is released all at once using
4291 the `obstack_free' function.  The `obstack_free' function takes a
4292 pointer to where in the stack it must start the deletion from (much
4293 like the cleanup chains have a pointer to where to start the cleanups).
4294 Because of the stack like structure of the `obstacks', this allows to
4295 free only a top portion of the obstack.  There are a few instances in
4296 GDB where such thing happens.  Calls to `obstack_free' are done after
4297 some local data is allocated to the obstack.  Only the local data is
4298 deleted from the obstack.  Of course this assumes that nothing between
4299 the `obstack_alloc' and the `obstack_free' allocates anything else on
4300 the same obstack.  For this reason it is best and safest to use
4301 temporary `obstacks'.
4303    Releasing the whole obstack is also not safe per se.  It is safe only
4304 under the condition that we know the `obstacks' memory is no longer
4305 needed.  In GDB we get rid of the `obstacks' only when we get rid of
4306 the whole objfile(s), for instance upon reading a new symbol file.
4308 13.5 gnu-regex
4309 ==============
4311 Regex conditionals.
4313 `C_ALLOCA'
4315 `NFAILURES'
4317 `RE_NREGS'
4319 `SIGN_EXTEND_CHAR'
4321 `SWITCH_ENUM_BUG'
4323 `SYNTAX_TABLE'
4325 `Sword'
4327 `sparc'
4329 13.6 Array Containers
4330 =====================
4332 Often it is necessary to manipulate a dynamic array of a set of
4333 objects.  C forces some bookkeeping on this, which can get cumbersome
4334 and repetitive.  The `vec.h' file contains macros for defining and
4335 using a typesafe vector type.  The functions defined will be inlined
4336 when compiling, and so the abstraction cost should be zero.  Domain
4337 checks are added to detect programming errors.
4339    An example use would be an array of symbols or section information.
4340 The array can be grown as symbols are read in (or preallocated), and
4341 the accessor macros provided keep care of all the necessary
4342 bookkeeping.  Because the arrays are type safe, there is no danger of
4343 accidentally mixing up the contents.  Think of these as C++ templates,
4344 but implemented in C.
4346    Because of the different behavior of structure objects, scalar
4347 objects and of pointers, there are three flavors of vector, one for
4348 each of these variants.  Both the structure object and pointer variants
4349 pass pointers to objects around -- in the former case the pointers are
4350 stored into the vector and in the latter case the pointers are
4351 dereferenced and the objects copied into the vector.  The scalar object
4352 variant is suitable for `int'-like objects, and the vector elements are
4353 returned by value.
4355    There are both `index' and `iterate' accessors.  The iterator
4356 returns a boolean iteration condition and updates the iteration
4357 variable passed by reference.  Because the iterator will be inlined,
4358 the address-of can be optimized away.
4360    The vectors are implemented using the trailing array idiom, thus they
4361 are not resizeable without changing the address of the vector object
4362 itself.  This means you cannot have variables or fields of vector type
4363 -- always use a pointer to a vector.  The one exception is the final
4364 field of a structure, which could be a vector type.  You will have to
4365 use the `embedded_size' & `embedded_init' calls to create such objects,
4366 and they will probably not be resizeable (so don't use the "safe"
4367 allocation variants).  The trailing array idiom is used (rather than a
4368 pointer to an array of data), because, if we allow `NULL' to also
4369 represent an empty vector, empty vectors occupy minimal space in the
4370 structure containing them.
4372    Each operation that increases the number of active elements is
4373 available in "quick" and "safe" variants.  The former presumes that
4374 there is sufficient allocated space for the operation to succeed (it
4375 dies if there is not).  The latter will reallocate the vector, if
4376 needed.  Reallocation causes an exponential increase in vector size.
4377 If you know you will be adding N elements, it would be more efficient
4378 to use the reserve operation before adding the elements with the
4379 "quick" operation.  This will ensure there are at least as many
4380 elements as you ask for, it will exponentially increase if there are
4381 too few spare slots.  If you want reserve a specific number of slots,
4382 but do not want the exponential increase (for instance, you know this
4383 is the last allocation), use a negative number for reservation.  You
4384 can also create a vector of a specific size from the get go.
4386    You should prefer the push and pop operations, as they append and
4387 remove from the end of the vector. If you need to remove several items
4388 in one go, use the truncate operation.  The insert and remove
4389 operations allow you to change elements in the middle of the vector.
4390 There are two remove operations, one which preserves the element
4391 ordering `ordered_remove', and one which does not `unordered_remove'.
4392 The latter function copies the end element into the removed slot,
4393 rather than invoke a memmove operation.  The `lower_bound' function
4394 will determine where to place an item in the array using insert that
4395 will maintain sorted order.
4397    If you need to directly manipulate a vector, then the `address'
4398 accessor will return the address of the start of the vector.  Also the
4399 `space' predicate will tell you whether there is spare capacity in the
4400 vector.  You will not normally need to use these two functions.
4402    Vector types are defined using a `DEF_VEC_{O,P,I}(TYPENAME)' macro.
4403 Variables of vector type are declared using a `VEC(TYPENAME)' macro.
4404 The characters `O', `P' and `I' indicate whether TYPENAME is an object
4405 (`O'), pointer (`P') or integral (`I') type.  Be careful to pick the
4406 correct one, as you'll get an awkward and inefficient API if you use
4407 the wrong one.  There is a check, which results in a compile-time
4408 warning, for the `P' and `I' versions, but there is no check for the
4409 `O' versions, as that is not possible in plain C.
4411    An example of their use would be,
4413      DEF_VEC_P(tree);   // non-managed tree vector.
4415      struct my_struct {
4416        VEC(tree) *v;      // A (pointer to) a vector of tree pointers.
4417      };
4419      struct my_struct *s;
4421      if (VEC_length(tree, s->v)) { we have some contents }
4422      VEC_safe_push(tree, s->v, decl); // append some decl onto the end
4423      for (ix = 0; VEC_iterate(tree, s->v, ix, elt); ix++)
4424        { do something with elt }
4426    The `vec.h' file provides details on how to invoke the various
4427 accessors provided.  They are enumerated here:
4429 `VEC_length'
4430      Return the number of items in the array,
4432 `VEC_empty'
4433      Return true if the array has no elements.
4435 `VEC_last'
4436 `VEC_index'
4437      Return the last or arbitrary item in the array.
4439 `VEC_iterate'
4440      Access an array element and indicate whether the array has been
4441      traversed.
4443 `VEC_alloc'
4444 `VEC_free'
4445      Create and destroy an array.
4447 `VEC_embedded_size'
4448 `VEC_embedded_init'
4449      Helpers for embedding an array as the final element of another
4450      struct.
4452 `VEC_copy'
4453      Duplicate an array.
4455 `VEC_space'
4456      Return the amount of free space in an array.
4458 `VEC_reserve'
4459      Ensure a certain amount of free space.
4461 `VEC_quick_push'
4462 `VEC_safe_push'
4463      Append to an array, either assuming the space is available, or
4464      making sure that it is.
4466 `VEC_pop'
4467      Remove the last item from an array.
4469 `VEC_truncate'
4470      Remove several items from the end of an array.
4472 `VEC_safe_grow'
4473      Add several items to the end of an array.
4475 `VEC_replace'
4476      Overwrite an item in the array.
4478 `VEC_quick_insert'
4479 `VEC_safe_insert'
4480      Insert an item into the middle of the array.  Either the space must
4481      already exist, or the space is created.
4483 `VEC_ordered_remove'
4484 `VEC_unordered_remove'
4485      Remove an item from the array, preserving order or not.
4487 `VEC_block_remove'
4488      Remove a set of items from the array.
4490 `VEC_address'
4491      Provide the address of the first element.
4493 `VEC_lower_bound'
4494      Binary search the array.
4497 13.7 include
4498 ============
4500 \x1f
4501 File: gdbint.info,  Node: Coding,  Next: Porting GDB,  Prev: Support Libraries,  Up: Top
4503 14 Coding
4504 *********
4506 This chapter covers topics that are lower-level than the major
4507 algorithms of GDB.
4509 14.1 Cleanups
4510 =============
4512 Cleanups are a structured way to deal with things that need to be done
4513 later.
4515    When your code does something (e.g., `xmalloc' some memory, or
4516 `open' a file) that needs to be undone later (e.g., `xfree' the memory
4517 or `close' the file), it can make a cleanup.  The cleanup will be done
4518 at some future point: when the command is finished and control returns
4519 to the top level; when an error occurs and the stack is unwound; or
4520 when your code decides it's time to explicitly perform cleanups.
4521 Alternatively you can elect to discard the cleanups you created.
4523    Syntax:
4525 `struct cleanup *OLD_CHAIN;'
4526      Declare a variable which will hold a cleanup chain handle.
4528 `OLD_CHAIN = make_cleanup (FUNCTION, ARG);'
4529      Make a cleanup which will cause FUNCTION to be called with ARG (a
4530      `char *') later.  The result, OLD_CHAIN, is a handle that can
4531      later be passed to `do_cleanups' or `discard_cleanups'.  Unless
4532      you are going to call `do_cleanups' or `discard_cleanups', you can
4533      ignore the result from `make_cleanup'.
4535 `do_cleanups (OLD_CHAIN);'
4536      Do all cleanups added to the chain since the corresponding
4537      `make_cleanup' call was made.
4539 `discard_cleanups (OLD_CHAIN);'
4540      Same as `do_cleanups' except that it just removes the cleanups from
4541      the chain and does not call the specified functions.
4543    Cleanups are implemented as a chain.  The handle returned by
4544 `make_cleanups' includes the cleanup passed to the call and any later
4545 cleanups appended to the chain (but not yet discarded or performed).
4546 E.g.:
4548      make_cleanup (a, 0);
4549      {
4550        struct cleanup *old = make_cleanup (b, 0);
4551        make_cleanup (c, 0)
4552        ...
4553        do_cleanups (old);
4554      }
4556 will call `c()' and `b()' but will not call `a()'.  The cleanup that
4557 calls `a()' will remain in the cleanup chain, and will be done later
4558 unless otherwise discarded.
4560    Your function should explicitly do or discard the cleanups it
4561 creates.  Failing to do this leads to non-deterministic behavior since
4562 the caller will arbitrarily do or discard your functions cleanups.
4563 This need leads to two common cleanup styles.
4565    The first style is try/finally.  Before it exits, your code-block
4566 calls `do_cleanups' with the old cleanup chain and thus ensures that
4567 your code-block's cleanups are always performed.  For instance, the
4568 following code-segment avoids a memory leak problem (even when `error'
4569 is called and a forced stack unwind occurs) by ensuring that the
4570 `xfree' will always be called:
4572      struct cleanup *old = make_cleanup (null_cleanup, 0);
4573      data = xmalloc (sizeof blah);
4574      make_cleanup (xfree, data);
4575      ... blah blah ...
4576      do_cleanups (old);
4578    The second style is try/except.  Before it exits, your code-block
4579 calls `discard_cleanups' with the old cleanup chain and thus ensures
4580 that any created cleanups are not performed.  For instance, the
4581 following code segment, ensures that the file will be closed but only
4582 if there is an error:
4584      FILE *file = fopen ("afile", "r");
4585      struct cleanup *old = make_cleanup (close_file, file);
4586      ... blah blah ...
4587      discard_cleanups (old);
4588      return file;
4590    Some functions, e.g., `fputs_filtered()' or `error()', specify that
4591 they "should not be called when cleanups are not in place".  This means
4592 that any actions you need to reverse in the case of an error or
4593 interruption must be on the cleanup chain before you call these
4594 functions, since they might never return to your code (they `longjmp'
4595 instead).
4597 14.2 Per-architecture module data
4598 =================================
4600 The multi-arch framework includes a mechanism for adding module
4601 specific per-architecture data-pointers to the `struct gdbarch'
4602 architecture object.
4604    A module registers one or more per-architecture data-pointers using:
4606  -- Function: struct gdbarch_data *gdbarch_data_register_pre_init
4607           (gdbarch_data_pre_init_ftype *PRE_INIT)
4608      PRE_INIT is used to, on-demand, allocate an initial value for a
4609      per-architecture data-pointer using the architecture's obstack
4610      (passed in as a parameter).  Since PRE_INIT can be called during
4611      architecture creation, it is not parameterized with the
4612      architecture.  and must not call modules that use per-architecture
4613      data.
4615  -- Function: struct gdbarch_data *gdbarch_data_register_post_init
4616           (gdbarch_data_post_init_ftype *POST_INIT)
4617      POST_INIT is used to obtain an initial value for a
4618      per-architecture data-pointer _after_.  Since POST_INIT is always
4619      called after architecture creation, it both receives the fully
4620      initialized architecture and is free to call modules that use
4621      per-architecture data (care needs to be taken to ensure that those
4622      other modules do not try to call back to this module as that will
4623      create in cycles in the initialization call graph).
4625    These functions return a `struct gdbarch_data' that is used to
4626 identify the per-architecture data-pointer added for that module.
4628    The per-architecture data-pointer is accessed using the function:
4630  -- Function: void *gdbarch_data (struct gdbarch *GDBARCH, struct
4631           gdbarch_data *DATA_HANDLE)
4632      Given the architecture ARCH and module data handle DATA_HANDLE
4633      (returned by `gdbarch_data_register_pre_init' or
4634      `gdbarch_data_register_post_init'), this function returns the
4635      current value of the per-architecture data-pointer.  If the data
4636      pointer is `NULL', it is first initialized by calling the
4637      corresponding PRE_INIT or POST_INIT method.
4639    The examples below assume the following definitions:
4641      struct nozel { int total; };
4642      static struct gdbarch_data *nozel_handle;
4644    A module can extend the architecture vector, adding additional
4645 per-architecture data, using the PRE_INIT method.  The module's
4646 per-architecture data is then initialized during architecture creation.
4648    In the below, the module's per-architecture _nozel_ is added.  An
4649 architecture can specify its nozel by calling `set_gdbarch_nozel' from
4650 `gdbarch_init'.
4652      static void *
4653      nozel_pre_init (struct obstack *obstack)
4654      {
4655        struct nozel *data = OBSTACK_ZALLOC (obstack, struct nozel);
4656        return data;
4657      }
4659      extern void
4660      set_gdbarch_nozel (struct gdbarch *gdbarch, int total)
4661      {
4662        struct nozel *data = gdbarch_data (gdbarch, nozel_handle);
4663        data->total = nozel;
4664      }
4666    A module can on-demand create architecture dependant data structures
4667 using `post_init'.
4669    In the below, the nozel's total is computed on-demand by
4670 `nozel_post_init' using information obtained from the architecture.
4672      static void *
4673      nozel_post_init (struct gdbarch *gdbarch)
4674      {
4675        struct nozel *data = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct nozel);
4676        nozel->total = gdbarch... (gdbarch);
4677        return data;
4678      }
4680      extern int
4681      nozel_total (struct gdbarch *gdbarch)
4682      {
4683        struct nozel *data = gdbarch_data (gdbarch, nozel_handle);
4684        return data->total;
4685      }
4687 14.3 Wrapping Output Lines
4688 ==========================
4690 Output that goes through `printf_filtered' or `fputs_filtered' or
4691 `fputs_demangled' needs only to have calls to `wrap_here' added in
4692 places that would be good breaking points.  The utility routines will
4693 take care of actually wrapping if the line width is exceeded.
4695    The argument to `wrap_here' is an indentation string which is
4696 printed _only_ if the line breaks there.  This argument is saved away
4697 and used later.  It must remain valid until the next call to
4698 `wrap_here' or until a newline has been printed through the
4699 `*_filtered' functions.  Don't pass in a local variable and then return!
4701    It is usually best to call `wrap_here' after printing a comma or
4702 space.  If you call it before printing a space, make sure that your
4703 indentation properly accounts for the leading space that will print if
4704 the line wraps there.
4706    Any function or set of functions that produce filtered output must
4707 finish by printing a newline, to flush the wrap buffer, before switching
4708 to unfiltered (`printf') output.  Symbol reading routines that print
4709 warnings are a good example.
4711 14.4 GDB Coding Standards
4712 =========================
4714 GDB follows the GNU coding standards, as described in
4715 `etc/standards.texi'.  This file is also available for anonymous FTP
4716 from GNU archive sites.  GDB takes a strict interpretation of the
4717 standard; in general, when the GNU standard recommends a practice but
4718 does not require it, GDB requires it.
4720    GDB follows an additional set of coding standards specific to GDB,
4721 as described in the following sections.
4723 14.4.1 ISO C
4724 ------------
4726 GDB assumes an ISO/IEC 9899:1990 (a.k.a. ISO C90) compliant compiler.
4728    GDB does not assume an ISO C or POSIX compliant C library.
4730 14.4.2 Memory Management
4731 ------------------------
4733 GDB does not use the functions `malloc', `realloc', `calloc', `free'
4734 and `asprintf'.
4736    GDB uses the functions `xmalloc', `xrealloc' and `xcalloc' when
4737 allocating memory.  Unlike `malloc' et.al.  these functions do not
4738 return when the memory pool is empty.  Instead, they unwind the stack
4739 using cleanups.  These functions return `NULL' when requested to
4740 allocate a chunk of memory of size zero.
4742    _Pragmatics: By using these functions, the need to check every
4743 memory allocation is removed.  These functions provide portable
4744 behavior._
4746    GDB does not use the function `free'.
4748    GDB uses the function `xfree' to return memory to the memory pool.
4749 Consistent with ISO-C, this function ignores a request to free a `NULL'
4750 pointer.
4752    _Pragmatics: On some systems `free' fails when passed a `NULL'
4753 pointer._
4755    GDB can use the non-portable function `alloca' for the allocation of
4756 small temporary values (such as strings).
4758    _Pragmatics: This function is very non-portable.  Some systems
4759 restrict the memory being allocated to no more than a few kilobytes._
4761    GDB uses the string function `xstrdup' and the print function
4762 `xstrprintf'.
4764    _Pragmatics: `asprintf' and `strdup' can fail.  Print functions such
4765 as `sprintf' are very prone to buffer overflow errors._
4767 14.4.3 Compiler Warnings
4768 ------------------------
4770 With few exceptions, developers should avoid the configuration option
4771 `--disable-werror' when building GDB.  The exceptions are listed in the
4772 file `gdb/MAINTAINERS'.  The default, when building with GCC, is
4773 `--enable-werror'.
4775    This option causes GDB (when built using GCC) to be compiled with a
4776 carefully selected list of compiler warning flags.  Any warnings from
4777 those flags are treated as errors.
4779    The current list of warning flags includes:
4781 `-Wall'
4782      Recommended GCC warnings.
4784 `-Wdeclaration-after-statement'
4785      GCC 3.x (and later) and C99 allow declarations mixed with code,
4786      but GCC 2.x and C89 do not.
4788 `-Wpointer-arith'
4790 `-Wformat-nonliteral'
4791      Non-literal format strings, with a few exceptions, are bugs - they
4792      might contain unintended user-supplied format specifiers.  Since
4793      GDB uses the `format printf' attribute on all `printf' like
4794      functions this checks not just `printf' calls but also calls to
4795      functions such as `fprintf_unfiltered'.
4797 `-Wno-pointer-sign'
4798      In version 4.0, GCC began warning about pointer argument passing or
4799      assignment even when the source and destination differed only in
4800      signedness.  However, most GDB code doesn't distinguish carefully
4801      between `char' and `unsigned char'.  In early 2006 the GDB
4802      developers decided correcting these warnings wasn't worth the time
4803      it would take.
4805 `-Wno-unused-parameter'
4806      Due to the way that GDB is implemented many functions have unused
4807      parameters.  Consequently this warning is avoided.  The macro
4808      `ATTRIBUTE_UNUSED' is not used as it leads to false negatives --
4809      it is not an error to have `ATTRIBUTE_UNUSED' on a parameter that
4810      is being used.
4812 `-Wno-unused'
4813 `-Wno-switch'
4814 `-Wno-char-subscripts'
4815      These are warnings which might be useful for GDB, but are
4816      currently too noisy to enable with `-Werror'.
4819 14.4.4 Formatting
4820 -----------------
4822 The standard GNU recommendations for formatting must be followed
4823 strictly.
4825    A function declaration should not have its name in column zero.  A
4826 function definition should have its name in column zero.
4828      /* Declaration */
4829      static void foo (void);
4830      /* Definition */
4831      void
4832      foo (void)
4833      {
4834      }
4836    _Pragmatics: This simplifies scripting.  Function definitions can be
4837 found using `^function-name'._
4839    There must be a space between a function or macro name and the
4840 opening parenthesis of its argument list (except for macro definitions,
4841 as required by C).  There must not be a space after an open
4842 paren/bracket or before a close paren/bracket.
4844    While additional whitespace is generally helpful for reading, do not
4845 use more than one blank line to separate blocks, and avoid adding
4846 whitespace after the end of a program line (as of 1/99, some 600 lines
4847 had whitespace after the semicolon).  Excess whitespace causes
4848 difficulties for `diff' and `patch' utilities.
4850    Pointers are declared using the traditional K&R C style:
4852      void *foo;
4854 and not:
4856      void * foo;
4857      void* foo;
4859 14.4.5 Comments
4860 ---------------
4862 The standard GNU requirements on comments must be followed strictly.
4864    Block comments must appear in the following form, with no `/*'- or
4865 `*/'-only lines, and no leading `*':
4867      /* Wait for control to return from inferior to debugger.  If inferior
4868         gets a signal, we may decide to start it up again instead of
4869         returning.  That is why there is a loop in this function.  When
4870         this function actually returns it means the inferior should be left
4871         stopped and GDB should read more commands.  */
4873    (Note that this format is encouraged by Emacs; tabbing for a
4874 multi-line comment works correctly, and `M-q' fills the block
4875 consistently.)
4877    Put a blank line between the block comments preceding function or
4878 variable definitions, and the definition itself.
4880    In general, put function-body comments on lines by themselves, rather
4881 than trying to fit them into the 20 characters left at the end of a
4882 line, since either the comment or the code will inevitably get longer
4883 than will fit, and then somebody will have to move it anyhow.
4885 14.4.6 C Usage
4886 --------------
4888 Code must not depend on the sizes of C data types, the format of the
4889 host's floating point numbers, the alignment of anything, or the order
4890 of evaluation of expressions.
4892    Use functions freely.  There are only a handful of compute-bound
4893 areas in GDB that might be affected by the overhead of a function call,
4894 mainly in symbol reading.  Most of GDB's performance is limited by the
4895 target interface (whether serial line or system call).
4897    However, use functions with moderation.  A thousand one-line
4898 functions are just as hard to understand as a single thousand-line
4899 function.
4901    _Macros are bad, M'kay._ (But if you have to use a macro, make sure
4902 that the macro arguments are protected with parentheses.)
4904    Declarations like `struct foo *' should be used in preference to
4905 declarations like `typedef struct foo { ... } *foo_ptr'.
4907 14.4.7 Function Prototypes
4908 --------------------------
4910 Prototypes must be used when both _declaring_ and _defining_ a
4911 function.  Prototypes for GDB functions must include both the argument
4912 type and name, with the name matching that used in the actual function
4913 definition.
4915    All external functions should have a declaration in a header file
4916 that callers include, except for `_initialize_*' functions, which must
4917 be external so that `init.c' construction works, but shouldn't be
4918 visible to random source files.
4920    Where a source file needs a forward declaration of a static function,
4921 that declaration must appear in a block near the top of the source file.
4923 14.4.8 Internal Error Recovery
4924 ------------------------------
4926 During its execution, GDB can encounter two types of errors.  User
4927 errors and internal errors.  User errors include not only a user
4928 entering an incorrect command but also problems arising from corrupt
4929 object files and system errors when interacting with the target.
4930 Internal errors include situations where GDB has detected, at run time,
4931 a corrupt or erroneous situation.
4933    When reporting an internal error, GDB uses `internal_error' and
4934 `gdb_assert'.
4936    GDB must not call `abort' or `assert'.
4938    _Pragmatics: There is no `internal_warning' function.  Either the
4939 code detected a user error, recovered from it and issued a `warning' or
4940 the code failed to correctly recover from the user error and issued an
4941 `internal_error'._
4943 14.4.9 File Names
4944 -----------------
4946 Any file used when building the core of GDB must be in lower case. Any
4947 file used when building the core of GDB must be 8.3 unique.  These
4948 requirements apply to both source and generated files.
4950    _Pragmatics: The core of GDB must be buildable on many platforms
4951 including DJGPP and MacOS/HFS.  Every time an unfriendly file is
4952 introduced to the build process both `Makefile.in' and `configure.in'
4953 need to be modified accordingly.  Compare the convoluted conversion
4954 process needed to transform `COPYING' into `copying.c' with the
4955 conversion needed to transform `version.in' into `version.c'._
4957    Any file non 8.3 compliant file (that is not used when building the
4958 core of GDB) must be added to `gdb/config/djgpp/fnchange.lst'.
4960    _Pragmatics: This is clearly a compromise._
4962    When GDB has a local version of a system header file (ex `string.h')
4963 the file name based on the POSIX header prefixed with `gdb_'
4964 (`gdb_string.h').  These headers should be relatively independent: they
4965 should use only macros defined by `configure', the compiler, or the
4966 host; they should include only system headers; they should refer only
4967 to system types.  They may be shared between multiple programs, e.g.
4968 GDB and GDBSERVER.
4970    For other files `-' is used as the separator.
4972 14.4.10 Include Files
4973 ---------------------
4975 A `.c' file should include `defs.h' first.
4977    A `.c' file should directly include the `.h' file of every
4978 declaration and/or definition it directly refers to.  It cannot rely on
4979 indirect inclusion.
4981    A `.h' file should directly include the `.h' file of every
4982 declaration and/or definition it directly refers to.  It cannot rely on
4983 indirect inclusion.  Exception: The file `defs.h' does not need to be
4984 directly included.
4986    An external declaration should only appear in one include file.
4988    An external declaration should never appear in a `.c' file.
4989 Exception: a declaration for the `_initialize' function that pacifies
4990 `-Wmissing-declaration'.
4992    A `typedef' definition should only appear in one include file.
4994    An opaque `struct' declaration can appear in multiple `.h' files.
4995 Where possible, a `.h' file should use an opaque `struct' declaration
4996 instead of an include.
4998    All `.h' files should be wrapped in:
5000      #ifndef INCLUDE_FILE_NAME_H
5001      #define INCLUDE_FILE_NAME_H
5002      header body
5003      #endif
5005 14.4.11 Clean Design and Portable Implementation
5006 ------------------------------------------------
5008 In addition to getting the syntax right, there's the little question of
5009 semantics.  Some things are done in certain ways in GDB because long
5010 experience has shown that the more obvious ways caused various kinds of
5011 trouble.
5013    You can't assume the byte order of anything that comes from a target
5014 (including VALUEs, object files, and instructions).  Such things must
5015 be byte-swapped using `SWAP_TARGET_AND_HOST' in GDB, or one of the swap
5016 routines defined in `bfd.h', such as `bfd_get_32'.
5018    You can't assume that you know what interface is being used to talk
5019 to the target system.  All references to the target must go through the
5020 current `target_ops' vector.
5022    You can't assume that the host and target machines are the same
5023 machine (except in the "native" support modules).  In particular, you
5024 can't assume that the target machine's header files will be available
5025 on the host machine.  Target code must bring along its own header files
5026 - written from scratch or explicitly donated by their owner, to avoid
5027 copyright problems.
5029    Insertion of new `#ifdef''s will be frowned upon.  It's much better
5030 to write the code portably than to conditionalize it for various
5031 systems.
5033    New `#ifdef''s which test for specific compilers or manufacturers or
5034 operating systems are unacceptable.  All `#ifdef''s should test for
5035 features.  The information about which configurations contain which
5036 features should be segregated into the configuration files.  Experience
5037 has proven far too often that a feature unique to one particular system
5038 often creeps into other systems; and that a conditional based on some
5039 predefined macro for your current system will become worthless over
5040 time, as new versions of your system come out that behave differently
5041 with regard to this feature.
5043    Adding code that handles specific architectures, operating systems,
5044 target interfaces, or hosts, is not acceptable in generic code.
5046    One particularly notorious area where system dependencies tend to
5047 creep in is handling of file names.  The mainline GDB code assumes
5048 Posix semantics of file names: absolute file names begin with a forward
5049 slash `/', slashes are used to separate leading directories,
5050 case-sensitive file names.  These assumptions are not necessarily true
5051 on non-Posix systems such as MS-Windows.  To avoid system-dependent
5052 code where you need to take apart or construct a file name, use the
5053 following portable macros:
5055 `HAVE_DOS_BASED_FILE_SYSTEM'
5056      This preprocessing symbol is defined to a non-zero value on hosts
5057      whose filesystems belong to the MS-DOS/MS-Windows family.  Use this
5058      symbol to write conditional code which should only be compiled for
5059      such hosts.
5061 `IS_DIR_SEPARATOR (C)'
5062      Evaluates to a non-zero value if C is a directory separator
5063      character.  On Unix and GNU/Linux systems, only a slash `/' is
5064      such a character, but on Windows, both `/' and `\' will pass.
5066 `IS_ABSOLUTE_PATH (FILE)'
5067      Evaluates to a non-zero value if FILE is an absolute file name.
5068      For Unix and GNU/Linux hosts, a name which begins with a slash `/'
5069      is absolute.  On DOS and Windows, `d:/foo' and `x:\bar' are also
5070      absolute file names.
5072 `FILENAME_CMP (F1, F2)'
5073      Calls a function which compares file names F1 and F2 as
5074      appropriate for the underlying host filesystem.  For Posix systems,
5075      this simply calls `strcmp'; on case-insensitive filesystems it
5076      will call `strcasecmp' instead.
5078 `DIRNAME_SEPARATOR'
5079      Evaluates to a character which separates directories in
5080      `PATH'-style lists, typically held in environment variables.  This
5081      character is `:' on Unix, `;' on DOS and Windows.
5083 `SLASH_STRING'
5084      This evaluates to a constant string you should use to produce an
5085      absolute filename from leading directories and the file's basename.
5086      `SLASH_STRING' is `"/"' on most systems, but might be `"\\"' for
5087      some Windows-based ports.
5089    In addition to using these macros, be sure to use portable library
5090 functions whenever possible.  For example, to extract a directory or a
5091 basename part from a file name, use the `dirname' and `basename'
5092 library functions (available in `libiberty' for platforms which don't
5093 provide them), instead of searching for a slash with `strrchr'.
5095    Another way to generalize GDB along a particular interface is with an
5096 attribute struct.  For example, GDB has been generalized to handle
5097 multiple kinds of remote interfaces--not by `#ifdef's everywhere, but
5098 by defining the `target_ops' structure and having a current target (as
5099 well as a stack of targets below it, for memory references).  Whenever
5100 something needs to be done that depends on which remote interface we are
5101 using, a flag in the current target_ops structure is tested (e.g.,
5102 `target_has_stack'), or a function is called through a pointer in the
5103 current target_ops structure.  In this way, when a new remote interface
5104 is added, only one module needs to be touched--the one that actually
5105 implements the new remote interface.  Other examples of
5106 attribute-structs are BFD access to multiple kinds of object file
5107 formats, or GDB's access to multiple source languages.
5109    Please avoid duplicating code.  For example, in GDB 3.x all the code
5110 interfacing between `ptrace' and the rest of GDB was duplicated in
5111 `*-dep.c', and so changing something was very painful.  In GDB 4.x,
5112 these have all been consolidated into `infptrace.c'.  `infptrace.c' can
5113 deal with variations between systems the same way any system-independent
5114 file would (hooks, `#if defined', etc.), and machines which are
5115 radically different don't need to use `infptrace.c' at all.
5117    All debugging code must be controllable using the `set debug MODULE'
5118 command.  Do not use `printf' to print trace messages.  Use
5119 `fprintf_unfiltered(gdb_stdlog, ...'.  Do not use `#ifdef DEBUG'.
5121 \x1f
5122 File: gdbint.info,  Node: Porting GDB,  Next: Versions and Branches,  Prev: Coding,  Up: Top
5124 15 Porting GDB
5125 **************
5127 Most of the work in making GDB compile on a new machine is in
5128 specifying the configuration of the machine.  This is done in a
5129 dizzying variety of header files and configuration scripts, which we
5130 hope to make more sensible soon.  Let's say your new host is called an
5131 XYZ (e.g.,  `sun4'), and its full three-part configuration name is
5132 `ARCH-XVEND-XOS' (e.g., `sparc-sun-sunos4').  In particular:
5134    * In the top level directory, edit `config.sub' and add ARCH, XVEND,
5135      and XOS to the lists of supported architectures, vendors, and
5136      operating systems near the bottom of the file.  Also, add XYZ as
5137      an alias that maps to `ARCH-XVEND-XOS'.  You can test your changes
5138      by running
5140           ./config.sub XYZ
5142      and
5144           ./config.sub `ARCH-XVEND-XOS'
5146      which should both respond with `ARCH-XVEND-XOS' and no error
5147      messages.
5149      You need to port BFD, if that hasn't been done already.  Porting
5150      BFD is beyond the scope of this manual.
5152    * To configure GDB itself, edit `gdb/configure.host' to recognize
5153      your system and set `gdb_host' to XYZ, and (unless your desired
5154      target is already available) also edit `gdb/configure.tgt',
5155      setting `gdb_target' to something appropriate (for instance, XYZ).
5157      _Maintainer's note: Work in progress.  The file
5158      `gdb/configure.host' originally needed to be modified when either a
5159      new native target or a new host machine was being added to GDB.
5160      Recent changes have removed this requirement.  The file now only
5161      needs to be modified when adding a new native configuration.  This
5162      will likely changed again in the future._
5164    * Finally, you'll need to specify and define GDB's host-, native-,
5165      and target-dependent `.h' and `.c' files used for your
5166      configuration.
5168 \x1f
5169 File: gdbint.info,  Node: Versions and Branches,  Next: Start of New Year Procedure,  Prev: Porting GDB,  Up: Top
5171 16 Versions and Branches
5172 ************************
5174 16.1 Versions
5175 =============
5177 GDB's version is determined by the file `gdb/version.in' and takes one
5178 of the following forms:
5180 MAJOR.MINOR
5181 MAJOR.MINOR.PATCHLEVEL
5182      an official release (e.g., 6.2 or 6.2.1)
5184 MAJOR.MINOR.PATCHLEVEL.YYYYMMDD
5185      a snapshot taken at YYYY-MM-DD-gmt (e.g., 6.1.50.20020302,
5186      6.1.90.20020304, or 6.1.0.20020308)
5188 MAJOR.MINOR.PATCHLEVEL.YYYYMMDD-cvs
5189      a CVS check out drawn on YYYY-MM-DD (e.g., 6.1.50.20020302-cvs,
5190      6.1.90.20020304-cvs, or 6.1.0.20020308-cvs)
5192 MAJOR.MINOR.PATCHLEVEL.YYYYMMDD (VENDOR)
5193      a vendor specific release of GDB, that while based on
5194      MAJOR.MINOR.PATCHLEVEL.YYYYMMDD, may include additional changes
5196    GDB's mainline uses the MAJOR and MINOR version numbers from the
5197 most recent release branch, with a PATCHLEVEL of 50.  At the time each
5198 new release branch is created, the mainline's MAJOR and MINOR version
5199 numbers are updated.
5201    GDB's release branch is similar.  When the branch is cut, the
5202 PATCHLEVEL is changed from 50 to 90.  As draft releases are drawn from
5203 the branch, the PATCHLEVEL is incremented.  Once the first release
5204 (MAJOR.MINOR) has been made, the PATCHLEVEL is set to 0 and updates
5205 have an incremented PATCHLEVEL.
5207    For snapshots, and CVS check outs, it is also possible to identify
5208 the CVS origin:
5210 MAJOR.MINOR.50.YYYYMMDD
5211      drawn from the HEAD of mainline CVS (e.g., 6.1.50.20020302)
5213 MAJOR.MINOR.90.YYYYMMDD
5214 MAJOR.MINOR.91.YYYYMMDD ...
5215      drawn from a release branch prior to the release (e.g.,
5216      6.1.90.20020304)
5218 MAJOR.MINOR.0.YYYYMMDD
5219 MAJOR.MINOR.1.YYYYMMDD ...
5220      drawn from a release branch after the release (e.g.,
5221      6.2.0.20020308)
5223    If the previous GDB version is 6.1 and the current version is 6.2,
5224 then, substituting 6 for MAJOR and 1 or 2 for MINOR, here's an
5225 illustration of a typical sequence:
5227           <HEAD>
5228              |
5229      6.1.50.20020302-cvs
5230              |
5231              +--------------------------.
5232              |                    <gdb_6_2-branch>
5233              |                          |
5234      6.2.50.20020303-cvs        6.1.90 (draft #1)
5235              |                          |
5236      6.2.50.20020304-cvs        6.1.90.20020304-cvs
5237              |                          |
5238      6.2.50.20020305-cvs        6.1.91 (draft #2)
5239              |                          |
5240      6.2.50.20020306-cvs        6.1.91.20020306-cvs
5241              |                          |
5242      6.2.50.20020307-cvs        6.2 (release)
5243              |                          |
5244      6.2.50.20020308-cvs        6.2.0.20020308-cvs
5245              |                          |
5246      6.2.50.20020309-cvs        6.2.1 (update)
5247              |                          |
5248      6.2.50.20020310-cvs         <branch closed>
5249              |
5250      6.2.50.20020311-cvs
5251              |
5252              +--------------------------.
5253              |                     <gdb_6_3-branch>
5254              |                          |
5255      6.3.50.20020312-cvs        6.2.90 (draft #1)
5256              |                          |
5258 16.2 Release Branches
5259 =====================
5261 GDB draws a release series (6.2, 6.2.1, ...) from a single release
5262 branch, and identifies that branch using the CVS branch tags:
5264      gdb_MAJOR_MINOR-YYYYMMDD-branchpoint
5265      gdb_MAJOR_MINOR-branch
5266      gdb_MAJOR_MINOR-YYYYMMDD-release
5268    _Pragmatics: To help identify the date at which a branch or release
5269 is made, both the branchpoint and release tags include the date that
5270 they are cut (YYYYMMDD) in the tag.  The branch tag, denoting the head
5271 of the branch, does not need this._
5273 16.3 Vendor Branches
5274 ====================
5276 To avoid version conflicts, vendors are expected to modify the file
5277 `gdb/version.in' to include a vendor unique alphabetic identifier (an
5278 official GDB release never uses alphabetic characters in its version
5279 identifier).  E.g., `6.2widgit2', or `6.2 (Widgit Inc Patch 2)'.
5281 16.4 Experimental Branches
5282 ==========================
5284 16.4.1 Guidelines
5285 -----------------
5287 GDB permits the creation of branches, cut from the CVS repository, for
5288 experimental development.  Branches make it possible for developers to
5289 share preliminary work, and maintainers to examine significant new
5290 developments.
5292    The following are a set of guidelines for creating such branches:
5294 _a branch has an owner_
5295      The owner can set further policy for a branch, but may not change
5296      the ground rules.  In particular, they can set a policy for
5297      commits (be it adding more reviewers or deciding who can commit).
5299 _all commits are posted_
5300      All changes committed to a branch shall also be posted to the GDB
5301      patches mailing list <gdb-patches@sources.redhat.com>.  While
5302      commentary on such changes are encouraged, people should remember
5303      that the changes only apply to a branch.
5305 _all commits are covered by an assignment_
5306      This ensures that all changes belong to the Free Software
5307      Foundation, and avoids the possibility that the branch may become
5308      contaminated.
5310 _a branch is focused_
5311      A focused branch has a single objective or goal, and does not
5312      contain unnecessary or irrelevant changes.  Cleanups, where
5313      identified, being be pushed into the mainline as soon as possible.
5315 _a branch tracks mainline_
5316      This keeps the level of divergence under control.  It also keeps
5317      the pressure on developers to push cleanups and other stuff into
5318      the mainline.
5320 _a branch shall contain the entire GDB module_
5321      The GDB module `gdb' should be specified when creating a branch
5322      (branches of individual files should be avoided).  *Note Tags::.
5324 _a branch shall be branded using `version.in'_
5325      The file `gdb/version.in' shall be modified so that it identifies
5326      the branch OWNER and branch NAME, e.g.,
5327      `6.2.50.20030303_owner_name' or `6.2 (Owner Name)'.
5330 16.4.2 Tags
5331 -----------
5333 To simplify the identification of GDB branches, the following branch
5334 tagging convention is strongly recommended:
5336 `OWNER_NAME-YYYYMMDD-branchpoint'
5337 `OWNER_NAME-YYYYMMDD-branch'
5338      The branch point and corresponding branch tag.  YYYYMMDD is the
5339      date that the branch was created.  A branch is created using the
5340      sequence:
5341           cvs rtag OWNER_NAME-YYYYMMDD-branchpoint gdb
5342           cvs rtag -b -r OWNER_NAME-YYYYMMDD-branchpoint \
5343              OWNER_NAME-YYYYMMDD-branch gdb
5345 `OWNER_NAME-YYYYMMDD-mergepoint'
5346      The tagged point, on the mainline, that was used when merging the
5347      branch on YYYYMMDD.  To merge in all changes since the branch was
5348      cut, use a command sequence like:
5349           cvs rtag OWNER_NAME-YYYYMMDD-mergepoint gdb
5350           cvs update \
5351              -jOWNER_NAME-YYYYMMDD-branchpoint
5352              -jOWNER_NAME-YYYYMMDD-mergepoint
5353      Similar sequences can be used to just merge in changes since the
5354      last merge.
5357 For further information on CVS, see Concurrent Versions System
5358 (http://www.gnu.org/software/cvs/).
5360 \x1f
5361 File: gdbint.info,  Node: Start of New Year Procedure,  Next: Releasing GDB,  Prev: Versions and Branches,  Up: Top
5363 17 Start of New Year Procedure
5364 ******************************
5366 At the start of each new year, the following actions should be
5367 performed:
5369    * Rotate the ChangeLog file
5371      The current `ChangeLog' file should be renamed into
5372      `ChangeLog-YYYY' where YYYY is the year that has just passed.  A
5373      new `ChangeLog' file should be created, and its contents should
5374      contain a reference to the previous ChangeLog.  The following
5375      should also be preserved at the end of the new ChangeLog, in order
5376      to provide the appropriate settings when editing this file with
5377      Emacs:
5378           Local Variables:
5379           mode: change-log
5380           left-margin: 8
5381           fill-column: 74
5382           version-control: never
5383           End:
5385    * Add an entry for the newly created ChangeLog file
5386      (`ChangeLog-YYYY') in `gdb/config/djgpp/fnchange.lst'.
5388    * Update the copyright year in the startup message
5390      Update the copyright year in file `top.c', function
5391      `print_gdb_version'.
5393    * Add the new year in the copyright notices of all source and
5394      documentation files.  This can be done semi-automatically by
5395      running the `copyright.sh' script.  This script requires Emacs 22
5396      or later to be installed.
5399 \x1f
5400 File: gdbint.info,  Node: Releasing GDB,  Next: Testsuite,  Prev: Start of New Year Procedure,  Up: Top
5402 18 Releasing GDB
5403 ****************
5405 18.1 Branch Commit Policy
5406 =========================
5408 The branch commit policy is pretty slack.  GDB releases 5.0, 5.1 and
5409 5.2 all used the below:
5411    * The `gdb/MAINTAINERS' file still holds.
5413    * Don't fix something on the branch unless/until it is also fixed in
5414      the trunk.  If this isn't possible, mentioning it in the
5415      `gdb/PROBLEMS' file is better than committing a hack.
5417    * When considering a patch for the branch, suggested criteria
5418      include: Does it fix a build?  Does it fix the sequence `break
5419      main; run' when debugging a static binary?
5421    * The further a change is from the core of GDB, the less likely the
5422      change will worry anyone (e.g., target specific code).
5424    * Only post a proposal to change the core of GDB after you've sent
5425      individual bribes to all the people listed in the `MAINTAINERS'
5426      file ;-)
5428    _Pragmatics: Provided updates are restricted to non-core
5429 functionality there is little chance that a broken change will be fatal.
5430 This means that changes such as adding a new architectures or (within
5431 reason) support for a new host are considered acceptable._
5433 18.2 Obsoleting code
5434 ====================
5436 Before anything else, poke the other developers (and around the source
5437 code) to see if there is anything that can be removed from GDB (an old
5438 target, an unused file).
5440    Obsolete code is identified by adding an `OBSOLETE' prefix to every
5441 line.  Doing this means that it is easy to identify something that has
5442 been obsoleted when greping through the sources.
5444    The process is done in stages -- this is mainly to ensure that the
5445 wider GDB community has a reasonable opportunity to respond.  Remember,
5446 everything on the Internet takes a week.
5448   1. Post the proposal on the GDB mailing list <gdb@sources.redhat.com>
5449      Creating a bug report to track the task's state, is also highly
5450      recommended.
5452   2. Wait a week or so.
5454   3. Post the proposal on the GDB Announcement mailing list
5455      <gdb-announce@sources.redhat.com>.
5457   4. Wait a week or so.
5459   5. Go through and edit all relevant files and lines so that they are
5460      prefixed with the word `OBSOLETE'.
5462   6. Wait until the next GDB version, containing this obsolete code,
5463      has been released.
5465   7. Remove the obsolete code.
5467 _Maintainer note: While removing old code is regrettable it is
5468 hopefully better for GDB's long term development.  Firstly it helps the
5469 developers by removing code that is either no longer relevant or simply
5470 wrong.  Secondly since it removes any history associated with the file
5471 (effectively clearing the slate) the developer has a much freer hand
5472 when it comes to fixing broken files._
5474 18.3 Before the Branch
5475 ======================
5477 The most important objective at this stage is to find and fix simple
5478 changes that become a pain to track once the branch is created.  For
5479 instance, configuration problems that stop GDB from even building.  If
5480 you can't get the problem fixed, document it in the `gdb/PROBLEMS' file.
5482 Prompt for `gdb/NEWS'
5483 ---------------------
5485 People always forget.  Send a post reminding them but also if you know
5486 something interesting happened add it yourself.  The `schedule' script
5487 will mention this in its e-mail.
5489 Review `gdb/README'
5490 -------------------
5492 Grab one of the nightly snapshots and then walk through the
5493 `gdb/README' looking for anything that can be improved.  The `schedule'
5494 script will mention this in its e-mail.
5496 Refresh any imported files.
5497 ---------------------------
5499 A number of files are taken from external repositories.  They include:
5501    * `texinfo/texinfo.tex'
5503    * `config.guess' et. al. (see the top-level `MAINTAINERS' file)
5505    * `etc/standards.texi', `etc/make-stds.texi'
5507 Check the ARI
5508 -------------
5510 A.R.I. is an `awk' script (Awk Regression Index ;-) that checks for a
5511 number of errors and coding conventions.  The checks include things
5512 like using `malloc' instead of `xmalloc' and file naming problems.
5513 There shouldn't be any regressions.
5515 18.3.1 Review the bug data base
5516 -------------------------------
5518 Close anything obviously fixed.
5520 18.3.2 Check all cross targets build
5521 ------------------------------------
5523 The targets are listed in `gdb/MAINTAINERS'.
5525 18.4 Cut the Branch
5526 ===================
5528 Create the branch
5529 -----------------
5531      $  u=5.1
5532      $  v=5.2
5533      $  V=`echo $v | sed 's/\./_/g'`
5534      $  D=`date -u +%Y-%m-%d`
5535      $  echo $u $V $D
5536      5.1 5_2 2002-03-03
5537      $  echo cvs -f -d :ext:sources.redhat.com:/cvs/src rtag \
5538      -D $D-gmt gdb_$V-$D-branchpoint insight
5539      cvs -f -d :ext:sources.redhat.com:/cvs/src rtag
5540      -D 2002-03-03-gmt gdb_5_2-2002-03-03-branchpoint insight
5541      $  ^echo ^^
5542      ...
5543      $  echo cvs -f -d :ext:sources.redhat.com:/cvs/src rtag \
5544      -b -r gdb_$V-$D-branchpoint gdb_$V-branch insight
5545      cvs -f -d :ext:sources.redhat.com:/cvs/src rtag \
5546      -b -r gdb_5_2-2002-03-03-branchpoint gdb_5_2-branch insight
5547      $  ^echo ^^
5548      ...
5549      $
5551    * By using `-D YYYY-MM-DD-gmt', the branch is forced to an exact
5552      date/time.
5554    * The trunk is first tagged so that the branch point can easily be
5555      found.
5557    * Insight, which includes GDB, is tagged at the same time.
5559    * `version.in' gets bumped to avoid version number conflicts.
5561    * The reading of `.cvsrc' is disabled using `-f'.
5563 Update `version.in'
5564 -------------------
5566      $  u=5.1
5567      $  v=5.2
5568      $  V=`echo $v | sed 's/\./_/g'`
5569      $  echo $u $v$V
5570      5.1 5_2
5571      $  cd /tmp
5572      $  echo cvs -f -d :ext:sources.redhat.com:/cvs/src co \
5573      -r gdb_$V-branch src/gdb/version.in
5574      cvs -f -d :ext:sources.redhat.com:/cvs/src co
5575       -r gdb_5_2-branch src/gdb/version.in
5576      $  ^echo ^^
5577      U src/gdb/version.in
5578      $  cd src/gdb
5579      $  echo $u.90-0000-00-00-cvs > version.in
5580      $  cat version.in
5581      5.1.90-0000-00-00-cvs
5582      $  cvs -f commit version.in
5584    * `0000-00-00' is used as a date to pump prime the version.in update
5585      mechanism.
5587    * `.90' and the previous branch version are used as fairly arbitrary
5588      initial branch version number.
5590 Update the web and news pages
5591 -----------------------------
5593 Something?
5595 Tweak cron to track the new branch
5596 ----------------------------------
5598 The file `gdbadmin/cron/crontab' contains gdbadmin's cron table.  This
5599 file needs to be updated so that:
5601    * A daily timestamp is added to the file `version.in'.
5603    * The new branch is included in the snapshot process.
5605 See the file `gdbadmin/cron/README' for how to install the updated cron
5606 table.
5608    The file `gdbadmin/ss/README' should also be reviewed to reflect any
5609 changes.  That file is copied to both the branch/ and current/ snapshot
5610 directories.
5612 Update the NEWS and README files
5613 --------------------------------
5615 The `NEWS' file needs to be updated so that on the branch it refers to
5616 _changes in the current release_ while on the trunk it also refers to
5617 _changes since the current release_.
5619    The `README' file needs to be updated so that it refers to the
5620 current release.
5622 Post the branch info
5623 --------------------
5625 Send an announcement to the mailing lists:
5627    * GDB Announcement mailing list <gdb-announce@sources.redhat.com>
5629    * GDB Discussion mailing list <gdb@sources.redhat.com> and GDB
5630      Testers mailing list <gdb-testers@sources.redhat.com>
5632    _Pragmatics: The branch creation is sent to the announce list to
5633 ensure that people people not subscribed to the higher volume discussion
5634 list are alerted._
5636    The announcement should include:
5638    * The branch tag.
5640    * How to check out the branch using CVS.
5642    * The date/number of weeks until the release.
5644    * The branch commit policy still holds.
5646 18.5 Stabilize the branch
5647 =========================
5649 Something goes here.
5651 18.6 Create a Release
5652 =====================
5654 The process of creating and then making available a release is broken
5655 down into a number of stages.  The first part addresses the technical
5656 process of creating a releasable tar ball.  The later stages address the
5657 process of releasing that tar ball.
5659    When making a release candidate just the first section is needed.
5661 18.6.1 Create a release candidate
5662 ---------------------------------
5664 The objective at this stage is to create a set of tar balls that can be
5665 made available as a formal release (or as a less formal release
5666 candidate).
5668 Freeze the branch
5669 .................
5671 Send out an e-mail notifying everyone that the branch is frozen to
5672 <gdb-patches@sources.redhat.com>.
5674 Establish a few defaults.
5675 .........................
5677      $  b=gdb_5_2-branch
5678      $  v=5.2
5679      $  t=/sourceware/snapshot-tmp/gdbadmin-tmp
5680      $  echo $t/$b/$v
5681      /sourceware/snapshot-tmp/gdbadmin-tmp/gdb_5_2-branch/5.2
5682      $  mkdir -p $t/$b/$v
5683      $  cd $t/$b/$v
5684      $  pwd
5685      /sourceware/snapshot-tmp/gdbadmin-tmp/gdb_5_2-branch/5.2
5686      $  which autoconf
5687      /home/gdbadmin/bin/autoconf
5688      $
5690 Notes:
5692    * Check the `autoconf' version carefully.  You want to be using the
5693      version taken from the `binutils' snapshot directory, which can be
5694      found at `ftp://sources.redhat.com/pub/binutils/'. It is very
5695      unlikely that a system installed version of `autoconf' (e.g.,
5696      `/usr/bin/autoconf') is correct.
5698 Check out the relevant modules:
5699 ...............................
5701      $  for m in gdb insight
5702      do
5703      ( mkdir -p $m && cd $m && cvs -q -f -d /cvs/src co -P -r $b $m )
5704      done
5705      $
5707 Note:
5709    * The reading of `.cvsrc' is disabled (`-f') so that there isn't any
5710      confusion between what is written here and what your local `cvs'
5711      really does.
5713 Update relevant files.
5714 ......................
5716 `gdb/NEWS'
5717      Major releases get their comments added as part of the mainline.
5718      Minor releases should probably mention any significant bugs that
5719      were fixed.
5721      Don't forget to include the `ChangeLog' entry.
5723           $  emacs gdb/src/gdb/NEWS
5724           ...
5725           c-x 4 a
5726           ...
5727           c-x c-s c-x c-c
5728           $  cp gdb/src/gdb/NEWS insight/src/gdb/NEWS
5729           $  cp gdb/src/gdb/ChangeLog insight/src/gdb/ChangeLog
5731 `gdb/README'
5732      You'll need to update:
5734         * The version.
5736         * The update date.
5738         * Who did it.
5740           $  emacs gdb/src/gdb/README
5741           ...
5742           c-x 4 a
5743           ...
5744           c-x c-s c-x c-c
5745           $  cp gdb/src/gdb/README insight/src/gdb/README
5746           $  cp gdb/src/gdb/ChangeLog insight/src/gdb/ChangeLog
5748      _Maintainer note: Hopefully the `README' file was reviewed before
5749      the initial branch was cut so just a simple substitute is needed
5750      to get it updated._
5752      _Maintainer note: Other projects generate `README' and `INSTALL'
5753      from the core documentation.  This might be worth pursuing._
5755 `gdb/version.in'
5756           $  echo $v > gdb/src/gdb/version.in
5757           $  cat gdb/src/gdb/version.in
5758           5.2
5759           $  emacs gdb/src/gdb/version.in
5760           ...
5761           c-x 4 a
5762           ... Bump to version ...
5763           c-x c-s c-x c-c
5764           $  cp gdb/src/gdb/version.in insight/src/gdb/version.in
5765           $  cp gdb/src/gdb/ChangeLog insight/src/gdb/ChangeLog
5768 Do the dirty work
5769 .................
5771 This is identical to the process used to create the daily snapshot.
5773      $  for m in gdb insight
5774      do
5775      ( cd $m/src && gmake -f src-release $m.tar )
5776      done
5778    If the top level source directory does not have `src-release' (GDB
5779 version 5.3.1 or earlier), try these commands instead:
5781      $  for m in gdb insight
5782      do
5783      ( cd $m/src && gmake -f Makefile.in $m.tar )
5784      done
5786 Check the source files
5787 ......................
5789 You're looking for files that have mysteriously disappeared.
5790 `distclean' has the habit of deleting files it shouldn't.  Watch out
5791 for the `version.in' update `cronjob'.
5793      $  ( cd gdb/src && cvs -f -q -n update )
5794      M djunpack.bat
5795      ? gdb-5.1.91.tar
5796      ? proto-toplev
5797      ... lots of generated files ...
5798      M gdb/ChangeLog
5799      M gdb/NEWS
5800      M gdb/README
5801      M gdb/version.in
5802      ... lots of generated files ...
5803      $
5805 _Don't worry about the `gdb.info-??' or `gdb/p-exp.tab.c'.  They were
5806 generated (and yes `gdb.info-1' was also generated only something
5807 strange with CVS means that they didn't get suppressed).  Fixing it
5808 would be nice though._
5810 Create compressed versions of the release
5811 .........................................
5813      $  cp */src/*.tar .
5814      $  cp */src/*.bz2 .
5815      $  ls -F
5816      gdb/ gdb-5.2.tar insight/ insight-5.2.tar
5817      $  for m in gdb insight
5818      do
5819      bzip2 -v -9 -c $m-$v.tar > $m-$v.tar.bz2
5820      gzip -v -9 -c $m-$v.tar > $m-$v.tar.gz
5821      done
5822      $
5824 Note:
5826    * A pipe such as `bunzip2 < xxx.bz2 | gzip -9 > xxx.gz' is not since,
5827      in that mode, `gzip' does not know the name of the file and, hence,
5828      can not include it in the compressed file.  This is also why the
5829      release process runs `tar' and `bzip2' as separate passes.
5831 18.6.2 Sanity check the tar ball
5832 --------------------------------
5834 Pick a popular machine (Solaris/PPC?) and try the build on that.
5836      $  bunzip2 < gdb-5.2.tar.bz2 | tar xpf -
5837      $  cd gdb-5.2
5838      $  ./configure
5839      $  make
5840      ...
5841      $  ./gdb/gdb ./gdb/gdb
5842      GNU gdb 5.2
5843      ...
5844      (gdb)  b main
5845      Breakpoint 1 at 0x80732bc: file main.c, line 734.
5846      (gdb)  run
5847      Starting program: /tmp/gdb-5.2/gdb/gdb
5849      Breakpoint 1, main (argc=1, argv=0xbffff8b4) at main.c:734
5850      734       catch_errors (captured_main, &args, "", RETURN_MASK_ALL);
5851      (gdb)  print args
5852      $1 = {argc = 136426532, argv = 0x821b7f0}
5853      (gdb)
5855 18.6.3 Make a release candidate available
5856 -----------------------------------------
5858 If this is a release candidate then the only remaining steps are:
5860   1. Commit `version.in' and `ChangeLog'
5862   2. Tweak `version.in' (and `ChangeLog' to read L.M.N-0000-00-00-cvs
5863      so that the version update process can restart.
5865   3. Make the release candidate available in
5866      `ftp://sources.redhat.com/pub/gdb/snapshots/branch'
5868   4. Notify the relevant mailing lists ( <gdb@sources.redhat.com> and
5869      <gdb-testers@sources.redhat.com> that the candidate is available.
5871 18.6.4 Make a formal release available
5872 --------------------------------------
5874 (And you thought all that was required was to post an e-mail.)
5876 Install on sware
5877 ................
5879 Copy the new files to both the release and the old release directory:
5881      $  cp *.bz2 *.gz ~ftp/pub/gdb/old-releases/
5882      $  cp *.bz2 *.gz ~ftp/pub/gdb/releases
5884 Clean up the releases directory so that only the most recent releases
5885 are available (e.g. keep 5.2 and 5.2.1 but remove 5.1):
5887      $  cd ~ftp/pub/gdb/releases
5888      $  rm ...
5890 Update the file `README' and `.message' in the releases directory:
5892      $  vi README
5893      ...
5894      $  rm -f .message
5895      $  ln README .message
5897 Update the web pages.
5898 .....................
5900 `htdocs/download/ANNOUNCEMENT'
5901      This file, which is posted as the official announcement, includes:
5902         * General announcement.
5904         * News.  If making an M.N.1 release, retain the news from
5905           earlier M.N release.
5907         * Errata.
5909 `htdocs/index.html'
5910 `htdocs/news/index.html'
5911 `htdocs/download/index.html'
5912      These files include:
5913         * Announcement of the most recent release.
5915         * News entry (remember to update both the top level and the
5916           news directory).
5917      These pages also need to be regenerate using `index.sh'.
5919 `download/onlinedocs/'
5920      You need to find the magic command that is used to generate the
5921      online docs from the `.tar.bz2'.  The best way is to look in the
5922      output from one of the nightly `cron' jobs and then just edit
5923      accordingly.  Something like:
5925           $  ~/ss/update-web-docs \
5926            ~ftp/pub/gdb/releases/gdb-5.2.tar.bz2 \
5927            $PWD/www \
5928            /www/sourceware/htdocs/gdb/download/onlinedocs \
5929            gdb
5931 `download/ari/'
5932      Just like the online documentation.  Something like:
5934           $  /bin/sh ~/ss/update-web-ari \
5935            ~ftp/pub/gdb/releases/gdb-5.2.tar.bz2 \
5936            $PWD/www \
5937            /www/sourceware/htdocs/gdb/download/ari \
5938            gdb
5941 Shadow the pages onto gnu
5942 .........................
5944 Something goes here.
5946 Install the GDB tar ball on GNU
5947 ...............................
5949 At the time of writing, the GNU machine was `gnudist.gnu.org' in
5950 `~ftp/gnu/gdb'.
5952 Make the `ANNOUNCEMENT'
5953 .......................
5955 Post the `ANNOUNCEMENT' file you created above to:
5957    * GDB Announcement mailing list <gdb-announce@sources.redhat.com>
5959    * General GNU Announcement list <info-gnu@gnu.org> (but delay it a
5960      day or so to let things get out)
5962    * GDB Bug Report mailing list <bug-gdb@gnu.org>
5964 18.6.5 Cleanup
5965 --------------
5967 The release is out but you're still not finished.
5969 Commit outstanding changes
5970 ..........................
5972 In particular you'll need to commit any changes to:
5974    * `gdb/ChangeLog'
5976    * `gdb/version.in'
5978    * `gdb/NEWS'
5980    * `gdb/README'
5982 Tag the release
5983 ...............
5985 Something like:
5987      $  d=`date -u +%Y-%m-%d`
5988      $  echo $d
5989      2002-01-24
5990      $  ( cd insight/src/gdb && cvs -f -q update )
5991      $  ( cd insight/src && cvs -f -q tag gdb_5_2-$d-release )
5993    Insight is used since that contains more of the release than GDB.
5995 Mention the release on the trunk
5996 ................................
5998 Just put something in the `ChangeLog' so that the trunk also indicates
5999 when the release was made.
6001 Restart `gdb/version.in'
6002 ........................
6004 If `gdb/version.in' does not contain an ISO date such as `2002-01-24'
6005 then the daily `cronjob' won't update it.  Having committed all the
6006 release changes it can be set to `5.2.0_0000-00-00-cvs' which will
6007 restart things (yes the `_' is important - it affects the snapshot
6008 process).
6010    Don't forget the `ChangeLog'.
6012 Merge into trunk
6013 ................
6015 The files committed to the branch may also need changes merged into the
6016 trunk.
6018 Revise the release schedule
6019 ...........................
6021 Post a revised release schedule to GDB Discussion List
6022 <gdb@sources.redhat.com> with an updated announcement.  The schedule
6023 can be generated by running:
6025      $  ~/ss/schedule `date +%s` schedule
6027 The first parameter is approximate date/time in seconds (from the epoch)
6028 of the most recent release.
6030    Also update the schedule `cronjob'.
6032 18.7 Post release
6033 =================
6035 Remove any `OBSOLETE' code.
6037 \x1f
6038 File: gdbint.info,  Node: Testsuite,  Next: Hints,  Prev: Releasing GDB,  Up: Top
6040 19 Testsuite
6041 ************
6043 The testsuite is an important component of the GDB package.  While it
6044 is always worthwhile to encourage user testing, in practice this is
6045 rarely sufficient; users typically use only a small subset of the
6046 available commands, and it has proven all too common for a change to
6047 cause a significant regression that went unnoticed for some time.
6049    The GDB testsuite uses the DejaGNU testing framework.  The tests
6050 themselves are calls to various `Tcl' procs; the framework runs all the
6051 procs and summarizes the passes and fails.
6053 19.1 Using the Testsuite
6054 ========================
6056 To run the testsuite, simply go to the GDB object directory (or to the
6057 testsuite's objdir) and type `make check'.  This just sets up some
6058 environment variables and invokes DejaGNU's `runtest' script.  While
6059 the testsuite is running, you'll get mentions of which test file is in
6060 use, and a mention of any unexpected passes or fails.  When the
6061 testsuite is finished, you'll get a summary that looks like this:
6063                      === gdb Summary ===
6065      # of expected passes            6016
6066      # of unexpected failures        58
6067      # of unexpected successes       5
6068      # of expected failures          183
6069      # of unresolved testcases       3
6070      # of untested testcases         5
6072    To run a specific test script, type:
6073      make check RUNTESTFLAGS='TESTS'
6074    where TESTS is a list of test script file names, separated by spaces.
6076    The ideal test run consists of expected passes only; however, reality
6077 conspires to keep us from this ideal.  Unexpected failures indicate
6078 real problems, whether in GDB or in the testsuite.  Expected failures
6079 are still failures, but ones which have been decided are too hard to
6080 deal with at the time; for instance, a test case might work everywhere
6081 except on AIX, and there is no prospect of the AIX case being fixed in
6082 the near future.  Expected failures should not be added lightly, since
6083 you may be masking serious bugs in GDB.  Unexpected successes are
6084 expected fails that are passing for some reason, while unresolved and
6085 untested cases often indicate some minor catastrophe, such as the
6086 compiler being unable to deal with a test program.
6088    When making any significant change to GDB, you should run the
6089 testsuite before and after the change, to confirm that there are no
6090 regressions.  Note that truly complete testing would require that you
6091 run the testsuite with all supported configurations and a variety of
6092 compilers; however this is more than really necessary.  In many cases
6093 testing with a single configuration is sufficient.  Other useful
6094 options are to test one big-endian (Sparc) and one little-endian (x86)
6095 host, a cross config with a builtin simulator (powerpc-eabi, mips-elf),
6096 or a 64-bit host (Alpha).
6098    If you add new functionality to GDB, please consider adding tests
6099 for it as well; this way future GDB hackers can detect and fix their
6100 changes that break the functionality you added.  Similarly, if you fix
6101 a bug that was not previously reported as a test failure, please add a
6102 test case for it.  Some cases are extremely difficult to test, such as
6103 code that handles host OS failures or bugs in particular versions of
6104 compilers, and it's OK not to try to write tests for all of those.
6106    DejaGNU supports separate build, host, and target machines.  However,
6107 some GDB test scripts do not work if the build machine and the host
6108 machine are not the same.  In such an environment, these scripts will
6109 give a result of "UNRESOLVED", like this:
6111      UNRESOLVED: gdb.base/example.exp: This test script does not work on a remote host.
6113 19.2 Testsuite Organization
6114 ===========================
6116 The testsuite is entirely contained in `gdb/testsuite'.  While the
6117 testsuite includes some makefiles and configury, these are very minimal,
6118 and used for little besides cleaning up, since the tests themselves
6119 handle the compilation of the programs that GDB will run.  The file
6120 `testsuite/lib/gdb.exp' contains common utility procs useful for all
6121 GDB tests, while the directory `testsuite/config' contains
6122 configuration-specific files, typically used for special-purpose
6123 definitions of procs like `gdb_load' and `gdb_start'.
6125    The tests themselves are to be found in `testsuite/gdb.*' and
6126 subdirectories of those.  The names of the test files must always end
6127 with `.exp'.  DejaGNU collects the test files by wildcarding in the
6128 test directories, so both subdirectories and individual files get
6129 chosen and run in alphabetical order.
6131    The following table lists the main types of subdirectories and what
6132 they are for.  Since DejaGNU finds test files no matter where they are
6133 located, and since each test file sets up its own compilation and
6134 execution environment, this organization is simply for convenience and
6135 intelligibility.
6137 `gdb.base'
6138      This is the base testsuite.  The tests in it should apply to all
6139      configurations of GDB (but generic native-only tests may live
6140      here).  The test programs should be in the subset of C that is
6141      valid K&R, ANSI/ISO, and C++ (`#ifdef's are allowed if necessary,
6142      for instance for prototypes).
6144 `gdb.LANG'
6145      Language-specific tests for any language LANG besides C.  Examples
6146      are `gdb.cp' and `gdb.java'.
6148 `gdb.PLATFORM'
6149      Non-portable tests.  The tests are specific to a specific
6150      configuration (host or target), such as HP-UX or eCos.  Example is
6151      `gdb.hp', for HP-UX.
6153 `gdb.COMPILER'
6154      Tests specific to a particular compiler.  As of this writing (June
6155      1999), there aren't currently any groups of tests in this category
6156      that couldn't just as sensibly be made platform-specific, but one
6157      could imagine a `gdb.gcc', for tests of GDB's handling of GCC
6158      extensions.
6160 `gdb.SUBSYSTEM'
6161      Tests that exercise a specific GDB subsystem in more depth.  For
6162      instance, `gdb.disasm' exercises various disassemblers, while
6163      `gdb.stabs' tests pathways through the stabs symbol reader.
6165 19.3 Writing Tests
6166 ==================
6168 In many areas, the GDB tests are already quite comprehensive; you
6169 should be able to copy existing tests to handle new cases.
6171    You should try to use `gdb_test' whenever possible, since it
6172 includes cases to handle all the unexpected errors that might happen.
6173 However, it doesn't cost anything to add new test procedures; for
6174 instance, `gdb.base/exprs.exp' defines a `test_expr' that calls
6175 `gdb_test' multiple times.
6177    Only use `send_gdb' and `gdb_expect' when absolutely necessary.
6178 Even if GDB has several valid responses to a command, you can use
6179 `gdb_test_multiple'.  Like `gdb_test', `gdb_test_multiple' recognizes
6180 internal errors and unexpected prompts.
6182    Do not write tests which expect a literal tab character from GDB.
6183 On some operating systems (e.g. OpenBSD) the TTY layer expands tabs to
6184 spaces, so by the time GDB's output reaches expect the tab is gone.
6186    The source language programs do _not_ need to be in a consistent
6187 style.  Since GDB is used to debug programs written in many different
6188 styles, it's worth having a mix of styles in the testsuite; for
6189 instance, some GDB bugs involving the display of source lines would
6190 never manifest themselves if the programs used GNU coding style
6191 uniformly.
6193 \x1f
6194 File: gdbint.info,  Node: Hints,  Next: GDB Observers,  Prev: Testsuite,  Up: Top
6196 20 Hints
6197 ********
6199 Check the `README' file, it often has useful information that does not
6200 appear anywhere else in the directory.
6202 * Menu:
6204 * Getting Started::             Getting started working on GDB
6205 * Debugging GDB::               Debugging GDB with itself
6207 \x1f
6208 File: gdbint.info,  Node: Getting Started,  Up: Hints
6210 20.1 Getting Started
6211 ====================
6213 GDB is a large and complicated program, and if you first starting to
6214 work on it, it can be hard to know where to start.  Fortunately, if you
6215 know how to go about it, there are ways to figure out what is going on.
6217    This manual, the GDB Internals manual, has information which applies
6218 generally to many parts of GDB.
6220    Information about particular functions or data structures are
6221 located in comments with those functions or data structures.  If you
6222 run across a function or a global variable which does not have a
6223 comment correctly explaining what is does, this can be thought of as a
6224 bug in GDB; feel free to submit a bug report, with a suggested comment
6225 if you can figure out what the comment should say.  If you find a
6226 comment which is actually wrong, be especially sure to report that.
6228    Comments explaining the function of macros defined in host, target,
6229 or native dependent files can be in several places.  Sometimes they are
6230 repeated every place the macro is defined.  Sometimes they are where the
6231 macro is used.  Sometimes there is a header file which supplies a
6232 default definition of the macro, and the comment is there.  This manual
6233 also documents all the available macros.
6235    Start with the header files.  Once you have some idea of how GDB's
6236 internal symbol tables are stored (see `symtab.h', `gdbtypes.h'), you
6237 will find it much easier to understand the code which uses and creates
6238 those symbol tables.
6240    You may wish to process the information you are getting somehow, to
6241 enhance your understanding of it.  Summarize it, translate it to another
6242 language, add some (perhaps trivial or non-useful) feature to GDB, use
6243 the code to predict what a test case would do and write the test case
6244 and verify your prediction, etc.  If you are reading code and your eyes
6245 are starting to glaze over, this is a sign you need to use a more active
6246 approach.
6248    Once you have a part of GDB to start with, you can find more
6249 specifically the part you are looking for by stepping through each
6250 function with the `next' command.  Do not use `step' or you will
6251 quickly get distracted; when the function you are stepping through
6252 calls another function try only to get a big-picture understanding
6253 (perhaps using the comment at the beginning of the function being
6254 called) of what it does.  This way you can identify which of the
6255 functions being called by the function you are stepping through is the
6256 one which you are interested in.  You may need to examine the data
6257 structures generated at each stage, with reference to the comments in
6258 the header files explaining what the data structures are supposed to
6259 look like.
6261    Of course, this same technique can be used if you are just reading
6262 the code, rather than actually stepping through it.  The same general
6263 principle applies--when the code you are looking at calls something
6264 else, just try to understand generally what the code being called does,
6265 rather than worrying about all its details.
6267    A good place to start when tracking down some particular area is with
6268 a command which invokes that feature.  Suppose you want to know how
6269 single-stepping works.  As a GDB user, you know that the `step' command
6270 invokes single-stepping.  The command is invoked via command tables
6271 (see `command.h'); by convention the function which actually performs
6272 the command is formed by taking the name of the command and adding
6273 `_command', or in the case of an `info' subcommand, `_info'.  For
6274 example, the `step' command invokes the `step_command' function and the
6275 `info display' command invokes `display_info'.  When this convention is
6276 not followed, you might have to use `grep' or `M-x tags-search' in
6277 emacs, or run GDB on itself and set a breakpoint in `execute_command'.
6279    If all of the above fail, it may be appropriate to ask for
6280 information on `bug-gdb'.  But _never_ post a generic question like "I
6281 was wondering if anyone could give me some tips about understanding
6282 GDB"--if we had some magic secret we would put it in this manual.
6283 Suggestions for improving the manual are always welcome, of course.
6285 \x1f
6286 File: gdbint.info,  Node: Debugging GDB,  Up: Hints
6288 20.2 Debugging GDB with itself
6289 ==============================
6291 If GDB is limping on your machine, this is the preferred way to get it
6292 fully functional.  Be warned that in some ancient Unix systems, like
6293 Ultrix 4.2, a program can't be running in one process while it is being
6294 debugged in another.  Rather than typing the command `./gdb ./gdb',
6295 which works on Suns and such, you can copy `gdb' to `gdb2' and then
6296 type `./gdb ./gdb2'.
6298    When you run GDB in the GDB source directory, it will read a
6299 `.gdbinit' file that sets up some simple things to make debugging gdb
6300 easier.  The `info' command, when executed without a subcommand in a
6301 GDB being debugged by gdb, will pop you back up to the top level gdb.
6302 See `.gdbinit' for details.
6304    If you use emacs, you will probably want to do a `make TAGS' after
6305 you configure your distribution; this will put the machine dependent
6306 routines for your local machine where they will be accessed first by
6307 `M-.'
6309    Also, make sure that you've either compiled GDB with your local cc,
6310 or have run `fixincludes' if you are compiling with gcc.
6312 20.3 Submitting Patches
6313 =======================
6315 Thanks for thinking of offering your changes back to the community of
6316 GDB users.  In general we like to get well designed enhancements.
6317 Thanks also for checking in advance about the best way to transfer the
6318 changes.
6320    The GDB maintainers will only install "cleanly designed" patches.
6321 This manual summarizes what we believe to be clean design for GDB.
6323    If the maintainers don't have time to put the patch in when it
6324 arrives, or if there is any question about a patch, it goes into a
6325 large queue with everyone else's patches and bug reports.
6327    The legal issue is that to incorporate substantial changes requires a
6328 copyright assignment from you and/or your employer, granting ownership
6329 of the changes to the Free Software Foundation.  You can get the
6330 standard documents for doing this by sending mail to `gnu@gnu.org' and
6331 asking for it.  We recommend that people write in "All programs owned
6332 by the Free Software Foundation" as "NAME OF PROGRAM", so that changes
6333 in many programs (not just GDB, but GAS, Emacs, GCC, etc) can be
6334 contributed with only one piece of legalese pushed through the
6335 bureaucracy and filed with the FSF.  We can't start merging changes
6336 until this paperwork is received by the FSF (their rules, which we
6337 follow since we maintain it for them).
6339    Technically, the easiest way to receive changes is to receive each
6340 feature as a small context diff or unidiff, suitable for `patch'.  Each
6341 message sent to me should include the changes to C code and header
6342 files for a single feature, plus `ChangeLog' entries for each directory
6343 where files were modified, and diffs for any changes needed to the
6344 manuals (`gdb/doc/gdb.texinfo' or `gdb/doc/gdbint.texinfo').  If there
6345 are a lot of changes for a single feature, they can be split down into
6346 multiple messages.
6348    In this way, if we read and like the feature, we can add it to the
6349 sources with a single patch command, do some testing, and check it in.
6350 If you leave out the `ChangeLog', we have to write one.  If you leave
6351 out the doc, we have to puzzle out what needs documenting.  Etc., etc.
6353    The reason to send each change in a separate message is that we will
6354 not install some of the changes.  They'll be returned to you with
6355 questions or comments.  If we're doing our job correctly, the message
6356 back to you will say what you have to fix in order to make the change
6357 acceptable.  The reason to have separate messages for separate features
6358 is so that the acceptable changes can be installed while one or more
6359 changes are being reworked.  If multiple features are sent in a single
6360 message, we tend to not put in the effort to sort out the acceptable
6361 changes from the unacceptable, so none of the features get installed
6362 until all are acceptable.
6364    If this sounds painful or authoritarian, well, it is.  But we get a
6365 lot of bug reports and a lot of patches, and many of them don't get
6366 installed because we don't have the time to finish the job that the bug
6367 reporter or the contributor could have done.  Patches that arrive
6368 complete, working, and well designed, tend to get installed on the day
6369 they arrive.  The others go into a queue and get installed as time
6370 permits, which, since the maintainers have many demands to meet, may not
6371 be for quite some time.
6373    Please send patches directly to the GDB maintainers
6374 <gdb-patches@sources.redhat.com>.
6376 20.4 Obsolete Conditionals
6377 ==========================
6379 Fragments of old code in GDB sometimes reference or set the following
6380 configuration macros.  They should not be used by new code, and old uses
6381 should be removed as those parts of the debugger are otherwise touched.
6383 `STACK_END_ADDR'
6384      This macro used to define where the end of the stack appeared, for
6385      use in interpreting core file formats that don't record this
6386      address in the core file itself.  This information is now
6387      configured in BFD, and GDB gets the info portably from there.  The
6388      values in GDB's configuration files should be moved into BFD
6389      configuration files (if needed there), and deleted from all of
6390      GDB's config files.
6392      Any `FOO-xdep.c' file that references STACK_END_ADDR is so old
6393      that it has never been converted to use BFD.  Now that's old!
6396 20.5 Build Script
6397 =================
6399 The script `gdb_buildall.sh' builds GDB with flag
6400 `--enable-targets=all' set.  This builds GDB with all supported targets
6401 activated.  This helps testing GDB when doing changes that affect more
6402 than one architecture and is much faster than using `gdb_mbuild.sh'.
6404    After building GDB the script checks which architectures are
6405 supported and then switches the current architecture to each of those
6406 to get information about the architecture.  The test results are stored
6407 in log files in the directory the script was called from.
6409 \x1f
6410 File: gdbint.info,  Node: GDB Observers,  Next: GNU Free Documentation License,  Prev: Hints,  Up: Top
6412 Appendix A GDB Currently available observers
6413 ********************************************
6415 A.1 Implementation rationale
6416 ============================
6418 An "observer" is an entity which is interested in being notified when
6419 GDB reaches certain states, or certain events occur in GDB.  The entity
6420 being observed is called the "subject".  To receive notifications, the
6421 observer attaches a callback to the subject.  One subject can have
6422 several observers.
6424    `observer.c' implements an internal generic low-level event
6425 notification mechanism.  This generic event notification mechanism is
6426 then re-used to implement the exported high-level notification
6427 management routines for all possible notifications.
6429    The current implementation of the generic observer provides support
6430 for contextual data.  This contextual data is given to the subject when
6431 attaching the callback.  In return, the subject will provide this
6432 contextual data back to the observer as a parameter of the callback.
6434    Note that the current support for the contextual data is only
6435 partial, as it lacks a mechanism that would deallocate this data when
6436 the callback is detached.  This is not a problem so far, as this
6437 contextual data is only used internally to hold a function pointer.
6438 Later on, if a certain observer needs to provide support for user-level
6439 contextual data, then the generic notification mechanism will need to be
6440 enhanced to allow the observer to provide a routine to deallocate the
6441 data when attaching the callback.
6443    The observer implementation is also currently not reentrant.  In
6444 particular, it is therefore not possible to call the attach or detach
6445 routines during a notification.
6447 A.2 Debugging
6448 =============
6450 Observer notifications can be traced using the command `set debug
6451 observer 1' (*note Optional messages about internal happenings:
6452 (gdb)Debugging Output.).
6454 A.3 `normal_stop' Notifications
6455 ===============================
6457 GDB notifies all `normal_stop' observers when the inferior execution
6458 has just stopped, the associated messages and annotations have been
6459 printed, and the control is about to be returned to the user.
6461    Note that the `normal_stop' notification is not emitted when the
6462 execution stops due to a breakpoint, and this breakpoint has a
6463 condition that is not met.  If the breakpoint has any associated
6464 commands list, the commands are executed after the notification is
6465 emitted.
6467    The following interfaces are available to manage observers:
6469  -- Function: extern struct observer *observer_attach_EVENT
6470           (observer_EVENT_ftype *F)
6471      Using the function F, create an observer that is notified when
6472      ever EVENT occurs, return the observer.
6474  -- Function: extern void observer_detach_EVENT (struct observer
6475           *OBSERVER);
6476      Remove OBSERVER from the list of observers to be notified when
6477      EVENT occurs.
6479  -- Function: extern void observer_notify_EVENT (void);
6480      Send a notification to all EVENT observers.
6482    The following observable events are defined:
6484  -- Function: void normal_stop (struct bpstats *BS)
6485      The inferior has stopped for real.
6487  -- Function: void target_changed (struct target_ops *TARGET)
6488      The target's register contents have changed.
6490  -- Function: void executable_changed (void *UNUSED_ARGS)
6491      The executable being debugged by GDB has changed: The user decided
6492      to debug a different program, or the program he was debugging has
6493      been modified since being loaded by the debugger (by being
6494      recompiled, for instance).
6496  -- Function: void inferior_created (struct target_ops *OBJFILE, int
6497           FROM_TTY)
6498      GDB has just connected to an inferior.  For `run', GDB calls this
6499      observer while the inferior is still stopped at the entry-point
6500      instruction.  For `attach' and `core', GDB calls this observer
6501      immediately after connecting to the inferior, and before any
6502      information on the inferior has been printed.
6504  -- Function: void solib_loaded (struct so_list *SOLIB)
6505      The shared library specified by SOLIB has been loaded.  Note that
6506      when GDB calls this observer, the library's symbols probably
6507      haven't been loaded yet.
6509  -- Function: void solib_unloaded (struct so_list *SOLIB)
6510      The shared library specified by SOLIB has been unloaded.
6512  -- Function: void new_objfile (struct objfile *OBJFILE)
6513      The symbol file specified by OBJFILE has been loaded.  Called with
6514      OBJFILE equal to `NULL' to indicate previously loaded symbol table
6515      data has now been invalidated.
6517 \x1f
6518 File: gdbint.info,  Node: GNU Free Documentation License,  Next: Index,  Prev: GDB Observers,  Up: Top
6520 Appendix B GNU Free Documentation License
6521 *****************************************
6523                       Version 1.2, November 2002
6525      Copyright (C) 2000,2001,2002 Free Software Foundation, Inc.
6526      51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
6528      Everyone is permitted to copy and distribute verbatim copies
6529      of this license document, but changing it is not allowed.
6531   0. PREAMBLE
6533      The purpose of this License is to make a manual, textbook, or other
6534      functional and useful document "free" in the sense of freedom: to
6535      assure everyone the effective freedom to copy and redistribute it,
6536      with or without modifying it, either commercially or
6537      noncommercially.  Secondarily, this License preserves for the
6538      author and publisher a way to get credit for their work, while not
6539      being considered responsible for modifications made by others.
6541      This License is a kind of "copyleft", which means that derivative
6542      works of the document must themselves be free in the same sense.
6543      It complements the GNU General Public License, which is a copyleft
6544      license designed for free software.
6546      We have designed this License in order to use it for manuals for
6547      free software, because free software needs free documentation: a
6548      free program should come with manuals providing the same freedoms
6549      that the software does.  But this License is not limited to
6550      software manuals; it can be used for any textual work, regardless
6551      of subject matter or whether it is published as a printed book.
6552      We recommend this License principally for works whose purpose is
6553      instruction or reference.
6555   1. APPLICABILITY AND DEFINITIONS
6557      This License applies to any manual or other work, in any medium,
6558      that contains a notice placed by the copyright holder saying it
6559      can be distributed under the terms of this License.  Such a notice
6560      grants a world-wide, royalty-free license, unlimited in duration,
6561      to use that work under the conditions stated herein.  The
6562      "Document", below, refers to any such manual or work.  Any member
6563      of the public is a licensee, and is addressed as "you".  You
6564      accept the license if you copy, modify or distribute the work in a
6565      way requiring permission under copyright law.
6567      A "Modified Version" of the Document means any work containing the
6568      Document or a portion of it, either copied verbatim, or with
6569      modifications and/or translated into another language.
6571      A "Secondary Section" is a named appendix or a front-matter section
6572      of the Document that deals exclusively with the relationship of the
6573      publishers or authors of the Document to the Document's overall
6574      subject (or to related matters) and contains nothing that could
6575      fall directly within that overall subject.  (Thus, if the Document
6576      is in part a textbook of mathematics, a Secondary Section may not
6577      explain any mathematics.)  The relationship could be a matter of
6578      historical connection with the subject or with related matters, or
6579      of legal, commercial, philosophical, ethical or political position
6580      regarding them.
6582      The "Invariant Sections" are certain Secondary Sections whose
6583      titles are designated, as being those of Invariant Sections, in
6584      the notice that says that the Document is released under this
6585      License.  If a section does not fit the above definition of
6586      Secondary then it is not allowed to be designated as Invariant.
6587      The Document may contain zero Invariant Sections.  If the Document
6588      does not identify any Invariant Sections then there are none.
6590      The "Cover Texts" are certain short passages of text that are
6591      listed, as Front-Cover Texts or Back-Cover Texts, in the notice
6592      that says that the Document is released under this License.  A
6593      Front-Cover Text may be at most 5 words, and a Back-Cover Text may
6594      be at most 25 words.
6596      A "Transparent" copy of the Document means a machine-readable copy,
6597      represented in a format whose specification is available to the
6598      general public, that is suitable for revising the document
6599      straightforwardly with generic text editors or (for images
6600      composed of pixels) generic paint programs or (for drawings) some
6601      widely available drawing editor, and that is suitable for input to
6602      text formatters or for automatic translation to a variety of
6603      formats suitable for input to text formatters.  A copy made in an
6604      otherwise Transparent file format whose markup, or absence of
6605      markup, has been arranged to thwart or discourage subsequent
6606      modification by readers is not Transparent.  An image format is
6607      not Transparent if used for any substantial amount of text.  A
6608      copy that is not "Transparent" is called "Opaque".
6610      Examples of suitable formats for Transparent copies include plain
6611      ASCII without markup, Texinfo input format, LaTeX input format,
6612      SGML or XML using a publicly available DTD, and
6613      standard-conforming simple HTML, PostScript or PDF designed for
6614      human modification.  Examples of transparent image formats include
6615      PNG, XCF and JPG.  Opaque formats include proprietary formats that
6616      can be read and edited only by proprietary word processors, SGML or
6617      XML for which the DTD and/or processing tools are not generally
6618      available, and the machine-generated HTML, PostScript or PDF
6619      produced by some word processors for output purposes only.
6621      The "Title Page" means, for a printed book, the title page itself,
6622      plus such following pages as are needed to hold, legibly, the
6623      material this License requires to appear in the title page.  For
6624      works in formats which do not have any title page as such, "Title
6625      Page" means the text near the most prominent appearance of the
6626      work's title, preceding the beginning of the body of the text.
6628      A section "Entitled XYZ" means a named subunit of the Document
6629      whose title either is precisely XYZ or contains XYZ in parentheses
6630      following text that translates XYZ in another language.  (Here XYZ
6631      stands for a specific section name mentioned below, such as
6632      "Acknowledgements", "Dedications", "Endorsements", or "History".)
6633      To "Preserve the Title" of such a section when you modify the
6634      Document means that it remains a section "Entitled XYZ" according
6635      to this definition.
6637      The Document may include Warranty Disclaimers next to the notice
6638      which states that this License applies to the Document.  These
6639      Warranty Disclaimers are considered to be included by reference in
6640      this License, but only as regards disclaiming warranties: any other
6641      implication that these Warranty Disclaimers may have is void and
6642      has no effect on the meaning of this License.
6644   2. VERBATIM COPYING
6646      You may copy and distribute the Document in any medium, either
6647      commercially or noncommercially, provided that this License, the
6648      copyright notices, and the license notice saying this License
6649      applies to the Document are reproduced in all copies, and that you
6650      add no other conditions whatsoever to those of this License.  You
6651      may not use technical measures to obstruct or control the reading
6652      or further copying of the copies you make or distribute.  However,
6653      you may accept compensation in exchange for copies.  If you
6654      distribute a large enough number of copies you must also follow
6655      the conditions in section 3.
6657      You may also lend copies, under the same conditions stated above,
6658      and you may publicly display copies.
6660   3. COPYING IN QUANTITY
6662      If you publish printed copies (or copies in media that commonly
6663      have printed covers) of the Document, numbering more than 100, and
6664      the Document's license notice requires Cover Texts, you must
6665      enclose the copies in covers that carry, clearly and legibly, all
6666      these Cover Texts: Front-Cover Texts on the front cover, and
6667      Back-Cover Texts on the back cover.  Both covers must also clearly
6668      and legibly identify you as the publisher of these copies.  The
6669      front cover must present the full title with all words of the
6670      title equally prominent and visible.  You may add other material
6671      on the covers in addition.  Copying with changes limited to the
6672      covers, as long as they preserve the title of the Document and
6673      satisfy these conditions, can be treated as verbatim copying in
6674      other respects.
6676      If the required texts for either cover are too voluminous to fit
6677      legibly, you should put the first ones listed (as many as fit
6678      reasonably) on the actual cover, and continue the rest onto
6679      adjacent pages.
6681      If you publish or distribute Opaque copies of the Document
6682      numbering more than 100, you must either include a
6683      machine-readable Transparent copy along with each Opaque copy, or
6684      state in or with each Opaque copy a computer-network location from
6685      which the general network-using public has access to download
6686      using public-standard network protocols a complete Transparent
6687      copy of the Document, free of added material.  If you use the
6688      latter option, you must take reasonably prudent steps, when you
6689      begin distribution of Opaque copies in quantity, to ensure that
6690      this Transparent copy will remain thus accessible at the stated
6691      location until at least one year after the last time you
6692      distribute an Opaque copy (directly or through your agents or
6693      retailers) of that edition to the public.
6695      It is requested, but not required, that you contact the authors of
6696      the Document well before redistributing any large number of
6697      copies, to give them a chance to provide you with an updated
6698      version of the Document.
6700   4. MODIFICATIONS
6702      You may copy and distribute a Modified Version of the Document
6703      under the conditions of sections 2 and 3 above, provided that you
6704      release the Modified Version under precisely this License, with
6705      the Modified Version filling the role of the Document, thus
6706      licensing distribution and modification of the Modified Version to
6707      whoever possesses a copy of it.  In addition, you must do these
6708      things in the Modified Version:
6710        A. Use in the Title Page (and on the covers, if any) a title
6711           distinct from that of the Document, and from those of
6712           previous versions (which should, if there were any, be listed
6713           in the History section of the Document).  You may use the
6714           same title as a previous version if the original publisher of
6715           that version gives permission.
6717        B. List on the Title Page, as authors, one or more persons or
6718           entities responsible for authorship of the modifications in
6719           the Modified Version, together with at least five of the
6720           principal authors of the Document (all of its principal
6721           authors, if it has fewer than five), unless they release you
6722           from this requirement.
6724        C. State on the Title page the name of the publisher of the
6725           Modified Version, as the publisher.
6727        D. Preserve all the copyright notices of the Document.
6729        E. Add an appropriate copyright notice for your modifications
6730           adjacent to the other copyright notices.
6732        F. Include, immediately after the copyright notices, a license
6733           notice giving the public permission to use the Modified
6734           Version under the terms of this License, in the form shown in
6735           the Addendum below.
6737        G. Preserve in that license notice the full lists of Invariant
6738           Sections and required Cover Texts given in the Document's
6739           license notice.
6741        H. Include an unaltered copy of this License.
6743        I. Preserve the section Entitled "History", Preserve its Title,
6744           and add to it an item stating at least the title, year, new
6745           authors, and publisher of the Modified Version as given on
6746           the Title Page.  If there is no section Entitled "History" in
6747           the Document, create one stating the title, year, authors,
6748           and publisher of the Document as given on its Title Page,
6749           then add an item describing the Modified Version as stated in
6750           the previous sentence.
6752        J. Preserve the network location, if any, given in the Document
6753           for public access to a Transparent copy of the Document, and
6754           likewise the network locations given in the Document for
6755           previous versions it was based on.  These may be placed in
6756           the "History" section.  You may omit a network location for a
6757           work that was published at least four years before the
6758           Document itself, or if the original publisher of the version
6759           it refers to gives permission.
6761        K. For any section Entitled "Acknowledgements" or "Dedications",
6762           Preserve the Title of the section, and preserve in the
6763           section all the substance and tone of each of the contributor
6764           acknowledgements and/or dedications given therein.
6766        L. Preserve all the Invariant Sections of the Document,
6767           unaltered in their text and in their titles.  Section numbers
6768           or the equivalent are not considered part of the section
6769           titles.
6771        M. Delete any section Entitled "Endorsements".  Such a section
6772           may not be included in the Modified Version.
6774        N. Do not retitle any existing section to be Entitled
6775           "Endorsements" or to conflict in title with any Invariant
6776           Section.
6778        O. Preserve any Warranty Disclaimers.
6780      If the Modified Version includes new front-matter sections or
6781      appendices that qualify as Secondary Sections and contain no
6782      material copied from the Document, you may at your option
6783      designate some or all of these sections as invariant.  To do this,
6784      add their titles to the list of Invariant Sections in the Modified
6785      Version's license notice.  These titles must be distinct from any
6786      other section titles.
6788      You may add a section Entitled "Endorsements", provided it contains
6789      nothing but endorsements of your Modified Version by various
6790      parties--for example, statements of peer review or that the text
6791      has been approved by an organization as the authoritative
6792      definition of a standard.
6794      You may add a passage of up to five words as a Front-Cover Text,
6795      and a passage of up to 25 words as a Back-Cover Text, to the end
6796      of the list of Cover Texts in the Modified Version.  Only one
6797      passage of Front-Cover Text and one of Back-Cover Text may be
6798      added by (or through arrangements made by) any one entity.  If the
6799      Document already includes a cover text for the same cover,
6800      previously added by you or by arrangement made by the same entity
6801      you are acting on behalf of, you may not add another; but you may
6802      replace the old one, on explicit permission from the previous
6803      publisher that added the old one.
6805      The author(s) and publisher(s) of the Document do not by this
6806      License give permission to use their names for publicity for or to
6807      assert or imply endorsement of any Modified Version.
6809   5. COMBINING DOCUMENTS
6811      You may combine the Document with other documents released under
6812      this License, under the terms defined in section 4 above for
6813      modified versions, provided that you include in the combination
6814      all of the Invariant Sections of all of the original documents,
6815      unmodified, and list them all as Invariant Sections of your
6816      combined work in its license notice, and that you preserve all
6817      their Warranty Disclaimers.
6819      The combined work need only contain one copy of this License, and
6820      multiple identical Invariant Sections may be replaced with a single
6821      copy.  If there are multiple Invariant Sections with the same name
6822      but different contents, make the title of each such section unique
6823      by adding at the end of it, in parentheses, the name of the
6824      original author or publisher of that section if known, or else a
6825      unique number.  Make the same adjustment to the section titles in
6826      the list of Invariant Sections in the license notice of the
6827      combined work.
6829      In the combination, you must combine any sections Entitled
6830      "History" in the various original documents, forming one section
6831      Entitled "History"; likewise combine any sections Entitled
6832      "Acknowledgements", and any sections Entitled "Dedications".  You
6833      must delete all sections Entitled "Endorsements."
6835   6. COLLECTIONS OF DOCUMENTS
6837      You may make a collection consisting of the Document and other
6838      documents released under this License, and replace the individual
6839      copies of this License in the various documents with a single copy
6840      that is included in the collection, provided that you follow the
6841      rules of this License for verbatim copying of each of the
6842      documents in all other respects.
6844      You may extract a single document from such a collection, and
6845      distribute it individually under this License, provided you insert
6846      a copy of this License into the extracted document, and follow
6847      this License in all other respects regarding verbatim copying of
6848      that document.
6850   7. AGGREGATION WITH INDEPENDENT WORKS
6852      A compilation of the Document or its derivatives with other
6853      separate and independent documents or works, in or on a volume of
6854      a storage or distribution medium, is called an "aggregate" if the
6855      copyright resulting from the compilation is not used to limit the
6856      legal rights of the compilation's users beyond what the individual
6857      works permit.  When the Document is included in an aggregate, this
6858      License does not apply to the other works in the aggregate which
6859      are not themselves derivative works of the Document.
6861      If the Cover Text requirement of section 3 is applicable to these
6862      copies of the Document, then if the Document is less than one half
6863      of the entire aggregate, the Document's Cover Texts may be placed
6864      on covers that bracket the Document within the aggregate, or the
6865      electronic equivalent of covers if the Document is in electronic
6866      form.  Otherwise they must appear on printed covers that bracket
6867      the whole aggregate.
6869   8. TRANSLATION
6871      Translation is considered a kind of modification, so you may
6872      distribute translations of the Document under the terms of section
6873      4.  Replacing Invariant Sections with translations requires special
6874      permission from their copyright holders, but you may include
6875      translations of some or all Invariant Sections in addition to the
6876      original versions of these Invariant Sections.  You may include a
6877      translation of this License, and all the license notices in the
6878      Document, and any Warranty Disclaimers, provided that you also
6879      include the original English version of this License and the
6880      original versions of those notices and disclaimers.  In case of a
6881      disagreement between the translation and the original version of
6882      this License or a notice or disclaimer, the original version will
6883      prevail.
6885      If a section in the Document is Entitled "Acknowledgements",
6886      "Dedications", or "History", the requirement (section 4) to
6887      Preserve its Title (section 1) will typically require changing the
6888      actual title.
6890   9. TERMINATION
6892      You may not copy, modify, sublicense, or distribute the Document
6893      except as expressly provided for under this License.  Any other
6894      attempt to copy, modify, sublicense or distribute the Document is
6895      void, and will automatically terminate your rights under this
6896      License.  However, parties who have received copies, or rights,
6897      from you under this License will not have their licenses
6898      terminated so long as such parties remain in full compliance.
6900  10. FUTURE REVISIONS OF THIS LICENSE
6902      The Free Software Foundation may publish new, revised versions of
6903      the GNU Free Documentation License from time to time.  Such new
6904      versions will be similar in spirit to the present version, but may
6905      differ in detail to address new problems or concerns.  See
6906      `http://www.gnu.org/copyleft/'.
6908      Each version of the License is given a distinguishing version
6909      number.  If the Document specifies that a particular numbered
6910      version of this License "or any later version" applies to it, you
6911      have the option of following the terms and conditions either of
6912      that specified version or of any later version that has been
6913      published (not as a draft) by the Free Software Foundation.  If
6914      the Document does not specify a version number of this License,
6915      you may choose any version ever published (not as a draft) by the
6916      Free Software Foundation.
6918 B.1 ADDENDUM: How to use this License for your documents
6919 ========================================================
6921 To use this License in a document you have written, include a copy of
6922 the License in the document and put the following copyright and license
6923 notices just after the title page:
6925        Copyright (C)  YEAR  YOUR NAME.
6926        Permission is granted to copy, distribute and/or modify this document
6927        under the terms of the GNU Free Documentation License, Version 1.2
6928        or any later version published by the Free Software Foundation;
6929        with no Invariant Sections, no Front-Cover Texts, and no Back-Cover
6930        Texts.  A copy of the license is included in the section entitled ``GNU
6931        Free Documentation License''.
6933    If you have Invariant Sections, Front-Cover Texts and Back-Cover
6934 Texts, replace the "with...Texts." line with this:
6936          with the Invariant Sections being LIST THEIR TITLES, with
6937          the Front-Cover Texts being LIST, and with the Back-Cover Texts
6938          being LIST.
6940    If you have Invariant Sections without Cover Texts, or some other
6941 combination of the three, merge those two alternatives to suit the
6942 situation.
6944    If your document contains nontrivial examples of program code, we
6945 recommend releasing these examples in parallel under your choice of
6946 free software license, such as the GNU General Public License, to
6947 permit their use in free software.