ChangeLog entry for changes committed Monday, 5 Jan. Wrote this on Monday,
[deliverable/binutils-gdb.git] / gdb / d10v-tdep.c
index 3ac0572ef24e85b5b9ac7f458b601030ec5f3b36..9ca62a5980877e39f6c31164dc37374b2fb401a0 100644 (file)
@@ -1,14 +1,18 @@
-/* Target-dependent code for MItsubishi D10V, for GDB.
-   Copyright (C) 1996 Free Software Foundation, Inc.
+/* Target-dependent code for Mitsubishi D10V, for GDB.
+   Copyright (C) 1996, 1997 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
 (at your option) any later version.
+
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 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.  */
@@ -29,11 +33,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 #include "symfile.h"
 #include "objfiles.h"
 
-void d10v_frame_find_saved_regs PARAMS ((struct frame_info *fi, struct frame_saved_regs *fsr));
+void d10v_frame_find_saved_regs PARAMS ((struct frame_info *fi,
+                                        struct frame_saved_regs *fsr));
 static void d10v_pop_dummy_frame PARAMS ((struct frame_info *fi));
 
-/* Discard from the stack the innermost frame,
-   restoring all saved registers.  */
+/* Discard from the stack the innermost frame, restoring all saved
+   registers.  */
 
 void
 d10v_pop_frame ()
@@ -131,7 +136,7 @@ d10v_skip_prologue (pc)
   if (find_pc_partial_function (pc, NULL, &func_addr, &func_end))
     {
       sal = find_pc_line (func_addr, 0);
-      if (sal.end < func_end)
+      if ( sal.end && sal.end < func_end)
        return sal.end;
     }
   
@@ -436,13 +441,6 @@ show_regs (args, from_tty)
   printf_filtered ("A0-A1  %010llx %010llx\n",num1, num2);
 }
 
-void
-_initialize_d10v_tdep ()
-{
-  tm_print_insn = print_insn_d10v;
-  add_com ("regs", class_vars, show_regs, "Print all registers");
-} 
-
 static CORE_ADDR
 d10v_xlate_addr (addr)
      int addr;
