/* Scheme interface to types.
- Copyright (C) 2008-2016 Free Software Foundation, Inc.
+ Copyright (C) 2008-2019 Free Software Foundation, Inc.
This file is part of GDB.
#include "gdbtypes.h"
#include "objfiles.h"
#include "language.h"
-#include "vec.h"
#include "bcache.h"
#include "dwarf2loc.h"
#include "typeprint.h"
return t_smob->type;
}
-/* Return the name of TYPE in expanded form.
- Space for the result is malloc'd, caller must free.
- If there's an error computing the name, the result is NULL and the
- exception is stored in *EXCP. */
+/* Return the name of TYPE in expanded form. If there's an error
+ computing the name, throws the gdb exception with scm_throw. */
-static char *
-tyscm_type_name (struct type *type, SCM *excp)
+static std::string
+tyscm_type_name (struct type *type)
{
- char *name = NULL;
-
- TRY
+ SCM excp;
+ try
{
- struct cleanup *old_chain;
- struct ui_file *stb;
-
- stb = mem_fileopen ();
- old_chain = make_cleanup_ui_file_delete (stb);
+ string_file stb;
- LA_PRINT_TYPE (type, "", stb, -1, 0, &type_print_raw_options);
-
- name = ui_file_xstrdup (stb, NULL);
- do_cleanups (old_chain);
+ LA_PRINT_TYPE (type, "", &stb, -1, 0, &type_print_raw_options);
+ return std::move (stb.string ());
}
- CATCH (except, RETURN_MASK_ALL)
+ catch (const gdb_exception &except)
{
- *excp = gdbscm_scm_from_gdb_exception (except);
- return NULL;
+ excp = gdbscm_scm_from_gdb_exception (unpack (except));
}
- END_CATCH
- return name;
+ gdbscm_throw (excp);
}
\f
/* Administrivia for type smobs. */
tyscm_print_type_smob (SCM self, SCM port, scm_print_state *pstate)
{
type_smob *t_smob = (type_smob *) SCM_SMOB_DATA (self);
- SCM exception;
- char *name = tyscm_type_name (t_smob->type, &exception);
-
- if (name == NULL)
- gdbscm_throw (exception);
+ std::string name = tyscm_type_name (t_smob->type);
/* pstate->writingp = zero if invoked by display/~A, and nonzero if
invoked by write/~S. What to do here may need to evolve.
if (pstate->writingp)
gdbscm_printf (port, "#<%s ", type_smob_name);
- scm_puts (name, port);
+ scm_puts (name.c_str (), port);
if (pstate->writingp)
scm_puts (">", port);
{
type_smob *type1_smob, *type2_smob;
struct type *type1, *type2;
- int result = 0;
+ bool result = false;
SCM_ASSERT_TYPE (tyscm_is_type (type1_scm), type1_scm, SCM_ARG1, FUNC_NAME,
type_smob_name);
type1 = type1_smob->type;
type2 = type2_smob->type;
- TRY
+ gdbscm_gdb_exception exc {};
+ try
{
result = types_deeply_equal (type1, type2);
}
- CATCH (except, RETURN_MASK_ALL)
+ catch (const gdb_exception &except)
{
- GDBSCM_HANDLE_GDB_EXCEPTION (except);
+ exc = unpack (except);
}
- END_CATCH
+ GDBSCM_HANDLE_GDB_EXCEPTION (exc);
return scm_from_bool (result);
}
return t_smob;
}
+/* Return the type field of T_SCM, an object of type <gdb:type>.
+ This exists so that we don't have to export the struct's contents. */
+
+struct type *
+tyscm_scm_to_type (SCM t_scm)
+{
+ type_smob *t_smob;
+
+ gdb_assert (tyscm_is_type (t_scm));
+ t_smob = (type_smob *) SCM_SMOB_DATA (t_scm);
+ return t_smob->type;
+}
+
/* Helper function for save_objfile_types to make a deep copy of the type. */
static int
type_smob *t_smob
= tyscm_get_type_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
struct type *type = t_smob->type;
+ const char *tagname = nullptr;
+
+ if (TYPE_CODE (type) == TYPE_CODE_STRUCT
+ || TYPE_CODE (type) == TYPE_CODE_UNION
+ || TYPE_CODE (type) == TYPE_CODE_ENUM)
+ tagname = TYPE_NAME (type);
- if (!TYPE_TAG_NAME (type))
+ if (tagname == nullptr)
return SCM_BOOL_F;
- return gdbscm_scm_from_c_string (TYPE_TAG_NAME (type));
+ return gdbscm_scm_from_c_string (tagname);
}
/* (type-name <gdb:type>) -> string
type_smob *t_smob
= tyscm_get_type_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
struct type *type = t_smob->type;
- char *thetype;
- SCM exception, result;
-
- thetype = tyscm_type_name (type, &exception);
-
- if (thetype == NULL)
- gdbscm_throw (exception);
-
- result = gdbscm_scm_from_c_string (thetype);
- xfree (thetype);
+ std::string thetype = tyscm_type_name (type);
+ SCM result = gdbscm_scm_from_c_string (thetype.c_str ());
return result;
}
= tyscm_get_type_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
struct type *type = t_smob->type;
- TRY
+ try
{
check_typedef (type);
}
- CATCH (except, RETURN_MASK_ALL)
+ catch (const gdb_exception &except)
{
}
- END_CATCH
/* Ignore exceptions. */
= tyscm_get_type_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
struct type *type = t_smob->type;
- TRY
+ gdbscm_gdb_exception exc {};
+ try
{
type = check_typedef (type);
}
- CATCH (except, RETURN_MASK_ALL)
+ catch (const gdb_exception &except)
{
- GDBSCM_HANDLE_GDB_EXCEPTION (except);
+ exc = unpack (except);
}
- END_CATCH
+ GDBSCM_HANDLE_GDB_EXCEPTION (exc);
return tyscm_scm_from_type (type);
}
for (;;)
{
- TRY
+ gdbscm_gdb_exception exc {};
+ try
{
type = check_typedef (type);
}
- CATCH (except, RETURN_MASK_ALL)
+ catch (const gdb_exception &except)
{
- GDBSCM_HANDLE_GDB_EXCEPTION (except);
+ exc = unpack (except);
}
- END_CATCH
+ GDBSCM_HANDLE_GDB_EXCEPTION (exc);
if (TYPE_CODE (type) != TYPE_CODE_PTR
&& TYPE_CODE (type) != TYPE_CODE_REF)
break;
_("Array length must not be negative"));
}
- TRY
+ gdbscm_gdb_exception exc {};
+ 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)
{
- GDBSCM_HANDLE_GDB_EXCEPTION (except);
+ exc = unpack (except);
}
- END_CATCH
+ GDBSCM_HANDLE_GDB_EXCEPTION (exc);
return tyscm_scm_from_type (array);
}
= tyscm_get_type_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
struct type *type = t_smob->type;
- TRY
+ gdbscm_gdb_exception exc {};
+ try
{
type = lookup_pointer_type (type);
}
- CATCH (except, RETURN_MASK_ALL)
+ catch (const gdb_exception &except)
{
- GDBSCM_HANDLE_GDB_EXCEPTION (except);
+ exc = unpack (except);
}
- END_CATCH
+ GDBSCM_HANDLE_GDB_EXCEPTION (exc);
return tyscm_scm_from_type (type);
}
= tyscm_get_type_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
struct type *type = t_smob->type;
- TRY
+ gdbscm_gdb_exception exc {};
+ try
{
- type = lookup_reference_type (type);
+ type = lookup_lvalue_reference_type (type);
}
- CATCH (except, RETURN_MASK_ALL)
+ catch (const gdb_exception &except)
{
- GDBSCM_HANDLE_GDB_EXCEPTION (except);
+ exc = unpack (except);
}
- END_CATCH
+ GDBSCM_HANDLE_GDB_EXCEPTION (exc);
return tyscm_scm_from_type (type);
}
= tyscm_get_type_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
struct type *type = t_smob->type;
- TRY
+ gdbscm_gdb_exception exc {};
+ try
{
type = make_cv_type (1, 0, type, NULL);
}
- CATCH (except, RETURN_MASK_ALL)
+ catch (const gdb_exception &except)
{
- GDBSCM_HANDLE_GDB_EXCEPTION (except);
+ exc = unpack (except);
}
- END_CATCH
+ GDBSCM_HANDLE_GDB_EXCEPTION (exc);
return tyscm_scm_from_type (type);
}
= tyscm_get_type_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
struct type *type = t_smob->type;
- TRY
+ gdbscm_gdb_exception exc {};
+ try
{
type = make_cv_type (0, 1, type, NULL);
}
- CATCH (except, RETURN_MASK_ALL)
+ catch (const gdb_exception &except)
{
- GDBSCM_HANDLE_GDB_EXCEPTION (except);
+ exc = unpack (except);
}
- END_CATCH
+ GDBSCM_HANDLE_GDB_EXCEPTION (exc);
return tyscm_scm_from_type (type);
}
= tyscm_get_type_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
struct type *type = t_smob->type;
- TRY
+ gdbscm_gdb_exception exc {};
+ try
{
type = make_cv_type (0, 0, type, NULL);
}
- CATCH (except, RETURN_MASK_ALL)
+ catch (const gdb_exception &except)
{
- GDBSCM_HANDLE_GDB_EXCEPTION (except);
+ exc = unpack (except);
}
- END_CATCH
+ GDBSCM_HANDLE_GDB_EXCEPTION (exc);
return tyscm_scm_from_type (type);
}
\f
type_smob *t_smob
= tyscm_get_type_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
struct type *type = t_smob->type;
- char *field;
- int i;
- struct cleanup *cleanups;
SCM_ASSERT_TYPE (scm_is_string (field_scm), field_scm, SCM_ARG2, FUNC_NAME,
_("string"));
gdbscm_out_of_range_error (FUNC_NAME, SCM_ARG1, self,
_(not_composite_error));
- field = gdbscm_scm_to_c_string (field_scm);
- cleanups = make_cleanup (xfree, field);
+ {
+ gdb::unique_xmalloc_ptr<char> field = gdbscm_scm_to_c_string (field_scm);
- for (i = 0; i < TYPE_NFIELDS (type); i++)
- {
- const char *t_field_name = TYPE_FIELD_NAME (type, i);
+ for (int i = 0; i < TYPE_NFIELDS (type); i++)
+ {
+ const char *t_field_name = TYPE_FIELD_NAME (type, i);
- if (t_field_name && (strcmp_iw (t_field_name, field) == 0))
- {
- do_cleanups (cleanups);
+ if (t_field_name && (strcmp_iw (t_field_name, field.get ()) == 0))
+ {
+ field.reset (nullptr);
return tyscm_make_field_smob (self, i);
- }
- }
-
- do_cleanups (cleanups);
+ }
+ }
+ }
gdbscm_out_of_range_error (FUNC_NAME, SCM_ARG1, field_scm,
_("Unknown field"));
type_smob *t_smob
= tyscm_get_type_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
struct type *type = t_smob->type;
- char *field;
- int i;
- struct cleanup *cleanups;
SCM_ASSERT_TYPE (scm_is_string (field_scm), field_scm, SCM_ARG2, FUNC_NAME,
_("string"));
gdbscm_out_of_range_error (FUNC_NAME, SCM_ARG1, self,
_(not_composite_error));
- field = gdbscm_scm_to_c_string (field_scm);
- cleanups = make_cleanup (xfree, field);
-
- for (i = 0; i < TYPE_NFIELDS (type); i++)
- {
- const char *t_field_name = TYPE_FIELD_NAME (type, i);
+ {
+ gdb::unique_xmalloc_ptr<char> field
+ = gdbscm_scm_to_c_string (field_scm);
- if (t_field_name && (strcmp_iw (t_field_name, field) == 0))
- {
- do_cleanups (cleanups);
- return SCM_BOOL_T;
- }
- }
+ for (int i = 0; i < TYPE_NFIELDS (type); i++)
+ {
+ const char *t_field_name = TYPE_FIELD_NAME (type, i);
- do_cleanups (cleanups);
+ if (t_field_name && (strcmp_iw (t_field_name, field.get ()) == 0))
+ return SCM_BOOL_T;
+ }
+ }
return SCM_BOOL_F;
}
type_smob *t_smob;
struct type *type;
SCM it_scm, result, progress, object;
- int field, rc;
+ int field;
it_scm = itscm_get_iterator_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
i_smob = (iterator_smob *) SCM_SMOB_DATA (it_scm);
{
field_smob *f_smob
= tyscm_get_field_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
- struct field *field = tyscm_field_smob_to_field (f_smob);
struct type *type = tyscm_field_smob_containing_type (f_smob);
if (TYPE_CODE (type) == TYPE_CODE_STRUCT)
{
struct type *type = NULL;
- TRY
+ try
{
if (startswith (type_name, "struct "))
type = lookup_struct (type_name + 7, NULL);
type = lookup_typename (current_language, get_current_arch (),
type_name, block, 0);
}
- CATCH (except, RETURN_MASK_ALL)
+ catch (const gdb_exception &except)
{
return NULL;
}
- END_CATCH
return type;
}