aboutsummaryrefslogtreecommitdiff
path: root/gdbserver/thread-db.cc
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@polymtl.ca>2022-01-16 21:27:58 -0500
committerSimon Marchi <simon.marchi@polymtl.ca>2022-01-18 13:44:32 -0500
commitc058728c31684d08da396f1bf50fabaa196dc9d9 (patch)
tree8e0d08d18cf135f7071fa9ee37dd549ee86656a8 /gdbserver/thread-db.cc
parentc68665c7260985ac8497ccafcea961f4a261c675 (diff)
downloadgdb-c058728c31684d08da396f1bf50fabaa196dc9d9.zip
gdb-c058728c31684d08da396f1bf50fabaa196dc9d9.tar.gz
gdb-c058728c31684d08da396f1bf50fabaa196dc9d9.tar.bz2
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
Diffstat (limited to 'gdbserver/thread-db.cc')
-rw-r--r--gdbserver/thread-db.cc44
1 files changed, 17 insertions, 27 deletions
diff --git a/gdbserver/thread-db.cc b/gdbserver/thread-db.cc
index 62ce23c..6e0e222 100644
--- a/gdbserver/thread-db.cc
+++ b/gdbserver/thread-db.cc
@@ -184,9 +184,8 @@ find_one_thread (ptid_t ptid)
error ("Cannot get thread info for LWP %d: %s",
lwpid, thread_db_err_str (err));
- if (debug_threads)
- debug_printf ("Found thread %ld (LWP %d)\n",
- (unsigned long) ti.ti_tid, ti.ti_lid);
+ threads_debug_printf ("Found thread %ld (LWP %d)",
+ (unsigned long) ti.ti_tid, ti.ti_lid);
if (lwpid != ti.ti_lid)
{
@@ -218,9 +217,8 @@ attach_thread (const td_thrhandle_t *th_p, td_thrinfo_t *ti_p)
struct lwp_info *lwp;
int err;
- if (debug_threads)
- debug_printf ("Attaching to thread %ld (LWP %d)\n",
- (unsigned long) ti_p->ti_tid, ti_p->ti_lid);
+ threads_debug_printf ("Attaching to thread %ld (LWP %d)",
+ (unsigned long) ti_p->ti_tid, ti_p->ti_lid);
err = the_linux_target->attach_lwp (ptid);
if (err != 0)
{
@@ -283,10 +281,9 @@ find_new_threads_callback (const td_thrhandle_t *th_p, void *data)
thread that previously exited and was joined. (glibc marks
terminated and joined threads with kernel thread ID -1. See
glibc PR17707. */
- if (debug_threads)
- debug_printf ("thread_db: skipping exited and "
- "joined thread (0x%lx)\n",
- (unsigned long) ti.ti_tid);
+ threads_debug_printf ("thread_db: skipping exited and "
+ "joined thread (0x%lx)",
+ (unsigned long) ti.ti_tid);
return 0;
}
@@ -333,9 +330,8 @@ thread_db_find_new_threads (void)
TD_THR_ANY_STATE,
TD_THR_LOWEST_PRIORITY,
TD_SIGNO_MASK, TD_THR_ANY_USER_FLAGS);
- if (debug_threads)
- debug_printf ("Found %d threads in iteration %d.\n",
- new_thread_count, iteration);
+ threads_debug_printf ("Found %d threads in iteration %d.",
+ new_thread_count, iteration);
if (new_thread_count != 0)
{
@@ -492,8 +488,7 @@ thread_db_load_search (void)
err = tdb->td_ta_new_p (&tdb->proc_handle, &tdb->thread_agent);
if (err != TD_OK)
{
- if (debug_threads)
- debug_printf ("td_ta_new(): %s\n", thread_db_err_str (err));
+ threads_debug_printf ("td_ta_new(): %s", thread_db_err_str (err));
free (tdb);
proc->priv->thread_db = NULL;
return 0;
@@ -535,8 +530,7 @@ try_thread_db_load_1 (void *handle)
{ \
if ((a) == NULL) \
{ \
- if (debug_threads) \
- debug_printf ("dlsym: %s\n", dlerror ()); \
+ threads_debug_printf ("dlsym: %s", dlerror ()); \
if (required) \
{ \
free (tdb); \
@@ -556,8 +550,7 @@ try_thread_db_load_1 (void *handle)
err = tdb->td_ta_new_p (&tdb->proc_handle, &tdb->thread_agent);
if (err != TD_OK)
{
- if (debug_threads)
- debug_printf ("td_ta_new(): %s\n", thread_db_err_str (err));
+ threads_debug_printf ("td_ta_new(): %s", thread_db_err_str (err));
free (tdb);
proc->priv->thread_db = NULL;
return 0;
@@ -601,14 +594,12 @@ try_thread_db_load (const char *library)
{
void *handle;
- if (debug_threads)
- debug_printf ("Trying host libthread_db library: %s.\n",
- library);
+ threads_debug_printf ("Trying host libthread_db library: %s.",
+ library);
handle = dlopen (library, RTLD_NOW);
if (handle == NULL)
{
- if (debug_threads)
- debug_printf ("dlopen failed: %s.\n", dlerror ());
+ threads_debug_printf ("dlopen failed: %s.", dlerror ());
return 0;
}
@@ -623,7 +614,7 @@ try_thread_db_load (const char *library)
const char *const libpath = dladdr_to_soname (td_init);
if (libpath != NULL)
- debug_printf ("Host %s resolved to: %s.\n", library, libpath);
+ threads_debug_printf ("Host %s resolved to: %s.", library, libpath);
}
}
#endif
@@ -722,8 +713,7 @@ thread_db_load_search (void)
}
}
- if (debug_threads)
- debug_printf ("thread_db_load_search returning %d\n", rc);
+ threads_debug_printf ("thread_db_load_search returning %d", rc);
return rc;
}