1 /* Disassemble from a buffer, for GNU.
2 Copyright (C) 1993-2016 Free Software Foundation, Inc.
4 This file is part of the GNU opcodes library.
6 This library is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
11 It is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
14 License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19 MA 02110-1301, USA. */
26 /* Get LENGTH bytes from info's buffer, at target address memaddr.
27 Transfer them to myaddr. */
29 buffer_read_memory (bfd_vma memaddr
,
32 struct disassemble_info
*info
)
34 unsigned int opb
= info
->octets_per_byte
;
35 unsigned int end_addr_offset
= length
/ opb
;
36 unsigned int max_addr_offset
= info
->buffer_length
/ opb
;
37 unsigned int octets
= (memaddr
- info
->buffer_vma
) * opb
;
39 if (memaddr
< info
->buffer_vma
40 || memaddr
- info
->buffer_vma
> max_addr_offset
41 || memaddr
- info
->buffer_vma
+ end_addr_offset
> max_addr_offset
42 || (info
->stop_vma
&& (memaddr
>= info
->stop_vma
43 || memaddr
+ end_addr_offset
> info
->stop_vma
)))
44 /* Out of bounds. Use EIO because GDB uses it. */
46 memcpy (myaddr
, info
->buffer
+ octets
, length
);
51 /* Print an error message. We can assume that this is in response to
52 an error return from buffer_read_memory. */
55 perror_memory (int status
,
57 struct disassemble_info
*info
)
61 info
->fprintf_func (info
->stream
, _("Unknown error %d\n"), status
);
66 /* Actually, address between memaddr and memaddr + len was
68 sprintf_vma (buf
, memaddr
);
69 info
->fprintf_func (info
->stream
,
70 _("Address 0x%s is out of bounds.\n"), buf
);
74 /* This could be in a separate file, to save miniscule amounts of space
75 in statically linked executables. */
77 /* Just print the address is hex. This is included for completeness even
78 though both GDB and objdump provide their own (to print symbolic
82 generic_print_address (bfd_vma addr
, struct disassemble_info
*info
)
86 sprintf_vma (buf
, addr
);
87 (*info
->fprintf_func
) (info
->stream
, "0x%s", buf
);
90 /* Just return true. */
93 generic_symbol_at_address (bfd_vma addr ATTRIBUTE_UNUSED
,
94 struct disassemble_info
*info ATTRIBUTE_UNUSED
)
99 /* Just return TRUE. */
102 generic_symbol_is_valid (asymbol
* sym ATTRIBUTE_UNUSED
,
103 struct disassemble_info
*info ATTRIBUTE_UNUSED
)