A @code{gdb.Symtab} object has the following methods:
+@defun Symtab.__init__ (filename, compunit)
+Create a new symtab for given @var{filename} in given @var{compunit}.
+@end defun
+
@defun Symtab.is_valid ()
Returns @code{True} if the @code{gdb.Symtab} object is valid,
@code{False} if not. A @code{gdb.Symtab} object can become invalid if
} \
} while (0)
+static void set_symtab (symtab_object *obj, struct symtab *symtab);
+
static PyObject *
stpy_str (PyObject *self)
{
return symtab_to_linetable_object (self);
}
+/* Object initializer; creates new symtab.
+
+ Use: __init__(FILENAME, COMPUNIT). */
+
+static int
+stpy_init (PyObject *zelf, PyObject *args, PyObject *kw)
+{
+ struct symtab_object *self = (struct symtab_object*) zelf;
+
+ if (self->symtab)
+ {
+ PyErr_Format (PyExc_RuntimeError,
+ _("Symtab object already initialized."));
+ return -1;
+ }
+
+ static const char *keywords[] = { "filename", "compunit", nullptr };
+ const char *filename;
+ PyObject *cu_obj;
+
+ if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "sO", keywords,
+ &filename, &cu_obj))
+ return -1;
+
+
+ compunit_symtab *cu = compunit_object_to_compunit (cu_obj);
+ if (cu == nullptr)
+ {
+ PyErr_Format (PyExc_TypeError,
+ _("The compunit argument is not valid gdb.Compunit "
+ "object"));
+ return -1;
+ }
+
+ struct symtab *symtab = allocate_symtab (cu, filename);
+ set_symtab (self, symtab);
+
+ return 0;
+}
+
static PyObject *
salpy_str (PyObject *self)
{
static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
gdbpy_initialize_symtabs (void)
{
- symtab_object_type.tp_new = PyType_GenericNew;
if (gdbpy_type_ready (&symtab_object_type) < 0)
return -1;
0, /*tp_iternext */
symtab_object_methods, /*tp_methods */
0, /*tp_members */
- symtab_object_getset /*tp_getset */
+ symtab_object_getset, /*tp_getset */
+ 0, /*tp_base */
+ 0, /*tp_dict */
+ 0, /*tp_descr_get */
+ 0, /*tp_descr_set */
+ 0, /*tp_dictoffset */
+ stpy_init, /*tp_init */
+ 0, /*tp_alloc */
+ PyType_GenericNew, /*tp_new */
};
static gdb_PyGetSetDef sal_object_getset[] = {
gdb_test "python print (symtab.compunit.static_block() is symtab.static_block())" \
"True" "Test symtab.compunit.static_block() is symtab.static_block()"
+# Test creating new symtab in existing compunit
+gdb_py_test_silent_cmd "python cu = symtab.compunit" "remember compunit" 1
+gdb_test "python print(repr( gdb.Symtab(\"some_file.txt\", cu) ))" \
+ "<gdb.Symtab object at .*>" \
+ "test creation of symtab"
+
+gdb_test "python print(repr( gdb.Symtab(\"some_file.txt\", (1,2,3)) ))" \
+ "TypeError.*:.*" \
+ "test creation of symtab passing non-compunit object"
+
+
# Test is_valid when the objfile is unloaded. This must be the last
# test as it unloads the object file in GDB.
gdb_unload
gdb_test_no_output "python sal = None" "test sal destructor"
gdb_test_no_output "python symtab = None" "test symtab destructor"
+
+gdb_test "python print(repr( gdb.Symtab(\"some_file2.txt\", cu) ))" \
+ "TypeError.*:.*" \
+ "test creation of symtab passing invalid compunit"