summaryrefslogtreecommitdiff
path: root/plugins/pyoida/debug/debugger.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/pyoida/debug/debugger.c')
-rw-r--r--plugins/pyoida/debug/debugger.c87
1 files changed, 79 insertions, 8 deletions
diff --git a/plugins/pyoida/debug/debugger.c b/plugins/pyoida/debug/debugger.c
index 380f579..75de6d8 100644
--- a/plugins/pyoida/debug/debugger.c
+++ b/plugins/pyoida/debug/debugger.c
@@ -28,9 +28,12 @@
#include <pygobject.h>
+#include "../quirks.h"
+/* Fournit les identifiants de tous les threads actifs. */
+static PyObject *py_binary_debugger_list_all_threads(PyObject *, PyObject *);
/* Fournit la pile d'exécution courante via un débogueur. */
static PyObject *py_binary_debugger_get_current_stack(PyObject *, PyObject *);
@@ -38,9 +41,6 @@ static PyObject *py_binary_debugger_get_current_stack(PyObject *, PyObject *);
-
-
-
/******************************************************************************
* *
* Paramètres : type = type de l'objet à instancier. *
@@ -89,6 +89,15 @@ static PyObject *py_binary_debugger_new(PyTypeObject *type, PyObject *args, PyOb
PyObject *py_binary_debugger_from_c(GBinaryDebugger *debugger)
{
+ PyObject *module; /* Module d'appartenance */
+ PyTypeObject *type; /* Type Python correspondant */
+
+ module = PyImport_ImportModule("pyoida.debug");
+ type = (PyTypeObject*)PyObject_GetAttrString(module, "BinaryDebugger");
+ Py_DECREF(module);
+
+ pychrysalide_set_instance_data(G_OBJECT(debugger), type);
+
return pygobject_new(G_OBJECT(debugger));
}
@@ -96,25 +105,75 @@ PyObject *py_binary_debugger_from_c(GBinaryDebugger *debugger)
+
/******************************************************************************
* *
* Paramètres : self = classe représentant un débogueur. *
* args = arguments fournis à l'appel. *
* *
-* Description : Fournit la pile d'exécution courante via un débogueur. *
+* Description : Fournit les identifiants de tous les threads actifs. *
* *
-* Retour : Valeur booléenne indiquant le statut d'une option. *
+* Retour : Object Python représentant le résultat de l'opération. *
* *
* Remarques : - *
* *
******************************************************************************/
-static PyObject *py_binary_debugger_get_current_stack(PyObject *self, PyObject *args)
+static PyObject *py_binary_debugger_list_all_threads(PyObject *self, PyObject *args)
{
+ PyObject *result; /* Trouvailles à retourner */
+ GBinaryDebugger *debugger; /* Version native */
+ char **names; /* Noms associés aux threads */
+ size_t count; /* Taille de cette liste */
+ pid_t *threads; /* Liste des threads actifs */
+ size_t i; /* Boucle de parcours */
+ PyObject *thread; /* Détails sur un thread donné */
+
+ debugger = G_BINARY_DEBUGGER(pygobject_get(self));
+
+ threads = g_binary_debugger_list_all_threads(debugger, &names, &count);
+
+ result = PyTuple_New(count);
+
+ for (i = 0; i < count; i++)
+ {
+ thread = PyTuple_New(2);
+ PyTuple_SetItem(result, i, thread);
+
+ PyTuple_SetItem(thread, 0, PyLong_FromLong(threads[i]));
+ PyTuple_SetItem(thread, 1, PyString_FromString(names[i]));
+
+ free(names[i]);
+
+ }
+
+ if (names != NULL)
+ free(names);
+
+ if (threads != NULL)
+ free(threads);
+
+ return result;
+
+}
+
- printf(" -->> get stack\n");
+/******************************************************************************
+* *
+* Paramètres : self = classe représentant un débogueur. *
+* args = arguments fournis à l'appel. *
+* *
+* Description : Fournit la pile d'exécution courante via un débogueur. *
+* *
+* Retour : Object Python représentant le résultat de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
- return Py_BuildValue("i", true);
+static PyObject *py_binary_debugger_get_current_stack(PyObject *self, PyObject *args)
+{
+ return PyLong_FromLong(23);
}
@@ -136,10 +195,16 @@ static PyObject *py_binary_debugger_get_current_stack(PyObject *self, PyObject *
bool register_python_binary_debugger(PyObject *module)
{
+ PyObject *pygobj_mod; /* Module Python-GObject */
int ret; /* Bilan d'un appel */
static PyMethodDef py_binary_debugger_methods[] = {
{
+ "list_all_threads", (PyCFunction)py_binary_debugger_list_all_threads,
+ METH_NOARGS,
+ "List all current active threads."
+ },
+ {
"get_current_stack", (PyCFunction)py_binary_debugger_get_current_stack,
METH_NOARGS,
"Provide the current callstack using a debugger."
@@ -163,6 +228,12 @@ bool register_python_binary_debugger(PyObject *module)
};
+ pygobj_mod = PyImport_ImportModule("gobject");
+ if (pygobj_mod == NULL) return false;
+
+ py_binary_debugger_type.tp_base = (PyTypeObject *)PyObject_GetAttrString(pygobj_mod, "GObject");
+ Py_DECREF(pygobj_mod);
+
if (PyType_Ready(&py_binary_debugger_type) < 0)
return false;