aboutsummaryrefslogtreecommitdiff
path: root/gdb/python
diff options
context:
space:
mode:
Diffstat (limited to 'gdb/python')
-rw-r--r--gdb/python/py-block.c48
-rw-r--r--gdb/python/py-inferior.c17
-rw-r--r--gdb/python/py-infthread.c16
-rw-r--r--gdb/python/py-objfile.c25
-rw-r--r--gdb/python/py-symbol.c24
-rw-r--r--gdb/python/py-symtab.c42
6 files changed, 167 insertions, 5 deletions
diff --git a/gdb/python/py-block.c b/gdb/python/py-block.c
index 9d0d6cc..08d4455 100644
--- a/gdb/python/py-block.c
+++ b/gdb/python/py-block.c
@@ -263,6 +263,36 @@ blpy_block_syms_dealloc (PyObject *obj)
Py_XDECREF (iter_obj->source);
}
+/* Implementation of gdb.Block.is_valid (self) -> Boolean.
+ Returns True if this block object still exists in GDB. */
+
+static PyObject *
+blpy_is_valid (PyObject *self, PyObject *args)
+{
+ struct block *block;
+
+ block = block_object_to_block (self);
+ if (block == NULL)
+ Py_RETURN_FALSE;
+
+ Py_RETURN_TRUE;
+}
+
+/* Implementation of gdb.BlockIterator.is_valid (self) -> Boolean.
+ Returns True if this block iterator object still exists in GDB */
+
+static PyObject *
+blpy_iter_is_valid (PyObject *self, PyObject *args)
+{
+ block_syms_iterator_object *iter_obj =
+ (block_syms_iterator_object *) self;
+
+ if (iter_obj->source->block == NULL)
+ Py_RETURN_FALSE;
+
+ Py_RETURN_TRUE;
+}
+
/* Return the innermost lexical block containing the specified pc value,
or 0 if there is none. */
PyObject *
@@ -342,6 +372,13 @@ gdbpy_initialize_blocks (void)
+static PyMethodDef block_object_methods[] = {
+ { "is_valid", blpy_is_valid, METH_NOARGS,
+ "is_valid () -> Boolean.\n\
+Return true if this block is valid, false if not." },
+ {NULL} /* Sentinel */
+};
+
static PyGetSetDef block_object_getset[] = {
{ "start", blpy_get_start, NULL, "Start address of the block.", NULL },
{ "end", blpy_get_end, NULL, "End address of the block.", NULL },
@@ -381,11 +418,18 @@ PyTypeObject block_object_type = {
0, /* tp_weaklistoffset */
blpy_iter, /* tp_iter */
0, /* tp_iternext */
- 0, /* tp_methods */
+ block_object_methods, /* tp_methods */
0, /* tp_members */
block_object_getset /* tp_getset */
};
+static PyMethodDef block_iterator_object_methods[] = {
+ { "is_valid", blpy_iter_is_valid, METH_NOARGS,
+ "is_valid () -> Boolean.\n\
+Return true if this block iterator is valid, false if not." },
+ {NULL} /* Sentinel */
+};
+
static PyTypeObject block_syms_iterator_object_type = {
PyObject_HEAD_INIT (NULL)
0, /*ob_size*/
@@ -415,5 +459,5 @@ static PyTypeObject block_syms_iterator_object_type = {
0, /*tp_weaklistoffset */
blpy_block_syms_iter, /*tp_iter */
blpy_block_syms_iternext, /*tp_iternext */
- 0 /*tp_methods */
+ block_iterator_object_methods /*tp_methods */
};
diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c
index ee41ea7..b9df394 100644
--- a/gdb/python/py-inferior.c
+++ b/gdb/python/py-inferior.c
@@ -606,6 +606,20 @@ infpy_search_memory (PyObject *self, PyObject *args, PyObject *kw)
Py_RETURN_NONE;
}
+/* Implementation of gdb.Inferior.is_valid (self) -> Boolean.
+ Returns True if this inferior object still exists in GDB. */
+
+static PyObject *
+infpy_is_valid (PyObject *self, PyObject *args)
+{
+ inferior_object *inf = (inferior_object *) self;
+
+ if (! inf->inferior)
+ Py_RETURN_FALSE;
+
+ Py_RETURN_TRUE;
+}
+
/* Clear the INFERIOR pointer in an Inferior object and clear the
thread list. */
@@ -676,6 +690,9 @@ static PyGetSetDef inferior_object_getset[] =
static PyMethodDef inferior_object_methods[] =
{
+ { "is_valid", infpy_is_valid, METH_NOARGS,
+ "is_valid () -> Boolean.\n\
+Return true if this inferior is valid, false if not." },
{ "threads", infpy_threads, METH_NOARGS,
"Return all the threads of this inferior." },
{ "read_memory", (PyCFunction) infpy_read_memory,
diff --git a/gdb/python/py-infthread.c b/gdb/python/py-infthread.c
index 059422d..b37c53c 100644
--- a/gdb/python/py-infthread.c
+++ b/gdb/python/py-infthread.c
@@ -222,7 +222,20 @@ thpy_is_exited (PyObject *self, PyObject *args)
Py_RETURN_FALSE;
}
+/* Implementation of gdb.InfThread.is_valid (self) -> Boolean.
+ Returns True if this inferior Thread object still exists
+ in GDB. */
+static PyObject *
+thpy_is_valid (PyObject *self, PyObject *args)
+{
+ thread_object *thread_obj = (thread_object *) self;
+
+ if (! thread_obj->thread)
+ Py_RETURN_FALSE;
+
+ Py_RETURN_TRUE;
+}
/* Implementation of gdb.selected_thread () -> gdb.InferiorThread.
Returns the selected thread object. */
@@ -269,6 +282,9 @@ static PyGetSetDef thread_object_getset[] =
static PyMethodDef thread_object_methods[] =
{
+ { "is_valid", thpy_is_valid, METH_NOARGS,
+ "is_valid () -> Boolean.\n\
+Return true if this inferior thread is valid, false if not." },
{ "switch", thpy_switch, METH_NOARGS,
"switch ()\n\
Makes this the GDB selected thread." },
diff --git a/gdb/python/py-objfile.c b/gdb/python/py-objfile.c
index 7f9d9ee..f9821f5 100644
--- a/gdb/python/py-objfile.c
+++ b/gdb/python/py-objfile.c
@@ -118,6 +118,20 @@ objfpy_set_printers (PyObject *o, PyObject *value, void *ignore)
return 0;
}
+/* Implementation of gdb.Objfile.is_valid (self) -> Boolean.
+ Returns True if this object file still exists in GDB. */
+
+static PyObject *
+objfpy_is_valid (PyObject *self, PyObject *args)
+{
+ objfile_object *obj = (objfile_object *) self;
+
+ if (! obj->objfile)
+ Py_RETURN_FALSE;
+
+ Py_RETURN_TRUE;
+}
+
/* Clear the OBJFILE pointer in an Objfile object and remove the
@@ -181,6 +195,15 @@ gdbpy_initialize_objfile (void)
+static PyMethodDef objfile_object_methods[] =
+{
+ { "is_valid", objfpy_is_valid, METH_NOARGS,
+ "is_valid () -> Boolean.\n\
+Return true if this object file is valid, false if not." },
+
+ { NULL }
+};
+
static PyGetSetDef objfile_getset[] =
{
{ "filename", objfpy_get_filename, NULL,
@@ -220,7 +243,7 @@ static PyTypeObject objfile_object_type =
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
- 0, /* tp_methods */
+ objfile_object_methods, /* tp_methods */
0, /* tp_members */
objfile_getset, /* tp_getset */
0, /* tp_base */
diff --git a/gdb/python/py-symbol.c b/gdb/python/py-symbol.c
index 2df2336..2c7900f 100644
--- a/gdb/python/py-symbol.c
+++ b/gdb/python/py-symbol.c
@@ -167,6 +167,21 @@ sympy_is_variable (PyObject *self, void *closure)
|| class == LOC_OPTIMIZED_OUT));
}
+/* Implementation of gdb.Symbol.is_valid (self) -> Boolean.
+ Returns True if this Symbol still exists in GDB. */
+
+static PyObject *
+sympy_is_valid (PyObject *self, PyObject *args)
+{
+ struct symbol *symbol = NULL;
+
+ symbol = symbol_object_to_symbol (self);
+ if (symbol == NULL)
+ Py_RETURN_FALSE;
+
+ Py_RETURN_TRUE;
+}
+
/* Given a symbol, and a symbol_object that has previously been
allocated and initialized, populate the symbol_object with the
struct symbol data. Also, register the symbol_object life-cycle
@@ -420,6 +435,13 @@ to display demangled or mangled names.", NULL },
{ NULL } /* Sentinel */
};
+static PyMethodDef symbol_object_methods[] = {
+ { "is_valid", sympy_is_valid, METH_NOARGS,
+ "is_valid () -> Boolean.\n\
+Return true if this symbol is valid, false if not." },
+ {NULL} /* Sentinel */
+};
+
PyTypeObject symbol_object_type = {
PyObject_HEAD_INIT (NULL)
0, /*ob_size*/
@@ -449,7 +471,7 @@ PyTypeObject symbol_object_type = {
0, /*tp_weaklistoffset */
0, /*tp_iter */
0, /*tp_iternext */
- 0, /*tp_methods */
+ symbol_object_methods, /*tp_methods */
0, /*tp_members */
symbol_object_getset /*tp_getset */
};
diff --git a/gdb/python/py-symtab.c b/gdb/python/py-symtab.c
index 5c1c6bb..107cdec 100644
--- a/gdb/python/py-symtab.c
+++ b/gdb/python/py-symtab.c
@@ -138,6 +138,21 @@ stpy_fullname (PyObject *self, PyObject *args)
Py_RETURN_NONE;
}
+/* Implementation of gdb.Symtab.is_valid (self) -> Boolean.
+ Returns True if this Symbol table still exists in GDB. */
+
+static PyObject *
+stpy_is_valid (PyObject *self, PyObject *args)
+{
+ struct symtab *symtab = NULL;
+
+ symtab = symtab_object_to_symtab (self);
+ if (symtab == NULL)
+ Py_RETURN_FALSE;
+
+ Py_RETURN_TRUE;
+}
+
static PyObject *
salpy_str (PyObject *self)
{
@@ -212,6 +227,21 @@ salpy_get_symtab (PyObject *self, void *closure)
return (PyObject *) self_sal->symtab;
}
+/* Implementation of gdb.Symtab_and_line.is_valid (self) -> Boolean.
+ Returns True if this Symbol table and line object still exists GDB. */
+
+static PyObject *
+salpy_is_valid (PyObject *self, PyObject *args)
+{
+ struct symtab_and_line *sal;
+
+ sal = sal_object_to_symtab_and_line (self);
+ if (sal == NULL)
+ Py_RETURN_FALSE;
+
+ Py_RETURN_TRUE;
+}
+
static void
salpy_dealloc (PyObject *self)
{
@@ -441,6 +471,9 @@ static PyGetSetDef symtab_object_getset[] = {
};
static PyMethodDef symtab_object_methods[] = {
+ { "is_valid", stpy_is_valid, METH_NOARGS,
+ "is_valid () -> Boolean.\n\
+Return true if this symbol table is valid, false if not." },
{ "fullname", stpy_fullname, METH_NOARGS,
"fullname () -> String.\n\
Return the symtab's full source filename." },
@@ -489,6 +522,13 @@ static PyGetSetDef sal_object_getset[] = {
{NULL} /* Sentinel */
};
+static PyMethodDef sal_object_methods[] = {
+ { "is_valid", salpy_is_valid, METH_NOARGS,
+ "is_valid () -> Boolean.\n\
+Return true if this symbol table and line is valid, false if not." },
+ {NULL} /* Sentinel */
+};
+
static PyTypeObject sal_object_type = {
PyObject_HEAD_INIT (NULL)
0, /*ob_size*/
@@ -518,7 +558,7 @@ static PyTypeObject sal_object_type = {
0, /*tp_weaklistoffset */
0, /*tp_iter */
0, /*tp_iternext */
- 0, /*tp_methods */
+ sal_object_methods, /*tp_methods */
0, /*tp_members */
sal_object_getset /*tp_getset */
};