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