/src/binutils-gdb/opcodes/dis-buf.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* Disassemble from a buffer, for GNU. |
2 | | Copyright (C) 1993-2025 Free Software Foundation, Inc. |
3 | | |
4 | | This file is part of the GNU opcodes library. |
5 | | |
6 | | This library is free software; you can redistribute it and/or modify |
7 | | it under the terms of the GNU General Public License as published by |
8 | | the Free Software Foundation; either version 3, or (at your option) |
9 | | any later version. |
10 | | |
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. |
15 | | |
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. */ |
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. */ |
28 | | int |
29 | | buffer_read_memory (bfd_vma memaddr, |
30 | | bfd_byte *myaddr, |
31 | | unsigned int length, |
32 | | struct disassemble_info *info) |
33 | 382M | { |
34 | 382M | unsigned int opb = info->octets_per_byte; |
35 | 382M | size_t end_addr_offset = length / opb; |
36 | 382M | size_t max_addr_offset = info->buffer_length / opb; |
37 | 382M | size_t octets = (memaddr - info->buffer_vma) * opb; |
38 | | |
39 | 382M | if (memaddr < info->buffer_vma |
40 | 382M | || memaddr - info->buffer_vma > max_addr_offset |
41 | 382M | || memaddr - info->buffer_vma + end_addr_offset > max_addr_offset |
42 | 382M | || (info->stop_vma && (memaddr >= info->stop_vma |
43 | 0 | || memaddr + end_addr_offset > info->stop_vma))) |
44 | | /* Out of bounds. Use EIO because GDB uses it. */ |
45 | 700k | return EIO; |
46 | 381M | memcpy (myaddr, info->buffer + octets, length); |
47 | | |
48 | 381M | return 0; |
49 | 382M | } |
50 | | |
51 | | /* Print an error message. We can assume that this is in response to |
52 | | an error return from buffer_read_memory. */ |
53 | | |
54 | | void |
55 | | perror_memory (int status, |
56 | | bfd_vma memaddr, |
57 | | struct disassemble_info *info) |
58 | 86.6k | { |
59 | 86.6k | if (status != EIO) |
60 | | /* Can't happen. */ |
61 | 0 | info->fprintf_func (info->stream, _("Unknown error %d\n"), status); |
62 | 86.6k | else |
63 | 86.6k | { |
64 | | /* Actually, address between memaddr and memaddr + len was |
65 | | out of bounds. */ |
66 | 86.6k | info->fprintf_func (info->stream, |
67 | 86.6k | _("Address 0x%" PRIx64 " is out of bounds.\n"), |
68 | 86.6k | (uint64_t) memaddr); |
69 | 86.6k | } |
70 | 86.6k | } |
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 | | |
79 | | void |
80 | | generic_print_address (bfd_vma addr, struct disassemble_info *info) |
81 | 4.52M | { |
82 | 4.52M | (*info->fprintf_func) (info->stream, "0x%08" PRIx64, (uint64_t) addr); |
83 | 4.52M | } |
84 | | |
85 | | /* Just return NULL. */ |
86 | | |
87 | | asymbol * |
88 | | generic_symbol_at_address (bfd_vma addr ATTRIBUTE_UNUSED, |
89 | | struct disassemble_info *info ATTRIBUTE_UNUSED) |
90 | 332k | { |
91 | 332k | return NULL; |
92 | 332k | } |
93 | | |
94 | | /* Just return TRUE. */ |
95 | | |
96 | | bool |
97 | | generic_symbol_is_valid (asymbol * sym ATTRIBUTE_UNUSED, |
98 | | struct disassemble_info *info ATTRIBUTE_UNUSED) |
99 | 1.78M | { |
100 | 1.78M | return true; |
101 | 1.78M | } |