GDB Internals - Target Architecture Definition

Go to the first, previous, next, last section, table of contents.

# Target Architecture Definition

GDB's target architecture defines what sort of machine-language programs GDB can work with, and how it works with them.

At present, the target architecture definition consists of a number of C macros.

## Registers and Memory

GDB's model of the target machine is rather simple. GDB assumes the machine includes a bank of registers and a block of memory. Each register may have a different size.

GDB does not have a magical way to match up with the compiler's idea of which registers are which; however, it is critical that they do match up accurately. The only way to make this work is to get accurate information about the order that the compiler uses, and to reflect that in the `REGISTER_NAME` and related macros.

GDB can handle big-endian, little-endian, and bi-endian architectures.

## Frame Interpretation

## Inferior Call Setup

## Compiler Characteristics

## Target Conditionals

This section describes the macros that you can use to define the target machine.

`ADDITIONAL_OPTIONS`
`ADDITIONAL_OPTION_CASES`
`ADDITIONAL_OPTION_HANDLER`
`ADDITIONAL_OPTION_HELP`
  These are a set of macros that allow the addition of additional command line options to GDB. They are currently used only for the unsupported i960 Nindy target, and should not be used in any other configuration.
`ADDR_BITS_REMOVE (addr)`
  If a raw machine address includes any bits that are not really part of the address, then define this macro to expand into an expression that zeros those bits in addr. For example, the two low-order bits of a Motorola 88K address may be used by some kernels for their own purposes, since addresses must always be 4-byte aligned, and so are of no use for addressing. Those bits should be filtered out with an expression such as `((addr) & ~3)`.
`BEFORE_MAIN_LOOP_HOOK`
  Define this to expand into any code that you want to execute before the main loop starts. Although this is not, strictly speaking, a target conditional, that is how it is currently being used. Note that if a configuration were to define it one way for a host and a different way for the target, GDB will probably not compile, let alone run correctly. This is currently used only for the unsupported i960 Nindy target, and should not be used in any other configuration.
`BELIEVE_PCC_PROMOTION`
  Define if the compiler promotes a short or char parameter to an int, but still reports the parameter as its original type, rather than the promoted type.
`BELIEVE_PCC_PROMOTION_TYPE`
  Define this if GDB should believe the type of a short argument when compiled by pcc, but look within a full int space to get its value. Only defined for Sun-3 at present.
`BITS_BIG_ENDIAN`
  Define this if the numbering of bits in the targets does *not* match the endianness of the target byte order. A value of 1 means that the bits are numbered in a big-endian order, 0 means little-endian.
`BREAKPOINT`
  This is the character array initializer for the bit pattern to put into memory where a breakpoint is set. Although it's common to use a trap instruction for a breakpoint, it's not required; for instance, the bit pattern could be an invalid instruction. The breakpoint must be no longer than the shortest instruction of the architecture. BREAKPOINT has been deprecated in favour of BREAKPOINT_FROM_PC.
`BIG_BREAKPOINT`
`LITTLE_BREAKPOINT`
  Similar to BREAKPOINT, but used for bi-endian targets. BIG_BREAKPOINT and LITTLE_BREAKPOINT have been deprecated in favour of BREAKPOINT_FROM_PC.
`REMOTE_BREAKPOINT`
`LITTLE_REMOTE_BREAKPOINT`
`BIG_REMOTE_BREAKPOINT`
  Similar to BREAKPOINT, but used for remote targets. BIG_REMOTE_BREAKPOINT and LITTLE_REMOTE_BREAKPOINT have been deprecated in favour of BREAKPOINT_FROM_PC.
`BREAKPOINT_FROM_PC (pcptr, lenptr)`
  Use the program counter to determine the contents and size of a breakpoint instruction. It returns a pointer to a string of bytes that encode a breakpoint instruction, stores the length of the string to *lenptr, and adjusts pc (if necessary) to point to the actual memory location where the breakpoint should be inserted. Although it is common to use a trap instruction for a breakpoint, it's not required; for instance, the bit pattern could be an invalid instruction. The breakpoint must be no longer than the shortest instruction of the architecture. Replaces all the other BREAKPOINT macros.
