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]

Re: [RFA] dwarf2read.c: fix computing list of included symtabs


Tom Tromey writes:
 > >>>>> "Doug" == Doug Evans <dje@google.com> writes:
 > 
 > Doug> My workaround for http://sourceware.org/bugzilla/show_bug.cgi?id=15021
 > Doug> doesn't take into account the fact that TUs can share symtabs.
 > Doug> This results in duplicate copies of symtabs in symtab->includes.
 > 
 > Doug> Regression tested on amd64-linux with/without fission, and with dwz.
 > 
 > Doug> Ok to check in?
 > 
 > Doug> 2013-06-15  Doug Evans  <dje@google.com>
 > 
 > Doug> 	* dwarf2read.c (recursively_compute_inclusions): Change type of
 > Doug> 	result parameter to VEC (symtab_ptr) **.  New parameter all_type_symtabs.
 > Doug> 	Watch for duplicate symtabs coming from type units.
 > Doug> 	(compute_symtab_includes): Update call to recursively_compute_inclusions.
 > Doug> 	Build vector of included symtabs instead of per_cus.
 > Doug> 	* symtab.h (symtab_ptr): New typedef.
 > Doug> 	(DEF_VEC_P (symtab_ptr)): New VEC type.
 > 
 > Looks good to me.
 > 
 > Tom

Here is what I checked in.

2013-08-01  Doug Evans  <dje@google.com>

	Further workarounds for binutils/15021.
	* dwarf2read.c (recursively_compute_inclusions): Change type of result
	parameter to VEC (symtab_ptr) **.  New parameter all_type_symtabs.
	Watch for duplicate symtabs coming from type units.
	(compute_symtab_includes): Update call to
	recursively_compute_inclusions. Build vector of included symtabs
	instead of per_cus.
	* symtab.h (symtab_ptr): New typedef.
	(DEF_VEC_P (symtab_ptr)): New VEC type.
	* linespec.c (symtab_p): Delete.  All uses updated to use symtab_ptr
	instead.

