Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » signal handler is not called in DEBUG
signal handler is not called in DEBUG [message #1714149] Tue, 10 November 2015 09:56 Go to next message
chen zero is currently offline chen zeroFriend
Messages: 9
Registered: July 2009
Junior Member
Hello,
Eclipse version:
Luna Service Release 2 (4.4.2)
Build id: 20150219-0600

I found that if I use "kill -2 pid"
to send signal to the app under debug, the signal handler will not called.
If I ran the app in Terminal, the handler will be called.

if there is any constraints to debug app that handles signals?
but how to debug if app uses signals ?
Thanks!
chenzero

#include <cstdio>
#include <signal.h>
#include <unistd.h>

static bool loop;
static void sigfunc(int);

static void sigfunc(int signo) {
	printf("SIGINT received!\n");
	loop = false;
}

int main(int argc, char** argv) {
	loop = true;
	if (signal(SIGINT, sigfunc) == SIG_ERR) {
		printf("Could not setup signal handler for SIGINT!\n");
		return -1;
	}
	pid_t pid = getpid();

	printf("Waiting for SIGINT, pid: %d Press Ctrl+C to exit.\n", pid );
	printf("kill -2 %d \n", pid);

	while (loop) {
                 ;
	}
	return 0;
}

[Updated on: Wed, 11 November 2015 05:36]

Report message to a moderator

Re: signal handler is not called in DEBUG [message #1714182 is a reply to message #1714149] Tue, 10 November 2015 14:38 Go to previous messageGo to next message
David VavraFriend
Messages: 1426
Registered: October 2012
Senior Member
GDB is intercepting the signals. You will need to tell GDB to pass it on.
Here's an example: http://nirbhay.in/2012/09/debug-signal-handlers-using-gdb/
More specific info: https://sourceware.org/gdb/onlinedocs/gdb/Signals.html

There are others, Google gdb and signal handlers.


EDIT:

To do this, go to the console view (you might want to open a second one) then select the GDB console from the Display Selected Console pull-down list. The one you want has the gdb version in parentheses. It's NOT the traces display.

Here's a partial list of signals caught by GDB:

index.php/fa/23890/0/

[Updated on: Tue, 10 November 2015 15:02]

Report message to a moderator

Re: signal handler is not called in DEBUG [message #1714251 is a reply to message #1714182] Wed, 11 November 2015 06:21 Go to previous messageGo to next message
chen zero is currently offline chen zeroFriend
Messages: 9
Registered: July 2009
Junior Member
Thank you for the detailed, and nice explanations !

for people that use Eclipse CDT to debug signals:
in the project home path, create a file named .gdbinit with following line:
handle all nostop pass

the .gdbinit file is specified in the
Debug configuration >> Debugger >> GDB command file

Thanks!
chenzero
Re: signal handler is not called in DEBUG [message #1714320 is a reply to message #1714251] Wed, 11 November 2015 17:28 Go to previous messageGo to next message
David VavraFriend
Messages: 1426
Registered: October 2012
Senior Member
Excellent point about using the .gdbinit file. Don't know how I overlooked that. Confused
Re: signal handler is not called in DEBUG [message #1714349 is a reply to message #1714320] Thu, 12 November 2015 05:27 Go to previous message
chen zero is currently offline chen zeroFriend
Messages: 9
Registered: July 2009
Junior Member
Cheers for Eclipse, the really great tool !
chenzero
Previous Topic:Clang - Run as "Local C++ application"
Next Topic:Headless CDT build with ANT tasks
Goto Forum:
  


Current Time: Thu Apr 25 14:13:40 GMT 2024

Powered by FUDForum. Page generated in 0.03395 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top