`CALL_DUMMY_P`
  A C expresson that is non-zero when the target suports inferior function calls.
`CALL_DUMMY_WORDS`
  Pointer to an array of LONGEST words of data containing host-byte-ordered REGISTER_BYTES sized values that partially specify the sequence of instructions needed for an inferior function call. Should be deprecated in favour of a macro that uses target-byte-ordered data.
`SIZEOF_CALL_DUMMY_WORDS`
  The size of CALL_DUMMY_WORDS. When CALL_DUMMY_P this must return a positive value. See also CALL_DUMMY_LENGTH.
`CALL_DUMMY`
  A static initializer for CALL_DUMMY_WORDS. Deprecated.
`CALL_DUMMY_LOCATION`
  inferior.h
`CALL_DUMMY_STACK_ADJUST`
  Stack adjustment needed when performing an inferior function call. Should be deprecated in favor of something like STACK_ALIGN.
`CALL_DUMMY_STACK_ADJUST_P`
  Predicate for use of CALL_DUMMY_STACK_ADJUST. Should be deprecated in favor of something like STACK_ALIGN.
`CANNOT_FETCH_REGISTER (regno)`
  A C expression that should be nonzero if regno cannot be fetched from an inferior process. This is only relevant if `FETCH_INFERIOR_REGISTERS` is not defined.
`CANNOT_STORE_REGISTER (regno)`
  A C expression that should be nonzero if regno should not be written to the target. This is often the case for program counters, status words, and other special registers. If this is not defined, GDB will assume that all registers may be written.
`DO_DEFERRED_STORES`
`CLEAR_DEFERRED_STORES`
  Define this to execute any deferred stores of registers into the inferior, and to cancel any deferred stores. Currently only implemented correctly for native Sparc configurations?
`CPLUS_MARKER`
  Define this to expand into the character that G++ uses to distinguish compiler-generated identifiers from programmer-specified identifiers. By default, this expands into `'$'`. Most System V targets should define this to `'.'`.
`DBX_PARM_SYMBOL_CLASS`
  Hook for the `SYMBOL_CLASS` of a parameter when decoding DBX symbol information. In the i960, parameters can be stored as locals or as args, depending on the type of the debug record.
`DECR_PC_AFTER_BREAK`
  Define this to be the amount by which to decrement the PC after the program encounters a breakpoint. This is often the number of bytes in BREAKPOINT, though not always. For most targets this value will be 0.
`DECR_PC_AFTER_HW_BREAK`
  Similarly, for hardware breakpoints.
`DISABLE_UNSETTABLE_BREAK addr`
  If defined, this should evaluate to 1 if addr is in a shared library in which breakpoints cannot be set and so should be disabled.
`DO_REGISTERS_INFO`
  If defined, use this to print the value of a register or all registers.
`END_OF_TEXT_DEFAULT`
  This is an expression that should designate the end of the text section (? FIXME ?)
`EXTRACT_RETURN_VALUE(type,regbuf,valbuf)`
  Define this to extract a function's return value of type type from the raw register state regbuf and copy that, in virtual format, into valbuf.
`EXTRACT_STRUCT_VALUE_ADDRESS(regbuf)`
  When EXTRACT_STRUCT_VALUE_ADDRESS_P this is used to to extract from an array regbuf (containing the raw register state) the address in which a function should return its structure value, as a CORE_ADDR (or an expression that can be used as one).
`EXTRACT_STRUCT_VALUE_ADDRESS_P`
  Predicate for EXTRACT_STRUCT_VALUE_ADDRESS.