Index: dwarf2read.c
===================================================================
RCS file: /cvs/src/src/gdb/dwarf2read.c,v
retrieving revision 1.819
diff -u -p -r1.819 dwarf2read.c
--- dwarf2read.c	31 Jul 2013 00:30:18 -0000	1.819
+++ dwarf2read.c	1 Aug 2013 23:29:29 -0000
@@ -7354,12 +7354,13 @@ get_symtab (struct dwarf2_per_cu_data *p
    included by PER_CU.  */
 
 static void
-recursively_compute_inclusions (VEC (dwarf2_per_cu_ptr) **result,
-				htab_t all_children,
+recursively_compute_inclusions (VEC (symtab_ptr) **result,
+				htab_t all_children, htab_t all_type_symtabs,
 				struct dwarf2_per_cu_data *per_cu)
 {
   void **slot;
   int ix;
+  struct symtab *symtab;
   struct dwarf2_per_cu_data *iter;
 
   slot = htab_find_slot (all_children, per_cu, INSERT);
@@ -7371,13 +7372,31 @@ recursively_compute_inclusions (VEC (dwa
 
   *slot = per_cu;
   /* Only add a CU if it has a symbol table.  */
-  if (get_symtab (per_cu) != NULL)
-    VEC_safe_push (dwarf2_per_cu_ptr, *result, per_cu);
+  symtab = get_symtab (per_cu);
+  if (symtab != NULL)
+    {
+      /* If this is a type unit only add its symbol table if we haven't
+	 seen it yet (type unit per_cu's can share symtabs).  */
+      if (per_cu->is_debug_types)
+	{
+	  slot = htab_find_slot (all_type_symtabs, symtab, INSERT);
+	  if (*slot == NULL)
+	    {
+	      *slot = symtab;
+	      VEC_safe_push (symtab_ptr, *result, symtab);
+	    }
+	}
+      else
+	VEC_safe_push (symtab_ptr, *result, symtab);
+    }
 
   for (ix = 0;
        VEC_iterate (dwarf2_per_cu_ptr, per_cu->imported_symtabs, ix, iter);
        ++ix)
-    recursively_compute_inclusions (result, all_children, iter);
+    {
+      recursively_compute_inclusions (result, all_children,
+				      all_type_symtabs, iter);
+    }
 }
 
 /* Compute the symtab 'includes' fields for the symtab related to
@@ -7391,9 +7410,10 @@ compute_symtab_includes (struct dwarf2_p
   if (!VEC_empty (dwarf2_per_cu_ptr, per_cu->imported_symtabs))
     {
       int ix, len;
-      struct dwarf2_per_cu_data *iter;
-      VEC (dwarf2_per_cu_ptr) *result_children = NULL;
-      htab_t all_children;
+      struct dwarf2_per_cu_data *per_cu_iter;
+      struct symtab *symtab_iter;
+      VEC (symtab_ptr) *result_symtabs = NULL;
+      htab_t all_children, all_type_symtabs;
       struct symtab *symtab = get_symtab (per_cu);
 
       /* If we don't have a symtab, we can just skip this case.  */
@@ -7402,28 +7422,32 @@ compute_symtab_includes (struct dwarf2_p
 
       all_children = htab_create_alloc (1, htab_hash_pointer, htab_eq_pointer,
 					NULL, xcalloc, xfree);
+      all_type_symtabs = htab_create_alloc (1, htab_hash_pointer, htab_eq_pointer,
+					    NULL, xcalloc, xfree);
 
       for (ix = 0;
 	   VEC_iterate (dwarf2_per_cu_ptr, per_cu->imported_symtabs,
-			ix, iter);
+			ix, per_cu_iter);
 	   ++ix)
-	recursively_compute_inclusions (&result_children, all_children, iter);
+	{
+	  recursively_compute_inclusions (&result_symtabs, all_children,
+					  all_type_symtabs, per_cu_iter);
+	}
 
-      /* Now we have a transitive closure of all the included CUs, and
-	 for .gdb_index version 7 the included TUs, so we can convert it
-	 to a list of symtabs.  */
-      len = VEC_length (dwarf2_per_cu_ptr, result_children);
+      /* Now we have a transitive closure of all the included symtabs.  */
+      len = VEC_length (symtab_ptr, result_symtabs);
       symtab->includes
 	= obstack_alloc (&dwarf2_per_objfile->objfile->objfile_obstack,
 			 (len + 1) * sizeof (struct symtab *));
       for (ix = 0;
-	   VEC_iterate (dwarf2_per_cu_ptr, result_children, ix, iter);
+	   VEC_iterate (symtab_ptr, result_symtabs, ix, symtab_iter);
 	   ++ix)
-	symtab->includes[ix] = get_symtab (iter);
+	symtab->includes[ix] = symtab_iter;
       symtab->includes[len] = NULL;
 
-      VEC_free (dwarf2_per_cu_ptr, result_children);
+      VEC_free (symtab_ptr, result_symtabs);
       htab_delete (all_children);
+      htab_delete (all_type_symtabs);
     }
 }
 
Index: linespec.c
===================================================================
RCS file: /cvs/src/src/gdb/linespec.c,v
retrieving revision 1.185
diff -u -p -r1.185 linespec.c
--- linespec.c	30 May 2013 16:57:38 -0000	1.185
+++ linespec.c	1 Aug 2013 23:29:29 -0000
@@ -45,9 +45,6 @@
 #include "ada-lang.h"
 #include "stack.h"
 
-typedef struct symtab *symtab_p;
-DEF_VEC_P (symtab_p);
-
 typedef struct symbol *symbolp;
 DEF_VEC_P (symbolp);
 
@@ -124,7 +121,7 @@ struct linespec
      be NULL.  If SOURCE_FILENAME is NULL (no user-specified filename),
      FILE_SYMTABS should contain one single NULL member.  This will
      cause the code to use the default symtab.  */
-  VEC (symtab_p) *file_symtabs;
+  VEC (symtab_ptr) *file_symtabs;
 
   /* The name of a function or method and any matching symbols.  */
 
@@ -217,7 +214,7 @@ struct collect_info
   struct linespec_state *state;
 
   /* A list of symtabs to which to restrict matches.  */
-  VEC (symtab_p) *file_symtabs;
+  VEC (symtab_ptr) *file_symtabs;
 
   /* The result being accumulated.  */
   struct
@@ -332,7 +329,7 @@ static struct symtabs_and_lines decode_o
 					     linespec_p ls,
 					     char **argptr);
 
-static VEC (symtab_p) *symtabs_from_filename (const char *);
+static VEC (symtab_ptr) *symtabs_from_filename (const char *);
 
 static VEC (symbolp) *find_label_symbols (struct linespec_state *self,
 					  VEC (symbolp) *function_symbols,
@@ -340,7 +337,7 @@ static VEC (symbolp) *find_label_symbols
 					  const char *name);
 
 static void find_linespec_symbols (struct linespec_state *self,
-				   VEC (symtab_p) *file_symtabs,
+				   VEC (symtab_ptr) *file_symtabs,
 				   const char *name,
 				   VEC (symbolp) **symbols,
 				   VEC (minsym_and_objfile_d) **minsyms);
@@ -360,7 +357,7 @@ static void add_all_symbol_names_from_ps
 					      struct program_space *pspace,
 					      VEC (const_char_ptr) *names);
 
