From patchwork Thu Apr 4 16:58:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Buettner X-Patchwork-Id: 32167 Received: (qmail 106649 invoked by alias); 4 Apr 2019 17:00: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 106546 invoked by uid 89); 4 Apr 2019 17:00:03 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-16.4 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= 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 17:00:01 +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 249478763B for ; Thu, 4 Apr 2019 17:00:00 +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 EA8C960BF7; Thu, 4 Apr 2019 16:59:59 +0000 (UTC) From: Kevin Buettner To: gdb-patches@sourceware.org Cc: Kevin Buettner Subject: [PATCH v4 6/6] Rename python function thread_from_thread_handle to thread_from_handle Date: Thu, 4 Apr 2019 09:58:54 -0700 Message-Id: <20190404165854.17343-7-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 This renaming was done to stay consistent with the naming of the new gdb.InferiorThread.handle method. I had initially named it "thread_handle" but Tom Tromey suggested just "handle". The old name (thread_from_thread_handle) still works, but is marked as deprecated in comments in the code as well as in the documentation. I have some code which uses these functions. I very much like the brevity of the new names. gdb/doc/ChangeLog: * python.texi (Inferiors In Python): Rename Inferior.thread_from_thread_handle to Inferior.thread_from_handle. Add note about the former being deprecated. gdb/ChangeLog: * python/py-inferior.c (infpy_thread_from_thread_handle): Adjust comments to reflect renaming of thread_from_thread_handle to thread_from_handle. Adjust keywords. Fix type error message. (inferior_object_methods): Add thread_from_handle. Retain thread_from_thread_handle, but mark it as deprecated. testsuite/ChangeLog: * gdb.python/py-thrhandle.exp: Adjust tests to call thread_from_handle instead of thread_from_thread_handle. --- gdb/doc/python.texi | 9 +++++-- gdb/python/py-inferior.c | 12 ++++++--- gdb/testsuite/gdb.python/py-thrhandle.exp | 30 +++++++++++------------ 3 files changed, 31 insertions(+), 20 deletions(-) diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi index 6a967ec26c..36947de30b 100644 --- a/gdb/doc/python.texi +++ b/gdb/doc/python.texi @@ -3000,11 +3000,16 @@ containing the address where the pattern was found, or @code{None} if the pattern could not be found. @end defun +@findex Inferior.thread_from_handle @findex Inferior.thread_from_thread_handle -@defun Inferior.thread_from_thread_handle (thread_handle) -Return the thread object corresponding to @var{thread_handle}, a thread +@defun Inferior.thread_from_handle (handle) +Return the thread object corresponding to @var{handle}, a thread library specific data structure such as @code{pthread_t} for pthreads library implementations. + +The function @code{Inferior.thread_from_thread_handle} provides +the same functionality, but use of @code{Inferior.thread_from_thread_handle} +is deprecated. @end defun @node Events In Python diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c index 7129815b21..36c9a65049 100644 --- a/gdb/python/py-inferior.c +++ b/gdb/python/py-inferior.c @@ -759,7 +759,7 @@ infpy_is_valid (PyObject *self, PyObject *args) Py_RETURN_TRUE; } -/* Implementation of gdb.Inferior.thread_from_thread_handle (self, handle) +/* Implementation of gdb.Inferior.thread_from_handle (self, handle) -> gdb.InferiorThread. */ static PyObject * @@ -767,7 +767,7 @@ infpy_thread_from_thread_handle (PyObject *self, PyObject *args, PyObject *kw) { PyObject *handle_obj; inferior_object *inf_obj = (inferior_object *) self; - static const char *keywords[] = { "thread_handle", NULL }; + static const char *keywords[] = { "handle", NULL }; INFPY_REQUIRE_VALID (inf_obj); @@ -795,7 +795,7 @@ infpy_thread_from_thread_handle (PyObject *self, PyObject *args, PyObject *kw) else { PyErr_SetString (PyExc_TypeError, - _("Argument 'handle_obj' must be a thread handle object.")); + _("Argument 'handle' must be a thread handle object.")); return NULL; } @@ -961,9 +961,15 @@ 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 is deprecated. */ { "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.\n\ +This method is deprecated - use thread_from_handle instead." }, + { "thread_from_handle", (PyCFunction) infpy_thread_from_thread_handle, + METH_VARARGS | METH_KEYWORDS, + "thread_from_handle (handle) -> gdb.InferiorThread.\n\ Return thread object corresponding to thread handle." }, { "architecture", (PyCFunction) infpy_architecture, METH_NOARGS, "architecture () -> gdb.Architecture\n\ diff --git a/gdb/testsuite/gdb.python/py-thrhandle.exp b/gdb/testsuite/gdb.python/py-thrhandle.exp index 57b97faa18..19c690be14 100644 --- a/gdb/testsuite/gdb.python/py-thrhandle.exp +++ b/gdb/testsuite/gdb.python/py-thrhandle.exp @@ -16,7 +16,7 @@ # Please email any bugs, comments, and/or additions to this file to: # bug-gdb@gnu.org -# This file verifies that methods Inferior.thread_from_thread_handle +# This file verifies that methods Inferior.thread_from_handle # and InferiorThread.handle work as expected. load_lib gdb-python.exp @@ -67,44 +67,44 @@ gdb_test "info threads" \ {.*[\r\n]+\* +([0-9]+) +Thread[^\r\n]* do_something \(n=\1\) at.*} # Check for expected results when passing a valid thread handle to -# thread_from_thread_handle(). +# thread_from_handle(). -gdb_test "python print(gdb.selected_inferior().thread_from_thread_handle(gdb.parse_and_eval('thrs\[0\]')).num)" \ +gdb_test "python print(gdb.selected_inferior().thread_from_handle(gdb.parse_and_eval('thrs\[0\]')).num)" \ "1" "print thread id for thrs\[0\]" -gdb_test "python print(gdb.selected_inferior().thread_from_thread_handle(gdb.parse_and_eval('thrs\[1\]')).num)" \ +gdb_test "python print(gdb.selected_inferior().thread_from_handle(gdb.parse_and_eval('thrs\[1\]')).num)" \ "2" "print thread id for thrs\[1\]" -gdb_test "python print(gdb.selected_inferior().thread_from_thread_handle(gdb.parse_and_eval('thrs\[2\]')).num)" \ +gdb_test "python print(gdb.selected_inferior().thread_from_handle(gdb.parse_and_eval('thrs\[2\]')).num)" \ "3" "print thread id for thrs\[2\]" # Objects which are of the correct size, but which are bogus thread # handles should return None. For the first test (using thrs[3]), we # use 0. For the second (thrs[4]), we use an unlikely bit pattern. -gdb_test "python print(gdb.selected_inferior().thread_from_thread_handle(gdb.parse_and_eval('thrs\[3\]')))" \ +gdb_test "python print(gdb.selected_inferior().thread_from_handle(gdb.parse_and_eval('thrs\[3\]')))" \ "None" "print thread for bogus handle thrs\[3\]" -gdb_test "python print(gdb.selected_inferior().thread_from_thread_handle(gdb.parse_and_eval('thrs\[4\]')))" \ +gdb_test "python print(gdb.selected_inferior().thread_from_handle(gdb.parse_and_eval('thrs\[4\]')))" \ "None" "print thread for bogus handle thrs\[4\]" # We should see an exception when passing an object of the wrong type. -gdb_test "python print(gdb.selected_inferior().thread_from_thread_handle(gdb.lookup_symbol('main')))" \ - ".*TypeError: Argument 'handle_obj' must be a thread handle object.*" \ - "TypeError when passing a symbol object to thread_from_thread_handle" +gdb_test "python print(gdb.selected_inferior().thread_from_handle(gdb.lookup_symbol('main')))" \ + ".*TypeError: Argument 'handle' must be a thread handle object.*" \ + "TypeError when passing a symbol object to thread_from_handle" # We should see an exception when passing too large of an object. -gdb_test "python print(gdb.selected_inferior().thread_from_thread_handle(gdb.parse_and_eval('thrs')))" \ +gdb_test "python print(gdb.selected_inferior().thread_from_handle(gdb.parse_and_eval('thrs')))" \ ".*Thread handle size mismatch.*" \ - "Pass overly large object to thread_from_thread_handle" + "Pass overly large object to thread_from_handle" # We should see an exception when passing too small of an object. -gdb_test "python print(gdb.selected_inferior().thread_from_thread_handle(gdb.parse_and_eval('\"S\"')))" \ +gdb_test "python print(gdb.selected_inferior().thread_from_handle(gdb.parse_and_eval('\"S\"')))" \ ".*Thread handle size mismatch.*" \ - "Pass too small of an object to thread_from_thread_handle" + "Pass too small of an object to thread_from_handle" # Test the thread_handle method @@ -121,7 +121,7 @@ foreach thrN {0 1 2} { 1 gdb_py_test_silent_cmd \ - "python hand_bytes = inf.thread_from_thread_handle(hand).handle()" \ + "python hand_bytes = inf.thread_from_handle(hand).handle()" \ "fetch thread handle from thread" \ 1