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] dwarf2read.c: Handle missing DWO file more gracefully.


Hi.
GDB will throw an error if a Fission stub DIE refers to a missing DWO file.
This can happen, for example, if a DWP file is built without all the
associated DWO files.  It should handle this more gracefully
which this patch does.

This patch also stops gdb for looking for the DWO file in the,
for example, build tree if it can't find it in the DWP file.

Committed.

Testcase to follow once I figure out if/how I can use the dwarf assembler
for this.

2013-04-30  Doug Evans  <dje@google.com>

	* dwarf2read.c (lookup_dwo_unit): Return NULL if DWO not found.
	(init_cutu_and_read_dies): Flag a complaint, not error, for bad
	DWO stub.  If DWO isn't found, just use stub.
	(lookup_dwo_cutu): Don't try DWO if there's a DWP file.

Index: dwarf2read.c
===================================================================
RCS file: /cvs/src/src/gdb/dwarf2read.c,v
retrieving revision 1.792
diff -u -p -r1.792 dwarf2read.c
--- dwarf2read.c	30 Apr 2013 21:11:50 -0000	1.792
+++ dwarf2read.c	30 Apr 2013 22:07:40 -0000
@@ -4605,7 +4605,7 @@ read_cutu_die_from_dwo (struct dwarf2_pe
 
 /* Subroutine of init_cutu_and_read_dies to simplify it.
    Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
-   If the specified DWO unit cannot be found an error is thrown.  */
+   Returns NULL if the specified DWO unit cannot be found.  */
 
 static struct dwo_unit *
 lookup_dwo_unit (struct dwarf2_per_cu_data *this_cu,
@@ -4650,14 +4650,6 @@ lookup_dwo_unit (struct dwarf2_per_cu_da
 				       signature);
     }
 
-  if (dwo_unit == NULL)
-    {
-      error (_("Dwarf Error: CU at offset 0x%x references unknown DWO"
-	       " with ID %s [in module %s]"),
-	     this_cu->offset.sect_off, hex_string (signature),
-	     this_cu->objfile->name);
-    }
-
   return dwo_unit;
 }
 
@@ -4834,21 +4826,35 @@ init_cutu_and_read_dies (struct dwarf2_p
       struct die_info *dwo_comp_unit_die;
 
       if (has_children)
-	error (_("Dwarf Error: compilation unit with DW_AT_GNU_dwo_name"
-		 " has children (offset 0x%x) [in module %s]"),
-	       this_cu->offset.sect_off, bfd_get_filename (abfd));
+	{
+	  complaint (&symfile_complaints,
+		     _("Dwarf Error: compilation unit with DW_AT_GNU_dwo_name"
+		       " has children (offset 0x%x) [in module %s]"),
+		     this_cu->offset.sect_off, bfd_get_filename (abfd));
+	}
       dwo_unit = lookup_dwo_unit (this_cu, comp_unit_die);
-      if (read_cutu_die_from_dwo (this_cu, dwo_unit,
-				  abbrev_table != NULL,
-				  comp_unit_die,
-				  &reader, &info_ptr,
-				  &dwo_comp_unit_die, &has_children) == 0)
+      if (dwo_unit != NULL)
 	{
-	  /* Dummy die.  */
-	  do_cleanups (cleanups);
-	  return;
+	  if (read_cutu_die_from_dwo (this_cu, dwo_unit,
+				      abbrev_table != NULL,
+				      comp_unit_die,
+				      &reader, &info_ptr,
+				      &dwo_comp_unit_die, &has_children) == 0)
+	    {
+	      /* Dummy die.  */
+	      do_cleanups (cleanups);
+	      return;
+	    }
+	  comp_unit_die = dwo_comp_unit_die;
+	}
+      else
+	{
+	  /* Yikes, we couldn't find the rest of the DIE, we only have
+	     the stub.  A complaint has already been logged.  There's
+	     not much more we can do except pass on the stub DIE to
+	     die_reader_func.  We don't want to throw an error on bad
+	     debug info.  */
 	}
-      comp_unit_die = dwo_comp_unit_die;
     }
 
   /* All of the above is setup for this call.  Yikes.  */
