This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
[PATCH] Add control variable for debug output to linux threads
- To: Mark Kettenis <kettenis at wins dot uva dot nl>
- Subject: [PATCH] Add control variable for debug output to linux threads
- From: Michael Snyder <msnyder at cygnus dot com>
- Date: Thu, 26 Apr 2001 16:13:34 -0700
- CC: gdb-patches at sources dot redhat dot com
- Organization: Red Hat
- References: <200104191140.f3JBemM02725@delius.kettenis.local>
Mark,
This patch replaces your DEBUG macro with a runtime variable that is
settable by a user command. At some recent check-in, you left the
DEBUG macro turned on, and users have been asking about the extra
messages.
2001-04-26 Michael Snyder <msnyder@redhat.com>
* thread-db.c (_initialize_thread_db): Add set/show command
"debug-linux-threads" for debugging output.
* lin-lwp.c (various): Use global "debug_linux_threads to
turn on extra debugging output.
Index: thread-db.c
===================================================================
RCS file: /cvs/src/src/gdb/thread-db.c,v
retrieving revision 1.7
diff -c -3 -p -r1.7 thread-db.c
*** thread-db.c 2001/04/17 19:14:54 1.7
--- thread-db.c 2001/04/26 23:09:11
***************
*** 31,42 ****
--- 31,46 ----
#include "symfile.h"
#include "objfiles.h"
#include "target.h"
+ #include "command.h"
+ #include "gdbcmd.h"
#include "regcache.h"
#ifndef LIBTHREAD_DB_SO
#define LIBTHREAD_DB_SO "libthread_db.so.1"
#endif
+ int debug_linux_threads = 0; /* Set non-zero for debugging output. */
+
/* If we're running on Linux, we must explicitly attach to any new threads. */
/* FIXME: There is certainly some room for improvements:
*************** static struct target_ops thread_db_ops;
*** 51,57 ****
static struct target_ops *target_beneath;
/* Pointer to the next function on the objfile event chain. */
! static void (*target_new_objfile_chain) (struct objfile *objfile);
/* Non-zero if we're using this module's target vector. */
static int using_thread_db;
--- 55,61 ----
static struct target_ops *target_beneath;
/* Pointer to the next function on the objfile event chain. */
! static void (*new_objfile_event_chain) (struct objfile *objfile);
/* Non-zero if we're using this module's target vector. */
static int using_thread_db;
*************** thread_db_new_objfile (struct objfile *o
*** 588,595 ****
}
quit:
! if (target_new_objfile_chain)
! target_new_objfile_chain (objfile);
}
static void
--- 592,599 ----
}
quit:
! if (new_objfile_event_chain)
! new_objfile_event_chain (objfile);
}
static void
*************** check_event (int pid)
*** 697,707 ****
error ("Thread creation event doesn't match breakpoint.");
#endif
! /* We may already know about this thread, for instance when the
! user has issued the `info threads' command before the SIGTRAP
! for hitting the thread creation breakpoint was reported. */
! if (! in_thread_list (pid))
! attach_thread (pid, msg.th_p, &ti, 1);
return;
case TD_DEATH:
--- 701,710 ----
error ("Thread creation event doesn't match breakpoint.");
#endif
! if (in_thread_list (pid))
! error ("Spurious thread creation event.");
!
! attach_thread (pid, msg.th_p, &ti, 1);
return;
case TD_DEATH:
*************** _initialize_thread_db (void)
*** 1023,1029 ****
add_target (&thread_db_ops);
/* Add ourselves to objfile event chain. */
! target_new_objfile_chain = target_new_objfile_hook;
target_new_objfile_hook = thread_db_new_objfile;
}
}
--- 1026,1037 ----
add_target (&thread_db_ops);
/* Add ourselves to objfile event chain. */
! new_objfile_event_chain = target_new_objfile_hook;
target_new_objfile_hook = thread_db_new_objfile;
}
+ add_show_from_set (add_set_cmd ("debug-linux-threads", class_support,
+ var_boolean, (char *) &debug_linux_threads,
+ "Set debug output for linux-threads \
+ on or off.\nUse \"on\" to enable, \"off\" to disable.", &setlist),
+ &showlist);
}
Index: lin-lwp.c
===================================================================
RCS file: /cvs/src/src/gdb/lin-lwp.c,v
retrieving revision 1.9
diff -c -3 -p -r1.9 lin-lwp.c
*** lin-lwp.c 2001/04/26 22:35:08 1.9
--- lin-lwp.c 2001/04/26 23:09:11
***************
*** 31,41 ****
#include "target.h"
#include "regcache.h"
! #define DEBUG 1
!
! #if DEBUG
extern const char *strsignal (int sig);
- #endif
/* On Linux there are no real LWP's. The closest thing to LWP's are
processes sharing the same VM space. A multi-threaded process is
--- 31,38 ----
#include "target.h"
#include "regcache.h"
! extern int debug_linux_threads;
extern const char *strsignal (int sig);
/* On Linux there are no real LWP's. The closest thing to LWP's are
processes sharing the same VM space. A multi-threaded process is
*************** stop_wait_callback (struct lwp_info *lp,
*** 521,529 ****
printf_unfiltered ("[%s exited]\n",
target_pid_to_str (lp->pid));
}
! #if DEBUG
! printf ("%s exited.\n", target_pid_to_str (lp->pid));
! #endif
delete_lwp (lp->pid);
return 0;
}
--- 518,526 ----
printf_unfiltered ("[%s exited]\n",
target_pid_to_str (lp->pid));
}
! if (debug_linux_threads)
! printf ("%s exited.\n", target_pid_to_str (lp->pid));
!
delete_lwp (lp->pid);
return 0;
}
*************** stop_wait_callback (struct lwp_info *lp,
*** 549,569 ****
If we do not do this, then we run the risk that the
user will delete or disable the breakpoint, but the
thread will have already tripped on it. */
! #if DEBUG
! printf ("Tripped breakpoint at %lx in LWP %d"
! " while waiting for SIGSTOP.\n",
! (long) read_pc_pid (lp->pid), pid);
! #endif
/* Set the PC to before the trap. */
if (DECR_PC_AFTER_BREAK)
write_pc_pid (read_pc_pid (pid) - DECR_PC_AFTER_BREAK, pid);
}
else
{
! #if DEBUG
! printf ("Received %s in LWP %d while waiting for SIGSTOP.\n",
! strsignal (WSTOPSIG (status)), pid);
! #endif
/* The thread was stopped with a signal other than
SIGSTOP, and didn't accidentiliy trip a breakpoint.
Record the wait status. */
--- 546,566 ----
If we do not do this, then we run the risk that the
user will delete or disable the breakpoint, but the
thread will have already tripped on it. */
!
! if (debug_linux_threads)
! printf ("Tripped breakpoint at %lx in LWP %d"
! " while waiting for SIGSTOP.\n",
! (long) read_pc_pid (lp->pid), pid);
!
/* Set the PC to before the trap. */
if (DECR_PC_AFTER_BREAK)
write_pc_pid (read_pc_pid (pid) - DECR_PC_AFTER_BREAK, pid);
}
else
{
! if (debug_linux_threads)
! printf ("Received %s in LWP %d while waiting for SIGSTOP.\n",
! strsignal (WSTOPSIG (status)), pid);
/* The thread was stopped with a signal other than
SIGSTOP, and didn't accidentiliy trip a breakpoint.
Record the wait status. */
*************** lin_lwp_wait (int pid, struct target_wai
*** 620,629 ****
lp = iterate_over_lwps (status_callback, NULL);
if (lp)
{
! #if DEBUG
! printf ("Using pending wait status for LWP %d.\n",
! GET_LWP (lp->pid));
! #endif
status = lp->status;
lp->status = 0;
}
--- 617,625 ----
lp = iterate_over_lwps (status_callback, NULL);
if (lp)
{
! if (debug_linux_threads)
! printf ("Using pending wait status for LWP %d.\n",
! GET_LWP (lp->pid));
status = lp->status;
lp->status = 0;
}
*************** lin_lwp_wait (int pid, struct target_wai
*** 635,653 ****
}
else if (is_lwp (pid))
{
! #if DEBUG
! printf ("Waiting for specific LWP %d.\n", GET_LWP (pid));
! #endif
/* We have a specific LWP to check. */
lp = find_lwp_pid (GET_LWP (pid));
gdb_assert (lp);
status = lp->status;
lp->status = 0;
! #if DEBUG
! if (status)
printf ("Using pending wait status for LWP %d.\n",
GET_LWP (lp->pid));
- #endif
/* If we have to wait, take into account whether PID is a cloned
process or not. And we have to convert it to something that
--- 631,648 ----
}
else if (is_lwp (pid))
{
! if (debug_linux_threads)
! printf ("Waiting for specific LWP %d.\n", GET_LWP (pid));
!
/* We have a specific LWP to check. */
lp = find_lwp_pid (GET_LWP (pid));
gdb_assert (lp);
status = lp->status;
lp->status = 0;
! if (debug_linux_threads)
! if (status)
printf ("Using pending wait status for LWP %d.\n",
GET_LWP (lp->pid));
/* If we have to wait, take into account whether PID is a cloned
process or not. And we have to convert it to something that
*************** lin_lwp_wait (int pid, struct target_wai
*** 725,733 ****
printf_unfiltered ("[%s exited]\n",
target_pid_to_str (lp->pid));
}
! #if DEBUG
! printf ("%s exited.\n", target_pid_to_str (lp->pid));
! #endif
delete_lwp (lp->pid);
/* Make sure there is at least one thread running. */
--- 720,728 ----
printf_unfiltered ("[%s exited]\n",
target_pid_to_str (lp->pid));
}
! if (debug_linux_threads)
! printf ("%s exited.\n", target_pid_to_str (lp->pid));
!
delete_lwp (lp->pid);
/* Make sure there is at least one thread running. */
*************** lin_lwp_wait (int pid, struct target_wai
*** 743,752 ****
if (lp->signalled && WIFSTOPPED (status)
&& WSTOPSIG (status) == SIGSTOP)
{
! #if DEBUG
! printf ("Delayed SIGSTOP caught for %s.\n",
! target_pid_to_str (lp->pid));
! #endif
/* This is a delayed SIGSTOP. */
lp->signalled = 0;
--- 738,747 ----
if (lp->signalled && WIFSTOPPED (status)
&& WSTOPSIG (status) == SIGSTOP)
{
! if (debug_linux_threads)
! printf ("Delayed SIGSTOP caught for %s.\n",
! target_pid_to_str (lp->pid));
!
/* This is a delayed SIGSTOP. */
lp->signalled = 0;