2003-04-30 Andrew Cagney <cagney@redhat.com>
[deliverable/binutils-gdb.git] / gdb / disasm.c
index 4ac22a27a6e46d01bf3180d25222a6c2cacf22ca..e46025573b4f7001e40d5847f1b1df7bfab70db9 100644 (file)
@@ -24,8 +24,8 @@
 #include "value.h"
 #include "ui-out.h"
 #include "gdb_string.h"
-
 #include "disasm.h"
+#include "gdbcore.h"
 
 /* Disassemble functions.
    FIXME: We should get rid of all the duplicate code in gdb that does
@@ -43,6 +43,28 @@ struct dis_line_entry
   CORE_ADDR end_pc;
 };
 
+/* 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)
+{
+  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)
+{
+  memory_error (status, memaddr);
+}
+
+/* Like print_address with slightly different parameters.  */
+static void
+dis_asm_print_address (bfd_vma addr, struct disassemble_info *info)
+{
+  print_address (addr, info->stream);
+}
+
 /* This variable determines where memory used for disassembly is read from. */
 int gdb_disassemble_from_exec = -1;
 
@@ -93,13 +115,15 @@ dump_insns (struct ui_out *uiout, disassemble_info * di,
 
   /* parts of the symbolic representation of the address */
   int unmapped;
-  char *filename = NULL;
-  char *name = NULL;
   int offset;
   int line;
+  struct cleanup *ui_out_chain;
 
   for (pc = low; pc < high;)
     {
+      char *filename = NULL;
+      char *name = NULL;
+
       QUIT;
       if (how_many >= 0)
        {
@@ -108,7 +132,7 @@ dump_insns (struct ui_out *uiout, disassemble_info * di,
          else
            num_displayed++;
        }
-      ui_out_tuple_begin (uiout, NULL);
+      ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
       ui_out_field_core_addr (uiout, "address", pc);
 
       if (!build_address_symbolic (pc, 0, &name, &offset, &filename,
@@ -131,7 +155,7 @@ dump_insns (struct ui_out *uiout, disassemble_info * di,
       pc += TARGET_PRINT_INSN (pc, di);
       ui_out_field_stream (uiout, "inst", stb);
       ui_file_rewind (stb->stream);
-      ui_out_tuple_end (uiout);
+      do_cleanups (ui_out_chain);
       ui_out_text (uiout, "\n");
     }
   return num_displayed;
@@ -157,6 +181,7 @@ do_mixed_source_and_assembly (struct ui_out *uiout,
   int next_line = 0;
   CORE_ADDR pc;
   int num_displayed = 0;
+  struct cleanup *ui_out_chain;
 
   mle = (struct dis_line_entry *) alloca (nlines
                                          * sizeof (struct dis_line_entry));
@@ -210,11 +235,14 @@ do_mixed_source_and_assembly (struct ui_out *uiout,
      they have been emitted before), followed by the assembly code
      for that line.  */
 
-  ui_out_list_begin (uiout, "asm_insns");
+  ui_out_chain = make_cleanup_ui_out_list_begin_end (uiout, "asm_insns");
 
   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)
        {
@@ -223,7 +251,9 @@ do_mixed_source_and_assembly (struct ui_out *uiout,
              /* Just one line to print. */
              if (next_line == mle[i].line)
                {
-                 ui_out_tuple_begin (uiout, "src_and_asm_line");
+                 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);
                }
              else
@@ -231,27 +261,38 @@ do_mixed_source_and_assembly (struct ui_out *uiout,
                  /* Several source lines w/o asm instructions associated. */
                  for (; next_line < mle[i].line; next_line++)
                    {
-                     ui_out_tuple_begin (uiout, "src_and_asm_line");
+                     struct cleanup *ui_out_list_chain_line;
+                     struct cleanup *ui_out_tuple_chain_line;
+                     
+                     ui_out_tuple_chain_line
+                       = make_cleanup_ui_out_tuple_begin_end (uiout,
+                                                              "src_and_asm_line");
                      print_source_lines (symtab, next_line, next_line + 1,
                                          0);
-                     ui_out_list_begin (uiout, "line_asm_insn");
-                     ui_out_list_end (uiout);
-                     ui_out_tuple_end (uiout);
+                     ui_out_list_chain_line
+                       = make_cleanup_ui_out_list_begin_end (uiout,
+                                                             "line_asm_insn");
+                     do_cleanups (ui_out_list_chain_line);
+                     do_cleanups (ui_out_tuple_chain_line);
                    }
                  /* Print the last line and leave list open for
                     asm instructions to be added. */
-                 ui_out_tuple_begin (uiout, "src_and_asm_line");
+                 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);
                }
            }
          else
            {
-             ui_out_tuple_begin (uiout, "src_and_asm_line");
+             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);
            }
 
          next_line = mle[i].line + 1;
-         ui_out_list_begin (uiout, "line_asm_insn");
+         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;
@@ -261,8 +302,8 @@ do_mixed_source_and_assembly (struct ui_out *uiout,
                                   how_many, stb);
       if (close_list)
        {
-         ui_out_list_end (uiout);
-         ui_out_tuple_end (uiout);
+         do_cleanups (ui_out_list_chain);
+         do_cleanups (ui_out_tuple_chain);
          ui_out_text (uiout, "\n");
          close_list = 0;
        }
@@ -270,7 +311,7 @@ do_mixed_source_and_assembly (struct ui_out *uiout,
        if (num_displayed >= how_many)
          break;
     }
-  ui_out_list_end (uiout);
+  do_cleanups (ui_out_chain);
 }
 
 
@@ -280,12 +321,13 @@ do_assembly_only (struct ui_out *uiout, disassemble_info * di,
                  int how_many, struct ui_stream *stb)
 {
   int num_displayed = 0;
+  struct cleanup *ui_out_chain;
 
-  ui_out_list_begin (uiout, "asm_insns");
+  ui_out_chain = make_cleanup_ui_out_list_begin_end (uiout, "asm_insns");
 
   num_displayed = dump_insns (uiout, di, low, high, how_many, stb);
 
-  ui_out_list_end (uiout);
+  do_cleanups (ui_out_chain);
 }
 
 void
@@ -319,11 +361,8 @@ gdb_disassembly (struct ui_out *uiout,
       di_initialized = 1;
     }
 
-  di.mach = TARGET_PRINT_INSN_INFO->mach;
-  if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
-    di.endian = BFD_ENDIAN_BIG;
-  else
-    di.endian = BFD_ENDIAN_LITTLE;
+  di.mach = gdbarch_bfd_arch_info (current_gdbarch)->mach;
+  di.endian = gdbarch_byte_order (current_gdbarch);
 
   /* If gdb_disassemble_from_exec == -1, then we use the following heuristic to
      determine whether or not to do disassembly from target memory or from the
@@ -342,7 +381,8 @@ gdb_disassembly (struct ui_out *uiout,
       if (strcmp (target_shortname, "child") == 0
          || strcmp (target_shortname, "procfs") == 0
          || strcmp (target_shortname, "vxprocess") == 0
-         || strstr (target_shortname, "-threads") != NULL)
+          || strcmp (target_shortname, "core") == 0
+         || strstr (target_shortname, "-thread") != NULL)
        gdb_disassemble_from_exec = 0;  /* It's a child process, read inferior mem */
       else
        gdb_disassemble_from_exec = 1;  /* It's remote, read the exec file */
@@ -373,3 +413,21 @@ gdb_disassembly (struct ui_out *uiout,
 
   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;
+
+extern void _initialize_disasm (void);
+
+void
+_initialize_disasm (void)
+{
+  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;
+}
This page took 0.026508 seconds and 4 git commands to generate.