2001-04-17 Michael Snyder <msnyder@redhat.com>
[deliverable/binutils-gdb.git] / opcodes / dis-buf.c
CommitLineData
252b5132 1/* Disassemble from a buffer, for GNU.
060d22b0
NC
2 Copyright 1993, 1994, 1996, 1997, 1998, 1999, 2000
3 Free Software Foundation, Inc.
252b5132
RH
4
5This program is free software; you can redistribute it and/or modify
6it under the terms of the GNU General Public License as published by
7the Free Software Foundation; either version 2 of the License, or
8(at your option) any later version.
9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with this program; if not, write to the Free Software
17Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
18
19#include "sysdep.h"
20#include "dis-asm.h"
21#include <errno.h>
22#include "opintl.h"
23
24/* Get LENGTH bytes from info's buffer, at target address memaddr.
25 Transfer them to myaddr. */
26int
27buffer_read_memory (memaddr, myaddr, length, info)
28 bfd_vma memaddr;
29 bfd_byte *myaddr;
f6af82bd 30 unsigned int length;
252b5132
RH
31 struct disassemble_info *info;
32{
f6af82bd
AM
33 unsigned int opb = info->octets_per_byte;
34 unsigned int end_addr_offset = length / opb;
35 unsigned int max_addr_offset = info->buffer_length / opb;
36 unsigned int octets = (memaddr - info->buffer_vma) * opb;
940b2b78 37
252b5132 38 if (memaddr < info->buffer_vma
940b2b78 39 || memaddr - info->buffer_vma + end_addr_offset > max_addr_offset)
252b5132
RH
40 /* Out of bounds. Use EIO because GDB uses it. */
41 return EIO;
940b2b78
TW
42 memcpy (myaddr, info->buffer + octets, length);
43
252b5132
RH
44 return 0;
45}
46
47/* Print an error message. We can assume that this is in response to
48 an error return from buffer_read_memory. */
49void
50perror_memory (status, memaddr, info)
51 int status;
52 bfd_vma memaddr;
53 struct disassemble_info *info;
54{
55 if (status != EIO)
56 /* Can't happen. */
57 info->fprintf_func (info->stream, _("Unknown error %d\n"), status);
58 else
59 /* Actually, address between memaddr and memaddr + len was
60 out of bounds. */
61 info->fprintf_func (info->stream,
62 _("Address 0x%x is out of bounds.\n"), memaddr);
63}
64
65/* This could be in a separate file, to save miniscule amounts of space
66 in statically linked executables. */
67
68/* Just print the address is hex. This is included for completeness even
69 though both GDB and objdump provide their own (to print symbolic
70 addresses). */
71
72void
73generic_print_address (addr, info)
74 bfd_vma addr;
75 struct disassemble_info *info;
76{
9c492adc
ILT
77 char buf[30];
78
79 sprintf_vma (buf, addr);
80 (*info->fprintf_func) (info->stream, "0x%s", buf);
252b5132
RH
81}
82
83/* Just concatenate the address as hex. This is included for
84 completeness even though both GDB and objdump provide their own (to
85 print symbolic addresses). */
86
87void
88generic_strcat_address (addr, buf, len)
89 bfd_vma addr;
90 char *buf;
91 int len;
92{
93 if (buf != (char *)NULL && len > 0)
94 {
95 char tmpBuf[30];
96
97 sprintf_vma (tmpBuf, addr);
57d91c3c 98 if ((strlen (buf) + strlen (tmpBuf)) <= (unsigned int) len)
252b5132
RH
99 strcat (buf, tmpBuf);
100 else
101 strncat (buf, tmpBuf, (len - strlen(buf)));
102 }
103 return;
104}
105
106/* Just return the given address. */
107
108int
109generic_symbol_at_address (addr, info)
57d91c3c
ILT
110 bfd_vma addr ATTRIBUTE_UNUSED;
111 struct disassemble_info *info ATTRIBUTE_UNUSED;
252b5132
RH
112{
113 return 1;
114}
This page took 0.072498 seconds and 4 git commands to generate.