@@ -651,5 +649,339 @@ d10v_extract_return_value (valtype, regbuf, valbuf)
      char regbuf[REGISTER_BYTES];
      char *valbuf;
 {
- memcpy (valbuf, regbuf + REGISTER_BYTE (2), TYPE_LENGTH (valtype));
+  memcpy (valbuf, regbuf + REGISTER_BYTE (2), TYPE_LENGTH (valtype));
+}
+
+/* The following code implements access to, and display of, the D10V's
+   instruction trace buffer.  The buffer consists of 64K or more
+   4-byte words of data, of which each words includes an 8-bit count,
+   an 8-bit segment number, and a 16-bit instruction address.
+
+   In theory, the trace buffer is continuously capturing instruction
+   data that the CPU presents on its "debug bus", but in practice, the
+   ROMified GDB stub only enables tracing when it continues or steps
+   the program, and stops tracing when the program stops; so it
+   actually works for GDB to read the buffer counter out of memory and
+   then read each trace word.  The counter records where the tracing
+   stops, but there is no record of where it started, so we remember
+   the PC when we resumed and then search backwards in the trace
+   buffer for a word that includes that address.  This is not perfect,
+   because you will miss trace data if the resumption PC is the target
+   of a branch.  (The value of the buffer counter is semi-random, any
+   trace data from a previous program stop is gone.)  */
+
+/* The address of the last word recorded in the trace buffer.  */
+
+#define DBBC_ADDR (0xd80000)
+
+/* The base of the trace buffer, at least for the "Board_0".  */
+
+#define TRACE_BUFFER_BASE (0xf40000)
+
+static void trace_command PARAMS ((char *, int));
+
+static void untrace_command PARAMS ((char *, int));
+
+static void trace_info PARAMS ((char *, int));
+
+static void tdisassemble_command PARAMS ((char *, int));
+
+static void display_trace PARAMS ((int, int));
+
+/* True when instruction traces are being collected.  */
+
+static int tracing;
+
+/* Remembered PC.  */
+
+static CORE_ADDR last_pc;
+
+/* True when trace output should be displayed whenever program stops.  */
+
+static int trace_display;
+
+/* True when trace listing should include source lines.  */
+
+static int default_trace_show_source = 1;
+
+struct trace_buffer {
+  int size;
+  short *counts;
+  CORE_ADDR *addrs;
+} trace_data;
+
+static void
+trace_command (args, from_tty)
+     char *args;
+     int from_tty;
+{
+  /* Clear the host-side trace buffer, allocating space if needed.  */
+  trace_data.size = 0;
+  if (trace_data.counts == NULL)
+    trace_data.counts = (short *) xmalloc (65536 * sizeof(short));
+  if (trace_data.addrs == NULL)
+    trace_data.addrs = (CORE_ADDR *) xmalloc (65536 * sizeof(CORE_ADDR));
+
+  tracing = 1;
+
+  printf_filtered ("Tracing is now on.\n");
+}
+
+static void
+untrace_command (args, from_tty)
+     char *args;
+     int from_tty;
+{
+  tracing = 0;
+
+  printf_filtered ("Tracing is now off.\n");
+}
+
+static void
+trace_info (args, from_tty)
+     char *args;
+     int from_tty;
+{
+  int i;
+
+  if (trace_data.size)
+    {
+      printf_filtered ("%d entries in trace buffer:\n", trace_data.size);
+
+      for (i = 0; i < trace_data.size; ++i)
+       {
+         printf_filtered ("%d: %d instruction%s at 0x%x\n",
+                          i, trace_data.counts[i],
+                          (trace_data.counts[i] == 1 ? "" : "s"),
+                          trace_data.addrs[i]);
+       }
+    }
+  else
+    printf_filtered ("No entries in trace buffer.\n");
+
+  printf_filtered ("Tracing is currently %s.\n", (tracing ? "on" : "off"));
+}
+
+/* Print the instruction at address MEMADDR in debugged memory,
+   on STREAM.  Returns length of the instruction, in bytes.  */
+
+static int
+print_insn (memaddr, stream)
+     CORE_ADDR memaddr;
+     GDB_FILE *stream;
+{
+  /* If there's no disassembler, something is very wrong.  */
+  if (tm_print_insn == NULL)
+    abort ();
+
+  if (TARGET_BYTE_ORDER == BIG_ENDIAN)
+    tm_print_insn_info.endian = BFD_ENDIAN_BIG;
+  else
+    tm_print_insn_info.endian = BFD_ENDIAN_LITTLE;
+  return (*tm_print_insn) (memaddr, &tm_print_insn_info);
+}
+
+void
+d10v_eva_prepare_to_trace ()
+{
+  if (!tracing)
+    return;
+
+  last_pc = read_register (PC_REGNUM);
 }
