1999-05-03 15:29:11 +08:00
|
|
|
/* Disassemble from a buffer, for GNU.
|
2022-01-02 06:30:17 +08:00
|
|
|
Copyright (C) 1993-2022 Free Software Foundation, Inc.
|
1999-05-03 15:29:11 +08:00
|
|
|
|
2007-07-05 17:49:03 +08:00
|
|
|
This file is part of the GNU opcodes library.
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify
|
2005-07-01 19:16:33 +08:00
|
|
|
it under the terms of the GNU General Public License as published by
|
2007-07-05 17:49:03 +08:00
|
|
|
the Free Software Foundation; either version 3, or (at your option)
|
|
|
|
any later version.
|
1999-05-03 15:29:11 +08:00
|
|
|
|
2007-07-05 17:49:03 +08:00
|
|
|
It 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.
|
1999-05-03 15:29:11 +08:00
|
|
|
|
2005-07-01 19:16:33 +08:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
|
|
|
|
MA 02110-1301, USA. */
|
1999-05-03 15:29:11 +08:00
|
|
|
|
|
|
|
#include "sysdep.h"
|
|
|
|
#include "dis-asm.h"
|
|
|
|
#include <errno.h>
|
|
|
|
#include "opintl.h"
|
|
|
|
|
|
|
|
/* Get LENGTH bytes from info's buffer, at target address memaddr.
|
|
|
|
Transfer them to myaddr. */
|
|
|
|
int
|
2005-07-01 19:16:33 +08:00
|
|
|
buffer_read_memory (bfd_vma memaddr,
|
|
|
|
bfd_byte *myaddr,
|
|
|
|
unsigned int length,
|
|
|
|
struct disassemble_info *info)
|
1999-05-03 15:29:11 +08:00
|
|
|
{
|
2000-02-21 20:01:27 +08:00
|
|
|
unsigned int opb = info->octets_per_byte;
|
2017-07-14 15:56:27 +08:00
|
|
|
size_t end_addr_offset = length / opb;
|
|
|
|
size_t max_addr_offset = info->buffer_length / opb;
|
|
|
|
size_t octets = (memaddr - info->buffer_vma) * opb;
|
2000-02-04 02:12:55 +08:00
|
|
|
|
1999-05-03 15:29:11 +08:00
|
|
|
if (memaddr < info->buffer_vma
|
2010-03-23 23:59:45 +08:00
|
|
|
|| memaddr - info->buffer_vma > max_addr_offset
|
2015-06-22 23:53:27 +08:00
|
|
|
|| memaddr - info->buffer_vma + end_addr_offset > max_addr_offset
|
|
|
|
|| (info->stop_vma && (memaddr >= info->stop_vma
|
|
|
|
|| memaddr + end_addr_offset > info->stop_vma)))
|
1999-05-03 15:29:11 +08:00
|
|
|
/* Out of bounds. Use EIO because GDB uses it. */
|
|
|
|
return EIO;
|
2000-02-04 02:12:55 +08:00
|
|
|
memcpy (myaddr, info->buffer + octets, length);
|
|
|
|
|
1999-05-03 15:29:11 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Print an error message. We can assume that this is in response to
|
|
|
|
an error return from buffer_read_memory. */
|
2005-07-01 19:16:33 +08:00
|
|
|
|
1999-05-03 15:29:11 +08:00
|
|
|
void
|
2005-07-01 19:16:33 +08:00
|
|
|
perror_memory (int status,
|
|
|
|
bfd_vma memaddr,
|
|
|
|
struct disassemble_info *info)
|
1999-05-03 15:29:11 +08:00
|
|
|
{
|
|
|
|
if (status != EIO)
|
|
|
|
/* Can't happen. */
|
|
|
|
info->fprintf_func (info->stream, _("Unknown error %d\n"), status);
|
|
|
|
else
|
2005-02-14 23:47:19 +08:00
|
|
|
{
|
|
|
|
/* Actually, address between memaddr and memaddr + len was
|
|
|
|
out of bounds. */
|
|
|
|
info->fprintf_func (info->stream,
|
Get rid of fprintf_vma and sprintf_vma
These two macros print either a 16 digit hex number or an 8 digit
hex number. Unfortunately they depend on both target and host, which
means that the output for 32-bit targets may be either 8 or 16 hex
digits.
Replace them in most cases with code that prints a bfd_vma using
PRIx64. In some cases, deliberately lose the leading zeros.
This change some output, notably in base/offset fields of m68k
disassembly which I think looks better that way, and in error
messages. I've kept leading zeros in symbol dumps (objdump -t)
and in PE header dumps.
bfd/
* bfd-in.h (fprintf_vma, sprintf_vma, printf_vma): Delete.
* bfd-in2.h: Regenerate.
* bfd.c (bfd_sprintf_vma): Don't use sprintf_vma.
(bfd_fprintf_vma): Don't use fprintf_vma.
* coff-rs6000.c (xcoff_reloc_type_tls): Don't use sprintf_vma.
Instead use PRIx64 to print bfd_vma values.
(xcoff_ppc_relocate_section): Likewise.
* cofflink.c (_bfd_coff_write_global_sym): Likewise.
* mmo.c (mmo_write_symbols_and_terminator): Likewise.
* srec.c (srec_write_symbols): Likewise.
* elf32-xtensa.c (print_r_reloc): Similarly for fprintf_vma.
* pei-x86_64.c (pex64_dump_xdata): Likewise.
(pex64_bfd_print_pdata_section): Likewise.
* som.c (som_print_symbol): Likewise.
* ecoff.c (_bfd_ecoff_print_symbol): Use bfd_fprintf_vma.
opcodes/
* dis-buf.c (perror_memory, generic_print_address): Don't use
sprintf_vma. Instead use PRIx64 to print bfd_vma values.
* i386-dis.c (print_operand_value, print_displacement): Likewise.
* m68k-dis.c (print_base, print_indexed): Likewise.
* ns32k-dis.c (print_insn_arg): Likewise.
* ia64-gen.c (_opcode_int64_low, _opcode_int64_high): Delete.
(opcode_fprintf_vma): Delete.
(print_main_table): Use PRIx64 to print opcode.
binutils/
* od-macho.c: Replace all uses of printf_vma with bfd_printf_vma.
* objcopy.c (copy_object): Don't use sprintf_vma. Instead use
PRIx64 to print bfd_vma values.
(copy_main): Likewise.
* readelf.c (CHECK_ENTSIZE_VALUES): Likewise.
(dynamic_section_mips_val): Likewise.
(print_vma): Don't use printf_vma. Instead use PRIx64 to print
bfd_vma values.
(dump_ia64_vms_dynamic_fixups): Likewise.
(process_version_sections): Likewise.
* rddbg.c (stab_context): Likewise.
gas/
* config/tc-i386.c (offset_in_range): Don't use sprintf_vma.
Instead use PRIx64 to print bfd_vma values.
(md_assemble): Likewise.
* config/tc-mips.c (load_register, macro): Likewise.
* messages.c (as_internal_value_out_of_range): Likewise.
* read.c (emit_expr_with_reloc): Likewise.
* config/tc-ia64.c (note_register_values): Don't use fprintf_vma.
Instead use PRIx64 to print bfd_vma values.
(print_dependency): Likewise.
* listing.c (list_symbol_table): Use bfd_sprintf_vma.
* symbols.c (print_symbol_value_1): Use %p to print pointers.
(print_binary): Likewise.
(print_expr_1): Use PRIx64 to print bfd_vma values.
* write.c (print_fixup): Use %p to print pointers. Don't use
fprintf_vma.
* testsuite/gas/all/overflow.l: Update expected output.
* testsuite/gas/m68k/mcf-mov3q.d: Likewise.
* testsuite/gas/m68k/operands.d: Likewise.
* testsuite/gas/s12z/truncated.d: Likewise.
ld/
* deffilep.y (def_file_print): Don't use fprintf_vma. Instead
use PRIx64 to print bfd_vma values.
* emultempl/armelf.em (gld${EMULATION_NAME}_finish): Don't use
sprintf_vma. Instead use PRIx64 to print bfd_vma values.
* emultempl/pe.em (gld${EMULATION_NAME}_finish): Likewise.
* ldlang.c (lang_map): Use %V to print region origin.
(lang_one_common): Don't use sprintf_vma.
* ldmisc.c (vfinfo): Don't use fprintf_vma or sprintf_vma.
* pe-dll.c (pe_dll_generate_def_file): Likewise.
gdb/
* remote.c (remote_target::trace_set_readonly_regions): Replace
uses of sprintf_vma with bfd_sprintf_vma.
2022-08-01 10:03:46 +08:00
|
|
|
_("Address 0x%" PRIx64 " is out of bounds.\n"),
|
|
|
|
(uint64_t) memaddr);
|
2005-02-14 23:47:19 +08:00
|
|
|
}
|
1999-05-03 15:29:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* This could be in a separate file, to save miniscule amounts of space
|
|
|
|
in statically linked executables. */
|
|
|
|
|
|
|
|
/* Just print the address is hex. This is included for completeness even
|
|
|
|
though both GDB and objdump provide their own (to print symbolic
|
|
|
|
addresses). */
|
|
|
|
|
|
|
|
void
|
2005-07-01 19:16:33 +08:00
|
|
|
generic_print_address (bfd_vma addr, struct disassemble_info *info)
|
1999-05-03 15:29:11 +08:00
|
|
|
{
|
Get rid of fprintf_vma and sprintf_vma
These two macros print either a 16 digit hex number or an 8 digit
hex number. Unfortunately they depend on both target and host, which
means that the output for 32-bit targets may be either 8 or 16 hex
digits.
Replace them in most cases with code that prints a bfd_vma using
PRIx64. In some cases, deliberately lose the leading zeros.
This change some output, notably in base/offset fields of m68k
disassembly which I think looks better that way, and in error
messages. I've kept leading zeros in symbol dumps (objdump -t)
and in PE header dumps.
bfd/
* bfd-in.h (fprintf_vma, sprintf_vma, printf_vma): Delete.
* bfd-in2.h: Regenerate.
* bfd.c (bfd_sprintf_vma): Don't use sprintf_vma.
(bfd_fprintf_vma): Don't use fprintf_vma.
* coff-rs6000.c (xcoff_reloc_type_tls): Don't use sprintf_vma.
Instead use PRIx64 to print bfd_vma values.
(xcoff_ppc_relocate_section): Likewise.
* cofflink.c (_bfd_coff_write_global_sym): Likewise.
* mmo.c (mmo_write_symbols_and_terminator): Likewise.
* srec.c (srec_write_symbols): Likewise.
* elf32-xtensa.c (print_r_reloc): Similarly for fprintf_vma.
* pei-x86_64.c (pex64_dump_xdata): Likewise.
(pex64_bfd_print_pdata_section): Likewise.
* som.c (som_print_symbol): Likewise.
* ecoff.c (_bfd_ecoff_print_symbol): Use bfd_fprintf_vma.
opcodes/
* dis-buf.c (perror_memory, generic_print_address): Don't use
sprintf_vma. Instead use PRIx64 to print bfd_vma values.
* i386-dis.c (print_operand_value, print_displacement): Likewise.
* m68k-dis.c (print_base, print_indexed): Likewise.
* ns32k-dis.c (print_insn_arg): Likewise.
* ia64-gen.c (_opcode_int64_low, _opcode_int64_high): Delete.
(opcode_fprintf_vma): Delete.
(print_main_table): Use PRIx64 to print opcode.
binutils/
* od-macho.c: Replace all uses of printf_vma with bfd_printf_vma.
* objcopy.c (copy_object): Don't use sprintf_vma. Instead use
PRIx64 to print bfd_vma values.
(copy_main): Likewise.
* readelf.c (CHECK_ENTSIZE_VALUES): Likewise.
(dynamic_section_mips_val): Likewise.
(print_vma): Don't use printf_vma. Instead use PRIx64 to print
bfd_vma values.
(dump_ia64_vms_dynamic_fixups): Likewise.
(process_version_sections): Likewise.
* rddbg.c (stab_context): Likewise.
gas/
* config/tc-i386.c (offset_in_range): Don't use sprintf_vma.
Instead use PRIx64 to print bfd_vma values.
(md_assemble): Likewise.
* config/tc-mips.c (load_register, macro): Likewise.
* messages.c (as_internal_value_out_of_range): Likewise.
* read.c (emit_expr_with_reloc): Likewise.
* config/tc-ia64.c (note_register_values): Don't use fprintf_vma.
Instead use PRIx64 to print bfd_vma values.
(print_dependency): Likewise.
* listing.c (list_symbol_table): Use bfd_sprintf_vma.
* symbols.c (print_symbol_value_1): Use %p to print pointers.
(print_binary): Likewise.
(print_expr_1): Use PRIx64 to print bfd_vma values.
* write.c (print_fixup): Use %p to print pointers. Don't use
fprintf_vma.
* testsuite/gas/all/overflow.l: Update expected output.
* testsuite/gas/m68k/mcf-mov3q.d: Likewise.
* testsuite/gas/m68k/operands.d: Likewise.
* testsuite/gas/s12z/truncated.d: Likewise.
ld/
* deffilep.y (def_file_print): Don't use fprintf_vma. Instead
use PRIx64 to print bfd_vma values.
* emultempl/armelf.em (gld${EMULATION_NAME}_finish): Don't use
sprintf_vma. Instead use PRIx64 to print bfd_vma values.
* emultempl/pe.em (gld${EMULATION_NAME}_finish): Likewise.
* ldlang.c (lang_map): Use %V to print region origin.
(lang_one_common): Don't use sprintf_vma.
* ldmisc.c (vfinfo): Don't use fprintf_vma or sprintf_vma.
* pe-dll.c (pe_dll_generate_def_file): Likewise.
gdb/
* remote.c (remote_target::trace_set_readonly_regions): Replace
uses of sprintf_vma with bfd_sprintf_vma.
2022-08-01 10:03:46 +08:00
|
|
|
(*info->fprintf_func) (info->stream, "0x%08" PRIx64, (uint64_t) addr);
|
1999-05-03 15:29:11 +08:00
|
|
|
}
|
|
|
|
|
2021-04-06 17:27:04 +08:00
|
|
|
/* Just return NULL. */
|
1999-05-03 15:29:11 +08:00
|
|
|
|
2021-04-06 17:27:04 +08:00
|
|
|
asymbol *
|
2005-07-01 19:16:33 +08:00
|
|
|
generic_symbol_at_address (bfd_vma addr ATTRIBUTE_UNUSED,
|
|
|
|
struct disassemble_info *info ATTRIBUTE_UNUSED)
|
1999-05-03 15:29:11 +08:00
|
|
|
{
|
2021-04-06 17:27:04 +08:00
|
|
|
return NULL;
|
1999-05-03 15:29:11 +08:00
|
|
|
}
|
2003-11-14 23:12:44 +08:00
|
|
|
|
|
|
|
/* Just return TRUE. */
|
|
|
|
|
Use bool in opcodes
cpu/
* frv.opc: Replace bfd_boolean with bool, FALSE with false, and
TRUE with true throughout.
opcodes/
* sysdep.h (POISON_BFD_BOOLEAN): Define.
* aarch64-asm-2.c, * aarch64-asm.c, * aarch64-asm.h,
* aarch64-dis-2.c, * aarch64-dis.c, * aarch64-dis.h,
* aarch64-gen.c, * aarch64-opc.c, * aarch64-opc.h, * arc-dis.c,
* arc-dis.h, * arc-fxi.h, * arc-opc.c, * arm-dis.c, * bfin-dis.c,
* cris-dis.c, * csky-dis.c, * csky-opc.h, * dis-buf.c,
* disassemble.c, * frv-opc.c, * frv-opc.h, * h8300-dis.c,
* i386-dis.c, * m68k-dis.c, * metag-dis.c, * microblaze-dis.c,
* microblaze-dis.h, * micromips-opc.c, * mips-dis.c,
* mips-formats.h, * mips-opc.c, * mips16-opc.c, * mmix-dis.c,
* msp430-dis.c, * nds32-dis.c, * nfp-dis.c, * nios2-dis.c,
* ppc-dis.c, * riscv-dis.c, * score-dis.c, * score7-dis.c,
* tic6x-dis.c, * v850-dis.c, * vax-dis.c, * wasm32-dis.c,
* xtensa-dis.c: Replace bfd_boolean with bool, FALSE with false,
and TRUE with true throughout.
2021-03-31 08:06:19 +08:00
|
|
|
bool
|
2003-11-14 23:12:44 +08:00
|
|
|
generic_symbol_is_valid (asymbol * sym ATTRIBUTE_UNUSED,
|
|
|
|
struct disassemble_info *info ATTRIBUTE_UNUSED)
|
|
|
|
{
|
Use bool in opcodes
cpu/
* frv.opc: Replace bfd_boolean with bool, FALSE with false, and
TRUE with true throughout.
opcodes/
* sysdep.h (POISON_BFD_BOOLEAN): Define.
* aarch64-asm-2.c, * aarch64-asm.c, * aarch64-asm.h,
* aarch64-dis-2.c, * aarch64-dis.c, * aarch64-dis.h,
* aarch64-gen.c, * aarch64-opc.c, * aarch64-opc.h, * arc-dis.c,
* arc-dis.h, * arc-fxi.h, * arc-opc.c, * arm-dis.c, * bfin-dis.c,
* cris-dis.c, * csky-dis.c, * csky-opc.h, * dis-buf.c,
* disassemble.c, * frv-opc.c, * frv-opc.h, * h8300-dis.c,
* i386-dis.c, * m68k-dis.c, * metag-dis.c, * microblaze-dis.c,
* microblaze-dis.h, * micromips-opc.c, * mips-dis.c,
* mips-formats.h, * mips-opc.c, * mips16-opc.c, * mmix-dis.c,
* msp430-dis.c, * nds32-dis.c, * nfp-dis.c, * nios2-dis.c,
* ppc-dis.c, * riscv-dis.c, * score-dis.c, * score7-dis.c,
* tic6x-dis.c, * v850-dis.c, * vax-dis.c, * wasm32-dis.c,
* xtensa-dis.c: Replace bfd_boolean with bool, FALSE with false,
and TRUE with true throughout.
2021-03-31 08:06:19 +08:00
|
|
|
return true;
|
2003-11-14 23:12:44 +08:00
|
|
|
}
|