Bug 15358 - gdb deadlock due to gdb calling calloc() in signal handler.
Summary: gdb deadlock due to gdb calling calloc() in signal handler.
Status: RESOLVED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: gdb (show other bugs)
Version: 7.2
: P2 normal
Target Milestone: 7.8
Assignee: Jan Kratochvil
URL:
Keywords:
Depends on: 15297
Blocks:
  Show dependency treegraph
 
Reported: 2013-04-11 15:02 UTC by Xavier Bru
Modified: 2014-03-18 21:52 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
Traces of manually reprucing the deadlock in calloc() (2.65 KB, application/octet-stream)
2013-04-11 15:02 UTC, Xavier Bru
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Xavier Bru 2013-04-11 15:02:43 UTC
Created attachment 6976 [details]
Traces of manually reprucing the deadlock in calloc()

gdb calls calloc() in signal hanler. It seems that this function is not reentrant.
If gdb catches a signal in calloc(), it can sometimes deadlock, due to calling calloc() in the signal handler. 


Version-Release number of selected component (if applicable): gdb-7.2-56


How reproducible: Can be reproduced manually using gdb to stop in calloc().
See attached traces .


Steps to Reproduce:
1. run gdb on gdb
2. set a breakpoint in calloc() after the cmpxchg instruction
3.  send a SIGTERM to gdb
  
Actual results:
gdb deadlocks


Expected results:
gdb should catch the signal and exit

Additional info:
On HPC cluster, gdb is used a lot by padb, ddt, etc with
a lot of parallel applications and it's very difficult to reproduce the issue in a testcase, but it has already been found in the deadlock (hereafter a trace on RHEL 6.1) :

# ps -ef | grep gdb
user   85753    1  0 15:04 ? 00:00:01 gdb --interpreter=mi -q
# gstack 85753
#0 0x000003405ef542e in __lll__lock_wait_private () from /lib64/libc.so.6
#1 0x000003405e7943b in _L_lock_8926 () from /lib64/libc.so.6
#2 0x000003405e7943b in calloc () from /lib64/libc.so.6
#3 0x0000000004159f9 in ?? ()
#4 0x000000000513b7b in ?? ()
#5 0x000000000513cbe in ?? ()
#6 0x0000000004134b7 in ?? ()
#7 <signal handler called>
#8 0x000003405e7a6e4 in _int_realloc () from /lib64/libc.so.6
#9 0x000003405e7aaf5 in realloc () from /lib64/libc.so.6
#10 0x000000000415a5d in ?? ()
#11 0x00000000054e873 in ?? ()
#12 0x000000000557094 in ?? ()
....
#41 0x000000000409869 in ?? ()
#42 0x000003405e1ecdd in __libc_start_main () from /lib64/libc.so.6
....
#50 0x000000000000000 in ?? ()
#
Comment 1 Jan Kratochvil 2013-04-12 08:35:19 UTC
See also Bug 15297.
Comment 2 Jan Kratochvil 2013-06-17 06:30:57 UTC
There still may be some issues you describe but doesn't your case rather happen fore remote gdbserver?  Such case should be fixed by the following pending patch:
[patch] Fix CTRL-C for remote.c (PR remote/15297)
http://sourceware.org/ml/gdb-patches/2013-06/msg00363.html
Comment 3 Jan Kratochvil 2013-07-03 05:31:06 UTC
[patch] Fix SIGTERM signal safety (PR gdb/15358)
http://sourceware.org/ml/gdb-patches/2013-07/msg00094.html
Comment 4 Jan Kratochvil 2014-03-14 18:38:10 UTC
just a new post:

[patch] Fix SIGTERM signal safety (PR gdb/15358) [refresh]
https://sourceware.org/ml/gdb-patches/2014-03/msg00336.html
Comment 5 Jan Kratochvil 2014-03-14 18:46:55 UTC
[patchv2] Fix SIGTERM signal safety (PR gdb/15358) [refresh]
https://sourceware.org/ml/gdb-patches/2014-03/msg00337.html
Message-ID: <20140314184535.GA30853@host2.jankratochvil.net>
Comment 6 Sourceware Commits 2014-03-18 21:51:30 UTC
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "gdb and binutils".

The branch, master has been updated
       via  06c868a8dc5ef46ab7dd6601c8bc2f417e415af9 (commit)
      from  dea80df0999ae0bad56e79af2a88a30be38bb8e4 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=06c868a8dc5ef46ab7dd6601c8bc2f417e415af9

commit 06c868a8dc5ef46ab7dd6601c8bc2f417e415af9
Author: Jan Kratochvil <jan.kratochvil@redhat.com>
Date:   Tue Mar 18 22:48:06 2014 +0100

    Fix SIGTERM signal safety (PR gdb/15358).
    
    gdb/
    2014-03-18  Jan Kratochvil  <jan.kratochvil@redhat.com>
    
    	PR gdb/15358
    	* defs.h (sync_quit_force_run): New declaration.
    	(QUIT): Check also SYNC_QUIT_FORCE_RUN.
    	* event-top.c (async_sigterm_handler): New declaration.
    	(async_sigterm_token): New variable.
    	(async_init_signals): Create also async_sigterm_token.
    	(async_sigterm_handler): New function.
    	(sync_quit_force_run): New variable.
    	(handle_sigterm): Replace quit_force call by other calls.
    	* utils.c (quit): Call quit_force if SYNC_QUIT_FORCE_RUN.
    
    gdb/testsuite/
    2014-03-18  Jan Kratochvil  <jan.kratochvil@redhat.com>
    
    	PR gdb/15358
    	* gdb.base/gdb-sigterm.c: New file.
    	* gdb.base/gdb-sigterm.exp: New file.
    
    Message-ID: <20140316135334.GA30698@host2.jankratochvil.net>

-----------------------------------------------------------------------

Summary of changes:
 gdb/ChangeLog                          |   13 ++++
 gdb/defs.h                             |    5 +-
 gdb/event-top.c                        |   27 ++++++++-
 gdb/testsuite/ChangeLog                |    6 ++
 gdb/testsuite/gdb.base/gdb-sigterm.c   |   26 +++++++++
 gdb/testsuite/gdb.base/gdb-sigterm.exp |   96 ++++++++++++++++++++++++++++++++
 gdb/utils.c                            |    6 ++
 7 files changed, 176 insertions(+), 3 deletions(-)
 create mode 100644 gdb/testsuite/gdb.base/gdb-sigterm.c
 create mode 100644 gdb/testsuite/gdb.base/gdb-sigterm.exp
Comment 7 Jan Kratochvil 2014-03-18 21:52:16 UTC
Checked in.