public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [patch] Change cplus_specific to an alocated struct
@ 2010-05-26 16:05 sami wagiaalla
  2010-05-26 16:55 ` sami wagiaalla
  2010-06-08 17:02 ` Tom Tromey
  0 siblings, 2 replies; 16+ messages in thread
From: sami wagiaalla @ 2010-05-26 16:05 UTC (permalink / raw)
  To: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 276 bytes --]

I plan to expand the cplus_specific struct to store template information 
needed, of course, only for C++. Tom suggested that I move the substruct 
out of struct general_symbol_info and change its reference to a pointer 
to be assigned to the struct if allocated.

Thoughts ?

[-- Attachment #2: cplus_specific-cleanup.patch --]
[-- Type: text/plain, Size: 8333 bytes --]

Change cplus_specific to an allocated struct.

2010-05-26  Sami Wagiaalla  <swagiaal@redhat.com>

	* symtab.h: Change general_symbol_info.cplus_specific to a pointer
	instead of a sub-struct.
	Added prototype for +symbol_get_cplus_demangled_name.
	* symtab.c (symbol_set_cplus_demangled_name): New function.
	(symbol_get_cplus_demangled_name): New function.
	(symbol_init_cplus_specific): New function.
	(symbol_init_language_specific): Set language_specific.cplus_specific
	to null instead of language_specific.cplus_specific.demangled_name.
	(symbol_set_names): Ditto.
	call symbol_init_cplus_specific when needed.
	(symbol_natural_name): Use symbol_demangled_name.
	(symbol_demangled_name): Use symbol_get_cplus_demangled_name.
	* ada-lang.c (ada_decode_symbol): Use symbol_get_cplus_demangled_name.
	Change char **result to char *result.

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 3b3894c..62e1251 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -1142,32 +1142,32 @@ static struct htab *decoded_names_store;
 char *
 ada_decode_symbol (const struct general_symbol_info *gsymbol)
 {
-  char **resultp =
-    (char **) &gsymbol->language_specific.cplus_specific.demangled_name;
-  if (*resultp == NULL)
+  char *result = symbol_get_cplus_demangled_name (gsymbol);
+
+  if (result == NULL)
     {
       const char *decoded = ada_decode (gsymbol->name);
       if (gsymbol->obj_section != NULL)
         {
 	  struct objfile *objf = gsymbol->obj_section->objfile;
-	  *resultp = obsavestring (decoded, strlen (decoded),
-				   &objf->objfile_obstack);
+	  result = obsavestring (decoded, strlen (decoded),
+	                         &objf->objfile_obstack);
         }
       /* Sometimes, we can't find a corresponding objfile, in which
          case, we put the result on the heap.  Since we only decode
          when needed, we hope this usually does not cause a
          significant memory leak (FIXME).  */
-      if (*resultp == NULL)
+      if (result == NULL)
         {
           char **slot = (char **) htab_find_slot (decoded_names_store,
                                                   decoded, INSERT);
           if (*slot == NULL)
             *slot = xstrdup (decoded);
-          *resultp = *slot;
+          result = *slot;
         }
     }
 
-  return *resultp;
+  return result;
 }
 
 static char *
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 8b30ff1..f20baab 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -338,6 +338,38 @@ gdb_mangle_name (struct type *type, int method_id, int signature_id)
   return (mangled_name);
 }
 
+/* Set the cplus demangled name of GSYMBOL to NAME.  NAME must be already
+   correctly allocated.  */
+static void
+symbol_set_cplus_demangled_name (struct general_symbol_info *gsymbol,
+                                 char *name)
+{
+  gdb_assert (gsymbol->language_specific.cplus_specific != NULL);
+  gsymbol->language_specific.cplus_specific->demangled_name = name;
+}
+
+/* Return the cplus demangled name of GSYMBOL.  If GYSMBOL does not have a
+   cplus_specific struct allocated NULL is returned.  */
+char *
+symbol_get_cplus_demangled_name (const struct general_symbol_info *gsymbol)
+{
+  if (gsymbol->language_specific.cplus_specific != NULL)
+    return gsymbol->language_specific.cplus_specific->demangled_name;
+
+  return NULL;
+}
+
+/* Initialize the cplus_specific structure.  'cplus_specific' is intended to
+   be allocated lazily.  So this should only be called if the structure is
+   needed.  */
+static void
+symbol_init_cplus_specific (struct general_symbol_info *gsymbol,
+                           struct objfile *objfile)
+{
+  gsymbol->language_specific.cplus_specific =
+      OBSTACK_ZALLOC (&objfile->objfile_obstack, struct cplus_specific);
+}
+
 \f
 /* Initialize the language dependent portion of a symbol
    depending upon the language for the symbol. */
@@ -351,7 +383,7 @@ symbol_init_language_specific (struct general_symbol_info *gsymbol,
       || gsymbol->language == language_java
       || gsymbol->language == language_objc)
     {
-      gsymbol->language_specific.cplus_specific.demangled_name = NULL;
+      gsymbol->language_specific.cplus_specific = NULL;
     }
   else
     {
@@ -527,7 +559,7 @@ symbol_set_names (struct general_symbol_info *gsymbol,
 	  memcpy (gsymbol->name, linkage_name, len);
 	  gsymbol->name[len] = '\0';
 	}
-      gsymbol->language_specific.cplus_specific.demangled_name = NULL;
+      gsymbol->language_specific.cplus_specific = NULL;
 
       return;
     }
