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