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