/* debug.c -- Handle generic debugging information.
- Copyright (C) 1995, 1996 Free Software Foundation, Inc.
+ Copyright (C) 1995, 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
Written by Ian Lance Taylor <ian@cygnus.com>.
This file is part of GNU Binutils.
unsigned int class_id;
/* The base for class_id for this call to debug_write. */
unsigned int base_id;
+ /* The current line number in debug_write. */
+ struct debug_lineno *current_write_lineno;
+ unsigned int current_write_lineno_index;
/* A list of classes which have assigned ID's during debug_write.
This is linked through the next_id field of debug_class_type. */
struct debug_class_id *id_list;
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 boolean debug_write_block
PARAMS ((struct debug_handle *, const struct debug_write_fns *, PTR,
struct debug_block *));
+static boolean debug_write_linenos
+ PARAMS ((struct debug_handle *, const struct debug_write_fns *, PTR,
+ bfd_vma));
static boolean debug_set_class_id
PARAMS ((struct debug_handle *, const char *, struct debug_type *));
static boolean debug_type_samep
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;
if (info->current_unit == NULL
|| info->current_file == NULL)
{
- debug_error ("debug_add_to_current_namespace: no current file");
+ debug_error (_("debug_add_to_current_namespace: no current file"));
return NULL;
}
if (info->current_unit == NULL)
{
- debug_error ("debug_start_source: no debug_set_filename call");
+ debug_error (_("debug_start_source: no debug_set_filename call"));
return false;
}
if (info->current_unit == NULL)
{
- debug_error ("debug_record_function: no debug_set_filename call");
+ debug_error (_("debug_record_function: no debug_set_filename call"));
return false;
}
if (info->current_unit == NULL
|| info->current_function == NULL)
{
- debug_error ("debug_record_parameter: no current function");
+ debug_error (_("debug_record_parameter: no current function"));
return false;
}
|| info->current_block == NULL
|| info->current_function == NULL)
{
- debug_error ("debug_end_function: no current function");
+ debug_error (_("debug_end_function: no current function"));
return false;
}
if (info->current_block->parent != NULL)
{
- debug_error ("debug_end_function: some blocks were not closed");
+ debug_error (_("debug_end_function: some blocks were not closed"));
return false;
}
if (info->current_unit == NULL
|| info->current_block == NULL)
{
- debug_error ("debug_start_block: no current block");
+ debug_error (_("debug_start_block: no current block"));
return false;
}
if (info->current_unit == NULL
|| info->current_block == NULL)
{
- debug_error ("debug_end_block: no current block");
+ debug_error (_("debug_end_block: no current block"));
return false;
}
parent = info->current_block->parent;
if (parent == NULL)
{
- debug_error ("debug_end_block: attempt to close top level block");
+ debug_error (_("debug_end_block: attempt to close top level block"));
return false;
}
if (info->current_unit == NULL)
{
- debug_error ("debug_record_line: no current unit");
+ debug_error (_("debug_record_line: no current unit"));
return false;
}
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");
+ debug_error (_("debug_start_common_block: not implemented"));
return false;
}
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");
+ debug_error (_("debug_end_common_block: not implemented"));
return false;
}
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;
}
if (info->current_unit == NULL
|| info->current_file == NULL)
{
- debug_error ("debug_record_variable: no current file");
+ debug_error (_("debug_record_variable: no current file"));
return false;
}
{
if (info->current_block == NULL)
{
- debug_error ("debug_record_variable: no current block");
+ debug_error (_("debug_record_variable: no current block"));
return false;
}
nsp = &info->current_block->locals;
/*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;
{
break;
default:
- debug_error ("debug_make_undefined_type: unsupported kind");
+ debug_error (_("debug_make_undefined_type: unsupported kind"));
return DEBUG_TYPE_NULL;
}
/*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;
/*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;
/*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;
/*ARGSUSED*/
debug_method
debug_make_method (handle, name, variants)
- PTR handle;
+ PTR handle ATTRIBUTE_UNUSED;
const char *name;
debug_method_variant *variants;
{
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;
if (info->current_unit == NULL
|| info->current_file == NULL)
{
- debug_error ("debug_record_variable: no current file");
- return false;
+ debug_error (_("debug_name_type: no current file"));
+ 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;
if (info->current_file == NULL)
{
- debug_error ("debug_tag_type: no current file");
+ debug_error (_("debug_tag_type: no current file"));
return DEBUG_TYPE_NULL;
}
{
if (strcmp (type->u.knamed->name->name, name) == 0)
return type;
- debug_error ("debug_tag_type: extra tag attempted");
+ debug_error (_("debug_tag_type: extra tag attempted"));
return DEBUG_TYPE_NULL;
}
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;
/*ARGSUSED*/
boolean
debug_record_type_size (handle, type, size)
- PTR handle;
+ PTR handle ATTRIBUTE_UNUSED;
debug_type type;
unsigned int size;
{
if (type->size != 0 && type->size != size)
- fprintf (stderr, "Warning: changing type size from %d to %d\n",
+ fprintf (stderr, _("Warning: changing type size from %d to %d\n"),
type->size, size);
type->size = size;
if (info->current_unit == NULL)
{
- debug_error ("debug_find_named_type: no current compilation unit");
+ debug_error (_("debug_find_named_type: no current compilation unit"));
return DEBUG_TYPE_NULL;
}
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:
{
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:
/*ARGSUSED*/
debug_type
debug_get_field_type (handle, field)
- PTR handle;
+ PTR handle ATTRIBUTE_UNUSED;
debug_field field;
{
if (field == NULL)
/*ARGSUSED*/
const char *
debug_get_field_name (handle, field)
- PTR handle;
+ PTR handle ATTRIBUTE_UNUSED;
debug_field field;
{
if (field == NULL)
/*ARGSUSED*/
bfd_vma
debug_get_field_bitpos (handle, field)
- PTR handle;
+ PTR handle ATTRIBUTE_UNUSED;
debug_field field;
{
if (field == NULL || field->static_member)
/*ARGSUSED*/
bfd_vma
debug_get_field_bitsize (handle, field)
- PTR handle;
+ PTR handle ATTRIBUTE_UNUSED;
debug_field field;
{
if (field == NULL || field->static_member)
/*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)
{
struct debug_file *f;
boolean first_file;
- struct debug_lineno *l;
+
+ info->current_write_lineno = u->linenos;
+ info->current_write_lineno_index = 0;
if (! (*fns->start_compilation_unit) (fhandle, u->files->filename))
return false;
}
}
- for (l = u->linenos; l != NULL; l = l->next)
- {
- unsigned int i;
-
- for (i = 0; i < DEBUG_LINENO_COUNT; i++)
- {
- if (l->linenos[i] == (unsigned long) -1)
- break;
- if (! (*fns->lineno) (fhandle, l->file->filename, l->linenos[i],
- l->addrs[i]))
- return false;
- }
- }
+ /* Output any line number information which hasn't already been
+ handled. */
+ if (! debug_write_linenos (info, fns, fhandle, (bfd_vma) -1))
+ return false;
}
return true;
{
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)
switch (type->kind)
{
case DEBUG_KIND_ILLEGAL:
- debug_error ("debug_write_type: illegal type encountered");
+ debug_error (_("debug_write_type: illegal type encountered"));
return false;
case DEBUG_KIND_INDIRECT:
if (*type->u.kindirect->slot == DEBUG_TYPE_NULL)
return false;
return (*fns->pointer_type) (fhandle);
case DEBUG_KIND_FUNCTION:
+ if (! debug_write_type (info, fns, fhandle,
+ type->u.kfunction->return_type,
+ (struct debug_name *) NULL))
+ return false;
if (type->u.kfunction->arg_types == NULL)
is = -1;
else
(struct debug_name *) NULL))
return false;
}
- if (! debug_write_type (info, fns, fhandle,
- type->u.kfunction->return_type,
- (struct debug_name *) NULL))
- return false;
return (*fns->function_type) (fhandle, is,
type->u.kfunction->varargs);
case DEBUG_KIND_REFERENCE:
struct debug_parameter *p;
struct debug_block *b;
+ if (! debug_write_linenos (info, fns, fhandle, function->blocks->start))
+ return false;
+
if (! debug_write_type (info, fns, fhandle, function->return_type,
(struct debug_name *) NULL))
return false;
struct debug_name *n;
struct debug_block *b;
+ if (! debug_write_linenos (info, fns, fhandle, block->start))
+ return false;
+
/* I can't see any point to writing out a block with no local
variables, so we don't bother, except for the top level block. */
if (block->locals != NULL || block->parent == NULL)
return false;
}
+ if (! debug_write_linenos (info, fns, fhandle, block->end))
+ return false;
+
if (block->locals != NULL || block->parent == NULL)
{
if (! (*fns->end_block) (fhandle, block->end))
return true;
}
+/* Write out line number information up to ADDRESS. */
+
+static boolean
+debug_write_linenos (info, fns, fhandle, address)
+ struct debug_handle *info;
+ const struct debug_write_fns *fns;
+ PTR fhandle;
+ bfd_vma address;
+{
+ while (info->current_write_lineno != NULL)
+ {
+ struct debug_lineno *l;
+
+ l = info->current_write_lineno;
+
+ while (info->current_write_lineno_index < DEBUG_LINENO_COUNT)
+ {
+ if (l->linenos[info->current_write_lineno_index]
+ == (unsigned long) -1)
+ break;
+
+ if (l->addrs[info->current_write_lineno_index] >= address)
+ return true;
+
+ if (! (*fns->lineno) (fhandle, l->file->filename,
+ l->linenos[info->current_write_lineno_index],
+ l->addrs[info->current_write_lineno_index]))
+ return false;
+
+ ++info->current_write_lineno_index;
+ }
+
+ info->current_write_lineno = l->next;
+ info->current_write_lineno_index = 0;
+ }
+
+ return true;
+}
+
/* Get the ID number for a class. If during the same call to
debug_write we find a struct with the same definition with the same
name, we use the same ID. This type of things happens because the
struct debug_type_compare_list top;
boolean ret;
+ if (t1 == NULL)
+ return t2 == NULL;
+ if (t2 == NULL)
+ return false;
+
while (t1->kind == DEBUG_KIND_INDIRECT)
{
t1 = *t1->u.kindirect->slot;
a1 = t1->u.kfunction->arg_types;
a2 = t2->u.kfunction->arg_types;
while (*a1 != NULL && *a2 != NULL)
- if (! debug_type_samep (info, *a1, *a2))
- break;
+ {
+ if (! debug_type_samep (info, *a1, *a2))
+ break;
+ ++a1;
+ ++a2;
+ }
ret = *a1 == NULL && *a2 == NULL;
}
break;
a1 = t1->u.kmethod->arg_types;
a2 = t2->u.kmethod->arg_types;
while (*a1 != NULL && *a2 != NULL)
- if (! debug_type_samep (info, *a1, *a2))
- break;
+ {
+ if (! debug_type_samep (info, *a1, *a2))
+ break;
+ ++a1;
+ ++a2;
+ }
ret = *a1 == NULL && *a2 == NULL;
}
break;
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)