GDB (xrefs)
Loading...
Searching...
No Matches
gdbarch.h
Go to the documentation of this file.
1/* Dynamic architecture support for GDB, the GNU debugger.
2
3 Copyright (C) 1998-2023 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20
21#ifndef GDBARCH_H
22#define GDBARCH_H
23
24#include <vector>
25#include "frame.h"
26#include "dis-asm.h"
27#include "gdbsupport/gdb_obstack.h"
28#include "infrun.h"
29#include "osabi.h"
30#include "displaced-stepping.h"
31#include "gdbsupport/gdb-checked-static-cast.h"
32#include "registry.h"
33
34struct floatformat;
35struct ui_file;
36struct value;
37struct objfile;
38struct obj_section;
39struct minimal_symbol;
40struct regcache;
41struct reggroup;
42struct regset;
43struct disassemble_info;
44struct target_ops;
45struct obstack;
46struct bp_target_info;
47struct target_desc;
48struct symbol;
49struct syscall;
50struct agent_expr;
51struct axs_value;
52struct stap_parse_info;
53struct expr_builder;
55struct mem_range;
56struct syscalls_info;
57struct thread_info;
58struct ui_out;
59struct inferior;
60struct x86_xsave_layout;
61
62#include "regcache.h"
63
64/* The base class for every architecture's tdep sub-class. The virtual
65 destructor ensures the class has RTTI information, which allows
66 gdb::checked_static_cast to be used in the gdbarch_tdep function. */
67
69{
70 virtual ~gdbarch_tdep_base() = default;
71};
72
73using gdbarch_tdep_up = std::unique_ptr<gdbarch_tdep_base>;
74
75/* The architecture associated with the inferior through the
76 connection to the target.
77
78 The architecture vector provides some information that is really a
79 property of the inferior, accessed through a particular target:
80 ptrace operations; the layout of certain RSP packets; the solib_ops
81 vector; etc. To differentiate architecture accesses to
82 per-inferior/target properties from
83 per-thread/per-frame/per-objfile properties, accesses to
84 per-inferior/target properties should be made through this
85 gdbarch. */
86
87/* This is a convenience wrapper for 'current_inferior ()->gdbarch'. */
88extern struct gdbarch *target_gdbarch (void);
89
90/* Callback type for the 'iterate_over_objfiles_in_search_order'
91 gdbarch method. */
92
94 = gdb::function_view<bool(objfile *)>;
95
96/* Callback type for regset section iterators. The callback usually
97 invokes the REGSET's supply or collect method, to which it must
98 pass a buffer - for collects this buffer will need to be created using
99 COLLECT_SIZE, for supply the existing buffer being read from should
100 be at least SUPPLY_SIZE. SECT_NAME is a BFD section name, and HUMAN_NAME
101 is used for diagnostic messages. CB_DATA should have been passed
102 unchanged through the iterator. */
105 (const char *sect_name, int supply_size, int collect_size,
106 const struct regset *regset, const char *human_name, void *cb_data);
107
108/* For a function call, does the function return a value using a
109 normal value return or a structure return - passing a hidden
110 argument pointing to storage. For the latter, there are two
111 cases: language-mandated structure return and target ABI
112 structure return. */
115{
116 /* Standard value return. */
118
119 /* Language ABI structure return. This is handled
120 by passing the return location as the first parameter to
121 the function, even preceding "this". */
123
124 /* Target ABI struct return. This is target-specific; for instance,
125 on ia64 the first argument is passed in out0 but the hidden
126 structure return pointer would normally be passed in r8. */
128};
130enum class memtag_type
131{
132 /* Logical tag, the tag that is stored in unused bits of a pointer to a
133 virtual address. */
134 logical = 0,
135
136 /* Allocation tag, the tag that is associated with every granule of memory in
137 the physical address space. Allocation tags are used to validate memory
138 accesses via pointers containing logical tags. */
140};
141
142/* Callback types for 'read_core_file_mappings' gdbarch method. */
145 gdb::function_view<void (ULONGEST count)>;
148 gdb::function_view<void (int num,
149 ULONGEST start,
150 ULONGEST end,
151 ULONGEST file_ofs,
152 const char *filename,
153 const bfd_build_id *build_id)>;
154
155/* Possible values for gdbarch_call_dummy_location. */
160};
161
162#include "gdbarch-gen.h"
163
164/* An internal function that should _only_ be called from gdbarch_tdep.
165 Returns the gdbarch_tdep_base field held within GDBARCH. */
166
167extern struct gdbarch_tdep_base *gdbarch_tdep_1 (struct gdbarch *gdbarch);
168
169/* Return the gdbarch_tdep_base object held within GDBARCH cast to the type
170 TDepType, which should be a sub-class of gdbarch_tdep_base.
171
172 When GDB is compiled in maintainer mode a run-time check is performed
173 that the gdbarch_tdep_base within GDBARCH really is of type TDepType.
174 When GDB is compiled in release mode the run-time check is not
175 performed, and we assume the caller knows what they are doing. */
176
177template<typename TDepType>
178static inline TDepType *
180{
182 return gdb::checked_static_cast<TDepType *> (tdep);
183}
184
185/* Mechanism for co-ordinating the selection of a specific
186 architecture.
187
188 GDB targets (*-tdep.c) can register an interest in a specific
189 architecture. Other GDB components can register a need to maintain
190 per-architecture data.
191
192 The mechanisms below ensures that there is only a loose connection
193 between the set-architecture command and the various GDB
194 components. Each component can independently register their need
195 to maintain architecture specific data with gdbarch.
196
197 Pragmatics:
198
199 Previously, a single TARGET_ARCHITECTURE_HOOK was provided. It
200 didn't scale.
201
202 The more traditional mega-struct containing architecture specific
203 data for all the various GDB components was also considered. Since
204 GDB is built from a variable number of (fairly independent)
205 components it was determined that the global approach was not
206 applicable. */
207
208
209/* Register a new architectural family with GDB.
210
211 Register support for the specified ARCHITECTURE with GDB. When
212 gdbarch determines that the specified architecture has been
213 selected, the corresponding INIT function is called.
214
215 --
216
217 The INIT function takes two parameters: INFO which contains the
218 information available to gdbarch about the (possibly new)
219 architecture; ARCHES which is a list of the previously created
220 ``struct gdbarch'' for this architecture.
221
222 The INFO parameter is, as far as possible, be pre-initialized with
223 information obtained from INFO.ABFD or the global defaults.
224
225 The ARCHES parameter is a linked list (sorted most recently used)
226 of all the previously created architures for this architecture
227 family. The (possibly NULL) ARCHES->gdbarch can used to access
228 values from the previously selected architecture for this
229 architecture family.
230
231 The INIT function shall return any of: NULL - indicating that it
232 doesn't recognize the selected architecture; an existing ``struct
233 gdbarch'' from the ARCHES list - indicating that the new
234 architecture is just a synonym for an earlier architecture (see
235 gdbarch_list_lookup_by_info()); a newly created ``struct gdbarch''
236 - that describes the selected architecture (see gdbarch_alloc()).
237
238 The DUMP_TDEP function shall print out all target specific values.
239 Care should be taken to ensure that the function works in both the
240 multi-arch and non- multi-arch cases. */
242struct gdbarch_list
245 struct gdbarch_list *next;
246};
248struct gdbarch_info
250 gdbarch_info ()
251 /* Ensure the union is zero-initialized. Relies on the fact that there's
252 no member larger than TDESC_DATA. */
253 : tdesc_data ()
254 {}
256 const struct bfd_arch_info *bfd_arch_info = nullptr;
258 enum bfd_endian byte_order = BFD_ENDIAN_UNKNOWN;
260 enum bfd_endian byte_order_for_code = BFD_ENDIAN_UNKNOWN;
262 bfd *abfd = nullptr;
263
264 /* Architecture-specific target description data. */
269 const struct target_desc *target_desc = nullptr;
270};
271
272typedef struct gdbarch *(gdbarch_init_ftype) (struct gdbarch_info info, struct gdbarch_list *arches);
273typedef void (gdbarch_dump_tdep_ftype) (struct gdbarch *gdbarch, struct ui_file *file);
274typedef bool (gdbarch_supports_arch_info_ftype) (const struct bfd_arch_info *);
276extern void gdbarch_register (enum bfd_architecture architecture,
277 gdbarch_init_ftype *init,
278 gdbarch_dump_tdep_ftype *dump_tdep = nullptr,
279 gdbarch_supports_arch_info_ftype *supports_arch_info = nullptr);
280
281
282/* Return a vector of the valid architecture names. Since architectures are
283 registered during the _initialize phase this function only returns useful
284 information once initialization has been completed. */
285
286extern std::vector<const char *> gdbarch_printable_names ();
287
288
289/* Helper function. Search the list of ARCHES for a GDBARCH that
290 matches the information provided by INFO. */
291
292extern struct gdbarch_list *gdbarch_list_lookup_by_info (struct gdbarch_list *arches, const struct gdbarch_info *info);
293
294
295/* Helper function. Create a preliminary ``struct gdbarch''. Perform
296 basic initialization using values obtained from the INFO and TDEP
297 parameters. set_gdbarch_*() functions are called to complete the
298 initialization of the object. */
299
300extern struct gdbarch *gdbarch_alloc (const struct gdbarch_info *info,
301 gdbarch_tdep_up tdep);
302
303
304/* Helper function. Free a partially-constructed ``struct gdbarch''.
305 It is assumed that the caller frees the ``struct
306 gdbarch_tdep''. */
307
308extern void gdbarch_free (struct gdbarch *);
310struct gdbarch_deleter
312 void operator() (gdbarch *arch) const
313 { gdbarch_free (arch); }
314};
316using gdbarch_up = std::unique_ptr<gdbarch, gdbarch_deleter>;
317
318/* Get the obstack owned by ARCH. */
319
320extern obstack *gdbarch_obstack (gdbarch *arch);
321
322/* Helper function. Allocate memory from the ``struct gdbarch''
323 obstack. The memory is freed when the corresponding architecture
324 is also freed. */
326#define GDBARCH_OBSTACK_CALLOC(GDBARCH, NR, TYPE) obstack_calloc<TYPE> (gdbarch_obstack ((GDBARCH)), (NR))
328#define GDBARCH_OBSTACK_ZALLOC(GDBARCH, TYPE) obstack_zalloc<TYPE> (gdbarch_obstack ((GDBARCH)))
329
330/* Duplicate STRING, returning an equivalent string that's allocated on the
331 obstack associated with GDBARCH. The string is freed when the corresponding
332 architecture is also freed. */
333
334extern char *gdbarch_obstack_strdup (struct gdbarch *arch, const char *string);
335
336/* Helper function. Force an update of the current architecture.
337
338 The actual architecture selected is determined by INFO, ``(gdb) set
339 architecture'' et.al., the existing architecture and BFD's default
340 architecture. INFO should be initialized to zero and then selected
341 fields should be updated.
342
343 Returns non-zero if the update succeeds. */
344
345extern int gdbarch_update_p (struct gdbarch_info info);
346
347
348/* Helper function. Find an architecture matching info.
349
350 INFO should have relevant fields set, and then finished using
351 gdbarch_info_fill.
352
353 Returns the corresponding architecture, or NULL if no matching
354 architecture was found. */
355
356extern struct gdbarch *gdbarch_find_by_info (struct gdbarch_info info);
357
358
359/* Helper function. Set the target gdbarch to "gdbarch". */
360
361extern void set_target_gdbarch (struct gdbarch *gdbarch);
362
363
364/* A registry adaptor for gdbarch. This arranges to store the
365 registry in the gdbarch. */
366template<>
368{
369 static registry<gdbarch> *get (gdbarch *arch);
370};
371
372/* Set the dynamic target-system-dependent parameters (architecture,
373 byte-order, ...) using information found in the BFD. */
374
375extern void set_gdbarch_from_file (bfd *);
376
377
378/* Initialize the current architecture to the "first" one we find on
379 our list. */
380
381extern void initialize_current_architecture (void);
382
383/* gdbarch trace variable */
384extern unsigned int gdbarch_debug;
385
386extern void gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file);
387
388/* Return the number of cooked registers (raw + pseudo) for ARCH. */
389
390static inline int
392{
393 return gdbarch_num_regs (arch) + gdbarch_num_pseudo_regs (arch);
394}
395
396#endif
constexpr string_view get()
Definition 70483.cc:49
static std::vector< const char * > arches
Definition arch-utils.c:685
int gdbarch_num_regs(struct gdbarch *gdbarch)
Definition gdbarch.c:1930
int gdbarch_num_pseudo_regs(struct gdbarch *gdbarch)
Definition gdbarch.c:1948
void gdbarch_dump(struct gdbarch *gdbarch, struct ui_file *file)
Definition gdbarch.c:537
unsigned int gdbarch_debug
int gdbarch_update_p(struct gdbarch_info info)
Definition arch-utils.c:585
void gdbarch_free(struct gdbarch *)
gdb::function_view< void(ULONGEST count)> read_core_file_mappings_pre_loop_ftype
Definition gdbarch.h:143
gdb::function_view< bool(objfile *)> iterate_over_objfiles_in_search_order_cb_ftype
Definition gdbarch.h:93
std::unique_ptr< gdbarch_tdep_base > gdbarch_tdep_up
Definition gdbarch.h:73
struct gdbarch * gdbarch_alloc(const struct gdbarch_info *info, gdbarch_tdep_up tdep)
Definition gdbarch.c:266
bool gdbarch_supports_arch_info_ftype(const struct bfd_arch_info *)
Definition gdbarch.h:273
struct gdbarch * target_gdbarch(void)
void set_target_gdbarch(struct gdbarch *gdbarch)
struct gdbarch * gdbarch_init_ftype(struct gdbarch_info info, struct gdbarch_list *arches)
Definition gdbarch.h:271
char * gdbarch_obstack_strdup(struct gdbarch *arch, const char *string)
void initialize_current_architecture(void)
Definition arch-utils.c:688
memtag_type
Definition gdbarch.h:130
void set_gdbarch_from_file(bfd *)
Definition arch-utils.c:649
void gdbarch_register(enum bfd_architecture architecture, gdbarch_init_ftype *init, gdbarch_dump_tdep_ftype *dump_tdep=nullptr, gdbarch_supports_arch_info_ftype *supports_arch_info=nullptr)
static TDepType * gdbarch_tdep(struct gdbarch *gdbarch)
Definition gdbarch.h:178
void iterate_over_regset_sections_cb(const char *sect_name, int supply_size, int collect_size, const struct regset *regset, const char *human_name, void *cb_data)
Definition gdbarch.h:104
obstack * gdbarch_obstack(gdbarch *arch)
std::vector< const char * > gdbarch_printable_names()
struct gdbarch_tdep_base * gdbarch_tdep_1(struct gdbarch *gdbarch)
void gdbarch_dump_tdep_ftype(struct gdbarch *gdbarch, struct ui_file *file)
Definition gdbarch.h:272
std::unique_ptr< gdbarch, gdbarch_deleter > gdbarch_up
Definition gdbarch.h:315
call_dummy_location_type
Definition gdbarch.h:156
@ AT_ENTRY_POINT
Definition gdbarch.h:158
@ ON_STACK
Definition gdbarch.h:157
gdb::function_view< void(int num, ULONGEST start, ULONGEST end, ULONGEST file_ofs, const char *filename, const bfd_build_id *build_id)> read_core_file_mappings_loop_ftype
Definition gdbarch.h:146
static int gdbarch_num_cooked_regs(gdbarch *arch)
Definition gdbarch.h:390
struct gdbarch_list * gdbarch_list_lookup_by_info(struct gdbarch_list *arches, const struct gdbarch_info *info)
function_call_return_method
Definition gdbarch.h:114
@ return_method_struct
Definition gdbarch.h:126
@ return_method_normal
Definition gdbarch.h:116
@ return_method_hidden_param
Definition gdbarch.h:121
struct gdbarch * gdbarch_find_by_info(struct gdbarch_info info)
info(Component c)
Definition gdbarch.py:41
gdb_osabi
Definition osabi.h:25
@ GDB_OSABI_UNKNOWN
Definition osabi.h:26
void operator()(gdbarch *arch) const
Definition gdbarch.h:311
enum bfd_endian byte_order
Definition gdbarch.h:257
bfd * abfd
Definition gdbarch.h:261
const struct bfd_arch_info * bfd_arch_info
Definition gdbarch.h:255
struct tdesc_arch_data * tdesc_data
Definition gdbarch.h:264
enum bfd_endian byte_order_for_code
Definition gdbarch.h:259
enum gdb_osabi osabi
Definition gdbarch.h:266
struct gdbarch * gdbarch
Definition gdbarch.h:243
struct gdbarch_list * next
Definition gdbarch.h:244
virtual ~gdbarch_tdep_base()=default
Definition value.h:130