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 755:ab873907b00e
prev362:dc40e2064dc4
next1092:7c4ffe27e7b5
author nkeynes
date Mon Jul 21 00:08:34 2008 +0000 (13 years ago)
permissions -rw-r--r--
last change Add gettext.h and build sanely without libintl if it's not available
Remove x86dasm's config.h & opintl.h (no longer needed and actually wrong)
file annotate diff log raw
nkeynes@362
     1
/* Disassemble from a buffer, for GNU.
nkeynes@362
     2
   Copyright 1993, 1994, 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2005
nkeynes@362
     3
   Free Software Foundation, Inc.
nkeynes@362
     4
nkeynes@362
     5
This program is free software; you can redistribute it and/or modify
nkeynes@362
     6
it under the terms of the GNU General Public License as published by
nkeynes@362
     7
the Free Software Foundation; either version 2 of the License, or
nkeynes@362
     8
(at your option) any later version.
nkeynes@362
     9
nkeynes@362
    10
This program is distributed in the hope that it will be useful,
nkeynes@362
    11
but WITHOUT ANY WARRANTY; without even the implied warranty of
nkeynes@362
    12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
nkeynes@362
    13
GNU General Public License for more details.
nkeynes@362
    14
nkeynes@362
    15
You should have received a copy of the GNU General Public License
nkeynes@362
    16
along with this program; if not, write to the Free Software
nkeynes@362
    17
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
nkeynes@362
    18
nkeynes@755
    19
#include "x86dasm/sysdep.h"
nkeynes@755
    20
#include "x86dasm/dis-asm.h"
nkeynes@362
    21
#include <errno.h>
nkeynes@755
    22
#include "gettext.h"
nkeynes@362
    23
nkeynes@362
    24
/* Get LENGTH bytes from info's buffer, at target address memaddr.
nkeynes@362
    25
   Transfer them to myaddr.  */
nkeynes@362
    26
int
nkeynes@362
    27
buffer_read_memory (memaddr, myaddr, length, info)
nkeynes@362
    28
     bfd_vma memaddr;
nkeynes@362
    29
     bfd_byte *myaddr;
nkeynes@362
    30
     unsigned int length;
nkeynes@362
    31
     struct disassemble_info *info;
nkeynes@362
    32
{
nkeynes@362
    33
  unsigned int opb = info->octets_per_byte;
nkeynes@362
    34
  unsigned int end_addr_offset = length / opb;
nkeynes@362
    35
  unsigned int max_addr_offset = info->buffer_length / opb; 
nkeynes@362
    36
  unsigned int octets = (memaddr - info->buffer_vma) * opb;
nkeynes@362
    37
nkeynes@362
    38
  if (memaddr < info->buffer_vma
nkeynes@362
    39
      || memaddr - info->buffer_vma + end_addr_offset > max_addr_offset)
nkeynes@362
    40
    /* Out of bounds.  Use EIO because GDB uses it.  */
nkeynes@362
    41
    return EIO;
nkeynes@362
    42
  memcpy (myaddr, info->buffer + octets, length);
nkeynes@362
    43
nkeynes@362
    44
  return 0;
nkeynes@362
    45
}
nkeynes@362
    46
nkeynes@362
    47
/* Print an error message.  We can assume that this is in response to
nkeynes@362
    48
   an error return from buffer_read_memory.  */
nkeynes@362
    49
void
nkeynes@362
    50
perror_memory (status, memaddr, info)
nkeynes@362
    51
     int status;
nkeynes@362
    52
     bfd_vma memaddr;
nkeynes@362
    53
     struct disassemble_info *info;
