Back to index

cell-binutils  2.17cvs20070401
dis-buf.c
Go to the documentation of this file.
00001 /* Disassemble from a buffer, for GNU.
00002    Copyright 1993, 1994, 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2005
00003    Free Software Foundation, Inc.
00004 
00005    This program is free software; you can redistribute it and/or modify
00006    it under the terms of the GNU General Public License as published by
00007    the Free Software Foundation; either version 2 of the License, or
00008    (at your option) any later version.
00009 
00010    This program is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013    GNU General Public License for more details.
00014 
00015    You should have received a copy of the GNU General Public License
00016    along with this program; if not, write to the Free Software
00017    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
00018    MA 02110-1301, USA.  */
00019 
00020 #include "sysdep.h"
00021 #include "dis-asm.h"
00022 #include <errno.h>
00023 #include "opintl.h"
00024 
00025 /* Get LENGTH bytes from info's buffer, at target address memaddr.
00026    Transfer them to myaddr.  */
00027 int
00028 buffer_read_memory (bfd_vma memaddr,
00029                   bfd_byte *myaddr,
00030                   unsigned int length,
00031                   struct disassemble_info *info)
00032 {
00033   unsigned int opb = info->octets_per_byte;
00034   unsigned int end_addr_offset = length / opb;
00035   unsigned int max_addr_offset = info->buffer_length / opb; 
00036   unsigned int octets = (memaddr - info->buffer_vma) * opb;
00037 
00038   if (memaddr < info->buffer_vma
00039       || memaddr - info->buffer_vma + end_addr_offset > max_addr_offset)
00040     /* Out of bounds.  Use EIO because GDB uses it.  */
00041     return EIO;
00042   memcpy (myaddr, info->buffer + octets, length);
00043 
00044   return 0;
00045 }
00046 
00047 /* Print an error message.  We can assume that this is in response to
00048    an error return from buffer_read_memory.  */
00049 
00050 void
00051 perror_memory (int status,
00052               bfd_vma memaddr,
00053               struct disassemble_info *info)
00054 {
00055   if (status != EIO)
00056     /* Can't happen.  */
00057     info->fprintf_func (info->stream, _("Unknown error %d\n"), status);
00058   else
00059     {
00060       char buf[30];
00061 
00062       /* Actually, address between memaddr and memaddr + len was
00063         out of bounds.  */
00064       sprintf_vma (buf, memaddr);
00065       info->fprintf_func (info->stream,
00066                        _("Address 0x%s is out of bounds.\n"), buf);
00067     }
00068 }
00069 
00070 /* This could be in a separate file, to save miniscule amounts of space
00071    in statically linked executables.  */
00072 
00073 /* Just print the address is hex.  This is included for completeness even
00074    though both GDB and objdump provide their own (to print symbolic
00075    addresses).  */
00076 
00077 void
00078 generic_print_address (bfd_vma addr, struct disassemble_info *info)
00079 {
00080   char buf[30];
00081 
00082   sprintf_vma (buf, addr);
00083   (*info->fprintf_func) (info->stream, "0x%s", buf);
00084 }
00085 
00086 /* Just return true.  */
00087 
00088 int
00089 generic_symbol_at_address (bfd_vma addr ATTRIBUTE_UNUSED,
00090                         struct disassemble_info *info ATTRIBUTE_UNUSED)
00091 {
00092   return 1;
00093 }
00094 
00095 /* Just return TRUE.  */
00096 
00097 bfd_boolean
00098 generic_symbol_is_valid (asymbol * sym ATTRIBUTE_UNUSED,
00099                       struct disassemble_info *info ATTRIBUTE_UNUSED)
00100 {
00101   return TRUE;
00102 }