-static VEC (symtab_p) *collect_symtabs_from_filename (const char *file);
+static VEC (symtab_ptr) *collect_symtabs_from_filename (const char *file);
 
 static void decode_digits_ordinary (struct linespec_state *self,
 				    linespec_p ls,
@@ -1841,8 +1838,8 @@ create_sals_line_offset (struct linespec
      set_default_source_symtab_and_line uses
      select_source_symtab that calls us with such an argument.  */
 
-  if (VEC_length (symtab_p, ls->file_symtabs) == 1
-      && VEC_index (symtab_p, ls->file_symtabs, 0) == NULL)
+  if (VEC_length (symtab_ptr, ls->file_symtabs) == 1
+      && VEC_index (symtab_ptr, ls->file_symtabs, 0) == NULL)
     {
       const char *fullname;
 
@@ -1852,8 +1849,8 @@ create_sals_line_offset (struct linespec
       set_default_source_symtab_and_line ();
       initialize_defaults (&self->default_symtab, &self->default_line);
       fullname = symtab_to_fullname (self->default_symtab);
-      VEC_pop (symtab_p, ls->file_symtabs);
-      VEC_free (symtab_p, ls->file_symtabs);
+      VEC_pop (symtab_ptr, ls->file_symtabs);
+      VEC_free (symtab_ptr, ls->file_symtabs);
       ls->file_symtabs = collect_symtabs_from_filename (fullname);
       use_default = 1;
     }
@@ -2214,7 +2211,7 @@ parse_linespec (linespec_parser *parser,
       char *var;
 
       /* A NULL entry means to use GLOBAL_DEFAULT_SYMTAB.  */
-      VEC_safe_push (symtab_p, PARSER_RESULT (parser)->file_symtabs, NULL);
+      VEC_safe_push (symtab_ptr, PARSER_RESULT (parser)->file_symtabs, NULL);
 
       /* User specified a convenience variable or history value.  */
       var = copy_token_string (token);
@@ -2275,7 +2272,7 @@ parse_linespec (linespec_parser *parser,
 	  xfree (user_filename);
 
 	  /* A NULL entry means to use GLOBAL_DEFAULT_SYMTAB.  */
-	  VEC_safe_push (symtab_p, PARSER_RESULT (parser)->file_symtabs, NULL);
+	  VEC_safe_push (symtab_ptr, PARSER_RESULT (parser)->file_symtabs, NULL);
 	}
     }
   /* If the next token is not EOI, KEYWORD, or COMMA, issue an error.  */
@@ -2290,7 +2287,7 @@ parse_linespec (linespec_parser *parser,
   else
     {
       /* A NULL entry means to use GLOBAL_DEFAULT_SYMTAB.  */
-      VEC_safe_push (symtab_p, PARSER_RESULT (parser)->file_symtabs, NULL);
+      VEC_safe_push (symtab_ptr, PARSER_RESULT (parser)->file_symtabs, NULL);
     }
 
   /* Parse the rest of the linespec.  */
@@ -2385,7 +2382,7 @@ linespec_parser_delete (void *arg)
   xfree ((char *) PARSER_RESULT (parser)->function_name);
 
   if (PARSER_RESULT (parser)->file_symtabs != NULL)
-    VEC_free (symtab_p, PARSER_RESULT (parser)->file_symtabs);
+    VEC_free (symtab_ptr, PARSER_RESULT (parser)->file_symtabs);
 
   if (PARSER_RESULT (parser)->function_symbols != NULL)
     VEC_free (symbolp, PARSER_RESULT (parser)->function_symbols);
@@ -2603,8 +2600,8 @@ decode_objc (struct linespec_state *self
 
   info.state = self;
   info.file_symtabs = NULL;
-  VEC_safe_push (symtab_p, info.file_symtabs, NULL);
-  make_cleanup (VEC_cleanup (symtab_p), &info.file_symtabs);
+  VEC_safe_push (symtab_ptr, info.file_symtabs, NULL);
+  make_cleanup (VEC_cleanup (symtab_ptr), &info.file_symtabs);
   info.result.symbols = NULL;
   info.result.minimal_symbols = NULL;
   values.nelts = 0;
@@ -2697,7 +2694,7 @@ collect_one_symbol (struct symbol *sym, 
 /* Return any symbols corresponding to CLASS_NAME in FILE_SYMTABS.  */
 
 static VEC (symbolp) *
-lookup_prefix_sym (struct linespec_state *state, VEC (symtab_p) *file_symtabs,
+lookup_prefix_sym (struct linespec_state *state, VEC (symtab_ptr) *file_symtabs,
 		   const char *class_name)
 {
   int ix;
@@ -2714,7 +2711,7 @@ lookup_prefix_sym (struct linespec_state
 					     xcalloc, xfree);
   cleanup = make_cleanup_htab_delete (collector.unique_syms);
 
-  for (ix = 0; VEC_iterate (symtab_p, file_symtabs, ix, elt); ++ix)
+  for (ix = 0; VEC_iterate (symtab_ptr, file_symtabs, ix, elt); ++ix)
     {
       if (elt == NULL)
 	{
@@ -2853,7 +2850,7 @@ find_superclass_methods (VEC (typep) *su
    in SYMBOLS (for debug symbols) and MINSYMS (for minimal symbols).  */
 
 static void
-find_method (struct linespec_state *self, VEC (symtab_p) *file_symtabs,
+find_method (struct linespec_state *self, VEC (symtab_ptr) *file_symtabs,
 	     const char *class_name, const char *method_name,
 	     VEC (symbolp) *sym_classes, VEC (symbolp) **symbols,
 	     VEC (minsym_and_objfile_d) **minsyms)
@@ -2949,7 +2946,7 @@ find_method (struct linespec_state *self
 struct symtab_collector
 {
   /* The result vector of symtabs.  */
-  VEC (symtab_p) *symtabs;
+  VEC (symtab_ptr) *symtabs;
 
   /* This is used to ensure the symtabs are unique.  */
   htab_t symtab_table;
@@ -2967,7 +2964,7 @@ add_symtabs_to_list (struct symtab *symt
   if (!*slot)
     {
       *slot = symtab;
-      VEC_safe_push (symtab_p, data->symtabs, symtab);
+      VEC_safe_push (symtab_ptr, data->symtabs, symtab);
     }
 
   return 0;
@@ -2975,7 +2972,7 @@ add_symtabs_to_list (struct symtab *symt
 
 /* Given a file name, return a VEC of all matching symtabs.  */
 
-static VEC (symtab_p) *
+static VEC (symtab_ptr) *
 collect_symtabs_from_filename (const char *file)
 {
   struct symtab_collector collector;
@@ -3003,14 +3000,14 @@ collect_symtabs_from_filename (const cha
 
 /* Return all the symtabs associated to the FILENAME.  */
 
-static VEC (symtab_p) *
+static VEC (symtab_ptr) *
 symtabs_from_filename (const char *filename)
 {
-  VEC (symtab_p) *result;
+  VEC (symtab_ptr) *result;
   
   result = collect_symtabs_from_filename (filename);
 
-  if (VEC_empty (symtab_p, result))
+  if (VEC_empty (symtab_ptr, result))
     {
       if (!have_full_symbols () && !have_partial_symbols ())
 	throw_error (NOT_FOUND_ERROR,
@@ -3028,7 +3025,7 @@ symtabs_from_filename (const char *filen
 
 static void
 find_function_symbols (struct linespec_state *state,
-		       VEC (symtab_p) *file_symtabs, const char *name,
+		       VEC (symtab_ptr) *file_symtabs, const char *name,
 		       VEC (symbolp) **symbols,
 		       VEC (minsym_and_objfile_d) **minsyms)
 {
@@ -3073,7 +3070,7 @@ find_function_symbols (struct linespec_s
 
 static void
 find_linespec_symbols (struct linespec_state *state,
-		       VEC (symtab_p) *file_symtabs,
+		       VEC (symtab_ptr) *file_symtabs,
 		       const char *name,
 		       VEC (symbolp) **symbols,
 		       VEC (minsym_and_objfile_d) **minsyms)
@@ -3255,7 +3252,7 @@ decode_digits_list_mode (struct linespec
 
   gdb_assert (self->list_mode);
 
-  for (ix = 0; VEC_iterate (symtab_p, ls->file_symtabs, ix, elt);
+  for (ix = 0; VEC_iterate (symtab_ptr, ls->file_symtabs, ix, elt);
        ++ix)
     {
       /* The logic above should ensure this.  */
@@ -3288,7 +3285,7 @@ decode_digits_ordinary (struct linespec_
   int ix;
   struct symtab *elt;
 
-  for (ix = 0; VEC_iterate (symtab_p, ls->file_symtabs, ix, elt); ++ix)
+  for (ix = 0; VEC_iterate (symtab_ptr, ls->file_symtabs, ix, elt); ++ix)
     {
       int i;
       VEC (CORE_ADDR) *pcs;
@@ -3591,7 +3588,7 @@ add_matching_symbols_to_info (const char
   int ix;
   struct symtab *elt;
 
-  for (ix = 0; VEC_iterate (symtab_p, info->file_symtabs, ix, elt); ++ix)
+  for (ix = 0; VEC_iterate (symtab_ptr, info->file_symtabs, ix, elt); ++ix)
     {
       if (elt == NULL)
 	{
Index: symtab.h
===================================================================
RCS file: /cvs/src/src/gdb/symtab.h,v
retrieving revision 1.235
diff -u -p -r1.235 symtab.h
--- symtab.h	12 Apr 2013 14:49:25 -0000	1.235
+++ symtab.h	1 Aug 2013 23:29:29 -0000
@@ -936,6 +936,10 @@ struct symtab
 #define BLOCKVECTOR(symtab)	(symtab)->blockvector
 #define LINETABLE(symtab)	(symtab)->linetable
 #define SYMTAB_PSPACE(symtab)	(symtab)->objfile->pspace
+
+typedef struct symtab *symtab_ptr;
+DEF_VEC_P (symtab_ptr);
+
 
 
 /* The virtual function table is now an array of structures which have the


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