]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/arch-utils.h
ld/aarch64elf: add support for DT_AARCH64_MEMTAG_STACK dynamic tag
[thirdparty/binutils-gdb.git] / gdb / arch-utils.h
CommitLineData
c0e8c252 1/* Dynamic architecture support for GDB, the GNU debugger.
d7bd68ca 2
d01e8234 3 Copyright (C) 1998-2025 Free Software Foundation, Inc.
c0e8c252
AC
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
a9762ec7 9 the Free Software Foundation; either version 3 of the License, or
c0e8c252
AC
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
a9762ec7 18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
c0e8c252 19
cc709640
TT
20#ifndef GDB_ARCH_UTILS_H
21#define GDB_ARCH_UTILS_H
c0e8c252 22
0d12e84c 23#include "gdbarch.h"
60045671 24#include "gdbsupport/environ.h"
44a61f1b 25#include "filenames.h"
0d12e84c 26
bd2b40ac 27class frame_info_ptr;
da3331ec
AC
28struct minimal_symbol;
29struct type;
30struct gdbarch_info;
b41c5a85 31struct dwarf2_frame_state;
da3331ec 32
04180708
YQ
33template <size_t bp_size, const gdb_byte *break_insn>
34struct bp_manipulation
35{
36 static int
37 kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
38 {
39 return bp_size;
22f13eb8 40 }
598cc9dc 41
04180708
YQ
42 static const gdb_byte *
43 bp_from_kind (struct gdbarch *gdbarch, int kind, int *size)
44 {
45 *size = kind;
46 return break_insn;
22f13eb8 47 }
04180708
YQ
48};
49
50template <size_t bp_size,
51 const gdb_byte *break_insn_little,
52 const gdb_byte *break_insn_big>
53struct bp_manipulation_endian
54{
55 static int
56 kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
57 {
58 return bp_size;
59 }
60
61 static const gdb_byte *
62 bp_from_kind (struct gdbarch *gdbarch, int kind, int *size)
63 {
64 *size = kind;
65 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
66 return break_insn_big;
67 else
68 return break_insn_little;
69 }
70};
71
72#define BP_MANIPULATION(BREAK_INSN) \
73 bp_manipulation<sizeof (BREAK_INSN), BREAK_INSN>
74
75#define BP_MANIPULATION_ENDIAN(BREAK_INSN_LITTLE, BREAK_INSN_BIG) \
76 bp_manipulation_endian<sizeof (BREAK_INSN_LITTLE), \
77 BREAK_INSN_LITTLE, BREAK_INSN_BIG>
d19280ad 78
d3d13bf8
AB
79/* Structure returned from gdbarch core_parse_exec_context method. Wraps
80 the execfn string and a vector containing the inferior argument. If a
81 gdbarch is unable to parse this information then an empty structure is
82 returned, check the execfn as an indication, if this is nullptr then no
83 other fields should be considered valid. */
84
85struct core_file_exec_context
86{
87 /* Constructor, just move everything into place. The EXEC_NAME should
88 never be nullptr. Only call this constructor if all the arguments
89 have been collected successfully, i.e. if the EXEC_NAME could be
90 found but not ARGV then use the no-argument constructor to create an
44a61f1b
AB
91 empty context object.
92
93 The EXEC_FILENAME must be the absolute filename of the executable
94 that generated this core file, or nullptr if the absolute filename
95 is not known. */
d3d13bf8 96 core_file_exec_context (gdb::unique_xmalloc_ptr<char> exec_name,
44a61f1b 97 gdb::unique_xmalloc_ptr<char> exec_filename,
60045671
AB
98 std::vector<gdb::unique_xmalloc_ptr<char>> argv,
99 std::vector<gdb::unique_xmalloc_ptr<char>> envp)
d3d13bf8 100 : m_exec_name (std::move (exec_name)),
44a61f1b 101 m_exec_filename (std::move (exec_filename)),
60045671
AB
102 m_arguments (std::move (argv)),
103 m_environment (std::move (envp))
d3d13bf8
AB
104 {
105 gdb_assert (m_exec_name != nullptr);
44a61f1b
AB
106 gdb_assert (exec_filename == nullptr
107 || IS_ABSOLUTE_PATH (exec_filename.get ()));
d3d13bf8
AB
108 }
109
110 /* Create a default context object. In its default state a context
111 object holds no useful information, and will return false from its
112 valid() method. */
113 core_file_exec_context () = default;
114
115 /* Return true if this object contains valid context information. */
116 bool valid () const
117 { return m_exec_name != nullptr; }
118
119 /* Return the execfn string (executable name) as extracted from the core
120 file. Will always return non-nullptr if valid() returns true. */
121 const char *execfn () const
122 { return m_exec_name.get (); }
123
44a61f1b
AB
124 /* Return the absolute path to the executable if known. This might
125 return nullptr even when execfn() returns a non-nullptr value.
126 Additionally, the file referenced here might have a different name
127 than the file returned by execfn if execfn is a symbolic link. */
128 const char *exec_filename () const
129 { return m_exec_filename.get (); }
130
d3d13bf8
AB
131 /* Return the vector of inferior arguments as extracted from the core
132 file. This does not include argv[0] (the executable name) for that
133 see the execfn() function. */
134 const std::vector<gdb::unique_xmalloc_ptr<char>> &args () const
135 { return m_arguments; }
136
60045671
AB
137 /* Return the environment variables from this context. */
138 gdb_environ environment () const;
139
d3d13bf8
AB
140private:
141
142 /* The executable filename as reported in the core file. Can be nullptr
143 if no executable name is found. */
144 gdb::unique_xmalloc_ptr<char> m_exec_name;
145
44a61f1b
AB
146 /* Full filename to the executable that was actually executed. The name
147 within EXEC_FILENAME might not match what the user typed, e.g. if the
148 user typed ./symlinked_name which is a symlink to /tmp/real_name then
149 this is going to contain '/tmp/realname' while EXEC_NAME above will
150 contain './symlinkedname'. */
151 gdb::unique_xmalloc_ptr<char> m_exec_filename;
152
d3d13bf8
AB
153 /* List of arguments. Doesn't include argv[0] which is the executable
154 name, for this look at m_exec_name field. */
155 std::vector<gdb::unique_xmalloc_ptr<char>> m_arguments;
60045671
AB
156
157 /* List of environment strings. */
158 std::vector<gdb::unique_xmalloc_ptr<char>> m_environment;
d3d13bf8
AB
159};
160
99e40580 161/* Default implementation of gdbarch_displaced_hw_singlestep. */
40a53766 162extern bool default_displaced_step_hw_singlestep (struct gdbarch *);
99e40580 163
237fc4c9
PA
164/* Possible value for gdbarch_displaced_step_location:
165 Place displaced instructions at the program's entry point,
166 leaving space for inferior function call return breakpoints. */
167extern CORE_ADDR displaced_step_at_entry_point (struct gdbarch *gdbarch);
168
0e2de366 169/* The only possible cases for inner_than. */
e14f6ec9
TT
170extern bool core_addr_lessthan (CORE_ADDR lhs, CORE_ADDR rhs);
171extern bool core_addr_greaterthan (CORE_ADDR lhs, CORE_ADDR rhs);
3339cf8b 172
e2d0e7eb 173/* Identity functions on a CORE_ADDR. Just return the "addr". */
f517ea4e 174
24568a2c 175extern CORE_ADDR core_addr_identity (struct gdbarch *gdbarch, CORE_ADDR addr);
e2d0e7eb 176extern gdbarch_convert_from_func_ptr_addr_ftype convert_from_func_ptr_addr_identity;
f517ea4e 177
0e2de366 178/* No-op conversion of reg to regnum. */
88c72b7d 179
d3f73121 180extern int no_op_reg_to_regnum (struct gdbarch *gdbarch, int reg);
88c72b7d 181
0e2de366 182/* Do nothing version of coff_make_msymbol_special. */
a2cf933a
EZ
183
184void default_coff_make_msymbol_special (int val, struct minimal_symbol *msym);
185
3e29f34a
MR
186/* Do nothing default implementation of gdbarch_make_symbol_special. */
187
188void default_make_symbol_special (struct symbol *sym, struct objfile *objfile);
189
190/* Do nothing default implementation of gdbarch_adjust_dwarf2_addr. */
191
192CORE_ADDR default_adjust_dwarf2_addr (CORE_ADDR pc);
193
194/* Do nothing default implementation of gdbarch_adjust_dwarf2_line. */
195
196CORE_ADDR default_adjust_dwarf2_line (CORE_ADDR addr, int rel);
197
b41c5a85
JW
198/* Default DWARF vendor CFI handler. */
199
200bool default_execute_dwarf_cfa_vendor_op (struct gdbarch *gdbarch, gdb_byte op,
201 struct dwarf2_frame_state *fs);
202
01fb7433 203/* Version of cannot_fetch_register() / cannot_store_register() that
0e2de366 204 always fails. */
01fb7433 205
64a3914f 206int cannot_register_not (struct gdbarch *gdbarch, int regnum);
01fb7433 207
39d4ef09 208/* Legacy version of target_virtual_frame_pointer(). Assumes that
064f5156 209 there is an gdbarch_deprecated_fp_regnum and that it is the same, cooked or
0ba6dca9 210 raw. */
39d4ef09
AC
211
212extern gdbarch_virtual_frame_pointer_ftype legacy_virtual_frame_pointer;
213
9b790ce7
UW
214/* Default implementation of gdbarch_floatformat_for_type. */
215extern const struct floatformat **
216 default_floatformat_for_type (struct gdbarch *gdbarch,
217 const char *name, int len);
218
d88cb738
LM
219/* Default implementation of gdbarch_remove_non_address_bits. */
220CORE_ADDR default_remove_non_address_bits (struct gdbarch *gdbarch,
221 CORE_ADDR pointer);
222
c193949e
LM
223/* Default implementation of gdbarch_memtag_to_string. */
224extern std::string default_memtag_to_string (struct gdbarch *gdbarch,
225 struct value *tag);
226
227/* Default implementation of gdbarch_tagged_address_p. */
7202f41f 228bool default_tagged_address_p (struct gdbarch *gdbarch, CORE_ADDR address);
c193949e
LM
229
230/* Default implementation of gdbarch_memtag_matches_p. */
231extern bool default_memtag_matches_p (struct gdbarch *gdbarch,
232 struct value *address);
233
234/* Default implementation of gdbarch_set_memtags. */
235bool default_set_memtags (struct gdbarch *gdbarch,
236 struct value *address, size_t length,
237 const gdb::byte_vector &tags,
238 memtag_type tag_type);
239
240/* Default implementation of gdbarch_get_memtag. */
241struct value *default_get_memtag (struct gdbarch *gdbarch,
242 struct value *address,
243 memtag_type tag_type);
244
8480a37e 245extern CORE_ADDR generic_skip_trampoline_code (const frame_info_ptr &frame,
52f729a7 246 CORE_ADDR pc);
bdcd319a 247
4c8c40e6
MK
248extern CORE_ADDR generic_skip_solib_resolver (struct gdbarch *gdbarch,
249 CORE_ADDR pc);
dea0c52f 250
e17a4113 251extern int generic_in_solib_return_trampoline (struct gdbarch *gdbarch,
2c02bd72 252 CORE_ADDR pc, const char *name);
d50355b6 253
c9cf6e20
MG
254extern int generic_stack_frame_destroyed_p (struct gdbarch *gdbarch,
255 CORE_ADDR pc);
c12260ac 256
7eb89530 257extern int default_code_of_frame_writable (struct gdbarch *gdbarch,
8480a37e 258 const frame_info_ptr &frame);
7eb89530 259
a1f4a1b6 260/* By default, registers are not convertible. */
76a8ddb9
UW
261extern int generic_convert_register_p (struct gdbarch *gdbarch, int regnum,
262 struct type *type);
13d01224 263
192cb3d4
MK
264extern int default_stabs_argument_has_addr (struct gdbarch *gdbarch,
265 struct type *type);
266
3ca64954
RC
267extern int generic_instruction_nullified (struct gdbarch *gdbarch,
268 struct regcache *regcache);
269
123dc839
DJ
270int default_remote_register_number (struct gdbarch *gdbarch,
271 int regno);
272
4182591f
AC
273/* For compatibility with older architectures, returns
274 (LEGACY_SIM_REGNO_IGNORE) when the register doesn't have a valid
275 name. */
276
e7faf938 277extern int legacy_register_sim_regno (struct gdbarch *gdbarch, int regnum);
4182591f 278
b6d373df
DJ
279/* Return the selected byte order, or BFD_ENDIAN_UNKNOWN if no byte
280 order was explicitly selected. */
281extern enum bfd_endian selected_byte_order (void);
282
a8cf2722
AC
283/* Return the selected architecture's name, or NULL if no architecture
284 was explicitly selected. */
285extern const char *selected_architecture_name (void);
286
100bcc3f 287/* Similar to init, but this time fill in the blanks. Information is
7a107747
DJ
288 obtained from the global "set ..." options and explicitly
289 initialized INFO fields. */
290extern void gdbarch_info_fill (struct gdbarch_info *info);
bf922ad9 291
2b026650
MK
292/* Return the architecture for ABFD. If no suitable architecture
293 could be find, return NULL. */
294
295extern struct gdbarch *gdbarch_from_bfd (bfd *abfd);
296
e17c207e
UW
297/* Return "current" architecture. If the target is running, this is the
298 architecture of the selected frame. Otherwise, the "current" architecture
299 defaults to the target architecture.
300
301 This function should normally be called solely by the command interpreter
302 routines to determine the architecture to execute a command in. */
303extern struct gdbarch *get_current_arch (void);
304
6c95b8df
PA
305extern int default_has_shared_address_space (struct gdbarch *);
306
7a697b8d 307extern int default_fast_tracepoint_valid_at (struct gdbarch *gdbarch,
281d762b 308 CORE_ADDR addr, std::string *msg);
7a697b8d 309
22f13eb8
YQ
310extern const gdb_byte *default_breakpoint_from_pc (struct gdbarch *gdbarch,
311 CORE_ADDR *pcptr,
312 int *lenptr);
313
833b7ab5
YQ
314extern int default_breakpoint_kind_from_current_state (struct gdbarch *gdbarch,
315 struct regcache *regcache,
316 CORE_ADDR *pcptr);
317
6710bf39
SS
318extern void default_gen_return_address (struct gdbarch *gdbarch,
319 struct agent_expr *ax,
320 struct axs_value *value,
321 CORE_ADDR scope);
322
f870a310
TT
323extern const char *default_auto_charset (void);
324extern const char *default_auto_wide_charset (void);
325
18648a37
YQ
326extern int default_return_in_first_hidden_param_p (struct gdbarch *,
327 struct type *);
c2170eef
MM
328
329extern int default_insn_is_call (struct gdbarch *, CORE_ADDR);
330extern int default_insn_is_ret (struct gdbarch *, CORE_ADDR);
331extern int default_insn_is_jump (struct gdbarch *, CORE_ADDR);
3437254d 332
5133a315
LM
333/* Default implementation of gdbarch_program_breakpoint_here_p. */
334extern bool default_program_breakpoint_here_p (struct gdbarch *gdbarch,
335 CORE_ADDR addr);
336
3437254d
PA
337/* Do-nothing version of vsyscall_range. Returns false. */
338
339extern int default_vsyscall_range (struct gdbarch *gdbarch, struct mem_range *range);
ae9bb220
PA
340
341/* Default way to advance the PC to the next instruction in order to
342 skip a permanent breakpoint. Increments the PC by the size of a
343 software breakpoint instruction, as determined with
344 gdbarch_breakpoint_from_pc. This matches how the breakpoints
345 module determines whether a breakpoint is permanent. */
346extern void default_skip_permanent_breakpoint (struct regcache *regcache);
347
f208eee0
JK
348/* Symbols for gdbarch_infcall_mmap; their Linux PROT_* system
349 definitions would be dependent on compilation host. */
350#define GDB_MMAP_PROT_READ 0x1 /* Page can be read. */
351#define GDB_MMAP_PROT_WRITE 0x2 /* Page can be written. */
352#define GDB_MMAP_PROT_EXEC 0x4 /* Page can be executed. */
353
354extern CORE_ADDR default_infcall_mmap (CORE_ADDR size, unsigned prot);
7f361056 355extern void default_infcall_munmap (CORE_ADDR addr, CORE_ADDR size);
953cff56 356extern std::string default_gcc_target_options (struct gdbarch *gdbarch);
ac04f72b 357extern const char *default_gnu_triplet_regexp (struct gdbarch *gdbarch);
3374165f 358extern int default_addressable_memory_unit_size (struct gdbarch *gdbarch);
f208eee0 359
5f034a78
MK
360extern void default_guess_tracepoint_registers (struct gdbarch *gdbarch,
361 struct regcache *regcache,
362 CORE_ADDR addr);
363
39503f82
YQ
364extern int default_print_insn (bfd_vma memaddr, disassemble_info *info);
365
46a62268
YQ
366/* Wrapper to gdbarch_skip_prologue, but doesn't throw exception. Catch
367 exception thrown from gdbarch_skip_prologue, and return PC. */
368
369extern CORE_ADDR gdbarch_skip_prologue_noexcept (gdbarch *gdbarch,
370 CORE_ADDR pc) noexcept;
371
1d509aa6
MM
372/* Default implementation of gdbarch_in_indirect_branch_thunk that returns
373 false. */
374extern bool default_in_indirect_branch_thunk (gdbarch *gdbarch,
375 CORE_ADDR pc);
376
2b4424c3
TT
377/* Default implementation of gdbarch type_align method. */
378extern ULONGEST default_type_align (struct gdbarch *gdbarch,
379 struct type *type);
380
aa7ca1bb 381/* Default implementation of gdbarch get_pc_address_flags method. */
8480a37e 382extern std::string default_get_pc_address_flags (const frame_info_ptr &frame,
aa7ca1bb
AH
383 CORE_ADDR pc);
384
7e183d27 385/* Default implementation of gdbarch read_core_file_mappings method. */
aa95b2d4
AM
386extern void default_read_core_file_mappings
387 (struct gdbarch *gdbarch,
388 struct bfd *cbfd,
389 read_core_file_mappings_pre_loop_ftype pre_loop_cb,
390 read_core_file_mappings_loop_ftype loop_cb);
a0eda3df 391
d3d13bf8
AB
392/* Default implementation of gdbarch_core_parse_exec_context. Returns
393 an empty core_file_exec_context. */
394extern core_file_exec_context default_core_parse_exec_context
395 (struct gdbarch *gdbarch, bfd *cbfd);
396
b93d537f
LM
397/* Default implementation of gdbarch
398 use_target_description_from_corefile_notes. */
399extern bool default_use_target_description_from_corefile_notes
400 (struct gdbarch *gdbarch,
401 struct bfd *corefile_bfd);
402
a0eda3df
CL
403/* Default implementation of gdbarch default_get_return_buf_addr method. */
404extern CORE_ADDR default_get_return_buf_addr (struct type *val_typegdbarch,
8480a37e 405 const frame_info_ptr &cur_frame);
4e1d2f58 406
33b5899f 407/* Default implementation of gdbarch default_dwarf2_omit_typedef_p method. */
c1a398a3
CL
408extern bool default_dwarf2_omit_typedef_p (struct type *target_type,
409 const char *producer,
410 const char *name);
411
4e1d2f58
TT
412extern enum return_value_convention default_gdbarch_return_value
413 (struct gdbarch *gdbarch, struct value *function, struct type *valtype,
414 struct regcache *regcache, struct value **read_value,
415 const gdb_byte *writebuf);
416
cc709640 417#endif /* GDB_ARCH_UTILS_H */