Any architecture to be debugged by GDB is described in a struct gdbarch. When an object file is to be debugged, GDB will select the correct struct gdbarch using information about the object file captured in its BFD.
The data in struct gdbarch facilitates both the symbol side processing (for which it also uses the BFD information) and the target side processing (in combination with the frame and target operation information).
struct gdbarch is a mixture of data values (number of bytes in an integer for example) and functions to perform standard operations (e.g. to print the registers). The major functional groups are:
Data values capturing details of the hardware architecture. For example the endianism and the number of bits in an address and in a word. Some of this data is captured in the BFD, to which there is a reference in the struct gdbarch. There is also a structure, struct gdbarch_tdep to capture additional target specific data, beyond that which is covered by the standard struct gdbarch.
Data values describing how all the standard high level scalar data structures are represented (char, int, double etc).
Functions to access and display registers. GDB includes the concept of "pseudo-registers", those registers which do not physically exist, but which have a meaning within the architecture. For example in the OpenRISC 1000, floating point registers are actually the same as the General Purpose Registers. However a set of floating point pseudo-registers could be defined, to allow the GPRs to be displayed in floating point format.
Functions to access information on stack frames. This includes setting up "dummy" frames to allow GDB to evaluate functions (for example using the call command).
An architecture will need to specify most of the contents of
struct gdbarch, for which a set of functions (all starting
set_gdbarch_
) are provided. Defaults are provided
for all entries, and in a small number of cases these will be
suitable.
Analysis of the stack frames of executing programs is complex with different approaches needed for different circumstances. A set of functions to identify stack frames and analyze their contents is associated with each struct gdbarch.
A set of utility functions are provided to access the members of
struct gdbarch. Element xyz
of a struct gdbarch pointed to
by g
may be accessed by using
gdbarch_xyz (g, ...)
. This will check,
using gdb_assert
that g
is
defined, and in the case of functions that g->x
is not NULL
and return either the value g->xyz
(for values) or the result of calling
g->xyz (...)
(for functions). This saves the
user testing for existence before each function call, and ensures
any errors are handled cleanly.