]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
sim: clean up bfd_vma printing
authorMike Frysinger <vapier@gentoo.org>
Tue, 4 May 2021 03:27:16 +0000 (23:27 -0400)
committerMike Frysinger <vapier@gentoo.org>
Tue, 4 May 2021 12:13:45 +0000 (08:13 -0400)
A lot of this code predates the bfd_vma format define, so we have a
random mix of casts to known types so we can printf the value.  Use
the BFD_VMA_FMT that now exists to simplify and reliability output
across different build configs.

18 files changed:
sim/common/ChangeLog
sim/common/cgen-trace.c
sim/common/sim-load.c
sim/cr16/ChangeLog
sim/cr16/interp.c
sim/cris/ChangeLog
sim/cris/sim-if.c
sim/d10v/ChangeLog
sim/d10v/d10v_sim.h
sim/d10v/interp.c
sim/erc32/ChangeLog
sim/erc32/func.c
sim/m32c/ChangeLog
sim/m32c/load.c
sim/rl78/ChangeLog
sim/rl78/load.c
sim/rx/ChangeLog
sim/rx/load.c

index 17b711c965e4726355b6a0f20dbd187f4aa6543f..783449941b286620640f8fc4b4b2bcd1b0050c07 100644 (file)
@@ -1,3 +1,10 @@
+2021-05-04  Mike Frysinger  <vapier@gentoo.org>
+
+       * cgen-trace.c (sim_disasm_perror_memory): Use BFD_VMA_FMT and drop
+       cast.
+       * sim-load.c (xprintf_bfd_vma): Delete.
+       (sim_load_file): Delete xprintf_bfd_vma calls.  Use BFD_VMA_FMT.
+
 2021-05-03  Simon Marchi  <simon.marchi@polymtl.ca>
 
        * hw-events.h (hw_event_queue_schedule_tracef): Use format attribute.
index 0f18c502c637f03c136b5fe18b70f7db6521ba25..649c37a61b1c0de44395f5265edcc2ae01b28d49 100644 (file)
@@ -340,8 +340,8 @@ sim_disasm_perror_memory (int status, bfd_vma memaddr,
     /* Actually, address between memaddr and memaddr + len was
        out of bounds.  */
     info->fprintf_func (info->stream,
-                       "Address 0x%x is out of bounds.",
-                       (int) memaddr);
+                       "Address 0x%" BFD_VMA_FMT "x is out of bounds.",
+                       memaddr);
 }
 
 /* Disassemble using the CGEN opcode table.
index e0aab1e9eb49d5ade1cf9bc17ece8bca5f7bce96..04681c524a0cd30f3a5319ecd9064925fd986ad7 100644 (file)
@@ -38,7 +38,6 @@ static void eprintf (host_callback *, const char *, ...);
 static void xprintf (host_callback *, const char *, ...);
 static void report_transfer_performance
   (host_callback *, unsigned long, time_t, time_t);
-static void xprintf_bfd_vma (host_callback *, bfd_vma);
 
 /* Load program PROG into the simulator using the function DO_LOAD.
    If PROG_BFD is non-NULL, the file has already been opened.
@@ -122,12 +121,12 @@ sim_load_file (SIM_DESC sd, const char *myname, host_callback *callback,
                lma = bfd_section_vma (s);
              if (verbose_p)
                {
-                 xprintf (callback, "Loading section %s, size 0x%lx %s ",
+                 xprintf (callback,
+                          "Loading section %s, size 0x%lx %s "
+                          "%" BFD_VMA_FMT "x\n",
                           bfd_section_name (s),
                           (unsigned long) size,
-                          (lma_p ? "lma" : "vma"));
-                 xprintf_bfd_vma (callback, lma);
-                 xprintf (callback, "\n");
+                          (lma_p ? "lma" : "vma"), lma);
                }
              data_count += size;
              bfd_get_section_contents (result_bfd, s, buffer, 0, size);
@@ -149,9 +148,8 @@ sim_load_file (SIM_DESC sd, const char *myname, host_callback *callback,
   if (verbose_p)
     {
       end_time = time (NULL);
-      xprintf (callback, "Start address ");
-      xprintf_bfd_vma (callback, bfd_get_start_address (result_bfd));
-      xprintf (callback, "\n");
+      xprintf (callback, "Start address %" BFD_VMA_FMT "x\n",
+              bfd_get_start_address (result_bfd));
       report_transfer_performance (callback, data_count, start_time, end_time);
     }
 
@@ -198,13 +196,3 @@ report_transfer_performance (host_callback *callback, unsigned long data_count,
     xprintf (callback, "%ld bits in <1 sec", (data_count * 8));
   xprintf (callback, ".\n");
 }
-
-/* Print a bfd_vma.
-   This is intended to handle the vagaries of 32 vs 64 bits, etc.  */
-
-static void
-xprintf_bfd_vma (host_callback *callback, bfd_vma vma)
-{
-  /* FIXME: for now */
-  xprintf (callback, "0x%lx", (unsigned long) vma);
-}
index 654b4e0987ec991f530dd708061a4c047355e0ec..ebf601fe9b9dfb556f489767de95bcf824b75b03 100644 (file)
@@ -1,3 +1,7 @@
+2021-05-04  Mike Frysinger  <vapier@gentoo.org>
+
+       * interp.c (sim_create_inferior): Use BFD_VMA_FMT and drop cast.
+
 2021-05-01  Mike Frysinger  <vapier@gentoo.org>
 
        * config.in, configure: Regenerate.
