From: Simon Marchi <simon.marchi@polymtl.ca>
To: gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@efficios.com>
Subject: [PATCH 5/6] gdb: make regcache::debug_print_register return a string
Date: Wed, 17 Apr 2024 16:54:10 -0400 [thread overview]
Message-ID: <20240417205426.2030615-5-simon.marchi@polymtl.ca> (raw)
In-Reply-To: <20240417205426.2030615-1-simon.marchi@polymtl.ca>
From: Simon Marchi <simon.marchi@efficios.com>
This makes it easier to introduce `target_debug_printf` in a subsequent
patch.
Change-Id: I5bb2d49476d17940d503e66f40762e3f1e3baabc
---
gdb/regcache.c | 28 +++++++++++++++-------------
gdb/regcache.h | 5 ++---
gdb/target.c | 8 ++++----
3 files changed, 21 insertions(+), 20 deletions(-)
diff --git a/gdb/regcache.c b/gdb/regcache.c
index b7abbe99f3cc..e673d56a7e94 100644
--- a/gdb/regcache.c
+++ b/gdb/regcache.c
@@ -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::debug_print_register (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. */
diff --git a/gdb/regcache.h b/gdb/regcache.h
index 9ba6c79ab0d5..3c621045c163 100644
--- a/gdb/regcache.h
+++ b/gdb/regcache.h
@@ -454,9 +454,8 @@ class regcache : public detached_regcache
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 dump of the contents of a register, suitable for debug output. */
+ std::string debug_print_register (int regno);
protected:
regcache (inferior *inf_for_target_calls, gdbarch *gdbarch);
diff --git a/gdb/target.c b/gdb/target.c
index 107a84b3ca1d..cdaaf253cbcd 100644
--- a/gdb/target.c
+++ b/gdb/target.c
@@ -3889,7 +3889,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->debug_print_register (regno).c_str ());
}
void
@@ -3900,9 +3901,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->debug_print_register (regno).c_str ());
}
int
--
2.44.0
next prev parent reply other threads:[~2024-04-17 21:01 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-17 20:54 [PATCH 1/6] gdb: add includes in target-debug.h Simon Marchi
2024-04-17 20:54 ` [PATCH 2/6] gdb: convert target debug macros to functions Simon Marchi
2024-04-19 19:12 ` Tom Tromey
2024-04-17 20:54 ` [PATCH 3/6] gdb: make target debug functions return std::string Simon Marchi
2024-04-19 19:20 ` Tom Tromey
2024-04-19 19:41 ` Simon Marchi
2024-04-19 20:19 ` Tom Tromey
2024-04-17 20:54 ` [PATCH 4/6] gdb: make debug_target use one-liners Simon Marchi
2024-04-19 19:23 ` Tom Tromey
2024-04-17 20:54 ` Simon Marchi [this message]
2024-04-19 19:24 ` [PATCH 5/6] gdb: make regcache::debug_print_register return a string Tom Tromey
2024-04-19 19:45 ` Simon Marchi
2024-04-17 20:54 ` [PATCH 6/6] gdb: add target_debug_printf and target_debug_printf_nofunc Simon Marchi
2024-04-19 19:27 ` Tom Tromey
2024-04-19 19:06 ` [PATCH 1/6] gdb: add includes in target-debug.h Tom Tromey
2024-04-19 19:07 ` Simon Marchi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240417205426.2030615-5-simon.marchi@polymtl.ca \
--to=simon.marchi@polymtl.ca \
--cc=gdb-patches@sourceware.org \
--cc=simon.marchi@efficios.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).