mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2024-12-14 04:43:38 +08:00
65b48a8140
This commit adds support to GDB so that it can modify the disassembler-options value that is passed to the disassembler, similar to objdump's -M option. Currently, the only supported targets are ARM, PowerPC and S/390, but adding support for a new target(s) is not difficult. include/ * dis-asm.h (disasm_options_t): New typedef. (parse_arm_disassembler_option): Remove prototype. (set_arm_regname_option): Likewise. (get_arm_regnames): Likewise. (get_arm_regname_num_options): Likewise. (disassemble_init_s390): New prototype. (disassembler_options_powerpc): Likewise. (disassembler_options_arm): Likewise. (disassembler_options_s390): Likewise. (remove_whitespace_and_extra_commas): Likewise. (disassembler_options_cmp): Likewise. (next_disassembler_option): New inline function. (FOR_EACH_DISASSEMBLER_OPTION): New macro. opcodes/ * disassemble.c Include "safe-ctype.h". (disassemble_init_for_target): Handle s390 init. (remove_whitespace_and_extra_commas): New function. (disassembler_options_cmp): Likewise. * arm-dis.c: Include "libiberty.h". (NUM_ELEM): Delete. (regnames): Use long disassembler style names. Add force-thumb and no-force-thumb options. (NUM_ARM_REGNAMES): Rename from this... (NUM_ARM_OPTIONS): ...to this. Use ARRAY_SIZE. (get_arm_regname_num_options): Delete. (set_arm_regname_option): Likewise. (get_arm_regnames): Likewise. (parse_disassembler_options): Likewise. (parse_arm_disassembler_option): Rename from this... (parse_arm_disassembler_options): ...to this. Make static. Use new FOR_EACH_DISASSEMBLER_OPTION macro to scan over options. (print_insn): Use parse_arm_disassembler_options. (disassembler_options_arm): New function. (print_arm_disassembler_options): Handle updated regnames. * ppc-dis.c: Include "libiberty.h". (ppc_opts): Add "32" and "64" entries. (ppc_parse_cpu): Use ARRAY_SIZE and disassembler_options_cmp. (powerpc_init_dialect): Add break to switch statement. Use new FOR_EACH_DISASSEMBLER_OPTION macro. (disassembler_options_powerpc): New function. (print_ppc_disassembler_options): Use ARRAY_SIZE. Remove printing of "32" and "64". * s390-dis.c: Include "libiberty.h". (init_flag): Remove unneeded variable. (struct s390_options_t): New structure type. (options): New structure. (init_disasm): Rename from this... (disassemble_init_s390): ...to this. Add initializations for current_arch_mask and option_use_insn_len_bits_p. Remove init_flag. (print_insn_s390): Delete call to init_disasm. (disassembler_options_s390): New function. (print_s390_disassembler_options): Print using information from struct 'options'. * po/opcodes.pot: Regenerate. binutils/ * objdump.c (main): Use remove_whitespace_and_extra_commas. gdb/ * NEWS: Mention new set/show disassembler-options commands. * doc/gdb.texinfo: Document new set/show disassembler-options commands. * disasm.c: Include "arch-utils.h", "gdbcmd.h" and "safe-ctype.h". (prospective_options): New static variable. (gdb_disassembler::gdb_disassembler): Initialize m_di.disassembler_options. (gdb_buffered_insn_length_init_dis): Initilize di->disassembler_options. (get_disassembler_options): New function. (set_disassembler_options): Likewise. (set_disassembler_options_sfunc): Likewise. (show_disassembler_options_sfunc): Likewise. (disassembler_options_completer): Likewise. (_initialize_disasm): Likewise. * disasm.h (get_disassembler_options): New prototype. (set_disassembler_options): Likewise. * gdbarch.sh (gdbarch_disassembler_options): New variable. (gdbarch_verify_disassembler_options): Likewise. * gdbarch.c: Regenerate. * gdbarch.h: Likewise. * arm-tdep.c (num_disassembly_options): Delete. (set_disassembly_style): Likewise. (arm_disassembler_options): New static variable. (set_disassembly_style_sfunc): Convert short style name into long option name. Call set_disassembler_options. (show_disassembly_style_sfunc): New function. (arm_gdbarch_init): Call set_gdbarch_disassembler_options and set_gdbarch_verify_disassembler_options. (_initialize_arm_tdep): Delete regnames variable and update callers. (arm_disassembler_options): Initialize. (disasm_options): New variable. (num_disassembly_options): Rename from this... (num_disassembly_styles): ...to this. Compute by scanning through disasm_options. (valid_disassembly_styles): Initialize using disasm_options. Remove calls to parse_arm_disassembler_option, get_arm_regnames and set_arm_regname_option. Pass show_disassembly_style_sfunc to the "disassembler" setshow command. * rs6000-tdep.c (powerpc_disassembler_options): New static variable. (rs6000_gdbarch_init): Call set_gdbarch_disassembler_options and set_gdbarch_verify_disassembler_options. * s390-tdep.c (s390_disassembler_options): New static variable. (s390_gdbarch_init):all set_gdbarch_disassembler_options and set_gdbarch_verify_disassembler_options. gdb/testsuite/ * gdb.arch/powerpc-power.exp: Delete test. * gdb.arch/powerpc-power.s: Likewise. * gdb.disasm/disassembler-options.exp: New test. * gdb.arch/powerpc-altivec.exp: Likewise. * gdb.arch/powerpc-altivec.s: Likewise. * gdb.arch/powerpc-altivec2.exp: Likewise. * gdb.arch/powerpc-altivec2.s: Likewise. * gdb.arch/powerpc-altivec3.exp: Likewise. * gdb.arch/powerpc-altivec3.s: Likewise. * gdb.arch/powerpc-power7.exp: Likewise. * gdb.arch/powerpc-power7.s: Likewise. * gdb.arch/powerpc-power8.exp: Likewise. * gdb.arch/powerpc-power8.s: Likewise. * gdb.arch/powerpc-power9.exp: Likewise. * gdb.arch/powerpc-power9.s: Likewise. * gdb.arch/powerpc-vsx.exp: Likewise. * gdb.arch/powerpc-vsx.s: Likewise. * gdb.arch/powerpc-vsx2.exp: Likewise. * gdb.arch/powerpc-vsx2.s: Likewise. * gdb.arch/powerpc-vsx3.exp: Likewise. * gdb.arch/powerpc-vsx3.s: Likewise. * gdb.arch/arm-disassembler-options.exp: Likewise. * gdb.arch/powerpc-disassembler-options.exp: Likewise. * gdb.arch/s390-disassembler-options.exp: Likewise.
150 lines
4.5 KiB
C++
150 lines
4.5 KiB
C++
/* Disassemble support for GDB.
|
|
Copyright (C) 2002-2017 Free Software Foundation, Inc.
|
|
|
|
This file is part of GDB.
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
|
|
|
#ifndef DISASM_H
|
|
#define DISASM_H
|
|
|
|
#include "dis-asm.h"
|
|
|
|
#define DISASSEMBLY_SOURCE_DEPRECATED (0x1 << 0)
|
|
#define DISASSEMBLY_RAW_INSN (0x1 << 1)
|
|
#define DISASSEMBLY_OMIT_FNAME (0x1 << 2)
|
|
#define DISASSEMBLY_FILENAME (0x1 << 3)
|
|
#define DISASSEMBLY_OMIT_PC (0x1 << 4)
|
|
#define DISASSEMBLY_SOURCE (0x1 << 5)
|
|
#define DISASSEMBLY_SPECULATIVE (0x1 << 6)
|
|
|
|
struct gdbarch;
|
|
struct ui_out;
|
|
struct ui_file;
|
|
|
|
class gdb_disassembler
|
|
{
|
|
using di_read_memory_ftype = decltype (disassemble_info::read_memory_func);
|
|
|
|
public:
|
|
gdb_disassembler (struct gdbarch *gdbarch, struct ui_file *file)
|
|
: gdb_disassembler (gdbarch, file, dis_asm_read_memory)
|
|
{}
|
|
|
|
int print_insn (CORE_ADDR memaddr, int *branch_delay_insns = NULL);
|
|
|
|
/* Return the gdbarch of gdb_disassembler. */
|
|
struct gdbarch *arch ()
|
|
{ return m_gdbarch; }
|
|
|
|
protected:
|
|
gdb_disassembler (struct gdbarch *gdbarch, struct ui_file *file,
|
|
di_read_memory_ftype func);
|
|
|
|
struct ui_file *stream ()
|
|
{ return (struct ui_file *) m_di.stream; }
|
|
|
|
private:
|
|
struct gdbarch *m_gdbarch;
|
|
|
|
/* Stores data required for disassembling instructions in
|
|
opcodes. */
|
|
struct disassemble_info m_di;
|
|
CORE_ADDR m_err_memaddr;
|
|
|
|
static int dis_asm_read_memory (bfd_vma memaddr, gdb_byte *myaddr,
|
|
unsigned int len,
|
|
struct disassemble_info *info);
|
|
static void dis_asm_memory_error (int err, bfd_vma memaddr,
|
|
struct disassemble_info *info);
|
|
static void dis_asm_print_address (bfd_vma addr,
|
|
struct disassemble_info *info);
|
|
};
|
|
|
|
/* An instruction to be disassembled. */
|
|
|
|
struct disasm_insn
|
|
{
|
|
/* The address of the memory containing the instruction. */
|
|
CORE_ADDR addr;
|
|
|
|
/* An optional instruction number. If non-zero, it is printed first. */
|
|
unsigned int number;
|
|
|
|
/* True if the instruction was executed speculatively. */
|
|
unsigned int is_speculative:1;
|
|
};
|
|
|
|
extern void gdb_disassembly (struct gdbarch *gdbarch, struct ui_out *uiout,
|
|
int flags, int how_many,
|
|
CORE_ADDR low, CORE_ADDR high);
|
|
|
|
/* Print the instruction at address MEMADDR in debugged memory,
|
|
on STREAM. Returns the length of the instruction, in bytes,
|
|
and, if requested, the number of branch delay slot instructions. */
|
|
|
|
extern int gdb_print_insn (struct gdbarch *gdbarch, CORE_ADDR memaddr,
|
|
struct ui_file *stream, int *branch_delay_insns);
|
|
|
|
/* Class used to pretty-print instructions. */
|
|
|
|
class gdb_pretty_print_disassembler
|
|
{
|
|
public:
|
|
explicit gdb_pretty_print_disassembler (struct gdbarch *gdbarch)
|
|
: m_di (gdbarch, &m_insn_stb)
|
|
{}
|
|
|
|
/* Prints the instruction INSN into UIOUT and returns the length of
|
|
the printed instruction in bytes. */
|
|
int pretty_print_insn (struct ui_out *uiout, const struct disasm_insn *insn,
|
|
int flags);
|
|
|
|
private:
|
|
/* Returns the architecture used for disassembling. */
|
|
struct gdbarch *arch () { return m_di.arch (); }
|
|
|
|
/* The disassembler used for instruction printing. */
|
|
gdb_disassembler m_di;
|
|
|
|
/* The buffer used to build the instruction string. The
|
|
disassembler is initialized with this stream. */
|
|
string_file m_insn_stb;
|
|
|
|
/* The buffer used to build the raw opcodes string. */
|
|
string_file m_opcode_stb;
|
|
};
|
|
|
|
/* Return the length in bytes of the instruction at address MEMADDR in
|
|
debugged memory. */
|
|
|
|
extern int gdb_insn_length (struct gdbarch *gdbarch, CORE_ADDR memaddr);
|
|
|
|
/* Return the length in bytes of INSN, originally at MEMADDR. MAX_LEN
|
|
is the size of the buffer containing INSN. */
|
|
|
|
extern int gdb_buffered_insn_length (struct gdbarch *gdbarch,
|
|
const gdb_byte *insn, int max_len,
|
|
CORE_ADDR memaddr);
|
|
|
|
/* Returns GDBARCH's disassembler options. */
|
|
|
|
extern char *get_disassembler_options (struct gdbarch *gdbarch);
|
|
|
|
/* Sets the active gdbarch's disassembler options to OPTIONS. */
|
|
|
|
extern void set_disassembler_options (char *options);
|
|
|
|
#endif
|