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

@@ -35,31 +35,22 @@ extern int using_threads;
extern bool debug_threads;
/* Print a "threads" debug statement. */
#define threads_debug_printf(fmt, ...) \
debug_prefixed_printf_cond (debug_threads, \
"threads", fmt, ##__VA_ARGS__)
/* Print "threads" enter/exit debug statements. */
#define THREADS_SCOPED_DEBUG_ENTER_EXIT \
scoped_debug_enter_exit (debug_threads, "threads")
extern int debug_timestamp;
void debug_flush (void);
void do_debug_enter (const char *function_name);
void do_debug_exit (const char *function_name);
/* Async signal safe debug output function that calls write directly. */
ssize_t debug_write (const void *buf, size_t nbyte);
/* These macros are for use in major functions that produce a lot of
debugging output. They help identify in the mass of debugging output
when these functions enter and exit. debug_enter is intended to be
called at the start of a function, before any other debugging output.
debug_exit is intended to be called at the end of the same function,
after all debugging output. */
#ifdef FUNCTION_NAME
#define debug_enter() \
do { do_debug_enter (FUNCTION_NAME); } while (0)
#define debug_exit() \
do { do_debug_exit (FUNCTION_NAME); } while (0)
#else
#define debug_enter() \
do { } while (0)
#define debug_exit() \
do { } while (0)
#endif
#endif /* GDBSERVER_DEBUG_H */