gdb fails to interrupt program being debugged

Originator:mackyle
Number:rdar://6850186 Date Originated:02-May-2009 10:39 AM
Status:Duplicate/6844166 Resolved:
Product:Developer Tools Product Version:xcode312_2621_developerdvd
Classification:Serious Bug Reproducible:Always
 
02-May-2009 10:39 AM Kyle McKay:
-------
Summary
-------
gdb fails to interrupt the program being debugged if the program is blocking SIGINT.

When using the sigwait function to retrieve signals, the program is expected to block them.  SIGINT is a commonly handled signal.  Any program using sigwait to retrieve signals and handling SIGINT this way will not be interruptible by gdb.

The Xcode debugger is also affected by this problem since it uses gdb.

------------------
Steps to Reproduce
------------------
1. Save this file as noint.c:

  #include <stddef.h>
  #include <unistd.h>
  #include <signal.h>
  
  int main(int argc, char *argv[])
  {
    sigset_t sigs;
    sigfillset(&sigs);
    sigprocmask(SIG_SETMASK, &sigs, NULL);
    for (;;) {
      pause();
      write(STDERR_FILENO, "Nope\n", 5);
    }
    return 0;
  }

2. Compile it like this:

  gcc -o noint -O0 -g noint.c

3. Load it under gdb like so:

  gdb -t /dev/null noint

4. Then run it with the "run" gdb command

5. Now attempt to interrupt it by pressing Ctrl-C

6. Notice it's not interruptible and gdb does not regain control

----------------
Expected Results
----------------
The expectation is that gdb will regain control when Ctrl-C is pressed.  Commenting out the call to sigprocmask and repeating the steps will result in gdb gaining control when Ctrl-C is pressed.

-----
Notes
-----
Although Xcode runs gdb using the mi interpreter (as opposed to the console interpreter), Xcode has the same problem interrupting the sample code above -- pressing the "Pause" button in the Xcode debugger does nothing.

Patching the gdb source (current as of Mac OS X 10.5.6) found here:

  http://opensource.apple.com/darwinsource/tarballs/other/gdb-768.tar.gz

with the attached interrupt_fix.patch eliminates the problem.

The patch makes minor changes to the macosx_child_stop and mi_cmd_exec_interrupt functions.

Here are the contents of interrupt_fix.patch:

  --- gdb/macosx/macosx-nat-inferior.c	2007-09-19 19:03:27.000000000 -0700
  +++ gdb/macosx/macosx-nat-inferior.c	2009-05-01 10:25:02.000000000 -0700
  @@ -1085,7 +1085,7 @@
     extern pid_t inferior_process_group;
     int ret;
   
  -  ret = kill (inferior_process_group, SIGINT);
  +  ret = kill (inferior_process_group, SIGSTOP);
   }
   
   static void
  --- gdb/mi/mi-main.c	2007-06-21 18:28:02.000000000 -0700
  +++ gdb/mi/mi-main.c	2009-05-01 21:38:47.000000000 -0700
  @@ -296,7 +296,7 @@
     else
       {
         int pid = PIDGET (inferior_ptid);
  -      kill (pid, SIGINT);
  +      kill (pid, SIGSTOP);
       }
   
     if (current_command_token) {



'interrupt_fix.patch' was successfully uploaded

13-May-2009 12:28 AM Kyle McKay:
Updated patch file (interrupt_fix_963.patch) attached for the most recent Apple gdb sources found here:

  http://www.opensource.apple.com/tarballs/gdb/gdb-963.tar.gz

Here are the contents of interrupt_fix_963.patch:

  --- gdb/infrun.c  2008-03-06 11:18:32.000000000 -0800
  +++ gdb/infrun.c  2009-05-12 23:25:55.000000000 -0700
  @@ -4072,7 +4072,7 @@
             switch ((enum target_signal) signum)
               {
               case TARGET_SIGNAL_TRAP:
  -            case TARGET_SIGNAL_INT:
  +            case TARGET_SIGNAL_STOP:
                 if (!allsigs && !sigs[signum])
                   {
                     if (query ("%s is used by the debugger.\n\
  @@ -4652,7 +4652,7 @@
     /* Signals caused by debugger's own actions
        should not be given to the program afterwards.  */
     signal_program[TARGET_SIGNAL_TRAP] = 0;
  -  signal_program[TARGET_SIGNAL_INT] = 0;
  +  signal_program[TARGET_SIGNAL_STOP] = 0;
   
     /* Signals that are not errors should not normally enter the debugger.  */
     signal_stop[TARGET_SIGNAL_ALRM] = 0;
  --- gdb/macosx/macosx-nat-inferior.c  2008-09-26 15:02:53.000000000 -0700
  +++ gdb/macosx/macosx-nat-inferior.c  2009-05-12 23:10:18.000000000 -0700
  @@ -1107,7 +1107,7 @@
     pid_t pid = PIDGET (inferior_ptid);
     int ret;
   
  -  ret = kill (pid, SIGINT);
  +  ret = kill (pid, SIGSTOP);
   }
   
   static void



'interrupt_fix_963.patch' was successfully uploaded

13-May-2009 11:31 AM KIT CHEUNG :
This bug has been closed as Duplicate. We are tracking this known issue under the Bug ID listed above in the bug State (Duplicate/XXXX).

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!