]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - opcodes/dis-buf.c
Update year range in copyright notice of binutils files
[thirdparty/binutils-gdb.git] / opcodes / dis-buf.c
CommitLineData
252b5132 1/* Disassemble from a buffer, for GNU.
d87bef3a 2 Copyright (C) 1993-2023 Free Software Foundation, Inc.
252b5132 3
9b201bb5
NC
4 This file is part of the GNU opcodes library.
5
6 This library is free software; you can redistribute it and/or modify
47b0e7ad 7 it under the terms of the GNU General Public License as published by
9b201bb5
NC
8 the Free Software Foundation; either version 3, or (at your option)
9 any later version.
252b5132 10
9b201bb5
NC
11 It is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
14 License for more details.
252b5132 15
47b0e7ad
NC
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19 MA 02110-1301, USA. */
252b5132
RH
20
21#include "sysdep.h"
22#include "dis-asm.h"
23#include <errno.h>
24#include "opintl.h"
25
26/* Get LENGTH bytes from info's buffer, at target address memaddr.
27 Transfer them to myaddr. */
28int
47b0e7ad
NC
29buffer_read_memory (bfd_vma memaddr,
30 bfd_byte *myaddr,
31 unsigned int length,
32 struct disassemble_info *info)
252b5132 33{
f6af82bd 34 unsigned int opb = info->octets_per_byte;
0f6329bd
RB
35 size_t end_addr_offset = length / opb;
36 size_t max_addr_offset = info->buffer_length / opb;
37 size_t octets = (memaddr - info->buffer_vma) * opb;
940b2b78 38
252b5132 39 if (memaddr < info->buffer_vma
f66187fd 40 || memaddr - info->buffer_vma > max_addr_offset
bdc4de1b
NC
41 || memaddr - info->buffer_vma + end_addr_offset > max_addr_offset
42 || (info->stop_vma && (memaddr >= info->stop_vma
43 || memaddr + end_addr_offset > info->stop_vma)))
252b5132
RH
44 /* Out of bounds. Use EIO because GDB uses it. */
45 return EIO;
940b2b78
TW
46 memcpy (myaddr, info->buffer + octets, length);
47
252b5132
RH
48 return 0;
49}
50
51/* Print an error message. We can assume that this is in response to
52 an error return from buffer_read_memory. */
47b0e7ad 53
252b5132 54void
47b0e7ad
NC
55perror_memory (int status,
56 bfd_vma memaddr,
57 struct disassemble_info *info)
252b5132
RH
58{
59 if (status != EIO)
60 /* Can't happen. */
61 info->fprintf_func (info->stream, _("Unknown error %d\n"), status);
62 else
d6098898 63 {
d6098898
L
64 /* Actually, address between memaddr and memaddr + len was
65 out of bounds. */
d6098898 66 info->fprintf_func (info->stream,
f493c217
AM
67 _("Address 0x%" PRIx64 " is out of bounds.\n"),
68 (uint64_t) memaddr);
d6098898 69 }
252b5132
RH
70}
71
72/* This could be in a separate file, to save miniscule amounts of space
73 in statically linked executables. */
74
75/* Just print the address is hex. This is included for completeness even
76 though both GDB and objdump provide their own (to print symbolic
77 addresses). */
78
79void
47b0e7ad 80generic_print_address (bfd_vma addr, struct disassemble_info *info)
252b5132 81{
f493c217 82 (*info->fprintf_func) (info->stream, "0x%08" PRIx64, (uint64_t) addr);
252b5132
RH
83}
84
a2e66773 85/* Just return NULL. */
252b5132 86
a2e66773 87asymbol *
47b0e7ad
NC
88generic_symbol_at_address (bfd_vma addr ATTRIBUTE_UNUSED,
89 struct disassemble_info *info ATTRIBUTE_UNUSED)
252b5132 90{
a2e66773 91 return NULL;
252b5132 92}
22a398e1
NC
93
94/* Just return TRUE. */
95
78933a4a 96bool
22a398e1
NC
97generic_symbol_is_valid (asymbol * sym ATTRIBUTE_UNUSED,
98 struct disassemble_info *info ATTRIBUTE_UNUSED)
99{
78933a4a 100 return true;
22a398e1 101}