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]

[1/10] RFC: move symbol allocation to a new function


This patch is pretty straightforward.

It introduces some new symbol-allocation functions and changes the rest
of gdb to use them.

This is handy because it lets us more easily change symbol
initialization in a later patch.

initialize_symbol was needed because xcoffread takes an unusual approach
to symbol allocation and I didn't want to untangle it all.

Tom

	* coffread.c (process_coff_symbol, coff_read_enum_type): Call
	allocate_symbol.
	* dwarf2read.c (fixup_go_packaging): Call allocate_symbol.
	(read_func_scope): Call allocate_template_symbol.
	(new_symbol_full): Call allocate_symbol.
	* jit.c (finalize_symtab): Call allocate_symbol.
	* jv-lang.c (add_class_symbol): Call allocate_symbol.
	* mdebugread.c (parse_symbol, new_block): Call allocate_symbol.
	* stabsread.c (patch_block_stabs, define_symbol, read_enum_type)
	(common_block_end): Call allocate_symbol.
	* symtab.c (allocate_symbol, initialize_symbol)
	(allocate_template_symbol): New functions.
	* symtab.c (allocate_symbol, initialize_symbol)
	(allocate_template_symbol): Declare.
	* xcoffread.c (process_xcoff_symbol): Call initialize_symbol.
---
 gdb/coffread.c   |    9 ++-------
 gdb/dwarf2read.c |    7 +++----
 gdb/jit.c        |    4 +---
 gdb/jv-lang.c    |    4 +---
 gdb/mdebugread.c |   10 ++--------
 gdb/stabsread.c  |   24 ++++++------------------
 gdb/symtab.c     |   34 ++++++++++++++++++++++++++++++++++
 gdb/symtab.h     |    6 ++++++
 gdb/xcoffread.c  |    2 +-
 9 files changed, 56 insertions(+), 44 deletions(-)

