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