From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 74D353858001 for ; Mon, 28 Feb 2022 11:30:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 74D353858001 Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-568-A4YPDFG5OayBtKFbS0sZuw-1; Mon, 28 Feb 2022 06:30:32 -0500 X-MC-Unique: A4YPDFG5OayBtKFbS0sZuw-1 Received: by mail-wr1-f71.google.com with SMTP id j27-20020adfb31b000000b001ea8356972bso1979536wrd.1 for ; Mon, 28 Feb 2022 03:30:32 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=5UFqfghVEfIa8nSsxQPsQQALLWe6NY7SmHcOIo9EN2E=; b=g0CS3Jxu3dqKtT75En2QgQR6TDsXuwsu9e5ytptrt2F+mkkaLFv4DDxWb0+MEVV31H ira4vUOcwCH/ZtVqHtlQKWSrC0SAZ9iQMM/sGuuGW2Zj1/ExQTbusYfVNuM8GK9HIc3b XLQTUNjH4XHhau/Xe4VhX2Oev7wXe+0sHiY/VDL79jExPNQnhi4bHzPlMbXWOqScF4rA OeWaa0QFYkfz+jymDWzzDkKsK569Ni7OE/C2yL66tc+MHAk+FB+hEGgwIA3gpjoX0Cor kegBUlPEGQfnHrJ4BX8DBcANl6rY+einrmSNd7d2bfjnOKiLiVltn5SGS7npzs2O8ehQ Krsw== X-Gm-Message-State: AOAM533Rbi2lXO5yq6TSif6krT2JsvrLGfUQA9swZACDUuH2ojW2Iyec Jov3aAdy8dkdjDsJSLa1ZknO1V+/wKtHVNzkZkuW8vfX1vu0UpeYxfVr/SVtT8PKAzwLQollDtB JWVQXhNTzEkI4I4U4ScZ33w== X-Received: by 2002:a5d:6d44:0:b0:1e4:9a6d:c171 with SMTP id k4-20020a5d6d44000000b001e49a6dc171mr16189297wri.468.1646047831462; Mon, 28 Feb 2022 03:30:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJxsQLRQWuuTBzwFby4h3zjCa5GJ2U+M0ZVXqM4PzE3p9KhExOYu1Ng4/YmzjugZpwPMZEF2Ww== X-Received: by 2002:a5d:6d44:0:b0:1e4:9a6d:c171 with SMTP id k4-20020a5d6d44000000b001e49a6dc171mr16189279wri.468.1646047831166; Mon, 28 Feb 2022 03:30:31 -0800 (PST) Received: from localhost (host86-169-131-29.range86-169.btcentralplus.com. [86.169.131.29]) by smtp.gmail.com with ESMTPSA id e18-20020adfdbd2000000b001e4bbbe5b92sm10746502wrj.76.2022.02.28.03.30.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Feb 2022 03:30:30 -0800 (PST) Date: Mon, 28 Feb 2022 11:30:29 +0000 From: Andrew Burgess To: Tom Tromey Cc: gdb-patches@sourceware.org Subject: [PATCHv2] gdb/python: Add gdb.InferiorThread.details attribute Message-ID: <20220228113029.GA1212730@redhat.com> References: <20220215115233.56924-1-aburgess@redhat.com> <87fso6n3l5.fsf@tromey.com> MIME-Version: 1.0 In-Reply-To: <87fso6n3l5.fsf@tromey.com> X-Operating-System: Linux/5.8.18-100.fc31.x86_64 (x86_64) X-Uptime: 11:27:57 up 1 day, 1:05, X-Editor: GNU Emacs [ http://www.gnu.org/software/emacs ] X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org 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: , X-List-Received-Date: Mon, 28 Feb 2022 11:30:36 -0000 * Tom Tromey [2022-02-25 12:33:42 -0700]: > >>>>> "Andrew" == Andrew Burgess via Gdb-patches writes: > > Andrew> As the string returned by target_extra_thread_info is unstructured, > Andrew> this attribute is only really useful for echoing straight through to > Andrew> the user, but, if a user wants to write a command that displays the > Andrew> same, or a similar 'Thread Id' to the one seen in 'info threads', then > Andrew> they need access to this string. > > It may be good to give a bit more information about this in the > documentation. Like, describing what this is used for and maybe how it > would appear on a Linux system. > > Andrew> + const char *extra_info = target_extra_thread_info (thread_obj->thread); > > If this can ever throw, it will break things here. Thanks for the feedback. In v2: - Improved the docs to given an example of what the string might contain, and where GDB currently displays the string, and - Use try/catch and GDB_PY_HANDLE_EXCEPTION in py-infthread.c in to handle any exceptions thrown from GDB core. Thanks, Andrew --- gdb/python: Add gdb.InferiorThread.details attribute 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/gdb.texinfo | 2 ++ gdb/doc/python.texi | 17 +++++++++++++ gdb/python/py-infthread.c | 29 +++++++++++++++++++++++ gdb/testsuite/gdb.python/py-infthread.exp | 5 ++++ 5 files changed, 58 insertions(+) diff --git a/gdb/NEWS b/gdb/NEWS index 41ea84e6063..dc2cac1871b 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -201,6 +201,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/gdb.texinfo b/gdb/doc/gdb.texinfo index 504eb663c14..f7f5f7a6158 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -3629,6 +3629,7 @@ @end smallexample @table @code +@anchor{info_threads} @kindex info threads @item info threads @r{[}@var{thread-id-list}@r{]} @@ -42719,6 +42720,7 @@ @xref{Tracepoint Packets}. +@anchor{qThreadExtraInfo} @item qThreadExtraInfo,@var{thread-id} @cindex thread attributes info, remote request @cindex @samp{qThreadExtraInfo} packet diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi index c1a3f5f2a7e..e59897dc3f7 100644 --- a/gdb/doc/python.texi +++ b/gdb/doc/python.texi @@ -3574,6 +3574,23 @@ 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}. + +For example, on a @sc{gnu}/Linux system, a thread that is in the +process of exiting will return the string @samp{Exiting}. For remote +targets the @code{details} string will be obtained with the +@samp{qThreadExtraInfo} remote packet, if the target supports it +(@pxref{qThreadExtraInfo,,@samp{qThreadExtraInfo}}). + +@value{GDBN} displays the @code{details} string as part of the +@samp{Target Id} column, in the @code{info threads} output +(@pxref{info_threads,,@samp{info threads}}). +@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..66c3efdf6cc 100644 --- a/gdb/python/py-infthread.c +++ b/gdb/python/py-infthread.c @@ -76,6 +76,32 @@ 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; + try + { + extra_info = target_extra_thread_info (thread_obj->thread); + } + catch (const gdb_exception &except) + { + GDB_PY_HANDLE_EXCEPTION (except); + } + 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 +373,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