PowerPC64 .branch_lt address
[binutils-gdb.git] / sim / rx / trace.c
index 112b1b0c7aec66081053aedba21c35eb904baaa4..8d9293c4a6369b1cf23c92a553e168a46256becc 100644 (file)
@@ -1,6 +1,6 @@
 /* trace.c --- tracing output for the RX simulator.
 
-Copyright (C) 2005, 2007, 2008, 2009 Free Software Foundation, Inc.
+Copyright (C) 2005-2022 Free Software Foundation, Inc.
 Contributed by Red Hat, Inc.
 
 This file is part of the GNU simulators.
@@ -18,6 +18,8 @@ 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, see <http://www.gnu.org/licenses/>.  */
 
+/* This must come before any other includes.  */
+#include "defs.h"
 
 #include <stdio.h>
 #include <stdarg.h>
@@ -33,6 +35,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 #include "cpu.h"
 #include "mem.h"
 #include "load.h"
+#include "trace.h"
 
 static int
 sim_dis_read (bfd_vma memaddr, bfd_byte * ptr, unsigned int length,
@@ -80,7 +83,7 @@ remove_useless_symbols (asymbol ** symbols, long count)
 }
 
 static int
-compare_symbols (const PTR ap, const PTR bp)
+compare_symbols (const void *ap, const void *bp)
 {
   const asymbol *a = *(const asymbol **) ap;
   const asymbol *b = *(const asymbol **) bp;
@@ -94,7 +97,7 @@ compare_symbols (const PTR ap, const PTR bp)
 
 static char opbuf[1000];
 
-static int
+static int ATTRIBUTE_PRINTF (2, 3)
 op_printf (char *buf, char *fmt, ...)
 {
   int ret;
@@ -106,6 +109,18 @@ op_printf (char *buf, char *fmt, ...)
   return ret;
 }
 
+static int ATTRIBUTE_PRINTF (3, 4)
+op_styled_printf (char *buf, enum disassembler_style style, char *fmt, ...)
+{
+  int ret;
+  va_list ap;
+
+  va_start (ap, fmt);
+  ret = vsprintf (opbuf + strlen (opbuf), fmt, ap);
+  va_end (ap);
+  return ret;
+}
+
 static bfd *       current_bfd = NULL;
 static asymbol **  symtab = NULL;
 static int         symcount = 0;
@@ -138,8 +153,10 @@ load_file_and_line (const char *filename, int lineno)
       break;
   if (!f)
     {
+      FILE *file;
       int i;
       struct stat s;
+      size_t ret;
       const char *found_filename, *slash;
 
       found_filename = filename;
@@ -158,9 +175,9 @@ load_file_and_line (const char *filename, int lineno)
       files = f;
       f->filename = strdup (filename);
       f->data = (char *) malloc (s.st_size + 2);
-      FILE *file = fopen (found_filename, "rb");
-      fread (f->data, 1, s.st_size, file);
-      f->data[s.st_size] = 0;
+      file = fopen (found_filename, "rb");
+      ret = fread (f->data, 1, s.st_size, file);
+      f->data[ret] = 0;
       fclose (file);
 
       f->nlines = 1;
@@ -204,7 +221,7 @@ sim_get_current_source_location (const char **  pfilename,
 
       initted = 1;
       memset (& info, 0, sizeof (info));
-      INIT_DISASSEMBLE_INFO (info, stdout, op_printf);
+      INIT_DISASSEMBLE_INFO (info, stdout, op_printf, op_styled_printf);
       info.read_memory_func = sim_dis_read;
       info.arch = bfd_get_arch (current_bfd);
       info.mach = bfd_get_mach (current_bfd);
@@ -227,7 +244,7 @@ sim_get_current_source_location (const char **  pfilename,
          if (s->flags & SEC_CODE || code_section == 0)
            {
              code_section = s;
-             code_base = bfd_section_lma (current_bfd, s);
+             code_base = bfd_section_lma (s);
              break;
            }
        }
@@ -321,7 +338,13 @@ sim_disasm_one (void)
     }
 
   opbuf[0] = 0;
-  printf ("\033[33m%06x: ", mypc);
+#ifdef CYCLE_ACCURATE
+  printf ("\033[33m %04u %06x: ", (int)(regs.cycle_count % 10000), mypc);
+#else
+  printf ("\033[33m %06x: ", mypc);
+
+#endif
+
   max = print_insn_rx (mypc, & info);
 
   for (i = 0; i < max; i++)