import gdb-2000-02-02 snapshot
[deliverable/binutils-gdb.git] / opcodes / dis-buf.c
CommitLineData
252b5132 1/* Disassemble from a buffer, for GNU.
57d91c3c 2 Copyright (C) 1993, 1994, 1998, 1999 Free Software Foundation, Inc.
252b5132
RH
3
4This program is free software; you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation; either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program; if not, write to the Free Software
16Foundation, 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. */
25int
26buffer_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
9c492adc 33 || memaddr - info->buffer_vma + length > info->buffer_length)
252b5132
RH
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. */
42void
43perror_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
65void
66generic_print_address (addr, info)
67 bfd_vma addr;
68 struct disassemble_info *info;
69{
9c492adc
ILT
70 char buf[30];
71
72 sprintf_vma (buf, addr);
73 (*info->fprintf_func) (info->stream, "0x%s", buf);
252b5132
RH
74}
75
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). */
79
80void
81generic_strcat_address (addr, buf, len)
82 bfd_vma addr;
83 char *buf;
84 int len;
85{
86 if (buf != (char *)NULL && len > 0)
87 {
88 char tmpBuf[30];
89
90 sprintf_vma (tmpBuf, addr);
57d91c3c 91 if ((strlen (buf) + strlen (tmpBuf)) <= (unsigned int) len)
252b5132
RH
92 strcat (buf, tmpBuf);
93 else
94 strncat (buf, tmpBuf, (len - strlen(buf)));
95 }
96 return;
97}
98
99/* Just return the given address. */
100
101int
102generic_symbol_at_address (addr, info)
57d91c3c
ILT
103 bfd_vma addr ATTRIBUTE_UNUSED;
104 struct disassemble_info *info ATTRIBUTE_UNUSED;
252b5132
RH
105{
106 return 1;
107}
This page took 0.042391 seconds and 4 git commands to generate.