From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Cc: Pedro Alves <palves@redhat.com>
Subject: [PING^2][PATCH][gdb] Fix hang after ext sigkill
Date: Mon, 23 Mar 2020 20:16:54 +0100 [thread overview]
Message-ID: <b420fd6d-28b1-8736-8f91-20e8ec988f11@suse.de> (raw)
In-Reply-To: <2dc5460f-33b3-227d-6e46-8d8663149931@suse.de>
On 09-03-2020 13:52, Tom de Vries wrote:
> On 24-02-2020 21:14, Tom de Vries wrote:
>> Hi,
>>
>> Consider the test-case from this patch, compiled with pthread support:
>> ...
>> $ gcc src/gdb/testsuite/gdb.threads/hang-after-ext-sigkill.c -lpthread
>> ...
>>
>> After running, the program sleeps:
>> ...
>> $ gdb a.out
>> Reading symbols from a.out...
>> (gdb) r
>> Starting program: /data/gdb_versions/devel/a.out
>> [Thread debugging using libthread_db enabled]
>> Using host libthread_db library "/lib64/libthread_db.so.1".
>> [New Thread 0x7ffff77fe700 (LWP 22604)]
>> ...
>>
>> Until we interrupt it with a control-C:
>> ...
>> ^C
>> Thread 1 "a.out" received signal SIGINT, Interrupt.
>> 0x00007ffff78c50f0 in nanosleep () from /lib64/libc.so.6
>> (gdb)
>> ...
>>
>> If we then kill the inferior using an external SIGKILL:
>> ...
>> (gdb) shell killall -s SIGKILL a.out
>> ...
>> and subsequently continue:
>> ...
>> (gdb) c
>> Continuing.
>> Couldn't get registers: No such process.
>> Couldn't get registers: No such process.
>> (gdb) Couldn't get registers: No such process.
>> (gdb) Couldn't get registers: No such process.
>> (gdb) Couldn't get registers: No such process.
>> <repeat>
>> ...
>> gdb hangs which repeating the same warning. Typing control-C no longer helps,
>> and we have to kill gdb using kill.
>>
>> This is a regression since commit 873657b9e8 "Preserve selected thread in
>> all-stop w/ background execution". The commit adds a
>> scoped_restore_current_thread typed variable restore_thread to
>> fetch_inferior_event, and the hang is caused by the constructor throwing an
>> exception.
>>
>> Fix this by catching the exception in the constructor.
>>
>> Build and reg-tested on x86_64-linux.
>>
>> OK for trunk?
>>
>
Ping^2.
Thanks,
- Tom
>
>> [gdb] Fix hang after ext sigkill
>>
>> gdb/ChangeLog:
>>
>> 2020-02-24 Tom de Vries <tdevries@suse.de>
>>
>> PR gdb/25471
>> * thread.c
>> (scoped_restore_current_thread::scoped_restore_current_thread): Catch
>> exception in get_frame_id.
>> (scoped_restore_current_thread::~scoped_restore_current_thread):
>> Handle lack of inferior.
>>
>> gdb/testsuite/ChangeLog:
>>
>> 2020-02-24 Tom de Vries <tdevries@suse.de>
>>
>> PR gdb/25471
>> * gdb.threads/hang-after-ext-sigkill.c: New test.
>> * gdb.threads/hang-after-ext-sigkill.exp: New file.
>> * lib/gdb.exp (runto): Handle "Temporary breakpoint" string.
>>
>> ---
>> gdb/testsuite/gdb.threads/hang-after-ext-sigkill.c | 40 ++++++++++++
>> .../gdb.threads/hang-after-ext-sigkill.exp | 73 ++++++++++++++++++++++
>> gdb/testsuite/lib/gdb.exp | 2 +-
>> gdb/thread.c | 14 ++++-
>> 4 files changed, 127 insertions(+), 2 deletions(-)
>>
>> diff --git a/gdb/testsuite/gdb.threads/hang-after-ext-sigkill.c b/gdb/testsuite/gdb.threads/hang-after-ext-sigkill.c
>> new file mode 100644
>> index 0000000000..bfce6c3085
>> --- /dev/null
>> +++ b/gdb/testsuite/gdb.threads/hang-after-ext-sigkill.c
>> @@ -0,0 +1,40 @@
>> +/* This testcase is part of GDB, the GNU debugger.
>> +
>> + Copyright 2020 Free Software Foundation, Inc.
>> +
>> + This program is free software; you can redistribute it and/or modify
>> + it under the terms of the GNU General Public License as published by
>> + the Free Software Foundation; either version 3 of the License, or
>> + (at your option) any later version.
>> +
>> + This program is distributed in the hope that it will be useful,
>> + but WITHOUT ANY WARRANTY; without even the implied warranty of
>> + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
>> + GNU General Public License for more details.
>> +
>> + You should have received a copy of the GNU General Public License
>> + along with this program. If not, see <http://www.gnu.org/licenses/>. */
>> +
>> +#include <pthread.h>
>> +#include <unistd.h>
>> +
>> +static void *
>> +fun (void *dummy)
>> +{
>> + while (1)
>> + sleep (1);
>> +
>> + return NULL;
>> +}
>> +
>> +int
>> +main (void)
>> +{
>> + pthread_t thread;
>> + pthread_create (&thread, NULL, fun, NULL);
>> +
>> + while (1)
>> + sleep (1);
>> +
>> + return 0;
>> +}
>> diff --git a/gdb/testsuite/gdb.threads/hang-after-ext-sigkill.exp b/gdb/testsuite/gdb.threads/hang-after-ext-sigkill.exp
>> new file mode 100644
>> index 0000000000..3702eb8c13
>> --- /dev/null
>> +++ b/gdb/testsuite/gdb.threads/hang-after-ext-sigkill.exp
>> @@ -0,0 +1,73 @@
>> +# Copyright (C) 2020 Free Software Foundation, Inc.
>> +
>> +# This program is free software; you can redistribute it and/or modify
>> +# it under the terms of the GNU General Public License as published by
>> +# the Free Software Foundation; either version 3 of the License, or
>> +# (at your option) any later version.
>> +#
>> +# This program is distributed in the hope that it will be useful,
>> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
>> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
>> +# GNU General Public License for more details.
>> +#
>> +# You should have received a copy of the GNU General Public License
>> +# along with this program. If not, see <http://www.gnu.org/licenses/>.
>> +
>> +standard_testfile
>> +
>> +if {[prepare_for_testing "failed to prepare" $testfile $srcfile \
>> + {pthreads}] == -1} {
>> + return -1
>> +}
>> +
>> +set res [runto main no-message temporary]
>> +if { $res != 1 } {
>> + return -1
>> +}
>> +
>> +set pid -1
>> +gdb_test_multiple "info inferior 1" "get inferior pid" {
>> + -re -wrap "process (\[0-9\]*).*" {
>> + set pid $expect_out(1,string)
>> + pass $gdb_test_name
>> + }
>> +}
>> +if { $pid == -1 } {
>> + return -1
>> +}
>> +
>> +gdb_test_multiple "continue" "" {
>> + -re "Continuing" {
>> + pass $gdb_test_name
>> + }
>> +}
>> +
>> +send_gdb "\003"
>> +
>> +gdb_test_multiple "" "get sigint" {
>> + -re -wrap "Thread \[0-9\]+ .* received signal SIGINT, Interrupt\..*" {
>> + pass $gdb_test_name
>> + }
>> +}
>> +
>> +gdb_test_no_output "shell kill -s SIGKILL $pid" "shell kill -s SIGKILL pid"
>> +
>> +# Expect the signal to arrive, and the program to terminate.
>> +# Ideally at the first continue, currently though at the second.
>> +set killed_msg "Program terminated with signal SIGKILL, Killed\."
>> +set no_longer_exists_msg "The program no longer exists\."
>> +set not_being_run_msg "The program is not being run\."
>> +set msg [join [list $killed_msg $no_longer_exists_msg $not_being_run_msg] \
>> + ".*"]
>> +
>> +# Don't expect '$gdb_prompt $', there still may be output after the prompt,
>> +# f.i.:
>> +# ...
>> +# (gdb) [Thread 0x7ffff74c6700 (LWP 19277) exited]^M
>> +# ...
>> +gdb_test_multiple "continue" "" {
>> + -re ".*\r\n$gdb_prompt " {
>> + gdb_test "continue" $msg $gdb_test_name
>> + }
>> +}
>> +
>> diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
>> index 81518b9646..745694df2d 100644
>> --- a/gdb/testsuite/lib/gdb.exp
>> +++ b/gdb/testsuite/lib/gdb.exp
>> @@ -571,7 +571,7 @@ proc runto { function args } {
>> }
>> return 1
>> }
>> - -re "Breakpoint \[0-9\]*, \[0-9xa-f\]* in .*$gdb_prompt $" {
>> + -re "\[Bb\]reakpoint \[0-9\]*, \[0-9xa-f\]* in .*$gdb_prompt $" {
>> if { $print_pass } {
>> pass $test_name
>> }
>> diff --git a/gdb/thread.c b/gdb/thread.c
>> index 54b59e2244..9876ca3c76 100644
>> --- a/gdb/thread.c
>> +++ b/gdb/thread.c
>> @@ -1444,6 +1444,8 @@ scoped_restore_current_thread::restore ()
>>
>> scoped_restore_current_thread::~scoped_restore_current_thread ()
>> {
>> + if (m_inf == NULL)
>> + return;
>> if (!m_dont_restore)
>> {
>> try
>> @@ -1488,7 +1490,17 @@ scoped_restore_current_thread::scoped_restore_current_thread ()
>> else
>> frame = NULL;
>>
>> - m_selected_frame_id = get_frame_id (frame);
>> + try
>> + {
>> + m_selected_frame_id = get_frame_id (frame);
>> + }
>> + catch (const gdb_exception &ex)
>> + {
>> + m_inf = NULL;
>> + m_selected_frame_id = null_frame_id;
>> + m_selected_frame_level = -1;
>> + return;
>> + }
>> m_selected_frame_level = frame_relative_level (frame);
>>
>> tp->incref ();
>>
next prev parent reply other threads:[~2020-03-23 19:16 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-24 20:14 [PATCH][gdb] " Tom de Vries
2020-03-09 12:52 ` [PING][PATCH][gdb] " Tom de Vries
2020-03-23 19:16 ` Tom de Vries [this message]
2020-03-24 15:35 ` [PATCH][gdb] " Simon Marchi
2020-03-25 10:29 ` Tom de Vries
2020-03-25 14:44 ` Simon Marchi
2020-03-25 15:51 ` Tom de Vries
2020-03-25 15:57 ` Simon Marchi
2020-04-16 13:28 ` Pedro Alves
2020-04-21 12:38 ` Tom de Vries
2020-04-21 13:42 ` Pedro Alves
2020-09-25 9:39 ` Tom de Vries
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=b420fd6d-28b1-8736-8f91-20e8ec988f11@suse.de \
--to=tdevries@suse.de \
--cc=gdb-patches@sourceware.org \
--cc=palves@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox