User forums > Using Code::Blocks
Signals (debugging) - can anyone explain this weird behaviour?
johne53:
Consider the following simple program:-
--- Code: ---#include <signal.h>
#include <iostream>
void sighandler(int signum) {
std::cout << "Received signal " << signum << std::endl;
if (signum == 9) exit(42);
}
int main()
{
for (int i = 1; i <= 15; ++i )
signal(i, sighandler);
for(;;) sleep(1);
exit(0);
}
--- End code ---
All it does is catch signals and print a message in a console window. If I compile it under Linux (gcc4.2) or under Cygwin (gcc3.4) and run it normally, it works fine. So if I launch the program, click on the console window and press CTRL+C, I see the message Received signal 2. Both Linux and Cygwin use the gdb debugger and it usually works fine for me. However, if I try to debug this program using C::B, here's what happens:-
LINUX:
The program runs and I click inside its console Window. If I then type CTRL+C, the console window disappears but gdb appears to keep running.
CYGWIN:
The program runs and I click inside its console Window. If I then type CTRL+C, a message appears in the debugger output window saying Program received signal SIGINT, Interrupt but the signal doesn't get passed to the running program (i.e. if I set a break point in function sighandler() it never gets reached).
Do I need to enable something within C::B to make this work in such a way that the program works the same way, whether it's running normally or in the debugger?
MortenMacFly:
--- Quote from: johne53 on November 20, 2008, 06:30:45 pm ---Do I need to enable something within C::B to make this work in such a way that the program works the same way, whether it's running normally or in the debugger?
--- End quote ---
Normally not. Since you are using two completely different dev environments (and I'd bet the version of e.g. GCC/GDB differ quite much) you are comparing kind of apples with oranges here. I'd say it's best if you ask in a GCC/GDB forum.
You could try before if it's the same if you run GDB on the command line. Then you know for sure it's not a C::B issue. Still - there *could* be a switch - but then again: Better ask the GCC/GDB devs.
Jenna:
If you start your program with gdb from commandline, you can stop it pressing Ctrl-C and type info signals, to see what gdb does if an external signal occured.
In the most cases it stops the program and prints, what signal occured, in some cases it does not pass the signal to the program after pressing "c".
You can change that behaviour.
Type "help handle" to see what is possible.
mandrav:
--- Quote from: jens on November 21, 2008, 07:40:42 am ---If you start your program with gdb from commandline, you can stop it pressing Ctrl-C and type info signals, to see what gdb does if an external signal occured.
--- End quote ---
"Debug->Information->Signal handling" will do the same thing in C::B. I just didn't have the time to make it editable so far.
johne53:
--- Quote from: mandrav on November 21, 2008, 10:07:42 am ---"Debug->Information->Signal handling" will do the same thing in C::B. I just didn't have the time to make it editable so far.
--- End quote ---
Hmmm.... Debug->Information->Signal handling is grayed out in my version (Windows platform). Is that what you meant? Or is it time for me to update to the latest version?
Navigation
[0] Message Index
[#] Next page
Go to full version