#include "demangle.h"
#include "objfiles.h"
#include "language.h"
-#include "vec.h"
+#include "common/vec.h"
#include "typeprint.h"
-#include "py-ref.h"
typedef struct pyty_type_object
{
if (arg == NULL)
return NULL;
- /* At least python-2.4 had the second parameter non-const. */
- if (PyObject_SetAttrString (result.get (), (char *) attrstring,
- arg.get ()) < 0)
+ if (PyObject_SetAttrString (result.get (), attrstring, arg.get ()) < 0)
return NULL;
}
struct type *type = ((type_object *) py_type)->type;
struct type *checked_type = type;
- TRY
+ try
{
checked_type = check_typedef (checked_type);
}
- CATCH (except, RETURN_MASK_ALL)
+ catch (const gdb_exception &except)
{
GDB_PY_HANDLE_EXCEPTION (except);
}
- END_CATCH
gdbpy_ref<> type_holder;
if (checked_type != type)
return PyString_FromString (tagname);
}
+/* Return the type's objfile, or None. */
+static PyObject *
+typy_get_objfile (PyObject *self, void *closure)
+{
+ struct type *type = ((type_object *) self)->type;
+ struct objfile *objfile = TYPE_OBJFILE (type);
+
+ if (objfile == nullptr)
+ Py_RETURN_NONE;
+ return objfile_to_objfile_object (objfile).release ();
+}
+
/* Return the type, stripped of typedefs. */
static PyObject *
typy_strip_typedefs (PyObject *self, PyObject *args)
{
struct type *type = ((type_object *) self)->type;
- TRY
+ try
{
type = check_typedef (type);
}
- CATCH (except, RETURN_MASK_ALL)
+ catch (const gdb_exception &except)
{
GDB_PY_HANDLE_EXCEPTION (except);
}
- END_CATCH
return type_to_type_object (type);
}
for (;;)
{
- TRY
+ try
{
type = check_typedef (type);
}
- CATCH (except, RETURN_MASK_ALL)
+ catch (const gdb_exception &except)
{
GDB_PY_HANDLE_EXCEPTION (except);
}
- END_CATCH
if (TYPE_CODE (type) != TYPE_CODE_PTR && !TYPE_IS_REFERENCE (type))
break;
return NULL;
}
- TRY
+ try
{
array = lookup_array_range_type (type, n1, n2);
if (is_vector)
make_vector_type (array);
}
- CATCH (except, RETURN_MASK_ALL)
+ catch (const gdb_exception &except)
{
GDB_PY_HANDLE_EXCEPTION (except);
}
- END_CATCH
return type_to_type_object (array);
}
{
struct type *type = ((type_object *) self)->type;
- TRY
+ try
{
type = lookup_pointer_type (type);
}
- CATCH (except, RETURN_MASK_ALL)
+ catch (const gdb_exception &except)
{
GDB_PY_HANDLE_EXCEPTION (except);
}
- END_CATCH
return type_to_type_object (type);
}
{
struct type *type = ((type_object *) self)->type;
- TRY
+ try
{
type = lookup_lvalue_reference_type (type);
}
- CATCH (except, RETURN_MASK_ALL)
+ catch (const gdb_exception &except)
{
GDB_PY_HANDLE_EXCEPTION (except);
}
- END_CATCH
return type_to_type_object (type);
}
{
struct type *type = ((type_object *) self)->type;
- TRY
+ try
{
type = make_cv_type (1, 0, type, NULL);
}
- CATCH (except, RETURN_MASK_ALL)
+ catch (const gdb_exception &except)
{
GDB_PY_HANDLE_EXCEPTION (except);
}
- END_CATCH
return type_to_type_object (type);
}
{
struct type *type = ((type_object *) self)->type;
- TRY
+ try
{
type = make_cv_type (0, 1, type, NULL);
}
- CATCH (except, RETURN_MASK_ALL)
+ catch (const gdb_exception &except)
{
GDB_PY_HANDLE_EXCEPTION (except);
}
- END_CATCH
return type_to_type_object (type);
}
{
struct type *type = ((type_object *) self)->type;
- TRY
+ try
{
type = make_cv_type (0, 0, type, NULL);
}
- CATCH (except, RETURN_MASK_ALL)
+ catch (const gdb_exception &except)
{
GDB_PY_HANDLE_EXCEPTION (except);
}
- END_CATCH
return type_to_type_object (type);
}
{
struct type *type = ((type_object *) self)->type;
- TRY
+ try
{
check_typedef (type);
}
- CATCH (except, RETURN_MASK_ALL)
+ catch (const gdb_exception &except)
{
}
- END_CATCH
/* Ignore exceptions. */
struct type *type = ((type_object *) self)->type;
ULONGEST align = 0;
- TRY
+ try
{
align = type_align (type);
}
- CATCH (except, RETURN_MASK_ALL)
+ catch (const gdb_exception &except)
{
align = 0;
}
- END_CATCH
/* Ignore exceptions. */
{
struct type *type = NULL;
- TRY
+ try
{
if (startswith (type_name, "struct "))
type = lookup_struct (type_name + 7, NULL);
type = lookup_typename (python_language, python_gdbarch,
type_name, block, 0);
}
- CATCH (except, RETURN_MASK_ALL)
+ catch (const gdb_exception &except)
{
GDB_PY_HANDLE_EXCEPTION (except);
}
- END_CATCH
return type;
}
if (! type)
return NULL;
- TRY
+ try
{
/* If the demangled_type matches with one of the types
below, run the corresponding function and save the type
break;
}
}
- CATCH (except, RETURN_MASK_ALL)
+ catch (const gdb_exception &except)
{
GDB_PY_HANDLE_EXCEPTION (except);
}
- END_CATCH
}
/* If we have a type from the switch statement above, just return
return NULL;
}
- TRY
+ try
{
/* Note -- this is not thread-safe. */
info = cp_demangled_name_to_comp (TYPE_NAME (type), &err);
}
- CATCH (except, RETURN_MASK_ALL)
+ catch (const gdb_exception &except)
{
GDB_PY_HANDLE_EXCEPTION (except);
}
- END_CATCH
if (! info)
{
}
}
- TRY
+ try
{
type = check_typedef (type);
if (TYPE_IS_REFERENCE (type))
type = check_typedef (TYPE_TARGET_TYPE (type));
}
- CATCH (except, RETURN_MASK_ALL)
+ catch (const gdb_exception &except)
{
GDB_PY_HANDLE_EXCEPTION (except);
}
- END_CATCH
/* We might not have DW_TAG_template_*, so try to parse the type's
name. This is inefficient if we do not have a template type --
return NULL;
}
- TRY
+ try
{
val = value_of_variable (sym, block);
}
- CATCH (except, RETURN_MASK_ALL)
+ catch (const gdb_exception &except)
{
GDB_PY_HANDLE_EXCEPTION (except);
}
- END_CATCH
return value_to_value_object (val);
}
{
string_file thetype;
- TRY
+ try
{
LA_PRINT_TYPE (type_object_to_type (self), "", &thetype, -1, 0,
&type_print_raw_options);
}
- CATCH (except, RETURN_MASK_ALL)
+ catch (const gdb_exception &except)
{
GDB_PY_HANDLE_EXCEPTION (except);
}
- END_CATCH
return PyUnicode_Decode (thetype.c_str (), thetype.size (),
host_charset (), NULL);
result = true;
else
{
- TRY
+ try
{
result = types_deeply_equal (type1, type2);
}
- CATCH (except, RETURN_MASK_ALL)
+ catch (const gdb_exception &except)
{
/* If there is a GDB exception, a comparison is not capable
(or trusted), so exit. */
GDB_PY_HANDLE_EXCEPTION (except);
}
- END_CATCH
}
if (op == (result ? Py_EQ : Py_NE))
for (i = 0; pyty_codes[i].name; ++i)
{
- if (PyModule_AddIntConstant (gdb_module,
- /* Cast needed for Python 2.4. */
- (char *) pyty_codes[i].name,
+ if (PyModule_AddIntConstant (gdb_module, pyty_codes[i].name,
pyty_codes[i].code) < 0)
return -1;
}
"The size of this type, in bytes.", NULL },
{ "tag", typy_get_tag, NULL,
"The tag name for this type, or None.", NULL },
+ { "objfile", typy_get_objfile, NULL,
+ "The objfile this type was defined in, or None.", NULL },
{ NULL }
};