`FLOAT_INFO`
  If defined, then the `info float' command will print information about the processor's floating point unit.
`FP_REGNUM`
  If the virtual frame pointer is kept in a register, then define this macro to be the number (greater than or equal to zero) of that register. This should only need to be defined if `TARGET_READ_FP` and `TARGET_WRITE_FP` are not defined.
`FRAMELESS_FUNCTION_INVOCATION(fi)`
  Define this to an expression that returns 1 if the function invocation represented by fi does not have a stack frame associated with it. Otherwise return 0.
`FRAME_ARGS_ADDRESS_CORRECT`
  stack.c
`FRAME_CHAIN(frame)`
  Given frame, return a pointer to the calling frame.
`FRAME_CHAIN_COMBINE(chain,frame)`
  Define this to take the frame chain pointer and the frame's nominal address and produce the nominal address of the caller's frame. Presently only defined for HP PA.
`FRAME_CHAIN_VALID(chain,thisframe)`
  Define this to be an expression that returns zero if the given frame is an outermost frame, with no caller, and nonzero otherwise. Three common definitions are available. `default_frame_chain_valid` (the default) is nonzero if the chain pointer is nonzero and given frame's PC is not inside the startup file (such as ``crt0.o'`). `alternate_frame_chain_valid` is nonzero if the chain pointer is nonzero and the given frame's PC is not in `main()` or a known entry point function (such as `_start()`).
`FRAME_INIT_SAVED_REGS(frame)`
  See ``frame.h'`. Determines the address of all registers in the current stack frame storing each in `frame->saved_regs`. Space for `frame->saved_regs` shall be allocated by `FRAME_INIT_SAVED_REGS` using either `frame_saved_regs_zalloc` or `frame_obstack_alloc`. FRAME_FIND_SAVED_REGS and EXTRA_FRAME_INFO are deprecated.
`FRAME_NUM_ARGS (fi)`
  For the frame described by fi return the number of arguments that are being passed. If the number of arguments is not known, return `-1`.
`FRAME_SAVED_PC(frame)`
  Given frame, return the pc saved there. That is, the return address.
`FUNCTION_EPILOGUE_SIZE`
  For some COFF targets, the `x_sym.x_misc.x_fsize` field of the function end symbol is 0. For such targets, you must define `FUNCTION_EPILOGUE_SIZE` to expand into the standard size of a function's epilogue.
`GCC_COMPILED_FLAG_SYMBOL`
`GCC2_COMPILED_FLAG_SYMBOL`
  If defined, these are the names of the symbols that GDB will look for to detect that GCC compiled the file. The default symbols are `gcc_compiled.` and `gcc2_compiled.`, respectively. (Currently only defined for the Delta 68.)
`GDB_MULTI_ARCH`
  If defined and non-zero, enables suport for multiple architectures within GDB. The support can be enabled at two levels. At level one, only definitions for previously undefined macros are provided; at level two, a multi-arch definition of all architecture dependant macros will be defined.
`GDB_TARGET_IS_HPPA`
  This determines whether horrible kludge code in dbxread.c and partial-stab.h is used to mangle multiple-symbol-table files from HPPA's. This should all be ripped out, and a scheme like elfread.c used.
`GDB_TARGET_IS_MACH386`
`GDB_TARGET_IS_SUN3`
`GDB_TARGET_IS_SUN386`
  Kludges that should go away.
`GET_LONGJMP_TARGET`
  For most machines, this is a target-dependent parameter. On the DECstation and the Iris, this is a native-dependent parameter, since <setjmp.h> is needed to define it. This macro determines the target PC address that longjmp() will jump to, assuming that we have just stopped at a longjmp breakpoint. It takes a CORE_ADDR * as argument, and stores the target PC value through this pointer. It examines the current state of the machine as needed.
`GET_SAVED_REGISTER`
  Define this if you need to supply your own definition for the function `get_saved_register`.
`HAVE_REGISTER_WINDOWS`
  Define this if the target has register windows.
`REGISTER_IN_WINDOW_P (regnum)`
  Define this to be an expression that is 1 if the given register is in the window.
`IBM6000_TARGET`
  Shows that we are configured for an IBM RS/6000 target. This conditional should be eliminated (FIXME) and replaced by feature-specific macros. It was introduced in haste and we are repenting at leisure.
`IEEE_FLOAT`
  Define this if the target system uses IEEE-format floating point numbers.
