From patchwork Wed Aug 16 17:36:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Buettner X-Patchwork-Id: 22158 Received: (qmail 38814 invoked by alias); 16 Aug 2017 17:37:09 -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 38700 invoked by uid 89); 16 Aug 2017 17:37:05 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= 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; Wed, 16 Aug 2017 17:37:04 +0000 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 91D07C01DDAD for ; Wed, 16 Aug 2017 17:37:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 91D07C01DDAD Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=kevinb@redhat.com Received: from pinnacle.lan (ovpn-117-126.phx2.redhat.com [10.3.117.126]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 727BF6F96C for ; Wed, 16 Aug 2017 17:37:03 +0000 (UTC) Date: Wed, 16 Aug 2017 10:36:57 -0700 From: Kevin Buettner To: gdb-patches@sourceware.org Subject: Re: [PATCH v4 2/7] Add `thread_from_thread_handle' method to (Python) gdb.Inferior Message-ID: <20170816103657.283cd869@pinnacle.lan> In-Reply-To: <20170816092542.6d2deb00@pinnacle.lan> References: <20170816092542.6d2deb00@pinnacle.lan> MIME-Version: 1.0 X-IsSubscribed: yes gdb/ChangeLog: * python/py-inferior.c (gdbpy_thread_from_thread_handle): New function. (inferior_object_methods): Add gdbpy_thread_from_thread_handle. * python/python-internal.h (thread_object_type): Declare. --- gdb/python/py-inferior.c | 54 ++++++++++++++++++++++++++++++++++++++++++++ gdb/python/python-internal.h | 2 ++ 2 files changed, 56 insertions(+) diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c index f6a24a0..67a7e6e 100644 --- a/gdb/python/py-inferior.c +++ b/gdb/python/py-inferior.c @@ -751,6 +751,56 @@ infpy_is_valid (PyObject *self, PyObject *args) Py_RETURN_TRUE; } +/* Implementation of gdb.Inferior.thread_from_thread_handle (self, handle) + -> gdb.InferiorThread. */ + +PyObject * +infpy_thread_from_thread_handle (PyObject *self, PyObject *args, PyObject *kw) +{ + PyObject *handle_obj, *result; + inferior_object *inf_obj = (inferior_object *) self; + static const char *keywords[] = { "thread_handle", NULL }; + + INFPY_REQUIRE_VALID (inf_obj); + + if (! gdb_PyArg_ParseTupleAndKeywords (args, kw, "O", keywords, &handle_obj)) + return NULL; + + result = Py_None; + + if (!gdbpy_is_value_object (handle_obj)) + { + PyErr_SetString (PyExc_TypeError, + _("Argument 'handle_obj' must be a thread handle object.")); + + return NULL; + } + else + { + TRY + { + struct thread_info *thread_info; + struct value *val = value_object_to_value (handle_obj); + + thread_info = find_thread_by_handle (val, inf_obj->inferior); + if (thread_info != NULL) + { + result = (PyObject *) find_thread_object (thread_info->ptid); + if (result != NULL) + Py_INCREF (result); + } + } + CATCH (except, RETURN_MASK_ALL) + { + GDB_PY_HANDLE_EXCEPTION (except); + } + END_CATCH + } + + return result; +} + + static void infpy_dealloc (PyObject *obj) { @@ -861,6 +911,10 @@ Write the given buffer object to the inferior's memory." }, METH_VARARGS | METH_KEYWORDS, "search_memory (address, length, pattern) -> long\n\ Return a long with the address of a match, or None." }, + { "thread_from_thread_handle", (PyCFunction) infpy_thread_from_thread_handle, + METH_VARARGS | METH_KEYWORDS, + "thread_from_thread_handle (handle) -> gdb.InferiorThread.\n\ +Return thread object corresponding to thread handle." }, { NULL } }; diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h index ebb83f0..40e64f0 100644 --- a/gdb/python/python-internal.h +++ b/gdb/python/python-internal.h @@ -379,6 +379,8 @@ extern PyTypeObject breakpoint_object_type CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("breakpoint_object"); extern PyTypeObject frame_object_type CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("frame_object"); +extern PyTypeObject thread_object_type + CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("thread_object"); typedef struct gdbpy_breakpoint_object {