From patchwork Thu Oct 22 09:59:00 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 9305 Received: (qmail 37591 invoked by alias); 22 Oct 2015 09:59:13 -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 37510 invoked by uid 89); 22 Oct 2015 09:59:13 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_HELO_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 (AES256-GCM-SHA384 encrypted) ESMTPS; Thu, 22 Oct 2015 09:59:09 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (Postfix) with ESMTPS id 541B540 for ; Thu, 22 Oct 2015 09:59:08 +0000 (UTC) Received: from brno.lan (ovpn01.gateway.prod.ext.ams2.redhat.com [10.39.146.11]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t9M9x5Ft014526 for ; Thu, 22 Oct 2015 05:59:07 -0400 From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 2/6] Linux: dump the signalled thread first Date: Thu, 22 Oct 2015 10:59:00 +0100 Message-Id: <1445507944-9197-3-git-send-email-palves@redhat.com> In-Reply-To: <1445507944-9197-1-git-send-email-palves@redhat.com> References: <1445507944-9197-1-git-send-email-palves@redhat.com> ... like the kernel does. gcore-thread.exp has a check to make sure the signalled thread is the current thread after loading the core back, but that just works by accident, because the signalled thread happened to be the last thread on the thread list, and gdb currently iterates over threads in reverse order. So this fixes gcore-thread.exp once we start walking threads in ascending number. gdb/ChangeLog: 2015-10-22 Pedro Alves * linux-tdep.c (find_stop_signal): Delete. (struct linux_corefile_thread_data) : Remove field. (linux_corefile_thread_callback): Rename to ... (linux_corefile_thread): ... this. Now takes a struct linux_corefile_thread_data pointer rather than a void pointer. Remove thread state and thread pid checks. (linux_make_corefile_notes): Prefer dumping the signalled thread first. Use ALL_NON_EXITED_THREADS instead of iterate_over_threads. --- gdb/linux-tdep.c | 126 +++++++++++++++++++++++++++---------------------------- 1 file changed, 63 insertions(+), 63 deletions(-) diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c index 7c24eaa..2e7b87f 100644 --- a/gdb/linux-tdep.c +++ b/gdb/linux-tdep.c @@ -1342,18 +1342,6 @@ find_signalled_thread (struct thread_info *info, void *data) return 0; } -static enum gdb_signal -find_stop_signal (void) -{ - struct thread_info *info = - iterate_over_threads (find_signalled_thread, NULL); - - if (info) - return info->suspend.stop_signal; - else - return GDB_SIGNAL_0; -} - /* Generate corefile notes for SPU contexts. */ static char * @@ -1656,62 +1644,49 @@ linux_get_siginfo_data (struct gdbarch *gdbarch, LONGEST *size) struct linux_corefile_thread_data { struct gdbarch *gdbarch; - int pid; bfd *obfd; char *note_data; int *note_size; enum gdb_signal stop_signal; }; -/* Called by gdbthread.c once per thread. Records the thread's - register state for the corefile note section. */ +/* Records the thread's register state for the corefile note + section. */ -static int -linux_corefile_thread_callback (struct thread_info *info, void *data) +static void +linux_corefile_thread (struct thread_info *info, + struct linux_corefile_thread_data *args) { - struct linux_corefile_thread_data *args - = (struct linux_corefile_thread_data *) data; - - /* It can be current thread - which cannot be removed by update_thread_list. */ - if (info->state == THREAD_EXITED) - return 0; - - if (ptid_get_pid (info->ptid) == args->pid) - { - struct cleanup *old_chain; - struct regcache *regcache; - gdb_byte *siginfo_data; - LONGEST siginfo_size = 0; - - regcache = get_thread_arch_regcache (info->ptid, args->gdbarch); - - old_chain = save_inferior_ptid (); - inferior_ptid = info->ptid; - target_fetch_registers (regcache, -1); - siginfo_data = linux_get_siginfo_data (args->gdbarch, &siginfo_size); - do_cleanups (old_chain); - - old_chain = make_cleanup (xfree, siginfo_data); - - args->note_data = linux_collect_thread_registers - (regcache, info->ptid, args->obfd, args->note_data, - args->note_size, args->stop_signal); - - /* Don't return anything if we got no register information above, - such a core file is useless. */ - if (args->note_data != NULL) - if (siginfo_data != NULL) - args->note_data = elfcore_write_note (args->obfd, - args->note_data, - args->note_size, - "CORE", NT_SIGINFO, - siginfo_data, siginfo_size); - - do_cleanups (old_chain); - } - - return !args->note_data; + struct cleanup *old_chain; + struct regcache *regcache; + gdb_byte *siginfo_data; + LONGEST siginfo_size = 0; + + regcache = get_thread_arch_regcache (info->ptid, args->gdbarch); + + old_chain = save_inferior_ptid (); + inferior_ptid = info->ptid; + target_fetch_registers (regcache, -1); + siginfo_data = linux_get_siginfo_data (args->gdbarch, &siginfo_size); + do_cleanups (old_chain); + + old_chain = make_cleanup (xfree, siginfo_data); + + args->note_data = linux_collect_thread_registers + (regcache, info->ptid, args->obfd, args->note_data, + args->note_size, args->stop_signal); + + /* Don't return anything if we got no register information above, + such a core file is useless. */ + if (args->note_data != NULL) + if (siginfo_data != NULL) + args->note_data = elfcore_write_note (args->obfd, + args->note_data, + args->note_size, + "CORE", NT_SIGINFO, + siginfo_data, siginfo_size); + + do_cleanups (old_chain); } /* Fill the PRPSINFO structure with information about the process being @@ -1927,6 +1902,7 @@ linux_make_corefile_notes (struct gdbarch *gdbarch, bfd *obfd, int *note_size) char *note_data = NULL; gdb_byte *auxv; int auxv_len; + struct thread_info *curr_thr, *signalled_thr, *thr; if (! gdbarch_iterate_over_regset_sections_p (gdbarch)) return NULL; @@ -1963,13 +1939,37 @@ linux_make_corefile_notes (struct gdbarch *gdbarch, bfd *obfd, int *note_size) } END_CATCH + /* Like the kernel, prefer dumping the signalled thread first. + "First thread" is what tools use to infer the signalled thread. + In case there's more than one signalled thread, prefer the + current thread, if it is signalled. */ + curr_thr = inferior_thread (); + if (curr_thr->suspend.stop_signal != GDB_SIGNAL_0) + signalled_thr = curr_thr; + else + { + signalled_thr = iterate_over_threads (find_signalled_thread, NULL); + if (signalled_thr == NULL) + signalled_thr = curr_thr; + } + thread_args.gdbarch = gdbarch; - thread_args.pid = ptid_get_pid (inferior_ptid); thread_args.obfd = obfd; thread_args.note_data = note_data; thread_args.note_size = note_size; - thread_args.stop_signal = find_stop_signal (); - iterate_over_threads (linux_corefile_thread_callback, &thread_args); + thread_args.stop_signal = signalled_thr->suspend.stop_signal; + + linux_corefile_thread (signalled_thr, &thread_args); + ALL_NON_EXITED_THREADS (thr) + { + if (thr == signalled_thr) + continue; + if (ptid_get_pid (thr->ptid) != ptid_get_pid (inferior_ptid)) + continue; + + linux_corefile_thread (thr, &thread_args); + } + note_data = thread_args.note_data; if (!note_data) return NULL;