`INIT_EXTRA_FRAME_INFO (fromleaf, frame)`
  If additional information about the frame is required this should be stored in `frame->extra_info`. Space for `frame->extra_info` is allocated using `frame_obstack_alloc`.
`INIT_FRAME_PC (fromleaf, prev)`
  This is a C statement that sets the pc of the frame pointed to by prev. [By default...]
`INNER_THAN (lhs,rhs)`
  Returns non-zero if stack address lhs is inner than (nearer to the stack top) stack address rhs. Define this as `lhs < rhs` if the target's stack grows downward in memory, or `lhs > rsh` if the stack grows upward.
`IN_SIGTRAMP (pc, name)`
  Define this to return true if the given pc and/or name indicates that the current function is a sigtramp.
`SIGTRAMP_START (pc)`
`SIGTRAMP_END (pc)`
  Define these to be the start and end address of the sigtramp for the given pc. On machines where the address is just a compile time constant, the macro expansion will typically just ignore the supplied pc.
`IN_SOLIB_CALL_TRAMPOLINE pc name`
  Define this to evaluate to nonzero if the program is stopped in the trampoline that connects to a shared library.
`IN_SOLIB_RETURN_TRAMPOLINE pc name`
  Define this to evaluate to nonzero if the program is stopped in the trampoline that returns from a shared library.
`IS_TRAPPED_INTERNALVAR (name)`
  This is an ugly hook to allow the specification of special actions that should occur as a side-effect of setting the value of a variable internal to GDB. Currently only used by the h8500. Note that this could be either a host or target conditional.
`NEED_TEXT_START_END`
  Define this if GDB should determine the start and end addresses of the text section. (Seems dubious.)
`NO_HIF_SUPPORT`
  (Specific to the a29k.)
`SOFTWARE_SINGLE_STEP_P`
  Define this as 1 if the target does not have a hardware single-step mechanism. The macro `SOFTWARE_SINGLE_STEP` must also be defined.
`SOFTWARE_SINGLE_STEP(signal,insert_breapoints_p)`
  A function that inserts or removes (dependant on insert_breapoints_p) breakpoints at each possible destinations of the next instruction. See `sparc-tdep.c` and `rs6000-tdep.c` for examples.
`PCC_SOL_BROKEN`
  (Used only in the Convex target.)
`PC_IN_CALL_DUMMY`
  inferior.h
`PC_LOAD_SEGMENT`
  If defined, print information about the load segment for the program counter. (Defined only for the RS/6000.)
`PC_REGNUM`
  If the program counter is kept in a register, then define this macro to be the number (greater than or equal to zero) of that register. This should only need to be defined if `TARGET_READ_PC` and `TARGET_WRITE_PC` are not defined.
`NPC_REGNUM`
  The number of the "next program counter" register, if defined.
`NNPC_REGNUM`
  The number of the "next next program counter" register, if defined. Currently, this is only defined for the Motorola 88K.
`PRINT_REGISTER_HOOK (regno)`
  If defined, this must be a function that prints the contents of the given register to standard output.
`PRINT_TYPELESS_INTEGER`
  This is an obscure substitute for `print_longest` that seems to have been defined for the Convex target.
`PROCESS_LINENUMBER_HOOK`
  A hook defined for XCOFF reading.
`PROLOGUE_FIRSTLINE_OVERLAP`
  (Only used in unsupported Convex configuration.)
`PS_REGNUM`
  If defined, this is the number of the processor status register. (This definition is only used in generic code when parsing "$ps".)
`POP_FRAME`
  Used in ``call_function_by_hand'` to remove an artificial stack frame.
`PUSH_ARGUMENTS (nargs, args, sp, struct_return, struct_addr)`
  Define this to push arguments onto the stack for inferior function call. Return the updated stack pointer value.
`PUSH_DUMMY_FRAME`
  Used in ``call_function_by_hand'` to create an artificial stack frame.
`REGISTER_BYTES`
  The total amount of space needed to store GDB's copy of the machine's register state.
`REGISTER_NAME(i)`
  Return the name of register i as a string. May return NULL or NUL to indicate that register i is not valid.
