This is the mail archive of the
gdb@sourceware.org
mailing list for the GDB project.
pthread_sigmask and gdb
- From: Jaimon Jose <jjaimon at Yahoo dot com>
- To: gdb at sourceware dot org
- Date: Mon, 06 Nov 2006 19:25:01 +0530
- Subject: pthread_sigmask and gdb
- Reply-to: jjaimon at yahoo dot com
I have a server program where the main thread block on all signals and
handle them appropriately. This was required for a graceful shutdown
(using SIGINT ) or a reconfigure ( HUP ). However, I see that, gdb
doesn't allow me to break into the debugger ( interrupt the running
program ) if I block SIGINT. The "info signal" states that,
Signal Stop Print Pass to program Description
SIGHUP Yes Yes Yes Hangup
SIGINT Yes Yes No Interrupt
Still, SIGINT is passed to the program being debugged instead of GDB
handling this. I have attached a sample program where I can reproduce
this. I tried this on Solaris and HPUX. Once I attach to the running
program, I can interrupt the program using "Ctrl-C". But, this doesn't
work on gdb ( on SLES, SuSE 10.1 and RHAS 3.0 - gdb 6.4 and 6.0 ) and
the signal is delivered to the running program. Any help is appreciated.
--jaimon
#include <stdio.h>
#include <signal.h>
#include <errno.h>
#include <string.h>
int main(void)
{
int err = 0;
bool bShutdown = 0;
sigset_t set, old;
sigfillset(&set);
sigdelset(&set,SIGTRAP);
// sigdelset(&set, SIGINT );
//
// Needed by gdb
//
sigdelset(&set, SIGUSR1 );
sigdelset(&set, SIGUSR2 );
sigdelset(&set, SIGUNUSED );
/* Java VM uses these signals in Linux */
for(int s=SIGRTMIN; s <= SIGRTMAX - 4; s++)
sigdelset(&set,s);
if (pthread_sigmask(SIG_BLOCK, &set, 0) != 0)
fprintf(stderr, "pthread_sigprocmask failed: %s\n", strerror(errno));
//
// Start additional threads
//
while (bShutdown == false)
{
int sig = 0;
siginfo_t info;
if ((sig = sigwaitinfo(&set, &info)) == -1)
{
fprintf(stderr, "Received invalid signal -1.\n");
continue;
}
switch (sig)
{
case SIGINT:
fprintf(stderr, "Received SIGINT\n");
// fall through
case SIGTERM:
fprintf(stderr, "Got SIGINT/SIGTERM signal, shutting down\n");
bShutdown = true;
break;
default:
fprintf(stderr, "Ignoring the unexpected signal, %d\n", sig);
break;
}
}
//
// Do additional cleanup
//
return 0;
}