Add translations for various sub-directories
[binutils-gdb.git] / gdb / arch-utils.h
blobd27cc1dbc06d9f68f3d438662d3c4deeced9c37b
1 /* Dynamic architecture support for GDB, the GNU debugger.
3 Copyright (C) 1998-2024 Free Software Foundation, Inc.
5 This file is part of GDB.
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.
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.
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/>. */
20 #ifndef GDB_ARCH_UTILS_H
21 #define GDB_ARCH_UTILS_H
23 #include "gdbarch.h"
24 #include "gdbsupport/environ.h"
25 #include "filenames.h"
27 class frame_info_ptr;
28 struct minimal_symbol;
29 struct type;
30 struct gdbarch_info;
31 struct dwarf2_frame_state;
33 template <size_t bp_size, const gdb_byte *break_insn>
34 struct bp_manipulation
36 static int
37 kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
39 return bp_size;
42 static const gdb_byte *
43 bp_from_kind (struct gdbarch *gdbarch, int kind, int *size)
45 *size = kind;
46 return break_insn;
50 template <size_t bp_size,
51 const gdb_byte *break_insn_little,
52 const gdb_byte *break_insn_big>
53 struct bp_manipulation_endian
55 static int
56 kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
58 return bp_size;
61 static const gdb_byte *
62 bp_from_kind (struct gdbarch *gdbarch, int kind, int *size)
64 *size = kind;
65 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
66 return break_insn_big;
67 else
68 return break_insn_little;
72 #define BP_MANIPULATION(BREAK_INSN) \
73 bp_manipulation<sizeof (BREAK_INSN), BREAK_INSN>
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>
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. */
85 struct core_file_exec_context
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
91 empty context object.
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. */
96 core_file_exec_context (gdb::unique_xmalloc_ptr<char> exec_name,
97 gdb::unique_xmalloc_ptr<char> exec_filename,
98 std::vector<gdb::unique_xmalloc_ptr<char>> argv,
99 std::vector<gdb::unique_xmalloc_ptr<char>> envp)
100 : m_exec_name (std::move (exec_name)),
101 m_exec_filename (std::move (exec_filename)),
102 m_arguments (std::move (argv)),
103 m_environment (std::move (envp))
105 gdb_assert (m_exec_name != nullptr);
106 gdb_assert (exec_filename == nullptr
107 || IS_ABSOLUTE_PATH (exec_filename.get ()));
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;
115 /* Return true if this object contains valid context information. */
116 bool valid () const
117 { return m_exec_name != nullptr; }
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 (); }
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 (); }
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; }
137 /* Return the environment variables from this context. */
138 gdb_environ environment () const;
140 private:
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;
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;
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;
157 /* List of environment strings. */
158 std::vector<gdb::unique_xmalloc_ptr<char>> m_environment;
161 /* Default implementation of gdbarch_displaced_hw_singlestep. */
162 extern bool default_displaced_step_hw_singlestep (struct gdbarch *);
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. */
167 extern CORE_ADDR displaced_step_at_entry_point (struct gdbarch *gdbarch);
169 /* The only possible cases for inner_than. */
170 extern bool core_addr_lessthan (CORE_ADDR lhs, CORE_ADDR rhs);
171 extern bool core_addr_greaterthan (CORE_ADDR lhs, CORE_ADDR rhs);
173 /* Identity functions on a CORE_ADDR. Just return the "addr". */
175 extern CORE_ADDR core_addr_identity (struct gdbarch *gdbarch, CORE_ADDR addr);
176 extern gdbarch_convert_from_func_ptr_addr_ftype convert_from_func_ptr_addr_identity;
178 /* No-op conversion of reg to regnum. */
180 extern int no_op_reg_to_regnum (struct gdbarch *gdbarch, int reg);
182 /* Do nothing version of coff_make_msymbol_special. */
184 void default_coff_make_msymbol_special (int val, struct minimal_symbol *msym);
186 /* Do nothing default implementation of gdbarch_make_symbol_special. */
188 void default_make_symbol_special (struct symbol *sym, struct objfile *objfile);
190 /* Do nothing default implementation of gdbarch_adjust_dwarf2_addr. */
192 CORE_ADDR default_adjust_dwarf2_addr (CORE_ADDR pc);
194 /* Do nothing default implementation of gdbarch_adjust_dwarf2_line. */
196 CORE_ADDR default_adjust_dwarf2_line (CORE_ADDR addr, int rel);
198 /* Default DWARF vendor CFI handler. */
200 bool default_execute_dwarf_cfa_vendor_op (struct gdbarch *gdbarch, gdb_byte op,
201 struct dwarf2_frame_state *fs);
203 /* Version of cannot_fetch_register() / cannot_store_register() that
204 always fails. */
206 int cannot_register_not (struct gdbarch *gdbarch, int regnum);
208 /* Legacy version of target_virtual_frame_pointer(). Assumes that
209 there is an gdbarch_deprecated_fp_regnum and that it is the same, cooked or
210 raw. */
212 extern gdbarch_virtual_frame_pointer_ftype legacy_virtual_frame_pointer;
214 /* Default implementation of gdbarch_floatformat_for_type. */
215 extern const struct floatformat **
216 default_floatformat_for_type (struct gdbarch *gdbarch,
217 const char *name, int len);
219 /* Default implementation of gdbarch_remove_non_address_bits. */
220 CORE_ADDR default_remove_non_address_bits (struct gdbarch *gdbarch,
221 CORE_ADDR pointer);
223 /* Default implementation of gdbarch_memtag_to_string. */
224 extern std::string default_memtag_to_string (struct gdbarch *gdbarch,
225 struct value *tag);
227 /* Default implementation of gdbarch_tagged_address_p. */
228 bool default_tagged_address_p (struct gdbarch *gdbarch, CORE_ADDR address);
230 /* Default implementation of gdbarch_memtag_matches_p. */
231 extern bool default_memtag_matches_p (struct gdbarch *gdbarch,
232 struct value *address);
234 /* Default implementation of gdbarch_set_memtags. */
235 bool default_set_memtags (struct gdbarch *gdbarch,
236 struct value *address, size_t length,
237 const gdb::byte_vector &tags,
238 memtag_type tag_type);
240 /* Default implementation of gdbarch_get_memtag. */
241 struct value *default_get_memtag (struct gdbarch *gdbarch,
242 struct value *address,
243 memtag_type tag_type);
245 extern CORE_ADDR generic_skip_trampoline_code (const frame_info_ptr &frame,
246 CORE_ADDR pc);
248 extern CORE_ADDR generic_skip_solib_resolver (struct gdbarch *gdbarch,
249 CORE_ADDR pc);
251 extern int generic_in_solib_return_trampoline (struct gdbarch *gdbarch,
252 CORE_ADDR pc, const char *name);
254 extern int generic_stack_frame_destroyed_p (struct gdbarch *gdbarch,
255 CORE_ADDR pc);
257 extern int default_code_of_frame_writable (struct gdbarch *gdbarch,
258 const frame_info_ptr &frame);
260 /* By default, registers are not convertible. */
261 extern int generic_convert_register_p (struct gdbarch *gdbarch, int regnum,
262 struct type *type);
264 extern int default_stabs_argument_has_addr (struct gdbarch *gdbarch,
265 struct type *type);
267 extern int generic_instruction_nullified (struct gdbarch *gdbarch,
268 struct regcache *regcache);
270 int default_remote_register_number (struct gdbarch *gdbarch,
271 int regno);
273 /* For compatibility with older architectures, returns
274 (LEGACY_SIM_REGNO_IGNORE) when the register doesn't have a valid
275 name. */
277 extern int legacy_register_sim_regno (struct gdbarch *gdbarch, int regnum);
279 /* Return the selected byte order, or BFD_ENDIAN_UNKNOWN if no byte
280 order was explicitly selected. */
281 extern enum bfd_endian selected_byte_order (void);
283 /* Return the selected architecture's name, or NULL if no architecture
284 was explicitly selected. */
285 extern const char *selected_architecture_name (void);
287 /* Similar to init, but this time fill in the blanks. Information is
288 obtained from the global "set ..." options and explicitly
289 initialized INFO fields. */
290 extern void gdbarch_info_fill (struct gdbarch_info *info);
292 /* Return the architecture for ABFD. If no suitable architecture
293 could be find, return NULL. */
295 extern struct gdbarch *gdbarch_from_bfd (bfd *abfd);
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.
301 This function should normally be called solely by the command interpreter
302 routines to determine the architecture to execute a command in. */
303 extern struct gdbarch *get_current_arch (void);
305 extern int default_has_shared_address_space (struct gdbarch *);
307 extern int default_fast_tracepoint_valid_at (struct gdbarch *gdbarch,
308 CORE_ADDR addr, std::string *msg);
310 extern const gdb_byte *default_breakpoint_from_pc (struct gdbarch *gdbarch,
311 CORE_ADDR *pcptr,
312 int *lenptr);
314 extern int default_breakpoint_kind_from_current_state (struct gdbarch *gdbarch,
315 struct regcache *regcache,
316 CORE_ADDR *pcptr);
318 extern void default_gen_return_address (struct gdbarch *gdbarch,
319 struct agent_expr *ax,
320 struct axs_value *value,
321 CORE_ADDR scope);
323 extern const char *default_auto_charset (void);
324 extern const char *default_auto_wide_charset (void);
326 extern int default_return_in_first_hidden_param_p (struct gdbarch *,
327 struct type *);
329 extern int default_insn_is_call (struct gdbarch *, CORE_ADDR);
330 extern int default_insn_is_ret (struct gdbarch *, CORE_ADDR);
331 extern int default_insn_is_jump (struct gdbarch *, CORE_ADDR);
333 /* Default implementation of gdbarch_program_breakpoint_here_p. */
334 extern bool default_program_breakpoint_here_p (struct gdbarch *gdbarch,
335 CORE_ADDR addr);
337 /* Do-nothing version of vsyscall_range. Returns false. */
339 extern int default_vsyscall_range (struct gdbarch *gdbarch, struct mem_range *range);
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. */
346 extern void default_skip_permanent_breakpoint (struct regcache *regcache);
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. */
354 extern CORE_ADDR default_infcall_mmap (CORE_ADDR size, unsigned prot);
355 extern void default_infcall_munmap (CORE_ADDR addr, CORE_ADDR size);
356 extern std::string default_gcc_target_options (struct gdbarch *gdbarch);
357 extern const char *default_gnu_triplet_regexp (struct gdbarch *gdbarch);
358 extern int default_addressable_memory_unit_size (struct gdbarch *gdbarch);
360 extern void default_guess_tracepoint_registers (struct gdbarch *gdbarch,
361 struct regcache *regcache,
362 CORE_ADDR addr);
364 extern int default_print_insn (bfd_vma memaddr, disassemble_info *info);
366 /* Wrapper to gdbarch_skip_prologue, but doesn't throw exception. Catch
367 exception thrown from gdbarch_skip_prologue, and return PC. */
369 extern CORE_ADDR gdbarch_skip_prologue_noexcept (gdbarch *gdbarch,
370 CORE_ADDR pc) noexcept;
372 /* Default implementation of gdbarch_in_indirect_branch_thunk that returns
373 false. */
374 extern bool default_in_indirect_branch_thunk (gdbarch *gdbarch,
375 CORE_ADDR pc);
377 /* Default implementation of gdbarch type_align method. */
378 extern ULONGEST default_type_align (struct gdbarch *gdbarch,
379 struct type *type);
381 /* Default implementation of gdbarch get_pc_address_flags method. */
382 extern std::string default_get_pc_address_flags (const frame_info_ptr &frame,
383 CORE_ADDR pc);
385 /* Default implementation of gdbarch read_core_file_mappings method. */
386 extern 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);
392 /* Default implementation of gdbarch_core_parse_exec_context. Returns
393 an empty core_file_exec_context. */
394 extern core_file_exec_context default_core_parse_exec_context
395 (struct gdbarch *gdbarch, bfd *cbfd);
397 /* Default implementation of gdbarch
398 use_target_description_from_corefile_notes. */
399 extern bool default_use_target_description_from_corefile_notes
400 (struct gdbarch *gdbarch,
401 struct bfd *corefile_bfd);
403 /* Default implementation of gdbarch default_get_return_buf_addr method. */
404 extern CORE_ADDR default_get_return_buf_addr (struct type *val_typegdbarch,
405 const frame_info_ptr &cur_frame);
407 /* Default implementation of gdbarch default_dwarf2_omit_typedef_p method. */
408 extern bool default_dwarf2_omit_typedef_p (struct type *target_type,
409 const char *producer,
410 const char *name);
412 extern 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);
417 #endif /* GDB_ARCH_UTILS_H */