`REGISTER_NAMES`
  Deprecated in favor of REGISTER_NAME.
`REG_STRUCT_HAS_ADDR (gcc_p, type)`
  Define this to return 1 if the given type will be passed by pointer rather than directly.
`SAVE_DUMMY_FRAME_TOS (sp)`
  Used in ``call_function_by_hand'` to notify the target dependent code of the top-of-stack value that will be passed to the the inferior code. This is the value of the SP after both the dummy frame and space for parameters/results have been allocated on the stack.
`SDB_REG_TO_REGNUM`
  Define this to convert sdb register numbers into GDB regnums. If not defined, no conversion will be done.
`SHIFT_INST_REGS`
  (Only used for m88k targets.)
`SKIP_PROLOGUE (pc)`
  A C expression that returns the address of the "real" code beyond the function entry prologue found at pc.
`SKIP_PROLOGUE_FRAMELESS_P`
  A C expression that should behave similarly, but that can stop as soon as the function is known to have a frame. If not defined, `SKIP_PROLOGUE` will be used instead.
`SKIP_TRAMPOLINE_CODE (pc)`
  If the target machine has trampoline code that sits between callers and the functions being called, then define this macro to return a new PC that is at the start of the real function.
`SP_REGNUM`
  If the stack-pointer is kept in a register, then define this macro to be the number (greater than or equal to zero) of that register. This should only need to be defined if `TARGET_WRITE_SP` and `TARGET_WRITE_SP` are not defined.
