/* debug.c -- Handle generic debugging information.
- Copyright (C) 1995, 1996, 1998 Free Software Foundation, Inc.
+ Copyright 1995, 1996, 1997, 1998, 2000, 2002 Free Software Foundation, Inc.
Written by Ian Lance Taylor <ian@cygnus.com>.
This file is part of GNU Binutils.
struct debug_type *t2;
};
+/* During debug_get_real_type, a linked list of these structures is
+ kept on the stack to avoid infinite recursion. */
+
+struct debug_type_real_list
+{
+ /* Next type on list. */
+ struct debug_type_real_list *next;
+ /* The type we are checking. */
+ struct debug_type *t;
+};
+
/* Local functions. */
static void debug_error PARAMS ((const char *));
enum debug_object_linkage));
static struct debug_type *debug_make_type
PARAMS ((struct debug_handle *, enum debug_type_kind, unsigned int));
-static struct debug_type *debug_get_real_type PARAMS ((PTR, debug_type));
+static struct debug_type *debug_get_real_type
+ PARAMS ((PTR, debug_type, struct debug_type_real_list *));
static boolean debug_write_name
PARAMS ((struct debug_handle *, const struct debug_write_fns *, PTR,
struct debug_name *));
static struct debug_name *
debug_add_to_namespace (info, nsp, name, kind, linkage)
- struct debug_handle *info;
+ struct debug_handle *info ATTRIBUTE_UNUSED;
struct debug_namespace **nsp;
const char *name;
enum debug_object_kind kind;
boolean
debug_start_common_block (handle, name)
- PTR handle;
- const char *name;
+ PTR handle ATTRIBUTE_UNUSED;
+ const char *name ATTRIBUTE_UNUSED;
{
/* FIXME */
debug_error (_("debug_start_common_block: not implemented"));
boolean
debug_end_common_block (handle, name)
- PTR handle;
- const char *name;
+ PTR handle ATTRIBUTE_UNUSED;
+ const char *name ATTRIBUTE_UNUSED;
{
/* FIXME */
debug_error (_("debug_end_common_block: not implemented"));
boolean
debug_record_label (handle, name, type, addr)
- PTR handle;
- const char *name;
- debug_type type;
- bfd_vma addr;
+ PTR handle ATTRIBUTE_UNUSED;
+ const char *name ATTRIBUTE_UNUSED;
+ debug_type type ATTRIBUTE_UNUSED;
+ bfd_vma addr ATTRIBUTE_UNUSED;
{
/* FIXME. */
- debug_error (_("debug_record_label not implemented"));
+ debug_error (_("debug_record_label: not implemented"));
return false;
}
n->u.variable = v;
- return true;
+ return true;
}
/* Make a type with a given kind and size. */
-/*ARGSUSED*/
static struct debug_type *
debug_make_type (info, kind, size)
- struct debug_handle *info;
+ struct debug_handle *info ATTRIBUTE_UNUSED;
enum debug_type_kind kind;
unsigned int size;
{
The fourth argument is whether this is a virtual class. The fifth
argument is the visibility of the base class. */
-/*ARGSUSED*/
debug_baseclass
debug_make_baseclass (handle, type, bitpos, virtual, visibility)
- PTR handle;
+ PTR handle ATTRIBUTE_UNUSED;
debug_type type;
bfd_vma bitpos;
boolean virtual;
enum debug_visibility visibility;
-{
+{
struct debug_baseclass *b;
b = (struct debug_baseclass *) xmalloc (sizeof *b);
the field (it may be zero). The sixth argument is the visibility
of the field. */
-/*ARGSUSED*/
debug_field
debug_make_field (handle, name, type, bitpos, bitsize, visibility)
- PTR handle;
+ PTR handle ATTRIBUTE_UNUSED;
const char *name;
debug_type type;
bfd_vma bitpos;
global variable). The fifth argument is the visibility of the
member. */
-/*ARGSUSED*/
debug_field
debug_make_static_member (handle, name, type, physname, visibility)
- PTR handle;
+ PTR handle ATTRIBUTE_UNUSED;
const char *name;
debug_type type;
const char *physname;
/* Make a method. The second argument is the name, and the third
argument is a NULL terminated array of method variants. */
-/*ARGSUSED*/
debug_method
debug_make_method (handle, name, variants)
- PTR handle;
+ PTR handle ATTRIBUTE_UNUSED;
const char *name;
debug_method_variant *variants;
{
function context. FIXME: Are the const and volatile arguments
necessary? Could we just use debug_make_const_type? */
-/*ARGSUSED*/
debug_method_variant
debug_make_method_variant (handle, physname, type, visibility, constp,
volatilep, voffset, context)
- PTR handle;
+ PTR handle ATTRIBUTE_UNUSED;
const char *physname;
debug_type type;
enum debug_visibility visibility;
debug_method_variant
debug_make_static_method_variant (handle, physname, type, visibility,
constp, volatilep)
- PTR handle;
+ PTR handle ATTRIBUTE_UNUSED;
const char *physname;
debug_type type;
enum debug_visibility visibility;
|| info->current_file == NULL)
{
debug_error (_("debug_name_type: no current file"));
- return false;
+ return DEBUG_TYPE_NULL;
}
t = debug_make_type (info, DEBUG_KIND_NAMED, 0);
nm = debug_add_to_namespace (info, &info->current_file->globals, name,
DEBUG_OBJECT_TYPE, DEBUG_LINKAGE_NONE);
if (nm == NULL)
- return false;
+ return DEBUG_TYPE_NULL;
nm->u.type = t;
nm = debug_add_to_namespace (info, &info->current_file->globals, name,
DEBUG_OBJECT_TAG, DEBUG_LINKAGE_NONE);
if (nm == NULL)
- return false;
+ return DEBUG_TYPE_NULL;
nm->u.tag = t;
/* Record the size of a given type. */
-/*ARGSUSED*/
boolean
debug_record_type_size (handle, type, size)
- PTR handle;
+ PTR handle ATTRIBUTE_UNUSED;
debug_type type;
unsigned int size;
{
}
}
- return DEBUG_TYPE_NULL;
+ return DEBUG_TYPE_NULL;
}
/* Find a tagged type. */
return DEBUG_TYPE_NULL;
}
-/* Get a base type. */
+/* Get a base type. We build a linked list on the stack to avoid
+ crashing if the type is defined circularly. */
static struct debug_type *
-debug_get_real_type (handle, type)
+debug_get_real_type (handle, type, list)
PTR handle;
debug_type type;
+ struct debug_type_real_list *list;
{
+ struct debug_type_real_list *l;
+ struct debug_type_real_list rl;
+
switch (type->kind)
{
default:
return type;
+
+ case DEBUG_KIND_INDIRECT:
+ case DEBUG_KIND_NAMED:
+ case DEBUG_KIND_TAGGED:
+ break;
+ }
+
+ for (l = list; l != NULL; l = l->next)
+ {
+ if (l->t == type)
+ {
+ fprintf (stderr,
+ _("debug_get_real_type: circular debug information for %s\n"),
+ debug_get_type_name (handle, type));
+ return NULL;
+ }
+ }
+
+ rl.next = list;
+ rl.t = type;
+
+ switch (type->kind)
+ {
+ /* The default case is just here to avoid warnings. */
+ default:
case DEBUG_KIND_INDIRECT:
if (*type->u.kindirect->slot != NULL)
- return debug_get_real_type (handle, *type->u.kindirect->slot);
+ return debug_get_real_type (handle, *type->u.kindirect->slot, &rl);
return type;
case DEBUG_KIND_NAMED:
case DEBUG_KIND_TAGGED:
- return debug_get_real_type (handle, type->u.knamed->type);
+ return debug_get_real_type (handle, type->u.knamed->type, &rl);
}
/*NOTREACHED*/
}
{
if (type == NULL)
return DEBUG_KIND_ILLEGAL;
- type = debug_get_real_type (handle, type);
+ type = debug_get_real_type (handle, type, NULL);
+ if (type == NULL)
+ return DEBUG_KIND_ILLEGAL;
return type->kind;
}
{
if (type == NULL)
return DEBUG_TYPE_NULL;
- type = debug_get_real_type (handle, type);
+ type = debug_get_real_type (handle, type, NULL);
+ if (type == NULL)
+ return DEBUG_TYPE_NULL;
switch (type->kind)
{
default:
case DEBUG_KIND_METHOD:
return type->u.kmethod->return_type;
}
- /*NOTREACHED*/
+ /*NOTREACHED*/
}
/* Get the parameter types of a function or method type (except that
{
if (type == NULL)
return NULL;
- type = debug_get_real_type (handle, type);
+ type = debug_get_real_type (handle, type, NULL);
+ if (type == NULL)
+ return NULL;
switch (type->kind)
{
default:
{
if (type == NULL)
return NULL;
- type = debug_get_real_type (handle, type);
+ type = debug_get_real_type (handle, type, NULL);
+ if (type == NULL)
+ return NULL;
switch (type->kind)
{
default:
{
if (type == NULL)
return NULL;
- type = debug_get_real_type (handle, type);
+ type = debug_get_real_type (handle, type, NULL);
+ if (type == NULL)
+ return NULL;
switch (type->kind)
{
default:
/* Get the type of a field. */
-/*ARGSUSED*/
debug_type
debug_get_field_type (handle, field)
- PTR handle;
+ PTR handle ATTRIBUTE_UNUSED;
debug_field field;
{
if (field == NULL)
/* Get the name of a field. */
-/*ARGSUSED*/
const char *
debug_get_field_name (handle, field)
- PTR handle;
+ PTR handle ATTRIBUTE_UNUSED;
debug_field field;
{
if (field == NULL)
/* Get the bit position of a field. */
-/*ARGSUSED*/
bfd_vma
debug_get_field_bitpos (handle, field)
- PTR handle;
+ PTR handle ATTRIBUTE_UNUSED;
debug_field field;
{
if (field == NULL || field->static_member)
/* Get the bit size of a field. */
-/*ARGSUSED*/
bfd_vma
debug_get_field_bitsize (handle, field)
- PTR handle;
+ PTR handle ATTRIBUTE_UNUSED;
debug_field field;
{
if (field == NULL || field->static_member)
/* Get the visibility of a field. */
-/*ARGSUSED*/
enum debug_visibility
debug_get_field_visibility (handle, field)
- PTR handle;
+ PTR handle ATTRIBUTE_UNUSED;
debug_field field;
{
if (field == NULL)
const char *
debug_get_field_physname (handle, field)
- PTR handle;
+ PTR handle ATTRIBUTE_UNUSED;
debug_field field;
{
if (field == NULL || ! field->static_member)
{
unsigned int i;
int is;
- const char *tag;
+ const char *tag = NULL;
/* If we have a name for this type, just output it. We only output
typedef names after they have been defined. We output type tags
struct debug_type *real;
unsigned int id;
- real = debug_get_real_type ((PTR) info, type);
+ real = debug_get_real_type ((PTR) info, type, NULL);
+ if (real == NULL)
+ return (*fns->empty_type) (fhandle);
id = 0;
if ((real->kind == DEBUG_KIND_STRUCT
|| real->kind == DEBUG_KIND_UNION
if (name != NULL)
name->mark = info->mark;
- tag = NULL;
if (name != NULL
&& type->kind != DEBUG_KIND_NAMED
&& type->kind != DEBUG_KIND_TAGGED)
case DEBUG_KIND_POINTER:
ret = debug_type_samep (info, t1->u.kpointer, t2->u.kpointer);
break;
-
+
case DEBUG_KIND_FUNCTION:
if (t1->u.kfunction->varargs != t2->u.kfunction->varargs
|| ! debug_type_samep (info, t1->u.kfunction->return_type,
if (strcmp (f1->name, f2->name) != 0
|| ! debug_type_samep (info,
debug_get_real_type ((PTR) info,
- f1->type),
+ f1->type, NULL),
debug_get_real_type ((PTR) info,
- f2->type)))
+ f2->type, NULL)))
return false;
}
if (*pf1 != NULL || *pf2 != NULL)