From patchwork Thu Apr 4 16:58:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Buettner X-Patchwork-Id: 32163 Received: (qmail 105532 invoked by alias); 4 Apr 2019 16:59:57 -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 105483 invoked by uid 89); 4 Apr 2019 16:59:57 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-16.2 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy=HContent-Transfer-Encoding:8bit 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; Thu, 04 Apr 2019 16:59:55 +0000 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 999E0C049E23 for ; Thu, 4 Apr 2019 16:59:54 +0000 (UTC) Received: from f29-efi-1.lan (ovpn-116-219.phx2.redhat.com [10.3.116.219]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6A67B60BF7; Thu, 4 Apr 2019 16:59:54 +0000 (UTC) From: Kevin Buettner To: gdb-patches@sourceware.org Cc: Kevin Buettner Subject: [PATCH v4 2/6] Add python method InferiorThread.handle Date: Thu, 4 Apr 2019 09:58:50 -0700 Message-Id: <20190404165854.17343-3-kevinb@redhat.com> In-Reply-To: <20190404165854.17343-1-kevinb@redhat.com> References: <20190404165854.17343-1-kevinb@redhat.com> MIME-Version: 1.0 X-IsSubscribed: yes gdb/ChangeLog: * python/py-infthread.c (thpy_thread_handle): New function. (thread_object_methods): Register thpy_thread_handle. --- gdb/python/py-infthread.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/gdb/python/py-infthread.c b/gdb/python/py-infthread.c index bf90d08ae6..1d201b9b35 100644 --- a/gdb/python/py-infthread.c +++ b/gdb/python/py-infthread.c @@ -257,6 +257,37 @@ thpy_is_valid (PyObject *self, PyObject *args) Py_RETURN_TRUE; } +/* Implementation of gdb.InferiorThread.handle (self) -> handle. */ + +static PyObject * +thpy_thread_handle (PyObject *self, PyObject *args) +{ + thread_object *thread_obj = (thread_object *) self; + THPY_REQUIRE_VALID (thread_obj); + + gdb::byte_vector hv; + + TRY + { + hv = target_thread_info_to_thread_handle (thread_obj->thread); + } + CATCH (ex, RETURN_MASK_ALL) + { + GDB_PY_HANDLE_EXCEPTION (ex); + } + END_CATCH + + if (hv.size () == 0) + { + PyErr_SetString (PyExc_RuntimeError, _("Thread handle not found.")); + return NULL; + } + + PyObject *object = PyBytes_FromStringAndSize ((const char *) hv.data (), + hv.size()); + return object; +} + /* Return a reference to a new Python object representing a ptid_t. The object is a tuple containing (pid, lwp, tid). */ PyObject * @@ -336,6 +367,9 @@ Return whether the thread is running." }, { "is_exited", thpy_is_exited, METH_NOARGS, "is_exited () -> Boolean\n\ Return whether the thread is exited." }, + { "handle", thpy_thread_handle, METH_NOARGS, + "handle () -> handle\n\ +Return thread library specific handle for thread." }, { NULL } };