diff --git a/gdb/coffread.c b/gdb/coffread.c
index 3cc14ce..d8a60fc 100644
--- a/gdb/coffread.c
+++ b/gdb/coffread.c
@@ -1534,12 +1534,9 @@ process_coff_symbol (struct coff_symbol *cs,
 		     union internal_auxent *aux,
 		     struct objfile *objfile)
 {
-  struct symbol *sym
-    = (struct symbol *) obstack_alloc (&objfile->objfile_obstack,
-				       sizeof (struct symbol));
+  struct symbol *sym = allocate_symbol (objfile);
   char *name;
 
-  memset (sym, 0, sizeof (struct symbol));
   name = cs->c_name;
   name = EXTERNAL_NAME (name, objfile->obfd);
   SYMBOL_SET_LANGUAGE (sym, current_subfile->language);
@@ -2097,9 +2094,7 @@ coff_read_enum_type (int index, int length, int lastsym,
       switch (ms->c_sclass)
 	{
 	case C_MOE:
-	  sym = (struct symbol *) obstack_alloc
-	    (&objfile->objfile_obstack, sizeof (struct symbol));
-	  memset (sym, 0, sizeof (struct symbol));
+	  sym = allocate_symbol (objfile);
 
 	  SYMBOL_SET_LINKAGE_NAME (sym,
 				   obstack_copy0 (&objfile->objfile_obstack,
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index d26e7c8..06c6353 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -6840,7 +6840,7 @@ fixup_go_packaging (struct dwarf2_cu *cu)
 
       TYPE_TAG_NAME (type) = TYPE_NAME (type);
 
-      sym = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct symbol);
+      sym = allocate_symbol (objfile);
       SYMBOL_SET_LANGUAGE (sym, language_go);
       SYMBOL_SET_NAMES (sym, saved_package_name,
 			strlen (saved_package_name), 0, objfile);
@@ -9496,8 +9496,7 @@ read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
       if (child_die->tag == DW_TAG_template_type_param
 	  || child_die->tag == DW_TAG_template_value_param)
 	{
-	  templ_func = OBSTACK_ZALLOC (&objfile->objfile_obstack,
-				       struct template_symbol);
+	  templ_func = allocate_template_symbol (objfile);
 	  templ_func->base.is_cplus_template_function = 1;
 	  break;
 	}
@@ -15788,7 +15787,7 @@ new_symbol_full (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
       if (space)
 	sym = space;
       else
-	sym = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct symbol);
+	sym = allocate_symbol (objfile);
       OBJSTAT (objfile, n_syms++);
 
       /* Cache this symbol's name and the name's demangled form (if any).  */
diff --git a/gdb/jit.c b/gdb/jit.c
index ecf7317..3f0b118 100644
--- a/gdb/jit.c
+++ b/gdb/jit.c
@@ -677,8 +677,7 @@ finalize_symtab (struct gdb_symtab *stab, struct objfile *objfile)
        i--, gdb_block_iter = gdb_block_iter->next)
     {
       struct block *new_block = allocate_block (&objfile->objfile_obstack);
-      struct symbol *block_name = obstack_alloc (&objfile->objfile_obstack,
-                                                 sizeof (struct symbol));
+      struct symbol *block_name = allocate_symbol (objfile);
       struct type *block_type = arch_type (get_objfile_arch (objfile),
 					   TYPE_CODE_VOID,
 					   1,
@@ -691,7 +690,6 @@ finalize_symtab (struct gdb_symtab *stab, struct objfile *objfile)
       BLOCK_END (new_block) = (CORE_ADDR) gdb_block_iter->end;
 
       /* The name.  */
-      memset (block_name, 0, sizeof (struct symbol));
       SYMBOL_DOMAIN (block_name) = VAR_DOMAIN;
       SYMBOL_CLASS (block_name) = LOC_BLOCK;
       SYMBOL_SYMTAB (block_name) = symtab;
diff --git a/gdb/jv-lang.c b/gdb/jv-lang.c
index 48b5b3c..38991cf 100644
--- a/gdb/jv-lang.c
+++ b/gdb/jv-lang.c
@@ -185,9 +185,7 @@ add_class_symbol (struct type *type, CORE_ADDR addr)
   struct symbol *sym;
   struct objfile *objfile = get_dynamics_objfile (get_type_arch (type));
 
-  sym = (struct symbol *)
-    obstack_alloc (&objfile->objfile_obstack, sizeof (struct symbol));
-  memset (sym, 0, sizeof (struct symbol));
+  sym = allocate_symbol (objfile);
   SYMBOL_SET_LANGUAGE (sym, language_java);
   SYMBOL_SET_LINKAGE_NAME (sym, TYPE_TAG_NAME (type));
   SYMBOL_CLASS (sym) = LOC_TYPEDEF;
diff --git a/gdb/mdebugread.c b/gdb/mdebugread.c
index 2fed944..d3d6f29 100644
--- a/gdb/mdebugread.c
+++ b/gdb/mdebugread.c
@@ -1048,10 +1048,7 @@ parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend,
 		FIELD_NAME (*f) = debug_info->ss + cur_fdr->issBase + tsym.iss;
 		FIELD_BITSIZE (*f) = 0;
 
-		enum_sym = ((struct symbol *)
-			    obstack_alloc (&mdebugread_objfile->objfile_obstack,
-					   sizeof (struct symbol)));
-		memset (enum_sym, 0, sizeof (struct symbol));
+		enum_sym = allocate_symbol (mdebugread_objfile);
 		SYMBOL_SET_LINKAGE_NAME
 		  (enum_sym,
 		   obstack_copy0 (&mdebugread_objfile->objfile_obstack,
@@ -4879,11 +4876,8 @@ new_block (enum block_type type)
 static struct symbol *
 new_symbol (char *name)
 {
-  struct symbol *s = ((struct symbol *)
-		      obstack_alloc (&mdebugread_objfile->objfile_obstack,
-				     sizeof (struct symbol)));
+  struct symbol *s = allocate_symbol (mdebugread_objfile);
 
-  memset (s, 0, sizeof (*s));
   SYMBOL_SET_LANGUAGE (s, psymtab_language);
   SYMBOL_SET_NAMES (s, name, strlen (name), 1, mdebugread_objfile);
   return s;
diff --git a/gdb/stabsread.c b/gdb/stabsread.c
index a38ead1..f780515 100644
--- a/gdb/stabsread.c
+++ b/gdb/stabsread.c
@@ -379,11 +379,7 @@ patch_block_stabs (struct pending *symbols, struct pending_stabs *stabs,
 	      /* On xcoff, if a global is defined and never referenced,
 	         ld will remove it from the executable.  There is then
 	         a N_GSYM stab for it, but no regular (C_EXT) symbol.  */
-	      sym = (struct symbol *)
-		obstack_alloc (&objfile->objfile_obstack,
-			       sizeof (struct symbol));
-
-	      memset (sym, 0, sizeof (struct symbol));
+	      sym = allocate_symbol (objfile);
 	      SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
 	      SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
 	      SYMBOL_SET_LINKAGE_NAME
@@ -647,9 +643,7 @@ define_symbol (CORE_ADDR valu, char *string, int desc, int type,
      e.g. ":t10=*2" or a nameless enum like " :T16=ered:0,green:1,blue:2,;" */
   nameless = (p == string || ((string[0] == ' ') && (string[1] == ':')));
 
-  current_symbol = sym = (struct symbol *)
-    obstack_alloc (&objfile->objfile_obstack, sizeof (struct symbol));
-  memset (sym, 0, sizeof (struct symbol));
+  current_symbol = sym = allocate_symbol (objfile);
 
   switch (type & N_TYPE)
     {
@@ -1290,8 +1284,7 @@ define_symbol (CORE_ADDR valu, char *string, int desc, int type,
       if (synonym)
         {
           /* Create the STRUCT_DOMAIN clone.  */
-          struct symbol *struct_sym = (struct symbol *)
-            obstack_alloc (&objfile->objfile_obstack, sizeof (struct symbol));
+          struct symbol *struct_sym = allocate_symbol (objfile);
 
           *struct_sym = *sym;
           SYMBOL_CLASS (struct_sym) = LOC_TYPEDEF;
@@ -1335,8 +1328,7 @@ define_symbol (CORE_ADDR valu, char *string, int desc, int type,
       if (synonym)
 	{
 	  /* Clone the sym and then modify it.  */
-	  struct symbol *typedef_sym = (struct symbol *)
-	    obstack_alloc (&objfile->objfile_obstack, sizeof (struct symbol));
+	  struct symbol *typedef_sym = allocate_symbol (objfile);
 
 	  *typedef_sym = *sym;
 	  SYMBOL_CLASS (typedef_sym) = LOC_TYPEDEF;
@@ -3680,9 +3672,7 @@ read_enum_type (char **pp, struct type *type,
       if (nbits != 0)
 	return error_type (pp, objfile);
 
-      sym = (struct symbol *)
-	obstack_alloc (&objfile->objfile_obstack, sizeof (struct symbol));
-      memset (sym, 0, sizeof (struct symbol));
+      sym = allocate_symbol (objfile);
       SYMBOL_SET_LINKAGE_NAME (sym, name);
       SYMBOL_SET_LANGUAGE (sym, current_subfile->language);
       SYMBOL_CLASS (sym) = LOC_CONST;
@@ -4354,9 +4344,7 @@ common_block_end (struct objfile *objfile)
       return;
     }
 
-  sym = (struct symbol *)
-    obstack_alloc (&objfile->objfile_obstack, sizeof (struct symbol));
-  memset (sym, 0, sizeof (struct symbol));
+  sym = allocate_symbol (objfile);
   /* Note: common_block_name already saved on objfile_obstack.  */
   SYMBOL_SET_LINKAGE_NAME (sym, common_block_name);
   SYMBOL_CLASS (sym) = LOC_BLOCK;
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 57441c1..6cd8d1f 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -5038,6 +5038,40 @@ producer_is_realview (const char *producer)
   return 0;
 }
 
+/* Allocate and initialize a new 'struct symbol' on OBJFILE's
+   obstack.  */
+
+struct symbol *
+allocate_symbol (struct objfile *objfile)
+{
+  struct symbol *result;
+
+  result = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct symbol);
+
+  return result;
+}
+
+/* Initialize the symbol SYM.  */
+
+void
+initialize_symbol (struct symbol *sym)
+{
+  memset (sym, 0, sizeof (*sym));
+}
+
+/* Allocate and initialize a new 'struct template_symbol' on OBJFILE's
+   obstack.  */
+
+struct template_symbol *
+allocate_template_symbol (struct objfile *objfile)
+{
+  struct template_symbol *result;
+
+  result = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct template_symbol);
+
+  return result;
+}
+
 void
 _initialize_symtab (void)
 {
diff --git a/gdb/symtab.h b/gdb/symtab.h
index 378e933..8368eef 100644
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -1318,4 +1318,10 @@ void iterate_over_symbols (const struct block *block, const char *name,
 struct cleanup *demangle_for_lookup (const char *name, enum language lang,
 				     const char **result_name);
 
+struct symbol *allocate_symbol (struct objfile *);
+
+void initialize_symbol (struct symbol *);
+
+struct template_symbol *allocate_template_symbol (struct objfile *);
+
 #endif /* !defined(SYMTAB_H) */
diff --git a/gdb/xcoffread.c b/gdb/xcoffread.c
index 896b817..cb0cb72 100644
--- a/gdb/xcoffread.c
+++ b/gdb/xcoffread.c
@@ -1546,7 +1546,7 @@ process_xcoff_symbol (struct coff_symbol *cs, struct objfile *objfile)
   if (name[0] == '.')
     ++name;
 
-  memset (sym, '\0', sizeof (struct symbol));
+  initialize_symbol (sym);
 
   /* default assumptions */
   SYMBOL_VALUE_ADDRESS (sym) = cs->c_value + off;
-- 
1.7.7.6


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