From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 130907 invoked by alias); 30 Jan 2017 10:05:59 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 130804 invoked by uid 89); 30 Jan 2017 10:05:58 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.0 required=5.0 tests=AWL,BAYES_00,KAM_LAZY_DOMAIN_SECURITY,RP_MATCHES_RCVD autolearn=no version=3.3.2 spammy=HX-Envelope-From:sk:mmetzge X-HELO: mga14.intel.com Received: from mga14.intel.com (HELO mga14.intel.com) (192.55.52.115) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 30 Jan 2017 10:05:48 +0000 Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 30 Jan 2017 02:05:46 -0800 X-ExtLoop1: 1 Received: from irvmail001.ir.intel.com ([163.33.26.43]) by orsmga002.jf.intel.com with ESMTP; 30 Jan 2017 02:05:44 -0800 Received: from ulvlx001.iul.intel.com (ulvlx001.iul.intel.com [172.28.207.17]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id v0UA5hg7022183; Mon, 30 Jan 2017 10:05:43 GMT Received: from ulvlx001.iul.intel.com (localhost [127.0.0.1]) by ulvlx001.iul.intel.com with ESMTP id v0UA5hRd006883; Mon, 30 Jan 2017 11:05:43 +0100 Received: (from mmetzger@localhost) by ulvlx001.iul.intel.com with œ id v0UA5hVt006879; Mon, 30 Jan 2017 11:05:43 +0100 From: Markus Metzger To: gdb-patches@sourceware.org Cc: palves@redhat.com Subject: [PATCH v3 1/5] thread: add can_access_registers_ptid Date: Mon, 30 Jan 2017 10:06:00 -0000 Message-Id: <1485770743-6603-2-git-send-email-markus.t.metzger@intel.com> In-Reply-To: <1485770743-6603-1-git-send-email-markus.t.metzger@intel.com> References: <1485770743-6603-1-git-send-email-markus.t.metzger@intel.com> X-IsSubscribed: yes X-SW-Source: 2017-01/txt/msg00647.txt.bz2 Add a function can_access_registers_ptid that behaves like validate_registers_access but returns a boolean value instead of throwing an exception. 2017-01-30 Markus Metzger * gdbthread.h (can_access_registers_ptid): New. * thread.c (can_access_registers_ptid): New. --- gdb/gdbthread.h | 4 ++++ gdb/thread.c | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/gdb/gdbthread.h b/gdb/gdbthread.h index 455cfd8..06ed78f 100644 --- a/gdb/gdbthread.h +++ b/gdb/gdbthread.h @@ -625,6 +625,10 @@ extern void thread_cancel_execution_command (struct thread_info *thr); executing). */ extern void validate_registers_access (void); +/* Check whether it makes sense to access a register of PTID at this point. + Returns true if registers may be accessed; false otherwise. */ +extern bool can_access_registers_ptid (ptid_t ptid); + /* Returns whether to show which thread hit the breakpoint, received a signal, etc. and ended up causing a user-visible stop. This is true iff we ever detected multiple threads. */ diff --git a/gdb/thread.c b/gdb/thread.c index e45b257..99fe424 100644 --- a/gdb/thread.c +++ b/gdb/thread.c @@ -1141,6 +1141,26 @@ validate_registers_access (void) error (_("Selected thread is running.")); } +/* See gdbthread.h. */ + +bool +can_access_registers_ptid (ptid_t ptid) +{ + /* No thread, no registers. */ + if (ptid_equal (ptid, null_ptid)) + return false; + + /* Don't try to read from a dead thread. */ + if (is_exited (ptid)) + return false; + + /* ... or from a spinning thread. FIXME: see validate_registers_access. */ + if (is_executing (ptid)) + return false; + + return true; +} + int pc_in_thread_step_range (CORE_ADDR pc, struct thread_info *thread) { -- 1.8.3.1