+
+/* Collect trace data from the target board and format it into a form
+   more useful for display.  */
+
+void
+d10v_eva_get_trace_data ()
+{
+  int count, i, j, oldsize;
+  int trace_addr, trace_seg, trace_cnt, next_cnt;
+  unsigned int last_trace, trace_word, next_word;
+  unsigned int *tmpspace;
+
+  if (!tracing)
+    return;
+
+  tmpspace = xmalloc (65536 * sizeof(unsigned int));
+
+  last_trace = read_memory_unsigned_integer (DBBC_ADDR, 2) << 2;
+
+  /* Collect buffer contents from the target, stopping when we reach
+     the word recorded when execution resumed.  */
+
+  count = 0;
+  while (last_trace > 0)
+    {
+      QUIT;
+      trace_word =
+       read_memory_unsigned_integer (TRACE_BUFFER_BASE + last_trace, 4);
+      trace_addr = trace_word & 0xffff;
+      last_trace -= 4;
+      /* Ignore an apparently nonsensical entry.  */
+      if (trace_addr == 0xffd5)
+       continue;
+      tmpspace[count++] = trace_word;
+      if (trace_addr == last_pc)
+       break;
+      if (count > 65535)
+       break;
+    }
+
+  /* Move the data to the host-side trace buffer, adjusting counts to
+     include the last instruction executed and transforming the address
+     into something that GDB likes.  */
+
+  for (i = 0; i < count; ++i)
+    {
+      trace_word = tmpspace[i];
+      next_word = ((i == 0) ? 0 : tmpspace[i - 1]);
+      trace_addr = trace_word & 0xffff;
+      next_cnt = (next_word >> 24) & 0xff;
+      j = trace_data.size + count - i - 1;
+      trace_data.addrs[j] = (trace_addr << 2) + 0x1000000;
+      trace_data.counts[j] = next_cnt + 1;
+    }
+
+  oldsize = trace_data.size;
+  trace_data.size += count;
+
+  free (tmpspace);
+
+  if (trace_display)
+    display_trace (oldsize, trace_data.size);
+}
+
+static void
+tdisassemble_command (arg, from_tty)
+     char *arg;
+     int from_tty;
+{
+  int i, count;
+  CORE_ADDR low, high;
+  char *space_index;
+
+  if (!arg)
+    {
+      low = 0;
+      high = trace_data.size;
+    }
+  else if (!(space_index = (char *) strchr (arg, ' ')))
+    {
+      low = parse_and_eval_address (arg);
+      high = low + 5;
+    }
+  else
+    {
+      /* Two arguments.  */
+      *space_index = '\0';
+      low = parse_and_eval_address (arg);
+      high = parse_and_eval_address (space_index + 1);
+      if (high < low)
+       high = low;
+    }
+
+  printf_filtered ("Dump of trace from %d to %d:\n", low, high);
+
+  display_trace (low, high);
+
+  printf_filtered ("End of trace dump.\n");
+  gdb_flush (gdb_stdout);
+}
+
+static void
+display_trace (low, high)
+     int low, high;
+{
+  int i, count, trace_show_source, first, suppress;
+  CORE_ADDR next_address;
+
+  trace_show_source = default_trace_show_source;
+  if (!have_full_symbols () && !have_partial_symbols())
+    {
+      trace_show_source = 0;
+      printf_filtered ("No symbol table is loaded.  Use the \"file\" command.\n");
+      printf_filtered ("Trace will not display any source.\n");
+    }
+
+  first = 1;
+  suppress = 0;
+  for (i = low; i < high; ++i)
+    {
+      next_address = trace_data.addrs[i];
+      count = trace_data.counts[i]; 
+      while (count-- > 0)
+       {
+         QUIT;
+         if (trace_show_source)
+           {
+             struct symtab_and_line sal, sal_prev;
+
+             sal_prev = find_pc_line (next_address - 4, 0);
+             sal = find_pc_line (next_address, 0);
+
+             if (sal.symtab)
+               {
+                 if (first || sal.line != sal_prev.line)
+                   print_source_lines (sal.symtab, sal.line, sal.line + 1, 0);
+                 suppress = 0;
+               }
+             else
+               {
+                 if (!suppress)
+                   /* FIXME-32x64--assumes sal.pc fits in long.  */
+                   printf_filtered ("No source file for address %s.\n",
+                                    local_hex_string((unsigned long) sal.pc));
+                 suppress = 1;
+               }
+           }
+         first = 0;
+         print_address (next_address, gdb_stdout);
+         printf_filtered (":");
+         printf_filtered ("\t");
+         wrap_here ("    ");
+         next_address = next_address + print_insn (next_address, gdb_stdout);
+         printf_filtered ("\n");
+         gdb_flush (gdb_stdout);
+       }
+    }
+}
+
+extern void (*target_resume_hook) PARAMS ((void));
+extern void (*target_wait_loop_hook) PARAMS ((void));
+
+void
+_initialize_d10v_tdep ()
+{
+  tm_print_insn = print_insn_d10v;
+
+  target_resume_hook = d10v_eva_prepare_to_trace;
+  target_wait_loop_hook = d10v_eva_get_trace_data;
+
+  add_com ("regs", class_vars, show_regs, "Print all registers");
+
+  add_com ("trace", class_support, trace_command,
+          "Enable tracing of instruction execution.");
+
+  add_com ("untrace", class_support, untrace_command,
+          "Disable tracing of instruction execution.");
+
+  add_com ("tdisassemble", class_vars, tdisassemble_command,
+          "Disassemble the trace buffer.\n\
+Two optional arguments specify a range of trace buffer entries\n\
+as reported by info trace (NOT addresses!).");
+
+  add_info ("trace", trace_info,
+           "Display info about the trace data buffer.");
+
+  add_show_from_set (add_set_cmd ("tracedisplay", no_class,
+                                 var_integer, (char *)&trace_display,
+                                 "Set automatic display of trace.\n", &setlist),
+                    &showlist);
+  add_show_from_set (add_set_cmd ("tracesource", no_class,
+                                 var_integer, (char *)&default_trace_show_source,
+                                 "Set display of source code with trace.\n", &setlist),
+                    &showlist);
+
+} 
This page took 0.028337 seconds and 4 git commands to generate.