/* Python interface to inferior threads.
- Copyright (C) 2009-2018 Free Software Foundation, Inc.
+ Copyright (C) 2009-2019 Free Software Foundation, Inc.
This file is part of GDB.
} \
} while (0)
-thread_object *
+gdbpy_ref<thread_object>
create_thread_object (struct thread_info *tp)
{
- thread_object *thread_obj;
+ gdbpy_ref<thread_object> thread_obj;
- thread_obj = PyObject_New (thread_object, &thread_object_type);
- if (!thread_obj)
+ gdbpy_ref<inferior_object> inf_obj = inferior_to_inferior_object (tp->inf);
+ if (inf_obj == NULL)
+ return NULL;
+
+ thread_obj.reset (PyObject_New (thread_object, &thread_object_type));
+ if (thread_obj == NULL)
return NULL;
thread_obj->thread = tp;
- thread_obj->inf_obj = (PyObject *) inferior_to_inferior_object (tp->inf);
+ thread_obj->inf_obj = (PyObject *) inf_obj.release ();
return thread_obj;
}
THPY_REQUIRE_VALID (thread_obj);
- TRY
+ try
{
switch_to_thread (thread_obj->thread);
}
- CATCH (except, RETURN_MASK_ALL)
+ catch (const gdb_exception &except)
{
GDB_PY_HANDLE_EXCEPTION (except);
}
- END_CATCH
Py_RETURN_NONE;
}
Py_RETURN_TRUE;
}
+/* Implementation of gdb.InferiorThread.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;
+
+ try
+ {
+ hv = target_thread_info_to_thread_handle (thread_obj->thread);
+ }
+ catch (const gdb_exception &except)
+ {
+ GDB_PY_HANDLE_EXCEPTION (except);
+ }
+
+ if (hv.size () == 0)
+ {
+ PyErr_SetString (PyExc_RuntimeError, _("Thread handle not found."));
+ 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 *
if (!ret)
return NULL;
- pid = ptid_get_pid (ptid);
- lwp = ptid_get_lwp (ptid);
- tid = ptid_get_tid (ptid);
+ pid = ptid.pid ();
+ lwp = ptid.lwp ();
+ tid = ptid.tid ();
PyTuple_SET_ITEM (ret, 0, PyInt_FromLong (pid));
PyTuple_SET_ITEM (ret, 1, PyInt_FromLong (lwp));
gdbpy_selected_thread (PyObject *self, PyObject *args)
{
if (inferior_ptid != null_ptid)
- {
- PyObject *thread_obj
- = (PyObject *) thread_to_thread_object (inferior_thread ());
- if (thread_obj != NULL)
- {
- Py_INCREF (thread_obj);
- return thread_obj;
- }
- }
+ return thread_to_thread_object (inferior_thread ()).release ();
Py_RETURN_NONE;
}
{ "is_exited", thpy_is_exited, METH_NOARGS,
"is_exited () -> Boolean\n\
Return whether the thread is exited." },
+ { "handle", thpy_thread_handle, METH_NOARGS,
+ "handle () -> handle\n\
+Return thread library specific handle for thread." },
{ NULL }
};