This is the mail archive of the mailing list for the GDB project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

pthread_sigmask and gdb

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.

#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;

//	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++)

	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");

		switch (sig)
			case SIGINT:
				fprintf(stderr, "Received SIGINT\n"); 
				// fall through
			case SIGTERM:
				fprintf(stderr, "Got SIGINT/SIGTERM signal, shutting down\n"); 
				bShutdown = true;
				fprintf(stderr, "Ignoring the unexpected signal, %d\n", sig);
	// Do additional cleanup
	return 0;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]