/* Disassemble support for GDB.
- Copyright 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
+ Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008
+ Free Software Foundation, Inc.
This file is part of GDB.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
+ the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA. */
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include "defs.h"
#include "target.h"
#include "gdb_string.h"
#include "disasm.h"
#include "gdbcore.h"
+#include "dis-asm.h"
/* Disassemble functions.
FIXME: We should get rid of all the duplicate code in gdb that does
/* Like target_read_memory, but slightly different parameters. */
static int
-dis_asm_read_memory (bfd_vma memaddr, bfd_byte *myaddr, unsigned int len,
- disassemble_info *info)
+dis_asm_read_memory (bfd_vma memaddr, gdb_byte *myaddr, unsigned int len,
+ struct disassemble_info *info)
{
- return target_read_memory (memaddr, (char *) myaddr, len);
+ return target_read_memory (memaddr, myaddr, len);
}
/* Like memory_error with slightly different parameters. */
static void
-dis_asm_memory_error (int status, bfd_vma memaddr, disassemble_info *info)
+dis_asm_memory_error (int status, bfd_vma memaddr,
+ struct disassemble_info *info)
{
memory_error (status, memaddr);
}
}
static int
-dump_insns (struct ui_out *uiout, disassemble_info * di,
+dump_insns (struct ui_out *uiout, struct disassemble_info * di,
CORE_ADDR low, CORE_ADDR high,
int how_many, struct ui_stream *stb)
{
xfree (name);
ui_file_rewind (stb->stream);
- pc += TARGET_PRINT_INSN (pc, di);
+ pc += gdbarch_print_insn (current_gdbarch, pc, di);
ui_out_field_stream (uiout, "inst", stb);
ui_file_rewind (stb->stream);
do_cleanups (ui_out_chain);
CORE_ADDR pc;
int num_displayed = 0;
struct cleanup *ui_out_chain;
+ struct cleanup *ui_out_tuple_chain = make_cleanup (null_cleanup, 0);
+ struct cleanup *ui_out_list_chain = make_cleanup (null_cleanup, 0);
mle = (struct dis_line_entry *) alloca (nlines
* sizeof (struct dis_line_entry));
for (i = 0; i < newlines; i++)
{
- struct cleanup *ui_out_tuple_chain = NULL;
- struct cleanup *ui_out_list_chain = NULL;
- int close_list = 1;
-
/* Print out everything from next_line to the current line. */
if (mle[i].line >= next_line)
{
next_line = mle[i].line + 1;
ui_out_list_chain
= make_cleanup_ui_out_list_begin_end (uiout, "line_asm_insn");
- /* Don't close the list if the lines are not in order. */
- if (i < (newlines - 1) && mle[i + 1].line <= mle[i].line)
- close_list = 0;
}
num_displayed += dump_insns (uiout, di, mle[i].start_pc, mle[i].end_pc,
how_many, stb);
- if (close_list)
+
+ /* When we've reached the end of the mle array, or we've seen the last
+ assembly range for this source line, close out the list/tuple. */
+ if (i == (newlines - 1) || mle[i + 1].line > mle[i].line)
{
do_cleanups (ui_out_list_chain);
do_cleanups (ui_out_tuple_chain);
+ ui_out_tuple_chain = make_cleanup (null_cleanup, 0);
+ ui_out_list_chain = make_cleanup (null_cleanup, 0);
ui_out_text (uiout, "\n");
- close_list = 0;
}
- if (how_many >= 0)
- if (num_displayed >= how_many)
- break;
+ if (how_many >= 0 && num_displayed >= how_many)
+ break;
}
do_cleanups (ui_out_chain);
}
static void
-do_assembly_only (struct ui_out *uiout, disassemble_info * di,
+do_assembly_only (struct ui_out *uiout, struct disassemble_info * di,
CORE_ADDR low, CORE_ADDR high,
int how_many, struct ui_stream *stb)
{
/* Initialize the disassemble info struct ready for the specified
stream. */
-static int
+static int ATTR_FORMAT (printf, 2, 3)
fprintf_disasm (void *stream, const char *format, ...)
{
va_list args;
return 0;
}
-static disassemble_info
+static struct disassemble_info
gdb_disassemble_info (struct gdbarch *gdbarch, struct ui_file *file)
{
- disassemble_info di;
+ struct disassemble_info di;
init_disassemble_info (&di, file, fprintf_disasm);
di.flavour = bfd_target_unknown_flavour;
di.memory_error_func = dis_asm_memory_error;
/* NOTE: cagney/2003-04-28: The original code, from the old Insight
disassembler had a local optomization here. By default it would
access the executable file, instead of the target memory (there
- was a growing list of exceptions though). Unfortunatly, the
+ was a growing list of exceptions though). Unfortunately, the
heuristic was flawed. Commands like "disassemble &variable"
didn't work as they relied on the access going to the target.
Further, it has been supperseeded by trust-read-only-sections
di.arch = gdbarch_bfd_arch_info (gdbarch)->arch;
di.mach = gdbarch_bfd_arch_info (gdbarch)->mach;
di.endian = gdbarch_byte_order (gdbarch);
+ disassemble_init_for_target (&di);
return di;
}
{
struct ui_stream *stb = ui_out_stream_new (uiout);
struct cleanup *cleanups = make_cleanup_ui_out_stream_delete (stb);
- disassemble_info di = gdb_disassemble_info (current_gdbarch, stb->stream);
+ struct disassemble_info di = gdb_disassemble_info (current_gdbarch, stb->stream);
/* To collect the instruction outputted from opcodes. */
struct symtab *symtab = NULL;
struct linetable_entry *le = NULL;
}
/* Print the instruction at address MEMADDR in debugged memory,
- on STREAM. Returns length of the instruction, in bytes. */
+ on STREAM. Returns the length of the instruction, in bytes,
+ and, if requested, the number of branch delay slot instructions. */
int
-gdb_print_insn (CORE_ADDR memaddr, struct ui_file *stream)
+gdb_print_insn (CORE_ADDR memaddr, struct ui_file *stream,
+ int *branch_delay_insns)
{
- disassemble_info di = gdb_disassemble_info (current_gdbarch, stream);
- return TARGET_PRINT_INSN (memaddr, &di);
+ struct disassemble_info di;
+ int length;
+
+ di = gdb_disassemble_info (current_gdbarch, stream);
+ length = gdbarch_print_insn (current_gdbarch, memaddr, &di);
+ if (branch_delay_insns)
+ {
+ if (di.insn_info_valid)
+ *branch_delay_insns = di.branch_delay_insns;
+ else
+ *branch_delay_insns = 0;
+ }
+ return length;
}