From patchwork Sun Sep 16 05:16:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Buettner X-Patchwork-Id: 29403 Received: (qmail 96914 invoked by alias); 16 Sep 2018 05:17:04 -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 96548 invoked by uid 89); 16 Sep 2018 05:16:44 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=representing, Hx-languages-length:1602 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; Sun, 16 Sep 2018 05:16:43 +0000 Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C9C325F724 for ; Sun, 16 Sep 2018 05:16:21 +0000 (UTC) Received: from pinnacle.lan (ovpn-117-176.phx2.redhat.com [10.3.117.176]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AA67B30912F4 for ; Sun, 16 Sep 2018 05:16:21 +0000 (UTC) Date: Sat, 15 Sep 2018 22:16:20 -0700 From: Kevin Buettner To: gdb-patches@sourceware.org Subject: [PATCH 2/4] Add python method gdb.InferiorThread.thread_handle Message-ID: <20180915221620.7e44a7bc@pinnacle.lan> In-Reply-To: <20180915220836.7dda4a63@pinnacle.lan> References: <20180915220836.7dda4a63@pinnacle.lan> MIME-Version: 1.0 X-IsSubscribed: yes gdb/ChangeLog: * py-infthread.c (thpy_thread_handle): New function. (thread_object_methods): Add thpy_thread_handle. --- gdb/python/py-infthread.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/gdb/python/py-infthread.c b/gdb/python/py-infthread.c index 36ae71b..9073231 100644 --- a/gdb/python/py-infthread.c +++ b/gdb/python/py-infthread.c @@ -253,6 +253,32 @@ thpy_is_valid (PyObject *self, PyObject *args) Py_RETURN_TRUE; } +/* Implementation of gdb.InferiorThread.thread_handle (self, gdbtype) -> handle. */ + +static PyObject * +thpy_thread_handle (PyObject *self, PyObject *args) +{ + PyObject *type_obj; + struct type *type; + thread_object *thread_obj = (thread_object *) self; + + THPY_REQUIRE_VALID (thread_obj); + + if (! PyArg_ParseTuple (args, "O", &type_obj)) + return NULL; + + type = type_object_to_type (type_obj); + if (type == nullptr) + { + PyErr_SetString (PyExc_RuntimeError, + _("Argument must be a type.")); + return NULL; + } + + return value_to_value_object + (thread_to_thread_handle (thread_obj->thread, type)); +} + /* Return a reference to a new Python object representing a ptid_t. The object is a tuple containing (pid, lwp, tid). */ PyObject * @@ -340,6 +366,9 @@ Return whether the thread is running." }, { "is_exited", thpy_is_exited, METH_NOARGS, "is_exited () -> Boolean\n\ Return whether the thread is exited." }, + { "thread_handle", thpy_thread_handle, METH_VARARGS, + "thread_handle (gdbtype) -> handle\n\ +Return thread handle for thread." }, { NULL } };