/* Disassemble support for GDB.
- Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010,
- 2011 Free Software Foundation, Inc.
+ Copyright (C) 2000-2014 Free Software Foundation, Inc.
This file is part of GDB.
#include "target.h"
#include "value.h"
#include "ui-out.h"
-#include "gdb_string.h"
+#include <string.h>
#include "disasm.h"
#include "gdbcore.h"
#include "dis-asm.h"
dis_asm_read_memory (bfd_vma memaddr, gdb_byte *myaddr, unsigned int len,
struct disassemble_info *info)
{
- return target_read_memory (memaddr, myaddr, len);
+ return target_read_code (memaddr, myaddr, len);
}
/* Like memory_error with slightly different parameters. */
mle1 = (struct dis_line_entry *) mle1p;
mle2 = (struct dis_line_entry *) mle2p;
- val = mle1->line - mle2->line;
-
- if (val != 0)
- return val;
-
- return mle1->start_pc - mle2->start_pc;
+ /* End of sequence markers have a line number of 0 but don't want to
+ be sorted to the head of the list, instead sort by PC. */
+ if (mle1->line == 0 || mle2->line == 0)
+ {
+ val = mle1->start_pc - mle2->start_pc;
+ if (val == 0)
+ val = mle1->line - mle2->line;
+ }
+ else
+ {
+ val = mle1->line - mle2->line;
+ if (val == 0)
+ val = mle1->start_pc - mle2->start_pc;
+ }
+ return val;
}
static int
dump_insns (struct gdbarch *gdbarch, struct ui_out *uiout,
struct disassemble_info * di,
CORE_ADDR low, CORE_ADDR high,
- int how_many, int flags, struct ui_stream *stb)
+ int how_many, int flags, struct ui_file *stb)
{
int num_displayed = 0;
CORE_ADDR pc;
num_displayed++;
}
ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
- ui_out_text (uiout, pc_prefix (pc));
+
+ if ((flags & DISASSEMBLY_OMIT_PC) == 0)
+ ui_out_text (uiout, pc_prefix (pc));
ui_out_field_core_addr (uiout, "address", gdbarch, pc);
if (!build_address_symbolic (gdbarch, pc, 0, &name, &offset, &filename,
if (name != NULL)
xfree (name);
- ui_file_rewind (stb->stream);
+ ui_file_rewind (stb);
if (flags & DISASSEMBLY_RAW_INSN)
{
CORE_ADDR old_pc = pc;
bfd_byte data;
int status;
+ const char *spacer = "";
+
+ /* Build the opcodes using a temporary stream so we can
+ write them out in a single go for the MI. */
+ struct ui_file *opcode_stream = mem_fileopen ();
+ struct cleanup *cleanups =
+ make_cleanup_ui_file_delete (opcode_stream);
pc += gdbarch_print_insn (gdbarch, pc, di);
for (;old_pc < pc; old_pc++)
status = (*di->read_memory_func) (old_pc, &data, 1, di);
if (status != 0)
(*di->memory_error_func) (status, old_pc, di);
- ui_out_message (uiout, 0, " %02x", (unsigned)data);
+ fprintf_filtered (opcode_stream, "%s%02x",
+ spacer, (unsigned) data);
+ spacer = " ";
}
+ ui_out_field_stream (uiout, "opcodes", opcode_stream);
ui_out_text (uiout, "\t");
+
+ do_cleanups (cleanups);
}
else
pc += gdbarch_print_insn (gdbarch, pc, di);
ui_out_field_stream (uiout, "inst", stb);
- ui_file_rewind (stb->stream);
+ ui_file_rewind (stb);
do_cleanups (ui_out_chain);
ui_out_text (uiout, "\n");
}
struct linetable_entry *le,
CORE_ADDR low, CORE_ADDR high,
struct symtab *symtab,
- int how_many, int flags, struct ui_stream *stb)
+ int how_many, int flags, struct ui_file *stb)
{
int newlines = 0;
struct dis_line_entry *mle;
int out_of_order = 0;
int next_line = 0;
int num_displayed = 0;
+ enum print_source_lines_flags psl_flags = 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);
+ if (flags & DISASSEMBLY_FILENAME)
+ psl_flags |= PRINT_SOURCE_LINES_FILENAME;
+
mle = (struct dis_line_entry *) alloca (nlines
* sizeof (struct dis_line_entry));
ui_out_tuple_chain
= make_cleanup_ui_out_tuple_begin_end (uiout,
"src_and_asm_line");
- print_source_lines (symtab, next_line, mle[i].line + 1, 0);
+ print_source_lines (symtab, next_line, mle[i].line + 1, psl_flags);
}
else
{
= make_cleanup_ui_out_tuple_begin_end (uiout,
"src_and_asm_line");
print_source_lines (symtab, next_line, next_line + 1,
- 0);
+ psl_flags);
ui_out_list_chain_line
= make_cleanup_ui_out_list_begin_end (uiout,
"line_asm_insn");
ui_out_tuple_chain
= make_cleanup_ui_out_tuple_begin_end (uiout,
"src_and_asm_line");
- print_source_lines (symtab, next_line, mle[i].line + 1, 0);
+ print_source_lines (symtab, next_line, mle[i].line + 1, psl_flags);
}
}
else
ui_out_tuple_chain
= make_cleanup_ui_out_tuple_begin_end (uiout,
"src_and_asm_line");
- print_source_lines (symtab, mle[i].line, mle[i].line + 1, 0);
+ print_source_lines (symtab, mle[i].line, mle[i].line + 1, psl_flags);
}
next_line = mle[i].line + 1;
do_assembly_only (struct gdbarch *gdbarch, struct ui_out *uiout,
struct disassemble_info * di,
CORE_ADDR low, CORE_ADDR high,
- int how_many, int flags, struct ui_stream *stb)
+ int how_many, int flags, struct ui_file *stb)
{
int num_displayed = 0;
struct cleanup *ui_out_chain;
return 0;
}
-static struct disassemble_info
+struct disassemble_info
gdb_disassemble_info (struct gdbarch *gdbarch, struct ui_file *file)
{
struct disassemble_info di;
char *file_string, int flags, 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 (gdbarch, stb->stream);
+ struct ui_file *stb = mem_fileopen ();
+ struct cleanup *cleanups = make_cleanup_ui_file_delete (stb);
+ struct disassemble_info di = gdb_disassemble_info (gdbarch, stb);
/* To collect the instruction outputted from opcodes. */
struct symtab *symtab = NULL;
struct linetable_entry *le = NULL;