mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-05-30 15:56:36 +08:00
Support buffer objects as handles in Inferior.thread_from_thread_handle()
InferiorThread.handle() returns a python bytes object. We'd like to be able to pass the output of this function, a thread handle, to Inferior.thread_from_thread_handle(). Up to now, thread_from_thread_handle() expects to receive a gdb.Value input. This commit adds support to also allow a python buffer object to be passed as the handle. infpy_thread_from_thread_handle() calls find_thread_by_handle() which has the obvious functionality. It used to pass the thread handle via a struct value pointer. I've revised this interface to instead pass a gdb::array_view<const gdb_byte> object. (Thanks to Tom Tromey for suggesting this data structure over an earlier version which passed a gdb_byte pointer and length.) gdb/ChangeLog: * gdbthread.h (find_thread_by_handle): Revise declaration. * thread.c (find_thread_by_handle): Likewise. Adjust implementation too. * python/py-inferior.c (infpy_thread_from_thread_handle): Add support for buffer objects as handles.
This commit is contained in:
@ -1,3 +1,11 @@
|
|||||||
|
2019-04-08 Kevin Buettner <kevinb@redhat.com>
|
||||||
|
|
||||||
|
* gdbthread.h (find_thread_by_handle): Revise declaration.
|
||||||
|
* thread.c (find_thread_by_handle): Likewise. Adjust
|
||||||
|
implementation too.
|
||||||
|
* python/py-inferior.c (infpy_thread_from_thread_handle): Add
|
||||||
|
support for buffer objects as handles.
|
||||||
|
|
||||||
2019-04-08 Kevin Buettner <kevinb@redhat.com>
|
2019-04-08 Kevin Buettner <kevinb@redhat.com>
|
||||||
|
|
||||||
* python/py-infthread.c (thpy_thread_handle): New function.
|
* python/py-infthread.c (thpy_thread_handle): New function.
|
||||||
|
@ -486,8 +486,8 @@ extern struct thread_info *find_thread_ptid (inferior *inf, ptid_t ptid);
|
|||||||
struct thread_info *find_thread_global_id (int global_id);
|
struct thread_info *find_thread_global_id (int global_id);
|
||||||
|
|
||||||
/* Find thread by thread library specific handle in inferior INF. */
|
/* Find thread by thread library specific handle in inferior INF. */
|
||||||
struct thread_info *find_thread_by_handle (struct value *thread_handle,
|
struct thread_info *find_thread_by_handle
|
||||||
struct inferior *inf);
|
(gdb::array_view<const gdb_byte> handle, struct inferior *inf);
|
||||||
|
|
||||||
/* Finds the first thread of the specified inferior. */
|
/* Finds the first thread of the specified inferior. */
|
||||||
extern struct thread_info *first_thread_of_inferior (inferior *inf);
|
extern struct thread_info *first_thread_of_inferior (inferior *inf);
|
||||||
|
@ -770,7 +770,25 @@ infpy_thread_from_thread_handle (PyObject *self, PyObject *args, PyObject *kw)
|
|||||||
if (! gdb_PyArg_ParseTupleAndKeywords (args, kw, "O", keywords, &handle_obj))
|
if (! gdb_PyArg_ParseTupleAndKeywords (args, kw, "O", keywords, &handle_obj))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (!gdbpy_is_value_object (handle_obj))
|
const gdb_byte *bytes;
|
||||||
|
size_t bytes_len;
|
||||||
|
Py_buffer_up buffer_up;
|
||||||
|
Py_buffer py_buf;
|
||||||
|
|
||||||
|
if (PyObject_CheckBuffer (handle_obj)
|
||||||
|
&& PyObject_GetBuffer (handle_obj, &py_buf, PyBUF_SIMPLE) == 0)
|
||||||
|
{
|
||||||
|
buffer_up.reset (&py_buf);
|
||||||
|
bytes = (const gdb_byte *) py_buf.buf;
|
||||||
|
bytes_len = py_buf.len;
|
||||||
|
}
|
||||||
|
else if (gdbpy_is_value_object (handle_obj))
|
||||||
|
{
|
||||||
|
struct value *val = value_object_to_value (handle_obj);
|
||||||
|
bytes = value_contents_all (val);
|
||||||
|
bytes_len = TYPE_LENGTH (value_type (val));
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
PyErr_SetString (PyExc_TypeError,
|
PyErr_SetString (PyExc_TypeError,
|
||||||
_("Argument 'handle_obj' must be a thread handle object."));
|
_("Argument 'handle_obj' must be a thread handle object."));
|
||||||
@ -781,9 +799,10 @@ infpy_thread_from_thread_handle (PyObject *self, PyObject *args, PyObject *kw)
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
struct thread_info *thread_info;
|
struct thread_info *thread_info;
|
||||||
struct value *val = value_object_to_value (handle_obj);
|
|
||||||
|
|
||||||
thread_info = find_thread_by_handle (val, inf_obj->inferior);
|
thread_info = find_thread_by_handle
|
||||||
|
(gdb::array_view<const gdb_byte> (bytes, bytes_len),
|
||||||
|
inf_obj->inferior);
|
||||||
if (thread_info != NULL)
|
if (thread_info != NULL)
|
||||||
return thread_to_thread_object (thread_info).release ();
|
return thread_to_thread_object (thread_info).release ();
|
||||||
}
|
}
|
||||||
|
@ -540,11 +540,11 @@ find_thread_ptid (inferior *inf, ptid_t ptid)
|
|||||||
/* See gdbthread.h. */
|
/* See gdbthread.h. */
|
||||||
|
|
||||||
struct thread_info *
|
struct thread_info *
|
||||||
find_thread_by_handle (struct value *thread_handle, struct inferior *inf)
|
find_thread_by_handle (gdb::array_view<const gdb_byte> handle,
|
||||||
|
struct inferior *inf)
|
||||||
{
|
{
|
||||||
return target_thread_handle_to_thread_info
|
return target_thread_handle_to_thread_info (handle.data (),
|
||||||
(value_contents_all (thread_handle),
|
handle.size (),
|
||||||
TYPE_LENGTH (value_type (thread_handle)),
|
|
||||||
inf);
|
inf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user