1a1ba9ba4Schristos /* Dynamic architecture support for GDB, the GNU debugger. 2a1ba9ba4Schristos 3*184b2d41Schristos Copyright (C) 1998-2020 Free Software Foundation, Inc. 4a1ba9ba4Schristos 5a1ba9ba4Schristos This file is part of GDB. 6a1ba9ba4Schristos 7a1ba9ba4Schristos This program is free software; you can redistribute it and/or modify 8a1ba9ba4Schristos it under the terms of the GNU General Public License as published by 9a1ba9ba4Schristos the Free Software Foundation; either version 3 of the License, or 10a1ba9ba4Schristos (at your option) any later version. 11a1ba9ba4Schristos 12a1ba9ba4Schristos This program is distributed in the hope that it will be useful, 13a1ba9ba4Schristos but WITHOUT ANY WARRANTY; without even the implied warranty of 14a1ba9ba4Schristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15a1ba9ba4Schristos GNU General Public License for more details. 16a1ba9ba4Schristos 17a1ba9ba4Schristos You should have received a copy of the GNU General Public License 18a1ba9ba4Schristos along with this program. If not, see <http://www.gnu.org/licenses/>. */ 19a1ba9ba4Schristos 20051580eeSchristos #ifndef ARCH_UTILS_H 21051580eeSchristos #define ARCH_UTILS_H 22a1ba9ba4Schristos 23*184b2d41Schristos #include "gdbarch.h" 24*184b2d41Schristos 25a1ba9ba4Schristos struct frame_info; 26a1ba9ba4Schristos struct minimal_symbol; 27a1ba9ba4Schristos struct type; 28a1ba9ba4Schristos struct gdbarch_info; 29051580eeSchristos struct dwarf2_frame_state; 30a1ba9ba4Schristos 3115d8e94aSchristos template <size_t bp_size, const gdb_byte *break_insn> 3215d8e94aSchristos struct bp_manipulation 3315d8e94aSchristos { 3415d8e94aSchristos static int kind_from_pcbp_manipulation3515d8e94aSchristos kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr) 3615d8e94aSchristos { 3715d8e94aSchristos return bp_size; 3815d8e94aSchristos } 3915d8e94aSchristos 4015d8e94aSchristos static const gdb_byte * bp_from_kindbp_manipulation4115d8e94aSchristos bp_from_kind (struct gdbarch *gdbarch, int kind, int *size) 4215d8e94aSchristos { 4315d8e94aSchristos *size = kind; 4415d8e94aSchristos return break_insn; 4515d8e94aSchristos } 4615d8e94aSchristos }; 4715d8e94aSchristos 4815d8e94aSchristos template <size_t bp_size, 4915d8e94aSchristos const gdb_byte *break_insn_little, 5015d8e94aSchristos const gdb_byte *break_insn_big> 5115d8e94aSchristos struct bp_manipulation_endian 5215d8e94aSchristos { 5315d8e94aSchristos static int kind_from_pcbp_manipulation_endian5415d8e94aSchristos kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr) 5515d8e94aSchristos { 5615d8e94aSchristos return bp_size; 5715d8e94aSchristos } 5815d8e94aSchristos 5915d8e94aSchristos static const gdb_byte * bp_from_kindbp_manipulation_endian6015d8e94aSchristos bp_from_kind (struct gdbarch *gdbarch, int kind, int *size) 6115d8e94aSchristos { 6215d8e94aSchristos *size = kind; 6315d8e94aSchristos if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) 6415d8e94aSchristos return break_insn_big; 6515d8e94aSchristos else 6615d8e94aSchristos return break_insn_little; 6715d8e94aSchristos } 6815d8e94aSchristos }; 6915d8e94aSchristos 7015d8e94aSchristos #define BP_MANIPULATION(BREAK_INSN) \ 7115d8e94aSchristos bp_manipulation<sizeof (BREAK_INSN), BREAK_INSN> 7215d8e94aSchristos 7315d8e94aSchristos #define BP_MANIPULATION_ENDIAN(BREAK_INSN_LITTLE, BREAK_INSN_BIG) \ 7415d8e94aSchristos bp_manipulation_endian<sizeof (BREAK_INSN_LITTLE), \ 7515d8e94aSchristos BREAK_INSN_LITTLE, BREAK_INSN_BIG> 7615d8e94aSchristos 77a1ba9ba4Schristos /* Default implementation of gdbarch_displaced_hw_singlestep. */ 78a1ba9ba4Schristos extern int 79a1ba9ba4Schristos default_displaced_step_hw_singlestep (struct gdbarch *, 80a1ba9ba4Schristos struct displaced_step_closure *); 81a1ba9ba4Schristos 82a1ba9ba4Schristos /* Possible value for gdbarch_displaced_step_location: 83a1ba9ba4Schristos Place displaced instructions at the program's entry point, 84a1ba9ba4Schristos leaving space for inferior function call return breakpoints. */ 85a1ba9ba4Schristos extern CORE_ADDR displaced_step_at_entry_point (struct gdbarch *gdbarch); 86a1ba9ba4Schristos 87a1ba9ba4Schristos /* The only possible cases for inner_than. */ 88a1ba9ba4Schristos extern int core_addr_lessthan (CORE_ADDR lhs, CORE_ADDR rhs); 89a1ba9ba4Schristos extern int core_addr_greaterthan (CORE_ADDR lhs, CORE_ADDR rhs); 90a1ba9ba4Schristos 91a1ba9ba4Schristos /* Identity functions on a CORE_ADDR. Just return the "addr". */ 92a1ba9ba4Schristos 93a1ba9ba4Schristos extern CORE_ADDR core_addr_identity (struct gdbarch *gdbarch, CORE_ADDR addr); 94a1ba9ba4Schristos extern gdbarch_convert_from_func_ptr_addr_ftype convert_from_func_ptr_addr_identity; 95a1ba9ba4Schristos 96a1ba9ba4Schristos /* No-op conversion of reg to regnum. */ 97a1ba9ba4Schristos 98a1ba9ba4Schristos extern int no_op_reg_to_regnum (struct gdbarch *gdbarch, int reg); 99a1ba9ba4Schristos 100a1ba9ba4Schristos /* Do nothing version of coff_make_msymbol_special. */ 101a1ba9ba4Schristos 102a1ba9ba4Schristos void default_coff_make_msymbol_special (int val, struct minimal_symbol *msym); 103a1ba9ba4Schristos 104a1ba9ba4Schristos /* Do nothing default implementation of gdbarch_make_symbol_special. */ 105a1ba9ba4Schristos 106a1ba9ba4Schristos void default_make_symbol_special (struct symbol *sym, struct objfile *objfile); 107a1ba9ba4Schristos 108a1ba9ba4Schristos /* Do nothing default implementation of gdbarch_adjust_dwarf2_addr. */ 109a1ba9ba4Schristos 110a1ba9ba4Schristos CORE_ADDR default_adjust_dwarf2_addr (CORE_ADDR pc); 111a1ba9ba4Schristos 112a1ba9ba4Schristos /* Do nothing default implementation of gdbarch_adjust_dwarf2_line. */ 113a1ba9ba4Schristos 114a1ba9ba4Schristos CORE_ADDR default_adjust_dwarf2_line (CORE_ADDR addr, int rel); 115a1ba9ba4Schristos 116051580eeSchristos /* Default DWARF vendor CFI handler. */ 117051580eeSchristos 118051580eeSchristos bool default_execute_dwarf_cfa_vendor_op (struct gdbarch *gdbarch, gdb_byte op, 119051580eeSchristos struct dwarf2_frame_state *fs); 120051580eeSchristos 121a1ba9ba4Schristos /* Version of cannot_fetch_register() / cannot_store_register() that 122a1ba9ba4Schristos always fails. */ 123a1ba9ba4Schristos 124a1ba9ba4Schristos int cannot_register_not (struct gdbarch *gdbarch, int regnum); 125a1ba9ba4Schristos 126a1ba9ba4Schristos /* Legacy version of target_virtual_frame_pointer(). Assumes that 127a1ba9ba4Schristos there is an gdbarch_deprecated_fp_regnum and that it is the same, cooked or 128a1ba9ba4Schristos raw. */ 129a1ba9ba4Schristos 130a1ba9ba4Schristos extern gdbarch_virtual_frame_pointer_ftype legacy_virtual_frame_pointer; 131a1ba9ba4Schristos 13215d8e94aSchristos /* Default implementation of gdbarch_floatformat_for_type. */ 13315d8e94aSchristos extern const struct floatformat ** 13415d8e94aSchristos default_floatformat_for_type (struct gdbarch *gdbarch, 13515d8e94aSchristos const char *name, int len); 13615d8e94aSchristos 137a1ba9ba4Schristos extern CORE_ADDR generic_skip_trampoline_code (struct frame_info *frame, 138a1ba9ba4Schristos CORE_ADDR pc); 139a1ba9ba4Schristos 140a1ba9ba4Schristos extern CORE_ADDR generic_skip_solib_resolver (struct gdbarch *gdbarch, 141a1ba9ba4Schristos CORE_ADDR pc); 142a1ba9ba4Schristos 143a1ba9ba4Schristos extern int generic_in_solib_return_trampoline (struct gdbarch *gdbarch, 144a1ba9ba4Schristos CORE_ADDR pc, const char *name); 145a1ba9ba4Schristos 146a1ba9ba4Schristos extern int generic_stack_frame_destroyed_p (struct gdbarch *gdbarch, 147a1ba9ba4Schristos CORE_ADDR pc); 148a1ba9ba4Schristos 149b2396a7bSchristos extern int default_code_of_frame_writable (struct gdbarch *gdbarch, 150b2396a7bSchristos struct frame_info *frame); 151b2396a7bSchristos 152a1ba9ba4Schristos /* By default, registers are not convertible. */ 153a1ba9ba4Schristos extern int generic_convert_register_p (struct gdbarch *gdbarch, int regnum, 154a1ba9ba4Schristos struct type *type); 155a1ba9ba4Schristos 156a1ba9ba4Schristos extern int default_stabs_argument_has_addr (struct gdbarch *gdbarch, 157a1ba9ba4Schristos struct type *type); 158a1ba9ba4Schristos 159a1ba9ba4Schristos extern int generic_instruction_nullified (struct gdbarch *gdbarch, 160a1ba9ba4Schristos struct regcache *regcache); 161a1ba9ba4Schristos 162a1ba9ba4Schristos int default_remote_register_number (struct gdbarch *gdbarch, 163a1ba9ba4Schristos int regno); 164a1ba9ba4Schristos 165a1ba9ba4Schristos /* For compatibility with older architectures, returns 166a1ba9ba4Schristos (LEGACY_SIM_REGNO_IGNORE) when the register doesn't have a valid 167a1ba9ba4Schristos name. */ 168a1ba9ba4Schristos 169a1ba9ba4Schristos extern int legacy_register_sim_regno (struct gdbarch *gdbarch, int regnum); 170a1ba9ba4Schristos 171a1ba9ba4Schristos /* Return the selected byte order, or BFD_ENDIAN_UNKNOWN if no byte 172a1ba9ba4Schristos order was explicitly selected. */ 173a1ba9ba4Schristos extern enum bfd_endian selected_byte_order (void); 174a1ba9ba4Schristos 175a1ba9ba4Schristos /* Return the selected architecture's name, or NULL if no architecture 176a1ba9ba4Schristos was explicitly selected. */ 177a1ba9ba4Schristos extern const char *selected_architecture_name (void); 178a1ba9ba4Schristos 179a1ba9ba4Schristos /* Initialize a ``struct info''. Can't use memset(0) since some 180a1ba9ba4Schristos default values are not zero. "fill" takes all available 181a1ba9ba4Schristos information and fills in any unspecified fields. */ 182a1ba9ba4Schristos 183a1ba9ba4Schristos extern void gdbarch_info_init (struct gdbarch_info *info); 184a1ba9ba4Schristos 185a1ba9ba4Schristos /* Similar to init, but this time fill in the blanks. Information is 186a1ba9ba4Schristos obtained from the global "set ..." options and explicitly 187a1ba9ba4Schristos initialized INFO fields. */ 188a1ba9ba4Schristos extern void gdbarch_info_fill (struct gdbarch_info *info); 189a1ba9ba4Schristos 190a1ba9ba4Schristos /* Return the architecture for ABFD. If no suitable architecture 191a1ba9ba4Schristos could be find, return NULL. */ 192a1ba9ba4Schristos 193a1ba9ba4Schristos extern struct gdbarch *gdbarch_from_bfd (bfd *abfd); 194a1ba9ba4Schristos 195a1ba9ba4Schristos /* Return "current" architecture. If the target is running, this is the 196a1ba9ba4Schristos architecture of the selected frame. Otherwise, the "current" architecture 197a1ba9ba4Schristos defaults to the target architecture. 198a1ba9ba4Schristos 199a1ba9ba4Schristos This function should normally be called solely by the command interpreter 200a1ba9ba4Schristos routines to determine the architecture to execute a command in. */ 201a1ba9ba4Schristos extern struct gdbarch *get_current_arch (void); 202a1ba9ba4Schristos 203a1ba9ba4Schristos extern int default_has_shared_address_space (struct gdbarch *); 204a1ba9ba4Schristos 205a1ba9ba4Schristos extern int default_fast_tracepoint_valid_at (struct gdbarch *gdbarch, 206051580eeSchristos CORE_ADDR addr, std::string *msg); 207a1ba9ba4Schristos 20815d8e94aSchristos extern const gdb_byte *default_breakpoint_from_pc (struct gdbarch *gdbarch, 20915d8e94aSchristos CORE_ADDR *pcptr, 21015d8e94aSchristos int *lenptr); 21115d8e94aSchristos 21215d8e94aSchristos extern int default_breakpoint_kind_from_current_state (struct gdbarch *gdbarch, 21315d8e94aSchristos struct regcache *regcache, 21415d8e94aSchristos CORE_ADDR *pcptr); 215a1ba9ba4Schristos 216a1ba9ba4Schristos extern void default_gen_return_address (struct gdbarch *gdbarch, 217a1ba9ba4Schristos struct agent_expr *ax, 218a1ba9ba4Schristos struct axs_value *value, 219a1ba9ba4Schristos CORE_ADDR scope); 220a1ba9ba4Schristos 221a1ba9ba4Schristos extern const char *default_auto_charset (void); 222a1ba9ba4Schristos extern const char *default_auto_wide_charset (void); 223a1ba9ba4Schristos 224a1ba9ba4Schristos extern int default_return_in_first_hidden_param_p (struct gdbarch *, 225a1ba9ba4Schristos struct type *); 226a1ba9ba4Schristos 227a1ba9ba4Schristos extern int default_insn_is_call (struct gdbarch *, CORE_ADDR); 228a1ba9ba4Schristos extern int default_insn_is_ret (struct gdbarch *, CORE_ADDR); 229a1ba9ba4Schristos extern int default_insn_is_jump (struct gdbarch *, CORE_ADDR); 230a1ba9ba4Schristos 231*184b2d41Schristos /* Default implementation of gdbarch_program_breakpoint_here_p. */ 232*184b2d41Schristos extern bool default_program_breakpoint_here_p (struct gdbarch *gdbarch, 233*184b2d41Schristos CORE_ADDR addr); 234*184b2d41Schristos 235a1ba9ba4Schristos /* Do-nothing version of vsyscall_range. Returns false. */ 236a1ba9ba4Schristos 237a1ba9ba4Schristos extern int default_vsyscall_range (struct gdbarch *gdbarch, struct mem_range *range); 238a1ba9ba4Schristos 239a1ba9ba4Schristos /* Default way to advance the PC to the next instruction in order to 240a1ba9ba4Schristos skip a permanent breakpoint. Increments the PC by the size of a 241a1ba9ba4Schristos software breakpoint instruction, as determined with 242a1ba9ba4Schristos gdbarch_breakpoint_from_pc. This matches how the breakpoints 243a1ba9ba4Schristos module determines whether a breakpoint is permanent. */ 244a1ba9ba4Schristos extern void default_skip_permanent_breakpoint (struct regcache *regcache); 245a1ba9ba4Schristos 246a1ba9ba4Schristos /* Symbols for gdbarch_infcall_mmap; their Linux PROT_* system 247a1ba9ba4Schristos definitions would be dependent on compilation host. */ 248a1ba9ba4Schristos #define GDB_MMAP_PROT_READ 0x1 /* Page can be read. */ 249a1ba9ba4Schristos #define GDB_MMAP_PROT_WRITE 0x2 /* Page can be written. */ 250a1ba9ba4Schristos #define GDB_MMAP_PROT_EXEC 0x4 /* Page can be executed. */ 251a1ba9ba4Schristos 252a1ba9ba4Schristos extern CORE_ADDR default_infcall_mmap (CORE_ADDR size, unsigned prot); 253a1ba9ba4Schristos extern void default_infcall_munmap (CORE_ADDR addr, CORE_ADDR size); 254*184b2d41Schristos extern std::string default_gcc_target_options (struct gdbarch *gdbarch); 255a1ba9ba4Schristos extern const char *default_gnu_triplet_regexp (struct gdbarch *gdbarch); 256a1ba9ba4Schristos extern int default_addressable_memory_unit_size (struct gdbarch *gdbarch); 257a1ba9ba4Schristos 258b2396a7bSchristos extern void default_guess_tracepoint_registers (struct gdbarch *gdbarch, 259b2396a7bSchristos struct regcache *regcache, 260b2396a7bSchristos CORE_ADDR addr); 261b2396a7bSchristos 262051580eeSchristos extern int default_print_insn (bfd_vma memaddr, disassemble_info *info); 263051580eeSchristos 26415d8e94aSchristos /* Wrapper to gdbarch_skip_prologue, but doesn't throw exception. Catch 26515d8e94aSchristos exception thrown from gdbarch_skip_prologue, and return PC. */ 26615d8e94aSchristos 26715d8e94aSchristos extern CORE_ADDR gdbarch_skip_prologue_noexcept (gdbarch *gdbarch, 26815d8e94aSchristos CORE_ADDR pc) noexcept; 26915d8e94aSchristos 270051580eeSchristos /* Default implementation of gdbarch_in_indirect_branch_thunk that returns 271051580eeSchristos false. */ 272051580eeSchristos extern bool default_in_indirect_branch_thunk (gdbarch *gdbarch, 273051580eeSchristos CORE_ADDR pc); 274051580eeSchristos 275051580eeSchristos /* Default implementation of gdbarch type_align method. */ 276051580eeSchristos extern ULONGEST default_type_align (struct gdbarch *gdbarch, 277051580eeSchristos struct type *type); 278051580eeSchristos 279*184b2d41Schristos /* Default implementation of gdbarch get_pc_address_flags method. */ 280*184b2d41Schristos extern std::string default_get_pc_address_flags (frame_info *frame, 281*184b2d41Schristos CORE_ADDR pc); 282*184b2d41Schristos 283*184b2d41Schristos /* Default implementation of gdbarch read_core_file_mappings method. */ 284*184b2d41Schristos extern void default_read_core_file_mappings (struct gdbarch *gdbarch, 285*184b2d41Schristos struct bfd *cbfd, 286*184b2d41Schristos gdb::function_view<void (ULONGEST count)> 287*184b2d41Schristos pre_loop_cb, 288*184b2d41Schristos gdb::function_view<void (int num, 289*184b2d41Schristos ULONGEST start, 290*184b2d41Schristos ULONGEST end, 291*184b2d41Schristos ULONGEST file_ofs, 292*184b2d41Schristos const char *filename, 293*184b2d41Schristos const void *other)> 294*184b2d41Schristos loop_cb); 295051580eeSchristos #endif /* ARCH_UTILS_H */ 296