nkeynes@362
    54
{
nkeynes@362
    55
  if (status != EIO)
nkeynes@362
    56
    /* Can't happen.  */
nkeynes@362
    57
    info->fprintf_func (info->stream, _("Unknown error %d\n"), status);
nkeynes@362
    58
  else
nkeynes@362
    59
    {
nkeynes@362
    60
      char buf[30];
nkeynes@362
    61
nkeynes@362
    62
      /* Actually, address between memaddr and memaddr + len was
nkeynes@362
    63
	 out of bounds.  */
nkeynes@362
    64
      sprintf_vma (buf, memaddr);
nkeynes@362
    65
      info->fprintf_func (info->stream,
nkeynes@362
    66
			  _("Address 0x%s is out of bounds.\n"), buf);
nkeynes@362
    67
    }
nkeynes@362
    68
}
nkeynes@362
    69
nkeynes@362
    70
/* This could be in a separate file, to save miniscule amounts of space
nkeynes@362
    71
   in statically linked executables.  */
nkeynes@362
    72
nkeynes@362
    73
/* Just print the address is hex.  This is included for completeness even
nkeynes@362
    74
   though both GDB and objdump provide their own (to print symbolic
nkeynes@362
    75
   addresses).  */
nkeynes@362
    76
nkeynes@362
    77
void
nkeynes@362
    78
generic_print_address (addr, info)
nkeynes@362
    79
     bfd_vma addr;
nkeynes@362
    80
     struct disassemble_info *info;
nkeynes@362
    81
{
nkeynes@362
    82
  char buf[30];
nkeynes@362
    83
nkeynes@362
    84
  sprintf_vma (buf, addr);
nkeynes@362
    85
  (*info->fprintf_func) (info->stream, "0x%s", buf);
nkeynes@362
    86
}
nkeynes@362
    87
nkeynes@362
    88
#if 0
nkeynes@362
    89
/* Just concatenate the address as hex.  This is included for
nkeynes@362
    90
   completeness even though both GDB and objdump provide their own (to
nkeynes@362
    91
   print symbolic addresses).  */
nkeynes@362
    92
nkeynes@362
    93
void generic_strcat_address PARAMS ((bfd_vma, char *, int));
nkeynes@362
    94
nkeynes@362
    95
void
nkeynes@362
    96
generic_strcat_address (addr, buf, len)
nkeynes@362
    97
     bfd_vma addr;
nkeynes@362
    98
     char *buf;
nkeynes@362
    99
     int len;
nkeynes@362
   100
{
nkeynes@362
   101
  if (buf != (char *)NULL && len > 0)
nkeynes@362
   102
    {
nkeynes@362
   103
      char tmpBuf[30];
nkeynes@362
   104
nkeynes@362
   105
      sprintf_vma (tmpBuf, addr);
nkeynes@362
   106
      if ((strlen (buf) + strlen (tmpBuf)) <= (unsigned int) len)
nkeynes@362
   107
	strcat (buf, tmpBuf);
nkeynes@362
   108
      else
nkeynes@362
   109
	strncat (buf, tmpBuf, (len - strlen(buf)));
nkeynes@362
   110
    }
nkeynes@362
   111
  return;
nkeynes@362
   112
}
nkeynes@362
   113
#endif
nkeynes@362
   114
nkeynes@362
   115
/* Just return true.  */
nkeynes@362
   116
nkeynes@362
   117
int
nkeynes@362
   118
generic_symbol_at_address (addr, info)
nkeynes@362
   119
     bfd_vma addr ATTRIBUTE_UNUSED;
nkeynes@362
   120
     struct disassemble_info *info ATTRIBUTE_UNUSED;
nkeynes@362
   121
{
nkeynes@362
   122
  return 1;
nkeynes@362
   123
}
nkeynes@362
   124
nkeynes@362
   125
/* Just return TRUE.  */
nkeynes@362
   126
nkeynes@362
   127
bfd_boolean
nkeynes@362
   128
generic_symbol_is_valid (asymbol * sym ATTRIBUTE_UNUSED,
nkeynes@362
   129
			 struct disassemble_info *info ATTRIBUTE_UNUSED)
nkeynes@362
   130
{
nkeynes@362
   131
  return TRUE;
nkeynes@362
   132
}
.