| 1 | /* Disassemble from a buffer, for GNU. |
| 2 | Copyright (C) 1993, 1994, 1998 Free Software Foundation, Inc. |
| 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
| 17 | |
| 18 | #include "sysdep.h" |
| 19 | #include "dis-asm.h" |
| 20 | #include <errno.h> |
| 21 | #include "opintl.h" |
| 22 | |
| 23 | /* Get LENGTH bytes from info's buffer, at target address memaddr. |
| 24 | Transfer them to myaddr. */ |
| 25 | int |
| 26 | buffer_read_memory (memaddr, myaddr, length, info) |
| 27 | bfd_vma memaddr; |
| 28 | bfd_byte *myaddr; |
| 29 | int length; |
| 30 | struct disassemble_info *info; |
| 31 | { |
| 32 | if (memaddr < info->buffer_vma |
| 33 | || memaddr + length > info->buffer_vma + info->buffer_length) |
| 34 | /* Out of bounds. Use EIO because GDB uses it. */ |
| 35 | return EIO; |
| 36 | memcpy (myaddr, info->buffer + (memaddr - info->buffer_vma), length); |
| 37 | return 0; |
| 38 | } |
| 39 | |
| 40 | /* Print an error message. We can assume that this is in response to |
| 41 | an error return from buffer_read_memory. */ |
| 42 | void |
| 43 | perror_memory (status, memaddr, info) |
| 44 | int status; |
| 45 | bfd_vma memaddr; |
| 46 | struct disassemble_info *info; |
| 47 | { |
| 48 | if (status != EIO) |
| 49 | /* Can't happen. */ |
| 50 | info->fprintf_func (info->stream, _("Unknown error %d\n"), status); |
| 51 | else |
| 52 | /* Actually, address between memaddr and memaddr + len was |
| 53 | out of bounds. */ |
| 54 | info->fprintf_func (info->stream, |
| 55 | _("Address 0x%x is out of bounds.\n"), memaddr); |
| 56 | } |
| 57 | |
| 58 | /* This could be in a separate file, to save miniscule amounts of space |
| 59 | in statically linked executables. */ |
| 60 | |
| 61 | /* Just print the address is hex. This is included for completeness even |
| 62 | though both GDB and objdump provide their own (to print symbolic |
| 63 | addresses). */ |
| 64 | |
| 65 | void |
| 66 | generic_print_address (addr, info) |
| 67 | bfd_vma addr; |
| 68 | struct disassemble_info *info; |
| 69 | { |
| 70 | (*info->fprintf_func) (info->stream, "0x%x", addr); |
| 71 | } |
| 72 | |
| 73 | /* Just concatenate the address as hex. This is included for |
| 74 | completeness even though both GDB and objdump provide their own (to |
| 75 | print symbolic addresses). */ |
| 76 | |
| 77 | void |
| 78 | generic_strcat_address (addr, buf, len) |
| 79 | bfd_vma addr; |
| 80 | char *buf; |
| 81 | int len; |
| 82 | { |
| 83 | if (buf != (char *)NULL && len > 0) |
| 84 | { |
| 85 | char tmpBuf[30]; |
| 86 | |
| 87 | sprintf_vma (tmpBuf, addr); |
| 88 | if ((strlen (buf) + strlen (tmpBuf)) <= len) |
| 89 | strcat (buf, tmpBuf); |
| 90 | else |
| 91 | strncat (buf, tmpBuf, (len - strlen(buf))); |
| 92 | } |
| 93 | return; |
| 94 | } |
| 95 | |
| 96 | /* Just return the given address. */ |
| 97 | |
| 98 | int |
| 99 | generic_symbol_at_address (addr, info) |
| 100 | bfd_vma addr; |
| 101 | struct disassemble_info * info; |
| 102 | { |
| 103 | return 1; |
| 104 | } |