]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/gdbarch.h
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / gdbarch.h
CommitLineData
adf40b2e 1/* Dynamic architecture support for GDB, the GNU debugger.
79d45cd4 2
213516ef 3 Copyright (C) 1998-2023 Free Software Foundation, Inc.
c906108c 4
c5aa993b 5 This file is part of GDB.
c906108c 6
c5aa993b
JM
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
a9762ec7 9 the Free Software Foundation; either version 3 of the License, or
c5aa993b 10 (at your option) any later version.
618f726f 11
c5aa993b
JM
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.
618f726f 16
c5aa993b 17 You should have received a copy of the GNU General Public License
a9762ec7 18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
c906108c 19
adf40b2e 20
c906108c
SS
21#ifndef GDBARCH_H
22#define GDBARCH_H
23
a0ff9e1a 24#include <vector>
eb7a547a 25#include "frame.h"
65b48a81 26#include "dis-asm.h"
bf31fd38 27#include "gdbsupport/gdb_obstack.h"
fdb61c6c 28#include "infrun.h"
fe4b2ee6 29#include "osabi.h"
c7acb87b 30#include "displaced-stepping.h"
c44885db 31#include "gdbsupport/gdb-checked-static-cast.h"
cb275538 32#include "registry.h"
eb7a547a 33
da3331ec
AC
34struct floatformat;
35struct ui_file;
cce74817 36struct value;
b6af0555 37struct objfile;
1c772458 38struct obj_section;
a2cf933a 39struct minimal_symbol;
049ee0e4 40struct regcache;
b59ff9d5 41struct reggroup;
6ce6d90f 42struct regset;
a89aa300 43struct disassemble_info;
e2d0e7eb 44struct target_ops;
030f20e1 45struct obstack;
8181d85f 46struct bp_target_info;
424163ea 47struct target_desc;
3e29f34a 48struct symbol;
a96d9b2e 49struct syscall;
175ff332 50struct agent_expr;
6710bf39 51struct axs_value;
55aa24fb 52struct stap_parse_info;
37eedb39 53struct expr_builder;
7e35103a 54struct ravenscar_arch_ops;
3437254d 55struct mem_range;
458c8db8 56struct syscalls_info;
4dfc5dbc 57struct thread_info;
012b3a21 58struct ui_out;
187b041e 59struct inferior;
0f71a2f6 60
8a526fa6
PA
61#include "regcache.h"
62
c44885db
AB
63/* The base class for every architecture's tdep sub-class. The virtual
64 destructor ensures the class has RTTI information, which allows
ab25d9bb 65 gdb::checked_static_cast to be used in the gdbarch_tdep function. */
c44885db 66
ab25d9bb 67struct gdbarch_tdep_base
c44885db 68{
ab25d9bb 69 virtual ~gdbarch_tdep_base() = default;
c44885db 70};
345bd07c 71
6ecd4729
PA
72/* The architecture associated with the inferior through the
73 connection to the target.
74
75 The architecture vector provides some information that is really a
76 property of the inferior, accessed through a particular target:
77 ptrace operations; the layout of certain RSP packets; the solib_ops
78 vector; etc. To differentiate architecture accesses to
79 per-inferior/target properties from
80 per-thread/per-frame/per-objfile properties, accesses to
81 per-inferior/target properties should be made through this
82 gdbarch. */
83
84/* This is a convenience wrapper for 'current_inferior ()->gdbarch'. */
f5656ead 85extern struct gdbarch *target_gdbarch (void);
6ecd4729 86
19630284
JB
87/* Callback type for the 'iterate_over_objfiles_in_search_order'
88 gdbarch method. */
89
6e9cd73e
SM
90using iterate_over_objfiles_in_search_order_cb_ftype
91 = gdb::function_view<bool(objfile *)>;
19630284 92
1528345d
AA
93/* Callback type for regset section iterators. The callback usually
94 invokes the REGSET's supply or collect method, to which it must
a616bb94
AH
95 pass a buffer - for collects this buffer will need to be created using
96 COLLECT_SIZE, for supply the existing buffer being read from should
97 be at least SUPPLY_SIZE. SECT_NAME is a BFD section name, and HUMAN_NAME
98 is used for diagnostic messages. CB_DATA should have been passed
99 unchanged through the iterator. */
1528345d 100
5aa82d05 101typedef void (iterate_over_regset_sections_cb)
a616bb94
AH
102 (const char *sect_name, int supply_size, int collect_size,
103 const struct regset *regset, const char *human_name, void *cb_data);
5aa82d05 104
c5ac5cbb
AH
105/* For a function call, does the function return a value using a
106 normal value return or a structure return - passing a hidden
107 argument pointing to storage. For the latter, there are two
108 cases: language-mandated structure return and target ABI
109 structure return. */
110
111enum function_call_return_method
112{
113 /* Standard value return. */
114 return_method_normal = 0,
115
116 /* Language ABI structure return. This is handled
117 by passing the return location as the first parameter to
118 the function, even preceding "this". */
119 return_method_hidden_param,
120
121 /* Target ABI struct return. This is target-specific; for instance,
122 on ia64 the first argument is passed in out0 but the hidden
123 structure return pointer would normally be passed in r8. */
124 return_method_struct,
125};
126
c193949e
LM
127enum class memtag_type
128{
129 /* Logical tag, the tag that is stored in unused bits of a pointer to a
130 virtual address. */
131 logical = 0,
132
133 /* Allocation tag, the tag that is associated with every granule of memory in
134 the physical address space. Allocation tags are used to validate memory
135 accesses via pointers containing logical tags. */
136 allocation,
137};
138
aa95b2d4
AM
139/* Callback types for 'read_core_file_mappings' gdbarch method. */
140
141using read_core_file_mappings_pre_loop_ftype =
142 gdb::function_view<void (ULONGEST count)>;
143
144using read_core_file_mappings_loop_ftype =
145 gdb::function_view<void (int num,
146 ULONGEST start,
147 ULONGEST end,
148 ULONGEST file_ofs,
149 const char *filename,
150 const bfd_build_id *build_id)>;
c5ac5cbb 151
7807dfae
TT
152/* Possible values for gdbarch_call_dummy_location. */
153enum call_dummy_location_type
154{
155 ON_STACK,
156 AT_ENTRY_POINT,
157};
158
2b7c3f1d 159#include "gdbarch-gen.h"
7e183d27 160
08106042 161/* An internal function that should _only_ be called from gdbarch_tdep.
ab25d9bb 162 Returns the gdbarch_tdep_base field held within GDBARCH. */
0f71a2f6 163
ab25d9bb 164extern struct gdbarch_tdep_base *gdbarch_tdep_1 (struct gdbarch *gdbarch);
08106042 165
ab25d9bb
AB
166/* Return the gdbarch_tdep_base object held within GDBARCH cast to the type
167 TDepType, which should be a sub-class of gdbarch_tdep_base.
168
169 When GDB is compiled in maintainer mode a run-time check is performed
170 that the gdbarch_tdep_base within GDBARCH really is of type TDepType.
171 When GDB is compiled in release mode the run-time check is not
172 performed, and we assume the caller knows what they are doing. */
08106042
AB
173
174template<typename TDepType>
175static inline TDepType *
176gdbarch_tdep (struct gdbarch *gdbarch)
177{
ab25d9bb 178 struct gdbarch_tdep_base *tdep = gdbarch_tdep_1 (gdbarch);
c44885db 179 return gdb::checked_static_cast<TDepType *> (tdep);
08106042 180}
0f71a2f6
JM
181
182/* Mechanism for co-ordinating the selection of a specific
183 architecture.
184
185 GDB targets (*-tdep.c) can register an interest in a specific
186 architecture. Other GDB components can register a need to maintain
187 per-architecture data.
188
189 The mechanisms below ensures that there is only a loose connection
190 between the set-architecture command and the various GDB
99e7bb18 191 components. Each component can independently register their need
0f71a2f6
JM
192 to maintain architecture specific data with gdbarch.
193
194 Pragmatics:
195
196 Previously, a single TARGET_ARCHITECTURE_HOOK was provided. It
197 didn't scale.
198
199 The more traditional mega-struct containing architecture specific
200 data for all the various GDB components was also considered. Since
99e7bb18 201 GDB is built from a variable number of (fairly independent)
0f71a2f6 202 components it was determined that the global aproach was not
0963b4bd 203 applicable. */
0f71a2f6
JM
204
205
206/* Register a new architectural family with GDB.
207
208 Register support for the specified ARCHITECTURE with GDB. When
209 gdbarch determines that the specified architecture has been
210 selected, the corresponding INIT function is called.
211
212 --
213
214 The INIT function takes two parameters: INFO which contains the
215 information available to gdbarch about the (possibly new)
216 architecture; ARCHES which is a list of the previously created
217 ``struct gdbarch'' for this architecture.
218
0f79675b 219 The INFO parameter is, as far as possible, be pre-initialized with
7a107747 220 information obtained from INFO.ABFD or the global defaults.
0f79675b
AC
221
222 The ARCHES parameter is a linked list (sorted most recently used)
223 of all the previously created architures for this architecture
224 family. The (possibly NULL) ARCHES->gdbarch can used to access
225 values from the previously selected architecture for this
59837fe0 226 architecture family.
0f71a2f6
JM
227
228 The INIT function shall return any of: NULL - indicating that it
ec3d358c 229 doesn't recognize the selected architecture; an existing ``struct
0f71a2f6
JM
230 gdbarch'' from the ARCHES list - indicating that the new
231 architecture is just a synonym for an earlier architecture (see
232 gdbarch_list_lookup_by_info()); a newly created ``struct gdbarch''
4b9b3959
AC
233 - that describes the selected architecture (see gdbarch_alloc()).
234
235 The DUMP_TDEP function shall print out all target specific values.
236 Care should be taken to ensure that the function works in both the
0963b4bd 237 multi-arch and non- multi-arch cases. */
0f71a2f6 238
adf40b2e
JM
239struct gdbarch_list
240{
241 struct gdbarch *gdbarch;
242 struct gdbarch_list *next;
243};
0f71a2f6 244
adf40b2e
JM
245struct gdbarch_info
246{
b447dd03
SM
247 gdbarch_info ()
248 /* Ensure the union is zero-initialized. Relies on the fact that there's
249 no member larger than TDESC_DATA. */
250 : tdesc_data ()
251 {}
0f71a2f6 252
b447dd03 253 const struct bfd_arch_info *bfd_arch_info = nullptr;
0f71a2f6 254
b447dd03 255 enum bfd_endian byte_order = BFD_ENDIAN_UNKNOWN;
9d4fde75 256
b447dd03
SM
257 enum bfd_endian byte_order_for_code = BFD_ENDIAN_UNKNOWN;
258
259 bfd *abfd = nullptr;
0f71a2f6 260
4f3681cc
TJB
261 /* Architecture-specific target description data. */
262 struct tdesc_arch_data *tdesc_data;
4be87837 263
b447dd03 264 enum gdb_osabi osabi = GDB_OSABI_UNKNOWN;
424163ea 265
b447dd03 266 const struct target_desc *target_desc = nullptr;
adf40b2e 267};
0f71a2f6 268
104c1213 269typedef struct gdbarch *(gdbarch_init_ftype) (struct gdbarch_info info, struct gdbarch_list *arches);
4b9b3959 270typedef void (gdbarch_dump_tdep_ftype) (struct gdbarch *gdbarch, struct ui_file *file);
0f71a2f6 271
4b9b3959 272extern void gdbarch_register (enum bfd_architecture architecture,
ec29a63c
TT
273 gdbarch_init_ftype *init,
274 gdbarch_dump_tdep_ftype *dump_tdep = nullptr);
4b9b3959 275
0f71a2f6 276
9b1f59fc
SM
277/* Return a vector of the valid architecture names. Since architectures are
278 registered during the _initialize phase this function only returns useful
279 information once initialization has been completed. */
b4a20239 280
9b1f59fc 281extern std::vector<const char *> gdbarch_printable_names ();
b4a20239
AC
282
283
0f71a2f6 284/* Helper function. Search the list of ARCHES for a GDBARCH that
0963b4bd 285 matches the information provided by INFO. */
0f71a2f6 286
424163ea 287extern struct gdbarch_list *gdbarch_list_lookup_by_info (struct gdbarch_list *arches, const struct gdbarch_info *info);
0f71a2f6
JM
288
289
290/* Helper function. Create a preliminary ``struct gdbarch''. Perform
424163ea 291 basic initialization using values obtained from the INFO and TDEP
0f71a2f6 292 parameters. set_gdbarch_*() functions are called to complete the
0963b4bd 293 initialization of the object. */
0f71a2f6 294
ab25d9bb 295extern struct gdbarch *gdbarch_alloc (const struct gdbarch_info *info, struct gdbarch_tdep_base *tdep);
0f71a2f6
JM
296
297
4b9b3959
AC
298/* Helper function. Free a partially-constructed ``struct gdbarch''.
299 It is assumed that the caller freeds the ``struct
0963b4bd 300 gdbarch_tdep''. */
4b9b3959 301
058f20d5
JB
302extern void gdbarch_free (struct gdbarch *);
303
284a0e3c
SM
304/* Get the obstack owned by ARCH. */
305
306extern obstack *gdbarch_obstack (gdbarch *arch);
058f20d5 307
aebd7893
AC
308/* Helper function. Allocate memory from the ``struct gdbarch''
309 obstack. The memory is freed when the corresponding architecture
310 is also freed. */
311
284a0e3c
SM
312#define GDBARCH_OBSTACK_CALLOC(GDBARCH, NR, TYPE) obstack_calloc<TYPE> (gdbarch_obstack ((GDBARCH)), (NR))
313
314#define GDBARCH_OBSTACK_ZALLOC(GDBARCH, TYPE) obstack_zalloc<TYPE> (gdbarch_obstack ((GDBARCH)))
aebd7893 315
6c214e7c
PP
316/* Duplicate STRING, returning an equivalent string that's allocated on the
317 obstack associated with GDBARCH. The string is freed when the corresponding
318 architecture is also freed. */
319
320extern char *gdbarch_obstack_strdup (struct gdbarch *arch, const char *string);
aebd7893 321
0963b4bd 322/* Helper function. Force an update of the current architecture.
0f71a2f6 323
b732d07d
AC
324 The actual architecture selected is determined by INFO, ``(gdb) set
325 architecture'' et.al., the existing architecture and BFD's default
326 architecture. INFO should be initialized to zero and then selected
327 fields should be updated.
0f71a2f6 328
0963b4bd 329 Returns non-zero if the update succeeds. */
16f33e29
AC
330
331extern int gdbarch_update_p (struct gdbarch_info info);
0f71a2f6
JM
332
333
ebdba546
AC
334/* Helper function. Find an architecture matching info.
335
b447dd03
SM
336 INFO should have relevant fields set, and then finished using
337 gdbarch_info_fill.
ebdba546
AC
338
339 Returns the corresponding architecture, or NULL if no matching
59837fe0 340 architecture was found. */
ebdba546
AC
341
342extern struct gdbarch *gdbarch_find_by_info (struct gdbarch_info info);
343
344
aff68abb 345/* Helper function. Set the target gdbarch to "gdbarch". */
ebdba546 346
aff68abb 347extern void set_target_gdbarch (struct gdbarch *gdbarch);
ebdba546 348
0f71a2f6 349
cb275538
TT
350/* A registry adaptor for gdbarch. This arranges to store the
351 registry in the gdbarch. */
352template<>
353struct registry_accessor<gdbarch>
354{
355 static registry<gdbarch> *get (gdbarch *arch);
356};
0f71a2f6 357
99e7bb18 358/* Set the dynamic target-system-dependent parameters (architecture,
0963b4bd 359 byte-order, ...) using information found in the BFD. */
c906108c 360
104c1213 361extern void set_gdbarch_from_file (bfd *);
c906108c
SS
362
363
e514a9d6
JM
364/* Initialize the current architecture to the "first" one we find on
365 our list. */
366
367extern void initialize_current_architecture (void);
368
c906108c 369/* gdbarch trace variable */
ccce17b0 370extern unsigned int gdbarch_debug;
c906108c 371
4b9b3959 372extern void gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file);
0f71a2f6 373
f6efe3f8
SM
374/* Return the number of cooked registers (raw + pseudo) for ARCH. */
375
376static inline int
377gdbarch_num_cooked_regs (gdbarch *arch)
378{
379 return gdbarch_num_regs (arch) + gdbarch_num_pseudo_regs (arch);
380}
381
c906108c 382#endif