* elf32-i386.c (elf_i386_info_to_howto_rel): Give a warning for
[binutils.git] / opcodes / dis-buf.c
blobb828206d43f650a9b1bd8ce689e1811b1d4c0c5b
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 unsigned int length;
30 struct disassemble_info *info;
32 unsigned int opb = info->octets_per_byte;
33 unsigned int end_addr_offset = length / opb;
34 unsigned int max_addr_offset = info->buffer_length / opb;
35 unsigned int octets = (memaddr - info->buffer_vma) * opb;
37 if (memaddr < info->buffer_vma
38 || memaddr - info->buffer_vma + end_addr_offset > max_addr_offset)
39 /* Out of bounds. Use EIO because GDB uses it. */
40 return EIO;
41 memcpy (myaddr, info->buffer + octets, length);
43 return 0;
46 /* Print an error message. We can assume that this is in response to
47 an error return from buffer_read_memory. */
48 void
49 perror_memory (status, memaddr, info)
50 int status;
51 bfd_vma memaddr;
52 struct disassemble_info *info;
54 if (status != EIO)
55 /* Can't happen. */
56 info->fprintf_func (info->stream, _("Unknown error %d\n"), status);
57 else
58 /* Actually, address between memaddr and memaddr + len was
59 out of bounds. */
60 info->fprintf_func (info->stream,
61 _("Address 0x%x is out of bounds.\n"), memaddr);
64 /* This could be in a separate file, to save miniscule amounts of space
65 in statically linked executables. */
67 /* Just print the address is hex. This is included for completeness even
68 though both GDB and objdump provide their own (to print symbolic
69 addresses). */
71 void
72 generic_print_address (addr, info)
73 bfd_vma addr;
74 struct disassemble_info *info;
76 char buf[30];
78 sprintf_vma (buf, addr);
79 (*info->fprintf_func) (info->stream, "0x%s", buf);
82 /* Just concatenate the address as hex. This is included for
83 completeness even though both GDB and objdump provide their own (to
84 print symbolic addresses). */
86 void
87 generic_strcat_address (addr, buf, len)
88 bfd_vma addr;
89 char *buf;
90 int len;
92 if (buf != (char *)NULL && len > 0)
94 char tmpBuf[30];
96 sprintf_vma (tmpBuf, addr);
97 if ((strlen (buf) + strlen (tmpBuf)) <= (unsigned int) len)
98 strcat (buf, tmpBuf);
99 else
100 strncat (buf, tmpBuf, (len - strlen(buf)));
102 return;
105 /* Just return the given address. */
108 generic_symbol_at_address (addr, info)
109 bfd_vma addr ATTRIBUTE_UNUSED;
110 struct disassemble_info *info ATTRIBUTE_UNUSED;
112 return 1;