From patchwork Mon Jun 9 20:30:20 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kratochvil X-Patchwork-Id: 1398 Received: (qmail 26644 invoked by alias); 9 Jun 2014 20:30:27 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 26633 invoked by uid 89); 9 Jun 2014 20:30:26 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.4 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 09 Jun 2014 20:30:25 +0000 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s59KUOnG002373 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Mon, 9 Jun 2014 16:30:24 -0400 Received: from host2.jankratochvil.net (ovpn-116-48.ams2.redhat.com [10.36.116.48]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s59KUKgl027557 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=NO) for ; Mon, 9 Jun 2014 16:30:23 -0400 Date: Mon, 9 Jun 2014 22:30:20 +0200 From: Jan Kratochvil To: gdb-patches@sourceware.org Subject: [patch] Fix 'gcore' with exited threads Message-ID: <20140609203020.GA22447@host2.jankratochvil.net> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-IsSubscribed: yes Hi, https://bugzilla.redhat.com/show_bug.cgi?id=1099405 Program received signal SIGABRT, Aborted. [...] (gdb) gcore foobar Couldn't get registers: No such process. (gdb) info threads [...] (gdb) gcore foobar Saved corefile foobar (gdb) gcore tries to access the exited thread: [Thread 0x7ffff7fce700 (LWP 6895) exited] ptrace(PTRACE_GETREGS, 6895, 0, 0x7fff18167dd0) = -1 ESRCH (No such process) Without the TRY_CATCH protection testsuite FAILs for: FAIL: gdb.threads/gcore-thread.exp: save a zeroed-threads corefile FAIL: gdb.threads/gcore-thread.exp: core0file: re-load generated corefile (bad file format) Maybe the TRY_CATCH could be more inside update_thread_list(). Similar update_thread_list() call is IMO missing in procfs_make_note_section() but I do not have where to verify that change. Jan gdb/ 2014-06-09 Jan Kratochvil * linux-tdep.c (linux_make_corefile_notes): call update_thread_list, protected against exceptions. gdb/testsuite/ 2014-06-09 Jan Kratochvil * gdb.threads/gcore-stale-thread.c: New file. * gdb.threads/gcore-stale-thread.exp: New file. diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c index c10b8ee..fc5a943 100644 --- a/gdb/linux-tdep.c +++ b/gdb/linux-tdep.c @@ -1440,6 +1440,7 @@ linux_make_corefile_notes (struct gdbarch *gdbarch, bfd *obfd, int *note_size, char *note_data = NULL; gdb_byte *auxv; int auxv_len; + volatile struct gdb_exception e; if (linux_fill_prpsinfo (&prpsinfo)) { @@ -1463,6 +1464,12 @@ linux_make_corefile_notes (struct gdbarch *gdbarch, bfd *obfd, int *note_size, } /* Thread register information. */ + TRY_CATCH (e, RETURN_MASK_ERROR) + { + update_thread_list (); + } + if (e.reason < 0) + exception_print (gdb_stderr, e); thread_args.gdbarch = gdbarch; thread_args.pid = ptid_get_pid (inferior_ptid); thread_args.obfd = obfd; diff --git a/gdb/testsuite/gdb.threads/gcore-stale-thread.c b/gdb/testsuite/gdb.threads/gcore-stale-thread.c new file mode 100644 index 0000000..9fba7a7 --- /dev/null +++ b/gdb/testsuite/gdb.threads/gcore-stale-thread.c @@ -0,0 +1,39 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2014 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 . */ + +#include +#include + +static void * +start (void *arg) +{ + return arg; +} + +int +main (void) +{ + pthread_t thread; + int i; + + i = pthread_create (&thread, NULL, start, NULL); + assert (i == 0); + i = pthread_join (thread, NULL); + assert (i == 0); + + return 0; /* break-here */ +} diff --git a/gdb/testsuite/gdb.threads/gcore-stale-thread.exp b/gdb/testsuite/gdb.threads/gcore-stale-thread.exp new file mode 100644 index 0000000..a6677a8 --- /dev/null +++ b/gdb/testsuite/gdb.threads/gcore-stale-thread.exp @@ -0,0 +1,56 @@ +# Copyright 2014 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 . + +# This file was written by Michael Snyder (msnyder@redhat.com) +# This is a test for the gdb command "generate-core-file". + +standard_testfile +set corefile [standard_output_file ${testfile}.core] + +if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable debug] != ""} { + return -1 +} + +clean_restart ${testfile} + +gdb_test_multiple "help gcore" "help gcore" { + -re "Undefined command: .gcore.*\r\n$gdb_prompt $" { + # gcore command not supported -- nothing to test here. + unsupported "gdb does not support gcore on this target" + return -1 + } + -re "Save a core file .*\r\n$gdb_prompt $" { + pass "help gcore" + } +} + +if { ! [ runto_main ] } then { + return -1 +} + +gdb_test_multiple "info threads" "threads are supported" { + -re ".* main .*\r\n$gdb_prompt $" { + # OK, threads are supported. + } + -re "\r\n$gdb_prompt $" { + unsupported "gdb does not support threads on this target" + return -1 + } +} + +gdb_breakpoint ${srcfile}:[gdb_get_line_number "break-here"] +gdb_continue_to_breakpoint "break-here" ".* break-here .*" + +gdb_gcore_cmd "$corefile" "save a corefile"