[v2,2/5] Add python method InferiorThread.thread_handle
Commit Message
gdb/ChangeLog:
* python/py-infthread.c (thpy_thread_handle): New function.
(thread_object_methods): Register thpy_thread_handle.
---
gdb/python/py-infthread.c | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
Comments
>>>>> "Kevin" == Kevin Buettner <kevinb@redhat.com> writes:
Kevin> +/* Implementation of gdb.InferiorThread.thread_handle (self) -> handle. */
What would you think of just the name "handle"? The "thread" part
seemed redundant to me.
Kevin> + gdb::byte_vector hv = target_thread_info_to_thread_handle (thread_obj->thread);
In general, calls into gdb from Python require a try/catch.
It can be ok if you're 100% sure a throw is not only not possible but
will never be possible. (I feel like we normally ignore out-of-memory
exceptions when deciding this, but that's probably a bad idea.)
Kevin> + PyObject *object = PyBytes_FromStringAndSize ((const char *) hv.data (),
Kevin> + hv.size());
I thought this wasn't available in Python 2 but I see it is used
unconditionally in py-record-btrace.c.
Tom
On Tue, 05 Mar 2019 14:48:34 -0700
Tom Tromey <tom@tromey.com> wrote:
> >>>>> "Kevin" == Kevin Buettner <kevinb@redhat.com> writes:
>
> Kevin> +/* Implementation of gdb.InferiorThread.thread_handle (self) -> handle. */
>
> What would you think of just the name "handle"? The "thread" part
> seemed redundant to me.
I like this idea, though to maintain consistency, I think we should
also rename the existing Inferior.thread_from_thread_handle function
to Inferior.thread_from_handle. I'll add another commit which does
this to the upcoming v3 series which I'm working on.
Kevin
>>>>> "Kevin" == Kevin Buettner <kevinb@redhat.com> writes:
Kevin> I like this idea, though to maintain consistency, I think we should
Kevin> also rename the existing Inferior.thread_from_thread_handle function
Kevin> to Inferior.thread_from_handle. I'll add another commit which does
Kevin> this to the upcoming v3 series which I'm working on.
I think we should probably keep the old name as an alias, at least.
I'd rather not break existing scripts (if there are any using this)
unless we really have to.
Tom
On Wed, 20 Mar 2019 14:39:44 -0600
Tom Tromey <tom@tromey.com> wrote:
> >>>>> "Kevin" == Kevin Buettner <kevinb@redhat.com> writes:
>
> Kevin> I like this idea, though to maintain consistency, I think we should
> Kevin> also rename the existing Inferior.thread_from_thread_handle function
> Kevin> to Inferior.thread_from_handle. I'll add another commit which does
> Kevin> this to the upcoming v3 series which I'm working on.
>
> I think we should probably keep the old name as an alias, at least.
> I'd rather not break existing scripts (if there are any using this)
> unless we really have to.
Okay, I'll retain the old name as an alias.
Kevin
@@ -257,6 +257,24 @@ thpy_is_valid (PyObject *self, PyObject *args)
Py_RETURN_TRUE;
}
+/* Implementation of gdb.InferiorThread.thread_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 = target_thread_info_to_thread_handle (thread_obj->thread);
+
+ if (hv.size () == 0)
+ 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 +354,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_NOARGS,
+ "thread_handle () -> handle\n\
+Return thread handle for thread." },
{ NULL }
};