`STAB_REG_TO_REGNUM`
  Define this to convert stab register numbers (as gotten from `r' declarations) into GDB regnums. If not defined, no conversion will be done.
`STACK_ALIGN (addr)`
  Define this to adjust the address to the alignment required for the processor's stack.
`STEP_SKIPS_DELAY (addr)`
  Define this to return true if the address is of an instruction with a delay slot. If a breakpoint has been placed in the instruction's delay slot, GDB will single-step over that instruction before resuming normally. Currently only defined for the Mips.
`STORE_RETURN_VALUE (type, valbuf)`
  A C expression that stores a function return value of type type, where valbuf is the address of the value to be stored.
`SUN_FIXED_LBRAC_BUG`
  (Used only for Sun-3 and Sun-4 targets.)
`SYMBOL_RELOADING_DEFAULT`
  The default value of the `symbol-reloading' variable. (Never defined in current sources.)
`TARGET_BYTE_ORDER_DEFAULT`
  The ordering of bytes in the target. This must be either `BIG_ENDIAN` or `LITTLE_ENDIAN`. This macro replaces TARGET_BYTE_ORDER which is deprecated.
`TARGET_BYTE_ORDER_SELECTABLE_P`
  Non-zero if the target has both `BIG_ENDIAN` and `LITTLE_ENDIAN` variants. This macro replaces TARGET_BYTE_ORDER_SELECTABLE which is deprecated.
`TARGET_CHAR_BIT`
  Number of bits in a char; defaults to 8.
`TARGET_COMPLEX_BIT`
  Number of bits in a complex number; defaults to `2 * TARGET_FLOAT_BIT`. At present this macro is not used.
`TARGET_DOUBLE_BIT`
  Number of bits in a double float; defaults to `8 * TARGET_CHAR_BIT`.
`TARGET_DOUBLE_COMPLEX_BIT`
  Number of bits in a double complex; defaults to `2 * TARGET_DOUBLE_BIT`. At present this macro is not used.
`TARGET_FLOAT_BIT`
  Number of bits in a float; defaults to `4 * TARGET_CHAR_BIT`.
`TARGET_INT_BIT`
  Number of bits in an integer; defaults to `4 * TARGET_CHAR_BIT`.
`TARGET_LONG_BIT`
  Number of bits in a long integer; defaults to `4 * TARGET_CHAR_BIT`.
`TARGET_LONG_DOUBLE_BIT`
  Number of bits in a long double float; defaults to `2 * TARGET_DOUBLE_BIT`.
`TARGET_LONG_LONG_BIT`
  Number of bits in a long long integer; defaults to `2 * TARGET_LONG_BIT`.
`TARGET_PTR_BIT`
  Number of bits in a pointer; defaults to `TARGET_INT_BIT`.
`TARGET_SHORT_BIT`
  Number of bits in a short integer; defaults to `2 * TARGET_CHAR_BIT`.
`TARGET_READ_PC`
`TARGET_WRITE_PC (val, pid)`
`TARGET_READ_SP`
`TARGET_WRITE_SP`
`TARGET_READ_FP`
`TARGET_WRITE_FP`
  These change the behavior of `read_pc`, `write_pc`, `read_sp`, `write_sp`, `read_fp` and `write_fp`. For most targets, these may be left undefined. GDB will call the read and write register functions with the relevant `_REGNUM` argument. These macros are useful when a target keeps one of these registers in a hard to get at place; for example, part in a segment register and part in an ordinary register.
`TARGET_VIRTUAL_FRAME_POINTER(pc,regp,offsetp)`
  Returns a `(register, offset)` pair representing the virtual frame pointer in use at the code address `"pc"`. If virtual frame pointers are not used, a default definition simply returns `FP_REGNUM`, with an offset of zero.
`USE_STRUCT_CONVENTION (gcc_p, type)`
  If defined, this must be an expression that is nonzero if a value of the given type being returned from a function must have space allocated for it on the stack. gcc_p is true if the function being considered is known to have been compiled by GCC; this is helpful for systems where GCC is known to use different calling convention than other compilers.
`VARIABLES_INSIDE_BLOCK (desc, gcc_p)`
  For dbx-style debugging information, if the compiler puts variable declarations inside LBRAC/RBRAC blocks, this should be defined to be nonzero. desc is the value of `n_desc` from the `N_RBRAC` symbol, and gcc_p is true if GDB has noticed the presence of either the `GCC_COMPILED_SYMBOL` or the `GCC2_COMPILED_SYMBOL`. By default, this is 0.
`OS9K_VARIABLES_INSIDE_BLOCK (desc, gcc_p)`
  Similarly, for OS/9000. Defaults to 1.

Motorola M68K target conditionals.

`BPT_VECTOR`
  Define this to be the 4-bit location of the breakpoint trap vector. If not defined, it will default to `0xf`.
`REMOTE_BPT_VECTOR`
  Defaults to `1`.

## Adding a New Target

The following files define a target to GDB:

``gdb/config/arch/ttt.mt'`
  Contains a Makefile fragment specific to this target. Specifies what object files are needed for target ttt, by defining ``TDEPFILES=...'`. Also specifies the header file which describes ttt, by defining ``TM_FILE= tm-ttt.h'`. You can also define ``TM_CFLAGS'`, ``TM_CLIBS'`, ``TM_CDEPS'`, but these are now deprecated and may go away in future versions of GDB.
``gdb/config/arch/tm-ttt.h'`
  (``tm.h'` is a link to this file, created by configure). Contains macro definitions about the target machine's registers, stack frame format and instructions.
``gdb/ttt-tdep.c'`
  Contains any miscellaneous code required for this target machine. On some machines it doesn't exist at all. Sometimes the macros in ``tm-ttt.h'` become very complicated, so they are implemented as functions here instead, and the macro is simply defined to call the function. This is vastly preferable, since it is easier to understand and debug.
``gdb/config/arch/tm-arch.h'`
  This often exists to describe the basic layout of the target machine's processor chip (registers, stack, etc). If used, it is included by ``tm-ttt.h'`. It can be shared among many targets that use the same processor.
``gdb/arch-tdep.c'`
  Similarly, there are often common subroutines that are shared by all target machines that use this particular architecture.

If you are adding a new operating system for an existing CPU chip, add a ``config/tm-os.h'` file that describes the operating system facilities that are unusual (extra symbol table info; the breakpoint instruction needed; etc). Then write a ``arch/tm-os.h'` that just `#include`s ``tm-arch.h'` and ``config/tm-os.h'`.

Go to the first, previous, next, last section, table of contents.