This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch rfc] Add gdb_print_insn (eliminate many tm_print_insn_info)


Hello,

This patch adds a second entry point (gdb_print_insn) into the disassembler. The new entry point makes it possible to replace things like:

TARGET_PRINT_INSN (addr, &deprecated_tm_print_insn_info);

with

gdb_print_insn (addr, stream);

Baring comment, I'll commit this in a few days,
Andrew
2003-05-01  Andrew Cagney  <cagney@redhat.com>

	* disasm.h (print_insn): Declare.
	* disasm.c (init_gdb_disassemble_info): New function.
	(gdb_disassembly): Call init_gdb_disassemble_info.
	(gdb_print_insn): New function.
	* v850-tdep.c (v850_scan_prologue): Call gdb_print_insn, instead
	of TARGET_PRINT_INSN.  Send debug info to "gdb_stdlog".
	* mcore-tdep.c: Include "disasm.h"
	(mcore_dump_insn): Call gdb_print_insn, instead of TARGET_PRINT_INSN.
	* d10v-tdep.c: Include "disasm.h".
	(display_trace): Call gdb_print_insn, instead of print_insn.
	(print_insn): Delete function.
	* printcmd.c: Include "disasm.h".
	(print_insn): Delete function.
	(print_formatted): Call gdb_print_insn, instead of print_insn.
	* Makefile.in (printcmd.o): Update dependencies.
	(mcore-tdep.o, d10v-tdep.o): Ditto.
	
Index: tui/ChangeLog
2003-04-28  Andrew Cagney  <cagney@redhat.com>

	* tuiDisassem.c (tui_disassemble): Call gdb_print_insn, instead of
	TARGET_PRINT_INSN.  Do not initialize a disassemble_info object.

Index: Makefile.in
===================================================================
RCS file: /cvs/src/src/gdb/Makefile.in,v
retrieving revision 1.371
diff -u -r1.371 Makefile.in
--- Makefile.in	30 Apr 2003 22:01:36 -0000	1.371
+++ Makefile.in	2 May 2003 00:39:34 -0000
@@ -1640,7 +1640,7 @@
 	$(gdb_string_h) $(value_h) $(inferior_h) $(dis_asm_h) $(symfile_h) \
 	$(objfiles_h) $(language_h) $(arch_utils_h) $(regcache_h) \
 	$(remote_h) $(floatformat_h) $(gdb_sim_d10v_h) $(sim_regno_h) \
-	$(gdb_assert_h)
+	$(gdb_assert_h) $(disasm_h)
 dbug-rom.o: dbug-rom.c $(defs_h) $(gdbcore_h) $(target_h) $(monitor_h) \
 	$(serial_h) $(regcache_h) $(m68k_tdep_h)
 dbxread.o: dbxread.c $(defs_h) $(gdb_string_h) $(gdb_obstack_h) \
@@ -1945,7 +1945,7 @@
 	$(gdb_string_h) $(regcache_h) $(serial_h)
 mcore-tdep.o: mcore-tdep.c $(defs_h) $(frame_h) $(symtab_h) $(value_h) \
 	$(gdbcmd_h) $(regcache_h) $(symfile_h) $(gdbcore_h) $(inferior_h) \
-	$(arch_utils_h) $(gdb_string_h)
+	$(arch_utils_h) $(gdb_string_h) $(disasm_h)
 mdebugread.o: mdebugread.c $(defs_h) $(symtab_h) $(gdbtypes_h) $(gdbcore_h) \
 	$(symfile_h) $(objfiles_h) $(gdb_obstack_h) $(buildsym_h) \
 	$(stabsread_h) $(complaints_h) $(demangle_h) $(gdb_assert_h) \
@@ -2061,7 +2061,7 @@
 	$(gdbtypes_h) $(value_h) $(language_h) $(expression_h) $(gdbcore_h) \
 	$(gdbcmd_h) $(target_h) $(breakpoint_h) $(demangle_h) $(valprint_h) \
 	$(annotate_h) $(symfile_h) $(objfiles_h) $(completer_h) $(ui_out_h) \
-	$(gdb_assert_h) $(block_h)
+	$(gdb_assert_h) $(block_h) $(disasm_h)
 proc-api.o: proc-api.c $(defs_h) $(gdbcmd_h) $(completer_h) $(gdb_wait_h) \
 	$(proc_utils_h)
 proc-events.o: proc-events.c $(defs_h)
