This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[commit] Fix inter-compilation-unit crash in the dwarf2 reader


My recent patch to always use the full DIE reader for compilation unit
DIEs had a merge bug.  We have to set cu->per_cu before calling
init_cu_die_reader, or it will crash; and in some cases we weren't
doing so early enough.

I've tested this patch on arm-none-eabi and x86_64-linux, and checked
it in.  The process_psymtab_comp_unit is not strictly required, but
the way I left the code after my previous patch was ugly; the two
pointers are logically related, and should be initialized at the same
time.

2009-11-12  Daniel Jacobowitz  <dan@codesourcery.com>

	* dwarf2read.c (process_psymtab_comp_unit): Initialize per_cu backlink
	at the same time as the forward link.
	(load_partial_comp_unit): Initialize per_cu links before calling
	init_cu_die_reader.

---
 gdb/dwarf2read.c |   39 +++++++++++++++++++--------------------
 1 file changed, 19 insertions(+), 20 deletions(-)

Index: gdb-mainline/gdb/dwarf2read.c
===================================================================
--- gdb-mainline.orig/gdb/dwarf2read.c	2009-11-05 17:10:08.000000000 -0800
+++ gdb-mainline/gdb/dwarf2read.c	2009-11-11 06:47:04.000000000 -0800
@@ -1887,6 +1887,20 @@ process_psymtab_comp_unit (struct objfil
 
   cu.list_in_scope = &file_symbols;
 
+  /* If this compilation unit was already read in, free the
+     cached copy in order to read it in again.	This is
+     necessary because we skipped some symbols when we first
+     read in the compilation unit (see load_partial_dies).
+     This problem could be avoided, but the benefit is
+     unclear.  */
+  if (this_cu->cu != NULL)
+    free_one_cached_comp_unit (this_cu->cu);
+
+  /* Note that this is a pointer to our stack frame, being
+     added to a global data structure.	It will be cleaned up
+     in free_stack_comp_unit when we finish with this
+     compilation unit.	*/
+  this_cu->cu = &cu;
   cu.per_cu = this_cu;
 
   /* Read the abbrevs for this compilation unit into a table.  */
@@ -1941,21 +1955,6 @@ process_psymtab_comp_unit (struct objfil
   /* Store the function that reads in the rest of the symbol table */
   pst->read_symtab = dwarf2_psymtab_to_symtab;
 
-  /* If this compilation unit was already read in, free the
-     cached copy in order to read it in again.	This is
-     necessary because we skipped some symbols when we first
-     read in the compilation unit (see load_partial_dies).
-     This problem could be avoided, but the benefit is
-     unclear.  */
-  if (this_cu->cu != NULL)
-    free_one_cached_comp_unit (this_cu->cu);
-
-  /* Note that this is a pointer to our stack frame, being
-     added to a global data structure.	It will be cleaned up
-     in free_stack_comp_unit when we finish with this
-     compilation unit.	*/
-  this_cu->cu = &cu;
-
   this_cu->psymtab = pst;
 
   dwarf2_find_base_address (comp_unit_die, &cu);
@@ -2153,6 +2152,11 @@ load_partial_comp_unit (struct dwarf2_pe
 
   /* ??? Missing cleanup for CU?  */
 
+  /* Link this compilation unit into the compilation unit tree.  */
+  this_cu->cu = cu;
+  cu->per_cu = this_cu;
+  cu->type_hash = this_cu->type_hash;
+
   info_ptr = partial_read_comp_unit_head (&cu->header, info_ptr,
 					  dwarf2_per_objfile->info.buffer,
 					  dwarf2_per_objfile->info.size,
@@ -2178,11 +2182,6 @@ load_partial_comp_unit (struct dwarf2_pe
   else
     set_cu_language (language_minimal, cu);
 
-  /* Link this compilation unit into the compilation unit tree.  */
-  this_cu->cu = cu;
-  cu->per_cu = this_cu;
-  cu->type_hash = this_cu->type_hash;
-
   /* Check if comp unit has_children.
      If so, read the rest of the partial symbols from this comp unit.
      If not, there's no more debug_info for this comp unit. */

-- 
Daniel Jacobowitz
CodeSourcery


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]