Search
lxdream.org :: lxdream/src/x86dasm/dis-buf.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/x86dasm/dis-buf.c
changeset 1092:7c4ffe27e7b5
prev755:ab873907b00e
author nkeynes
date Sun Dec 20 21:01:03 2009 +1000 (11 years ago)
permissions -rw-r--r--
last change Fix 64-bit x86 disassembly
Add crash-report hook to SIGILL and SIGBUS
view annotate diff log raw
     1 /* Disassemble from a buffer, for GNU.
     2    Copyright 1993, 1994, 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2005
     3    Free Software Foundation, Inc.
     5 This program is free software; you can redistribute it and/or modify
     6 it under the terms of the GNU General Public License as published by
     7 the Free Software Foundation; either version 2 of the License, or
     8 (at your option) any later version.
    10 This program is distributed in the hope that it will be useful,
    11 but WITHOUT ANY WARRANTY; without even the implied warranty of
    12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    13 GNU General Public License for more details.
    15 You should have received a copy of the GNU General Public License
    16 along with this program; if not, write to the Free Software
    17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
    19 #include "x86dasm/sysdep.h"
    20 #include "x86dasm/dis-asm.h"
    21 #include <errno.h>
    22 #include "gettext.h"
    24 /* Get LENGTH bytes from info's buffer, at target address memaddr.
    25    Transfer them to myaddr.  */
    26 int
    27 buffer_read_memory (memaddr, myaddr, length, info)
    28      bfd_vma memaddr;
    29      bfd_byte *myaddr;
    30      unsigned int length;
    31      struct disassemble_info *info;
    32 {
    33   unsigned int opb = info->octets_per_byte;
    34   uintptr_t octets = memaddr * opb;
    36   memcpy (myaddr, info->buffer + octets, length);
    38   return 0;
    39 }
    41 /* Print an error message.  We can assume that this is in response to
    42    an error return from buffer_read_memory.  */
    43 void
    44 perror_memory (status, memaddr, info)
    45      int status;
    46      bfd_vma memaddr;
    47      struct disassemble_info *info;
    48 {
    49   if (status != EIO)
    50     /* Can't happen.  */
    51     info->fprintf_func (info->stream, _("Unknown error %d\n"), status);
    52   else
    53     {
    54       char buf[30];
    56       /* Actually, address between memaddr and memaddr + len was
    57 	 out of bounds.  */
    58       sprintf_vma (buf, memaddr);
    59       info->fprintf_func (info->stream,
    60 			  _("Address 0x%s is out of bounds.\n"), buf);
    61     }
    62 }
    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;
    75 {
    76   char buf[30];
    78   sprintf_vma (buf, addr);
    79   (*info->fprintf_func) (info->stream, "0x%s", buf);
    80 }
    82 #if 0
    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).  */
    87 void generic_strcat_address PARAMS ((bfd_vma, char *, int));
    89 void
    90 generic_strcat_address (addr, buf, len)
    91      bfd_vma addr;
    92      char *buf;
    93      int len;
    94 {
    95   if (buf != (char *)NULL && len > 0)
    96     {
    97       char tmpBuf[30];
    99       sprintf_vma (tmpBuf, addr);
   100       if ((strlen (buf) + strlen (tmpBuf)) <= (unsigned int) len)
   101 	strcat (buf, tmpBuf);
   102       else
   103 	strncat (buf, tmpBuf, (len - strlen(buf)));
   104     }
   105   return;
   106 }
   107 #endif
   109 /* Just return true.  */
   111 int
   112 generic_symbol_at_address (addr, info)
   113      bfd_vma addr ATTRIBUTE_UNUSED;
   114      struct disassemble_info *info ATTRIBUTE_UNUSED;
   115 {
   116   return 1;
   117 }
   119 /* Just return TRUE.  */
   121 bfd_boolean
   122 generic_symbol_is_valid (asymbol * sym ATTRIBUTE_UNUSED,
   123 			 struct disassemble_info *info ATTRIBUTE_UNUSED)
   124 {
   125   return TRUE;
   126 }
.