gdb: add target_debug_printf and target_debug_printf_nofunc

Add the `target_debug_printf` and `target_debug_printf_nofunc` macros
and use them when outputting debug messages depending on `targetdebug`.
I opted for `target_debug_printf_nofunc` to follow the current style
where the function name is already printed, along with the arguments.

Modify the debug printfs in the `debug_target` methods (generated by
`make-target-delegates.py`) to use `target_debug_printf_nofunc` as well.

This makes the "target" debug prints integrate nicely with the other
debug prints that use the "new" debug print system:

    [infrun] proceed: enter
      [infrun] follow_fork: enter
        [target] -> multi-thread->record_will_replay (...)
        [target] <- multi-thread->record_will_replay (-1, 0) = false
        [target] -> multi-thread->supports_multi_process (...)
        [target] <- multi-thread->supports_multi_process () = true
      [infrun] follow_fork: exit
      ...

Change-Id: Ide3c8c1b8a30e6d4c353a29cba911c7192de29ac
Approved-By: Tom Tromey <tom@tromey.com>
This commit is contained in:
Simon Marchi
2024-04-19 15:46:54 -04:00
committed by Simon Marchi
parent 8a8b6c53e1
commit cb5dfff88e
3 changed files with 390 additions and 590 deletions

View File

@@ -274,9 +274,7 @@ def write_debugmethod(
debugname = "debug_target::" + name debugname = "debug_target::" + name
names = write_function_header(f, False, debugname, return_type, argtypes) names = write_function_header(f, False, debugname, return_type, argtypes)
print( print(
' gdb_printf (gdb_stdlog, "-> %s->' f' target_debug_printf_nofunc ("-> %s->{name} (...)", this->beneath ()->shortname ());',
+ name
+ ' (...)\\n", this->beneath ()->shortname ());',
file=f, file=f,
) )
@@ -311,11 +309,8 @@ def write_debugmethod(
ret = "" ret = ""
print( print(
( f' target_debug_printf_nofunc ("<- %s->{name} ({args_fmt}){ret_fmt}",\n'
" gdb_printf (gdb_stdlog,\n" f"\t this->beneath ()->shortname (){args}{ret});",
'\t "<- %s->{name} ({args_fmt}){ret_fmt}\\n",\n'
"\t this->beneath ()->shortname (){args}{ret});"
).format(name=name, args_fmt=args_fmt, args=args, ret_fmt=ret_fmt, ret=ret),
file=f, file=f,
) )

File diff suppressed because it is too large Load Diff

View File

@@ -110,6 +110,16 @@ bool may_stop = true;
static unsigned int targetdebug = 0; static unsigned int targetdebug = 0;
/* Print a "target" debug statement with the function name prefix. */
#define target_debug_printf(fmt, ...) \
debug_prefixed_printf_cond (targetdebug > 0, "target", fmt, ##__VA_ARGS__)
/* Print a "target" debug statement without the function name prefix. */
#define target_debug_printf_nofunc(fmt, ...) \
debug_prefixed_printf_cond_nofunc (targetdebug > 0, "target", fmt, ##__VA_ARGS__)
static void static void
set_targetdebug (const char *args, int from_tty, struct cmd_list_element *c) set_targetdebug (const char *args, int from_tty, struct cmd_list_element *c)
{ {
@@ -822,15 +832,9 @@ open_target (const char *args, int from_tty, struct cmd_list_element *command)
auto *ti = static_cast<target_info *> (command->context ()); auto *ti = static_cast<target_info *> (command->context ());
target_open_ftype *func = target_factories[ti]; target_open_ftype *func = target_factories[ti];
if (targetdebug) target_debug_printf_nofunc ("-> %s->open (...)", ti->shortname);
gdb_printf (gdb_stdlog, "-> %s->open (...)\n",
ti->shortname);
func (args, from_tty); func (args, from_tty);
target_debug_printf_nofunc ("<- %s->open (%s, %d)", ti->shortname, args, from_tty);
if (targetdebug)
gdb_printf (gdb_stdlog, "<- %s->open (%s, %d)\n",
ti->shortname, args, from_tty);
} }
/* See target.h. */ /* See target.h. */
@@ -1157,8 +1161,7 @@ target_ops_ref_policy::decref (target_ops *t)
t->close (); t->close ();
if (targetdebug) target_debug_printf_nofunc ("closing target");
gdb_printf (gdb_stdlog, "closing target\n");
} }
} }
@@ -1693,18 +1696,15 @@ target_xfer_partial (struct target_ops *ops,
if (targetdebug) if (targetdebug)
{ {
const unsigned char *myaddr = NULL; const unsigned char *myaddr = NULL;
std::string s
gdb_printf (gdb_stdlog, = string_printf ("%s:target_xfer_partial "
"%s:target_xfer_partial "
"(%d, %s, %s, %s, %s, %s) = %d, %s", "(%d, %s, %s, %s, %s, %s) = %d, %s",
ops->shortname (), ops->shortname (), (int) object,
(int) object,
(annex ? annex : "(null)"), (annex ? annex : "(null)"),
host_address_to_string (readbuf), host_address_to_string (readbuf),
host_address_to_string (writebuf), host_address_to_string (writebuf),
core_addr_to_string_nz (offset), core_addr_to_string_nz (offset), pulongest (len),
pulongest (len), retval, retval, pulongest (*xfered_len));
pulongest (*xfered_len));
if (readbuf) if (readbuf)
myaddr = readbuf; myaddr = readbuf;
@@ -1714,24 +1714,26 @@ target_xfer_partial (struct target_ops *ops,
{ {
int i; int i;
gdb_puts (", bytes =", gdb_stdlog); string_appendf (s, ", bytes =");
for (i = 0; i < *xfered_len; i++) for (i = 0; i < *xfered_len; i++)
{ {
if ((((intptr_t) &(myaddr[i])) & 0xf) == 0) if ((((intptr_t) &(myaddr[i])) & 0xf) == 0)
{ {
if (targetdebug < 2 && i > 0) if (targetdebug < 2 && i > 0)
{ {
gdb_printf (gdb_stdlog, " ..."); string_appendf (s, " ...");
break; break;
} }
gdb_printf (gdb_stdlog, "\n");
target_debug_printf_nofunc ("%s", s.c_str ());
s.clear();
} }
gdb_printf (gdb_stdlog, " %02x", myaddr[i] & 0xff); string_appendf (s, " %02x", myaddr[i] & 0xff);
} }
} }
gdb_putc ('\n', gdb_stdlog); target_debug_printf_nofunc ("%s", s.c_str ());
} }
/* Check implementations of to_xfer_partial update *XFERED_LEN /* Check implementations of to_xfer_partial update *XFERED_LEN
@@ -2944,10 +2946,7 @@ target_info_proc (const char *args, enum info_proc_what what)
{ {
if (t->info_proc (args, what)) if (t->info_proc (args, what))
{ {
if (targetdebug) target_debug_printf_nofunc ("target_info_proc (\"%s\", %d)", args, what);
gdb_printf (gdb_stdlog,
"target_info_proc (\"%s\", %d)\n", args, what);
return 1; return 1;
} }
} }
@@ -3238,14 +3237,9 @@ target_fileio_open (struct inferior *inf, const char *filename,
else else
fd = acquire_fileio_fd (t, fd); fd = acquire_fileio_fd (t, fd);
if (targetdebug) target_debug_printf_nofunc ("target_fileio_open (%d,%s,0x%x,0%o,%d) = %d (%d)",
gdb_printf (gdb_stdlog, inf == NULL ? 0 : inf->num, filename, flags, mode,
"target_fileio_open (%d,%s,0x%x,0%o,%d)" warn_if_slow, fd, fd != -1 ? 0 : *target_errno);
" = %d (%d)\n",
inf == NULL ? 0 : inf->num,
filename, flags, mode,
warn_if_slow, fd,
fd != -1 ? 0 : *target_errno);
return fd; return fd;
} }
@@ -3270,12 +3264,9 @@ target_fileio_pwrite (int fd, const gdb_byte *write_buf, int len,
ret = fh->target->fileio_pwrite (fh->target_fd, write_buf, ret = fh->target->fileio_pwrite (fh->target_fd, write_buf,
len, offset, target_errno); len, offset, target_errno);
if (targetdebug) target_debug_printf_nofunc ("target_fileio_pwrite (%d,...,%d,%s) = %d (%d)", fd,
gdb_printf (gdb_stdlog, len, pulongest (offset), ret,
"target_fileio_pwrite (%d,...,%d,%s) " ret != -1 ? 0 : *target_errno);
"= %d (%d)\n",
fd, len, pulongest (offset),
ret, ret != -1 ? 0 : *target_errno);
return ret; return ret;
} }
@@ -3296,12 +3287,8 @@ target_fileio_pread (int fd, gdb_byte *read_buf, int len,
ret = fh->target->fileio_pread (fh->target_fd, read_buf, ret = fh->target->fileio_pread (fh->target_fd, read_buf,
len, offset, target_errno); len, offset, target_errno);
if (targetdebug) target_debug_printf_nofunc ("target_fileio_pread (%d,...,%d,%s) = %d (%d)", fd, len,
gdb_printf (gdb_stdlog, pulongest (offset), ret, ret != -1 ? 0 : *target_errno);
"target_fileio_pread (%d,...,%d,%s) "
"= %d (%d)\n",
fd, len, pulongest (offset),
ret, ret != -1 ? 0 : *target_errno);
return ret; return ret;
} }
@@ -3320,10 +3307,8 @@ target_fileio_fstat (int fd, struct stat *sb, fileio_error *target_errno)
else else
ret = fh->target->fileio_fstat (fh->target_fd, sb, target_errno); ret = fh->target->fileio_fstat (fh->target_fd, sb, target_errno);
if (targetdebug) target_debug_printf_nofunc ("target_fileio_fstat (%d) = %d (%d)", fd, ret,
gdb_printf (gdb_stdlog, ret != -1 ? 0 : *target_errno);
"target_fileio_fstat (%d) = %d (%d)\n",
fd, ret, ret != -1 ? 0 : *target_errno);
return ret; return ret;
} }
@@ -3347,10 +3332,8 @@ target_fileio_close (int fd, fileio_error *target_errno)
release_fileio_fd (fd, fh); release_fileio_fd (fd, fh);
} }
if (targetdebug) target_debug_printf_nofunc ("target_fileio_close (%d) = %d (%d)", fd, ret,
gdb_printf (gdb_stdlog, ret != -1 ? 0 : *target_errno);
"target_fileio_close (%d) = %d (%d)\n",
fd, ret, ret != -1 ? 0 : *target_errno);
return ret; return ret;
} }
@@ -3367,12 +3350,9 @@ target_fileio_unlink (struct inferior *inf, const char *filename,
if (ret == -1 && *target_errno == FILEIO_ENOSYS) if (ret == -1 && *target_errno == FILEIO_ENOSYS)
continue; continue;
if (targetdebug) target_debug_printf_nofunc ("target_fileio_unlink (%d,%s) = %d (%d)",
gdb_printf (gdb_stdlog, inf == NULL ? 0 : inf->num, filename, ret,
"target_fileio_unlink (%d,%s)" ret != -1 ? 0 : *target_errno);
" = %d (%d)\n",
inf == NULL ? 0 : inf->num, filename,
ret, ret != -1 ? 0 : *target_errno);
return ret; return ret;
} }
@@ -3394,12 +3374,9 @@ target_fileio_readlink (struct inferior *inf, const char *filename,
if (!ret.has_value () && *target_errno == FILEIO_ENOSYS) if (!ret.has_value () && *target_errno == FILEIO_ENOSYS)
continue; continue;
if (targetdebug) target_debug_printf_nofunc ("target_fileio_readlink (%d,%s) = %s (%d)",
gdb_printf (gdb_stdlog, inf == NULL ? 0 : inf->num, filename,
"target_fileio_readlink (%d,%s)" ret ? ret->c_str () : "(nil)",
" = %s (%d)\n",
inf == NULL ? 0 : inf->num,
filename, ret ? ret->c_str () : "(nil)",
ret ? 0 : *target_errno); ret ? 0 : *target_errno);
return ret; return ret;
} }
@@ -3894,9 +3871,7 @@ void
target_fetch_registers (struct regcache *regcache, int regno) target_fetch_registers (struct regcache *regcache, int regno)
{ {
current_inferior ()->top_target ()->fetch_registers (regcache, regno); current_inferior ()->top_target ()->fetch_registers (regcache, regno);
if (targetdebug) target_debug_printf ("%s", regcache->register_debug_string (regno).c_str ());
gdb_printf (gdb_stdlog, "target_fetch_registers: %s",
regcache->register_debug_string (regno).c_str ());
} }
void void
@@ -3906,9 +3881,7 @@ target_store_registers (struct regcache *regcache, int regno)
error (_("Writing to registers is not allowed (regno %d)"), regno); error (_("Writing to registers is not allowed (regno %d)"), regno);
current_inferior ()->top_target ()->store_registers (regcache, regno); current_inferior ()->top_target ()->store_registers (regcache, regno);
if (targetdebug) target_debug_printf ("%s", regcache->register_debug_string (regno).c_str ());
gdb_printf (gdb_stdlog, "target_store_registers: %s",
regcache->register_debug_string (regno).c_str ());
} }
int int