@@ -623,10 +655,12 @@ symbol_set_names (struct general_symbol_info *gsymbol,
 
   gsymbol->name = (*slot)->mangled + lookup_len - len;
   if ((*slot)->demangled[0] != '\0')
-    gsymbol->language_specific.cplus_specific.demangled_name
-      = (*slot)->demangled;
+    {
+      symbol_init_cplus_specific (gsymbol, objfile);
+      symbol_set_cplus_demangled_name (gsymbol, (*slot)->demangled);
+    }
   else
-    gsymbol->language_specific.cplus_specific.demangled_name = NULL;
+    gsymbol->language_specific.cplus_specific = NULL;
 }
 
 /* Return the source code name of a symbol.  In languages where
@@ -635,24 +669,11 @@ symbol_set_names (struct general_symbol_info *gsymbol,
 char *
 symbol_natural_name (const struct general_symbol_info *gsymbol)
 {
-  switch (gsymbol->language)
-    {
-    case language_cplus:
-    case language_d:
-    case language_java:
-    case language_objc:
-      if (gsymbol->language_specific.cplus_specific.demangled_name != NULL)
-	return gsymbol->language_specific.cplus_specific.demangled_name;
-      break;
-    case language_ada:
-      if (gsymbol->language_specific.cplus_specific.demangled_name != NULL)
-	return gsymbol->language_specific.cplus_specific.demangled_name;
-      else
-	return ada_decode_symbol (gsymbol);
-      break;
-    default:
-      break;
-    }
+  char *name = symbol_demangled_name (gsymbol);
+
+  if (name != NULL)
+    return name;
+
   return gsymbol->name;
 }
 
@@ -661,18 +682,22 @@ symbol_natural_name (const struct general_symbol_info *gsymbol)
 char *
 symbol_demangled_name (const struct general_symbol_info *gsymbol)
 {
+  char *name;
+
   switch (gsymbol->language)
     {
     case language_cplus:
     case language_d:
     case language_java:
     case language_objc:
-      if (gsymbol->language_specific.cplus_specific.demangled_name != NULL)
-	return gsymbol->language_specific.cplus_specific.demangled_name;
+      name = symbol_get_cplus_demangled_name (gsymbol);
+      if (name != NULL)
+	return name;
       break;
     case language_ada:
-      if (gsymbol->language_specific.cplus_specific.demangled_name != NULL)
-	return gsymbol->language_specific.cplus_specific.demangled_name;
+      name = symbol_get_cplus_demangled_name (gsymbol);
+      if (name != NULL)
+	return name;
       else
 	return ada_decode_symbol (gsymbol);
       break;
diff --git a/gdb/symtab.h b/gdb/symtab.h
index 115c8ba..8ae799b 100644
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -75,7 +75,13 @@ struct program_space;
 
    --chastain 2003-08-21  */
 
+/* Struct for storing C++ specific information.  Allocated when needed.  */
 
+struct cplus_specific
+{
+  /* This is in fact used for C++, Java, and Objective C.  */
+  char *demangled_name;
+};
 
 /* Define a structure for the information that is common to all symbol types,
    including minimal symbols, partial symbols, and full symbols.  In a
@@ -120,16 +126,11 @@ struct general_symbol_info
   value;
 
   /* Since one and only one language can apply, wrap the language specific
-     information inside a union. */
+     information inside a union.  */
 
   union
   {
-    struct cplus_specific
-    {
-      /* This is in fact used for C++, Java, and Objective C.  */
-      char *demangled_name;
-    }
-    cplus_specific;
+    struct cplus_specific *cplus_specific;
   }
   language_specific;
 
@@ -172,6 +173,10 @@ extern CORE_ADDR symbol_overlayed_address (CORE_ADDR, struct obj_section *);
 #define SYMBOL_SECTION(symbol)		(symbol)->ginfo.section
 #define SYMBOL_OBJ_SECTION(symbol)	(symbol)->ginfo.obj_section
 
+
+extern char *
+symbol_get_cplus_demangled_name (const struct general_symbol_info *gsymbol);
+
 /* Initializes the language dependent portion of a symbol
    depending upon the language for the symbol. */
 #define SYMBOL_INIT_LANGUAGE_SPECIFIC(symbol,language) \

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2010-07-16 15:29 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-05-26 16:05 [patch] Change cplus_specific to an alocated struct sami wagiaalla
2010-05-26 16:55 ` sami wagiaalla
2010-06-08 17:02 ` Tom Tromey
2010-06-14 19:29   ` sami wagiaalla
2010-06-15 22:56     ` Tom Tromey
2010-07-12 18:03       ` [patch 1/3] " sami wagiaalla
2010-07-13 17:16         ` Tom Tromey
2010-07-16 14:15           ` sami wagiaalla
2010-07-16 15:24             ` Tom Tromey
2010-07-12 18:06       ` [patch 2/3] " sami wagiaalla
2010-07-13 17:24         ` Tom Tromey
2010-07-16 14:15           ` sami wagiaalla
2010-07-12 18:08       ` [patch 3/3] " sami wagiaalla
2010-07-13 17:38         ` Tom Tromey
2010-07-16 14:15           ` sami wagiaalla
2010-07-16 15:29             ` Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).