Bug #21567 mysqld doesn't react to Ctrl-C when run under GDB even with the --gdb option
Submitted: 10 Aug 2006 15:11 Modified: 17 Mar 2008 20:20
Reporter: Georgi Kodinov Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: General Severity:S3 (Non-critical)
Version:4.1.22-BK/5.0.25-BK OS:Mac OS X (MacOSX 10.4.7/Intel)
Assigned to: Tatiana Azundris Nuernberg CPU Architecture:Any

[10 Aug 2006 15:11] Georgi Kodinov
Description:
On Linux if you run mysql under the gdb debugger with --gdb option it will allow Ctrl-C to stop the server and return to the gdb prompt. However on MacOSX / Intel Ctrl-C in gdb doesn't work for mysql.
I've verified that it works with a 'hello world' type of C program.
Under MacOSX It however reacts (and shows the gdb prompt) to the unix 'kill' command (no args) : 'killall mysqld' when issued from another terminal on the same box.

How to repeat:
1. Compile mysql from bk with BUILD/complie-pentium-debug-max
2. Start the server under GDB and don't set any breakpoints.
3. Try getting the gdb prompt by hitting Ctrl-C at the gdb's window. 
To be terribly specific I'm using the default Terminal.app (from the MacOSX distro) on a MacBook with its built-in keyboard. My gdb is from the latest XCode. it's version says : 6.3.50-20050815 (Apple version gdb-477).

Suggested fix:
Make the MacOSX binary behave in the same way as the linux one.
[10 Aug 2006 15:14] Georgi Kodinov
my .gdbinit

Attachment: gdbinit (application/octet-stream, text), 1.08 KiB.

[25 Sep 2006 10:38] Domas Mituzas
This behavior indeed exists, and might be the issue of how signals are delivered to threads by gdb. 

Threadless program with simple signal attached could be interrupted from inside gdb.
[8 Jan 2008 20:54] Mattias Jonsson
Seems like SIGINT is blocked even when --gdb is used on Mac OS X.

it seems to work with this small patch:
$ bk diffs -Nu mysqld.cc
===== mysqld.cc 1.637 vs edited =====
--- 1.637/sql/mysqld.cc	2007-12-15 15:10:03 +01:00
+++ edited/sql/mysqld.cc	2008-01-08 21:48:44 +01:00
@@ -2408,6 +2408,7 @@
     sigaddset(&set,THR_SERVER_ALARM);
   if (test_flags & TEST_SIGINT)
   {
+    sigdelset(&set,SIGINT);
     // May be SIGINT
     sigdelset(&set, thr_kill_signal);
   }

(or just add "if (!(test_flag & TEST_SIGINT))" before sigaddset(&set,SIGINT))
[9 Jan 2008 7:22] Tatiana Azundris Nuernberg
- verified as also existing on powermac (7.9)

- correct, on Mac, thr_kill_signal is set to SIGUSR2 (31 et al.)
  rather than SIGINT (2).

- this happens here:

#if defined(SIGUSR2)
  thr_kill_signal= thd_lib_detected == THD_LIB_LT ? SIGINT : SIGUSR2;
#else
  thr_kill_signal= SIGINT;
#endif

  If SIGUSR2 is defined, and it's not used up by LinuxThreads,
  we use it.  (In fact, even LT only uses it up on a really old
  kernel or with a really old libc, but we don't check for that.)

  The funny bit is that we *do* unblock SIGINT, in

pthread_handler_t signal_hand(void *arg __attribute__((unused))) {
...
  if (thd_lib_detected != THD_LIB_LT && (test_flags & TEST_SIGINT))
  {
    (void) sigemptyset(&set);                   // Setup up SIGINT for debug
    (void) sigaddset(&set,SIGINT);              // For debugging
    (void) pthread_sigmask(SIG_UNBLOCK,&set,NULL);
+   (void) sigprocmask(SIG_UNBLOCK, &set, NULL);
  }
...

  If we add that last line, everything works as expected on Mac.
  It's still not the preferred solution as sigprocmask() behaviour
  is undefined in MT use on some systems, so we'll just stick with
  the set-up in init_signals().  That uses sigprocmask() too, but
  at least at that stage, we only have one thread up.
[9 Jan 2008 7:59] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/40738

ChangeSet@1.2588, 2008-01-09 08:59:12+01:00, tnurnberg@mysql.com +1 -0
  Bug#21567: mysqld doesn't react to Ctrl-C when run under GDB even with the --gdb option
  
  Don't block SIGINT (Control-C) when --gdb is passed to mysqld.
  Was broken at least on OS X.
  
  (kudos to Mattias Jonsson)
[9 Jan 2008 9:11] Georgi Kodinov
Verified that it works on my MacOSX 10.5/Intel. Great work !
[5 Feb 2008 11:57] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/41703

ChangeSet@1.2547, 2008-02-05 12:56:49+01:00, tnurnberg@blasphemy.intern.azundris.com +1 -0
  Bug#21567: mysqld doesn't react to Ctrl-C when run under GDB even with the --gdb option
  
  Don't block SIGINT (Control-C) when --gdb is passed to mysqld.
  Was broken at least on OS X.
  
  (kudos to Mattias Jonsson)
[24 Feb 2008 10:57] Tatiana Azundris Nuernberg
pushed to 5.0.52, 5.1.23-rc, 6.0.5-alpha in opt
[13 Mar 2008 19:26] Bugs System
Pushed into 6.0.5-alpha
[13 Mar 2008 19:34] Bugs System
Pushed into 5.1.24-rc
[13 Mar 2008 19:42] Bugs System
Pushed into 5.0.60
[17 Mar 2008 20:20] Paul DuBois
Noted in 5.0.60, 5.1.24, 6.0.5 changelogs.

On Mac OS X, mysqld did not react to Ctrl-C when run under gdb, even
when run with the --gdb option.
[29 Mar 2008 23:51] Jon Stephens
Fix also documented for 5.1.23-ndb-6.3.11.