From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id mF+LDh2UC2LWfgAAWB0awg (envelope-from ) for ; Tue, 15 Feb 2022 06:53:01 -0500 Received: by simark.ca (Postfix, from userid 112) id 393D61F3C5; Tue, 15 Feb 2022 06:53:01 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RDNS_DYNAMIC,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 827CB1EDF0 for ; Tue, 15 Feb 2022 06:53:00 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6F8D23857C43 for ; Tue, 15 Feb 2022 11:52:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6F8D23857C43 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1644925977; bh=tQVJ/IHxd4bILZ08JHAEIpwOWwKLRV/717vAlOAWcgQ=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=vZtnkgzMaYwcO0CAzvDxBJY8EfM9piEZnamlr8A3Gxah0RzbY0C7l7V/COlYN4YKF qSM3yCl7uGOg8bCPKvddgP6WPK4dg7BL8t2bWVmLsA/bkHSUGrD7rNhfm9/696Af2A IEa0jmogtL+fIqwAUlh20nBlFBNNwzJQtZ9+SmDw= Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 0966D3858C74 for ; Tue, 15 Feb 2022 11:52:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0966D3858C74 Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-622-4LNR8tMLM4CNS-dypNHDOg-1; Tue, 15 Feb 2022 06:52:37 -0500 X-MC-Unique: 4LNR8tMLM4CNS-dypNHDOg-1 Received: by mail-wm1-f69.google.com with SMTP id 125-20020a1c0283000000b0037bf720e6a8so1263565wmc.8 for ; Tue, 15 Feb 2022 03:52:37 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=tQVJ/IHxd4bILZ08JHAEIpwOWwKLRV/717vAlOAWcgQ=; b=sI53bJiOKzCnTqHhg1TXOl/d4eQeVqErDFKwvHXDuZhdL6EJv6mgWWDHDW93MVEeEB /SJoHDRkenQgRyXuYrXCGMUj2EAwin2t+Z3MjvjbLJfqpZoWMXhy8XbN1Um6uclA/svJ uqHxDf3hkw4YZp5Knh06qaBR2lt0yHWcEpGIPl46gkU3yTtobf6oAOC2NyCSDbMK9kkZ 4S51gpQq3kPW8I+b3I4YGnjx7D8jZrNiSEHd/7V68M7KHfcxwgkZkH1lsupBXyuVPwD6 eFBc9wRxp7Ijd7wMnGV2UJkKDm1ulfqstS+iMc046jMBbj4i0+eYbByHylC0LkQ+Ai7a nxPQ== X-Gm-Message-State: AOAM530zs/O6tNBAKIqNdB4dLdWzG+JU/PtUZ1nPdbhp9sUb3r1hGd/0 icLWds+QWyGib7leN7gSmV/T1S06H8Bgr7KTeyqCI8ObCkJ3g4Ss3JUE+1X2d2FQhMblAK49IqV KX3UO03DQAa9Ox44QnZQiJehm/9PQfhm02loeeO5eceSQhvh+q8R3GvTxTZddV5reEmDQgngCag == X-Received: by 2002:a05:600c:1d1b:b0:37b:f8cc:2f71 with SMTP id l27-20020a05600c1d1b00b0037bf8cc2f71mr2795262wms.74.1644925956046; Tue, 15 Feb 2022 03:52:36 -0800 (PST) X-Google-Smtp-Source: ABdhPJyvRPHG7mj3sFzgV6nQquoETdwb2A/g+W9D4SCvRmDvs0c0B/fuaYnRq1KuzbuvelkAfcVDPA== X-Received: by 2002:a05:600c:1d1b:b0:37b:f8cc:2f71 with SMTP id l27-20020a05600c1d1b00b0037bf8cc2f71mr2795239wms.74.1644925955613; Tue, 15 Feb 2022 03:52:35 -0800 (PST) Received: from localhost (host86-134-151-224.range86-134.btcentralplus.com. [86.134.151.224]) by smtp.gmail.com with ESMTPSA id p8sm26321400wro.106.2022.02.15.03.52.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Feb 2022 03:52:35 -0800 (PST) To: gdb-patches@sourceware.org Subject: [PATCH] gdb/python: Add gdb.InferiorThread.details attribute Date: Tue, 15 Feb 2022 11:52:33 +0000 Message-Id: <20220215115233.56924-1-aburgess@redhat.com> X-Mailer: git-send-email 2.25.4 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Andrew Burgess via Gdb-patches Reply-To: Andrew Burgess Cc: Andrew Burgess Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" This adds a new read-only attribute gdb.InferiorThread.details, this attribute contains a string, the results of target_extra_thread_info for the thread, or None, if target_extra_thread_info returns nullptr. As the string returned by target_extra_thread_info is unstructured, this attribute is only really useful for echoing straight through to the user, but, if a user wants to write a command that displays the same, or a similar 'Thread Id' to the one seen in 'info threads', then they need access to this string. Given that the string produced by target_extra_thread_info varies by target, there's only minimal testing of this attribute, I check that the attribute can be accessed, and that the return value is either None, or a string. --- gdb/NEWS | 5 +++++ gdb/doc/python.texi | 7 +++++++ gdb/python/py-infthread.c | 21 +++++++++++++++++++++ gdb/testsuite/gdb.python/py-infthread.exp | 5 +++++ 4 files changed, 38 insertions(+) diff --git a/gdb/NEWS b/gdb/NEWS index 9da74e71796..10b5489622c 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -185,6 +185,11 @@ GNU/Linux/LoongArch loongarch*-*-linux* set styling'). When false, which is the default if the argument is not given, then no styling is applied to the returned string. + ** New read-only attribute gdb.InferiorThread.details, which is + either a string, containing additional, target specific thread + state information, or None, if there is no such additional + information. + * New features in the GDB remote stub, GDBserver ** GDBserver is now supported on OpenRISC GNU/Linux. diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi index c1a3f5f2a7e..ac4ebbeaeae 100644 --- a/gdb/doc/python.texi +++ b/gdb/doc/python.texi @@ -3574,6 +3574,13 @@ a @code{gdb.Inferior} object. This attribute is not writable. @end defvar +@defvar InferiorThread.details +A string containing target specific, thread state information. The +format of this string varies by target. If there is no additional +state information for this thread, then this attribute contains +@code{None}. +@end defvar + A @code{gdb.InferiorThread} object has the following methods: @defun InferiorThread.is_valid () diff --git a/gdb/python/py-infthread.c b/gdb/python/py-infthread.c index e568d8d916e..efd536688c1 100644 --- a/gdb/python/py-infthread.c +++ b/gdb/python/py-infthread.c @@ -76,6 +76,24 @@ thpy_get_name (PyObject *self, void *ignore) return PyString_FromString (name); } +/* Return a string containing target specific additional information about + the state of the thread, or None, if there is no such additional + information. */ + +static PyObject * +thpy_get_details (PyObject *self, void *ignore) +{ + thread_object *thread_obj = (thread_object *) self; + + THPY_REQUIRE_VALID (thread_obj); + + const char *extra_info = target_extra_thread_info (thread_obj->thread); + if (extra_info == nullptr) + Py_RETURN_NONE; + + return PyString_FromString (extra_info); +} + static int thpy_set_name (PyObject *self, PyObject *newvalue, void *ignore) { @@ -347,6 +365,9 @@ static gdb_PyGetSetDef thread_object_getset[] = { { "name", thpy_get_name, thpy_set_name, "The name of the thread, as set by the user or the OS.", NULL }, + { "details", thpy_get_details, NULL, + "A target specific string containing extra thread state details.", + NULL }, { "num", thpy_get_num, NULL, "Per-inferior number of the thread, as assigned by GDB.", NULL }, { "global_num", thpy_get_global_num, NULL, diff --git a/gdb/testsuite/gdb.python/py-infthread.exp b/gdb/testsuite/gdb.python/py-infthread.exp index 5cbbe43c44c..a7754198e60 100644 --- a/gdb/testsuite/gdb.python/py-infthread.exp +++ b/gdb/testsuite/gdb.python/py-infthread.exp @@ -77,6 +77,11 @@ gdb_py_test_silent_cmd "python gdb.selected_thread().name = None" \ gdb_test "python print (gdb.selected_thread().name == name)" "True" \ "check name of current thread again" +gdb_test_no_output "python details = gdb.selected_thread().details" \ + "record the thread details string" +gdb_test "python print(details is None or isinstance(details, str))" "True" \ + "check that the details has an acceptable type" + gdb_test "python print ('result = %s' % t0.is_stopped ())" " = True" "test InferiorThread.is_stopped" gdb_test "python print ('result = %s' % t0.is_running ())" " = False" "test InferiorThread.is_running" gdb_test "python print ('result = %s' % t0.is_exited ())" " = False" "test InferiorThread.is_exited" -- 2.25.4