gdbserver: introduce threads_debug_printf, THREADS_SCOPED_DEBUG_ENTER_EXIT

Add the threads_debug_printf and THREADS_SCOPED_DEBUG_ENTER_EXIT, which
use the logging infrastructure from gdbsupport/common-debug.h.  Replace
all debug_print uses that are predicated by debug_threads with
threads_dethreads_debug_printf.  Replace uses of the debug_enter and
debug_exit macros with THREADS_SCOPED_DEBUG_ENTER_EXIT, which serves
essentially the same purpose, but allows showing what comes between the
enter and the exit in an indented form.

Note that "threads" debug is currently used for a bit of everything in
GDBserver, not only threads related stuff.  It should ideally be cleaned
up and separated logically as is done in GDB, but that's out of the
scope of this patch.

Change-Id: I2d4546464462cb4c16f7f1168c5cec5a89f2289a
This commit is contained in:
Simon Marchi
2022-01-16 21:27:58 -05:00
parent c68665c726
commit c058728c31
13 changed files with 483 additions and 798 deletions

View File

@@ -1228,8 +1228,7 @@ handle_detach (char *own_buf)
pass signals down without informing GDB. */
if (!non_stop)
{
if (debug_threads)
debug_printf ("Forcing non-stop mode\n");
threads_debug_printf ("Forcing non-stop mode");
non_stop = true;
the_target->start_non_stop (true);
@@ -3336,10 +3335,10 @@ queue_stop_reply_callback (thread_info *thread)
{
if (target_thread_stopped (thread))
{
if (debug_threads)
debug_printf ("Reporting thread %s as already stopped with %s\n",
target_pid_to_str (thread->id).c_str (),
thread->last_status.to_string ().c_str ());
threads_debug_printf
("Reporting thread %s as already stopped with %s",
target_pid_to_str (thread->id).c_str (),
thread->last_status.to_string ().c_str ());
gdb_assert (thread->last_status.kind () != TARGET_WAITKIND_IGNORE);
@@ -4183,16 +4182,14 @@ process_point_options (struct gdb_breakpoint *bp, const char **packet)
if (*dataptr == 'X')
{
/* Conditional expression. */
if (debug_threads)
debug_printf ("Found breakpoint condition.\n");
threads_debug_printf ("Found breakpoint condition.");
if (!add_breakpoint_condition (bp, &dataptr))
dataptr = strchrnul (dataptr, ';');
}
else if (startswith (dataptr, "cmds:"))
{
dataptr += strlen ("cmds:");
if (debug_threads)
debug_printf ("Found breakpoint commands %s.\n", dataptr);
threads_debug_printf ("Found breakpoint commands %s.", dataptr);
persist = (*dataptr == '1');
dataptr += 2;
if (add_breakpoint_commands (bp, &dataptr, persist))
@@ -4576,8 +4573,7 @@ process_serial_event (void)
void
handle_serial_event (int err, gdb_client_data client_data)
{
if (debug_threads)
debug_printf ("handling possible serial event\n");
threads_debug_printf ("handling possible serial event");
/* Really handle it. */
if (process_serial_event () < 0)
@@ -4610,8 +4606,7 @@ void
handle_target_event (int err, gdb_client_data client_data)
{
client_state &cs = get_client_state ();
if (debug_threads)
debug_printf ("handling possible target event\n");
threads_debug_printf ("handling possible target event");
cs.last_ptid = mywait (minus_one_ptid, &cs.last_status,
TARGET_WNOHANG, 1);
@@ -4663,11 +4658,10 @@ handle_target_event (int err, gdb_client_data client_data)
inferior, as if it wasn't being traced. */
enum gdb_signal signal;
if (debug_threads)
debug_printf ("GDB not connected; forwarding event %d for"
" [%s]\n",
(int) cs.last_status.kind (),
target_pid_to_str (cs.last_ptid).c_str ());
threads_debug_printf ("GDB not connected; forwarding event %d for"
" [%s]",
(int) cs.last_status.kind (),
target_pid_to_str (cs.last_ptid).c_str ());
if (cs.last_status.kind () == TARGET_WAITKIND_STOPPED)
signal = cs.last_status.sig ();