mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2024-11-29 04:53:56 +08:00
187808b04f
ui_file_rewind is a ui_file method that only really works with mem buffer files, and is a nop on other ui_file types. It'd be desirable to eliminate it from the base ui_file interface, and move it to the "mem_fileopen" subclass of ui_file instead. A following patch does just that. Unfortunately, there are a couple references to ui_file_rewind inside gdb_disassembler::pretty_print_insn that were made harder to eliminate with the recent addition of the gdb_disassembler wrapper. Before the gdb_disassembler wrapper was added, in commite47ad6c0bd
("Refactor disassembly code"), gdb_pretty_print_insn used to be passed a ui_file pointer as argument, and it was simple to adjust that pointer be a "mem_fileopen" ui_file pointer instead, since there's only one gdb_pretty_print_insn caller. That commit made gdb_pretty_print_insn be a method of gdb_disassembler, and removed the method's ui_file parameter at the same time, replaced by referencing the gdb_disassembler's stream instead. The trouble is that a gdb_disassembler can be instantiated with a pointer any kind of ui_file. Casting the gdb_disassembler's stream to a mem_fileopen ui_file inside gdb_disassembler::pretty_print_insn in order to call the reset method would be gross hack. The fix here is to: - make gdb_disassembler::pretty_print_insn a be free function again instead of a method of gdb_disassembler. I.e., bring back gdb_pretty_print_insn. - but, don't add back the ui_file * parameter. Instead, move the mem_fileopen allocation inside. That is a better interface, given that the ui_file is only ever used as temporary scratch buffer as an implementation detail of gdb_pretty_print_insn. The function's real "where to send output" parameter is the ui_out pointer. (A following patch will add back buffer reuse across invocations differently). - don't add back a disassemble_info pointer either. That used to be necessary for this bit: err = m_di.read_memory_func (pc, &data, 1, &m_di); if (err != 0) m_di.memory_error_func (err, pc, &m_di); ... but AFAIK, it's not really necessary. We can replace those three lines with a call to read_code. This seems to fix a regression even, because before commitd8b49cf0c8
("Don't throw exception in dis_asm_memory_error"), that memory_error_func call would throw an error/exception, but now it only records the error in the gdb_disassembler's m_err_memaddr field. (read_code throws on error.) With all these, gdb_pretty_print_insn is completely layered on top of gdb_disassembler only using the latter's public API. gdb/ChangeLog: 2017-02-02 Pedro Alves <palves@redhat.com> * disasm.c (gdb_disassembler::pretty_print_insn): Rename to... (gdb_pretty_print_insn): ... this. Now a free function. Add back a 'gdbarch' parameter. Allocate a mem_fileopen stream here. Adjust to call gdb_print_insn instead of gdb_disassembler::print_insn. (dump_insns, do_mixed_source_and_assembly_deprecated) (do_mixed_source_and_assembly, do_assembly_only): Add back a 'gdbarch' parameter. Remove gdb_disassembler parameter. (gdb_disassembly): Don't allocate a gdb_disassembler here. * disasm.h (gdb_disassembler::pretty_print_insn): Delete declaration. (gdb_pretty_print_insn): Re-add declaration. * record-btrace.c (btrace_insn_history): Don't allocate a gdb_disassembler here. Adjust to call gdb_pretty_print_insn.
119 lines
3.7 KiB
C++
119 lines
3.7 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);
|
|
|
|
/* Prints the instruction INSN into UIOUT and returns the length of
|
|
the printed instruction in bytes. */
|
|
|
|
extern int gdb_pretty_print_insn (struct gdbarch *gdbarch, struct ui_out *uiout,
|
|
const struct disasm_insn *insn, int flags);
|
|
|
|
/* 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);
|
|
|
|
#endif
|