aboutsummaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
authorDaniel Jacobowitz <drow@false.org>2008-08-20 20:12:24 +0000
committerDaniel Jacobowitz <drow@false.org>2008-08-20 20:12:24 +0000
commitb60c80d639c055a03fcb7def9feb62f2e6e3009f (patch)
treec6b577d18e1e415f03c598457b687367f3a84b34 /gdb
parent51545339ac7cb71869b6e749c5d3cc2c15b3e12c (diff)
downloadgdb-b60c80d639c055a03fcb7def9feb62f2e6e3009f.zip
gdb-b60c80d639c055a03fcb7def9feb62f2e6e3009f.tar.gz
gdb-b60c80d639c055a03fcb7def9feb62f2e6e3009f.tar.bz2
* dwarf2read.c (struct attribute): Move earlier.
(struct die_info): Change attrs to a trailing array. (dwarf_alloc_die): Take the number of attributes. Allocate space for them. (read_full_die): Update call to dwarf_alloc_die. Do not manually allocate attributes.
Diffstat (limited to 'gdb')
-rw-r--r--gdb/ChangeLog9
-rw-r--r--gdb/dwarf2read.c52
2 files changed, 37 insertions, 24 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 42ac5a6..394586b 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,14 @@
2008-08-20 Daniel Jacobowitz <dan@codesourcery.com>
+ * dwarf2read.c (struct attribute): Move earlier.
+ (struct die_info): Change attrs to a trailing array.
+ (dwarf_alloc_die): Take the number of attributes. Allocate space
+ for them.
+ (read_full_die): Update call to dwarf_alloc_die. Do not manually
+ allocate attributes.
+
+2008-08-20 Daniel Jacobowitz <dan@codesourcery.com>
+
* dwarf2read.c (REF_HASH_SIZE): Delete.
(struct dwarf2_cu): Replace die_ref_table with die_hash.
(struct die_info): Remove next_ref.
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 4d16494..7eace88 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -521,6 +521,22 @@ struct attr_abbrev
enum dwarf_form form;
};
+/* Attributes have a name and a value */
+struct attribute
+ {
+ enum dwarf_attribute name;
+ enum dwarf_form form;
+ union
+ {
+ char *str;
+ struct dwarf_block *blk;
+ unsigned long unsnd;
+ long int snd;
+ CORE_ADDR addr;
+ }
+ u;
+ };
+
/* This data structure holds a complete die structure. */
struct die_info
{
@@ -528,7 +544,6 @@ struct die_info
unsigned int abbrev; /* Abbrev number */
unsigned int offset; /* Offset in .debug_info section */
unsigned int num_attrs; /* Number of attributes */
- struct attribute *attrs; /* An array of attributes */
/* The dies in a compilation unit form an n-ary tree. PARENT
points to this die's parent; CHILD points to the first child of
@@ -538,22 +553,11 @@ struct die_info
struct die_info *child; /* Its first child, if any. */
struct die_info *sibling; /* Its next sibling, if any. */
struct die_info *parent; /* Its parent, if any. */
- };
-/* Attributes have a name and a value */
-struct attribute
- {
- enum dwarf_attribute name;
- enum dwarf_form form;
- union
- {
- char *str;
- struct dwarf_block *blk;
- unsigned long unsnd;
- long int snd;
- CORE_ADDR addr;
- }
- u;
+ /* An array of attributes, with NUM_ATTRS elements. There may be
+ zero, but it's not common and zero-sized arrays are not
+ sufficiently portable C. */
+ struct attribute attrs[1];
};
struct function_range
@@ -997,7 +1001,7 @@ static struct dwarf_block *dwarf_alloc_block (struct dwarf2_cu *);
static struct abbrev_info *dwarf_alloc_abbrev (struct dwarf2_cu *);
-static struct die_info *dwarf_alloc_die (struct dwarf2_cu *);
+static struct die_info *dwarf_alloc_die (struct dwarf2_cu *, int);
static void initialize_cu_func_list (struct dwarf2_cu *);
@@ -6060,15 +6064,12 @@ read_full_die (struct die_info **diep, bfd *abfd, gdb_byte *info_ptr,
abbrev_number,
bfd_get_filename (abfd));
}
- die = dwarf_alloc_die (cu);
+ die = dwarf_alloc_die (cu, abbrev->num_attrs);
die->offset = offset;
die->tag = abbrev->tag;
die->abbrev = abbrev_number;
die->num_attrs = abbrev->num_attrs;
- die->attrs = (struct attribute *)
- obstack_alloc (&cu->comp_unit_obstack,
- die->num_attrs * sizeof (struct attribute));
for (i = 0; i < abbrev->num_attrs; ++i)
{
@@ -9448,12 +9449,15 @@ dwarf_alloc_abbrev (struct dwarf2_cu *cu)
}
static struct die_info *
-dwarf_alloc_die (struct dwarf2_cu *cu)
+dwarf_alloc_die (struct dwarf2_cu *cu, int num_attrs)
{
struct die_info *die;
+ size_t size = sizeof (struct die_info);
+
+ if (num_attrs > 1)
+ size += (num_attrs - 1) * sizeof (struct attribute);
- die = (struct die_info *)
- obstack_alloc (&cu->comp_unit_obstack, sizeof (struct die_info));
+ die = (struct die_info *) obstack_alloc (&cu->comp_unit_obstack, size);
memset (die, 0, sizeof (struct die_info));
return (die);
}