Index: d10v-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/d10v-tdep.c,v
retrieving revision 1.111
diff -u -r1.111 d10v-tdep.c
--- d10v-tdep.c	1 May 2003 15:37:45 -0000	1.111
+++ d10v-tdep.c	2 May 2003 00:39:34 -0000
@@ -43,6 +43,7 @@
 #include "floatformat.h"
 #include "gdb/sim-d10v.h"
 #include "sim-regno.h"
+#include "disasm.h"
 
 #include "gdb_assert.h"
 
@@ -1361,8 +1362,7 @@
 	  printf_filtered (":");
 	  printf_filtered ("\t");
 	  wrap_here ("    ");
-	  next_address += TARGET_PRINT_INSN (next_address,
-					     &deprecated_tm_print_insn_info);
+	  next_address += gdb_print_insn (next_address, gdb_stdout);
 	  printf_filtered ("\n");
 	  gdb_flush (gdb_stdout);
 	}
Index: disasm.c
===================================================================
RCS file: /cvs/src/src/gdb/disasm.c,v
retrieving revision 1.8
diff -u -r1.8 disasm.c
--- disasm.c	1 May 2003 23:21:08 -0000	1.8
+++ disasm.c	2 May 2003 00:39:34 -0000
@@ -307,22 +307,14 @@
   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 disassemble_info
+gdb_disassemble_info (struct gdbarch *gdbarch, struct ui_file *file)
 {
-  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;
-
-  INIT_DISASSEMBLE_INFO_NO_ARCH (di, stb->stream,
+  INIT_DISASSEMBLE_INFO_NO_ARCH (di, file,
 				 (fprintf_ftype) fprintf_unfiltered);
   di.flavour = bfd_target_unknown_flavour;
   di.memory_error_func = dis_asm_memory_error;
@@ -336,8 +328,25 @@
      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.mach = gdbarch_bfd_arch_info (gdbarch)->mach;
+  di.endian = gdbarch_byte_order (gdbarch);
+  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);
+  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);
@@ -361,6 +370,16 @@
   gdb_flush (gdb_stdout);
 }
 
+/* Print the instruction at address MEMADDR in debugged memory,
+   on STREAM.  Returns length of the instruction, in bytes.  */
+
+int
+gdb_print_insn (CORE_ADDR memaddr, struct ui_file *stream)
+{
+  disassemble_info di = gdb_disassemble_info (current_gdbarch, stream);
+  return TARGET_PRINT_INSN (memaddr, &di);
+}
+
 
 /* FIXME: cagney/2003-04-28: This global deprecated_tm_print_insn_info
    is going away.  */
@@ -371,6 +390,7 @@
 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;
Index: disasm.h
===================================================================
RCS file: /cvs/src/src/gdb/disasm.h,v
retrieving revision 1.2
diff -u -r1.2 disasm.h
--- disasm.h	12 Apr 2003 17:41:25 -0000	1.2
+++ disasm.h	2 May 2003 00:39:34 -0000
@@ -28,4 +28,10 @@
 			     int line_num,
 			     int mixed_source_and_assembly,
 			     int how_many, CORE_ADDR low, CORE_ADDR high);
+
+/* Print the instruction at address MEMADDR in debugged memory, on
+   STREAM.  Returns length of the instruction, in bytes.  */
+
+extern int gdb_print_insn (CORE_ADDR memaddr, struct ui_file *stream);
+
 #endif
Index: mcore-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/mcore-tdep.c,v
retrieving revision 1.60
diff -u -r1.60 mcore-tdep.c
--- mcore-tdep.c	30 Apr 2003 22:01:37 -0000	1.60
+++ mcore-tdep.c	2 May 2003 00:39:34 -0000
@@ -28,6 +28,7 @@
 #include "inferior.h"
 #include "arch-utils.h"
 #include "gdb_string.h"
+#include "disasm.h"
 
 /* Functions declared and used only in this file */
 
@@ -163,7 +164,7 @@
     {
       printf_filtered ("MCORE:  %s %08x %08x ",
 		       commnt, (unsigned int) pc, (unsigned int) insn);
-      TARGET_PRINT_INSN (pc, &deprecated_tm_print_insn_info);
+      gdb_print_insn (pc, gdb_stdout);
       printf_filtered ("\n");
     }
 }
Index: printcmd.c
===================================================================
RCS file: /cvs/src/src/gdb/printcmd.c,v
retrieving revision 1.60
diff -u -r1.60 printcmd.c
--- printcmd.c	30 Apr 2003 22:01:37 -0000	1.60
+++ printcmd.c	2 May 2003 00:39:35 -0000
@@ -42,6 +42,7 @@
 #include "ui-out.h"
 #include "gdb_assert.h"
 #include "block.h"