@@ -9294,7 +9300,10 @@ lookup_dwo_cutu (struct dwarf2_per_cu_da
   struct dwo_file *dwo_file;
   struct dwp_file *dwp_file;
 
-  /* Have we already read SIGNATURE from a DWP file?  */
+  /* First see if there's a DWP file.
+     If we have a DWP file but didn't find the DWO inside it, don't
+     look for the original DWO file.  It makes gdb behave differently
+     depending on whether one is debugging in the build tree.  */
 
   dwp_file = get_dwp_file ();
   if (dwp_file != NULL)
@@ -9321,45 +9330,47 @@ lookup_dwo_cutu (struct dwarf2_per_cu_da
 	    }
 	}
     }
-
-  /* Have we already seen DWO_NAME?  */
-
-  dwo_file_slot = lookup_dwo_file_slot (dwo_name, comp_dir);
-  if (*dwo_file_slot == NULL)
-    {
-      /* Read in the file and build a table of the DWOs it contains.  */
-      *dwo_file_slot = open_and_init_dwo_file (this_unit, dwo_name, comp_dir);
-    }
-  /* NOTE: This will be NULL if unable to open the file.  */
-  dwo_file = *dwo_file_slot;
-
-  if (dwo_file != NULL)
+  else
     {
-      struct dwo_unit *dwo_cutu = NULL;
+      /* No DWP file, look for the DWO file.  */
 
-      if (is_debug_types && dwo_file->tus)
+      dwo_file_slot = lookup_dwo_file_slot (dwo_name, comp_dir);
+      if (*dwo_file_slot == NULL)
 	{
-	  struct dwo_unit find_dwo_cutu;
-
-	  memset (&find_dwo_cutu, 0, sizeof (find_dwo_cutu));
-	  find_dwo_cutu.signature = signature;
-	  dwo_cutu = htab_find (dwo_file->tus, &find_dwo_cutu);
-	}
-      else if (!is_debug_types && dwo_file->cu)
-	{
-	  if (signature == dwo_file->cu->signature)
-	    dwo_cutu = dwo_file->cu;
+	  /* Read in the file and build a table of the CUs/TUs it contains.  */
+	  *dwo_file_slot = open_and_init_dwo_file (this_unit, dwo_name, comp_dir);
 	}
+      /* NOTE: This will be NULL if unable to open the file.  */
+      dwo_file = *dwo_file_slot;
 
-      if (dwo_cutu != NULL)
+      if (dwo_file != NULL)
 	{
-	  if (dwarf2_read_debug)
+	  struct dwo_unit *dwo_cutu = NULL;
+
+	  if (is_debug_types && dwo_file->tus)
+	    {
+	      struct dwo_unit find_dwo_cutu;
+
+	      memset (&find_dwo_cutu, 0, sizeof (find_dwo_cutu));
+	      find_dwo_cutu.signature = signature;
+	      dwo_cutu = htab_find (dwo_file->tus, &find_dwo_cutu);
+	    }
+	  else if (!is_debug_types && dwo_file->cu)
 	    {
-	      fprintf_unfiltered (gdb_stdlog, "DWO %s %s(%s) found: @%s\n",
-				  kind, dwo_name, hex_string (signature),
-				  host_address_to_string (dwo_cutu));
+	      if (signature == dwo_file->cu->signature)
+		dwo_cutu = dwo_file->cu;
+	    }
+
+	  if (dwo_cutu != NULL)
+	    {
+	      if (dwarf2_read_debug)
+		{
+		  fprintf_unfiltered (gdb_stdlog, "DWO %s %s(%s) found: @%s\n",
+				      kind, dwo_name, hex_string (signature),
+				      host_address_to_string (dwo_cutu));
+		}
+	      return dwo_cutu;
 	    }
-	  return dwo_cutu;
 	}
     }
 
@@ -9374,9 +9385,10 @@ lookup_dwo_cutu (struct dwarf2_per_cu_da
     }
 
   complaint (&symfile_complaints,
-	     _("Could not find DWO %s referenced by CU at offset 0x%x"
+	     _("Could not find DWO %s %s(%s) referenced by CU at offset 0x%x"
 	       " [in module %s]"),
-	     kind, this_unit->offset.sect_off, objfile->name);
+	     kind, dwo_name, hex_string (signature),
+	     this_unit->offset.sect_off, objfile->name);
   return NULL;
 }
 


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