Mirror of the gdb mailing list
 help / color / mirror / Atom feed
* pthread_sigmask and gdb
@ 2006-11-06 13:55 Jaimon Jose
  2006-11-06 14:05 ` Andreas Schwab
  0 siblings, 1 reply; 5+ messages in thread
From: Jaimon Jose @ 2006-11-06 13:55 UTC (permalink / raw)
  To: gdb

[-- Attachment #1: Type: text/plain, Size: 948 bytes --]

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

[-- Attachment #2: signal_test.cpp --]
[-- Type: text/plain, Size: 1163 bytes --]


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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2006-11-06 14:35 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-11-06 13:55 pthread_sigmask and gdb Jaimon Jose
2006-11-06 14:05 ` Andreas Schwab
2006-11-06 14:16   ` Daniel Jacobowitz
2006-11-06 14:18   ` Jaimon Jose
2006-11-06 14:35     ` Daniel Jacobowitz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox