/* Disassemble support for GDB.
- Copyright 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
+ Copyright 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
This file is part of GDB.
#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)
+ struct disassemble_info *info)
{
return target_read_memory (memaddr, (char *) 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)
{
ui_out_field_int (uiout, "offset", offset);
ui_out_text (uiout, ">:\t");
}
+ else
+ ui_out_text (uiout, ":\t");
+
if (filename != NULL)
xfree (filename);
if (name != NULL)
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)
{
do_cleanups (ui_out_chain);
}
-void
-gdb_disassembly (struct ui_out *uiout,
- char *file_string,
- int line_num,
- int mixed_source_and_assembly,
- int how_many, CORE_ADDR low, CORE_ADDR high)
+/* Initialize the disassemble info struct ready for the specified
+ stream. */
+
+static int
+fprintf_disasm (void *stream, const char *format, ...)
{
- struct ui_stream *stb = ui_out_stream_new (uiout);
- struct cleanup *cleanups = make_cleanup_ui_out_stream_delete (stb);
- disassemble_info di;
- /* To collect the instruction outputted from opcodes. */
- struct symtab *symtab = NULL;
- struct linetable_entry *le = NULL;
- int nlines = -1;
+ va_list args;
+ va_start (args, format);
+ vfprintf_filtered (stream, format, args);
+ va_end (args);
+ /* Something non -ve. */
+ return 0;
+}
- INIT_DISASSEMBLE_INFO_NO_ARCH (di, stb->stream,
- (fprintf_ftype) fprintf_unfiltered);
+static struct disassemble_info
+gdb_disassemble_info (struct gdbarch *gdbarch, struct ui_file *file)
+{
+ 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;
di.print_address_func = dis_asm_print_address;
/* 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
(although that should be superseeded by target_trust..._p()). */
di.read_memory_func = dis_asm_read_memory;
- di.mach = gdbarch_bfd_arch_info (current_gdbarch)->mach;
- di.endian = gdbarch_byte_order (current_gdbarch);
+ 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;
+}
+
+void
+gdb_disassembly (struct ui_out *uiout,
+ char *file_string,
+ int line_num,
+ int mixed_source_and_assembly,
+ int how_many, CORE_ADDR low, CORE_ADDR high)
+{
+ struct ui_stream *stb = ui_out_stream_new (uiout);
+ struct cleanup *cleanups = make_cleanup_ui_out_stream_delete (stb);
+ 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;
+ int nlines = -1;
/* Assume symtab is valid for whole PC range */
symtab = find_pc_symtab (low);
gdb_flush (gdb_stdout);
}
-\f
-/* FIXME: cagney/2003-04-28: This global deprecated_tm_print_insn_info
- is going away. */
-disassemble_info deprecated_tm_print_insn_info;
+/* Print the instruction at address MEMADDR in debugged memory,
+ on STREAM. Returns length of the instruction, in bytes. */
-extern void _initialize_disasm (void);
-
-void
-_initialize_disasm (void)
+int
+gdb_print_insn (CORE_ADDR memaddr, struct ui_file *stream)
{
- INIT_DISASSEMBLE_INFO_NO_ARCH (deprecated_tm_print_insn_info, gdb_stdout,
- (fprintf_ftype)fprintf_filtered);
- deprecated_tm_print_insn_info.flavour = bfd_target_unknown_flavour;
- deprecated_tm_print_insn_info.read_memory_func = dis_asm_read_memory;
- deprecated_tm_print_insn_info.memory_error_func = dis_asm_memory_error;
- deprecated_tm_print_insn_info.print_address_func = dis_asm_print_address;
+ struct disassemble_info di = gdb_disassemble_info (current_gdbarch, stream);
+ return TARGET_PRINT_INSN (memaddr, &di);
}