gdb/fortran: Don't include module symbols when searching for types
[deliverable/binutils-gdb.git] / gdb / python / py-infthread.c
index 9b90ad5524e6c91c796ee96909348acb206650b4..f1c316c1f17d8acd7da576292cbbb37572a138ea 100644 (file)
@@ -1,6 +1,6 @@
 /* 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.
 
@@ -36,17 +36,21 @@ extern PyTypeObject thread_object_type
       }                                                                \
   } 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;
 }
@@ -177,15 +181,14 @@ thpy_switch (PyObject *self, PyObject *args)
 
   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;
 }
@@ -253,6 +256,36 @@ thpy_is_valid (PyObject *self, PyObject *args)
   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 *
@@ -266,9 +299,9 @@ gdbpy_create_ptid_object (ptid_t ptid)
   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));
@@ -284,15 +317,7 @@ PyObject *
 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;
 }
@@ -340,6 +365,9 @@ Return whether the thread is running." },
   { "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 }
 };
This page took 0.073952 seconds and 4 git commands to generate.