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]

[RFA] buildsym.c cleanup


Hi.
While working on making reading of debug info more interruptible
I came across a bit of cleanup that can be done first.
This patch removes some publically used globals and either moves
them into buildsym.c or into their respective debug info readers.

Regression tested on amd64-linux, and a second time with -gstabs.
I didn't check coff though, however the change is mechanical.

Can someone test this on coff, or is this ok to check in now?

[I think there's more that can be done here,
but I think this can go in now.]

2013-05-14  Doug Evans  <dje@google.com>

	* buildsym.c (subfile_stack): Move here from buildsym.h.
	(pending_macros): Ditto.
	(get_macro_table): New function.
	(buildsym_init): Initialize subfile_stack.
	* coffread.c (type_vector,type_vector_length): Moved here from
	buildsym.h.
	(INITIAL_TYPE_VECTOR_LENGTH): Ditto.
	(coff_symtab_read): Use it.
	* dbxread.c (read_ofile_symtab): Delete init of subfile_stack.
	* dwarf2read.c (macro_start_file): Replace uses of pending_macros
	with call to get_macro_table.
	* stabsread.c (type_vector,type_vector_length): Moved here from
	buildsym.h.
	(INITIAL_TYPE_VECTOR_LENGTH): Ditto.
	* buildsym.h (get_macro_table): Declare.

Index: buildsym.c
===================================================================
RCS file: /cvs/src/src/gdb/buildsym.c,v
retrieving revision 1.108
diff -u -p -r1.108 buildsym.c
--- buildsym.c	1 Apr 2013 12:48:03 -0000	1.108
+++ buildsym.c	14 May 2013 15:38:50 -0000
@@ -102,13 +102,24 @@ struct pending_block
    associated symtab.  */
 
 static struct pending_block *pending_blocks;
-
+
+struct subfile_stack
+  {
+    struct subfile_stack *next;
+    char *name;
+  };
+
+static struct subfile_stack *subfile_stack;
+
+/* The macro table for the compilation unit whose symbols we're
+   currently reading.  All the symtabs for the CU will point to this.  */
+static struct macro_table *pending_macros;
+
 static int compare_line_numbers (const void *ln1p, const void *ln2p);
 
 static void record_pending_block (struct objfile *objfile,
 				  struct block *block,
 				  struct pending_block *opblock);
-
 
 /* Initial sizes of data structures.  These are realloc'd larger if
    needed, and realloc'd down to the size actually used, when
@@ -825,6 +836,19 @@ compare_line_numbers (const void *ln1p, 
   return ln1->line - ln2->line;
 }
 
+/* Return the macro table.
+   Initialize it if this is the first use.  */
+
+struct macro_table *
+get_macro_table (struct objfile *objfile, const char *comp_dir)
+{
+  if (! pending_macros)
+    pending_macros = new_macro_table (&objfile->per_bfd->storage_obstack,
+				      objfile->per_bfd->macro_cache,
+				      comp_dir);
+  return pending_macros;
+}
+
 /* Start a new symtab for a new source file.  Called, for example,
    when a stabs symbol of type N_SO is seen, or when a DWARF
    TAG_compile_unit DIE is seen.  It indicates the start of data for
@@ -1538,6 +1562,7 @@ buildsym_init (void)
   pending_blocks = NULL;
   pending_macros = NULL;
   using_directives = NULL;
+  subfile_stack = NULL;
 
   /* We shouldn't have any address map at this point.  */
   gdb_assert (! pending_addrmap);
Index: buildsym.h
===================================================================
RCS file: /cvs/src/src/gdb/buildsym.h,v
retrieving revision 1.39
diff -u -p -r1.39 buildsym.h
--- buildsym.h	21 Jan 2013 18:05:13 -0000	1.39
+++ buildsym.h	14 May 2013 15:38:50 -0000
@@ -173,37 +173,12 @@ EXTERN int within_function;
 
 
 
-struct subfile_stack
-  {
-    struct subfile_stack *next;
-    char *name;
-  };
-
-EXTERN struct subfile_stack *subfile_stack;
-
 #define next_symbol_text(objfile) (*next_symbol_text_func)(objfile)
 
 /* Function to invoke get the next symbol.  Return the symbol name.  */
 
 EXTERN char *(*next_symbol_text_func) (struct objfile *);
 
-/* Vector of types defined so far, indexed by their type numbers.
-   Used for both stabs and coff.  (In newer sun systems, dbx uses a
-   pair of numbers in parens, as in "(SUBFILENUM,NUMWITHINSUBFILE)".
-   Then these numbers must be translated through the type_translations
-   hash table to get the index into the type vector.)  */
-
-EXTERN struct type **type_vector;
-
-/* Number of elements allocated for type_vector currently.  */
-
-EXTERN int type_vector_length;
-
-/* Initial size of type vector.  Is realloc'd larger if needed, and
-   realloc'd down to the size actually used, when completed.  */
-
-#define	INITIAL_TYPE_VECTOR_LENGTH	160
-
 extern void add_symbol_to_list (struct symbol *symbol,
 				struct pending **listhead);
 