index 46150069a383e08df37659870141ac8f6e04fa97..8f7fafa715e9ff082df382ba69ad86b8cb8d82f8 100644 (file)
@@ -672,7 +672,8 @@ sim_create_inferior (SIM_DESC sd, struct bfd *abfd,
     start_address = 0x0;
 #ifdef DEBUG
   if (cr16_debug)
-    sim_io_printf (sd, "sim_create_inferior:  PC=0x%lx\n", (long) start_address);
+    sim_io_printf (sd, "sim_create_inferior:  PC=0x%" BFD_VMA_FMT "x\n",
+                  start_address);
 #endif
   {
     SIM_CPU *cpu = STATE_CPU (sd, 0);
index 1ac455e561bc369426edb67b07d181e4daba63d5..49db6ef32b2d14f3b7c6132de44a0dc8dd4f436a 100644 (file)
@@ -1,3 +1,9 @@
+2021-05-04  Mike Frysinger  <vapier@gentoo.org>
+
+       * sim-if.c (cris_load_elf_file): Use BFD_VMA_FMT
+       (cris_handle_interpreter): Likewise.  Delete phaddr.
+       (sim_open): Use PRIx32.
+
 2021-05-01  Mike Frysinger  <vapier@gentoo.org>
 
        * config.in, configure: Regenerate.
index 9914912b156b32373c006d1690a64a736d48eaf4..edd7885caf703bed88b57d32badb9989cb4bc371 100644 (file)
@@ -257,14 +257,16 @@ cris_load_elf_file (SIM_DESC sd, struct bfd *abfd, sim_write_fn do_write)
       buf = xmalloc (phdr[i].p_filesz);
 
       if (verbose)
-       sim_io_printf (sd, "Loading segment at 0x%lx, size 0x%lx\n",
+       sim_io_printf (sd,
+                      "Loading segment at 0x%" BFD_VMA_FMT "x, size 0x%lx\n",
                       lma, phdr[i].p_filesz);
 
       if (bfd_seek (abfd, phdr[i].p_offset, SEEK_SET) != 0
          || (bfd_bread (buf, phdr[i].p_filesz, abfd) != phdr[i].p_filesz))
        {
          sim_io_eprintf (sd,
-                         "%s: could not read segment at 0x%lx, size 0x%lx\n",
+                         "%s: could not read segment at 0x%" BFD_VMA_FMT "x, "
+                         "size 0x%lx\n",
                          STATE_MY_NAME (sd), lma, phdr[i].p_filesz);
          free (buf);
          return FALSE;
@@ -273,7 +275,8 @@ cris_load_elf_file (SIM_DESC sd, struct bfd *abfd, sim_write_fn do_write)
       if (do_write (sd, lma, buf, phdr[i].p_filesz) != phdr[i].p_filesz)
        {
          sim_io_eprintf (sd,
-                         "%s: could not load segment at 0x%lx, size 0x%lx\n",
+                         "%s: could not load segment at 0x%" BFD_VMA_FMT "x, "
+                         "size 0x%lx\n",
                          STATE_MY_NAME (sd), lma, phdr[i].p_filesz);
          free (buf);
          return FALSE;
@@ -495,7 +498,6 @@ static bfd_boolean
 cris_handle_interpreter (SIM_DESC sd, struct bfd *abfd)
 {
   int i, n_hdrs;
-  bfd_vma phaddr;
   bfd_byte buf[4];
   char *interp = NULL;
   struct bfd *ibfd;
@@ -571,7 +573,7 @@ cris_handle_interpreter (SIM_DESC sd, struct bfd *abfd)
         memory area, so we go via a temporary area.  Luckily, the
         interpreter is supposed to be small, less than 0x40000
         bytes.  */
-      sim_do_commandf (sd, "memory region 0x%lx,0x%lx",
+      sim_do_commandf (sd, "memory region 0x%" BFD_VMA_FMT "x,0x%lx",
                       interp_load_addr, interpsiz);
 
       /* Now that memory for the interpreter is defined, load it.  */
@@ -885,8 +887,8 @@ sim_open (SIM_OPEN_KIND kind, host_callback *callback, struct bfd *abfd,
 
   /* Allocate core managed memory if none specified by user.  */
   if (sim_core_read_buffer (sd, NULL, read_map, &c, startmem, 1) == 0)
-    sim_do_commandf (sd, "memory region 0x%lx,0x%lx", startmem,
-                    endmem - startmem);
+    sim_do_commandf (sd, "memory region 0x%" PRIx32 "x,0x%" PRIu32 "x",
+                    startmem, endmem - startmem);
 
   /* Allocate simulator I/O managed memory if none specified by user.  */
   if (cris_have_900000xxif)
index ebe6cd3f1a9f76d3be371db23ced5ff201550234..bbf97d20318b1a95e488a2ee0a949cd17f2f0e89 100644 (file)
@@ -1,3 +1,8 @@
+2021-05-04  Mike Frysinger  <vapier@gentoo.org>
+
+       * d10v_sim.h (decode_pc): Delete.
+       * interp.c (sim_create_inferior): Use BFD_VMA_FMT.
+
 2021-05-01  Mike Frysinger  <vapier@gentoo.org>
 
        * config.in, configure: Regenerate.
index a3755bf3ccb9d47d9c6c029e5aed5c4e0948efd2..64f974f01dbcca66dbf55a0a5af34ffd6ef4148f 100644 (file)
@@ -444,7 +444,6 @@ while (0)
 
 extern uint8 *dmem_addr (SIM_DESC, SIM_CPU *, uint16 offset);
 extern uint8 *imem_addr (SIM_DESC, SIM_CPU *, uint32);
-extern bfd_vma decode_pc (void);
 
 #define        RB(x)   (*(dmem_addr (sd, cpu, x)))
 #define SB(addr,data)  ( RB(addr) = (data & 0xff))
index 90c171eda398b118f29d05994c04f02121784b60..86e566a79fb836fdcde6c7e21d274ac1eaf85df6 100644 (file)
@@ -1160,7 +1160,8 @@ sim_create_inferior (SIM_DESC sd, struct bfd *abfd,
     start_address = 0xffc0 << 2;
 #ifdef DEBUG
   if (d10v_debug)
-    sim_io_printf (sd, "sim_create_inferior:  PC=0x%lx\n", (long) start_address);
+    sim_io_printf (sd, "sim_create_inferior:  PC=0x%" BFD_VMA_FMT "x\n",
+                  start_address);
 #endif
   {
     SIM_CPU *cpu = STATE_CPU (sd, 0);
index 12398af899725b725913b1e5398750c16d11e56f..a6b142a6ec28a896712161892126b3aaa573fde1 100644 (file)
@@ -1,3 +1,7 @@
+2021-05-04  Mike Frysinger  <vapier@gentoo.org>
+
+       * func.c (bfd_load): Use BFD_VMA_FMT.
+
 2021-05-01  Mike Frysinger  <vapier@gentoo.org>
 
        * config.in, configure: Regenerate.
index c6dfa1927ad4b332d4168e9b20be50d9e35ad16c..52428e48350fc5d8ef7865d7bb609e09cc65628a 100644 (file)
@@ -1056,7 +1056,7 @@ bfd_load (const char *fname)
            section_size = bfd_section_size (section);
 
            if (sis_verbose)
-               printf("\nsection %s at 0x%08lx (0x%lx bytes)",
+               printf("\nsection %s at 0x%08" BFD_VMA_FMT "x (0x%lx bytes)",
                       section_name, section_address, section_size);
 
            /* Text, data or lit */
index e3393c9be662958ddd0edc59a5a69048c96dadd0..df06256098359fd9af279148443559cff7282f11 100644 (file)
@@ -1,3 +1,7 @@
+2021-05-04  Mike Frysinger  <vapier@gentoo.org>
+
+       * load.c (m32c_load): Use BFD_VMA_FMT and drop casts.
+
 2021-05-02  Mike Frysinger  <vapier@gentoo.org>
 
        * m32c.opc: Include ansidecl.h.
index 156a275ad31bf18b7ef933e56492e893df0b4ffd..86e774e3abe9dc4caa635b2d7b75595aad9fca3a 100644 (file)
@@ -97,8 +97,8 @@ m32c_load (bfd * prog)
 
          base = bfd_section_lma (s);
          if (verbose)
-           fprintf (stderr, "[load a=%08x s=%08x %s]\n",
-                    (int) base, (int) size, bfd_section_name (s));
+           fprintf (stderr, "[load a=%08" BFD_VMA_FMT "x s=%08x %s]\n",
+                    base, (int) size, bfd_section_name (s));
          buf = (char *) malloc (size);
          bfd_get_section_contents (prog, s, buf, 0, size);
          mem_put_blk (base, buf, size);
index 9d70041b907fd8939ab657be8e594f97a827cdb8..1be5181dc6d1bc43daeb635a8a8d3b047b0820eb 100644 (file)
@@ -1,3 +1,7 @@
+2021-05-04  Mike Frysinger  <vapier@gentoo.org>
+
+       * load.c (rl78_load): Use BFD_VMA_FMT and drop casts.
+
 2021-05-01  Mike Frysinger  <vapier@gentoo.org>
 
        * config.in, configure: Regenerate.
index f89b5e69c4be359087ec396a488354d5dc5c2be8..c137ba6e40e42ea430cea2ee7817da7700e37192 100644 (file)
@@ -128,12 +128,15 @@ rl78_load (bfd *prog, host_callback *callbacks, const char * const simname)
 
       base = p->p_paddr;
       if (verbose > 1)
-       fprintf (stderr, "[load segment: lma=%08x vma=%08x size=%08x]\n",
-                (int) base, (int) p->p_vaddr, (int) size);
+       fprintf (stderr,
+                "[load segment: lma=%08" BFD_VMA_FMT "x vma=%08x "
+                "size=%08" BFD_VMA_FMT "x]\n",
+                base, (int) p->p_vaddr, size);
       if (callbacks)
        xprintf (callbacks,
-                "Loading section %s, size %#lx lma %08lx vma %08lx\n",
-                find_section_name_by_offset (prog, p->p_offset),
+                "Loading section %s, size %#" BFD_VMA_FMT "x "
+                "lma %08" BFD_VMA_FMT "x vma %08lx\n",
+                find_section_name_by_offset (prog, p->p_offset),
                 size, base, p->p_vaddr);
 
       buf = xmalloc (size);
@@ -147,13 +150,16 @@ rl78_load (bfd *prog, host_callback *callbacks, const char * const simname)
 
       if (bfd_bread (buf, size, prog) != size)
        {
-         fprintf (stderr, "%s: Failed to read %lx bytes\n", simname, size);
+         fprintf (stderr, "%s: Failed to read %" BFD_VMA_FMT "x bytes\n",
+                  simname, size);
          continue;
        }
 
       if (base > 0xeffff || base + size > 0xeffff)
        {
-         fprintf (stderr, "%s, Can't load image to RAM/SFR space: 0x%lx - 0x%lx\n",
+         fprintf (stderr,
+                  "%s, Can't load image to RAM/SFR space: 0x%" BFD_VMA_FMT "x "
+                  "- 0x%" BFD_VMA_FMT "x\n",
                   simname, base, base+size);
          continue;
        }
index 4d7e93dabe92bdca980333b0c08afd5fa1752f65..21a8ff626cf19345216cf9fdc4f5772b193e59f5 100644 (file)
@@ -1,3 +1,7 @@
+2021-05-04  Mike Frysinger  <vapier@gentoo.org>
+
+       * load.c (rx_load): Use BFD_VMA_FMT and drop casts.
+
 2021-05-03  Simon Marchi  <simon.marchi@polymtl.ca>
 
        * trace.c (op_printf): Likewise.
index b4523e12ac75fb5920080968232e4c93c7e979a7..b04826f55c7f212839cc3bc575ab5df3f2dcfb97 100644 (file)
@@ -128,8 +128,10 @@ rx_load (bfd *prog, host_callback *callback)
 
       base = p->p_paddr;
       if (verbose > 1)
-       fprintf (stderr, "[load segment: lma=%08x vma=%08x size=%08x]\n",
-                (int) base, (int) p->p_vaddr, (int) size);
+       fprintf (stderr,
+                "[load segment: lma=%08" BFD_VMA_FMT "x vma=%08x "
+                "size=%08" BFD_VMA_FMT "x]\n",
+                base, (int) p->p_vaddr, size);
       if (callback)
        xprintf (callback,
                 "Loading section %s, size %#lx lma %08lx vma %08lx\n",
@@ -151,7 +153,7 @@ rx_load (bfd *prog, host_callback *callback)
        }
       if (bfd_bread (buf, size, prog) != size)
        {
-         fprintf (stderr, "Failed to read %lx bytes\n", (long) size);
+         fprintf (stderr, "Failed to read %" BFD_VMA_FMT "x bytes\n", size);
          continue;
        }