tags:

views:

153

answers:

1

I'd built a version of gdb 7.0 for myself after being pointed to a new feature, and happened to have that in my path still.

Attempting to step through some new code, I'd added a pause() call, expecting to be able to get out like so:

(gdb) b 5048
Breakpoint 1 at 0x2b1811b25052: file testca.C, line 5048.
(gdb) signal SIGCONT
Continuing with signal SIGCONT.

Breakpoint 1, FLUSH_SUDF_TEST (h=@0x2b1811b061c0) at testca.C:5048
5048       rc = h.SAL_testcaFlushPagesByUDF( uPrimary - 1, uPrimary ) ;

(that was with the system gdb, version 6.6).

With gdb 7.0 I never hit the post-pause() breakpoint when I try this. With the various multi process debugging changes in gdb 7, does anybody know if signal handling has to be handled differently and how?

A: 

The pause() function does not return unless a signal handler is called (see the specification and the man page).

To make it return after your program receives SIGCONT, you must install an handler for SIGCONT. Try and see using the following example:

#include <signal.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>

volatile int caught_signal = 0;

void handler(int sig)
{
    caught_signal = sig; 
}

int main()
{
    signal(SIGCONT, handler);
    pause();
    printf("Caught signal: %d, %s\n",
            caught_signal, strsignal(caught_signal));
    return 0;
}

The behavior is correct with gdb 7.0: pause() completely ignores ignored signals (like SIGCHLD, returns on caught signals (SIGCONT), and no signal is delivered when the continue command is issued.

(gdb) break 17
Breakpoint 1 at 0x80484b3: file pause.c, line 17.
(gdb) continue
Continuing.
^C
Program received signal SIGINT, Interrupt.
0x0012d422 in __kernel_vsyscall ()
(gdb) signal SIGCHLD
Continuing with signal SIGCHLD.
^C
Program received signal SIGINT, Interrupt.
0x0012d422 in __kernel_vsyscall ()
(gdb) signal SIGCONT
Continuing with signal SIGCONT.

Breakpoint 1, main () at pause.c:17
17      printf("Caught signal: %d, %s\n",
(gdb) 
Danilo Piazzalunga
Ah. Excellent. Thank you very much. I'm able to use SIGPROF which we have hijacked for a handler that has no significant side effects.
Peeter Joot