@@ -296,10 +271,10 @@ extern void set_last_source_file (const 
 
 extern const char *get_last_source_file (void);
 
-/* The macro table for the compilation unit whose symbols we're
-   currently reading.  All the symtabs for this CU will point to
-   this.  */
-EXTERN struct macro_table *pending_macros;
+/* Return the macro table.  */
+
+extern struct macro_table *get_macro_table (struct objfile *objfile,
+					    const char *comp_dir);
 
 #undef EXTERN
 
Index: coffread.c
===================================================================
RCS file: /cvs/src/src/gdb/coffread.c,v
retrieving revision 1.145
diff -u -p -r1.145 coffread.c
--- coffread.c	8 Apr 2013 20:13:21 -0000	1.145
+++ coffread.c	14 May 2013 15:59:02 -0000
@@ -146,6 +146,19 @@ struct coff_symbol
     unsigned int c_type;
   };
 
+/* Vector of types defined so far, indexed by their type numbers.  */
+
+static struct type **type_vector;
+
+/* Number of elements allocated for type_vector currently.  */
+
+static int type_vector_length;
+
+/* Initial size of type vector.  Is realloc'd larger if needed, and
+   realloc'd down to the size actually used, when completed.  */
+
+#define INITIAL_TYPE_VECTOR_LENGTH 160
+
 extern void stabsread_clear_cache (void);
 
 static struct type *coff_read_struct_type (int, int, int,
@@ -787,7 +800,7 @@ coff_symtab_read (long symtab_offset, un
 
   if (type_vector)		/* Get rid of previous one.  */
     xfree (type_vector);
-  type_vector_length = 160;
+  type_vector_length = INITIAL_TYPE_VECTOR_LENGTH;
   type_vector = (struct type **)
     xmalloc (type_vector_length * sizeof (struct type *));
   memset (type_vector, 0, type_vector_length * sizeof (struct type *));
Index: dbxread.c
===================================================================
RCS file: /cvs/src/src/gdb/dbxread.c,v
retrieving revision 1.146
diff -u -p -r1.146 dbxread.c
--- dbxread.c	6 May 2013 19:15:17 -0000	1.146
+++ dbxread.c	14 May 2013 15:38:50 -0000
@@ -2528,7 +2528,6 @@ read_ofile_symtab (struct objfile *objfi
   section_offsets = pst->section_offsets;
 
   dbxread_objfile = objfile;
-  subfile_stack = NULL;
 
   stringtab_global = DBX_STRINGTAB (objfile);
   set_last_source_file (NULL);
Index: dwarf2read.c
===================================================================
RCS file: /cvs/src/src/gdb/dwarf2read.c,v
retrieving revision 1.798
diff -u -p -r1.798 dwarf2read.c
--- dwarf2read.c	13 May 2013 16:56:09 -0000	1.798
+++ dwarf2read.c	14 May 2013 15:38:50 -0000
@@ -18540,19 +18540,16 @@ macro_start_file (int file, int line,
   /* File name relative to the compilation directory of this source file.  */
   char *file_name = file_file_name (file, lh);
 
-  /* We don't create a macro table for this compilation unit
-     at all until we actually get a filename.  */
-  if (! pending_macros)
-    pending_macros = new_macro_table (&objfile->per_bfd->storage_obstack,
-				      objfile->per_bfd->macro_cache,
-				      comp_dir);
-
   if (! current_file)
     {
+      /* Note: We don't create a macro table for this compilation unit
+	 at all until we actually get a filename.  */
+      struct macro_table *macro_table = get_macro_table (objfile, comp_dir);
+
       /* If we have no current file, then this must be the start_file
 	 directive for the compilation unit's main source file.  */
-      current_file = macro_set_main (pending_macros, file_name);
-      macro_define_special (pending_macros);
+      current_file = macro_set_main (macro_table, file_name);
+      macro_define_special (macro_table);
     }
   else
     current_file = macro_include (current_file, line, file_name);
Index: stabsread.c
===================================================================
RCS file: /cvs/src/src/gdb/stabsread.c,v
retrieving revision 1.155
diff -u -p -r1.155 stabsread.c
--- stabsread.c	8 Apr 2013 20:18:11 -0000	1.155
+++ stabsread.c	14 May 2013 15:38:50 -0000
@@ -207,6 +207,23 @@ static int noname_undefs_length;
     if (**(pp) == '\\' || (**(pp) == '?' && (*(pp))[1] == '\0')) \
       *(pp) = next_symbol_text (objfile);	\
   } while (0)
+
+/* Vector of types defined so far, indexed by their type numbers.
+   (In newer sun systems, dbx uses a pair of numbers in parens,
+   as in "(SUBFILENUM,NUMWITHINSUBFILE)".
+   Then these numbers must be translated through the type_translations
+   hash table to get the index into the type vector.)  */
+
+static struct type **type_vector;
+
+/* Number of elements allocated for type_vector currently.  */
+
+static int type_vector_length;
+
+/* Initial size of type vector.  Is realloc'd larger if needed, and
+   realloc'd down to the size actually used, when completed.  */
+
+#define INITIAL_TYPE_VECTOR_LENGTH 160
 
 
 /* Look up a dbx type-number pair.  Return the address of the slot


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