]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb: make regcache::debug_print_register return a string
authorSimon Marchi <simon.marchi@efficios.com>
Fri, 19 Apr 2024 19:46:53 +0000 (15:46 -0400)
committerSimon Marchi <simon.marchi@polymtl.ca>
Fri, 19 Apr 2024 20:30:25 +0000 (16:30 -0400)
Rename the method to `register_debug_string`.

This makes it easier to introduce `target_debug_printf` in a subsequent
patch.

Change-Id: I5bb2d49476d17940d503e66f40762e3f1e3baabc
Approved-By: Tom Tromey <tom@tromey.com>
gdb/regcache.c
gdb/regcache.h
gdb/target.c

index b7abbe99f3cc5820812063816d7a58d4eebd8b75..c35a8138a39a9f3d8a9d7962ccf3bb04324602c1 100644 (file)
@@ -1463,36 +1463,38 @@ reg_buffer::num_raw_registers () const
   return gdbarch_num_regs (arch ());
 }
 
-void
-regcache::debug_print_register (const char *func,  int regno)
+std::string
+regcache::register_debug_string (int regno)
 {
   struct gdbarch *gdbarch = arch ();
+  std::string s;
 
-  gdb_printf (gdb_stdlog, "%s ", func);
   if (regno >= 0 && regno < gdbarch_num_regs (gdbarch)
       && gdbarch_register_name (gdbarch, regno)[0] != '\0')
-    gdb_printf (gdb_stdlog, "(%s)",
-               gdbarch_register_name (gdbarch, regno));
+    string_appendf (s, "register %s:", gdbarch_register_name (gdbarch, regno));
   else
-    gdb_printf (gdb_stdlog, "(%d)", regno);
+    string_appendf (s, "register %d:", regno);
+
   if (regno >= 0 && regno < gdbarch_num_regs (gdbarch))
     {
-      enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
       gdb::array_view<gdb_byte> buf = register_buffer (regno);
 
-      gdb_printf (gdb_stdlog, " = ");
+      string_appendf (s, " = ");
+
       for (gdb_byte byte : buf)
-       gdb_printf (gdb_stdlog, "%02x", byte);
+       string_appendf (s, "%02x", byte);
 
       if (buf.size () <= sizeof (LONGEST))
        {
-         ULONGEST val = extract_unsigned_integer (buf, byte_order);
+         ULONGEST val
+           = extract_unsigned_integer (buf, gdbarch_byte_order (gdbarch));
 
-         gdb_printf (gdb_stdlog, " %s %s",
-                     core_addr_to_string_nz (val), plongest (val));
+         string_appendf (s, " %s %s",
+                         core_addr_to_string_nz (val), plongest (val));
        }
     }
-  gdb_printf (gdb_stdlog, "\n");
+
+    return s;
 }
 
 /* Implement 'maint flush register-cache' command.  */
index 9ba6c79ab0d51d008bb392f3b6e71674b85746f1..1d049fe7ae8de794197076f9ede74fe8b9ab9ff4 100644 (file)
@@ -454,9 +454,8 @@ public:
     this->m_ptid = ptid;
   }
 
-/* Dump the contents of a register from the register cache to the target
-   debug.  */
-  void debug_print_register (const char *func, int regno);
+  /* Return a string with the contents of a register, suitable for debug output.  */
+  std::string register_debug_string (int regno);
 
 protected:
   regcache (inferior *inf_for_target_calls, gdbarch *gdbarch);
index 5c3c1a57dbd227b97bef697f156b49757533ccdd..0a836d1e146e77a3a7cd071caf4eb1cdab4167ce 100644 (file)
@@ -3895,7 +3895,8 @@ target_fetch_registers (struct regcache *regcache, int regno)
 {
   current_inferior ()->top_target ()->fetch_registers (regcache, regno);
   if (targetdebug)
-    regcache->debug_print_register ("target_fetch_registers", regno);
+    gdb_printf (gdb_stdlog, "target_fetch_registers: %s",
+               regcache->register_debug_string (regno).c_str ());
 }
 
 void
@@ -3906,9 +3907,8 @@ target_store_registers (struct regcache *regcache, int regno)
 
   current_inferior ()->top_target ()->store_registers (regcache, regno);
   if (targetdebug)
-    {
-      regcache->debug_print_register ("target_store_registers", regno);
-    }
+    gdb_printf (gdb_stdlog, "target_store_registers: %s",
+               regcache->register_debug_string (regno).c_str ());
 }
 
 int