Commit | Line | Data |
---|---|---|
aff22f45 | 1 | /* Disassemble from a buffer, for GNU. |
5c9b5f58 | 2 | Copyright (C) 1993, 1994 Free Software Foundation, Inc. |
aff22f45 JK |
3 | |
4 | This program is free software; you can redistribute it and/or modify | |
5 | it under the terms of the GNU General Public License as published by | |
6 | the Free Software Foundation; either version 2 of the License, or | |
7 | (at your option) any later version. | |
8 | ||
9 | This program is distributed in the hope that it will be useful, | |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | GNU General Public License for more details. | |
13 | ||
14 | You should have received a copy of the GNU General Public License | |
15 | along with this program; if not, write to the Free Software | |
16 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
17 | ||
18 | #include "dis-asm.h" | |
5c9b5f58 | 19 | #include <string.h> |
aff22f45 JK |
20 | #include <errno.h> |
21 | ||
22 | /* Get LENGTH bytes from info's buffer, at target address memaddr. | |
23 | Transfer them to myaddr. */ | |
24 | int | |
25 | buffer_read_memory (memaddr, myaddr, length, info) | |
26 | bfd_vma memaddr; | |
27 | bfd_byte *myaddr; | |
28 | int length; | |
29 | struct disassemble_info *info; | |
30 | { | |
31 | if (memaddr < info->buffer_vma | |
32 | || memaddr + length > info->buffer_vma + info->buffer_length) | |
33 | /* Out of bounds. Use EIO because GDB uses it. */ | |
34 | return EIO; | |
35 | memcpy (myaddr, info->buffer + (memaddr - info->buffer_vma), length); | |
36 | return 0; | |
37 | } | |
38 | ||
39 | /* Print an error message. We can assume that this is in response to | |
40 | an error return from buffer_read_memory. */ | |
41 | void | |
42 | perror_memory (status, memaddr, info) | |
43 | int status; | |
44 | bfd_vma memaddr; | |
45 | struct disassemble_info *info; | |
46 | { | |
47 | if (status != EIO) | |
48 | /* Can't happen. */ | |
49 | (*info->fprintf_func) (info->stream, "Unknown error %d\n", status); | |
50 | else | |
51 | /* Actually, address between memaddr and memaddr + len was | |
52 | out of bounds. */ | |
53 | (*info->fprintf_func) (info->stream, | |
54 | "Address 0x%x is out of bounds.\n", memaddr); | |
55 | } | |
5c9b5f58 PS |
56 | |
57 | /* This could be in a separate file, to save miniscule amounts of space | |
58 | in statically linked executables. */ | |
59 | ||
60 | /* Just print the address is hex. This is included for completeness even | |
61 | though both GDB and objdump provide their own (to print symbolic | |
62 | addresses). */ | |
63 | ||
64 | void | |
65 | generic_print_address (addr, info) | |
66 | bfd_vma addr; | |
67 | struct disassemble_info *info; | |
68 | { | |
69 | (*info->fprintf_func) (info->stream, "0x%x", addr); | |
70 | } |