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