1 This is gdbint.info, produced by makeinfo version 4.8 from
2 ../.././gdb/doc/gdbint.texinfo.
4 INFO-DIR-SECTION Software development
6 * Gdb-Internals: (gdbint). The GNU debugger's internals.
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".
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.
42 * Target Architecture Definition::
43 * Target Vector Definition::
48 * Versions and Branches::
49 * Start of New Year Procedure::
54 * GDB Observers:: GDB Currently available observers
55 * GNU Free Documentation License:: The license for this documentation
59 File: gdbint.info, Node: Requirements, Next: Overall Structure, Prev: Top, Up: Top
64 Before diving into the internals, you should understand the formal
65 requirements and other expectations for GDB. Although some of these
66 may seem obvious, there have been proposals for GDB that have run
67 counter to these requirements.
69 First of all, GDB is a debugger. It's not designed to be a front
70 panel for embedded systems. It's not a text editor. It's not a shell.
71 It's not a programming environment.
73 GDB is an interactive tool. Although a batch mode is available,
74 GDB's primary role is to interact with a human programmer.
76 GDB should be responsive to the user. A programmer hot on the trail
77 of a nasty bug, and operating under a looming deadline, is going to be
78 very impatient of everything, including the response time to debugger
81 GDB should be relatively permissive, such as for expressions. While
82 the compiler should be picky (or have the option to be made picky),
83 since source code lives for a long time usually, the programmer doing
84 debugging shouldn't be spending time figuring out to mollify the
87 GDB will be called upon to deal with really large programs.
88 Executable sizes of 50 to 100 megabytes occur regularly, and we've
89 heard reports of programs approaching 1 gigabyte in size.
91 GDB should be able to run everywhere. No other debugger is
92 available for even half as many configurations as GDB supports.
95 File: gdbint.info, Node: Overall Structure, Next: Algorithms, Prev: Requirements, Up: Top
100 GDB consists of three major subsystems: user interface, symbol handling
101 (the "symbol side"), and target system handling (the "target side").
103 The user interface consists of several actual interfaces, plus
106 The symbol side consists of object file readers, debugging info
107 interpreters, symbol table management, source language expression
108 parsing, type and value printing.
110 The target side consists of execution control, stack frame analysis,
111 and physical target manipulation.
113 The target side/symbol side division is not formal, and there are a
114 number of exceptions. For instance, core file support involves symbolic
115 elements (the basic core file reader is in BFD) and target elements (it
116 supplies the contents of memory and the values of registers). Instead,
117 this division is useful for understanding how the minor subsystems
123 The symbolic side of GDB can be thought of as "everything you can do in
124 GDB without having a live program running". For instance, you can look
125 at the types of variables, and evaluate many kinds of expressions.
130 The target side of GDB is the "bits and bytes manipulator". Although
131 it may make reference to symbolic info here and there, most of the
132 target side will run with only a stripped executable available--or even
133 no executable at all, in remote debugging cases.
135 Operations such as disassembly, stack frame crawls, and register
136 display, are able to work with no symbolic info at all. In some cases,
137 such as disassembly, GDB will use symbolic info to present addresses
138 relative to symbols rather than as raw numbers, but it will work either
144 "Host" refers to attributes of the system where GDB runs. "Target"
145 refers to the system where the program being debugged executes. In
146 most cases they are the same machine, in which case a third type of
147 "Native" attributes come into play.
149 Defines and include files needed to build on the host are host
150 support. Examples are tty support, system defined types, host byte
151 order, host float format.
153 Defines and information needed to handle the target format are target
154 dependent. Examples are the stack frame format, instruction set,
155 breakpoint instruction, registers, and how to set up and tear down the
156 stack to call a function.
158 Information that is only needed when the host and target are the
159 same, is native dependent. One example is Unix child process support;
160 if the host and target are not the same, doing a fork to start the
161 target process is a bad idea. The various macros needed for finding the
162 registers in the `upage', running `ptrace', and such are all in the
163 native-dependent files.
165 Another example of native-dependent code is support for features that
166 are really part of the target environment, but which require `#include'
167 files that are only available on the host system. Core file handling
168 and `setjmp' handling are two common cases.
170 When you want to make GDB work "native" on a particular machine, you
171 have to include all three kinds of information.
174 File: gdbint.info, Node: Algorithms, Next: User Interface, Prev: Overall Structure, Up: Top
179 GDB uses a number of debugging-specific algorithms. They are often not
180 very complicated, but get lost in the thicket of special cases and
181 real-world issues. This chapter describes the basic algorithms and
182 mentions some of the specific target definitions that they use.
187 A frame is a construct that GDB uses to keep track of calling and
190 GDB's frame model, a fresh design, was implemented with the need to
191 support DWARF's Call Frame Information in mind. In fact, the term
192 "unwind" is taken directly from that specification. Developers wishing
193 to learn more about unwinders, are encouraged to read the the DWARF
196 GDB's model is that you find a frame's registers by "unwinding" them
197 from the next younger frame. That is, `get_frame_register' which
198 returns the value of a register in frame #1 (the next-to-youngest
199 frame), is implemented by calling frame #0's `frame_register_unwind'
200 (the youngest frame). But then the obvious question is: how do you
201 access the registers of the youngest frame itself?
203 To answer this question, GDB has the "sentinel" frame, the "-1st"
204 frame. Unwinding registers from the sentinel frame gives you the
205 current values of the youngest real frame's registers. If F is a
206 sentinel frame, then `get_frame_type (F) == SENTINEL_FRAME'.
208 3.2 Prologue Analysis
209 =====================
211 To produce a backtrace and allow the user to manipulate older frames'
212 variables and arguments, GDB needs to find the base addresses of older
213 frames, and discover where those frames' registers have been saved.
214 Since a frame's "callee-saves" registers get saved by younger frames if
215 and when they're reused, a frame's registers may be scattered
216 unpredictably across younger frames. This means that changing the
217 value of a register-allocated variable in an older frame may actually
218 entail writing to a save slot in some younger frame.
220 Modern versions of GCC emit Dwarf call frame information ("CFI"),
221 which describes how to find frame base addresses and saved registers.
222 But CFI is not always available, so as a fallback GDB uses a technique
223 called "prologue analysis" to find frame sizes and saved registers. A
224 prologue analyzer disassembles the function's machine code starting
225 from its entry point, and looks for instructions that allocate frame
226 space, save the stack pointer in a frame pointer register, save
227 registers, and so on. Obviously, this can't be done accurately in
228 general, but it's tractible to do well enough to be very helpful.
229 Prologue analysis predates the GNU toolchain's support for CFI; at one
230 time, prologue analysis was the only mechanism GDB used for stack
231 unwinding at all, when the function calling conventions didn't specify
232 a fixed frame layout.
234 In the olden days, function prologues were generated by hand-written,
235 target-specific code in GCC, and treated as opaque and untouchable by
236 optimizers. Looking at this code, it was usually straightforward to
237 write a prologue analyzer for GDB that would accurately understand all
238 the prologues GCC would generate. However, over time GCC became more
239 aggressive about instruction scheduling, and began to understand more
240 about the semantics of the prologue instructions themselves; in
241 response, GDB's analyzers became more complex and fragile. Keeping the
242 prologue analyzers working as GCC (and the instruction sets themselves)
243 evolved became a substantial task.
245 To try to address this problem, the code in `prologue-value.h' and
246 `prologue-value.c' provides a general framework for writing prologue
247 analyzers that are simpler and more robust than ad-hoc analyzers. When
248 we analyze a prologue using the prologue-value framework, we're really
249 doing "abstract interpretation" or "pseudo-evaluation": running the
250 function's code in simulation, but using conservative approximations of
251 the values registers and memory would hold when the code actually runs.
252 For example, if our function starts with the instruction:
254 addi r1, 42 # add 42 to r1
255 we don't know exactly what value will be in `r1' after executing
256 this instruction, but we do know it'll be 42 greater than its original
259 If we then see an instruction like:
261 addi r1, 22 # add 22 to r1
262 we still don't know what `r1's' value is, but again, we can say it
263 is now 64 greater than its original value.
265 If the next instruction were:
267 mov r2, r1 # set r2 to r1's value
268 then we can say that `r2's' value is now the original value of `r1'
271 It's common for prologues to save registers on the stack, so we'll
272 need to track the values of stack frame slots, as well as the
273 registers. So after an instruction like this:
276 then we'd know that the stack slot four bytes above the frame pointer
277 holds the original value of `r1' plus 64.
281 Of course, this can only go so far before it gets unreasonable. If
282 we wanted to be able to say anything about the value of `r1' after the
285 xor r1, r3 # exclusive-or r1 and r3, place result in r1
286 then things would get pretty complex. But remember, we're just doing
287 a conservative approximation; if exclusive-or instructions aren't
288 relevant to prologues, we can just say `r1''s value is now "unknown".
289 We can ignore things that are too complex, if that loss of information
290 is acceptable for our application.
292 So when we say "conservative approximation" here, what we mean is an
293 approximation that is either accurate, or marked "unknown", but never
296 Using this framework, a prologue analyzer is simply an interpreter
297 for machine code, but one that uses conservative approximations for the
298 contents of registers and memory instead of actual values. Starting
299 from the function's entry point, you simulate instructions up to the
300 current PC, or an instruction that you don't know how to simulate. Now
301 you can examine the state of the registers and stack slots you've kept
304 * To see how large your stack frame is, just check the value of the
305 stack pointer register; if it's the original value of the SP minus
306 a constant, then that constant is the stack frame's size. If the
307 SP's value has been marked as "unknown", then that means the
308 prologue has done something too complex for us to track, and we
309 don't know the frame size.
311 * To see where we've saved the previous frame's registers, we just
312 search the values we've tracked -- stack slots, usually, but
313 registers, too, if you want -- for something equal to the
314 register's original value. If the calling conventions suggest a
315 standard place to save a given register, then we can check there
316 first, but really, anything that will get us back the original
317 value will probably work.
319 This does take some work. But prologue analyzers aren't
320 quick-and-simple pattern patching to recognize a few fixed prologue
321 forms any more; they're big, hairy functions. Along with inferior
322 function calls, prologue analysis accounts for a substantial portion of
323 the time needed to stabilize a GDB port. So it's worthwhile to look
324 for an approach that will be easier to understand and maintain. In the
325 approach described above:
327 * It's easier to see that the analyzer is correct: you just see
328 whether the analyzer properly (albiet conservatively) simulates
329 the effect of each instruction.
331 * It's easier to extend the analyzer: you can add support for new
332 instructions, and know that you haven't broken anything that
333 wasn't already broken before.
335 * It's orthogonal: to gather new information, you don't need to
336 complicate the code for each instruction. As long as your domain
337 of conservative values is already detailed enough to tell you what
338 you need, then all the existing instruction simulations are
339 already gathering the right data for you.
342 The file `prologue-value.h' contains detailed comments explaining
343 the framework and how to use it.
345 3.3 Breakpoint Handling
346 =======================
348 In general, a breakpoint is a user-designated location in the program
349 where the user wants to regain control if program execution ever reaches
352 There are two main ways to implement breakpoints; either as
353 "hardware" breakpoints or as "software" breakpoints.
355 Hardware breakpoints are sometimes available as a builtin debugging
356 features with some chips. Typically these work by having dedicated
357 register into which the breakpoint address may be stored. If the PC
358 (shorthand for "program counter") ever matches a value in a breakpoint
359 registers, the CPU raises an exception and reports it to GDB.
361 Another possibility is when an emulator is in use; many emulators
362 include circuitry that watches the address lines coming out from the
363 processor, and force it to stop if the address matches a breakpoint's
366 A third possibility is that the target already has the ability to do
367 breakpoints somehow; for instance, a ROM monitor may do its own
368 software breakpoints. So although these are not literally "hardware
369 breakpoints", from GDB's point of view they work the same; GDB need not
370 do anything more than set the breakpoint and wait for something to
373 Since they depend on hardware resources, hardware breakpoints may be
374 limited in number; when the user asks for more, GDB will start trying
375 to set software breakpoints. (On some architectures, notably the
376 32-bit x86 platforms, GDB cannot always know whether there's enough
377 hardware resources to insert all the hardware breakpoints and
378 watchpoints. On those platforms, GDB prints an error message only when
379 the program being debugged is continued.)
381 Software breakpoints require GDB to do somewhat more work. The
382 basic theory is that GDB will replace a program instruction with a
383 trap, illegal divide, or some other instruction that will cause an
384 exception, and then when it's encountered, GDB will take the exception
385 and stop the program. When the user says to continue, GDB will restore
386 the original instruction, single-step, re-insert the trap, and continue
389 Since it literally overwrites the program being tested, the program
390 area must be writable, so this technique won't work on programs in ROM.
391 It can also distort the behavior of programs that examine themselves,
392 although such a situation would be highly unusual.
394 Also, the software breakpoint instruction should be the smallest
395 size of instruction, so it doesn't overwrite an instruction that might
396 be a jump target, and cause disaster when the program jumps into the
397 middle of the breakpoint instruction. (Strictly speaking, the
398 breakpoint must be no larger than the smallest interval between
399 instructions that may be jump targets; perhaps there is an architecture
400 where only even-numbered instructions may jumped to.) Note that it's
401 possible for an instruction set not to have any instructions usable for
402 a software breakpoint, although in practice only the ARC has failed to
403 define such an instruction.
405 The basic definition of the software breakpoint is the macro
408 Basic breakpoint object handling is in `breakpoint.c'. However,
409 much of the interesting breakpoint action is in `infrun.c'.
411 `target_remove_breakpoint (BP_TGT)'
412 `target_insert_breakpoint (BP_TGT)'
413 Insert or remove a software breakpoint at address
414 `BP_TGT->placed_address'. Returns zero for success, non-zero for
415 failure. On input, BP_TGT contains the address of the breakpoint,
416 and is otherwise initialized to zero. The fields of the `struct
417 bp_target_info' pointed to by BP_TGT are updated to contain other
418 information about the breakpoint on output. The field
419 `placed_address' may be updated if the breakpoint was placed at a
420 related address; the field `shadow_contents' contains the real
421 contents of the bytes where the breakpoint has been inserted, if
422 reading memory would return the breakpoint instead of the
423 underlying memory; the field `shadow_len' is the length of memory
424 cached in `shadow_contents', if any; and the field `placed_size'
425 is optionally set and used by the target, if it could differ from
428 For example, the remote target `Z0' packet does not require
429 shadowing memory, so `shadow_len' is left at zero. However, the
430 length reported by `BREAKPOINT_FROM_PC' is cached in
431 `placed_size', so that a matching `z0' packet can be used to
432 remove the breakpoint.
434 `target_remove_hw_breakpoint (BP_TGT)'
435 `target_insert_hw_breakpoint (BP_TGT)'
436 Insert or remove a hardware-assisted breakpoint at address
437 `BP_TGT->placed_address'. Returns zero for success, non-zero for
438 failure. See `target_insert_breakpoint' for a description of the
439 `struct bp_target_info' pointed to by BP_TGT; the
440 `shadow_contents' and `shadow_len' members are not used for
441 hardware breakpoints, but `placed_size' may be.
452 3.7 Inferior Function Calls
453 ===========================
458 GDB has support for figuring out that the target is doing a `longjmp'
459 and for stopping at the target of the jump, if we are stepping. This
460 is done with a few specialized internal breakpoints, which are visible
461 in the output of the `maint info breakpoint' command.
463 To make this work, you need to define a macro called
464 `GET_LONGJMP_TARGET', which will examine the `jmp_buf' structure and
465 extract the longjmp target address. Since `jmp_buf' is target
466 specific, you will need to define it in the appropriate `tm-TARGET.h'
467 file. Look in `tm-sun4os4.h' and `sparc-tdep.c' for examples of how to
473 Watchpoints are a special kind of breakpoints (*note breakpoints:
474 Algorithms.) which break when data is accessed rather than when some
475 instruction is executed. When you have data which changes without your
476 knowing what code does that, watchpoints are the silver bullet to hunt
477 down and kill such bugs.
479 Watchpoints can be either hardware-assisted or not; the latter type
480 is known as "software watchpoints." GDB always uses hardware-assisted
481 watchpoints if they are available, and falls back on software
482 watchpoints otherwise. Typical situations where GDB will use software
485 * The watched memory region is too large for the underlying hardware
486 watchpoint support. For example, each x86 debug register can
487 watch up to 4 bytes of memory, so trying to watch data structures
488 whose size is more than 16 bytes will cause GDB to use software
491 * The value of the expression to be watched depends on data held in
492 registers (as opposed to memory).
494 * Too many different watchpoints requested. (On some architectures,
495 this situation is impossible to detect until the debugged program
496 is resumed.) Note that x86 debug registers are used both for
497 hardware breakpoints and for watchpoints, so setting too many
498 hardware breakpoints might cause watchpoint insertion to fail.
500 * No hardware-assisted watchpoints provided by the target
503 Software watchpoints are very slow, since GDB needs to single-step
504 the program being debugged and test the value of the watched
505 expression(s) after each instruction. The rest of this section is
506 mostly irrelevant for software watchpoints.
508 When the inferior stops, GDB tries to establish, among other
509 possible reasons, whether it stopped due to a watchpoint being hit.
510 For a data-write watchpoint, it does so by evaluating, for each
511 watchpoint, the expression whose value is being watched, and testing
512 whether the watched value has changed. For data-read and data-access
513 watchpoints, GDB needs the target to supply a primitive that returns
514 the address of the data that was accessed or read (see the description
515 of `target_stopped_data_address' below): if this primitive returns a
516 valid address, GDB infers that a watchpoint triggered if it watches an
517 expression whose evaluation uses that address.
519 GDB uses several macros and primitives to support hardware
522 `TARGET_HAS_HARDWARE_WATCHPOINTS'
523 If defined, the target supports hardware watchpoints.
525 `TARGET_CAN_USE_HARDWARE_WATCHPOINT (TYPE, COUNT, OTHER)'
526 Return the number of hardware watchpoints of type TYPE that are
527 possible to be set. The value is positive if COUNT watchpoints of
528 this type can be set, zero if setting watchpoints of this type is
529 not supported, and negative if COUNT is more than the maximum
530 number of watchpoints of type TYPE that can be set. OTHER is
531 non-zero if other types of watchpoints are currently enabled (there
532 are architectures which cannot set watchpoints of different types
535 `TARGET_REGION_OK_FOR_HW_WATCHPOINT (ADDR, LEN)'
536 Return non-zero if hardware watchpoints can be used to watch a
537 region whose address is ADDR and whose length in bytes is LEN.
539 `target_insert_watchpoint (ADDR, LEN, TYPE)'
540 `target_remove_watchpoint (ADDR, LEN, TYPE)'
541 Insert or remove a hardware watchpoint starting at ADDR, for LEN
542 bytes. TYPE is the watchpoint type, one of the possible values of
543 the enumerated data type `target_hw_bp_type', defined by
544 `breakpoint.h' as follows:
546 enum target_hw_bp_type
548 hw_write = 0, /* Common (write) HW watchpoint */
549 hw_read = 1, /* Read HW watchpoint */
550 hw_access = 2, /* Access (read or write) HW watchpoint */
551 hw_execute = 3 /* Execute HW breakpoint */
554 These two macros should return 0 for success, non-zero for failure.
556 `target_stopped_data_address (ADDR_P)'
557 If the inferior has some watchpoint that triggered, place the
558 address associated with the watchpoint at the location pointed to
559 by ADDR_P and return non-zero. Otherwise, return zero. Note that
560 this primitive is used by GDB only on targets that support
561 data-read or data-access type watchpoints, so targets that have
562 support only for data-write watchpoints need not implement these
565 `HAVE_STEPPABLE_WATCHPOINT'
566 If defined to a non-zero value, it is not necessary to disable a
567 watchpoint to step over it.
569 `HAVE_NONSTEPPABLE_WATCHPOINT'
570 If defined to a non-zero value, GDB should disable a watchpoint to
571 step the inferior over it.
573 `HAVE_CONTINUABLE_WATCHPOINT'
574 If defined to a non-zero value, it is possible to continue the
575 inferior after a watchpoint has been hit.
577 `CANNOT_STEP_HW_WATCHPOINTS'
578 If this is defined to a non-zero value, GDB will remove all
579 watchpoints before stepping the inferior.
581 `STOPPED_BY_WATCHPOINT (WAIT_STATUS)'
582 Return non-zero if stopped by a watchpoint. WAIT_STATUS is of the
583 type `struct target_waitstatus', defined by `target.h'. Normally,
584 this macro is defined to invoke the function pointed to by the
585 `to_stopped_by_watchpoint' member of the structure (of the type
586 `target_ops', defined on `target.h') that describes the
587 target-specific operations; `to_stopped_by_watchpoint' ignores the
588 WAIT_STATUS argument.
590 GDB does not require the non-zero value returned by
591 `STOPPED_BY_WATCHPOINT' to be 100% correct, so if a target cannot
592 determine for sure whether the inferior stopped due to a
593 watchpoint, it could return non-zero "just in case".
595 3.9.1 x86 Watchpoints
596 ---------------------
598 The 32-bit Intel x86 (a.k.a. ia32) processors feature special debug
599 registers designed to facilitate debugging. GDB provides a generic
600 library of functions that x86-based ports can use to implement support
601 for watchpoints and hardware-assisted breakpoints. This subsection
602 documents the x86 watchpoint facilities in GDB.
604 To use the generic x86 watchpoint support, a port should do the
607 * Define the macro `I386_USE_GENERIC_WATCHPOINTS' somewhere in the
608 target-dependent headers.
610 * Include the `config/i386/nm-i386.h' header file _after_ defining
611 `I386_USE_GENERIC_WATCHPOINTS'.
613 * Add `i386-nat.o' to the value of the Make variable `NATDEPFILES'
614 (*note NATDEPFILES: Native Debugging.) or `TDEPFILES' (*note
615 TDEPFILES: Target Architecture Definition.).
617 * Provide implementations for the `I386_DR_LOW_*' macros described
618 below. Typically, each macro should call a target-specific
619 function which does the real work.
621 The x86 watchpoint support works by maintaining mirror images of the
622 debug registers. Values are copied between the mirror images and the
623 real debug registers via a set of macros which each target needs to
626 `I386_DR_LOW_SET_CONTROL (VAL)'
627 Set the Debug Control (DR7) register to the value VAL.
629 `I386_DR_LOW_SET_ADDR (IDX, ADDR)'
630 Put the address ADDR into the debug register number IDX.
632 `I386_DR_LOW_RESET_ADDR (IDX)'
633 Reset (i.e. zero out) the address stored in the debug register
636 `I386_DR_LOW_GET_STATUS'
637 Return the value of the Debug Status (DR6) register. This value is
638 used immediately after it is returned by `I386_DR_LOW_GET_STATUS',
639 so as to support per-thread status register values.
641 For each one of the 4 debug registers (whose indices are from 0 to 3)
642 that store addresses, a reference count is maintained by GDB, to allow
643 sharing of debug registers by several watchpoints. This allows users
644 to define several watchpoints that watch the same expression, but with
645 different conditions and/or commands, without wasting debug registers
646 which are in short supply. GDB maintains the reference counts
647 internally, targets don't have to do anything to use this feature.
649 The x86 debug registers can each watch a region that is 1, 2, or 4
650 bytes long. The ia32 architecture requires that each watched region be
651 appropriately aligned: 2-byte region on 2-byte boundary, 4-byte region
652 on 4-byte boundary. However, the x86 watchpoint support in GDB can
653 watch unaligned regions and regions larger than 4 bytes (up to 16
654 bytes) by allocating several debug registers to watch a single region.
655 This allocation of several registers per a watched region is also done
656 automatically without target code intervention.
658 The generic x86 watchpoint support provides the following API for the
659 GDB's application code:
661 `i386_region_ok_for_watchpoint (ADDR, LEN)'
662 The macro `TARGET_REGION_OK_FOR_HW_WATCHPOINT' is set to call this
663 function. It counts the number of debug registers required to
664 watch a given region, and returns a non-zero value if that number
665 is less than 4, the number of debug registers available to x86
668 `i386_stopped_data_address (ADDR_P)'
669 The target function `target_stopped_data_address' is set to call
670 this function. This function examines the breakpoint condition
671 bits in the DR6 Debug Status register, as returned by the
672 `I386_DR_LOW_GET_STATUS' macro, and returns the address associated
673 with the first bit that is set in DR6.
675 `i386_stopped_by_watchpoint (void)'
676 The macro `STOPPED_BY_WATCHPOINT' is set to call this function.
677 The argument passed to `STOPPED_BY_WATCHPOINT' is ignored. This
678 function examines the breakpoint condition bits in the DR6 Debug
679 Status register, as returned by the `I386_DR_LOW_GET_STATUS'
680 macro, and returns true if any bit is set. Otherwise, false is
683 `i386_insert_watchpoint (ADDR, LEN, TYPE)'
684 `i386_remove_watchpoint (ADDR, LEN, TYPE)'
685 Insert or remove a watchpoint. The macros
686 `target_insert_watchpoint' and `target_remove_watchpoint' are set
687 to call these functions. `i386_insert_watchpoint' first looks for
688 a debug register which is already set to watch the same region for
689 the same access types; if found, it just increments the reference
690 count of that debug register, thus implementing debug register
691 sharing between watchpoints. If no such register is found, the
692 function looks for a vacant debug register, sets its mirrored
693 value to ADDR, sets the mirrored value of DR7 Debug Control
694 register as appropriate for the LEN and TYPE parameters, and then
695 passes the new values of the debug register and DR7 to the
696 inferior by calling `I386_DR_LOW_SET_ADDR' and
697 `I386_DR_LOW_SET_CONTROL'. If more than one debug register is
698 required to cover the given region, the above process is repeated
699 for each debug register.
701 `i386_remove_watchpoint' does the opposite: it resets the address
702 in the mirrored value of the debug register and its read/write and
703 length bits in the mirrored value of DR7, then passes these new
704 values to the inferior via `I386_DR_LOW_RESET_ADDR' and
705 `I386_DR_LOW_SET_CONTROL'. If a register is shared by several
706 watchpoints, each time a `i386_remove_watchpoint' is called, it
707 decrements the reference count, and only calls
708 `I386_DR_LOW_RESET_ADDR' and `I386_DR_LOW_SET_CONTROL' when the
711 `i386_insert_hw_breakpoint (BP_TGT)'
712 `i386_remove_hw_breakpoint (BP_TGT)'
713 These functions insert and remove hardware-assisted breakpoints.
714 The macros `target_insert_hw_breakpoint' and
715 `target_remove_hw_breakpoint' are set to call these functions.
716 The argument is a `struct bp_target_info *', as described in the
717 documentation for `target_insert_breakpoint'. These functions
718 work like `i386_insert_watchpoint' and `i386_remove_watchpoint',
719 respectively, except that they set up the debug registers to watch
720 instruction execution, and each hardware-assisted breakpoint
721 always requires exactly one debug register.
723 `i386_stopped_by_hwbp (void)'
724 This function returns non-zero if the inferior has some watchpoint
725 or hardware breakpoint that triggered. It works like
726 `i386_stopped_data_address', except that it doesn't record the
727 address whose watchpoint triggered.
729 `i386_cleanup_dregs (void)'
730 This function clears all the reference counts, addresses, and
731 control bits in the mirror images of the debug registers. It
732 doesn't affect the actual debug registers in the inferior process.
735 1. x86 processors support setting watchpoints on I/O reads or writes.
736 However, since no target supports this (as of March 2001), and
737 since `enum target_hw_bp_type' doesn't even have an enumeration
738 for I/O watchpoints, this feature is not yet available to GDB
741 2. x86 processors can enable watchpoints locally, for the current task
742 only, or globally, for all the tasks. For each debug register,
743 there's a bit in the DR7 Debug Control register that determines
744 whether the associated address is watched locally or globally. The
745 current implementation of x86 watchpoint support in GDB always
746 sets watchpoints to be locally enabled, since global watchpoints
747 might interfere with the underlying OS and are probably
748 unavailable in many platforms.
753 In the abstract, a checkpoint is a point in the execution history of
754 the program, which the user may wish to return to at some later time.
756 Internally, a checkpoint is a saved copy of the program state,
757 including whatever information is required in order to restore the
758 program to that state at a later time. This can be expected to include
759 the state of registers and memory, and may include external state such
760 as the state of open files and devices.
762 There are a number of ways in which checkpoints may be implemented
763 in gdb, eg. as corefiles, as forked processes, and as some opaque
764 method implemented on the target side.
766 A corefile can be used to save an image of target memory and register
767 state, which can in principle be restored later -- but corefiles do not
768 typically include information about external entities such as open
769 files. Currently this method is not implemented in gdb.
771 A forked process can save the state of user memory and registers, as
772 well as some subset of external (kernel) state. This method is used to
773 implement checkpoints on Linux, and in principle might be used on other
776 Some targets, eg. simulators, might have their own built-in method
777 for saving checkpoints, and gdb might be able to take advantage of that
778 capability without necessarily knowing any details of how it is done.
780 3.11 Observing changes in GDB internals
781 =======================================
783 In order to function properly, several modules need to be notified when
784 some changes occur in the GDB internals. Traditionally, these modules
785 have relied on several paradigms, the most common ones being hooks and
786 gdb-events. Unfortunately, none of these paradigms was versatile
787 enough to become the standard notification mechanism in GDB. The fact
788 that they only supported one "client" was also a strong limitation.
790 A new paradigm, based on the Observer pattern of the `Design
791 Patterns' book, has therefore been implemented. The goal was to provide
792 a new interface overcoming the issues with the notification mechanisms
793 previously available. This new interface needed to be strongly typed,
794 easy to extend, and versatile enough to be used as the standard
795 interface when adding new notifications.
797 See *Note GDB Observers:: for a brief description of the observers
798 currently implemented in GDB. The rationale for the current
799 implementation is also briefly discussed.
802 File: gdbint.info, Node: User Interface, Next: libgdb, Prev: Algorithms, Up: Top
807 GDB has several user interfaces. Although the command-line interface
808 is the most common and most familiar, there are others.
810 4.1 Command Interpreter
811 =======================
813 The command interpreter in GDB is fairly simple. It is designed to
814 allow for the set of commands to be augmented dynamically, and also has
815 a recursive subcommand capability, where the first argument to a
816 command may itself direct a lookup on a different command list.
818 For instance, the `set' command just starts a lookup on the
819 `setlist' command list, while `set thread' recurses to the
820 `set_thread_cmd_list'.
822 To add commands in general, use `add_cmd'. `add_com' adds to the
823 main command list, and should be used for those commands. The usual
824 place to add commands is in the `_initialize_XYZ' routines at the ends
825 of most source files.
827 To add paired `set' and `show' commands, use `add_setshow_cmd' or
828 `add_setshow_cmd_full'. The former is a slightly simpler interface
829 which is useful when you don't need to further modify the new command
830 structures, while the latter returns the new command structures for
833 Before removing commands from the command set it is a good idea to
834 deprecate them for some time. Use `deprecate_cmd' on commands or
835 aliases to set the deprecated flag. `deprecate_cmd' takes a `struct
836 cmd_list_element' as it's first argument. You can use the return value
837 from `add_com' or `add_cmd' to deprecate the command immediately after
840 The first time a command is used the user will be warned and offered
841 a replacement (if one exists). Note that the replacement string passed
842 to `deprecate_cmd' should be the full name of the command, i.e. the
843 entire string the user should type at the command line.
845 4.2 UI-Independent Output--the `ui_out' Functions
846 =================================================
848 The `ui_out' functions present an abstraction level for the GDB output
849 code. They hide the specifics of different user interfaces supported
850 by GDB, and thus free the programmer from the need to write several
851 versions of the same code, one each for every UI, to produce output.
853 4.2.1 Overview and Terminology
854 ------------------------------
856 In general, execution of each GDB command produces some sort of output,
857 and can even generate an input request.
859 Output can be generated for the following purposes:
861 * to display a _result_ of an operation;
863 * to convey _info_ or produce side-effects of a requested operation;
865 * to provide a _notification_ of an asynchronous event (including
866 progress indication of a prolonged asynchronous operation);
868 * to display _error messages_ (including warnings);
870 * to show _debug data_;
872 * to _query_ or prompt a user for input (a special case).
874 This section mainly concentrates on how to build result output,
875 although some of it also applies to other kinds of output.
877 Generation of output that displays the results of an operation
878 involves one or more of the following:
880 * output of the actual data
882 * formatting the output as appropriate for console output, to make it
883 easily readable by humans
885 * machine oriented formatting-a more terse formatting to allow for
886 easy parsing by programs which read GDB's output
888 * annotation, whose purpose is to help legacy GUIs to identify
889 interesting parts in the output
891 The `ui_out' routines take care of the first three aspects.
892 Annotations are provided by separate annotation routines. Note that use
893 of annotations for an interface between a GUI and GDB is deprecated.
895 Output can be in the form of a single item, which we call a "field";
896 a "list" consisting of identical fields; a "tuple" consisting of
897 non-identical fields; or a "table", which is a tuple consisting of a
898 header and a body. In a BNF-like form:
907 `<width> <alignment> <title>'
912 4.2.2 General Conventions
913 -------------------------
915 Most `ui_out' routines are of type `void', the exceptions are
916 `ui_out_stream_new' (which returns a pointer to the newly created
917 object) and the `make_cleanup' routines.
919 The first parameter is always the `ui_out' vector object, a pointer
920 to a `struct ui_out'.
922 The FORMAT parameter is like in `printf' family of functions. When
923 it is present, there must also be a variable list of arguments
924 sufficient used to satisfy the `%' specifiers in the supplied format.
926 When a character string argument is not used in a `ui_out' function
927 call, a `NULL' pointer has to be supplied instead.
929 4.2.3 Table, Tuple and List Functions
930 -------------------------------------
932 This section introduces `ui_out' routines for building lists, tuples
933 and tables. The routines to output the actual data items (fields) are
934 presented in the next section.
936 To recap: A "tuple" is a sequence of "fields", each field containing
937 information about an object; a "list" is a sequence of fields where
938 each field describes an identical object.
940 Use the "table" functions when your output consists of a list of
941 rows (tuples) and the console output should include a heading. Use this
942 even when you are listing just one object but you still want the header.
944 Tables can not be nested. Tuples and lists can be nested up to a
945 maximum of five levels.
947 The overall structure of the table output code is something like
961 Here is the description of table-, tuple- and list-related `ui_out'
964 -- Function: void ui_out_table_begin (struct ui_out *UIOUT, int
965 NBROFCOLS, int NR_ROWS, const char *TBLID)
966 The function `ui_out_table_begin' marks the beginning of the output
967 of a table. It should always be called before any other `ui_out'
968 function for a given table. NBROFCOLS is the number of columns in
969 the table. NR_ROWS is the number of rows in the table. TBLID is
970 an optional string identifying the table. The string pointed to
971 by TBLID is copied by the implementation of `ui_out_table_begin',
972 so the application can free the string if it was `malloc'ed.
974 The companion function `ui_out_table_end', described below, marks
975 the end of the table's output.
977 -- Function: void ui_out_table_header (struct ui_out *UIOUT, int
978 WIDTH, enum ui_align ALIGNMENT, const char *COLHDR)
979 `ui_out_table_header' provides the header information for a single
980 table column. You call this function several times, one each for
981 every column of the table, after `ui_out_table_begin', but before
984 The value of WIDTH gives the column width in characters. The
985 value of ALIGNMENT is one of `left', `center', and `right', and it
986 specifies how to align the header: left-justify, center, or
987 right-justify it. COLHDR points to a string that specifies the
988 column header; the implementation copies that string, so column
989 header strings in `malloc'ed storage can be freed after the call.
991 -- Function: void ui_out_table_body (struct ui_out *UIOUT)
992 This function delimits the table header from the table body.
994 -- Function: void ui_out_table_end (struct ui_out *UIOUT)
995 This function signals the end of a table's output. It should be
996 called after the table body has been produced by the list and
997 field output functions.
999 There should be exactly one call to `ui_out_table_end' for each
1000 call to `ui_out_table_begin', otherwise the `ui_out' functions
1001 will signal an internal error.
1003 The output of the tuples that represent the table rows must follow
1004 the call to `ui_out_table_body' and precede the call to
1005 `ui_out_table_end'. You build a tuple by calling `ui_out_tuple_begin'
1006 and `ui_out_tuple_end', with suitable calls to functions which actually
1007 output fields between them.
1009 -- Function: void ui_out_tuple_begin (struct ui_out *UIOUT, const char
1011 This function marks the beginning of a tuple output. ID points to
1012 an optional string that identifies the tuple; it is copied by the
1013 implementation, and so strings in `malloc'ed storage can be freed
1016 -- Function: void ui_out_tuple_end (struct ui_out *UIOUT)
1017 This function signals an end of a tuple output. There should be
1018 exactly one call to `ui_out_tuple_end' for each call to
1019 `ui_out_tuple_begin', otherwise an internal GDB error will be
1022 -- Function: struct cleanup *make_cleanup_ui_out_tuple_begin_end
1023 (struct ui_out *UIOUT, const char *ID)
1024 This function first opens the tuple and then establishes a cleanup
1025 (*note Cleanups: Coding.) to close the tuple. It provides a
1026 convenient and correct implementation of the non-portable(1) code
1028 struct cleanup *old_cleanup;
1029 ui_out_tuple_begin (uiout, "...");
1030 old_cleanup = make_cleanup ((void(*)(void *)) ui_out_tuple_end,
1033 -- Function: void ui_out_list_begin (struct ui_out *UIOUT, const char
1035 This function marks the beginning of a list output. ID points to
1036 an optional string that identifies the list; it is copied by the
1037 implementation, and so strings in `malloc'ed storage can be freed
1040 -- Function: void ui_out_list_end (struct ui_out *UIOUT)
1041 This function signals an end of a list output. There should be
1042 exactly one call to `ui_out_list_end' for each call to
1043 `ui_out_list_begin', otherwise an internal GDB error will be
1046 -- Function: struct cleanup *make_cleanup_ui_out_list_begin_end
1047 (struct ui_out *UIOUT, const char *ID)
1048 Similar to `make_cleanup_ui_out_tuple_begin_end', this function
1049 opens a list and then establishes cleanup (*note Cleanups: Coding.)
1050 that will close the list.list.
1052 4.2.4 Item Output Functions
1053 ---------------------------
1055 The functions described below produce output for the actual data items,
1056 or fields, which contain information about the object.
1058 Choose the appropriate function accordingly to your particular needs.
1060 -- Function: void ui_out_field_fmt (struct ui_out *UIOUT, char
1061 *FLDNAME, char *FORMAT, ...)
1062 This is the most general output function. It produces the
1063 representation of the data in the variable-length argument list
1064 according to formatting specifications in FORMAT, a `printf'-like
1065 format string. The optional argument FLDNAME supplies the name of
1066 the field. The data items themselves are supplied as additional
1067 arguments after FORMAT.
1069 This generic function should be used only when it is not possible
1070 to use one of the specialized versions (see below).
1072 -- Function: void ui_out_field_int (struct ui_out *UIOUT, const char
1073 *FLDNAME, int VALUE)
1074 This function outputs a value of an `int' variable. It uses the
1075 `"%d"' output conversion specification. FLDNAME specifies the
1078 -- Function: void ui_out_field_fmt_int (struct ui_out *UIOUT, int
1079 WIDTH, enum ui_align ALIGNMENT, const char *FLDNAME, int
1081 This function outputs a value of an `int' variable. It differs
1082 from `ui_out_field_int' in that the caller specifies the desired
1083 WIDTH and ALIGNMENT of the output. FLDNAME specifies the name of
1086 -- Function: void ui_out_field_core_addr (struct ui_out *UIOUT, const
1087 char *FLDNAME, CORE_ADDR ADDRESS)
1088 This function outputs an address.
1090 -- Function: void ui_out_field_string (struct ui_out *UIOUT, const
1091 char *FLDNAME, const char *STRING)
1092 This function outputs a string using the `"%s"' conversion
1095 Sometimes, there's a need to compose your output piece by piece using
1096 functions that operate on a stream, such as `value_print' or
1097 `fprintf_symbol_filtered'. These functions accept an argument of the
1098 type `struct ui_file *', a pointer to a `ui_file' object used to store
1099 the data stream used for the output. When you use one of these
1100 functions, you need a way to pass their results stored in a `ui_file'
1101 object to the `ui_out' functions. To this end, you first create a
1102 `ui_stream' object by calling `ui_out_stream_new', pass the `stream'
1103 member of that `ui_stream' object to `value_print' and similar
1104 functions, and finally call `ui_out_field_stream' to output the field
1105 you constructed. When the `ui_stream' object is no longer needed, you
1106 should destroy it and free its memory by calling `ui_out_stream_delete'.
1108 -- Function: struct ui_stream *ui_out_stream_new (struct ui_out *UIOUT)
1109 This function creates a new `ui_stream' object which uses the same
1110 output methods as the `ui_out' object whose pointer is passed in
1111 UIOUT. It returns a pointer to the newly created `ui_stream'
1114 -- Function: void ui_out_stream_delete (struct ui_stream *STREAMBUF)
1115 This functions destroys a `ui_stream' object specified by
1118 -- Function: void ui_out_field_stream (struct ui_out *UIOUT, const
1119 char *FIELDNAME, struct ui_stream *STREAMBUF)
1120 This function consumes all the data accumulated in
1121 `streambuf->stream' and outputs it like `ui_out_field_string'
1122 does. After a call to `ui_out_field_stream', the accumulated data
1123 no longer exists, but the stream is still valid and may be used
1124 for producing more fields.
1126 *Important:* If there is any chance that your code could bail out
1127 before completing output generation and reaching the point where
1128 `ui_out_stream_delete' is called, it is necessary to set up a cleanup,
1129 to avoid leaking memory and other resources. Here's a skeleton code to
1132 struct ui_stream *mybuf = ui_out_stream_new (uiout);
1133 struct cleanup *old = make_cleanup (ui_out_stream_delete, mybuf);
1137 If the function already has the old cleanup chain set (for other
1138 kinds of cleanups), you just have to add your cleanup to it:
1140 mybuf = ui_out_stream_new (uiout);
1141 make_cleanup (ui_out_stream_delete, mybuf);
1143 Note that with cleanups in place, you should not call
1144 `ui_out_stream_delete' directly, or you would attempt to free the same
1147 4.2.5 Utility Output Functions
1148 ------------------------------
1150 -- Function: void ui_out_field_skip (struct ui_out *UIOUT, const char
1152 This function skips a field in a table. Use it if you have to
1153 leave an empty field without disrupting the table alignment. The
1154 argument FLDNAME specifies a name for the (missing) filed.
1156 -- Function: void ui_out_text (struct ui_out *UIOUT, const char
1158 This function outputs the text in STRING in a way that makes it
1159 easy to be read by humans. For example, the console
1160 implementation of this method filters the text through a built-in
1161 pager, to prevent it from scrolling off the visible portion of the
1164 Use this function for printing relatively long chunks of text
1165 around the actual field data: the text it produces is not aligned
1166 according to the table's format. Use `ui_out_field_string' to
1167 output a string field, and use `ui_out_message', described below,
1168 to output short messages.
1170 -- Function: void ui_out_spaces (struct ui_out *UIOUT, int NSPACES)
1171 This function outputs NSPACES spaces. It is handy to align the
1172 text produced by `ui_out_text' with the rest of the table or list.
1174 -- Function: void ui_out_message (struct ui_out *UIOUT, int VERBOSITY,
1175 const char *FORMAT, ...)
1176 This function produces a formatted message, provided that the
1177 current verbosity level is at least as large as given by
1178 VERBOSITY. The current verbosity level is specified by the user
1179 with the `set verbositylevel' command.(2)
1181 -- Function: void ui_out_wrap_hint (struct ui_out *UIOUT, char *INDENT)
1182 This function gives the console output filter (a paging filter) a
1183 hint of where to break lines which are too long. Ignored for all
1184 other output consumers. INDENT, if non-`NULL', is the string to
1185 be printed to indent the wrapped text on the next line; it must
1186 remain accessible until the next call to `ui_out_wrap_hint', or
1187 until an explicit newline is produced by one of the other
1188 functions. If INDENT is `NULL', the wrapped text will not be
1191 -- Function: void ui_out_flush (struct ui_out *UIOUT)
1192 This function flushes whatever output has been accumulated so far,
1193 if the UI buffers output.
1195 4.2.6 Examples of Use of `ui_out' functions
1196 -------------------------------------------
1198 This section gives some practical examples of using the `ui_out'
1199 functions to generalize the old console-oriented code in GDB. The
1200 examples all come from functions defined on the `breakpoints.c' file.
1202 This example, from the `breakpoint_1' function, shows how to produce
1205 The original code was:
1207 if (!found_a_breakpoint++)
1209 annotate_breakpoints_headers ();
1212 printf_filtered ("Num ");
1214 printf_filtered ("Type ");
1216 printf_filtered ("Disp ");
1218 printf_filtered ("Enb ");
1222 printf_filtered ("Address ");
1225 printf_filtered ("What\n");
1227 annotate_breakpoints_table ();
1230 Here's the new version:
1232 nr_printable_breakpoints = ...;
1235 ui_out_table_begin (ui, 6, nr_printable_breakpoints, "BreakpointTable");
1237 ui_out_table_begin (ui, 5, nr_printable_breakpoints, "BreakpointTable");
1239 if (nr_printable_breakpoints > 0)
1240 annotate_breakpoints_headers ();
1241 if (nr_printable_breakpoints > 0)
1243 ui_out_table_header (uiout, 3, ui_left, "number", "Num"); /* 1 */
1244 if (nr_printable_breakpoints > 0)
1246 ui_out_table_header (uiout, 14, ui_left, "type", "Type"); /* 2 */
1247 if (nr_printable_breakpoints > 0)
1249 ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */
1250 if (nr_printable_breakpoints > 0)
1252 ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */
1255 if (nr_printable_breakpoints > 0)
1257 if (TARGET_ADDR_BIT <= 32)
1258 ui_out_table_header (uiout, 10, ui_left, "addr", "Address");/* 5 */
1260 ui_out_table_header (uiout, 18, ui_left, "addr", "Address");/* 5 */
1262 if (nr_printable_breakpoints > 0)
1264 ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */
1265 ui_out_table_body (uiout);
1266 if (nr_printable_breakpoints > 0)
1267 annotate_breakpoints_table ();
1269 This example, from the `print_one_breakpoint' function, shows how to
1270 produce the actual data for the table whose structure was defined in
1271 the above example. The original code was:
1275 printf_filtered ("%-3d ", b->number);
1277 if ((int)b->type > (sizeof(bptypes)/sizeof(bptypes[0]))
1278 || ((int) b->type != bptypes[(int) b->type].type))
1279 internal_error ("bptypes table does not describe type #%d.",
1281 printf_filtered ("%-14s ", bptypes[(int)b->type].description);
1283 printf_filtered ("%-4s ", bpdisps[(int)b->disposition]);
1285 printf_filtered ("%-3c ", bpenables[(int)b->enable]);
1288 This is the new version:
1291 ui_out_tuple_begin (uiout, "bkpt");
1293 ui_out_field_int (uiout, "number", b->number);
1295 if (((int) b->type > (sizeof (bptypes) / sizeof (bptypes[0])))
1296 || ((int) b->type != bptypes[(int) b->type].type))
1297 internal_error ("bptypes table does not describe type #%d.",
1299 ui_out_field_string (uiout, "type", bptypes[(int)b->type].description);
1301 ui_out_field_string (uiout, "disp", bpdisps[(int)b->disposition]);
1303 ui_out_field_fmt (uiout, "enabled", "%c", bpenables[(int)b->enable]);
1306 This example, also from `print_one_breakpoint', shows how to produce
1307 a complicated output field using the `print_expression' functions which
1308 requires a stream to be passed. It also shows how to automate stream
1309 destruction with cleanups. The original code was:
1312 print_expression (b->exp, gdb_stdout);
1316 struct ui_stream *stb = ui_out_stream_new (uiout);
1317 struct cleanup *old_chain = make_cleanup_ui_out_stream_delete (stb);
1320 print_expression (b->exp, stb->stream);
1321 ui_out_field_stream (uiout, "what", local_stream);
1323 This example, also from `print_one_breakpoint', shows how to use
1324 `ui_out_text' and `ui_out_field_string'. The original code was:
1327 if (b->dll_pathname == NULL)
1328 printf_filtered ("<any library> ");
1330 printf_filtered ("library \"%s\" ", b->dll_pathname);
1335 if (b->dll_pathname == NULL)
1337 ui_out_field_string (uiout, "what", "<any library>");
1338 ui_out_spaces (uiout, 1);
1342 ui_out_text (uiout, "library \"");
1343 ui_out_field_string (uiout, "what", b->dll_pathname);
1344 ui_out_text (uiout, "\" ");
1347 The following example from `print_one_breakpoint' shows how to use
1348 `ui_out_field_int' and `ui_out_spaces'. The original code was:
1351 if (b->forked_inferior_pid != 0)
1352 printf_filtered ("process %d ", b->forked_inferior_pid);
1357 if (b->forked_inferior_pid != 0)
1359 ui_out_text (uiout, "process ");
1360 ui_out_field_int (uiout, "what", b->forked_inferior_pid);
1361 ui_out_spaces (uiout, 1);
1364 Here's an example of using `ui_out_field_string'. The original code
1368 if (b->exec_pathname != NULL)
1369 printf_filtered ("program \"%s\" ", b->exec_pathname);
1374 if (b->exec_pathname != NULL)
1376 ui_out_text (uiout, "program \"");
1377 ui_out_field_string (uiout, "what", b->exec_pathname);
1378 ui_out_text (uiout, "\" ");
1381 Finally, here's an example of printing an address. The original
1385 printf_filtered ("%s ",
1386 hex_string_custom ((unsigned long) b->address, 8));
1391 ui_out_field_core_addr (uiout, "Address", b->address);
1393 4.3 Console Printing
1394 ====================
1399 ---------- Footnotes ----------
1401 (1) The function cast is not portable ISO C.
1403 (2) As of this writing (April 2001), setting verbosity level is not
1404 yet implemented, and is always returned as zero. So calling
1405 `ui_out_message' with a VERBOSITY argument more than zero will cause
1406 the message to never be printed.
1409 File: gdbint.info, Node: libgdb, Next: Symbol Handling, Prev: User Interface, Up: Top
1417 `libgdb' 1.0 was an abortive project of years ago. The theory was to
1418 provide an API to GDB's functionality.
1423 `libgdb' 2.0 is an ongoing effort to update GDB so that is better able
1424 to support graphical and other environments.
1426 Since `libgdb' development is on-going, its architecture is still
1427 evolving. The following components have so far been identified:
1429 * Observer - `gdb-events.h'.
1431 * Builder - `ui-out.h'
1433 * Event Loop - `event-loop.h'
1437 The model that ties these components together is described below.
1439 5.3 The `libgdb' Model
1440 ======================
1442 A client of `libgdb' interacts with the library in two ways.
1444 * As an observer (using `gdb-events') receiving notifications from
1445 `libgdb' of any internal state changes (break point changes, run
1448 * As a client querying `libgdb' (using the `ui-out' builder) to
1449 obtain various status values from GDB.
1451 Since `libgdb' could have multiple clients (e.g., a GUI supporting
1452 the existing GDB CLI), those clients must co-operate when controlling
1453 `libgdb'. In particular, a client must ensure that `libgdb' is idle
1454 (i.e. no other client is using `libgdb') before responding to a
1455 `gdb-event' by making a query.
1460 At present GDB's CLI is very much entangled in with the core of
1461 `libgdb'. Consequently, a client wishing to include the CLI in their
1462 interface needs to carefully co-ordinate its own and the CLI's
1465 It is suggested that the client set `libgdb' up to be bi-modal
1466 (alternate between CLI and client query modes). The notes below sketch
1469 * The client registers itself as an observer of `libgdb'.
1471 * The client create and install `cli-out' builder using its own
1472 versions of the `ui-file' `gdb_stderr', `gdb_stdtarg' and
1473 `gdb_stdout' streams.
1475 * The client creates a separate custom `ui-out' builder that is only
1476 used while making direct queries to `libgdb'.
1478 When the client receives input intended for the CLI, it simply
1479 passes it along. Since the `cli-out' builder is installed by default,
1480 all the CLI output in response to that command is routed (pronounced
1481 rooted) through to the client controlled `gdb_stdout' et. al. streams.
1482 At the same time, the client is kept abreast of internal changes by
1483 virtue of being a `libgdb' observer.
1485 The only restriction on the client is that it must wait until
1486 `libgdb' becomes idle before initiating any queries (using the client's
1489 5.5 `libgdb' components
1490 =======================
1492 Observer - `gdb-events.h'
1493 -------------------------
1495 `gdb-events' provides the client with a very raw mechanism that can be
1496 used to implement an observer. At present it only allows for one
1497 observer and that observer must, internally, handle the need to delay
1498 the processing of any event notifications until after `libgdb' has
1499 finished the current command.
1501 Builder - `ui-out.h'
1502 --------------------
1504 `ui-out' provides the infrastructure necessary for a client to create a
1505 builder. That builder is then passed down to `libgdb' when doing any
1508 Event Loop - `event-loop.h'
1509 ---------------------------
1511 `event-loop', currently non-re-entrant, provides a simple event loop.
1512 A client would need to either plug its self into this loop or,
1513 implement a new event-loop that GDB would use.
1515 The event-loop will eventually be made re-entrant. This is so that
1516 GDB can better handle the problem of some commands blocking instead of
1522 `libgdb' is the most obvious component of this system. It provides the
1523 query interface. Each function is parameterized by a `ui-out' builder.
1524 The result of the query is constructed using that builder before the
1525 query function returns.
1528 File: gdbint.info, Node: Symbol Handling, Next: Language Support, Prev: libgdb, Up: Top
1533 Symbols are a key part of GDB's operation. Symbols include variables,
1534 functions, and types.
1539 GDB reads symbols from "symbol files". The usual symbol file is the
1540 file containing the program which GDB is debugging. GDB can be
1541 directed to use a different file for symbols (with the `symbol-file'
1542 command), and it can also read more symbols via the `add-file' and
1543 `load' commands, or while reading symbols from shared libraries.
1545 Symbol files are initially opened by code in `symfile.c' using the
1546 BFD library (*note Support Libraries::). BFD identifies the type of
1547 the file by examining its header. `find_sym_fns' then uses this
1548 identification to locate a set of symbol-reading functions.
1550 Symbol-reading modules identify themselves to GDB by calling
1551 `add_symtab_fns' during their module initialization. The argument to
1552 `add_symtab_fns' is a `struct sym_fns' which contains the name (or name
1553 prefix) of the symbol format, the length of the prefix, and pointers to
1554 four functions. These functions are called at various times to process
1555 symbol files whose identification matches the specified prefix.
1557 The functions supplied by each module are:
1559 `XYZ_symfile_init(struct sym_fns *sf)'
1560 Called from `symbol_file_add' when we are about to read a new
1561 symbol file. This function should clean up any internal state
1562 (possibly resulting from half-read previous files, for example)
1563 and prepare to read a new symbol file. Note that the symbol file
1564 which we are reading might be a new "main" symbol file, or might
1565 be a secondary symbol file whose symbols are being added to the
1566 existing symbol table.
1568 The argument to `XYZ_symfile_init' is a newly allocated `struct
1569 sym_fns' whose `bfd' field contains the BFD for the new symbol
1570 file being read. Its `private' field has been zeroed, and can be
1571 modified as desired. Typically, a struct of private information
1572 will be `malloc''d, and a pointer to it will be placed in the
1575 There is no result from `XYZ_symfile_init', but it can call
1576 `error' if it detects an unavoidable problem.
1579 Called from `symbol_file_add' when discarding existing symbols.
1580 This function needs only handle the symbol-reading module's
1581 internal state; the symbol table data structures visible to the
1582 rest of GDB will be discarded by `symbol_file_add'. It has no
1583 arguments and no result. It may be called after
1584 `XYZ_symfile_init', if a new symbol table is being read, or may be
1585 called alone if all symbols are simply being discarded.
1587 `XYZ_symfile_read(struct sym_fns *sf, CORE_ADDR addr, int mainline)'
1588 Called from `symbol_file_add' to actually read the symbols from a
1589 symbol-file into a set of psymtabs or symtabs.
1591 `sf' points to the `struct sym_fns' originally passed to
1592 `XYZ_sym_init' for possible initialization. `addr' is the offset
1593 between the file's specified start address and its true address in
1594 memory. `mainline' is 1 if this is the main symbol table being
1595 read, and 0 if a secondary symbol file (e.g., shared library or
1596 dynamically loaded file) is being read.
1598 In addition, if a symbol-reading module creates psymtabs when
1599 XYZ_symfile_read is called, these psymtabs will contain a pointer to a
1600 function `XYZ_psymtab_to_symtab', which can be called from any point in
1601 the GDB symbol-handling code.
1603 `XYZ_psymtab_to_symtab (struct partial_symtab *pst)'
1604 Called from `psymtab_to_symtab' (or the `PSYMTAB_TO_SYMTAB' macro)
1605 if the psymtab has not already been read in and had its
1606 `pst->symtab' pointer set. The argument is the psymtab to be
1607 fleshed-out into a symtab. Upon return, `pst->readin' should have
1608 been set to 1, and `pst->symtab' should contain a pointer to the
1609 new corresponding symtab, or zero if there were no symbols in that
1610 part of the symbol file.
1612 6.2 Partial Symbol Tables
1613 =========================
1615 GDB has three types of symbol tables:
1617 * Full symbol tables ("symtabs"). These contain the main
1618 information about symbols and addresses.
1620 * Partial symbol tables ("psymtabs"). These contain enough
1621 information to know when to read the corresponding part of the full
1624 * Minimal symbol tables ("msymtabs"). These contain information
1625 gleaned from non-debugging symbols.
1627 This section describes partial symbol tables.
1629 A psymtab is constructed by doing a very quick pass over an
1630 executable file's debugging information. Small amounts of information
1631 are extracted--enough to identify which parts of the symbol table will
1632 need to be re-read and fully digested later, when the user needs the
1633 information. The speed of this pass causes GDB to start up very
1634 quickly. Later, as the detailed rereading occurs, it occurs in small
1635 pieces, at various times, and the delay therefrom is mostly invisible to
1638 The symbols that show up in a file's psymtab should be, roughly,
1639 those visible to the debugger's user when the program is not running
1640 code from that file. These include external symbols and types, static
1641 symbols and types, and `enum' values declared at file scope.
1643 The psymtab also contains the range of instruction addresses that the
1644 full symbol table would represent.
1646 The idea is that there are only two ways for the user (or much of the
1647 code in the debugger) to reference a symbol:
1649 * By its address (e.g., execution stops at some address which is
1650 inside a function in this file). The address will be noticed to
1651 be in the range of this psymtab, and the full symtab will be read
1652 in. `find_pc_function', `find_pc_line', and other `find_pc_...'
1653 functions handle this.
1655 * By its name (e.g., the user asks to print a variable, or set a
1656 breakpoint on a function). Global names and file-scope names will
1657 be found in the psymtab, which will cause the symtab to be pulled
1658 in. Local names will have to be qualified by a global name, or a
1659 file-scope name, in which case we will have already read in the
1660 symtab as we evaluated the qualifier. Or, a local symbol can be
1661 referenced when we are "in" a local scope, in which case the first
1662 case applies. `lookup_symbol' does most of the work here.
1664 The only reason that psymtabs exist is to cause a symtab to be read
1665 in at the right moment. Any symbol that can be elided from a psymtab,
1666 while still causing that to happen, should not appear in it. Since
1667 psymtabs don't have the idea of scope, you can't put local symbols in
1668 them anyway. Psymtabs don't have the idea of the type of a symbol,
1669 either, so types need not appear, unless they will be referenced by
1672 It is a bug for GDB to behave one way when only a psymtab has been
1673 read, and another way if the corresponding symtab has been read in.
1674 Such bugs are typically caused by a psymtab that does not contain all
1675 the visible symbols, or which has the wrong instruction address ranges.
1677 The psymtab for a particular section of a symbol file (objfile)
1678 could be thrown away after the symtab has been read in. The symtab
1679 should always be searched before the psymtab, so the psymtab will never
1680 be used (in a bug-free environment). Currently, psymtabs are allocated
1681 on an obstack, and all the psymbols themselves are allocated in a pair
1682 of large arrays on an obstack, so there is little to be gained by
1683 trying to free them unless you want to do a lot more work.
1688 Fundamental Types (e.g., `FT_VOID', `FT_BOOLEAN').
1689 --------------------------------------------------
1691 These are the fundamental types that GDB uses internally. Fundamental
1692 types from the various debugging formats (stabs, ELF, etc) are mapped
1693 into one of these. They are basically a union of all fundamental types
1694 that GDB knows about for all the languages that GDB knows about.
1696 Type Codes (e.g., `TYPE_CODE_PTR', `TYPE_CODE_ARRAY').
1697 ------------------------------------------------------
1699 Each time GDB builds an internal type, it marks it with one of these
1700 types. The type may be a fundamental type, such as `TYPE_CODE_INT', or
1701 a derived type, such as `TYPE_CODE_PTR' which is a pointer to another
1702 type. Typically, several `FT_*' types map to one `TYPE_CODE_*' type,
1703 and are distinguished by other members of the type struct, such as
1704 whether the type is signed or unsigned, and how many bits it uses.
1706 Builtin Types (e.g., `builtin_type_void', `builtin_type_char').
1707 ---------------------------------------------------------------
1709 These are instances of type structs that roughly correspond to
1710 fundamental types and are created as global types for GDB to use for
1711 various ugly historical reasons. We eventually want to eliminate
1712 these. Note for example that `builtin_type_int' initialized in
1713 `gdbtypes.c' is basically the same as a `TYPE_CODE_INT' type that is
1714 initialized in `c-lang.c' for an `FT_INTEGER' fundamental type. The
1715 difference is that the `builtin_type' is not associated with any
1716 particular objfile, and only one instance exists, while `c-lang.c'
1717 builds as many `TYPE_CODE_INT' types as needed, with each one
1718 associated with some particular objfile.
1720 6.4 Object File Formats
1721 =======================
1726 The `a.out' format is the original file format for Unix. It consists
1727 of three sections: `text', `data', and `bss', which are for program
1728 code, initialized data, and uninitialized data, respectively.
1730 The `a.out' format is so simple that it doesn't have any reserved
1731 place for debugging information. (Hey, the original Unix hackers used
1732 `adb', which is a machine-language debugger!) The only debugging
1733 format for `a.out' is stabs, which is encoded as a set of normal
1734 symbols with distinctive attributes.
1736 The basic `a.out' reader is in `dbxread.c'.
1741 The COFF format was introduced with System V Release 3 (SVR3) Unix.
1742 COFF files may have multiple sections, each prefixed by a header. The
1743 number of sections is limited.
1745 The COFF specification includes support for debugging. Although this
1746 was a step forward, the debugging information was woefully limited. For
1747 instance, it was not possible to represent code that came from an
1750 The COFF reader is in `coffread.c'.
1755 ECOFF is an extended COFF originally introduced for Mips and Alpha
1758 The basic ECOFF reader is in `mipsread.c'.
1763 The IBM RS/6000 running AIX uses an object file format called XCOFF.
1764 The COFF sections, symbols, and line numbers are used, but debugging
1765 symbols are `dbx'-style stabs whose strings are located in the `.debug'
1766 section (rather than the string table). For more information, see
1767 *Note Top: (stabs)Top.
1769 The shared library scheme has a clean interface for figuring out what
1770 shared libraries are in use, but the catch is that everything which
1771 refers to addresses (symbol tables and breakpoints at least) needs to be
1772 relocated for both shared libraries and the main executable. At least
1773 using the standard mechanism this can only be done once the program has
1774 been run (or the core file has been read).
1779 Windows 95 and NT use the PE ("Portable Executable") format for their
1780 executables. PE is basically COFF with additional headers.
1782 While BFD includes special PE support, GDB needs only the basic COFF
1788 The ELF format came with System V Release 4 (SVR4) Unix. ELF is similar
1789 to COFF in being organized into a number of sections, but it removes
1790 many of COFF's limitations.
1792 The basic ELF reader is in `elfread.c'.
1797 SOM is HP's object file and debug format (not to be confused with IBM's
1798 SOM, which is a cross-language ABI).
1800 The SOM reader is in `hpread.c'.
1802 6.4.8 Other File Formats
1803 ------------------------
1805 Other file formats that have been supported by GDB include Netware
1806 Loadable Modules (`nlmread.c').
1808 6.5 Debugging File Formats
1809 ==========================
1811 This section describes characteristics of debugging information that
1812 are independent of the object file format.
1817 `stabs' started out as special symbols within the `a.out' format.
1818 Since then, it has been encapsulated into other file formats, such as
1821 While `dbxread.c' does some of the basic stab processing, including
1822 for encapsulated versions, `stabsread.c' does the real work.
1827 The basic COFF definition includes debugging information. The level of
1828 support is minimal and non-extensible, and is not often used.
1830 6.5.3 Mips debug (Third Eye)
1831 ----------------------------
1833 ECOFF includes a definition of a special debug format.
1835 The file `mdebugread.c' implements reading for this format.
1840 DWARF 1 is a debugging format that was originally designed to be used
1841 with ELF in SVR4 systems.
1843 The DWARF 1 reader is in `dwarfread.c'.
1848 DWARF 2 is an improved but incompatible version of DWARF 1.
1850 The DWARF 2 reader is in `dwarf2read.c'.
1855 Like COFF, the SOM definition includes debugging information.
1857 6.6 Adding a New Symbol Reader to GDB
1858 =====================================
1860 If you are using an existing object file format (`a.out', COFF, ELF,
1861 etc), there is probably little to be done.
1863 If you need to add a new object file format, you must first add it to
1864 BFD. This is beyond the scope of this document.
1866 You must then arrange for the BFD code to provide access to the
1867 debugging symbols. Generally GDB will have to call swapping routines
1868 from BFD and a few other BFD internal routines to locate the debugging
1869 information. As much as possible, GDB should not depend on the BFD
1870 internal data structures.
1872 For some targets (e.g., COFF), there is a special transfer vector
1873 used to call swapping routines, since the external data structures on
1874 various platforms have different sizes and layouts. Specialized
1875 routines that will only ever be implemented by one object file format
1876 may be called directly. This interface should be described in a file
1877 `bfd/libXYZ.h', which is included by GDB.
1879 6.7 Memory Management for Symbol Files
1880 ======================================
1882 Most memory associated with a loaded symbol file is stored on its
1883 `objfile_obstack'. This includes symbols, types, namespace data, and
1884 other information produced by the symbol readers.
1886 Because this data lives on the objfile's obstack, it is automatically
1887 released when the objfile is unloaded or reloaded. Therefore one
1888 objfile must not reference symbol or type data from another objfile;
1889 they could be unloaded at different times.
1891 User convenience variables, et cetera, have associated types.
1892 Normally these types live in the associated objfile. However, when the
1893 objfile is unloaded, those types are deep copied to global memory, so
1894 that the values of the user variables and history items are not lost.
1897 File: gdbint.info, Node: Language Support, Next: Host Definition, Prev: Symbol Handling, Up: Top
1902 GDB's language support is mainly driven by the symbol reader, although
1903 it is possible for the user to set the source language manually.
1905 GDB chooses the source language by looking at the extension of the
1906 file recorded in the debug info; `.c' means C, `.f' means Fortran, etc.
1907 It may also use a special-purpose language identifier if the debug
1908 format supports it, like with DWARF.
1910 7.1 Adding a Source Language to GDB
1911 ===================================
1913 To add other languages to GDB's expression parser, follow the following
1916 _Create the expression parser._
1917 This should reside in a file `LANG-exp.y'. Routines for building
1918 parsed expressions into a `union exp_element' list are in
1921 Since we can't depend upon everyone having Bison, and YACC produces
1922 parsers that define a bunch of global names, the following lines
1923 *must* be included at the top of the YACC parser, to prevent the
1924 various parsers from defining the same global names:
1926 #define yyparse LANG_parse
1927 #define yylex LANG_lex
1928 #define yyerror LANG_error
1929 #define yylval LANG_lval
1930 #define yychar LANG_char
1931 #define yydebug LANG_debug
1932 #define yypact LANG_pact
1933 #define yyr1 LANG_r1
1934 #define yyr2 LANG_r2
1935 #define yydef LANG_def
1936 #define yychk LANG_chk
1937 #define yypgo LANG_pgo
1938 #define yyact LANG_act
1939 #define yyexca LANG_exca
1940 #define yyerrflag LANG_errflag
1941 #define yynerrs LANG_nerrs
1943 At the bottom of your parser, define a `struct language_defn' and
1944 initialize it with the right values for your language. Define an
1945 `initialize_LANG' routine and have it call
1946 `add_language(LANG_language_defn)' to tell the rest of GDB that
1947 your language exists. You'll need some other supporting variables
1948 and functions, which will be used via pointers from your
1949 `LANG_language_defn'. See the declaration of `struct
1950 language_defn' in `language.h', and the other `*-exp.y' files, for
1953 _Add any evaluation routines, if necessary_
1954 If you need new opcodes (that represent the operations of the
1955 language), add them to the enumerated type in `expression.h'. Add
1956 support code for these operations in the `evaluate_subexp' function
1957 defined in the file `eval.c'. Add cases for new opcodes in two
1958 functions from `parse.c': `prefixify_subexp' and
1959 `length_of_subexp'. These compute the number of `exp_element's
1960 that a given operation takes up.
1962 _Update some existing code_
1963 Add an enumerated identifier for your language to the enumerated
1964 type `enum language' in `defs.h'.
1966 Update the routines in `language.c' so your language is included.
1967 These routines include type predicates and such, which (in some
1968 cases) are language dependent. If your language does not appear
1969 in the switch statement, an error is reported.
1971 Also included in `language.c' is the code that updates the variable
1972 `current_language', and the routines that translate the
1973 `language_LANG' enumerated identifier into a printable string.
1975 Update the function `_initialize_language' to include your
1976 language. This function picks the default language upon startup,
1977 so is dependent upon which languages that GDB is built for.
1979 Update `allocate_symtab' in `symfile.c' and/or symbol-reading code
1980 so that the language of each symtab (source file) is set properly.
1981 This is used to determine the language to use at each stack frame
1982 level. Currently, the language is set based upon the extension of
1983 the source file. If the language can be better inferred from the
1984 symbol information, please set the language of the symtab in the
1985 symbol-reading code.
1987 Add helper code to `print_subexp' (in `expprint.c') to handle any
1988 new expression opcodes you have added to `expression.h'. Also,
1989 add the printed representations of your operators to
1992 _Add a place of call_
1993 Add a call to `LANG_parse()' and `LANG_error' in `parse_exp_1'
1994 (defined in `parse.c').
1996 _Use macros to trim code_
1997 The user has the option of building GDB for some or all of the
1998 languages. If the user decides to build GDB for the language
1999 LANG, then every file dependent on `language.h' will have the
2000 macro `_LANG_LANG' defined in it. Use `#ifdef's to leave out
2001 large routines that the user won't need if he or she is not using
2004 Note that you do not need to do this in your YACC parser, since if
2005 GDB is not build for LANG, then `LANG-exp.tab.o' (the compiled
2006 form of your parser) is not linked into GDB at all.
2008 See the file `configure.in' for how GDB is configured for
2009 different languages.
2011 _Edit `Makefile.in'_
2012 Add dependencies in `Makefile.in'. Make sure you update the macro
2013 variables such as `HFILES' and `OBJS', otherwise your code may not
2014 get linked in, or, worse yet, it may not get `tar'red into the
2018 File: gdbint.info, Node: Host Definition, Next: Target Architecture Definition, Prev: Language Support, Up: Top
2023 With the advent of Autoconf, it's rarely necessary to have host
2024 definition machinery anymore. The following information is provided,
2025 mainly, as an historical reference.
2027 8.1 Adding a New Host
2028 =====================
2030 GDB's host configuration support normally happens via Autoconf. New
2031 host-specific definitions should not be needed. Older hosts GDB still
2032 use the host-specific definitions and files listed below, but these
2033 mostly exist for historical reasons, and will eventually disappear.
2035 `gdb/config/ARCH/XYZ.mh'
2036 This file once contained both host and native configuration
2037 information (*note Native Debugging::) for the machine XYZ. The
2038 host configuration information is now handed by Autoconf.
2040 Host configuration information included a definition of
2041 `XM_FILE=xm-XYZ.h' and possibly definitions for `CC',
2042 `SYSV_DEFINE', `XM_CFLAGS', `XM_ADD_FILES', `XM_CLIBS',
2043 `XM_CDEPS', etc.; see `Makefile.in'.
2045 New host only configurations do not need this file.
2047 `gdb/config/ARCH/xm-XYZ.h'
2048 This file once contained definitions and includes required when
2049 hosting gdb on machine XYZ. Those definitions and includes are now
2050 handled by Autoconf.
2052 New host and native configurations do not need this file.
2054 _Maintainer's note: Some hosts continue to use the `xm-xyz.h' file
2055 to define the macros HOST_FLOAT_FORMAT, HOST_DOUBLE_FORMAT and
2056 HOST_LONG_DOUBLE_FORMAT. That code also needs to be replaced with
2057 either an Autoconf or run-time test._
2060 Generic Host Support Files
2061 --------------------------
2063 There are some "generic" versions of routines that can be used by
2064 various systems. These can be customized in various ways by macros
2065 defined in your `xm-XYZ.h' file. If these routines work for the XYZ
2066 host, you can just include the generic file's name (with `.o', not
2067 `.c') in `XDEPFILES'.
2069 Otherwise, if your machine needs custom support routines, you will
2070 need to write routines that perform the same functions as the generic
2071 file. Put them into `XYZ-xdep.c', and put `XYZ-xdep.o' into
2075 This contains serial line support for Unix systems. This is always
2076 included, via the makefile variable `SER_HARDWIRE'; override this
2077 variable in the `.mh' file to avoid it.
2080 This contains serial line support for 32-bit programs running
2081 under DOS, using the DJGPP (a.k.a. GO32) execution environment.
2084 This contains generic TCP support using sockets.
2086 8.2 Host Conditionals
2087 =====================
2089 When GDB is configured and compiled, various macros are defined or left
2090 undefined, to control compilation based on the attributes of the host
2091 system. These macros and their meanings (or if the meaning is not
2092 documented here, then one of the source files where they are used is
2096 The default name of GDB's initialization file (normally
2100 This macro is deprecated.
2103 If your host defines `SIGWINCH', you can define this to be the name
2104 of a function to be called if `SIGWINCH' is received.
2106 `SIGWINCH_HANDLER_BODY'
2107 Define this to expand into code that will define the function
2108 named by the expansion of `SIGWINCH_HANDLER'.
2110 `ALIGN_STACK_ON_STARTUP'
2111 Define this if your system is of a sort that will crash in
2112 `tgetent' if the stack happens not to be longword-aligned when
2113 `main' is called. This is a rare situation, but is known to occur
2114 on several different types of systems.
2117 Define this if host files use `\r\n' rather than `\n' as a line
2118 terminator. This will cause source file listings to omit `\r'
2119 characters when printing and it will allow `\r\n' line endings of
2120 files which are "sourced" by gdb. It must be possible to open
2121 files in binary mode using `O_BINARY' or, for fopen, `"rb"'.
2124 The default value of the prompt string (normally `"(gdb) "').
2127 The name of the generic TTY device, defaults to `"/dev/tty"'.
2130 Define this if binary files are opened the same way as text files.
2133 In some cases, use the system call `mmap' for reading symbol
2134 tables. For some machines this allows for sharing and quick
2138 Define this if the host system has `termio.h'.
2145 Values for host-side constants.
2148 Substitute for isatty, if not available.
2151 This is the longest integer type available on the host. If not
2152 defined, it will default to `long long' or `long', depending on
2156 Define this if the host C compiler supports `long long'. This is
2157 set by the `configure' script.
2159 `PRINTF_HAS_LONG_LONG'
2160 Define this if the host can handle printing of long long integers
2161 via the printf format conversion specifier `ll'. This is set by
2162 the `configure' script.
2165 Define this if the host C compiler supports `long double'. This is
2166 set by the `configure' script.
2168 `PRINTF_HAS_LONG_DOUBLE'
2169 Define this if the host can handle printing of long double
2170 float-point numbers via the printf format conversion specifier
2171 `Lg'. This is set by the `configure' script.
2173 `SCANF_HAS_LONG_DOUBLE'
2174 Define this if the host can handle the parsing of long double
2175 float-point numbers via the scanf format conversion specifier
2176 `Lg'. This is set by the `configure' script.
2179 Define this if `lseek (n)' does not necessarily move to byte number
2180 `n' in the file. This is only used when reading source files. It
2181 is normally faster to define `CRLF_SOURCE_FILES' when possible.
2184 This macro is used as the argument to `lseek' (or, most commonly,
2185 `bfd_seek'). FIXME, should be replaced by SEEK_SET instead, which
2186 is the POSIX equivalent.
2189 If defined, this should be one or more tokens, such as `volatile',
2190 that can be used in both the declaration and definition of
2191 functions to indicate that they never return. The default is
2192 already set correctly if compiling with GCC. This will almost
2193 never need to be defined.
2196 If defined, this should be one or more tokens, such as
2197 `__attribute__ ((noreturn))', that can be used in the declarations
2198 of functions to indicate that they never return. The default is
2199 already set correctly if compiling with GCC. This will almost
2200 never need to be defined.
2204 Define these to appropriate value for the system `lseek', if not
2208 This is the signal for stopping GDB. Defaults to `SIGTSTP'.
2209 (Only redefined for the Convex.)
2212 Means that System V (prior to SVR4) include files are in use.
2213 (FIXME: This symbol is abused in `infrun.c', `regex.c', and
2214 `utils.c' for other things, at the moment.)
2217 Define this to help placate `lint' in some situations.
2220 Define this to override the defaults of `__volatile__' or `/**/'.
2223 File: gdbint.info, Node: Target Architecture Definition, Next: Target Vector Definition, Prev: Host Definition, Up: Top
2225 9 Target Architecture Definition
2226 ********************************
2228 GDB's target architecture defines what sort of machine-language
2229 programs GDB can work with, and how it works with them.
2231 The target architecture object is implemented as the C structure
2232 `struct gdbarch *'. The structure, and its methods, are generated
2233 using the Bourne shell script `gdbarch.sh'.
2235 9.1 Operating System ABI Variant Handling
2236 =========================================
2238 GDB provides a mechanism for handling variations in OS ABIs. An OS ABI
2239 variant may have influence over any number of variables in the target
2240 architecture definition. There are two major components in the OS ABI
2241 mechanism: sniffers and handlers.
2243 A "sniffer" examines a file matching a BFD architecture/flavour pair
2244 (the architecture may be wildcarded) in an attempt to determine the OS
2245 ABI of that file. Sniffers with a wildcarded architecture are
2246 considered to be "generic", while sniffers for a specific architecture
2247 are considered to be "specific". A match from a specific sniffer
2248 overrides a match from a generic sniffer. Multiple sniffers for an
2249 architecture/flavour may exist, in order to differentiate between two
2250 different operating systems which use the same basic file format. The
2251 OS ABI framework provides a generic sniffer for ELF-format files which
2252 examines the `EI_OSABI' field of the ELF header, as well as note
2253 sections known to be used by several operating systems.
2255 A "handler" is used to fine-tune the `gdbarch' structure for the
2256 selected OS ABI. There may be only one handler for a given OS ABI for
2257 each BFD architecture.
2259 The following OS ABI variants are defined in `osabi.h':
2262 The ABI of the inferior is unknown. The default `gdbarch'
2263 settings for the architecture will be used.
2266 UNIX System V Release 4
2269 GNU using the Hurd kernel
2275 OSF/1, including Digital UNIX and Compaq Tru64 UNIX
2278 GNU using the Linux kernel
2280 `GDB_OSABI_FREEBSD_AOUT'
2281 FreeBSD using the a.out executable format
2283 `GDB_OSABI_FREEBSD_ELF'
2284 FreeBSD using the ELF executable format
2286 `GDB_OSABI_NETBSD_AOUT'
2287 NetBSD using the a.out executable format
2289 `GDB_OSABI_NETBSD_ELF'
2290 NetBSD using the ELF executable format
2301 `GDB_OSABI_ARM_EABI_V1'
2302 ARM Embedded ABI version 1
2304 `GDB_OSABI_ARM_EABI_V2'
2305 ARM Embedded ABI version 2
2307 `GDB_OSABI_ARM_APCS'
2308 Generic ARM Procedure Call Standard
2311 Here are the functions that make up the OS ABI framework:
2313 -- Function: const char *gdbarch_osabi_name (enum gdb_osabi OSABI)
2314 Return the name of the OS ABI corresponding to OSABI.
2316 -- Function: void gdbarch_register_osabi (enum bfd_architecture ARCH,
2317 unsigned long MACHINE, enum gdb_osabi OSABI, void
2318 (*INIT_OSABI)(struct gdbarch_info INFO, struct gdbarch
2320 Register the OS ABI handler specified by INIT_OSABI for the
2321 architecture, machine type and OS ABI specified by ARCH, MACHINE
2322 and OSABI. In most cases, a value of zero for the machine type,
2323 which implies the architecture's default machine type, will
2326 -- Function: void gdbarch_register_osabi_sniffer (enum
2327 bfd_architecture ARCH, enum bfd_flavour FLAVOUR, enum
2328 gdb_osabi (*SNIFFER)(bfd *ABFD))
2329 Register the OS ABI file sniffer specified by SNIFFER for the BFD
2330 architecture/flavour pair specified by ARCH and FLAVOUR. If ARCH
2331 is `bfd_arch_unknown', the sniffer is considered to be generic,
2332 and is allowed to examine FLAVOUR-flavoured files for any
2335 -- Function: enum gdb_osabi gdbarch_lookup_osabi (bfd *ABFD)
2336 Examine the file described by ABFD to determine its OS ABI. The
2337 value `GDB_OSABI_UNKNOWN' is returned if the OS ABI cannot be
2340 -- Function: void gdbarch_init_osabi (struct gdbarch info INFO, struct
2341 gdbarch *GDBARCH, enum gdb_osabi OSABI)
2342 Invoke the OS ABI handler corresponding to OSABI to fine-tune the
2343 `gdbarch' structure specified by GDBARCH. If a handler
2344 corresponding to OSABI has not been registered for GDBARCH's
2345 architecture, a warning will be issued and the debugging session
2346 will continue with the defaults already established for GDBARCH.
2348 9.2 Registers and Memory
2349 ========================
2351 GDB's model of the target machine is rather simple. GDB assumes the
2352 machine includes a bank of registers and a block of memory. Each
2353 register may have a different size.
2355 GDB does not have a magical way to match up with the compiler's idea
2356 of which registers are which; however, it is critical that they do
2357 match up accurately. The only way to make this work is to get accurate
2358 information about the order that the compiler uses, and to reflect that
2359 in the `REGISTER_NAME' and related macros.
2361 GDB can handle big-endian, little-endian, and bi-endian
2364 9.3 Pointers Are Not Always Addresses
2365 =====================================
2367 On almost all 32-bit architectures, the representation of a pointer is
2368 indistinguishable from the representation of some fixed-length number
2369 whose value is the byte address of the object pointed to. On such
2370 machines, the words "pointer" and "address" can be used interchangeably.
2371 However, architectures with smaller word sizes are often cramped for
2372 address space, so they may choose a pointer representation that breaks
2373 this identity, and allows a larger code address space.
2375 For example, the Renesas D10V is a 16-bit VLIW processor whose
2376 instructions are 32 bits long(1). If the D10V used ordinary byte
2377 addresses to refer to code locations, then the processor would only be
2378 able to address 64kb of instructions. However, since instructions must
2379 be aligned on four-byte boundaries, the low two bits of any valid
2380 instruction's byte address are always zero--byte addresses waste two
2381 bits. So instead of byte addresses, the D10V uses word addresses--byte
2382 addresses shifted right two bits--to refer to code. Thus, the D10V can
2383 use 16-bit words to address 256kb of code space.
2385 However, this means that code pointers and data pointers have
2386 different forms on the D10V. The 16-bit word `0xC020' refers to byte
2387 address `0xC020' when used as a data address, but refers to byte address
2388 `0x30080' when used as a code address.
2390 (The D10V also uses separate code and data address spaces, which also
2391 affects the correspondence between pointers and addresses, but we're
2392 going to ignore that here; this example is already too long.)
2394 To cope with architectures like this--the D10V is not the only
2395 one!--GDB tries to distinguish between "addresses", which are byte
2396 numbers, and "pointers", which are the target's representation of an
2397 address of a particular type of data. In the example above, `0xC020'
2398 is the pointer, which refers to one of the addresses `0xC020' or
2399 `0x30080', depending on the type imposed upon it. GDB provides
2400 functions for turning a pointer into an address and vice versa, in the
2401 appropriate way for the current architecture.
2403 Unfortunately, since addresses and pointers are identical on almost
2404 all processors, this distinction tends to bit-rot pretty quickly. Thus,
2405 each time you port GDB to an architecture which does distinguish
2406 between pointers and addresses, you'll probably need to clean up some
2407 architecture-independent code.
2409 Here are functions which convert between pointers and addresses:
2411 -- Function: CORE_ADDR extract_typed_address (void *BUF, struct type
2413 Treat the bytes at BUF as a pointer or reference of type TYPE, and
2414 return the address it represents, in a manner appropriate for the
2415 current architecture. This yields an address GDB can use to read
2416 target memory, disassemble, etc. Note that BUF refers to a buffer
2417 in GDB's memory, not the inferior's.
2419 For example, if the current architecture is the Intel x86, this
2420 function extracts a little-endian integer of the appropriate
2421 length from BUF and returns it. However, if the current
2422 architecture is the D10V, this function will return a 16-bit
2423 integer extracted from BUF, multiplied by four if TYPE is a
2424 pointer to a function.
2426 If TYPE is not a pointer or reference type, then this function
2427 will signal an internal error.
2429 -- Function: CORE_ADDR store_typed_address (void *BUF, struct type
2430 *TYPE, CORE_ADDR ADDR)
2431 Store the address ADDR in BUF, in the proper format for a pointer
2432 of type TYPE in the current architecture. Note that BUF refers to
2433 a buffer in GDB's memory, not the inferior's.
2435 For example, if the current architecture is the Intel x86, this
2436 function stores ADDR unmodified as a little-endian integer of the
2437 appropriate length in BUF. However, if the current architecture
2438 is the D10V, this function divides ADDR by four if TYPE is a
2439 pointer to a function, and then stores it in BUF.
2441 If TYPE is not a pointer or reference type, then this function
2442 will signal an internal error.
2444 -- Function: CORE_ADDR value_as_address (struct value *VAL)
2445 Assuming that VAL is a pointer, return the address it represents,
2446 as appropriate for the current architecture.
2448 This function actually works on integral values, as well as
2449 pointers. For pointers, it performs architecture-specific
2450 conversions as described above for `extract_typed_address'.
2452 -- Function: CORE_ADDR value_from_pointer (struct type *TYPE,
2454 Create and return a value representing a pointer of type TYPE to
2455 the address ADDR, as appropriate for the current architecture.
2456 This function performs architecture-specific conversions as
2457 described above for `store_typed_address'.
2459 Here are some macros which architectures can define to indicate the
2460 relationship between pointers and addresses. These have default
2461 definitions, appropriate for architectures on which all pointers are
2462 simple unsigned byte addresses.
2464 -- Target Macro: CORE_ADDR POINTER_TO_ADDRESS (struct type *TYPE, char
2466 Assume that BUF holds a pointer of type TYPE, in the appropriate
2467 format for the current architecture. Return the byte address the
2470 This function may safely assume that TYPE is either a pointer or a
2473 -- Target Macro: void ADDRESS_TO_POINTER (struct type *TYPE, char
2474 *BUF, CORE_ADDR ADDR)
2475 Store in BUF a pointer of type TYPE representing the address ADDR,
2476 in the appropriate format for the current architecture.
2478 This function may safely assume that TYPE is either a pointer or a
2484 Sometimes information about different kinds of addresses is available
2485 via the debug information. For example, some programming environments
2486 define addresses of several different sizes. If the debug information
2487 distinguishes these kinds of address classes through either the size
2488 info (e.g, `DW_AT_byte_size' in DWARF 2) or through an explicit address
2489 class attribute (e.g, `DW_AT_address_class' in DWARF 2), the following
2490 macros should be defined in order to disambiguate these types within
2491 GDB as well as provide the added information to a GDB user when
2492 printing type expressions.
2494 -- Target Macro: int ADDRESS_CLASS_TYPE_FLAGS (int BYTE_SIZE, int
2496 Returns the type flags needed to construct a pointer type whose
2497 size is BYTE_SIZE and whose address class is DWARF2_ADDR_CLASS.
2498 This function is normally called from within a symbol reader. See
2501 -- Target Macro: char *ADDRESS_CLASS_TYPE_FLAGS_TO_NAME (int
2503 Given the type flags representing an address class qualifier,
2506 -- Target Macro: int ADDRESS_CLASS_NAME_to_TYPE_FLAGS (int NAME, int
2508 Given an address qualifier name, set the `int' refererenced by
2509 TYPE_FLAGS_PTR to the type flags for that address class qualifier.
2511 Since the need for address classes is rather rare, none of the
2512 address class macros defined by default. Predicate macros are provided
2513 to detect when they are defined.
2515 Consider a hypothetical architecture in which addresses are normally
2516 32-bits wide, but 16-bit addresses are also supported. Furthermore,
2517 suppose that the DWARF 2 information for this architecture simply uses
2518 a `DW_AT_byte_size' value of 2 to indicate the use of one of these
2519 "short" pointers. The following functions could be defined to
2520 implement the address class macros:
2522 somearch_address_class_type_flags (int byte_size,
2523 int dwarf2_addr_class)
2526 return TYPE_FLAG_ADDRESS_CLASS_1;
2532 somearch_address_class_type_flags_to_name (int type_flags)
2534 if (type_flags & TYPE_FLAG_ADDRESS_CLASS_1)
2541 somearch_address_class_name_to_type_flags (char *name,
2542 int *type_flags_ptr)
2544 if (strcmp (name, "short") == 0)
2546 *type_flags_ptr = TYPE_FLAG_ADDRESS_CLASS_1;
2553 The qualifier `@short' is used in GDB's type expressions to indicate
2554 the presence of one of these "short" pointers. E.g, if the debug
2555 information indicates that `short_ptr_var' is one of these short
2556 pointers, GDB might show the following behavior:
2558 (gdb) ptype short_ptr_var
2561 9.5 Raw and Virtual Register Representations
2562 ============================================
2564 _Maintainer note: This section is pretty much obsolete. The
2565 functionality described here has largely been replaced by
2566 pseudo-registers and the mechanisms described in *Note Using Different
2567 Register and Memory Data Representations: Target Architecture
2568 Definition. See also Bug Tracking Database
2569 (http://www.gnu.org/software/gdb/bugs/) and ARI Index
2570 (http://sources.redhat.com/gdb/current/ari/) for more up-to-date
2573 Some architectures use one representation for a value when it lives
2574 in a register, but use a different representation when it lives in
2575 memory. In GDB's terminology, the "raw" representation is the one used
2576 in the target registers, and the "virtual" representation is the one
2577 used in memory, and within GDB `struct value' objects.
2579 _Maintainer note: Notice that the same mechanism is being used to
2580 both convert a register to a `struct value' and alternative register
2583 For almost all data types on almost all architectures, the virtual
2584 and raw representations are identical, and no special handling is
2585 needed. However, they do occasionally differ. For example:
2587 * The x86 architecture supports an 80-bit `long double' type.
2588 However, when we store those values in memory, they occupy twelve
2589 bytes: the floating-point number occupies the first ten, and the
2590 final two bytes are unused. This keeps the values aligned on
2591 four-byte boundaries, allowing more efficient access. Thus, the
2592 x86 80-bit floating-point type is the raw representation, and the
2593 twelve-byte loosely-packed arrangement is the virtual
2596 * Some 64-bit MIPS targets present 32-bit registers to GDB as 64-bit
2597 registers, with garbage in their upper bits. GDB ignores the top
2598 32 bits. Thus, the 64-bit form, with garbage in the upper 32
2599 bits, is the raw representation, and the trimmed 32-bit
2600 representation is the virtual representation.
2602 In general, the raw representation is determined by the
2603 architecture, or GDB's interface to the architecture, while the virtual
2604 representation can be chosen for GDB's convenience. GDB's register
2605 file, `registers', holds the register contents in raw format, and the
2606 GDB remote protocol transmits register values in raw format.
2608 Your architecture may define the following macros to request
2609 conversions between the raw and virtual format:
2611 -- Target Macro: int REGISTER_CONVERTIBLE (int REG)
2612 Return non-zero if register number REG's value needs different raw
2613 and virtual formats.
2615 You should not use `REGISTER_CONVERT_TO_VIRTUAL' for a register
2616 unless this macro returns a non-zero value for that register.
2618 -- Target Macro: int DEPRECATED_REGISTER_RAW_SIZE (int REG)
2619 The size of register number REG's raw value. This is the number
2620 of bytes the register will occupy in `registers', or in a GDB
2621 remote protocol packet.
2623 -- Target Macro: int DEPRECATED_REGISTER_VIRTUAL_SIZE (int REG)
2624 The size of register number REG's value, in its virtual format.
2625 This is the size a `struct value''s buffer will have, holding that
2628 -- Target Macro: struct type *DEPRECATED_REGISTER_VIRTUAL_TYPE (int
2630 This is the type of the virtual representation of register number
2631 REG. Note that there is no need for a macro giving a type for the
2632 register's raw form; once the register's value has been obtained,
2633 GDB always uses the virtual form.
2635 -- Target Macro: void REGISTER_CONVERT_TO_VIRTUAL (int REG, struct
2636 type *TYPE, char *FROM, char *TO)
2637 Convert the value of register number REG to TYPE, which should
2638 always be `DEPRECATED_REGISTER_VIRTUAL_TYPE (REG)'. The buffer at
2639 FROM holds the register's value in raw format; the macro should
2640 convert the value to virtual format, and place it at TO.
2642 Note that `REGISTER_CONVERT_TO_VIRTUAL' and
2643 `REGISTER_CONVERT_TO_RAW' take their REG and TYPE arguments in
2646 You should only use `REGISTER_CONVERT_TO_VIRTUAL' with registers
2647 for which the `REGISTER_CONVERTIBLE' macro returns a non-zero
2650 -- Target Macro: void REGISTER_CONVERT_TO_RAW (struct type *TYPE, int
2651 REG, char *FROM, char *TO)
2652 Convert the value of register number REG to TYPE, which should
2653 always be `DEPRECATED_REGISTER_VIRTUAL_TYPE (REG)'. The buffer at
2654 FROM holds the register's value in raw format; the macro should
2655 convert the value to virtual format, and place it at TO.
2657 Note that REGISTER_CONVERT_TO_VIRTUAL and REGISTER_CONVERT_TO_RAW
2658 take their REG and TYPE arguments in different orders.
2660 9.6 Using Different Register and Memory Data Representations
2661 ============================================================
2663 _Maintainer's note: The way GDB manipulates registers is undergoing
2664 significant change. Many of the macros and functions refered to in this
2665 section are likely to be subject to further revision. See A.R. Index
2666 (http://sources.redhat.com/gdb/current/ari/) and Bug Tracking Database
2667 (http://www.gnu.org/software/gdb/bugs) for further information.
2670 Some architectures can represent a data object in a register using a
2671 form that is different to the objects more normal memory representation.
2674 * The Alpha architecture can represent 32 bit integer values in
2675 floating-point registers.
2677 * The x86 architecture supports 80-bit floating-point registers. The
2678 `long double' data type occupies 96 bits in memory but only 80 bits
2679 when stored in a register.
2682 In general, the register representation of a data type is determined
2683 by the architecture, or GDB's interface to the architecture, while the
2684 memory representation is determined by the Application Binary Interface.
2686 For almost all data types on almost all architectures, the two
2687 representations are identical, and no special handling is needed.
2688 However, they do occasionally differ. Your architecture may define the
2689 following macros to request conversions between the register and memory
2690 representations of a data type:
2692 -- Target Macro: int CONVERT_REGISTER_P (int REG)
2693 Return non-zero if the representation of a data value stored in
2694 this register may be different to the representation of that same
2695 data value when stored in memory.
2697 When non-zero, the macros `REGISTER_TO_VALUE' and
2698 `VALUE_TO_REGISTER' are used to perform any necessary conversion.
2700 -- Target Macro: void REGISTER_TO_VALUE (int REG, struct type *TYPE,
2701 char *FROM, char *TO)
2702 Convert the value of register number REG to a data object of type
2703 TYPE. The buffer at FROM holds the register's value in raw
2704 format; the converted value should be placed in the buffer at TO.
2706 Note that `REGISTER_TO_VALUE' and `VALUE_TO_REGISTER' take their
2707 REG and TYPE arguments in different orders.
2709 You should only use `REGISTER_TO_VALUE' with registers for which
2710 the `CONVERT_REGISTER_P' macro returns a non-zero value.
2712 -- Target Macro: void VALUE_TO_REGISTER (struct type *TYPE, int REG,
2713 char *FROM, char *TO)
2714 Convert a data value of type TYPE to register number REG' raw
2717 Note that `REGISTER_TO_VALUE' and `VALUE_TO_REGISTER' take their
2718 REG and TYPE arguments in different orders.
2720 You should only use `VALUE_TO_REGISTER' with registers for which
2721 the `CONVERT_REGISTER_P' macro returns a non-zero value.
2723 -- Target Macro: void REGISTER_CONVERT_TO_TYPE (int REGNUM, struct
2724 type *TYPE, char *BUF)
2725 See `mips-tdep.c'. It does not do what you want.
2727 9.7 Frame Interpretation
2728 ========================
2730 9.8 Inferior Call Setup
2731 =======================
2733 9.9 Compiler Characteristics
2734 ============================
2736 9.10 Target Conditionals
2737 ========================
2739 This section describes the macros that you can use to define the target
2742 `ADDR_BITS_REMOVE (addr)'
2743 If a raw machine instruction address includes any bits that are not
2744 really part of the address, then define this macro to expand into
2745 an expression that zeroes those bits in ADDR. This is only used
2746 for addresses of instructions, and even then not in all contexts.
2748 For example, the two low-order bits of the PC on the
2749 Hewlett-Packard PA 2.0 architecture contain the privilege level of
2750 the corresponding instruction. Since instructions must always be
2751 aligned on four-byte boundaries, the processor masks out these
2752 bits to generate the actual address of the instruction.
2753 ADDR_BITS_REMOVE should filter out these bits with an expression
2754 such as `((addr) & ~3)'.
2756 `ADDRESS_CLASS_NAME_TO_TYPE_FLAGS (NAME, TYPE_FLAGS_PTR)'
2757 If NAME is a valid address class qualifier name, set the `int'
2758 referenced by TYPE_FLAGS_PTR to the mask representing the qualifier
2759 and return 1. If NAME is not a valid address class qualifier name,
2762 The value for TYPE_FLAGS_PTR should be one of
2763 `TYPE_FLAG_ADDRESS_CLASS_1', `TYPE_FLAG_ADDRESS_CLASS_2', or
2764 possibly some combination of these values or'd together. *Note
2765 Address Classes: Target Architecture Definition.
2767 `ADDRESS_CLASS_NAME_TO_TYPE_FLAGS_P ()'
2768 Predicate which indicates whether
2769 `ADDRESS_CLASS_NAME_TO_TYPE_FLAGS' has been defined.
2771 `ADDRESS_CLASS_TYPE_FLAGS (BYTE_SIZE, DWARF2_ADDR_CLASS)'
2772 Given a pointers byte size (as described by the debug information)
2773 and the possible `DW_AT_address_class' value, return the type flags
2774 used by GDB to represent this address class. The value returned
2775 should be one of `TYPE_FLAG_ADDRESS_CLASS_1',
2776 `TYPE_FLAG_ADDRESS_CLASS_2', or possibly some combination of these
2777 values or'd together. *Note Address Classes: Target Architecture
2780 `ADDRESS_CLASS_TYPE_FLAGS_P ()'
2781 Predicate which indicates whether `ADDRESS_CLASS_TYPE_FLAGS' has
2784 `ADDRESS_CLASS_TYPE_FLAGS_TO_NAME (TYPE_FLAGS)'
2785 Return the name of the address class qualifier associated with the
2786 type flags given by TYPE_FLAGS.
2788 `ADDRESS_CLASS_TYPE_FLAGS_TO_NAME_P ()'
2789 Predicate which indicates whether
2790 `ADDRESS_CLASS_TYPE_FLAGS_TO_NAME' has been defined. *Note
2791 Address Classes: Target Architecture Definition.
2793 `ADDRESS_TO_POINTER (TYPE, BUF, ADDR)'
2794 Store in BUF a pointer of type TYPE representing the address ADDR,
2795 in the appropriate format for the current architecture. This
2796 macro may safely assume that TYPE is either a pointer or a C++
2797 reference type. *Note Pointers Are Not Always Addresses: Target
2798 Architecture Definition.
2800 `BELIEVE_PCC_PROMOTION'
2801 Define if the compiler promotes a `short' or `char' parameter to
2802 an `int', but still reports the parameter as its original type,
2803 rather than the promoted type.
2806 Define this if the numbering of bits in the targets does *not*
2807 match the endianness of the target byte order. A value of 1 means
2808 that the bits are numbered in a big-endian bit order, 0 means
2812 This is the character array initializer for the bit pattern to put
2813 into memory where a breakpoint is set. Although it's common to
2814 use a trap instruction for a breakpoint, it's not required; for
2815 instance, the bit pattern could be an invalid instruction. The
2816 breakpoint must be no longer than the shortest instruction of the
2819 `BREAKPOINT' has been deprecated in favor of `BREAKPOINT_FROM_PC'.
2823 Similar to BREAKPOINT, but used for bi-endian targets.
2825 `BIG_BREAKPOINT' and `LITTLE_BREAKPOINT' have been deprecated in
2826 favor of `BREAKPOINT_FROM_PC'.
2828 `DEPRECATED_REMOTE_BREAKPOINT'
2829 `DEPRECATED_LITTLE_REMOTE_BREAKPOINT'
2830 `DEPRECATED_BIG_REMOTE_BREAKPOINT'
2831 Specify the breakpoint instruction sequence for a remote target.
2832 `DEPRECATED_REMOTE_BREAKPOINT', `DEPRECATED_BIG_REMOTE_BREAKPOINT'
2833 and `DEPRECATED_LITTLE_REMOTE_BREAKPOINT' have been deprecated in
2834 favor of `BREAKPOINT_FROM_PC' (*note BREAKPOINT_FROM_PC::).
2836 `BREAKPOINT_FROM_PC (PCPTR, LENPTR)'
2837 Use the program counter to determine the contents and size of a
2838 breakpoint instruction. It returns a pointer to a string of bytes
2839 that encode a breakpoint instruction, stores the length of the
2840 string to `*LENPTR', and adjusts the program counter (if
2841 necessary) to point to the actual memory location where the
2842 breakpoint should be inserted.
2844 Although it is common to use a trap instruction for a breakpoint,
2845 it's not required; for instance, the bit pattern could be an
2846 invalid instruction. The breakpoint must be no longer than the
2847 shortest instruction of the architecture.
2849 Replaces all the other BREAKPOINT macros.
2851 `MEMORY_INSERT_BREAKPOINT (BP_TGT)'
2852 `MEMORY_REMOVE_BREAKPOINT (BP_TGT)'
2853 Insert or remove memory based breakpoints. Reasonable defaults
2854 (`default_memory_insert_breakpoint' and
2855 `default_memory_remove_breakpoint' respectively) have been
2856 provided so that it is not necessary to define these for most
2857 architectures. Architectures which may want to define
2858 `MEMORY_INSERT_BREAKPOINT' and `MEMORY_REMOVE_BREAKPOINT' will
2859 likely have instructions that are oddly sized or are not stored in
2860 a conventional manner.
2862 It may also be desirable (from an efficiency standpoint) to define
2863 custom breakpoint insertion and removal routines if
2864 `BREAKPOINT_FROM_PC' needs to read the target's memory for some
2867 `ADJUST_BREAKPOINT_ADDRESS (ADDRESS)'
2868 Given an address at which a breakpoint is desired, return a
2869 breakpoint address adjusted to account for architectural
2870 constraints on breakpoint placement. This method is not needed by
2873 The FR-V target (see `frv-tdep.c') requires this method. The FR-V
2874 is a VLIW architecture in which a number of RISC-like instructions
2875 are grouped (packed) together into an aggregate instruction or
2876 instruction bundle. When the processor executes one of these
2877 bundles, the component instructions are executed in parallel.
2879 In the course of optimization, the compiler may group instructions
2880 from distinct source statements into the same bundle. The line
2881 number information associated with one of the latter statements
2882 will likely refer to some instruction other than the first one in
2883 the bundle. So, if the user attempts to place a breakpoint on one
2884 of these latter statements, GDB must be careful to _not_ place the
2885 break instruction on any instruction other than the first one in
2886 the bundle. (Remember though that the instructions within a
2887 bundle execute in parallel, so the _first_ instruction is the
2888 instruction at the lowest address and has nothing to do with
2891 The FR-V's `ADJUST_BREAKPOINT_ADDRESS' method will adjust a
2892 breakpoint's address by scanning backwards for the beginning of
2893 the bundle, returning the address of the bundle.
2895 Since the adjustment of a breakpoint may significantly alter a
2896 user's expectation, GDB prints a warning when an adjusted
2897 breakpoint is initially set and each time that that breakpoint is
2900 `CALL_DUMMY_LOCATION'
2901 See the file `inferior.h'.
2903 This method has been replaced by `push_dummy_code' (*note
2906 `CANNOT_FETCH_REGISTER (REGNO)'
2907 A C expression that should be nonzero if REGNO cannot be fetched
2908 from an inferior process. This is only relevant if
2909 `FETCH_INFERIOR_REGISTERS' is not defined.
2911 `CANNOT_STORE_REGISTER (REGNO)'
2912 A C expression that should be nonzero if REGNO should not be
2913 written to the target. This is often the case for program
2914 counters, status words, and other special registers. If this is
2915 not defined, GDB will assume that all registers may be written.
2917 `int CONVERT_REGISTER_P(REGNUM)'
2918 Return non-zero if register REGNUM can represent data values in a
2919 non-standard form. *Note Using Different Register and Memory Data
2920 Representations: Target Architecture Definition.
2922 `DECR_PC_AFTER_BREAK'
2923 Define this to be the amount by which to decrement the PC after the
2924 program encounters a breakpoint. This is often the number of
2925 bytes in `BREAKPOINT', though not always. For most targets this
2928 `DISABLE_UNSETTABLE_BREAK (ADDR)'
2929 If defined, this should evaluate to 1 if ADDR is in a shared
2930 library in which breakpoints cannot be set and so should be
2933 `PRINT_FLOAT_INFO()'
2934 If defined, then the `info float' command will print information
2935 about the processor's floating point unit.
2937 `print_registers_info (GDBARCH, FRAME, REGNUM, ALL)'
2938 If defined, pretty print the value of the register REGNUM for the
2939 specified FRAME. If the value of REGNUM is -1, pretty print
2940 either all registers (ALL is non zero) or a select subset of
2941 registers (ALL is zero).
2943 The default method prints one register per line, and if ALL is
2944 zero omits floating-point registers.
2946 `PRINT_VECTOR_INFO()'
2947 If defined, then the `info vector' command will call this function
2948 to print information about the processor's vector unit.
2950 By default, the `info vector' command will print all vector
2951 registers (the register's type having the vector attribute).
2953 `DWARF_REG_TO_REGNUM'
2954 Convert DWARF register number into GDB regnum. If not defined, no
2955 conversion will be performed.
2957 `DWARF2_REG_TO_REGNUM'
2958 Convert DWARF2 register number into GDB regnum. If not defined,
2959 no conversion will be performed.
2961 `ECOFF_REG_TO_REGNUM'
2962 Convert ECOFF register number into GDB regnum. If not defined, no
2963 conversion will be performed.
2965 `END_OF_TEXT_DEFAULT'
2966 This is an expression that should designate the end of the text
2969 `EXTRACT_RETURN_VALUE(TYPE, REGBUF, VALBUF)'
2970 Define this to extract a function's return value of type TYPE from
2971 the raw register state REGBUF and copy that, in virtual format,
2974 This method has been deprecated in favour of `gdbarch_return_value'
2975 (*note gdbarch_return_value::).
2977 `DEPRECATED_EXTRACT_STRUCT_VALUE_ADDRESS(REGBUF)'
2978 When defined, extract from the array REGBUF (containing the raw
2979 register state) the `CORE_ADDR' at which a function should return
2980 its structure value.
2982 *Note gdbarch_return_value::.
2984 `DEPRECATED_EXTRACT_STRUCT_VALUE_ADDRESS_P()'
2985 Predicate for `DEPRECATED_EXTRACT_STRUCT_VALUE_ADDRESS'.
2987 `DEPRECATED_FP_REGNUM'
2988 If the virtual frame pointer is kept in a register, then define
2989 this macro to be the number (greater than or equal to zero) of
2992 This should only need to be defined if `DEPRECATED_TARGET_READ_FP'
2995 `DEPRECATED_FRAMELESS_FUNCTION_INVOCATION(FI)'
2996 Define this to an expression that returns 1 if the function
2997 invocation represented by FI does not have a stack frame
2998 associated with it. Otherwise return 0.
3000 `frame_align (ADDRESS)'
3001 Define this to adjust ADDRESS so that it meets the alignment
3002 requirements for the start of a new stack frame. A stack frame's
3003 alignment requirements are typically stronger than a target
3004 processors stack alignment requirements (*note
3005 DEPRECATED_STACK_ALIGN::).
3007 This function is used to ensure that, when creating a dummy frame,
3008 both the initial stack pointer and (if needed) the address of the
3009 return value are correctly aligned.
3011 Unlike `DEPRECATED_STACK_ALIGN', this function always adjusts the
3012 address in the direction of stack growth.
3014 By default, no frame based stack alignment is performed.
3016 `int frame_red_zone_size'
3017 The number of bytes, beyond the innermost-stack-address, reserved
3018 by the ABI. A function is permitted to use this scratch area
3019 (instead of allocating extra stack space).
3021 When performing an inferior function call, to ensure that it does
3022 not modify this area, GDB adjusts the innermost-stack-address by
3023 FRAME_RED_ZONE_SIZE bytes before pushing parameters onto the stack.
3025 By default, zero bytes are allocated. The value must be aligned
3026 (*note frame_align::).
3028 The AMD64 (nee x86-64) ABI documentation refers to the _red zone_
3029 when describing this scratch area.
3031 `DEPRECATED_FRAME_CHAIN(FRAME)'
3032 Given FRAME, return a pointer to the calling frame.
3034 `DEPRECATED_FRAME_CHAIN_VALID(CHAIN, THISFRAME)'
3035 Define this to be an expression that returns zero if the given
3036 frame is an outermost frame, with no caller, and nonzero
3037 otherwise. Most normal situations can be handled without defining
3038 this macro, including `NULL' chain pointers, dummy frames, and
3039 frames whose PC values are inside the startup file (e.g.
3040 `crt0.o'), inside `main', or inside `_start'.
3042 `DEPRECATED_FRAME_INIT_SAVED_REGS(FRAME)'
3043 See `frame.h'. Determines the address of all registers in the
3044 current stack frame storing each in `frame->saved_regs'. Space for
3045 `frame->saved_regs' shall be allocated by
3046 `DEPRECATED_FRAME_INIT_SAVED_REGS' using `frame_saved_regs_zalloc'.
3048 `FRAME_FIND_SAVED_REGS' is deprecated.
3050 `FRAME_NUM_ARGS (FI)'
3051 For the frame described by FI return the number of arguments that
3052 are being passed. If the number of arguments is not known, return
3055 `DEPRECATED_FRAME_SAVED_PC(FRAME)'
3056 Given FRAME, return the pc saved there. This is the return
3059 This method is deprecated. *Note unwind_pc::.
3061 `CORE_ADDR unwind_pc (struct frame_info *THIS_FRAME)'
3062 Return the instruction address, in THIS_FRAME's caller, at which
3063 execution will resume after THIS_FRAME returns. This is commonly
3064 refered to as the return address.
3066 The implementation, which must be frame agnostic (work with any
3067 frame), is typically no more than:
3070 frame_unwind_unsigned_register (this_frame, D10V_PC_REGNUM, &pc);
3071 return d10v_make_iaddr (pc);
3073 *Note DEPRECATED_FRAME_SAVED_PC::, which this method replaces.
3075 `CORE_ADDR unwind_sp (struct frame_info *THIS_FRAME)'
3076 Return the frame's inner most stack address. This is commonly
3077 refered to as the frame's "stack pointer".
3079 The implementation, which must be frame agnostic (work with any
3080 frame), is typically no more than:
3083 frame_unwind_unsigned_register (this_frame, D10V_SP_REGNUM, &sp);
3084 return d10v_make_daddr (sp);
3086 *Note TARGET_READ_SP::, which this method replaces.
3088 `FUNCTION_EPILOGUE_SIZE'
3089 For some COFF targets, the `x_sym.x_misc.x_fsize' field of the
3090 function end symbol is 0. For such targets, you must define
3091 `FUNCTION_EPILOGUE_SIZE' to expand into the standard size of a
3092 function's epilogue.
3094 `DEPRECATED_FUNCTION_START_OFFSET'
3095 An integer, giving the offset in bytes from a function's address
3096 (as used in the values of symbols, function pointers, etc.), and
3097 the function's first genuine instruction.
3099 This is zero on almost all machines: the function's address is
3100 usually the address of its first instruction. However, on the
3101 VAX, for example, each function starts with two bytes containing a
3102 bitmask indicating which registers to save upon entry to the
3103 function. The VAX `call' instructions check this value, and save
3104 the appropriate registers automatically. Thus, since the offset
3105 from the function's address to its first instruction is two bytes,
3106 `DEPRECATED_FUNCTION_START_OFFSET' would be 2 on the VAX.
3108 `GCC_COMPILED_FLAG_SYMBOL'
3109 `GCC2_COMPILED_FLAG_SYMBOL'
3110 If defined, these are the names of the symbols that GDB will look
3111 for to detect that GCC compiled the file. The default symbols are
3112 `gcc_compiled.' and `gcc2_compiled.', respectively. (Currently
3113 only defined for the Delta 68.)
3116 If defined and non-zero, enables support for multiple architectures
3119 This support can be enabled at two levels. At level one, only
3120 definitions for previously undefined macros are provided; at level
3121 two, a multi-arch definition of all architecture dependent macros
3124 `GDB_TARGET_IS_HPPA'
3125 This determines whether horrible kludge code in `dbxread.c' and
3126 `partial-stab.h' is used to mangle multiple-symbol-table files from
3127 HPPA's. This should all be ripped out, and a scheme like
3128 `elfread.c' used instead.
3130 `GET_LONGJMP_TARGET'
3131 For most machines, this is a target-dependent parameter. On the
3132 DECstation and the Iris, this is a native-dependent parameter,
3133 since the header file `setjmp.h' is needed to define it.
3135 This macro determines the target PC address that `longjmp' will
3136 jump to, assuming that we have just stopped at a `longjmp'
3137 breakpoint. It takes a `CORE_ADDR *' as argument, and stores the
3138 target PC value through this pointer. It examines the current
3139 state of the machine as needed.
3141 `DEPRECATED_GET_SAVED_REGISTER'
3142 Define this if you need to supply your own definition for the
3143 function `DEPRECATED_GET_SAVED_REGISTER'.
3145 `DEPRECATED_IBM6000_TARGET'
3146 Shows that we are configured for an IBM RS/6000 system. This
3147 conditional should be eliminated (FIXME) and replaced by
3148 feature-specific macros. It was introduced in a haste and we are
3149 repenting at leisure.
3151 `I386_USE_GENERIC_WATCHPOINTS'
3152 An x86-based target can define this to use the generic x86
3153 watchpoint support; see *Note I386_USE_GENERIC_WATCHPOINTS:
3156 `SYMBOLS_CAN_START_WITH_DOLLAR'
3157 Some systems have routines whose names start with `$'. Giving this
3158 macro a non-zero value tells GDB's expression parser to check for
3159 such routines when parsing tokens that begin with `$'.
3161 On HP-UX, certain system routines (millicode) have names beginning
3162 with `$' or `$$'. For example, `$$dyncall' is a millicode routine
3163 that handles inter-space procedure calls on PA-RISC.
3165 `DEPRECATED_INIT_EXTRA_FRAME_INFO (FROMLEAF, FRAME)'
3166 If additional information about the frame is required this should
3167 be stored in `frame->extra_info'. Space for `frame->extra_info'
3168 is allocated using `frame_extra_info_zalloc'.
3170 `DEPRECATED_INIT_FRAME_PC (FROMLEAF, PREV)'
3171 This is a C statement that sets the pc of the frame pointed to by
3172 PREV. [By default...]
3174 `INNER_THAN (LHS, RHS)'
3175 Returns non-zero if stack address LHS is inner than (nearer to the
3176 stack top) stack address RHS. Define this as `lhs < rhs' if the
3177 target's stack grows downward in memory, or `lhs > rsh' if the
3180 `gdbarch_in_function_epilogue_p (GDBARCH, PC)'
3181 Returns non-zero if the given PC is in the epilogue of a function.
3182 The epilogue of a function is defined as the part of a function
3183 where the stack frame of the function already has been destroyed
3184 up to the final `return from function call' instruction.
3186 `DEPRECATED_SIGTRAMP_START (PC)'
3187 `DEPRECATED_SIGTRAMP_END (PC)'
3188 Define these to be the start and end address of the `sigtramp' for
3189 the given PC. On machines where the address is just a compile time
3190 constant, the macro expansion will typically just ignore the
3193 `IN_SOLIB_CALL_TRAMPOLINE (PC, NAME)'
3194 Define this to evaluate to nonzero if the program is stopped in the
3195 trampoline that connects to a shared library.
3197 `IN_SOLIB_RETURN_TRAMPOLINE (PC, NAME)'
3198 Define this to evaluate to nonzero if the program is stopped in the
3199 trampoline that returns from a shared library.
3201 `IN_SOLIB_DYNSYM_RESOLVE_CODE (PC)'
3202 Define this to evaluate to nonzero if the program is stopped in the
3205 `SKIP_SOLIB_RESOLVER (PC)'
3206 Define this to evaluate to the (nonzero) address at which execution
3207 should continue to get past the dynamic linker's symbol resolution
3208 function. A zero value indicates that it is not important or
3209 necessary to set a breakpoint to get through the dynamic linker
3210 and that single stepping will suffice.
3212 `INTEGER_TO_ADDRESS (TYPE, BUF)'
3213 Define this when the architecture needs to handle non-pointer to
3214 address conversions specially. Converts that value to an address
3215 according to the current architectures conventions.
3217 _Pragmatics: When the user copies a well defined expression from
3218 their source code and passes it, as a parameter, to GDB's `print'
3219 command, they should get the same value as would have been
3220 computed by the target program. Any deviation from this rule can
3221 cause major confusion and annoyance, and needs to be justified
3222 carefully. In other words, GDB doesn't really have the freedom to
3223 do these conversions in clever and useful ways. It has, however,
3224 been pointed out that users aren't complaining about how GDB casts
3225 integers to pointers; they are complaining that they can't take an
3226 address from a disassembly listing and give it to `x/i'. Adding
3227 an architecture method like `INTEGER_TO_ADDRESS' certainly makes
3228 it possible for GDB to "get it right" in all circumstances._
3230 *Note Pointers Are Not Always Addresses: Target Architecture
3234 (Specific to the a29k.)
3236 `POINTER_TO_ADDRESS (TYPE, BUF)'
3237 Assume that BUF holds a pointer of type TYPE, in the appropriate
3238 format for the current architecture. Return the byte address the
3239 pointer refers to. *Note Pointers Are Not Always Addresses:
3240 Target Architecture Definition.
3242 `REGISTER_CONVERTIBLE (REG)'
3243 Return non-zero if REG uses different raw and virtual formats.
3244 *Note Raw and Virtual Register Representations: Target
3245 Architecture Definition.
3247 `REGISTER_TO_VALUE(REGNUM, TYPE, FROM, TO)'
3248 Convert the raw contents of register REGNUM into a value of type
3249 TYPE. *Note Using Different Register and Memory Data
3250 Representations: Target Architecture Definition.
3252 `DEPRECATED_REGISTER_RAW_SIZE (REG)'
3253 Return the raw size of REG; defaults to the size of the register's
3254 virtual type. *Note Raw and Virtual Register Representations:
3255 Target Architecture Definition.
3257 `register_reggroup_p (GDBARCH, REGNUM, REGGROUP)'
3258 Return non-zero if register REGNUM is a member of the register
3261 By default, registers are grouped as follows:
3264 Any register with a valid name and a floating-point type.
3267 Any register with a valid name and a vector type.
3270 Any register with a valid name and a type other than vector or
3271 floating-point. `float_reggroup'.
3276 Any register with a valid name.
3278 `DEPRECATED_REGISTER_VIRTUAL_SIZE (REG)'
3279 Return the virtual size of REG; defaults to the size of the
3280 register's virtual type. Return the virtual size of REG. *Note
3281 Raw and Virtual Register Representations: Target Architecture
3284 `DEPRECATED_REGISTER_VIRTUAL_TYPE (REG)'
3285 Return the virtual type of REG. *Note Raw and Virtual Register
3286 Representations: Target Architecture Definition.
3288 `struct type *register_type (GDBARCH, REG)'
3289 If defined, return the type of register REG. This function
3290 superseeds `DEPRECATED_REGISTER_VIRTUAL_TYPE'. *Note Raw and
3291 Virtual Register Representations: Target Architecture Definition.
3293 `REGISTER_CONVERT_TO_VIRTUAL(REG, TYPE, FROM, TO)'
3294 Convert the value of register REG from its raw form to its virtual
3295 form. *Note Raw and Virtual Register Representations: Target
3296 Architecture Definition.
3298 `REGISTER_CONVERT_TO_RAW(TYPE, REG, FROM, TO)'
3299 Convert the value of register REG from its virtual form to its raw
3300 form. *Note Raw and Virtual Register Representations: Target
3301 Architecture Definition.
3303 `const struct regset *regset_from_core_section (struct gdbarch * GDBARCH, const char * SECT_NAME, size_t SECT_SIZE)'
3304 Return the appropriate register set for a core file section with
3305 name SECT_NAME and size SECT_SIZE.
3307 `SOFTWARE_SINGLE_STEP_P()'
3308 Define this as 1 if the target does not have a hardware single-step
3309 mechanism. The macro `SOFTWARE_SINGLE_STEP' must also be defined.
3311 `SOFTWARE_SINGLE_STEP(SIGNAL, INSERT_BREAPOINTS_P)'
3312 A function that inserts or removes (depending on
3313 INSERT_BREAPOINTS_P) breakpoints at each possible destinations of
3314 the next instruction. See `sparc-tdep.c' and `rs6000-tdep.c' for
3317 `SOFUN_ADDRESS_MAYBE_MISSING'
3318 Somebody clever observed that, the more actual addresses you have
3319 in the debug information, the more time the linker has to spend
3320 relocating them. So whenever there's some other way the debugger
3321 could find the address it needs, you should omit it from the debug
3322 info, to make linking faster.
3324 `SOFUN_ADDRESS_MAYBE_MISSING' indicates that a particular set of
3325 hacks of this sort are in use, affecting `N_SO' and `N_FUN'
3326 entries in stabs-format debugging information. `N_SO' stabs mark
3327 the beginning and ending addresses of compilation units in the text
3328 segment. `N_FUN' stabs mark the starts and ends of functions.
3330 `SOFUN_ADDRESS_MAYBE_MISSING' means two things:
3332 * `N_FUN' stabs have an address of zero. Instead, you should
3333 find the addresses where the function starts by taking the
3334 function name from the stab, and then looking that up in the
3335 minsyms (the linker/assembler symbol table). In other words,
3336 the stab has the name, and the linker/assembler symbol table
3337 is the only place that carries the address.
3339 * `N_SO' stabs have an address of zero, too. You just look at
3340 the `N_FUN' stabs that appear before and after the `N_SO'
3341 stab, and guess the starting and ending addresses of the
3342 compilation unit from them.
3345 If defined, print information about the load segment for the
3346 program counter. (Defined only for the RS/6000.)
3349 If the program counter is kept in a register, then define this
3350 macro to be the number (greater than or equal to zero) of that
3353 This should only need to be defined if `TARGET_READ_PC' and
3354 `TARGET_WRITE_PC' are not defined.
3357 If non-zero, round arguments to a boundary of this many bits before
3358 pushing them on the stack.
3360 `stabs_argument_has_addr (GDBARCH, TYPE)'
3361 Define this to return nonzero if a function argument of type TYPE
3362 is passed by reference instead of value.
3364 This method replaces `DEPRECATED_REG_STRUCT_HAS_ADDR' (*note
3365 DEPRECATED_REG_STRUCT_HAS_ADDR::).
3367 `PROCESS_LINENUMBER_HOOK'
3368 A hook defined for XCOFF reading.
3370 `PROLOGUE_FIRSTLINE_OVERLAP'
3371 (Only used in unsupported Convex configuration.)
3374 If defined, this is the number of the processor status register.
3375 (This definition is only used in generic code when parsing "$ps".)
3377 `DEPRECATED_POP_FRAME'
3378 If defined, used by `frame_pop' to remove a stack frame. This
3379 method has been superseeded by generic code.
3381 `push_dummy_call (GDBARCH, FUNCTION, REGCACHE, PC_ADDR, NARGS, ARGS, SP, STRUCT_RETURN, STRUCT_ADDR)'
3382 Define this to push the dummy frame's call to the inferior
3383 function onto the stack. In addition to pushing NARGS, the code
3384 should push STRUCT_ADDR (when STRUCT_RETURN), and the return
3387 FUNCTION is a pointer to a `struct value'; on architectures that
3388 use function descriptors, this contains the function descriptor
3391 Returns the updated top-of-stack pointer.
3393 This method replaces `DEPRECATED_PUSH_ARGUMENTS'.
3395 `CORE_ADDR push_dummy_code (GDBARCH, SP, FUNADDR, USING_GCC, ARGS, NARGS, VALUE_TYPE, REAL_PC, BP_ADDR)'
3396 Given a stack based call dummy, push the instruction sequence
3397 (including space for a breakpoint) to which the called function
3400 Set BP_ADDR to the address at which the breakpoint instruction
3401 should be inserted, REAL_PC to the resume address when starting
3402 the call sequence, and return the updated inner-most stack address.
3404 By default, the stack is grown sufficient to hold a frame-aligned
3405 (*note frame_align::) breakpoint, BP_ADDR is set to the address
3406 reserved for that breakpoint, and REAL_PC set to FUNADDR.
3408 This method replaces `CALL_DUMMY_LOCATION',
3409 `DEPRECATED_REGISTER_SIZE'.
3412 Return the name of register I as a string. May return `NULL' or
3413 `NUL' to indicate that register I is not valid.
3415 `DEPRECATED_REG_STRUCT_HAS_ADDR (GCC_P, TYPE)'
3416 Define this to return 1 if the given type will be passed by
3417 pointer rather than directly.
3419 This method has been replaced by `stabs_argument_has_addr' (*note
3420 stabs_argument_has_addr::).
3422 `SAVE_DUMMY_FRAME_TOS (SP)'
3423 Used in `call_function_by_hand' to notify the target dependent
3424 code of the top-of-stack value that will be passed to the the
3425 inferior code. This is the value of the `SP' after both the dummy
3426 frame and space for parameters/results have been allocated on the
3427 stack. *Note unwind_dummy_id::.
3430 Define this to convert sdb register numbers into GDB regnums. If
3431 not defined, no conversion will be done.
3433 `enum return_value_convention gdbarch_return_value (struct gdbarch *GDBARCH, struct type *VALTYPE, struct regcache *REGCACHE, void *READBUF, const void *WRITEBUF)'
3434 Given a function with a return-value of type RETTYPE, return which
3435 return-value convention that function would use.
3437 GDB currently recognizes two function return-value conventions:
3438 `RETURN_VALUE_REGISTER_CONVENTION' where the return value is found
3439 in registers; and `RETURN_VALUE_STRUCT_CONVENTION' where the return
3440 value is found in memory and the address of that memory location is
3441 passed in as the function's first parameter.
3443 If the register convention is being used, and WRITEBUF is
3444 non-`NULL', also copy the return-value in WRITEBUF into REGCACHE.
3446 If the register convention is being used, and READBUF is
3447 non-`NULL', also copy the return value from REGCACHE into READBUF
3448 (REGCACHE contains a copy of the registers from the just returned
3451 *Note DEPRECATED_EXTRACT_STRUCT_VALUE_ADDRESS::, for a description
3452 of how return-values that use the struct convention are handled.
3454 _Maintainer note: This method replaces separate predicate, extract,
3455 store methods. By having only one method, the logic needed to
3456 determine the return-value convention need only be implemented in
3457 one place. If GDB were written in an OO language, this method
3458 would instead return an object that knew how to perform the
3459 register return-value extract and store._
3461 _Maintainer note: This method does not take a GCC_P parameter, and
3462 such a parameter should not be added. If an architecture that
3463 requires per-compiler or per-function information be identified,
3464 then the replacement of RETTYPE with `struct value' FUNCTION
3467 _Maintainer note: The REGCACHE parameter limits this methods to
3468 the inner most frame. While replacing REGCACHE with a `struct
3469 frame_info' FRAME parameter would remove that limitation there has
3470 yet to be a demonstrated need for such a change._
3472 `SKIP_PERMANENT_BREAKPOINT'
3473 Advance the inferior's PC past a permanent breakpoint. GDB
3474 normally steps over a breakpoint by removing it, stepping one
3475 instruction, and re-inserting the breakpoint. However, permanent
3476 breakpoints are hardwired into the inferior, and can't be removed,
3477 so this strategy doesn't work. Calling
3478 `SKIP_PERMANENT_BREAKPOINT' adjusts the processor's state so that
3479 execution will resume just after the breakpoint. This macro does
3480 the right thing even when the breakpoint is in the delay slot of a
3483 `SKIP_PROLOGUE (PC)'
3484 A C expression that returns the address of the "real" code beyond
3485 the function entry prologue found at PC.
3487 `SKIP_TRAMPOLINE_CODE (PC)'
3488 If the target machine has trampoline code that sits between
3489 callers and the functions being called, then define this macro to
3490 return a new PC that is at the start of the real function.
3493 If the stack-pointer is kept in a register, then define this macro
3494 to be the number (greater than or equal to zero) of that register,
3495 or -1 if there is no such register.
3497 `STAB_REG_TO_REGNUM'
3498 Define this to convert stab register numbers (as gotten from `r'
3499 declarations) into GDB regnums. If not defined, no conversion
3502 `DEPRECATED_STACK_ALIGN (ADDR)'
3503 Define this to increase ADDR so that it meets the alignment
3504 requirements for the processor's stack.
3506 Unlike *Note frame_align::, this function always adjusts ADDR
3509 By default, no stack alignment is performed.
3511 `STEP_SKIPS_DELAY (ADDR)'
3512 Define this to return true if the address is of an instruction
3513 with a delay slot. If a breakpoint has been placed in the
3514 instruction's delay slot, GDB will single-step over that
3515 instruction before resuming normally. Currently only defined for
3518 `STORE_RETURN_VALUE (TYPE, REGCACHE, VALBUF)'
3519 A C expression that writes the function return value, found in
3520 VALBUF, into the REGCACHE. TYPE is the type of the value that is
3523 This method has been deprecated in favour of `gdbarch_return_value'
3524 (*note gdbarch_return_value::).
3526 `SYMBOL_RELOADING_DEFAULT'
3527 The default value of the "symbol-reloading" variable. (Never
3528 defined in current sources.)
3531 Number of bits in a char; defaults to 8.
3533 `TARGET_CHAR_SIGNED'
3534 Non-zero if `char' is normally signed on this architecture; zero if
3535 it should be unsigned.
3537 The ISO C standard requires the compiler to treat `char' as
3538 equivalent to either `signed char' or `unsigned char'; any
3539 character in the standard execution set is supposed to be positive.
3540 Most compilers treat `char' as signed, but `char' is unsigned on
3541 the IBM S/390, RS6000, and PowerPC targets.
3543 `TARGET_COMPLEX_BIT'
3544 Number of bits in a complex number; defaults to `2 *
3547 At present this macro is not used.
3550 Number of bits in a double float; defaults to `8 *
3553 `TARGET_DOUBLE_COMPLEX_BIT'
3554 Number of bits in a double complex; defaults to `2 *
3557 At present this macro is not used.
3560 Number of bits in a float; defaults to `4 * TARGET_CHAR_BIT'.
3563 Number of bits in an integer; defaults to `4 * TARGET_CHAR_BIT'.
3566 Number of bits in a long integer; defaults to `4 *
3569 `TARGET_LONG_DOUBLE_BIT'
3570 Number of bits in a long double float; defaults to `2 *
3573 `TARGET_LONG_LONG_BIT'
3574 Number of bits in a long long integer; defaults to `2 *
3578 Number of bits in a pointer; defaults to `TARGET_INT_BIT'.
3581 Number of bits in a short integer; defaults to `2 *
3585 `TARGET_WRITE_PC (VAL, PID)'
3588 These change the behavior of `read_pc', `write_pc', and `read_sp'.
3589 For most targets, these may be left undefined. GDB will call the
3590 read and write register functions with the relevant `_REGNUM'
3593 These macros are useful when a target keeps one of these registers
3594 in a hard to get at place; for example, part in a segment register
3595 and part in an ordinary register.
3597 *Note unwind_sp::, which replaces `TARGET_READ_SP'.
3599 `TARGET_VIRTUAL_FRAME_POINTER(PC, REGP, OFFSETP)'
3600 Returns a `(register, offset)' pair representing the virtual frame
3601 pointer in use at the code address PC. If virtual frame pointers
3602 are not used, a default definition simply returns
3603 `DEPRECATED_FP_REGNUM', with an offset of zero.
3605 `TARGET_HAS_HARDWARE_WATCHPOINTS'
3606 If non-zero, the target has support for hardware-assisted
3607 watchpoints. *Note watchpoints: Algorithms, for more details and
3608 other related macros.
3610 `TARGET_PRINT_INSN (ADDR, INFO)'
3611 This is the function used by GDB to print an assembly instruction.
3612 It prints the instruction at address ADDR in debugged memory and
3613 returns the length of the instruction, in bytes. If a target
3614 doesn't define its own printing routine, it defaults to an
3615 accessor function for the global pointer
3616 `deprecated_tm_print_insn'. This usually points to a function in
3617 the `opcodes' library (*note Opcodes: Support Libraries.). INFO
3618 is a structure (of type `disassemble_info') defined in
3619 `include/dis-asm.h' used to pass information to the instruction
3622 `struct frame_id unwind_dummy_id (struct frame_info *FRAME)'
3623 Given FRAME return a `struct frame_id' that uniquely identifies an
3624 inferior function call's dummy frame. The value returned must
3625 match the dummy frame stack value previously saved using
3626 `SAVE_DUMMY_FRAME_TOS'. *Note SAVE_DUMMY_FRAME_TOS::.
3628 `DEPRECATED_USE_STRUCT_CONVENTION (GCC_P, TYPE)'
3629 If defined, this must be an expression that is nonzero if a value
3630 of the given TYPE being returned from a function must have space
3631 allocated for it on the stack. GCC_P is true if the function
3632 being considered is known to have been compiled by GCC; this is
3633 helpful for systems where GCC is known to use different calling
3634 convention than other compilers.
3636 This method has been deprecated in favour of `gdbarch_return_value'
3637 (*note gdbarch_return_value::).
3639 `VALUE_TO_REGISTER(TYPE, REGNUM, FROM, TO)'
3640 Convert a value of type TYPE into the raw contents of register
3641 REGNUM's. *Note Using Different Register and Memory Data
3642 Representations: Target Architecture Definition.
3644 `VARIABLES_INSIDE_BLOCK (DESC, GCC_P)'
3645 For dbx-style debugging information, if the compiler puts variable
3646 declarations inside LBRAC/RBRAC blocks, this should be defined to
3647 be nonzero. DESC is the value of `n_desc' from the `N_RBRAC'
3648 symbol, and GCC_P is true if GDB has noticed the presence of
3649 either the `GCC_COMPILED_SYMBOL' or the `GCC2_COMPILED_SYMBOL'.
3650 By default, this is 0.
3652 `OS9K_VARIABLES_INSIDE_BLOCK (DESC, GCC_P)'
3653 Similarly, for OS/9000. Defaults to 1.
3655 Motorola M68K target conditionals.
3658 Define this to be the 4-bit location of the breakpoint trap
3659 vector. If not defined, it will default to `0xf'.
3665 A string containing the name of the function to call in order to
3666 allocate some memory in the inferior. The default value is
3670 9.11 Adding a New Target
3671 ========================
3673 The following files add a target to GDB:
3675 `gdb/config/ARCH/TTT.mt'
3676 Contains a Makefile fragment specific to this target. Specifies
3677 what object files are needed for target TTT, by defining
3678 `TDEPFILES=...' and `TDEPLIBS=...'. Also specifies the header
3679 file which describes TTT, by defining `TM_FILE= tm-TTT.h'.
3681 You can also define `TM_CFLAGS', `TM_CLIBS', `TM_CDEPS', but these
3682 are now deprecated, replaced by autoconf, and may go away in
3683 future versions of GDB.
3686 Contains any miscellaneous code required for this target machine.
3687 On some machines it doesn't exist at all. Sometimes the macros in
3688 `tm-TTT.h' become very complicated, so they are implemented as
3689 functions here instead, and the macro is simply defined to call the
3690 function. This is vastly preferable, since it is easier to
3691 understand and debug.
3695 This often exists to describe the basic layout of the target
3696 machine's processor chip (registers, stack, etc.). If used, it is
3697 included by `TTT-tdep.h'. It can be shared among many targets
3698 that use the same processor.
3700 `gdb/config/ARCH/tm-TTT.h'
3701 (`tm.h' is a link to this file, created by `configure'). Contains
3702 macro definitions about the target machine's registers, stack frame
3703 format and instructions.
3705 New targets do not need this file and should not create it.
3707 `gdb/config/ARCH/tm-ARCH.h'
3708 This often exists to describe the basic layout of the target
3709 machine's processor chip (registers, stack, etc.). If used, it is
3710 included by `tm-TTT.h'. It can be shared among many targets that
3711 use the same processor.
3713 New targets do not need this file and should not create it.
3716 If you are adding a new operating system for an existing CPU chip,
3717 add a `config/tm-OS.h' file that describes the operating system
3718 facilities that are unusual (extra symbol table info; the breakpoint
3719 instruction needed; etc.). Then write a `ARCH/tm-OS.h' that just
3720 `#include's `tm-ARCH.h' and `config/tm-OS.h'.
3722 9.12 Converting an existing Target Architecture to Multi-arch
3723 =============================================================
3725 This section describes the current accepted best practice for converting
3726 an existing target architecture to the multi-arch framework.
3728 The process consists of generating, testing, posting and committing a
3729 sequence of patches. Each patch must contain a single change, for
3732 * Directly convert a group of functions into macros (the conversion
3733 does not change the behavior of any of the functions).
3735 * Replace a non-multi-arch with a multi-arch mechanism (e.g.,
3738 * Enable multi-arch level one.
3740 * Delete one or more files.
3743 There isn't a size limit on a patch, however, a developer is strongly
3744 encouraged to keep the patch size down.
3746 Since each patch is well defined, and since each change has been
3747 tested and shows no regressions, the patches are considered _fairly_
3748 obvious. Such patches, when submitted by developers listed in the
3749 `MAINTAINERS' file, do not need approval. Occasional steps in the
3750 process may be more complicated and less clear. The developer is
3751 expected to use their judgment and is encouraged to seek advice as
3757 The first step is to establish control. Build (with `-Werror' enabled)
3758 and test the target so that there is a baseline against which the
3759 debugger can be compared.
3761 At no stage can the test results regress or GDB stop compiling with
3764 9.12.2 Add the multi-arch initialization code
3765 ---------------------------------------------
3767 The objective of this step is to establish the basic multi-arch
3768 framework. It involves
3770 * The addition of a `ARCH_gdbarch_init' function(2) that creates the
3772 static struct gdbarch *
3773 d10v_gdbarch_init (info, arches)
3774 struct gdbarch_info info;
3775 struct gdbarch_list *arches;
3777 struct gdbarch *gdbarch;
3778 /* there is only one d10v architecture */
3780 return arches->gdbarch;
3781 gdbarch = gdbarch_alloc (&info, NULL);
3786 * A per-architecture dump function to print any architecture specific
3789 mips_dump_tdep (struct gdbarch *current_gdbarch,
3790 struct ui_file *file)
3792 ... code to print architecture specific info ...
3795 * A change to `_initialize_ARCH_tdep' to register this new
3798 _initialize_mips_tdep (void)
3800 gdbarch_register (bfd_arch_mips, mips_gdbarch_init,
3803 * Add the macro `GDB_MULTI_ARCH', defined as 0 (zero), to the file
3804 `config/ARCH/tm-ARCH.h'.
3807 9.12.3 Update multi-arch incompatible mechanisms
3808 ------------------------------------------------
3810 Some mechanisms do not work with multi-arch. They include:
3812 `FRAME_FIND_SAVED_REGS'
3813 Replaced with `DEPRECATED_FRAME_INIT_SAVED_REGS'
3815 At this stage you could also consider converting the macros into
3818 9.12.4 Prepare for multi-arch level to one
3819 ------------------------------------------
3821 Temporally set `GDB_MULTI_ARCH' to `GDB_MULTI_ARCH_PARTIAL' and then
3822 build and start GDB (the change should not be committed). GDB may not
3823 build, and once built, it may die with an internal error listing the
3824 architecture methods that must be provided.
3826 Fix any build problems (patch(es)).
3828 Convert all the architecture methods listed, which are only macros,
3829 into functions (patch(es)).
3831 Update `ARCH_gdbarch_init' to set all the missing architecture
3832 methods and wrap the corresponding macros in `#if !GDB_MULTI_ARCH'
3835 9.12.5 Set multi-arch level one
3836 -------------------------------
3838 Change the value of `GDB_MULTI_ARCH' to GDB_MULTI_ARCH_PARTIAL (a
3841 Any problems with throwing "the switch" should have been fixed
3844 9.12.6 Convert remaining macros
3845 -------------------------------
3847 Suggest converting macros into functions (and setting the corresponding
3848 architecture method) in small batches.
3850 9.12.7 Set multi-arch level to two
3851 ----------------------------------
3853 This should go smoothly.
3855 9.12.8 Delete the TM file
3856 -------------------------
3858 The `tm-ARCH.h' can be deleted. `ARCH.mt' and `configure.in' updated.
3860 ---------- Footnotes ----------
3862 (1) Some D10V instructions are actually pairs of 16-bit
3863 sub-instructions. However, since you can't jump into the middle of
3864 such a pair, code addresses can only refer to full 32 bit instructions,
3865 which is what matters in this explanation.
3867 (2) The above is from the original example and uses K&R C. GDB has
3868 since converted to ISO C but lets ignore that.
3871 File: gdbint.info, Node: Target Vector Definition, Next: Native Debugging, Prev: Target Architecture Definition, Up: Top
3873 10 Target Vector Definition
3874 ***************************
3876 The target vector defines the interface between GDB's abstract handling
3877 of target systems, and the nitty-gritty code that actually exercises
3878 control over a process or a serial port. GDB includes some 30-40
3879 different target vectors; however, each configuration of GDB includes
3885 Both executables and core files have target vectors.
3887 10.2 Standard Protocol and Remote Stubs
3888 =======================================
3890 GDB's file `remote.c' talks a serial protocol to code that runs in the
3891 target system. GDB provides several sample "stubs" that can be
3892 integrated into target programs or operating systems for this purpose;
3893 they are named `*-stub.c'.
3895 The GDB user's manual describes how to put such a stub into your
3896 target code. What follows is a discussion of integrating the SPARC
3897 stub into a complicated operating system (rather than a simple
3898 program), by Stu Grossman, the author of this stub.
3900 The trap handling code in the stub assumes the following upon entry
3903 1. %l1 and %l2 contain pc and npc respectively at the time of the
3906 2. traps are disabled;
3908 3. you are in the correct trap window.
3910 As long as your trap handler can guarantee those conditions, then
3911 there is no reason why you shouldn't be able to "share" traps with the
3912 stub. The stub has no requirement that it be jumped to directly from
3913 the hardware trap vector. That is why it calls `exceptionHandler()',
3914 which is provided by the external environment. For instance, this could
3915 set up the hardware traps to actually execute code which calls the stub
3916 first, and then transfers to its own trap handler.
3918 For the most point, there probably won't be much of an issue with
3919 "sharing" traps, as the traps we use are usually not used by the kernel,
3920 and often indicate unrecoverable error conditions. Anyway, this is all
3921 controlled by a table, and is trivial to modify. The most important
3922 trap for us is for `ta 1'. Without that, we can't single step or do
3923 breakpoints. Everything else is unnecessary for the proper operation
3924 of the debugger/stub.
3926 From reading the stub, it's probably not obvious how breakpoints
3927 work. They are simply done by deposit/examine operations from GDB.
3929 10.3 ROM Monitor Interface
3930 ==========================
3932 10.4 Custom Protocols
3933 =====================
3935 10.5 Transport Layer
3936 ====================
3938 10.6 Builtin Simulator
3939 ======================
3942 File: gdbint.info, Node: Native Debugging, Next: Support Libraries, Prev: Target Vector Definition, Up: Top
3947 Several files control GDB's configuration for native support:
3949 `gdb/config/ARCH/XYZ.mh'
3950 Specifies Makefile fragments needed by a _native_ configuration on
3951 machine XYZ. In particular, this lists the required
3952 native-dependent object files, by defining `NATDEPFILES=...'.
3953 Also specifies the header file which describes native support on
3954 XYZ, by defining `NAT_FILE= nm-XYZ.h'. You can also define
3955 `NAT_CFLAGS', `NAT_ADD_FILES', `NAT_CLIBS', `NAT_CDEPS', etc.; see
3958 _Maintainer's note: The `.mh' suffix is because this file
3959 originally contained `Makefile' fragments for hosting GDB on
3960 machine XYZ. While the file is no longer used for this purpose,
3961 the `.mh' suffix remains. Perhaps someone will eventually rename
3962 these fragments so that they have a `.mn' suffix._
3964 `gdb/config/ARCH/nm-XYZ.h'
3965 (`nm.h' is a link to this file, created by `configure'). Contains
3966 C macro definitions describing the native system environment, such
3967 as child process control and core file support.
3970 Contains any miscellaneous C code required for this native support
3971 of this machine. On some machines it doesn't exist at all.
3973 There are some "generic" versions of routines that can be used by
3974 various systems. These can be customized in various ways by macros
3975 defined in your `nm-XYZ.h' file. If these routines work for the XYZ
3976 host, you can just include the generic file's name (with `.o', not
3977 `.c') in `NATDEPFILES'.
3979 Otherwise, if your machine needs custom support routines, you will
3980 need to write routines that perform the same functions as the generic
3981 file. Put them into `XYZ-nat.c', and put `XYZ-nat.o' into
3985 This contains the _target_ops vector_ that supports Unix child
3986 processes on systems which use ptrace and wait to control the
3990 This contains the _target_ops vector_ that supports Unix child
3991 processes on systems which use /proc to control the child.
3994 This does the low-level grunge that uses Unix system calls to do a
3995 "fork and exec" to start up a child process.
3998 This is the low level interface to inferior processes for systems
3999 using the Unix `ptrace' call in a vanilla way.
4001 11.1 Native core file Support
4002 =============================
4004 `core-aout.c::fetch_core_registers()'
4005 Support for reading registers out of a core file. This routine
4006 calls `register_addr()', see below. Now that BFD is used to read
4007 core files, virtually all machines should use `core-aout.c', and
4008 should just provide `fetch_core_registers' in `XYZ-nat.c' (or
4009 `REGISTER_U_ADDR' in `nm-XYZ.h').
4011 `core-aout.c::register_addr()'
4012 If your `nm-XYZ.h' file defines the macro `REGISTER_U_ADDR(addr,
4013 blockend, regno)', it should be defined to set `addr' to the
4014 offset within the `user' struct of GDB register number `regno'.
4015 `blockend' is the offset within the "upage" of `u.u_ar0'. If
4016 `REGISTER_U_ADDR' is defined, `core-aout.c' will define the
4017 `register_addr()' function and use the macro in it. If you do not
4018 define `REGISTER_U_ADDR', but you are using the standard
4019 `fetch_core_registers()', you will need to define your own version
4020 of `register_addr()', put it into your `XYZ-nat.c' file, and be
4021 sure `XYZ-nat.o' is in the `NATDEPFILES' list. If you have your
4022 own `fetch_core_registers()', you may not need a separate
4023 `register_addr()'. Many custom `fetch_core_registers()'
4024 implementations simply locate the registers themselves.
4026 When making GDB run native on a new operating system, to make it
4027 possible to debug core files, you will need to either write specific
4028 code for parsing your OS's core files, or customize `bfd/trad-core.c'.
4029 First, use whatever `#include' files your machine uses to define the
4030 struct of registers that is accessible (possibly in the u-area) in a
4031 core file (rather than `machine/reg.h'), and an include file that
4032 defines whatever header exists on a core file (e.g., the u-area or a
4033 `struct core'). Then modify `trad_unix_core_file_p' to use these
4034 values to set up the section information for the data segment, stack
4035 segment, any other segments in the core file (perhaps shared library
4036 contents or control information), "registers" segment, and if there are
4037 two discontiguous sets of registers (e.g., integer and float), the
4038 "reg2" segment. This section information basically delimits areas in
4039 the core file in a standard way, which the section-reading routines in
4040 BFD know how to seek around in.
4042 Then back in GDB, you need a matching routine called
4043 `fetch_core_registers'. If you can use the generic one, it's in
4044 `core-aout.c'; if not, it's in your `XYZ-nat.c' file. It will be
4045 passed a char pointer to the entire "registers" segment, its length,
4046 and a zero; or a char pointer to the entire "regs2" segment, its
4047 length, and a 2. The routine should suck out the supplied register
4048 values and install them into GDB's "registers" array.
4050 If your system uses `/proc' to control processes, and uses ELF
4051 format core files, then you may be able to use the same routines for
4052 reading the registers out of processes and out of core files.
4063 11.5 shared libraries
4064 =====================
4066 11.6 Native Conditionals
4067 ========================
4069 When GDB is configured and compiled, various macros are defined or left
4070 undefined, to control compilation when the host and target systems are
4071 the same. These macros should be defined (or left undefined) in
4074 `CHILD_PREPARE_TO_STORE'
4075 If the machine stores all registers at once in the child process,
4076 then define this to ensure that all values are correct. This
4077 usually entails a read from the child.
4079 [Note that this is incorrectly defined in `xm-SYSTEM.h' files
4082 `FETCH_INFERIOR_REGISTERS'
4083 Define this if the native-dependent code will provide its own
4084 routines `fetch_inferior_registers' and `store_inferior_registers'
4085 in `HOST-nat.c'. If this symbol is _not_ defined, and
4086 `infptrace.c' is included in this configuration, the default
4087 routines in `infptrace.c' are used for these functions.
4090 This macro is normally defined to be the number of the first
4091 floating point register, if the machine has such registers. As
4092 such, it would appear only in target-specific code. However,
4093 `/proc' support uses this to decide whether floats are in use on
4096 `GET_LONGJMP_TARGET'
4097 For most machines, this is a target-dependent parameter. On the
4098 DECstation and the Iris, this is a native-dependent parameter,
4099 since `setjmp.h' is needed to define it.
4101 This macro determines the target PC address that `longjmp' will
4102 jump to, assuming that we have just stopped at a longjmp
4103 breakpoint. It takes a `CORE_ADDR *' as argument, and stores the
4104 target PC value through this pointer. It examines the current
4105 state of the machine as needed.
4107 `I386_USE_GENERIC_WATCHPOINTS'
4108 An x86-based machine can define this to use the generic x86
4109 watchpoint support; see *Note I386_USE_GENERIC_WATCHPOINTS:
4113 Define this to the address of the `u' structure (the "user
4114 struct", also known as the "u-page") in kernel virtual memory.
4115 GDB needs to know this so that it can subtract this address from
4116 absolute addresses in the upage, that are obtained via ptrace or
4117 from core files. On systems that don't need this value, set it to
4120 `KERNEL_U_ADDR_HPUX'
4121 Define this to cause GDB to determine the address of `u' at
4122 runtime, by using HP-style `nlist' on the kernel's image in the
4125 `ONE_PROCESS_WRITETEXT'
4126 Define this to be able to, when a breakpoint insertion fails, warn
4127 the user that another process may be running with the same
4131 Defines the format for the name of a `/proc' device. Should be
4132 defined in `nm.h' _only_ in order to override the default
4133 definition in `procfs.c'.
4136 The type of the third argument to the `ptrace' system call, if it
4137 exists and is different from `int'.
4140 Defines the offset of the registers in the "u area".
4142 `SHELL_COMMAND_CONCAT'
4143 If defined, is a string to prefix on the shell command used to
4147 If defined, this is the name of the shell to use to run the
4148 inferior. Defaults to `"/bin/sh"'.
4150 `SOLIB_ADD (FILENAME, FROM_TTY, TARG, READSYMS)'
4151 Define this to expand into an expression that will cause the
4152 symbols in FILENAME to be added to GDB's symbol table. If READSYMS
4153 is zero symbols are not read but any necessary low level
4154 processing for FILENAME is still done.
4156 `SOLIB_CREATE_INFERIOR_HOOK'
4157 Define this to expand into any shared-library-relocation code that
4158 you want to be run just after the child process has been forked.
4160 `START_INFERIOR_TRAPS_EXPECTED'
4161 When starting an inferior, GDB normally expects to trap twice;
4162 once when the shell execs, and once when the program itself execs.
4163 If the actual number of traps is something other than 2, then
4164 define this macro to expand into the number expected.
4167 This determines whether small routines in `*-tdep.c', which
4168 translate register values between GDB's internal representation
4169 and the `/proc' representation, are compiled.
4172 This is the offset of the registers in the upage. It need only be
4173 defined if the generic ptrace register access routines in
4174 `infptrace.c' are being used (that is, `infptrace.c' is configured
4175 in, and `FETCH_INFERIOR_REGISTERS' is not defined). If the
4176 default value from `infptrace.c' is good enough, leave it
4179 The default value means that u.u_ar0 _points to_ the location of
4180 the registers. I'm guessing that `#define U_REGS_OFFSET 0' means
4181 that `u.u_ar0' _is_ the location of the registers.
4187 Define this to debug `ptrace' calls.
4190 File: gdbint.info, Node: Support Libraries, Next: Coding, Prev: Native Debugging, Up: Top
4192 12 Support Libraries
4193 ********************
4198 BFD provides support for GDB in several ways:
4200 _identifying executable and core files_
4201 BFD will identify a variety of file types, including a.out, coff,
4202 and several variants thereof, as well as several kinds of core
4205 _access to sections of files_
4206 BFD parses the file headers to determine the names, virtual
4207 addresses, sizes, and file locations of all the various named
4208 sections in files (such as the text section or the data section).
4209 GDB simply calls BFD to read or write section X at byte offset Y
4212 _specialized core file support_
4213 BFD provides routines to determine the failing command name stored
4214 in a core file, the signal with which the program failed, and
4215 whether a core file matches (i.e. could be a core dump of) a
4216 particular executable file.
4218 _locating the symbol information_
4219 GDB uses an internal interface of BFD to determine where to find
4220 the symbol information in an executable file or symbol-file. GDB
4221 itself handles the reading of symbols, since BFD does not
4222 "understand" debug symbols, but GDB uses BFD's cached information
4223 to find the symbols, string table, etc.
4228 The opcodes library provides GDB's disassembler. (It's a separate
4229 library because it's also used in binutils, for `objdump').
4240 The `libiberty' library provides a set of functions and features that
4241 integrate and improve on functionality found in modern operating
4242 systems. Broadly speaking, such features can be divided into three
4243 groups: supplemental functions (functions that may be missing in some
4244 environments and operating systems), replacement functions (providing a
4245 uniform and easier to use interface for commonly used standard
4246 functions), and extensions (which provide additional functionality
4247 beyond standard functions).
4249 GDB uses various features provided by the `libiberty' library, for
4250 instance the C++ demangler, the IEEE floating format support functions,
4251 the input options parser `getopt', the `obstack' extension, and other
4254 12.5.1 `obstacks' in GDB
4255 ------------------------
4257 The obstack mechanism provides a convenient way to allocate and free
4258 chunks of memory. Each obstack is a pool of memory that is managed
4259 like a stack. Objects (of any nature, size and alignment) are
4260 allocated and freed in a LIFO fashion on an obstack (see `libiberty''s
4261 documenatation for a more detailed explanation of `obstacks').
4263 The most noticeable use of the `obstacks' in GDB is in object files.
4264 There is an obstack associated with each internal representation of an
4265 object file. Lots of things get allocated on these `obstacks':
4266 dictionary entries, blocks, blockvectors, symbols, minimal symbols,
4267 types, vectors of fundamental types, class fields of types, object
4268 files section lists, object files section offets lists, line tables,
4269 symbol tables, partial symbol tables, string tables, symbol table
4270 private data, macros tables, debug information sections and entries,
4271 import and export lists (som), unwind information (hppa), dwarf2
4272 location expressions data. Plus various strings such as directory
4273 names strings, debug format strings, names of types.
4275 An essential and convenient property of all data on `obstacks' is
4276 that memory for it gets allocated (with `obstack_alloc') at various
4277 times during a debugging sesssion, but it is released all at once using
4278 the `obstack_free' function. The `obstack_free' function takes a
4279 pointer to where in the stack it must start the deletion from (much
4280 like the cleanup chains have a pointer to where to start the cleanups).
4281 Because of the stack like structure of the `obstacks', this allows to
4282 free only a top portion of the obstack. There are a few instances in
4283 GDB where such thing happens. Calls to `obstack_free' are done after
4284 some local data is allocated to the obstack. Only the local data is
4285 deleted from the obstack. Of course this assumes that nothing between
4286 the `obstack_alloc' and the `obstack_free' allocates anything else on
4287 the same obstack. For this reason it is best and safest to use
4288 temporary `obstacks'.
4290 Releasing the whole obstack is also not safe per se. It is safe only
4291 under the condition that we know the `obstacks' memory is no longer
4292 needed. In GDB we get rid of the `obstacks' only when we get rid of
4293 the whole objfile(s), for instance upon reading a new symbol file.
4320 File: gdbint.info, Node: Coding, Next: Porting GDB, Prev: Support Libraries, Up: Top
4325 This chapter covers topics that are lower-level than the major
4331 Cleanups are a structured way to deal with things that need to be done
4334 When your code does something (e.g., `xmalloc' some memory, or
4335 `open' a file) that needs to be undone later (e.g., `xfree' the memory
4336 or `close' the file), it can make a cleanup. The cleanup will be done
4337 at some future point: when the command is finished and control returns
4338 to the top level; when an error occurs and the stack is unwound; or
4339 when your code decides it's time to explicitly perform cleanups.
4340 Alternatively you can elect to discard the cleanups you created.
4344 `struct cleanup *OLD_CHAIN;'
4345 Declare a variable which will hold a cleanup chain handle.
4347 `OLD_CHAIN = make_cleanup (FUNCTION, ARG);'
4348 Make a cleanup which will cause FUNCTION to be called with ARG (a
4349 `char *') later. The result, OLD_CHAIN, is a handle that can
4350 later be passed to `do_cleanups' or `discard_cleanups'. Unless
4351 you are going to call `do_cleanups' or `discard_cleanups', you can
4352 ignore the result from `make_cleanup'.
4354 `do_cleanups (OLD_CHAIN);'
4355 Do all cleanups added to the chain since the corresponding
4356 `make_cleanup' call was made.
4358 `discard_cleanups (OLD_CHAIN);'
4359 Same as `do_cleanups' except that it just removes the cleanups from
4360 the chain and does not call the specified functions.
4362 Cleanups are implemented as a chain. The handle returned by
4363 `make_cleanups' includes the cleanup passed to the call and any later
4364 cleanups appended to the chain (but not yet discarded or performed).
4367 make_cleanup (a, 0);
4369 struct cleanup *old = make_cleanup (b, 0);
4375 will call `c()' and `b()' but will not call `a()'. The cleanup that
4376 calls `a()' will remain in the cleanup chain, and will be done later
4377 unless otherwise discarded.
4379 Your function should explicitly do or discard the cleanups it
4380 creates. Failing to do this leads to non-deterministic behavior since
4381 the caller will arbitrarily do or discard your functions cleanups.
4382 This need leads to two common cleanup styles.
4384 The first style is try/finally. Before it exits, your code-block
4385 calls `do_cleanups' with the old cleanup chain and thus ensures that
4386 your code-block's cleanups are always performed. For instance, the
4387 following code-segment avoids a memory leak problem (even when `error'
4388 is called and a forced stack unwind occurs) by ensuring that the
4389 `xfree' will always be called:
4391 struct cleanup *old = make_cleanup (null_cleanup, 0);
4392 data = xmalloc (sizeof blah);
4393 make_cleanup (xfree, data);
4397 The second style is try/except. Before it exits, your code-block
4398 calls `discard_cleanups' with the old cleanup chain and thus ensures
4399 that any created cleanups are not performed. For instance, the
4400 following code segment, ensures that the file will be closed but only
4401 if there is an error:
4403 FILE *file = fopen ("afile", "r");
4404 struct cleanup *old = make_cleanup (close_file, file);
4406 discard_cleanups (old);
4409 Some functions, e.g., `fputs_filtered()' or `error()', specify that
4410 they "should not be called when cleanups are not in place". This means
4411 that any actions you need to reverse in the case of an error or
4412 interruption must be on the cleanup chain before you call these
4413 functions, since they might never return to your code (they `longjmp'
4416 13.2 Per-architecture module data
4417 =================================
4419 The multi-arch framework includes a mechanism for adding module
4420 specific per-architecture data-pointers to the `struct gdbarch'
4421 architecture object.
4423 A module registers one or more per-architecture data-pointers using:
4425 -- Function: struct gdbarch_data *gdbarch_data_register_pre_init
4426 (gdbarch_data_pre_init_ftype *PRE_INIT)
4427 PRE_INIT is used to, on-demand, allocate an initial value for a
4428 per-architecture data-pointer using the architecture's obstack
4429 (passed in as a parameter). Since PRE_INIT can be called during
4430 architecture creation, it is not parameterized with the
4431 architecture. and must not call modules that use per-architecture
4434 -- Function: struct gdbarch_data *gdbarch_data_register_post_init
4435 (gdbarch_data_post_init_ftype *POST_INIT)
4436 POST_INIT is used to obtain an initial value for a
4437 per-architecture data-pointer _after_. Since POST_INIT is always
4438 called after architecture creation, it both receives the fully
4439 initialized architecture and is free to call modules that use
4440 per-architecture data (care needs to be taken to ensure that those
4441 other modules do not try to call back to this module as that will
4442 create in cycles in the initialization call graph).
4444 These functions return a `struct gdbarch_data' that is used to
4445 identify the per-architecture data-pointer added for that module.
4447 The per-architecture data-pointer is accessed using the function:
4449 -- Function: void *gdbarch_data (struct gdbarch *GDBARCH, struct
4450 gdbarch_data *DATA_HANDLE)
4451 Given the architecture ARCH and module data handle DATA_HANDLE
4452 (returned by `gdbarch_data_register_pre_init' or
4453 `gdbarch_data_register_post_init'), this function returns the
4454 current value of the per-architecture data-pointer. If the data
4455 pointer is `NULL', it is first initialized by calling the
4456 corresponding PRE_INIT or POST_INIT method.
4458 The examples below assume the following definitions:
4460 struct nozel { int total; };
4461 static struct gdbarch_data *nozel_handle;
4463 A module can extend the architecture vector, adding additional
4464 per-architecture data, using the PRE_INIT method. The module's
4465 per-architecture data is then initialized during architecture creation.
4467 In the below, the module's per-architecture _nozel_ is added. An
4468 architecture can specify its nozel by calling `set_gdbarch_nozel' from
4472 nozel_pre_init (struct obstack *obstack)
4474 struct nozel *data = OBSTACK_ZALLOC (obstack, struct nozel);
4479 set_gdbarch_nozel (struct gdbarch *gdbarch, int total)
4481 struct nozel *data = gdbarch_data (gdbarch, nozel_handle);
4482 data->total = nozel;
4485 A module can on-demand create architecture dependant data structures
4488 In the below, the nozel's total is computed on-demand by
4489 `nozel_post_init' using information obtained from the architecture.
4492 nozel_post_init (struct gdbarch *gdbarch)
4494 struct nozel *data = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct nozel);
4495 nozel->total = gdbarch... (gdbarch);
4500 nozel_total (struct gdbarch *gdbarch)
4502 struct nozel *data = gdbarch_data (gdbarch, nozel_handle);
4506 13.3 Wrapping Output Lines
4507 ==========================
4509 Output that goes through `printf_filtered' or `fputs_filtered' or
4510 `fputs_demangled' needs only to have calls to `wrap_here' added in
4511 places that would be good breaking points. The utility routines will
4512 take care of actually wrapping if the line width is exceeded.
4514 The argument to `wrap_here' is an indentation string which is
4515 printed _only_ if the line breaks there. This argument is saved away
4516 and used later. It must remain valid until the next call to
4517 `wrap_here' or until a newline has been printed through the
4518 `*_filtered' functions. Don't pass in a local variable and then return!
4520 It is usually best to call `wrap_here' after printing a comma or
4521 space. If you call it before printing a space, make sure that your
4522 indentation properly accounts for the leading space that will print if
4523 the line wraps there.
4525 Any function or set of functions that produce filtered output must
4526 finish by printing a newline, to flush the wrap buffer, before switching
4527 to unfiltered (`printf') output. Symbol reading routines that print
4528 warnings are a good example.
4530 13.4 GDB Coding Standards
4531 =========================
4533 GDB follows the GNU coding standards, as described in
4534 `etc/standards.texi'. This file is also available for anonymous FTP
4535 from GNU archive sites. GDB takes a strict interpretation of the
4536 standard; in general, when the GNU standard recommends a practice but
4537 does not require it, GDB requires it.
4539 GDB follows an additional set of coding standards specific to GDB,
4540 as described in the following sections.
4545 GDB assumes an ISO/IEC 9899:1990 (a.k.a. ISO C90) compliant compiler.
4547 GDB does not assume an ISO C or POSIX compliant C library.
4549 13.4.2 Memory Management
4550 ------------------------
4552 GDB does not use the functions `malloc', `realloc', `calloc', `free'
4555 GDB uses the functions `xmalloc', `xrealloc' and `xcalloc' when
4556 allocating memory. Unlike `malloc' et.al. these functions do not
4557 return when the memory pool is empty. Instead, they unwind the stack
4558 using cleanups. These functions return `NULL' when requested to
4559 allocate a chunk of memory of size zero.
4561 _Pragmatics: By using these functions, the need to check every
4562 memory allocation is removed. These functions provide portable
4565 GDB does not use the function `free'.
4567 GDB uses the function `xfree' to return memory to the memory pool.
4568 Consistent with ISO-C, this function ignores a request to free a `NULL'
4571 _Pragmatics: On some systems `free' fails when passed a `NULL'
4574 GDB can use the non-portable function `alloca' for the allocation of
4575 small temporary values (such as strings).
4577 _Pragmatics: This function is very non-portable. Some systems
4578 restrict the memory being allocated to no more than a few kilobytes._
4580 GDB uses the string function `xstrdup' and the print function
4583 _Pragmatics: `asprintf' and `strdup' can fail. Print functions such
4584 as `sprintf' are very prone to buffer overflow errors._
4586 13.4.3 Compiler Warnings
4587 ------------------------
4589 With few exceptions, developers should include the configuration option
4590 `--enable-gdb-build-warnings=,-Werror' when building GDB. The
4591 exceptions are listed in the file `gdb/MAINTAINERS'.
4593 This option causes GDB (when built using GCC) to be compiled with a
4594 carefully selected list of compiler warning flags. Any warnings from
4595 those flags being treated as errors.
4597 The current list of warning flags includes:
4600 Since GDB coding standard requires all functions to be declared
4601 using a prototype, the flag has the side effect of ensuring that
4602 prototyped functions are always visible with out resorting to
4603 `-Wstrict-prototypes'.
4606 Such code often appears to work except on instruction set
4607 architectures that use register windows.
4614 `-Wformat-nonliteral'
4615 Since GDB uses the `format printf' attribute on all `printf' like
4616 functions these check not just `printf' calls but also calls to
4617 functions such as `fprintf_unfiltered'.
4620 This warning includes uses of the assignment operator within an
4628 This warning has the additional benefit of detecting the absence
4629 of the `case' reserved word in a switch statement:
4630 enum { FD_SCHEDULED, NOTHING_SCHEDULED } sched;
4645 In version 4.0, GCC began warning about pointer argument passing or
4646 assignment even when the source and destination differed only in
4647 signedness. However, most GDB code doesn't distinguish carefully
4648 between `char' and `unsigned char'. In early 2006 the GDB
4649 developers decided correcting these warnings wasn't worth the time
4653 _Pragmatics: Due to the way that GDB is implemented most functions
4654 have unused parameters. Consequently the warning `-Wunused-parameter'
4655 is precluded from the list. The macro `ATTRIBUTE_UNUSED' is not used
4656 as it leads to false negatives -- it is not an error to have
4657 `ATTRIBUTE_UNUSED' on a parameter that is being used. The options
4658 `-Wall' and `-Wunused' are also precluded because they both include
4659 `-Wunused-parameter'._
4661 _Pragmatics: GDB has not simply accepted the warnings enabled by
4662 `-Wall -Werror -W...'. Instead it is selecting warnings when and where
4663 their benefits can be demonstrated._
4668 The standard GNU recommendations for formatting must be followed
4671 A function declaration should not have its name in column zero. A
4672 function definition should have its name in column zero.
4675 static void foo (void);
4682 _Pragmatics: This simplifies scripting. Function definitions can be
4683 found using `^function-name'._
4685 There must be a space between a function or macro name and the
4686 opening parenthesis of its argument list (except for macro definitions,
4687 as required by C). There must not be a space after an open
4688 paren/bracket or before a close paren/bracket.
4690 While additional whitespace is generally helpful for reading, do not
4691 use more than one blank line to separate blocks, and avoid adding
4692 whitespace after the end of a program line (as of 1/99, some 600 lines
4693 had whitespace after the semicolon). Excess whitespace causes
4694 difficulties for `diff' and `patch' utilities.
4696 Pointers are declared using the traditional K&R C style:
4708 The standard GNU requirements on comments must be followed strictly.
4710 Block comments must appear in the following form, with no `/*'- or
4711 `*/'-only lines, and no leading `*':
4713 /* Wait for control to return from inferior to debugger. If inferior
4714 gets a signal, we may decide to start it up again instead of
4715 returning. That is why there is a loop in this function. When
4716 this function actually returns it means the inferior should be left
4717 stopped and GDB should read more commands. */
4719 (Note that this format is encouraged by Emacs; tabbing for a
4720 multi-line comment works correctly, and `M-q' fills the block
4723 Put a blank line between the block comments preceding function or
4724 variable definitions, and the definition itself.
4726 In general, put function-body comments on lines by themselves, rather
4727 than trying to fit them into the 20 characters left at the end of a
4728 line, since either the comment or the code will inevitably get longer
4729 than will fit, and then somebody will have to move it anyhow.
4734 Code must not depend on the sizes of C data types, the format of the
4735 host's floating point numbers, the alignment of anything, or the order
4736 of evaluation of expressions.
4738 Use functions freely. There are only a handful of compute-bound
4739 areas in GDB that might be affected by the overhead of a function call,
4740 mainly in symbol reading. Most of GDB's performance is limited by the
4741 target interface (whether serial line or system call).
4743 However, use functions with moderation. A thousand one-line
4744 functions are just as hard to understand as a single thousand-line
4747 _Macros are bad, M'kay._ (But if you have to use a macro, make sure
4748 that the macro arguments are protected with parentheses.)
4750 Declarations like `struct foo *' should be used in preference to
4751 declarations like `typedef struct foo { ... } *foo_ptr'.
4753 13.4.7 Function Prototypes
4754 --------------------------
4756 Prototypes must be used when both _declaring_ and _defining_ a
4757 function. Prototypes for GDB functions must include both the argument
4758 type and name, with the name matching that used in the actual function
4761 All external functions should have a declaration in a header file
4762 that callers include, except for `_initialize_*' functions, which must
4763 be external so that `init.c' construction works, but shouldn't be
4764 visible to random source files.
4766 Where a source file needs a forward declaration of a static function,
4767 that declaration must appear in a block near the top of the source file.
4769 13.4.8 Internal Error Recovery
4770 ------------------------------
4772 During its execution, GDB can encounter two types of errors. User
4773 errors and internal errors. User errors include not only a user
4774 entering an incorrect command but also problems arising from corrupt
4775 object files and system errors when interacting with the target.
4776 Internal errors include situations where GDB has detected, at run time,
4777 a corrupt or erroneous situation.
4779 When reporting an internal error, GDB uses `internal_error' and
4782 GDB must not call `abort' or `assert'.
4784 _Pragmatics: There is no `internal_warning' function. Either the
4785 code detected a user error, recovered from it and issued a `warning' or
4786 the code failed to correctly recover from the user error and issued an
4792 Any file used when building the core of GDB must be in lower case. Any
4793 file used when building the core of GDB must be 8.3 unique. These
4794 requirements apply to both source and generated files.
4796 _Pragmatics: The core of GDB must be buildable on many platforms
4797 including DJGPP and MacOS/HFS. Every time an unfriendly file is
4798 introduced to the build process both `Makefile.in' and `configure.in'
4799 need to be modified accordingly. Compare the convoluted conversion
4800 process needed to transform `COPYING' into `copying.c' with the
4801 conversion needed to transform `version.in' into `version.c'._
4803 Any file non 8.3 compliant file (that is not used when building the
4804 core of GDB) must be added to `gdb/config/djgpp/fnchange.lst'.
4806 _Pragmatics: This is clearly a compromise._
4808 When GDB has a local version of a system header file (ex `string.h')
4809 the file name based on the POSIX header prefixed with `gdb_'
4810 (`gdb_string.h'). These headers should be relatively independent: they
4811 should use only macros defined by `configure', the compiler, or the
4812 host; they should include only system headers; they should refer only
4813 to system types. They may be shared between multiple programs, e.g.
4816 For other files `-' is used as the separator.
4818 13.4.10 Include Files
4819 ---------------------
4821 A `.c' file should include `defs.h' first.
4823 A `.c' file should directly include the `.h' file of every
4824 declaration and/or definition it directly refers to. It cannot rely on
4827 A `.h' file should directly include the `.h' file of every
4828 declaration and/or definition it directly refers to. It cannot rely on
4829 indirect inclusion. Exception: The file `defs.h' does not need to be
4832 An external declaration should only appear in one include file.
4834 An external declaration should never appear in a `.c' file.
4835 Exception: a declaration for the `_initialize' function that pacifies
4836 `-Wmissing-declaration'.
4838 A `typedef' definition should only appear in one include file.
4840 An opaque `struct' declaration can appear in multiple `.h' files.
4841 Where possible, a `.h' file should use an opaque `struct' declaration
4842 instead of an include.
4844 All `.h' files should be wrapped in:
4846 #ifndef INCLUDE_FILE_NAME_H
4847 #define INCLUDE_FILE_NAME_H
4851 13.4.11 Clean Design and Portable Implementation
4852 ------------------------------------------------
4854 In addition to getting the syntax right, there's the little question of
4855 semantics. Some things are done in certain ways in GDB because long
4856 experience has shown that the more obvious ways caused various kinds of
4859 You can't assume the byte order of anything that comes from a target
4860 (including VALUEs, object files, and instructions). Such things must
4861 be byte-swapped using `SWAP_TARGET_AND_HOST' in GDB, or one of the swap
4862 routines defined in `bfd.h', such as `bfd_get_32'.
4864 You can't assume that you know what interface is being used to talk
4865 to the target system. All references to the target must go through the
4866 current `target_ops' vector.
4868 You can't assume that the host and target machines are the same
4869 machine (except in the "native" support modules). In particular, you
4870 can't assume that the target machine's header files will be available
4871 on the host machine. Target code must bring along its own header files
4872 - written from scratch or explicitly donated by their owner, to avoid
4875 Insertion of new `#ifdef''s will be frowned upon. It's much better
4876 to write the code portably than to conditionalize it for various
4879 New `#ifdef''s which test for specific compilers or manufacturers or
4880 operating systems are unacceptable. All `#ifdef''s should test for
4881 features. The information about which configurations contain which
4882 features should be segregated into the configuration files. Experience
4883 has proven far too often that a feature unique to one particular system
4884 often creeps into other systems; and that a conditional based on some
4885 predefined macro for your current system will become worthless over
4886 time, as new versions of your system come out that behave differently
4887 with regard to this feature.
4889 Adding code that handles specific architectures, operating systems,
4890 target interfaces, or hosts, is not acceptable in generic code.
4892 One particularly notorious area where system dependencies tend to
4893 creep in is handling of file names. The mainline GDB code assumes
4894 Posix semantics of file names: absolute file names begin with a forward
4895 slash `/', slashes are used to separate leading directories,
4896 case-sensitive file names. These assumptions are not necessarily true
4897 on non-Posix systems such as MS-Windows. To avoid system-dependent
4898 code where you need to take apart or construct a file name, use the
4899 following portable macros:
4901 `HAVE_DOS_BASED_FILE_SYSTEM'
4902 This preprocessing symbol is defined to a non-zero value on hosts
4903 whose filesystems belong to the MS-DOS/MS-Windows family. Use this
4904 symbol to write conditional code which should only be compiled for
4907 `IS_DIR_SEPARATOR (C)'
4908 Evaluates to a non-zero value if C is a directory separator
4909 character. On Unix and GNU/Linux systems, only a slash `/' is
4910 such a character, but on Windows, both `/' and `\' will pass.
4912 `IS_ABSOLUTE_PATH (FILE)'
4913 Evaluates to a non-zero value if FILE is an absolute file name.
4914 For Unix and GNU/Linux hosts, a name which begins with a slash `/'
4915 is absolute. On DOS and Windows, `d:/foo' and `x:\bar' are also
4916 absolute file names.
4918 `FILENAME_CMP (F1, F2)'
4919 Calls a function which compares file names F1 and F2 as
4920 appropriate for the underlying host filesystem. For Posix systems,
4921 this simply calls `strcmp'; on case-insensitive filesystems it
4922 will call `strcasecmp' instead.
4925 Evaluates to a character which separates directories in
4926 `PATH'-style lists, typically held in environment variables. This
4927 character is `:' on Unix, `;' on DOS and Windows.
4930 This evaluates to a constant string you should use to produce an
4931 absolute filename from leading directories and the file's basename.
4932 `SLASH_STRING' is `"/"' on most systems, but might be `"\\"' for
4933 some Windows-based ports.
4935 In addition to using these macros, be sure to use portable library
4936 functions whenever possible. For example, to extract a directory or a
4937 basename part from a file name, use the `dirname' and `basename'
4938 library functions (available in `libiberty' for platforms which don't
4939 provide them), instead of searching for a slash with `strrchr'.
4941 Another way to generalize GDB along a particular interface is with an
4942 attribute struct. For example, GDB has been generalized to handle
4943 multiple kinds of remote interfaces--not by `#ifdef's everywhere, but
4944 by defining the `target_ops' structure and having a current target (as
4945 well as a stack of targets below it, for memory references). Whenever
4946 something needs to be done that depends on which remote interface we are
4947 using, a flag in the current target_ops structure is tested (e.g.,
4948 `target_has_stack'), or a function is called through a pointer in the
4949 current target_ops structure. In this way, when a new remote interface
4950 is added, only one module needs to be touched--the one that actually
4951 implements the new remote interface. Other examples of
4952 attribute-structs are BFD access to multiple kinds of object file
4953 formats, or GDB's access to multiple source languages.
4955 Please avoid duplicating code. For example, in GDB 3.x all the code
4956 interfacing between `ptrace' and the rest of GDB was duplicated in
4957 `*-dep.c', and so changing something was very painful. In GDB 4.x,
4958 these have all been consolidated into `infptrace.c'. `infptrace.c' can
4959 deal with variations between systems the same way any system-independent
4960 file would (hooks, `#if defined', etc.), and machines which are
4961 radically different don't need to use `infptrace.c' at all.
4963 All debugging code must be controllable using the `set debug MODULE'
4964 command. Do not use `printf' to print trace messages. Use
4965 `fprintf_unfiltered(gdb_stdlog, ...'. Do not use `#ifdef DEBUG'.
4968 File: gdbint.info, Node: Porting GDB, Next: Versions and Branches, Prev: Coding, Up: Top
4973 Most of the work in making GDB compile on a new machine is in
4974 specifying the configuration of the machine. This is done in a
4975 dizzying variety of header files and configuration scripts, which we
4976 hope to make more sensible soon. Let's say your new host is called an
4977 XYZ (e.g., `sun4'), and its full three-part configuration name is
4978 `ARCH-XVEND-XOS' (e.g., `sparc-sun-sunos4'). In particular:
4980 * In the top level directory, edit `config.sub' and add ARCH, XVEND,
4981 and XOS to the lists of supported architectures, vendors, and
4982 operating systems near the bottom of the file. Also, add XYZ as
4983 an alias that maps to `ARCH-XVEND-XOS'. You can test your changes
4990 ./config.sub `ARCH-XVEND-XOS'
4992 which should both respond with `ARCH-XVEND-XOS' and no error
4995 You need to port BFD, if that hasn't been done already. Porting
4996 BFD is beyond the scope of this manual.
4998 * To configure GDB itself, edit `gdb/configure.host' to recognize
4999 your system and set `gdb_host' to XYZ, and (unless your desired
5000 target is already available) also edit `gdb/configure.tgt',
5001 setting `gdb_target' to something appropriate (for instance, XYZ).
5003 _Maintainer's note: Work in progress. The file
5004 `gdb/configure.host' originally needed to be modified when either a
5005 new native target or a new host machine was being added to GDB.
5006 Recent changes have removed this requirement. The file now only
5007 needs to be modified when adding a new native configuration. This
5008 will likely changed again in the future._
5010 * Finally, you'll need to specify and define GDB's host-, native-,
5011 and target-dependent `.h' and `.c' files used for your
5015 File: gdbint.info, Node: Versions and Branches, Next: Start of New Year Procedure, Prev: Porting GDB, Up: Top
5017 15 Versions and Branches
5018 ************************
5023 GDB's version is determined by the file `gdb/version.in' and takes one
5024 of the following forms:
5027 MAJOR.MINOR.PATCHLEVEL
5028 an official release (e.g., 6.2 or 6.2.1)
5030 MAJOR.MINOR.PATCHLEVEL.YYYYMMDD
5031 a snapshot taken at YYYY-MM-DD-gmt (e.g., 6.1.50.20020302,
5032 6.1.90.20020304, or 6.1.0.20020308)
5034 MAJOR.MINOR.PATCHLEVEL.YYYYMMDD-cvs
5035 a CVS check out drawn on YYYY-MM-DD (e.g., 6.1.50.20020302-cvs,
5036 6.1.90.20020304-cvs, or 6.1.0.20020308-cvs)
5038 MAJOR.MINOR.PATCHLEVEL.YYYYMMDD (VENDOR)
5039 a vendor specific release of GDB, that while based on
5040 MAJOR.MINOR.PATCHLEVEL.YYYYMMDD, may include additional changes
5042 GDB's mainline uses the MAJOR and MINOR version numbers from the
5043 most recent release branch, with a PATCHLEVEL of 50. At the time each
5044 new release branch is created, the mainline's MAJOR and MINOR version
5045 numbers are updated.
5047 GDB's release branch is similar. When the branch is cut, the
5048 PATCHLEVEL is changed from 50 to 90. As draft releases are drawn from
5049 the branch, the PATCHLEVEL is incremented. Once the first release
5050 (MAJOR.MINOR) has been made, the PATCHLEVEL is set to 0 and updates
5051 have an incremented PATCHLEVEL.
5053 For snapshots, and CVS check outs, it is also possible to identify
5056 MAJOR.MINOR.50.YYYYMMDD
5057 drawn from the HEAD of mainline CVS (e.g., 6.1.50.20020302)
5059 MAJOR.MINOR.90.YYYYMMDD
5060 MAJOR.MINOR.91.YYYYMMDD ...
5061 drawn from a release branch prior to the release (e.g.,
5064 MAJOR.MINOR.0.YYYYMMDD
5065 MAJOR.MINOR.1.YYYYMMDD ...
5066 drawn from a release branch after the release (e.g.,
5069 If the previous GDB version is 6.1 and the current version is 6.2,
5070 then, substituting 6 for MAJOR and 1 or 2 for MINOR, here's an
5071 illustration of a typical sequence:
5077 +--------------------------.
5080 6.2.50.20020303-cvs 6.1.90 (draft #1)
5082 6.2.50.20020304-cvs 6.1.90.20020304-cvs
5084 6.2.50.20020305-cvs 6.1.91 (draft #2)
5086 6.2.50.20020306-cvs 6.1.91.20020306-cvs
5088 6.2.50.20020307-cvs 6.2 (release)
5090 6.2.50.20020308-cvs 6.2.0.20020308-cvs
5092 6.2.50.20020309-cvs 6.2.1 (update)
5094 6.2.50.20020310-cvs <branch closed>
5098 +--------------------------.
5101 6.3.50.20020312-cvs 6.2.90 (draft #1)
5104 15.2 Release Branches
5105 =====================
5107 GDB draws a release series (6.2, 6.2.1, ...) from a single release
5108 branch, and identifies that branch using the CVS branch tags:
5110 gdb_MAJOR_MINOR-YYYYMMDD-branchpoint
5111 gdb_MAJOR_MINOR-branch
5112 gdb_MAJOR_MINOR-YYYYMMDD-release
5114 _Pragmatics: To help identify the date at which a branch or release
5115 is made, both the branchpoint and release tags include the date that
5116 they are cut (YYYYMMDD) in the tag. The branch tag, denoting the head
5117 of the branch, does not need this._
5119 15.3 Vendor Branches
5120 ====================
5122 To avoid version conflicts, vendors are expected to modify the file
5123 `gdb/version.in' to include a vendor unique alphabetic identifier (an
5124 official GDB release never uses alphabetic characters in its version
5125 identifer). E.g., `6.2widgit2', or `6.2 (Widgit Inc Patch 2)'.
5127 15.4 Experimental Branches
5128 ==========================
5133 GDB permits the creation of branches, cut from the CVS repository, for
5134 experimental development. Branches make it possible for developers to
5135 share preliminary work, and maintainers to examine significant new
5138 The following are a set of guidelines for creating such branches:
5140 _a branch has an owner_
5141 The owner can set further policy for a branch, but may not change
5142 the ground rules. In particular, they can set a policy for
5143 commits (be it adding more reviewers or deciding who can commit).
5145 _all commits are posted_
5146 All changes committed to a branch shall also be posted to the GDB
5147 patches mailing list <gdb-patches@sources.redhat.com>. While
5148 commentary on such changes are encouraged, people should remember
5149 that the changes only apply to a branch.
5151 _all commits are covered by an assignment_
5152 This ensures that all changes belong to the Free Software
5153 Foundation, and avoids the possibility that the branch may become
5156 _a branch is focused_
5157 A focused branch has a single objective or goal, and does not
5158 contain unnecessary or irrelevant changes. Cleanups, where
5159 identified, being be pushed into the mainline as soon as possible.
5161 _a branch tracks mainline_
5162 This keeps the level of divergence under control. It also keeps
5163 the pressure on developers to push cleanups and other stuff into
5166 _a branch shall contain the entire GDB module_
5167 The GDB module `gdb' should be specified when creating a branch
5168 (branches of individual files should be avoided). *Note Tags::.
5170 _a branch shall be branded using `version.in'_
5171 The file `gdb/version.in' shall be modified so that it identifies
5172 the branch OWNER and branch NAME, e.g.,
5173 `6.2.50.20030303_owner_name' or `6.2 (Owner Name)'.
5179 To simplify the identification of GDB branches, the following branch
5180 tagging convention is strongly recommended:
5182 `OWNER_NAME-YYYYMMDD-branchpoint'
5183 `OWNER_NAME-YYYYMMDD-branch'
5184 The branch point and corresponding branch tag. YYYYMMDD is the
5185 date that the branch was created. A branch is created using the
5187 cvs rtag OWNER_NAME-YYYYMMDD-branchpoint gdb
5188 cvs rtag -b -r OWNER_NAME-YYYYMMDD-branchpoint \
5189 OWNER_NAME-YYYYMMDD-branch gdb
5191 `OWNER_NAME-YYYYMMDD-mergepoint'
5192 The tagged point, on the mainline, that was used when merging the
5193 branch on YYYYMMDD. To merge in all changes since the branch was
5194 cut, use a command sequence like:
5195 cvs rtag OWNER_NAME-YYYYMMDD-mergepoint gdb
5197 -jOWNER_NAME-YYYYMMDD-branchpoint
5198 -jOWNER_NAME-YYYYMMDD-mergepoint
5199 Similar sequences can be used to just merge in changes since the
5203 For further information on CVS, see Concurrent Versions System
5204 (http://www.gnu.org/software/cvs/).
5207 File: gdbint.info, Node: Start of New Year Procedure, Next: Releasing GDB, Prev: Versions and Branches, Up: Top
5209 16 Start of New Year Procedure
5210 ******************************
5212 At the start of each new year, the following actions should be
5215 * Rotate the ChangeLog file
5217 The current `ChangeLog' file should be renamed into
5218 `ChangeLog-YYYY' where YYYY is the year that has just passed. A
5219 new `ChangeLog' file should be created, and its contents should
5220 contain a reference to the previous ChangeLog. The following
5221 should also be preserved at the end of the new ChangeLog, in order
5222 to provide the appropriate settings when editing this file with
5228 version-control: never
5231 * Update the copyright year in the startup message
5233 Update the copyright year in file `top.c', function
5234 `print_gdb_version'.
5237 File: gdbint.info, Node: Releasing GDB, Next: Testsuite, Prev: Start of New Year Procedure, Up: Top
5242 17.1 Branch Commit Policy
5243 =========================
5245 The branch commit policy is pretty slack. GDB releases 5.0, 5.1 and
5246 5.2 all used the below:
5248 * The `gdb/MAINTAINERS' file still holds.
5250 * Don't fix something on the branch unless/until it is also fixed in
5251 the trunk. If this isn't possible, mentioning it in the
5252 `gdb/PROBLEMS' file is better than committing a hack.
5254 * When considering a patch for the branch, suggested criteria
5255 include: Does it fix a build? Does it fix the sequence `break
5256 main; run' when debugging a static binary?
5258 * The further a change is from the core of GDB, the less likely the
5259 change will worry anyone (e.g., target specific code).
5261 * Only post a proposal to change the core of GDB after you've sent
5262 individual bribes to all the people listed in the `MAINTAINERS'
5265 _Pragmatics: Provided updates are restricted to non-core
5266 functionality there is little chance that a broken change will be fatal.
5267 This means that changes such as adding a new architectures or (within
5268 reason) support for a new host are considered acceptable._
5270 17.2 Obsoleting code
5271 ====================
5273 Before anything else, poke the other developers (and around the source
5274 code) to see if there is anything that can be removed from GDB (an old
5275 target, an unused file).
5277 Obsolete code is identified by adding an `OBSOLETE' prefix to every
5278 line. Doing this means that it is easy to identify something that has
5279 been obsoleted when greping through the sources.
5281 The process is done in stages -- this is mainly to ensure that the
5282 wider GDB community has a reasonable opportunity to respond. Remember,
5283 everything on the Internet takes a week.
5285 1. Post the proposal on the GDB mailing list <gdb@sources.redhat.com>
5286 Creating a bug report to track the task's state, is also highly
5289 2. Wait a week or so.
5291 3. Post the proposal on the GDB Announcement mailing list
5292 <gdb-announce@sources.redhat.com>.
5294 4. Wait a week or so.
5296 5. Go through and edit all relevant files and lines so that they are
5297 prefixed with the word `OBSOLETE'.
5299 6. Wait until the next GDB version, containing this obsolete code,
5302 7. Remove the obsolete code.
5304 _Maintainer note: While removing old code is regrettable it is
5305 hopefully better for GDB's long term development. Firstly it helps the
5306 developers by removing code that is either no longer relevant or simply
5307 wrong. Secondly since it removes any history associated with the file
5308 (effectively clearing the slate) the developer has a much freer hand
5309 when it comes to fixing broken files._
5311 17.3 Before the Branch
5312 ======================
5314 The most important objective at this stage is to find and fix simple
5315 changes that become a pain to track once the branch is created. For
5316 instance, configuration problems that stop GDB from even building. If
5317 you can't get the problem fixed, document it in the `gdb/PROBLEMS' file.
5319 Prompt for `gdb/NEWS'
5320 ---------------------
5322 People always forget. Send a post reminding them but also if you know
5323 something interesting happened add it yourself. The `schedule' script
5324 will mention this in its e-mail.
5329 Grab one of the nightly snapshots and then walk through the
5330 `gdb/README' looking for anything that can be improved. The `schedule'
5331 script will mention this in its e-mail.
5333 Refresh any imported files.
5334 ---------------------------
5336 A number of files are taken from external repositories. They include:
5338 * `texinfo/texinfo.tex'
5340 * `config.guess' et. al. (see the top-level `MAINTAINERS' file)
5342 * `etc/standards.texi', `etc/make-stds.texi'
5347 A.R.I. is an `awk' script (Awk Regression Index ;-) that checks for a
5348 number of errors and coding conventions. The checks include things
5349 like using `malloc' instead of `xmalloc' and file naming problems.
5350 There shouldn't be any regressions.
5352 17.3.1 Review the bug data base
5353 -------------------------------
5355 Close anything obviously fixed.
5357 17.3.2 Check all cross targets build
5358 ------------------------------------
5360 The targets are listed in `gdb/MAINTAINERS'.
5370 $ V=`echo $v | sed 's/\./_/g'`
5371 $ D=`date -u +%Y-%m-%d`
5374 $ echo cvs -f -d :ext:sources.redhat.com:/cvs/src rtag \
5375 -D $D-gmt gdb_$V-$D-branchpoint insight+dejagnu
5376 cvs -f -d :ext:sources.redhat.com:/cvs/src rtag
5377 -D 2002-03-03-gmt gdb_5_2-2002-03-03-branchpoint insight+dejagnu
5380 $ echo cvs -f -d :ext:sources.redhat.com:/cvs/src rtag \
5381 -b -r gdb_$V-$D-branchpoint gdb_$V-branch insight+dejagnu
5382 cvs -f -d :ext:sources.redhat.com:/cvs/src rtag \
5383 -b -r gdb_5_2-2002-03-03-branchpoint gdb_5_2-branch insight+dejagnu
5388 * by using `-D YYYY-MM-DD-gmt' the branch is forced to an exact
5391 * the trunk is first taged so that the branch point can easily be
5394 * Insight (which includes GDB) and dejagnu are all tagged at the
5397 * `version.in' gets bumped to avoid version number conflicts
5399 * the reading of `.cvsrc' is disabled using `-f'
5406 $ V=`echo $v | sed 's/\./_/g'`
5410 $ echo cvs -f -d :ext:sources.redhat.com:/cvs/src co \
5411 -r gdb_$V-branch src/gdb/version.in
5412 cvs -f -d :ext:sources.redhat.com:/cvs/src co
5413 -r gdb_5_2-branch src/gdb/version.in
5415 U src/gdb/version.in
5417 $ echo $u.90-0000-00-00-cvs > version.in
5419 5.1.90-0000-00-00-cvs
5420 $ cvs -f commit version.in
5422 * `0000-00-00' is used as a date to pump prime the version.in update
5425 * `.90' and the previous branch version are used as fairly arbitrary
5426 initial branch version number
5428 Update the web and news pages
5429 -----------------------------
5433 Tweak cron to track the new branch
5434 ----------------------------------
5436 The file `gdbadmin/cron/crontab' contains gdbadmin's cron table. This
5437 file needs to be updated so that:
5439 * a daily timestamp is added to the file `version.in'
5441 * the new branch is included in the snapshot process
5443 See the file `gdbadmin/cron/README' for how to install the updated cron
5446 The file `gdbadmin/ss/README' should also be reviewed to reflect any
5447 changes. That file is copied to both the branch/ and current/ snapshot
5450 Update the NEWS and README files
5451 --------------------------------
5453 The `NEWS' file needs to be updated so that on the branch it refers to
5454 _changes in the current release_ while on the trunk it also refers to
5455 _changes since the current release_.
5457 The `README' file needs to be updated so that it refers to the
5460 Post the branch info
5461 --------------------
5463 Send an announcement to the mailing lists:
5465 * GDB Announcement mailing list <gdb-announce@sources.redhat.com>
5467 * GDB Discsussion mailing list <gdb@sources.redhat.com> and GDB
5468 Discsussion mailing list <gdb-testers@sources.redhat.com>
5470 _Pragmatics: The branch creation is sent to the announce list to
5471 ensure that people people not subscribed to the higher volume discussion
5474 The announcement should include:
5478 * how to check out the branch using CVS
5480 * the date/number of weeks until the release
5482 * the branch commit policy still holds.
5484 17.5 Stabilize the branch
5485 =========================
5487 Something goes here.
5489 17.6 Create a Release
5490 =====================
5492 The process of creating and then making available a release is broken
5493 down into a number of stages. The first part addresses the technical
5494 process of creating a releasable tar ball. The later stages address the
5495 process of releasing that tar ball.
5497 When making a release candidate just the first section is needed.
5499 17.6.1 Create a release candidate
5500 ---------------------------------
5502 The objective at this stage is to create a set of tar balls that can be
5503 made available as a formal release (or as a less formal release
5509 Send out an e-mail notifying everyone that the branch is frozen to
5510 <gdb-patches@sources.redhat.com>.
5512 Establish a few defaults.
5513 .........................
5517 $ t=/sourceware/snapshot-tmp/gdbadmin-tmp
5519 /sourceware/snapshot-tmp/gdbadmin-tmp/gdb_5_2-branch/5.2
5523 /sourceware/snapshot-tmp/gdbadmin-tmp/gdb_5_2-branch/5.2
5525 /home/gdbadmin/bin/autoconf
5530 * Check the `autoconf' version carefully. You want to be using the
5531 version taken from the `binutils' snapshot directory, which can be
5532 found at `ftp://sources.redhat.com/pub/binutils/'. It is very
5533 unlikely that a system installed version of `autoconf' (e.g.,
5534 `/usr/bin/autoconf') is correct.
5536 Check out the relevant modules:
5537 ...............................
5539 $ for m in gdb insight dejagnu
5541 ( mkdir -p $m && cd $m && cvs -q -f -d /cvs/src co -P -r $b $m )
5547 * The reading of `.cvsrc' is disabled (`-f') so that there isn't any
5548 confusion between what is written here and what your local `cvs'
5551 Update relevant files.
5552 ......................
5555 Major releases get their comments added as part of the mainline.
5556 Minor releases should probably mention any significant bugs that
5559 Don't forget to include the `ChangeLog' entry.
5561 $ emacs gdb/src/gdb/NEWS
5566 $ cp gdb/src/gdb/NEWS insight/src/gdb/NEWS
5567 $ cp gdb/src/gdb/ChangeLog insight/src/gdb/ChangeLog
5570 You'll need to update:
5578 $ emacs gdb/src/gdb/README
5583 $ cp gdb/src/gdb/README insight/src/gdb/README
5584 $ cp gdb/src/gdb/ChangeLog insight/src/gdb/ChangeLog
5586 _Maintainer note: Hopefully the `README' file was reviewed before
5587 the initial branch was cut so just a simple substitute is needed
5590 _Maintainer note: Other projects generate `README' and `INSTALL'
5591 from the core documentation. This might be worth pursuing._
5594 $ echo $v > gdb/src/gdb/version.in
5595 $ cat gdb/src/gdb/version.in
5597 $ emacs gdb/src/gdb/version.in
5600 ... Bump to version ...
5602 $ cp gdb/src/gdb/version.in insight/src/gdb/version.in
5603 $ cp gdb/src/gdb/ChangeLog insight/src/gdb/ChangeLog
5605 `dejagnu/src/dejagnu/configure.in'
5606 Dejagnu is more complicated. The version number is a parameter to
5607 `AM_INIT_AUTOMAKE'. Tweak it to read something like gdb-5.1.91.
5609 Don't forget to re-generate `configure'.
5611 Don't forget to include a `ChangeLog' entry.
5613 $ emacs dejagnu/src/dejagnu/configure.in
5618 $ ( cd dejagnu/src/dejagnu && autoconf )
5624 This is identical to the process used to create the daily snapshot.
5626 $ for m in gdb insight
5628 ( cd $m/src && gmake -f src-release $m.tar )
5630 $ ( m=dejagnu; cd $m/src && gmake -f src-release $m.tar.bz2 )
5632 If the top level source directory does not have `src-release' (GDB
5633 version 5.3.1 or earlier), try these commands instead:
5635 $ for m in gdb insight
5637 ( cd $m/src && gmake -f Makefile.in $m.tar )
5639 $ ( m=dejagnu; cd $m/src && gmake -f Makefile.in $m.tar.bz2 )
5641 Check the source files
5642 ......................
5644 You're looking for files that have mysteriously disappeared.
5645 `distclean' has the habit of deleting files it shouldn't. Watch out
5646 for the `version.in' update `cronjob'.
5648 $ ( cd gdb/src && cvs -f -q -n update )
5652 ... lots of generated files ...
5657 ... lots of generated files ...
5660 _Don't worry about the `gdb.info-??' or `gdb/p-exp.tab.c'. They were
5661 generated (and yes `gdb.info-1' was also generated only something
5662 strange with CVS means that they didn't get supressed). Fixing it
5663 would be nice though._
5665 Create compressed versions of the release
5666 .........................................
5671 dejagnu/ dejagnu-gdb-5.2.tar.bz2 gdb/ gdb-5.2.tar insight/ insight-5.2.tar
5672 $ for m in gdb insight
5674 bzip2 -v -9 -c $m-$v.tar > $m-$v.tar.bz2
5675 gzip -v -9 -c $m-$v.tar > $m-$v.tar.gz
5681 * A pipe such as `bunzip2 < xxx.bz2 | gzip -9 > xxx.gz' is not since,
5682 in that mode, `gzip' does not know the name of the file and, hence,
5683 can not include it in the compressed file. This is also why the
5684 release process runs `tar' and `bzip2' as separate passes.
5686 17.6.2 Sanity check the tar ball
5687 --------------------------------
5689 Pick a popular machine (Solaris/PPC?) and try the build on that.
5691 $ bunzip2 < gdb-5.2.tar.bz2 | tar xpf -
5696 $ ./gdb/gdb ./gdb/gdb
5700 Breakpoint 1 at 0x80732bc: file main.c, line 734.
5702 Starting program: /tmp/gdb-5.2/gdb/gdb
5704 Breakpoint 1, main (argc=1, argv=0xbffff8b4) at main.c:734
5705 734 catch_errors (captured_main, &args, "", RETURN_MASK_ALL);
5707 $1 = {argc = 136426532, argv = 0x821b7f0}
5710 17.6.3 Make a release candidate available
5711 -----------------------------------------
5713 If this is a release candidate then the only remaining steps are:
5715 1. Commit `version.in' and `ChangeLog'
5717 2. Tweak `version.in' (and `ChangeLog' to read L.M.N-0000-00-00-cvs
5718 so that the version update process can restart.
5720 3. Make the release candidate available in
5721 `ftp://sources.redhat.com/pub/gdb/snapshots/branch'
5723 4. Notify the relevant mailing lists ( <gdb@sources.redhat.com> and
5724 <gdb-testers@sources.redhat.com> that the candidate is available.
5726 17.6.4 Make a formal release available
5727 --------------------------------------
5729 (And you thought all that was required was to post an e-mail.)
5734 Copy the new files to both the release and the old release directory:
5736 $ cp *.bz2 *.gz ~ftp/pub/gdb/old-releases/
5737 $ cp *.bz2 *.gz ~ftp/pub/gdb/releases
5739 Clean up the releases directory so that only the most recent releases
5740 are available (e.g. keep 5.2 and 5.2.1 but remove 5.1):
5742 $ cd ~ftp/pub/gdb/releases
5745 Update the file `README' and `.message' in the releases directory:
5750 $ ln README .message
5752 Update the web pages.
5753 .....................
5755 `htdocs/download/ANNOUNCEMENT'
5756 This file, which is posted as the official announcement, includes:
5757 * General announcement
5759 * News. If making an M.N.1 release, retain the news from
5760 earlier M.N release.
5765 `htdocs/news/index.html'
5766 `htdocs/download/index.html'
5767 These files include:
5768 * announcement of the most recent release
5770 * news entry (remember to update both the top level and the
5772 These pages also need to be regenerate using `index.sh'.
5774 `download/onlinedocs/'
5775 You need to find the magic command that is used to generate the
5776 online docs from the `.tar.bz2'. The best way is to look in the
5777 output from one of the nightly `cron' jobs and then just edit
5778 accordingly. Something like:
5780 $ ~/ss/update-web-docs \
5781 ~ftp/pub/gdb/releases/gdb-5.2.tar.bz2 \
5783 /www/sourceware/htdocs/gdb/download/onlinedocs \
5787 Just like the online documentation. Something like:
5789 $ /bin/sh ~/ss/update-web-ari \
5790 ~ftp/pub/gdb/releases/gdb-5.2.tar.bz2 \
5792 /www/sourceware/htdocs/gdb/download/ari \
5796 Shadow the pages onto gnu
5797 .........................
5799 Something goes here.
5801 Install the GDB tar ball on GNU
5802 ...............................
5804 At the time of writing, the GNU machine was `gnudist.gnu.org' in
5807 Make the `ANNOUNCEMENT'
5808 .......................
5810 Post the `ANNOUNCEMENT' file you created above to:
5812 * GDB Announcement mailing list <gdb-announce@sources.redhat.com>
5814 * General GNU Announcement list <info-gnu@gnu.org> (but delay it a
5815 day or so to let things get out)
5817 * GDB Bug Report mailing list <bug-gdb@gnu.org>
5822 The release is out but you're still not finished.
5824 Commit outstanding changes
5825 ..........................
5827 In particular you'll need to commit any changes to:
5842 $ d=`date -u +%Y-%m-%d`
5845 $ ( cd insight/src/gdb && cvs -f -q update )
5846 $ ( cd insight/src && cvs -f -q tag gdb_5_2-$d-release )
5848 Insight is used since that contains more of the release than GDB
5849 (`dejagnu' doesn't get tagged but I think we can live with that).
5851 Mention the release on the trunk
5852 ................................
5854 Just put something in the `ChangeLog' so that the trunk also indicates
5855 when the release was made.
5857 Restart `gdb/version.in'
5858 ........................
5860 If `gdb/version.in' does not contain an ISO date such as `2002-01-24'
5861 then the daily `cronjob' won't update it. Having committed all the
5862 release changes it can be set to `5.2.0_0000-00-00-cvs' which will
5863 restart things (yes the `_' is important - it affects the snapshot
5866 Don't forget the `ChangeLog'.
5871 The files committed to the branch may also need changes merged into the
5874 Revise the release schedule
5875 ...........................
5877 Post a revised release schedule to GDB Discussion List
5878 <gdb@sources.redhat.com> with an updated announcement. The schedule
5879 can be generated by running:
5881 $ ~/ss/schedule `date +%s` schedule
5883 The first parameter is approximate date/time in seconds (from the epoch)
5884 of the most recent release.
5886 Also update the schedule `cronjob'.
5891 Remove any `OBSOLETE' code.
5894 File: gdbint.info, Node: Testsuite, Next: Hints, Prev: Releasing GDB, Up: Top
5899 The testsuite is an important component of the GDB package. While it
5900 is always worthwhile to encourage user testing, in practice this is
5901 rarely sufficient; users typically use only a small subset of the
5902 available commands, and it has proven all too common for a change to
5903 cause a significant regression that went unnoticed for some time.
5905 The GDB testsuite uses the DejaGNU testing framework. DejaGNU is
5906 built using `Tcl' and `expect'. The tests themselves are calls to
5907 various `Tcl' procs; the framework runs all the procs and summarizes
5908 the passes and fails.
5910 18.1 Using the Testsuite
5911 ========================
5913 To run the testsuite, simply go to the GDB object directory (or to the
5914 testsuite's objdir) and type `make check'. This just sets up some
5915 environment variables and invokes DejaGNU's `runtest' script. While
5916 the testsuite is running, you'll get mentions of which test file is in
5917 use, and a mention of any unexpected passes or fails. When the
5918 testsuite is finished, you'll get a summary that looks like this:
5922 # of expected passes 6016
5923 # of unexpected failures 58
5924 # of unexpected successes 5
5925 # of expected failures 183
5926 # of unresolved testcases 3
5927 # of untested testcases 5
5929 To run a specific test script, type:
5930 make check RUNTESTFLAGS='TESTS'
5931 where TESTS is a list of test script file names, separated by spaces.
5933 The ideal test run consists of expected passes only; however, reality
5934 conspires to keep us from this ideal. Unexpected failures indicate
5935 real problems, whether in GDB or in the testsuite. Expected failures
5936 are still failures, but ones which have been decided are too hard to
5937 deal with at the time; for instance, a test case might work everywhere
5938 except on AIX, and there is no prospect of the AIX case being fixed in
5939 the near future. Expected failures should not be added lightly, since
5940 you may be masking serious bugs in GDB. Unexpected successes are
5941 expected fails that are passing for some reason, while unresolved and
5942 untested cases often indicate some minor catastrophe, such as the
5943 compiler being unable to deal with a test program.
5945 When making any significant change to GDB, you should run the
5946 testsuite before and after the change, to confirm that there are no
5947 regressions. Note that truly complete testing would require that you
5948 run the testsuite with all supported configurations and a variety of
5949 compilers; however this is more than really necessary. In many cases
5950 testing with a single configuration is sufficient. Other useful
5951 options are to test one big-endian (Sparc) and one little-endian (x86)
5952 host, a cross config with a builtin simulator (powerpc-eabi, mips-elf),
5953 or a 64-bit host (Alpha).
5955 If you add new functionality to GDB, please consider adding tests
5956 for it as well; this way future GDB hackers can detect and fix their
5957 changes that break the functionality you added. Similarly, if you fix
5958 a bug that was not previously reported as a test failure, please add a
5959 test case for it. Some cases are extremely difficult to test, such as
5960 code that handles host OS failures or bugs in particular versions of
5961 compilers, and it's OK not to try to write tests for all of those.
5963 DejaGNU supports separate build, host, and target machines. However,
5964 some GDB test scripts do not work if the build machine and the host
5965 machine are not the same. In such an environment, these scripts will
5966 give a result of "UNRESOLVED", like this:
5968 UNRESOLVED: gdb.base/example.exp: This test script does not work on a remote host.
5970 18.2 Testsuite Organization
5971 ===========================
5973 The testsuite is entirely contained in `gdb/testsuite'. While the
5974 testsuite includes some makefiles and configury, these are very minimal,
5975 and used for little besides cleaning up, since the tests themselves
5976 handle the compilation of the programs that GDB will run. The file
5977 `testsuite/lib/gdb.exp' contains common utility procs useful for all
5978 GDB tests, while the directory `testsuite/config' contains
5979 configuration-specific files, typically used for special-purpose
5980 definitions of procs like `gdb_load' and `gdb_start'.
5982 The tests themselves are to be found in `testsuite/gdb.*' and
5983 subdirectories of those. The names of the test files must always end
5984 with `.exp'. DejaGNU collects the test files by wildcarding in the
5985 test directories, so both subdirectories and individual files get
5986 chosen and run in alphabetical order.
5988 The following table lists the main types of subdirectories and what
5989 they are for. Since DejaGNU finds test files no matter where they are
5990 located, and since each test file sets up its own compilation and
5991 execution environment, this organization is simply for convenience and
5995 This is the base testsuite. The tests in it should apply to all
5996 configurations of GDB (but generic native-only tests may live
5997 here). The test programs should be in the subset of C that is
5998 valid K&R, ANSI/ISO, and C++ (`#ifdef's are allowed if necessary,
5999 for instance for prototypes).
6002 Language-specific tests for any language LANG besides C. Examples
6003 are `gdb.cp' and `gdb.java'.
6006 Non-portable tests. The tests are specific to a specific
6007 configuration (host or target), such as HP-UX or eCos. Example is
6008 `gdb.hp', for HP-UX.
6011 Tests specific to a particular compiler. As of this writing (June
6012 1999), there aren't currently any groups of tests in this category
6013 that couldn't just as sensibly be made platform-specific, but one
6014 could imagine a `gdb.gcc', for tests of GDB's handling of GCC
6018 Tests that exercise a specific GDB subsystem in more depth. For
6019 instance, `gdb.disasm' exercises various disassemblers, while
6020 `gdb.stabs' tests pathways through the stabs symbol reader.
6025 In many areas, the GDB tests are already quite comprehensive; you
6026 should be able to copy existing tests to handle new cases.
6028 You should try to use `gdb_test' whenever possible, since it
6029 includes cases to handle all the unexpected errors that might happen.
6030 However, it doesn't cost anything to add new test procedures; for
6031 instance, `gdb.base/exprs.exp' defines a `test_expr' that calls
6032 `gdb_test' multiple times.
6034 Only use `send_gdb' and `gdb_expect' when absolutely necessary, such
6035 as when GDB has several valid responses to a command.
6037 The source language programs do _not_ need to be in a consistent
6038 style. Since GDB is used to debug programs written in many different
6039 styles, it's worth having a mix of styles in the testsuite; for
6040 instance, some GDB bugs involving the display of source lines would
6041 never manifest themselves if the programs used GNU coding style
6045 File: gdbint.info, Node: Hints, Next: GDB Observers, Prev: Testsuite, Up: Top
6050 Check the `README' file, it often has useful information that does not
6051 appear anywhere else in the directory.
6055 * Getting Started:: Getting started working on GDB
6056 * Debugging GDB:: Debugging GDB with itself
6059 File: gdbint.info, Node: Getting Started, Up: Hints
6061 19.1 Getting Started
6062 ====================
6064 GDB is a large and complicated program, and if you first starting to
6065 work on it, it can be hard to know where to start. Fortunately, if you
6066 know how to go about it, there are ways to figure out what is going on.
6068 This manual, the GDB Internals manual, has information which applies
6069 generally to many parts of GDB.
6071 Information about particular functions or data structures are
6072 located in comments with those functions or data structures. If you
6073 run across a function or a global variable which does not have a
6074 comment correctly explaining what is does, this can be thought of as a
6075 bug in GDB; feel free to submit a bug report, with a suggested comment
6076 if you can figure out what the comment should say. If you find a
6077 comment which is actually wrong, be especially sure to report that.
6079 Comments explaining the function of macros defined in host, target,
6080 or native dependent files can be in several places. Sometimes they are
6081 repeated every place the macro is defined. Sometimes they are where the
6082 macro is used. Sometimes there is a header file which supplies a
6083 default definition of the macro, and the comment is there. This manual
6084 also documents all the available macros.
6086 Start with the header files. Once you have some idea of how GDB's
6087 internal symbol tables are stored (see `symtab.h', `gdbtypes.h'), you
6088 will find it much easier to understand the code which uses and creates
6089 those symbol tables.
6091 You may wish to process the information you are getting somehow, to
6092 enhance your understanding of it. Summarize it, translate it to another
6093 language, add some (perhaps trivial or non-useful) feature to GDB, use
6094 the code to predict what a test case would do and write the test case
6095 and verify your prediction, etc. If you are reading code and your eyes
6096 are starting to glaze over, this is a sign you need to use a more active
6099 Once you have a part of GDB to start with, you can find more
6100 specifically the part you are looking for by stepping through each
6101 function with the `next' command. Do not use `step' or you will
6102 quickly get distracted; when the function you are stepping through
6103 calls another function try only to get a big-picture understanding
6104 (perhaps using the comment at the beginning of the function being
6105 called) of what it does. This way you can identify which of the
6106 functions being called by the function you are stepping through is the
6107 one which you are interested in. You may need to examine the data
6108 structures generated at each stage, with reference to the comments in
6109 the header files explaining what the data structures are supposed to
6112 Of course, this same technique can be used if you are just reading
6113 the code, rather than actually stepping through it. The same general
6114 principle applies--when the code you are looking at calls something
6115 else, just try to understand generally what the code being called does,
6116 rather than worrying about all its details.
6118 A good place to start when tracking down some particular area is with
6119 a command which invokes that feature. Suppose you want to know how
6120 single-stepping works. As a GDB user, you know that the `step' command
6121 invokes single-stepping. The command is invoked via command tables
6122 (see `command.h'); by convention the function which actually performs
6123 the command is formed by taking the name of the command and adding
6124 `_command', or in the case of an `info' subcommand, `_info'. For
6125 example, the `step' command invokes the `step_command' function and the
6126 `info display' command invokes `display_info'. When this convention is
6127 not followed, you might have to use `grep' or `M-x tags-search' in
6128 emacs, or run GDB on itself and set a breakpoint in `execute_command'.
6130 If all of the above fail, it may be appropriate to ask for
6131 information on `bug-gdb'. But _never_ post a generic question like "I
6132 was wondering if anyone could give me some tips about understanding
6133 GDB"--if we had some magic secret we would put it in this manual.
6134 Suggestions for improving the manual are always welcome, of course.
6137 File: gdbint.info, Node: Debugging GDB, Up: Hints
6139 19.2 Debugging GDB with itself
6140 ==============================
6142 If GDB is limping on your machine, this is the preferred way to get it
6143 fully functional. Be warned that in some ancient Unix systems, like
6144 Ultrix 4.2, a program can't be running in one process while it is being
6145 debugged in another. Rather than typing the command `./gdb ./gdb',
6146 which works on Suns and such, you can copy `gdb' to `gdb2' and then
6147 type `./gdb ./gdb2'.
6149 When you run GDB in the GDB source directory, it will read a
6150 `.gdbinit' file that sets up some simple things to make debugging gdb
6151 easier. The `info' command, when executed without a subcommand in a
6152 GDB being debugged by gdb, will pop you back up to the top level gdb.
6153 See `.gdbinit' for details.
6155 If you use emacs, you will probably want to do a `make TAGS' after
6156 you configure your distribution; this will put the machine dependent
6157 routines for your local machine where they will be accessed first by
6160 Also, make sure that you've either compiled GDB with your local cc,
6161 or have run `fixincludes' if you are compiling with gcc.
6163 19.3 Submitting Patches
6164 =======================
6166 Thanks for thinking of offering your changes back to the community of
6167 GDB users. In general we like to get well designed enhancements.
6168 Thanks also for checking in advance about the best way to transfer the
6171 The GDB maintainers will only install "cleanly designed" patches.
6172 This manual summarizes what we believe to be clean design for GDB.
6174 If the maintainers don't have time to put the patch in when it
6175 arrives, or if there is any question about a patch, it goes into a
6176 large queue with everyone else's patches and bug reports.
6178 The legal issue is that to incorporate substantial changes requires a
6179 copyright assignment from you and/or your employer, granting ownership
6180 of the changes to the Free Software Foundation. You can get the
6181 standard documents for doing this by sending mail to `gnu@gnu.org' and
6182 asking for it. We recommend that people write in "All programs owned
6183 by the Free Software Foundation" as "NAME OF PROGRAM", so that changes
6184 in many programs (not just GDB, but GAS, Emacs, GCC, etc) can be
6185 contributed with only one piece of legalese pushed through the
6186 bureaucracy and filed with the FSF. We can't start merging changes
6187 until this paperwork is received by the FSF (their rules, which we
6188 follow since we maintain it for them).
6190 Technically, the easiest way to receive changes is to receive each
6191 feature as a small context diff or unidiff, suitable for `patch'. Each
6192 message sent to me should include the changes to C code and header
6193 files for a single feature, plus `ChangeLog' entries for each directory
6194 where files were modified, and diffs for any changes needed to the
6195 manuals (`gdb/doc/gdb.texinfo' or `gdb/doc/gdbint.texinfo'). If there
6196 are a lot of changes for a single feature, they can be split down into
6199 In this way, if we read and like the feature, we can add it to the
6200 sources with a single patch command, do some testing, and check it in.
6201 If you leave out the `ChangeLog', we have to write one. If you leave
6202 out the doc, we have to puzzle out what needs documenting. Etc., etc.
6204 The reason to send each change in a separate message is that we will
6205 not install some of the changes. They'll be returned to you with
6206 questions or comments. If we're doing our job correctly, the message
6207 back to you will say what you have to fix in order to make the change
6208 acceptable. The reason to have separate messages for separate features
6209 is so that the acceptable changes can be installed while one or more
6210 changes are being reworked. If multiple features are sent in a single
6211 message, we tend to not put in the effort to sort out the acceptable
6212 changes from the unacceptable, so none of the features get installed
6213 until all are acceptable.
6215 If this sounds painful or authoritarian, well, it is. But we get a
6216 lot of bug reports and a lot of patches, and many of them don't get
6217 installed because we don't have the time to finish the job that the bug
6218 reporter or the contributor could have done. Patches that arrive
6219 complete, working, and well designed, tend to get installed on the day
6220 they arrive. The others go into a queue and get installed as time
6221 permits, which, since the maintainers have many demands to meet, may not
6222 be for quite some time.
6224 Please send patches directly to the GDB maintainers
6225 <gdb-patches@sources.redhat.com>.
6227 19.4 Obsolete Conditionals
6228 ==========================
6230 Fragments of old code in GDB sometimes reference or set the following
6231 configuration macros. They should not be used by new code, and old uses
6232 should be removed as those parts of the debugger are otherwise touched.
6235 This macro used to define where the end of the stack appeared, for
6236 use in interpreting core file formats that don't record this
6237 address in the core file itself. This information is now
6238 configured in BFD, and GDB gets the info portably from there. The
6239 values in GDB's configuration files should be moved into BFD
6240 configuration files (if needed there), and deleted from all of
6243 Any `FOO-xdep.c' file that references STACK_END_ADDR is so old
6244 that it has never been converted to use BFD. Now that's old!
6248 File: gdbint.info, Node: GDB Observers, Next: GNU Free Documentation License, Prev: Hints, Up: Top
6250 Appendix A GDB Currently available observers
6251 ********************************************
6253 A.1 Implementation rationale
6254 ============================
6256 An "observer" is an entity which is interested in being notified when
6257 GDB reaches certain states, or certain events occur in GDB. The entity
6258 being observed is called the "subject". To receive notifications, the
6259 observer attaches a callback to the subject. One subject can have
6262 `observer.c' implements an internal generic low-level event
6263 notification mechanism. This generic event notification mechanism is
6264 then re-used to implement the exported high-level notification
6265 management routines for all possible notifications.
6267 The current implementation of the generic observer provides support
6268 for contextual data. This contextual data is given to the subject when
6269 attaching the callback. In return, the subject will provide this
6270 contextual data back to the observer as a parameter of the callback.
6272 Note that the current support for the contextual data is only
6273 partial, as it lacks a mechanism that would deallocate this data when
6274 the callback is detached. This is not a problem so far, as this
6275 contextual data is only used internally to hold a function pointer.
6276 Later on, if a certain observer needs to provide support for user-level
6277 contextual data, then the generic notification mechanism will need to be
6278 enhanced to allow the observer to provide a routine to deallocate the
6279 data when attaching the callback.
6281 The observer implementation is also currently not reentrant. In
6282 particular, it is therefore not possible to call the attach or detach
6283 routines during a notification.
6288 Observer notifications can be traced using the command `set debug
6289 observer 1' (*note Optional messages about internal happenings:
6290 (gdb)Debugging Output.).
6292 A.3 `normal_stop' Notifications
6293 ===============================
6295 GDB notifies all `normal_stop' observers when the inferior execution
6296 has just stopped, the associated messages and annotations have been
6297 printed, and the control is about to be returned to the user.
6299 Note that the `normal_stop' notification is not emitted when the
6300 execution stops due to a breakpoint, and this breakpoint has a
6301 condition that is not met. If the breakpoint has any associated
6302 commands list, the commands are executed after the notification is
6305 The following interfaces are available to manage observers:
6307 -- Function: extern struct observer *observer_attach_EVENT
6308 (observer_EVENT_ftype *F)
6309 Using the function F, create an observer that is notified when
6310 ever EVENT occures, return the observer.
6312 -- Function: extern void observer_detach_EVENT (struct observer
6314 Remove OBSERVER from the list of observers to be notified when
6317 -- Function: extern void observer_notify_EVENT (void);
6318 Send a notification to all EVENT observers.
6320 The following observable events are defined:
6322 -- Function: void normal_stop (struct bpstats *BS)
6323 The inferior has stopped for real.
6325 -- Function: void target_changed (struct target_ops *TARGET)
6326 The target's register contents have changed.
6328 -- Function: void executable_changed (void *UNUSED_ARGS)
6329 The executable being debugged by GDB has changed: The user decided
6330 to debug a different program, or the program he was debugging has
6331 been modified since being loaded by the debugger (by being
6332 recompiled, for instance).
6334 -- Function: void inferior_created (struct target_ops *OBJFILE, int
6336 GDB has just connected to an inferior. For `run', GDB calls this
6337 observer while the inferior is still stopped at the entry-point
6338 instruction. For `attach' and `core', GDB calls this observer
6339 immediately after connecting to the inferior, and before any
6340 information on the inferior has been printed.
6342 -- Function: void solib_loaded (struct so_list *SOLIB)
6343 The shared library specified by SOLIB has been loaded. Note that
6344 when GDB calls this observer, the library's symbols probably
6345 haven't been loaded yet.
6347 -- Function: void solib_unloaded (struct so_list *SOLIB)
6348 The shared library specified by SOLIB has been unloaded.
6351 File: gdbint.info, Node: GNU Free Documentation License, Next: Index, Prev: GDB Observers, Up: Top
6353 Appendix B GNU Free Documentation License
6354 *****************************************
6356 Version 1.2, November 2002
6358 Copyright (C) 2000,2001,2002 Free Software Foundation, Inc.
6359 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
6361 Everyone is permitted to copy and distribute verbatim copies
6362 of this license document, but changing it is not allowed.
6366 The purpose of this License is to make a manual, textbook, or other
6367 functional and useful document "free" in the sense of freedom: to
6368 assure everyone the effective freedom to copy and redistribute it,
6369 with or without modifying it, either commercially or
6370 noncommercially. Secondarily, this License preserves for the
6371 author and publisher a way to get credit for their work, while not
6372 being considered responsible for modifications made by others.
6374 This License is a kind of "copyleft", which means that derivative
6375 works of the document must themselves be free in the same sense.
6376 It complements the GNU General Public License, which is a copyleft
6377 license designed for free software.
6379 We have designed this License in order to use it for manuals for
6380 free software, because free software needs free documentation: a
6381 free program should come with manuals providing the same freedoms
6382 that the software does. But this License is not limited to
6383 software manuals; it can be used for any textual work, regardless
6384 of subject matter or whether it is published as a printed book.
6385 We recommend this License principally for works whose purpose is
6386 instruction or reference.
6388 1. APPLICABILITY AND DEFINITIONS
6390 This License applies to any manual or other work, in any medium,
6391 that contains a notice placed by the copyright holder saying it
6392 can be distributed under the terms of this License. Such a notice
6393 grants a world-wide, royalty-free license, unlimited in duration,
6394 to use that work under the conditions stated herein. The
6395 "Document", below, refers to any such manual or work. Any member
6396 of the public is a licensee, and is addressed as "you". You
6397 accept the license if you copy, modify or distribute the work in a
6398 way requiring permission under copyright law.
6400 A "Modified Version" of the Document means any work containing the
6401 Document or a portion of it, either copied verbatim, or with
6402 modifications and/or translated into another language.
6404 A "Secondary Section" is a named appendix or a front-matter section
6405 of the Document that deals exclusively with the relationship of the
6406 publishers or authors of the Document to the Document's overall
6407 subject (or to related matters) and contains nothing that could
6408 fall directly within that overall subject. (Thus, if the Document
6409 is in part a textbook of mathematics, a Secondary Section may not
6410 explain any mathematics.) The relationship could be a matter of
6411 historical connection with the subject or with related matters, or
6412 of legal, commercial, philosophical, ethical or political position
6415 The "Invariant Sections" are certain Secondary Sections whose
6416 titles are designated, as being those of Invariant Sections, in
6417 the notice that says that the Document is released under this
6418 License. If a section does not fit the above definition of
6419 Secondary then it is not allowed to be designated as Invariant.
6420 The Document may contain zero Invariant Sections. If the Document
6421 does not identify any Invariant Sections then there are none.
6423 The "Cover Texts" are certain short passages of text that are
6424 listed, as Front-Cover Texts or Back-Cover Texts, in the notice
6425 that says that the Document is released under this License. A
6426 Front-Cover Text may be at most 5 words, and a Back-Cover Text may
6427 be at most 25 words.
6429 A "Transparent" copy of the Document means a machine-readable copy,
6430 represented in a format whose specification is available to the
6431 general public, that is suitable for revising the document
6432 straightforwardly with generic text editors or (for images
6433 composed of pixels) generic paint programs or (for drawings) some
6434 widely available drawing editor, and that is suitable for input to
6435 text formatters or for automatic translation to a variety of
6436 formats suitable for input to text formatters. A copy made in an
6437 otherwise Transparent file format whose markup, or absence of
6438 markup, has been arranged to thwart or discourage subsequent
6439 modification by readers is not Transparent. An image format is
6440 not Transparent if used for any substantial amount of text. A
6441 copy that is not "Transparent" is called "Opaque".
6443 Examples of suitable formats for Transparent copies include plain
6444 ASCII without markup, Texinfo input format, LaTeX input format,
6445 SGML or XML using a publicly available DTD, and
6446 standard-conforming simple HTML, PostScript or PDF designed for
6447 human modification. Examples of transparent image formats include
6448 PNG, XCF and JPG. Opaque formats include proprietary formats that
6449 can be read and edited only by proprietary word processors, SGML or
6450 XML for which the DTD and/or processing tools are not generally
6451 available, and the machine-generated HTML, PostScript or PDF
6452 produced by some word processors for output purposes only.
6454 The "Title Page" means, for a printed book, the title page itself,
6455 plus such following pages as are needed to hold, legibly, the
6456 material this License requires to appear in the title page. For
6457 works in formats which do not have any title page as such, "Title
6458 Page" means the text near the most prominent appearance of the
6459 work's title, preceding the beginning of the body of the text.
6461 A section "Entitled XYZ" means a named subunit of the Document
6462 whose title either is precisely XYZ or contains XYZ in parentheses
6463 following text that translates XYZ in another language. (Here XYZ
6464 stands for a specific section name mentioned below, such as
6465 "Acknowledgements", "Dedications", "Endorsements", or "History".)
6466 To "Preserve the Title" of such a section when you modify the
6467 Document means that it remains a section "Entitled XYZ" according
6470 The Document may include Warranty Disclaimers next to the notice
6471 which states that this License applies to the Document. These
6472 Warranty Disclaimers are considered to be included by reference in
6473 this License, but only as regards disclaiming warranties: any other
6474 implication that these Warranty Disclaimers may have is void and
6475 has no effect on the meaning of this License.
6479 You may copy and distribute the Document in any medium, either
6480 commercially or noncommercially, provided that this License, the
6481 copyright notices, and the license notice saying this License
6482 applies to the Document are reproduced in all copies, and that you
6483 add no other conditions whatsoever to those of this License. You
6484 may not use technical measures to obstruct or control the reading
6485 or further copying of the copies you make or distribute. However,
6486 you may accept compensation in exchange for copies. If you
6487 distribute a large enough number of copies you must also follow
6488 the conditions in section 3.
6490 You may also lend copies, under the same conditions stated above,
6491 and you may publicly display copies.
6493 3. COPYING IN QUANTITY
6495 If you publish printed copies (or copies in media that commonly
6496 have printed covers) of the Document, numbering more than 100, and
6497 the Document's license notice requires Cover Texts, you must
6498 enclose the copies in covers that carry, clearly and legibly, all
6499 these Cover Texts: Front-Cover Texts on the front cover, and
6500 Back-Cover Texts on the back cover. Both covers must also clearly
6501 and legibly identify you as the publisher of these copies. The
6502 front cover must present the full title with all words of the
6503 title equally prominent and visible. You may add other material
6504 on the covers in addition. Copying with changes limited to the
6505 covers, as long as they preserve the title of the Document and
6506 satisfy these conditions, can be treated as verbatim copying in
6509 If the required texts for either cover are too voluminous to fit
6510 legibly, you should put the first ones listed (as many as fit
6511 reasonably) on the actual cover, and continue the rest onto
6514 If you publish or distribute Opaque copies of the Document
6515 numbering more than 100, you must either include a
6516 machine-readable Transparent copy along with each Opaque copy, or
6517 state in or with each Opaque copy a computer-network location from
6518 which the general network-using public has access to download
6519 using public-standard network protocols a complete Transparent
6520 copy of the Document, free of added material. If you use the
6521 latter option, you must take reasonably prudent steps, when you
6522 begin distribution of Opaque copies in quantity, to ensure that
6523 this Transparent copy will remain thus accessible at the stated
6524 location until at least one year after the last time you
6525 distribute an Opaque copy (directly or through your agents or
6526 retailers) of that edition to the public.
6528 It is requested, but not required, that you contact the authors of
6529 the Document well before redistributing any large number of
6530 copies, to give them a chance to provide you with an updated
6531 version of the Document.
6535 You may copy and distribute a Modified Version of the Document
6536 under the conditions of sections 2 and 3 above, provided that you
6537 release the Modified Version under precisely this License, with
6538 the Modified Version filling the role of the Document, thus
6539 licensing distribution and modification of the Modified Version to
6540 whoever possesses a copy of it. In addition, you must do these
6541 things in the Modified Version:
6543 A. Use in the Title Page (and on the covers, if any) a title
6544 distinct from that of the Document, and from those of
6545 previous versions (which should, if there were any, be listed
6546 in the History section of the Document). You may use the
6547 same title as a previous version if the original publisher of
6548 that version gives permission.
6550 B. List on the Title Page, as authors, one or more persons or
6551 entities responsible for authorship of the modifications in
6552 the Modified Version, together with at least five of the
6553 principal authors of the Document (all of its principal
6554 authors, if it has fewer than five), unless they release you
6555 from this requirement.
6557 C. State on the Title page the name of the publisher of the
6558 Modified Version, as the publisher.
6560 D. Preserve all the copyright notices of the Document.
6562 E. Add an appropriate copyright notice for your modifications
6563 adjacent to the other copyright notices.
6565 F. Include, immediately after the copyright notices, a license
6566 notice giving the public permission to use the Modified
6567 Version under the terms of this License, in the form shown in
6570 G. Preserve in that license notice the full lists of Invariant
6571 Sections and required Cover Texts given in the Document's
6574 H. Include an unaltered copy of this License.
6576 I. Preserve the section Entitled "History", Preserve its Title,
6577 and add to it an item stating at least the title, year, new
6578 authors, and publisher of the Modified Version as given on
6579 the Title Page. If there is no section Entitled "History" in
6580 the Document, create one stating the title, year, authors,
6581 and publisher of the Document as given on its Title Page,
6582 then add an item describing the Modified Version as stated in
6583 the previous sentence.
6585 J. Preserve the network location, if any, given in the Document
6586 for public access to a Transparent copy of the Document, and
6587 likewise the network locations given in the Document for
6588 previous versions it was based on. These may be placed in
6589 the "History" section. You may omit a network location for a
6590 work that was published at least four years before the
6591 Document itself, or if the original publisher of the version
6592 it refers to gives permission.
6594 K. For any section Entitled "Acknowledgements" or "Dedications",
6595 Preserve the Title of the section, and preserve in the
6596 section all the substance and tone of each of the contributor
6597 acknowledgements and/or dedications given therein.
6599 L. Preserve all the Invariant Sections of the Document,
6600 unaltered in their text and in their titles. Section numbers
6601 or the equivalent are not considered part of the section
6604 M. Delete any section Entitled "Endorsements". Such a section
6605 may not be included in the Modified Version.
6607 N. Do not retitle any existing section to be Entitled
6608 "Endorsements" or to conflict in title with any Invariant
6611 O. Preserve any Warranty Disclaimers.
6613 If the Modified Version includes new front-matter sections or
6614 appendices that qualify as Secondary Sections and contain no
6615 material copied from the Document, you may at your option
6616 designate some or all of these sections as invariant. To do this,
6617 add their titles to the list of Invariant Sections in the Modified
6618 Version's license notice. These titles must be distinct from any
6619 other section titles.
6621 You may add a section Entitled "Endorsements", provided it contains
6622 nothing but endorsements of your Modified Version by various
6623 parties--for example, statements of peer review or that the text
6624 has been approved by an organization as the authoritative
6625 definition of a standard.
6627 You may add a passage of up to five words as a Front-Cover Text,
6628 and a passage of up to 25 words as a Back-Cover Text, to the end
6629 of the list of Cover Texts in the Modified Version. Only one
6630 passage of Front-Cover Text and one of Back-Cover Text may be
6631 added by (or through arrangements made by) any one entity. If the
6632 Document already includes a cover text for the same cover,
6633 previously added by you or by arrangement made by the same entity
6634 you are acting on behalf of, you may not add another; but you may
6635 replace the old one, on explicit permission from the previous
6636 publisher that added the old one.
6638 The author(s) and publisher(s) of the Document do not by this
6639 License give permission to use their names for publicity for or to
6640 assert or imply endorsement of any Modified Version.
6642 5. COMBINING DOCUMENTS
6644 You may combine the Document with other documents released under
6645 this License, under the terms defined in section 4 above for
6646 modified versions, provided that you include in the combination
6647 all of the Invariant Sections of all of the original documents,
6648 unmodified, and list them all as Invariant Sections of your
6649 combined work in its license notice, and that you preserve all
6650 their Warranty Disclaimers.
6652 The combined work need only contain one copy of this License, and
6653 multiple identical Invariant Sections may be replaced with a single
6654 copy. If there are multiple Invariant Sections with the same name
6655 but different contents, make the title of each such section unique
6656 by adding at the end of it, in parentheses, the name of the
6657 original author or publisher of that section if known, or else a
6658 unique number. Make the same adjustment to the section titles in
6659 the list of Invariant Sections in the license notice of the
6662 In the combination, you must combine any sections Entitled
6663 "History" in the various original documents, forming one section
6664 Entitled "History"; likewise combine any sections Entitled
6665 "Acknowledgements", and any sections Entitled "Dedications". You
6666 must delete all sections Entitled "Endorsements."
6668 6. COLLECTIONS OF DOCUMENTS
6670 You may make a collection consisting of the Document and other
6671 documents released under this License, and replace the individual
6672 copies of this License in the various documents with a single copy
6673 that is included in the collection, provided that you follow the
6674 rules of this License for verbatim copying of each of the
6675 documents in all other respects.
6677 You may extract a single document from such a collection, and
6678 distribute it individually under this License, provided you insert
6679 a copy of this License into the extracted document, and follow
6680 this License in all other respects regarding verbatim copying of
6683 7. AGGREGATION WITH INDEPENDENT WORKS
6685 A compilation of the Document or its derivatives with other
6686 separate and independent documents or works, in or on a volume of
6687 a storage or distribution medium, is called an "aggregate" if the
6688 copyright resulting from the compilation is not used to limit the
6689 legal rights of the compilation's users beyond what the individual
6690 works permit. When the Document is included in an aggregate, this
6691 License does not apply to the other works in the aggregate which
6692 are not themselves derivative works of the Document.
6694 If the Cover Text requirement of section 3 is applicable to these
6695 copies of the Document, then if the Document is less than one half
6696 of the entire aggregate, the Document's Cover Texts may be placed
6697 on covers that bracket the Document within the aggregate, or the
6698 electronic equivalent of covers if the Document is in electronic
6699 form. Otherwise they must appear on printed covers that bracket
6700 the whole aggregate.
6704 Translation is considered a kind of modification, so you may
6705 distribute translations of the Document under the terms of section
6706 4. Replacing Invariant Sections with translations requires special
6707 permission from their copyright holders, but you may include
6708 translations of some or all Invariant Sections in addition to the
6709 original versions of these Invariant Sections. You may include a
6710 translation of this License, and all the license notices in the
6711 Document, and any Warranty Disclaimers, provided that you also
6712 include the original English version of this License and the
6713 original versions of those notices and disclaimers. In case of a
6714 disagreement between the translation and the original version of
6715 this License or a notice or disclaimer, the original version will
6718 If a section in the Document is Entitled "Acknowledgements",
6719 "Dedications", or "History", the requirement (section 4) to
6720 Preserve its Title (section 1) will typically require changing the
6725 You may not copy, modify, sublicense, or distribute the Document
6726 except as expressly provided for under this License. Any other
6727 attempt to copy, modify, sublicense or distribute the Document is
6728 void, and will automatically terminate your rights under this
6729 License. However, parties who have received copies, or rights,
6730 from you under this License will not have their licenses
6731 terminated so long as such parties remain in full compliance.
6733 10. FUTURE REVISIONS OF THIS LICENSE
6735 The Free Software Foundation may publish new, revised versions of
6736 the GNU Free Documentation License from time to time. Such new
6737 versions will be similar in spirit to the present version, but may
6738 differ in detail to address new problems or concerns. See
6739 `http://www.gnu.org/copyleft/'.
6741 Each version of the License is given a distinguishing version
6742 number. If the Document specifies that a particular numbered
6743 version of this License "or any later version" applies to it, you
6744 have the option of following the terms and conditions either of
6745 that specified version or of any later version that has been
6746 published (not as a draft) by the Free Software Foundation. If
6747 the Document does not specify a version number of this License,
6748 you may choose any version ever published (not as a draft) by the
6749 Free Software Foundation.
6751 B.1 ADDENDUM: How to use this License for your documents
6752 ========================================================
6754 To use this License in a document you have written, include a copy of
6755 the License in the document and put the following copyright and license
6756 notices just after the title page:
6758 Copyright (C) YEAR YOUR NAME.
6759 Permission is granted to copy, distribute and/or modify this document
6760 under the terms of the GNU Free Documentation License, Version 1.2
6761 or any later version published by the Free Software Foundation;
6762 with no Invariant Sections, no Front-Cover Texts, and no Back-Cover
6763 Texts. A copy of the license is included in the section entitled ``GNU
6764 Free Documentation License''.
6766 If you have Invariant Sections, Front-Cover Texts and Back-Cover
6767 Texts, replace the "with...Texts." line with this:
6769 with the Invariant Sections being LIST THEIR TITLES, with
6770 the Front-Cover Texts being LIST, and with the Back-Cover Texts
6773 If you have Invariant Sections without Cover Texts, or some other
6774 combination of the three, merge those two alternatives to suit the
6777 If your document contains nontrivial examples of program code, we
6778 recommend releasing these examples in parallel under your choice of
6779 free software license, such as the GNU General Public License, to
6780 permit their use in free software.