Regenerate tree using Autoconf 2.64 and Automake 1.11.
[deliverable/binutils-gdb.git] / gdb / disasm.c
index 0a7c96c40d96a2f01d688dae79f3c4d924223048..6a1a31663c8e0352a9d0a84d2a5bc255da26601a 100644 (file)
@@ -1,13 +1,13 @@
 /* Disassemble support for GDB.
 
-   Copyright 2000, 2001, 2002, 2003, 2004, 2005
+   Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009
    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,
@@ -16,9 +16,7 @@
    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"
@@ -65,7 +63,8 @@ dis_asm_memory_error (int status, bfd_vma memaddr,
 static void
 dis_asm_print_address (bfd_vma addr, struct disassemble_info *info)
 {
-  print_address (addr, info->stream);
+  struct gdbarch *gdbarch = info->application_data;
+  print_address (gdbarch, addr, info->stream);
 }
 
 static int
@@ -86,9 +85,10 @@ compare_lines (const void *mle1p, const void *mle2p)
 }
 
 static int
-dump_insns (struct ui_out *uiout, struct disassemble_info * di,
+dump_insns (struct gdbarch *gdbarch, struct ui_out *uiout,
+           struct disassemble_info * di,
            CORE_ADDR low, CORE_ADDR high,
-           int how_many, struct ui_stream *stb)
+           int how_many, int flags, struct ui_stream *stb)
 {
   int num_displayed = 0;
   CORE_ADDR pc;
@@ -113,7 +113,7 @@ dump_insns (struct ui_out *uiout, struct disassemble_info * di,
            num_displayed++;
        }
       ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
-      ui_out_field_core_addr (uiout, "address", pc);
+      ui_out_field_core_addr (uiout, "address", gdbarch, pc);
 
       if (!build_address_symbolic (pc, 0, &name, &offset, &filename,
                                   &line, &unmapped))
@@ -135,7 +135,23 @@ dump_insns (struct ui_out *uiout, struct disassemble_info * di,
        xfree (name);
 
       ui_file_rewind (stb->stream);
-      pc += TARGET_PRINT_INSN (pc, di);
+      if (flags & DISASSEMBLY_RAW_INSN)
+        {
+          CORE_ADDR old_pc = pc;
+          bfd_byte data;
+          int status;
+          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);
+            }
+          ui_out_text (uiout, "\t");
+        }
+      else
+        pc += gdbarch_print_insn (gdbarch, pc, di);
       ui_out_field_stream (uiout, "inst", stb);
       ui_file_rewind (stb->stream);
       do_cleanups (ui_out_chain);
@@ -149,12 +165,12 @@ dump_insns (struct ui_out *uiout, struct disassemble_info * di,
    in source order, with (possibly) out of order assembly
    immediately following.  */
 static void
-do_mixed_source_and_assembly (struct ui_out *uiout,
+do_mixed_source_and_assembly (struct gdbarch *gdbarch, struct ui_out *uiout,
                              struct disassemble_info *di, int nlines,
                              struct linetable_entry *le,
                              CORE_ADDR low, CORE_ADDR high,
                              struct symtab *symtab,
-                             int how_many, struct ui_stream *stb)
+                             int how_many, int flags, struct ui_stream *stb)
 {
   int newlines = 0;
   struct dis_line_entry *mle;
@@ -276,8 +292,9 @@ do_mixed_source_and_assembly (struct ui_out *uiout,
            = make_cleanup_ui_out_list_begin_end (uiout, "line_asm_insn");
        }
 
-      num_displayed += dump_insns (uiout, di, mle[i].start_pc, mle[i].end_pc,
-                                  how_many, stb);
+      num_displayed += dump_insns (gdbarch, uiout, di,
+                                  mle[i].start_pc, mle[i].end_pc,
+                                  how_many, flags, stb);
 
       /* 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.  */
@@ -297,16 +314,18 @@ do_mixed_source_and_assembly (struct ui_out *uiout,
 
 
 static void
-do_assembly_only (struct ui_out *uiout, struct disassemble_info * di,
+do_assembly_only (struct gdbarch *gdbarch, struct ui_out *uiout,
+                 struct disassemble_info * di,
                  CORE_ADDR low, CORE_ADDR high,
-                 int how_many, struct ui_stream *stb)
+                 int how_many, int flags, struct ui_stream *stb)
 {
   int num_displayed = 0;
   struct cleanup *ui_out_chain;
 
   ui_out_chain = make_cleanup_ui_out_list_begin_end (uiout, "asm_insns");
 
-  num_displayed = dump_insns (uiout, di, low, high, how_many, stb);
+  num_displayed = dump_insns (gdbarch, uiout, di, low, high, how_many,
+                              flags, stb);
 
   do_cleanups (ui_out_chain);
 }
@@ -345,20 +364,21 @@ gdb_disassemble_info (struct gdbarch *gdbarch, struct ui_file *file)
   di.arch = gdbarch_bfd_arch_info (gdbarch)->arch;
   di.mach = gdbarch_bfd_arch_info (gdbarch)->mach;
   di.endian = gdbarch_byte_order (gdbarch);
+  di.endian_code = gdbarch_byte_order_for_code (gdbarch);
+  di.application_data = gdbarch;
   disassemble_init_for_target (&di);
   return di;
 }
 
 void
-gdb_disassembly (struct ui_out *uiout,
+gdb_disassembly (struct gdbarch *gdbarch, struct ui_out *uiout,
                char *file_string,
-               int line_num,
-               int mixed_source_and_assembly,
+               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 (current_gdbarch, stb->stream);
+  struct disassemble_info di = gdb_disassemble_info (gdbarch, stb->stream);
   /* To collect the instruction outputted from opcodes. */
   struct symtab *symtab = NULL;
   struct linetable_entry *le = NULL;
@@ -374,24 +394,37 @@ gdb_disassembly (struct ui_out *uiout,
       nlines = symtab->linetable->nitems;
     }
 
-  if (!mixed_source_and_assembly || nlines <= 0
+  if (!(flags & DISASSEMBLY_SOURCE) || nlines <= 0
       || symtab == NULL || symtab->linetable == NULL)
-    do_assembly_only (uiout, &di, low, high, how_many, stb);
+    do_assembly_only (gdbarch, uiout, &di, low, high, how_many, flags, stb);
 
-  else if (mixed_source_and_assembly)
-    do_mixed_source_and_assembly (uiout, &di, nlines, le, low,
-                                 high, symtab, how_many, stb);
+  else if (flags & DISASSEMBLY_SOURCE)
+    do_mixed_source_and_assembly (gdbarch, uiout, &di, nlines, le, low,
+                                 high, symtab, how_many, flags, stb);
 
   do_cleanups (cleanups);
   gdb_flush (gdb_stdout);
 }
 
 /* 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 (struct gdbarch *gdbarch, CORE_ADDR memaddr,
+               struct ui_file *stream, int *branch_delay_insns)
 {
-  struct 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 (gdbarch, stream);
+  length = gdbarch_print_insn (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;
 }
This page took 0.040656 seconds and 4 git commands to generate.