gdb/gdb-bz645773-ifort-case-2of...

205 lines
6.9 KiB
Diff

http://sourceware.org/ml/gdb-patches/2010-11/msg00107.html
Subject: [patch 1/2] Code cleanup: New init_one_comp_unit
Hi,
unify some code into a function, to be extended in the next patch.
Thanks,
Jan
gdb/
2010-11-06 Jan Kratochvil <jan.kratochvil@redhat.com>
Code cleanup.
* dwarf2read.c (alloc_one_comp_unit): Rename prototype to ...
(init_one_comp_unit): ... this one.
(prepare_one_comp_unit): New prototype.
(dw2_require_line_header, process_psymtab_comp_unit): Use
init_one_comp_unit.
(process_psymtab_comp_unit): Use prepare_one_comp_unit.
(load_partial_comp_unit): Remove variable attr. Use
init_one_comp_unit with xmalloc. Use prepare_one_comp_unit.
(load_full_comp_unit): Use init_one_comp_unit with xmalloc. Use
prepare_one_comp_unit.
(read_signatured_type): Remove variable attr. Use init_one_comp_unit.
Use prepare_one_comp_unit.
(alloc_one_comp_unit): Rename to ...
(init_one_comp_unit): ... here and remove there calloc, new parameter
cu.
(prepare_one_comp_unit): New function.
Index: gdb-7.2/gdb/dwarf2read.c
===================================================================
--- gdb-7.2.orig/gdb/dwarf2read.c 2010-11-07 05:36:34.000000000 +0100
+++ gdb-7.2/gdb/dwarf2read.c 2010-11-07 05:38:21.000000000 +0100
@@ -1214,7 +1214,11 @@ static struct dwarf2_per_cu_data *dwarf2
static struct dwarf2_per_cu_data *dwarf2_find_comp_unit
(unsigned int offset, struct objfile *objfile);
-static struct dwarf2_cu *alloc_one_comp_unit (struct objfile *objfile);
+static void init_one_comp_unit (struct dwarf2_cu *cu,
+ struct objfile *objfile);
+
+static void prepare_one_comp_unit (struct dwarf2_cu *cu,
+ struct die_info *comp_unit_die);
static void free_one_comp_unit (void *);
@@ -1980,10 +1984,7 @@ dw2_require_line_header (struct objfile
return;
this_cu->v.quick->read_lines = 1;
- memset (&cu, 0, sizeof (cu));
- cu.objfile = objfile;
- obstack_init (&cu.comp_unit_obstack);
-
+ init_one_comp_unit (&cu, objfile);
cleanups = make_cleanup (free_stack_comp_unit, &cu);
dwarf2_read_section (objfile, &dwarf2_per_objfile->info);
@@ -2978,10 +2979,7 @@ process_psymtab_comp_unit (struct objfil
CORE_ADDR best_lowpc = 0, best_highpc = 0;
struct die_reader_specs reader_specs;
- memset (&cu, 0, sizeof (cu));
- cu.objfile = objfile;
- obstack_init (&cu.comp_unit_obstack);
-
+ init_one_comp_unit (&cu, objfile);
back_to_inner = make_cleanup (free_stack_comp_unit, &cu);
info_ptr = partial_read_comp_unit_head (&cu.header, info_ptr,
@@ -3035,12 +3033,7 @@ process_psymtab_comp_unit (struct objfil
return info_ptr;
}
- /* Set the language we're debugging. */
- attr = dwarf2_attr (comp_unit_die, DW_AT_language, &cu);
- if (attr)
- set_cu_language (DW_UNSND (attr), &cu);
- else
- set_cu_language (language_minimal, &cu);
+ prepare_one_comp_unit (&cu, comp_unit_die);
/* Allocate a new partial symbol table structure. */
attr = dwarf2_attr (comp_unit_die, DW_AT_name, &cu);
@@ -3263,7 +3256,8 @@ load_partial_comp_unit (struct dwarf2_pe
info_ptr = dwarf2_per_objfile->info.buffer + this_cu->offset;
beg_of_comp_unit = info_ptr;
- cu = alloc_one_comp_unit (objfile);
+ cu = xmalloc (sizeof (*cu));
+ init_one_comp_unit (cu, objfile);
/* ??? Missing cleanup for CU? */
@@ -3290,12 +3284,7 @@ load_partial_comp_unit (struct dwarf2_pe
info_ptr = read_full_die (&reader_specs, &comp_unit_die, info_ptr,
&has_children);
- /* Set the language we're debugging. */
- attr = dwarf2_attr (comp_unit_die, DW_AT_language, cu);
- if (attr)
- set_cu_language (DW_UNSND (attr), cu);
- else
- set_cu_language (language_minimal, cu);
+ prepare_one_comp_unit (cu, comp_unit_die);
/* Check if comp unit has_children.
If so, read the rest of the partial symbols from this comp unit.
@@ -4227,7 +4216,8 @@ load_full_comp_unit (struct dwarf2_per_c
info_ptr = dwarf2_per_objfile->info.buffer + offset;
beg_of_comp_unit = info_ptr;
- cu = alloc_one_comp_unit (objfile);
+ cu = xmalloc (sizeof (*cu));
+ init_one_comp_unit (cu, objfile);
/* If an error occurs while loading, release our storage. */
free_cu_cleanup = make_cleanup (free_one_comp_unit, cu);
@@ -4254,11 +4244,7 @@ load_full_comp_unit (struct dwarf2_per_c
all objfiles needed for references have been loaded yet, and symbol
table processing isn't initialized. But we have to set the CU language,
or we won't be able to build types correctly. */
- attr = dwarf2_attr (cu->dies, DW_AT_language, cu);
- if (attr)
- set_cu_language (DW_UNSND (attr), cu);
- else
- set_cu_language (language_minimal, cu);
+ prepare_one_comp_unit (cu, cu->dies);
/* Similarly, if we do not read the producer, we can not apply
producer-specific interpretation. */
@@ -12617,17 +12603,15 @@ read_signatured_type (struct objfile *ob
struct dwarf2_cu *cu;
ULONGEST signature;
struct cleanup *back_to, *free_cu_cleanup;
- struct attribute *attr;
dwarf2_read_section (objfile, &dwarf2_per_objfile->types);
types_ptr = dwarf2_per_objfile->types.buffer + type_sig->offset;
gdb_assert (type_sig->per_cu.cu == NULL);
- cu = xmalloc (sizeof (struct dwarf2_cu));
- memset (cu, 0, sizeof (struct dwarf2_cu));
- obstack_init (&cu->comp_unit_obstack);
- cu->objfile = objfile;
+ cu = xmalloc (sizeof (*cu));
+ init_one_comp_unit (cu, objfile);
+
type_sig->per_cu.cu = cu;
cu->per_cu = &type_sig->per_cu;
@@ -12659,11 +12643,7 @@ read_signatured_type (struct objfile *ob
all objfiles needed for references have been loaded yet, and symbol
table processing isn't initialized. But we have to set the CU language,
or we won't be able to build types correctly. */
- attr = dwarf2_attr (cu->dies, DW_AT_language, cu);
- if (attr)
- set_cu_language (DW_UNSND (attr), cu);
- else
- set_cu_language (language_minimal, cu);
+ prepare_one_comp_unit (cu, cu->dies);
do_cleanups (back_to);
@@ -13755,15 +13735,29 @@ dwarf2_find_comp_unit (unsigned int offs
return this_cu;
}
-/* Malloc space for a dwarf2_cu for OBJFILE and initialize it. */
+/* Initialize dwarf2_cu CU for OBJFILE in a pre-allocated space. */
-static struct dwarf2_cu *
-alloc_one_comp_unit (struct objfile *objfile)
+static void
+init_one_comp_unit (struct dwarf2_cu *cu, struct objfile *objfile)
{
- struct dwarf2_cu *cu = xcalloc (1, sizeof (struct dwarf2_cu));
+ memset (cu, 0, sizeof (*cu));
cu->objfile = objfile;
obstack_init (&cu->comp_unit_obstack);
- return cu;
+}
+
+/* Initiailize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
+
+static void
+prepare_one_comp_unit (struct dwarf2_cu *cu, struct die_info *comp_unit_die)
+{
+ struct attribute *attr;
+
+ /* Set the language we're debugging. */
+ attr = dwarf2_attr (comp_unit_die, DW_AT_language, cu);
+ if (attr)
+ set_cu_language (DW_UNSND (attr), cu);
+ else
+ set_cu_language (language_minimal, cu);
}
/* Release one cached compilation unit, CU. We unlink it from the tree