This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[commit/dwarf2] Allocate attributes inside the DIE
- From: Daniel Jacobowitz <drow at false dot org>
- To: gdb-patches at sourceware dot org
- Date: Wed, 20 Aug 2008 16:28:09 -0400
- Subject: [commit/dwarf2] Allocate attributes inside the DIE
Another performance-neutral update. There's no need to allocate these
two items separately, since there's a 1:1 correspondence and we know
their fixed sizes at allocation time. So I removed the indirection
and combined the allocations, shrinking struct die_info further
(though at least at the moment, the space savings do not matter;
they're inside the alignment constant of the obstack on a 64-bit
host).
Tested on x86_64-linux, committed.
--
Daniel Jacobowitz
CodeSourcery
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.
---
gdb/dwarf2read.c | 52 ++++++++++++++++++++++++++++------------------------
1 file changed, 28 insertions(+), 24 deletions(-)
Index: src/gdb/dwarf2read.c
===================================================================
--- src.orig/gdb/dwarf2read.c 2008-08-10 11:10:07.000000000 -0400
+++ src/gdb/dwarf2read.c 2008-08-10 11:15:27.000000000 -0400
@@ -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_b
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, b
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);
}