News:

Accounts with zero posts and zero activity during the last months will be deleted periodically to fight SPAM!

Main Menu

Signals (debugging) - can anyone explain this weird behaviour?

Started by johne53, November 20, 2008, 06:30:45 PM

Previous topic - Next topic

johne53

Consider the following simple program:-

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


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?
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.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: [url="https://www.codeblocks.org/docs/main_codeblocks_en.html"]https://www.codeblocks.org/docs/main_codeblocks_en.html[/url]
C::B FAQ: [url="https://wiki.codeblocks.org/index.php?title=FAQ"]https://wiki.codeblocks.org/index.php?title=FAQ[/url]

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.

"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.
Be patient!
This bug will be fixed soon...

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.

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?

Jenna

Quote from: johne53 on November 21, 2008, 11:08:41 AM
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.

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?

It is only available, while debugging and if the debugging process is interrupted.
Start debugging and click the stop button once. This sends SIGINT to the debugger.

Now you should be able to use the "Information" submenu.

To change the debuggers behaviour, you can send commands to the debugger via "Debug -> Send user command to debugger" (only if debugging is interrupted).
The output is shown in the debugger log.

To see how signal handling can be changed, send "help handle" to the debugger.

johne53

Thanks Jens, I see it now. I can see that the default setting for SIGINT is not to pass it to the program. To change this, what command would I need to send to the debugger? Or is there maybe a config file somewhere that I could edit?

johne53

Or alternatively, is there any other signal that I can generate from a command line? It just occured to me that for testing purposes it doesn't need to be CTRL-C. Any signal could be suitable as long as I can generate it from the command line.

BTW, I did try help handle but it didn't seem to offer any solutions.

Jenna

Quote from: johne53 on November 21, 2008, 01:09:03 PM
Or alternatively, is there any other signal that I can generate from a command line? It just occured to me that for testing purposes it doesn't need to be CTRL-C. Any signal could be suitable as long as I can generate it from the command line.
http://sunsite.ualberta.ca/Documentation/Gnu/gdb-5.0/html_node/gdb_99.html#SEC99

Quote from: johne53 on November 21, 2008, 01:09:03 PM
BTW, I did try help handle but it didn't seem to offer any solutions.
http://sunsite.ualberta.ca/Documentation/Gnu/gdb-5.0/html_node/gdb_38.html

johne53