+#include "disasm.h"
 
 extern int asm_demangle;	/* Whether to demangle syms in asm printouts */
 extern int addressprint;	/* Whether to print hex addresses in HLL " */
@@ -175,8 +176,6 @@
 
 static struct format_data decode_format (char **, int, int);
 
-static int print_insn (CORE_ADDR, struct ui_file *);
-
 static void sym_info (char *, int);
 
 
@@ -310,7 +309,7 @@
       /* We often wrap here if there are long symbolic names.  */
       wrap_here ("    ");
       next_address = VALUE_ADDRESS (val)
-	+ print_insn (VALUE_ADDRESS (val), stream);
+	+ gdb_print_insn (VALUE_ADDRESS (val), stream);
       next_section = VALUE_BFD_SECTION (val);
       break;
 
@@ -2239,31 +2238,6 @@
   }
   do_cleanups (old_cleanups);
 }
-
-/* Print the instruction at address MEMADDR in debugged memory,
-   on STREAM.  Returns length of the instruction, in bytes.  */
-
-/* FIXME: cagney/2003-04-28: Should instead be using the generic
-   disassembler but first need to clean that up and stop it trying to
-   access the exec file.  */
-
-static int
-print_insn (CORE_ADDR memaddr, struct ui_file *stream)
-{
-  if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
-    deprecated_tm_print_insn_info.endian = BFD_ENDIAN_BIG;
-  else
-    deprecated_tm_print_insn_info.endian = BFD_ENDIAN_LITTLE;
-
-  if (TARGET_ARCHITECTURE != NULL)
-    deprecated_tm_print_insn_info.mach = TARGET_ARCHITECTURE->mach;
-  /* else: should set .mach=0 but some disassemblers don't grok this */
-
-  deprecated_tm_print_insn_info.stream = stream;
-
-  return TARGET_PRINT_INSN (memaddr, &deprecated_tm_print_insn_info);
-}
-
 
 void
 _initialize_printcmd (void)
Index: v850-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/v850-tdep.c,v
retrieving revision 1.59
diff -u -r1.59 v850-tdep.c
--- v850-tdep.c	30 Apr 2003 22:01:38 -0000	1.59
+++ v850-tdep.c	2 May 2003 00:39:35 -0000
@@ -613,8 +613,8 @@
       int insn2 = -1; /* dummy value */
 
 #ifdef DEBUG
-      printf_filtered ("0x%.8lx ", (long) current_pc);
-      TARGET_PRINT_INSN (current_pc, &deprecated_tm_print_insn_info);
+      fprintf_filtered (gdb_stdlog, "0x%.8lx ", (long) current_pc);
+      gdb_print_insn (current_pc, gdb_stdlog);
 #endif
 
       insn = read_memory_unsigned_integer (current_pc, 2);
Index: tui/tuiDisassem.c
===================================================================
RCS file: /cvs/src/src/gdb/tui/tuiDisassem.c,v
retrieving revision 1.19
diff -u -r1.19 tuiDisassem.c
--- tui/tuiDisassem.c	30 Apr 2003 22:01:38 -0000	1.19
+++ tui/tuiDisassem.c	2 May 2003 00:39:36 -0000
@@ -68,26 +68,10 @@
 tui_disassemble (struct tui_asm_line* lines, CORE_ADDR pc, int count)
 {
   struct ui_file *gdb_dis_out;
-  disassemble_info asm_info;
 
   /* now init the ui_file structure */
   gdb_dis_out = tui_sfileopen (256);
 
-  /* FIXME: cagney/2003-04-28: Should instead be using the generic
-     disassembler but first need to clean that up and stop it trying
-     to access the exec file.  */
-
-  memcpy (&asm_info, &deprecated_tm_print_insn_info, sizeof (asm_info));
-  asm_info.stream = gdb_dis_out;
-
-  if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
-    asm_info.endian = BFD_ENDIAN_BIG;
-  else
-    asm_info.endian = BFD_ENDIAN_LITTLE;
-
-  if (TARGET_ARCHITECTURE != NULL)
-    asm_info.mach = TARGET_ARCHITECTURE->mach;
-
   /* Now construct each line */
   for (; count > 0; count--, lines++)
     {
@@ -102,7 +86,7 @@
 
       ui_file_rewind (gdb_dis_out);
 
-      pc = pc + TARGET_PRINT_INSN (pc, &asm_info);
+      pc = pc + gdb_print_insn (pc, gdb_dis_out);
 
       lines->insn = xstrdup (tui_file_get_strbuf (gdb_dis_out));
 

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]