From b60c80d639c055a03fcb7def9feb62f2e6e3009f Mon Sep 17 00:00:00 2001 From: Daniel Jacobowitz Date: Wed, 20 Aug 2008 20:12:24 +0000 Subject: [PATCH] * 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. --- gdb/ChangeLog | 9 +++++++++ gdb/dwarf2read.c | 52 ++++++++++++++++++++++++++---------------------- 2 files changed, 37 insertions(+), 24 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 42ac5a6c089..394586b1ea9 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,12 @@ +2008-08-20 Daniel Jacobowitz + + * 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 * dwarf2read.c (REF_HASH_SIZE): Delete. diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index 4d16494093d..7eace886179 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); } -- 2.30.2