1999-09-11 Donn Terry <donn@interix.com>
[binutils.git] / opcodes / dis-buf.c
blob523fe72789dbcfd939cd1cd13ed72e4562150d76
1 /* Disassemble from a buffer, for GNU.
2 Copyright (C) 1993, 1994, 1998, 1999 Free Software Foundation, Inc.
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.
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.
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. */
18 #include "sysdep.h"
19 #include "dis-asm.h"
20 #include <errno.h>
21 #include "opintl.h"
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;
32 if (memaddr < info->buffer_vma
33 || memaddr - info->buffer_vma + length > 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;
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;
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);
58 /* This could be in a separate file, to save miniscule amounts of space
59 in statically linked executables. */
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). */
65 void
66 generic_print_address (addr, info)
67 bfd_vma addr;
68 struct disassemble_info *info;
70 char buf[30];
72 sprintf_vma (buf, addr);
73 (*info->fprintf_func) (info->stream, "0x%s", buf);
76 /* Just concatenate the address as hex. This is included for
77 completeness even though both GDB and objdump provide their own (to
78 print symbolic addresses). */
80 void
81 generic_strcat_address (addr, buf, len)
82 bfd_vma addr;
83 char *buf;
84 int len;
86 if (buf != (char *)NULL && len > 0)
88 char tmpBuf[30];
90 sprintf_vma (tmpBuf, addr);
91 if ((strlen (buf) + strlen (tmpBuf)) <= (unsigned int) len)
92 strcat (buf, tmpBuf);
93 else
94 strncat (buf, tmpBuf, (len - strlen(buf)));
96 return;
99 /* Just return the given address. */
102 generic_symbol_at_address (addr, info)
103 bfd_vma addr ATTRIBUTE_UNUSED;
104 struct disassemble_info *info ATTRIBUTE_UNUSED;
106 return 1;