Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: sami wagiaalla <swagiaal@redhat.com>
To: gdb-patches@sourceware.org
Subject: Re: [patch 3/3] Change cplus_specific to an alocated struct
Date: Mon, 12 Jul 2010 18:08:00 -0000	[thread overview]
Message-ID: <4C3B5A1E.10602@redhat.com> (raw)
In-Reply-To: <m3pqzrucpg.fsf@fleche.redhat.com>

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

This patch moves the demangled name for cplus symbols to be stored and 
retrieved from a dynamically allocated cplus_specific struct


[-- Attachment #2: dynamic-cplus_specific_3.patch --]
[-- Type: text/plain, Size: 6167 bytes --]

Use allocated cplus_specific for cplus symbols.

2010-07-12  Sami Wagiaalla  <swagiaal@redhat.com>

	* symtab.h (symbol_set_demangled_name): Now takes an optional objfile*
	argument.
	(cplus_specific): New struct.
	* symtab.c (symbol_set_demangled_name): Updated.
	Use cplus_specific for cplus symbols.
	(symbol_get_demangled_name): Retrive the name from the cplus_specific
	struct for cplus symbols.
	(symbol_init_language_specific): Set cplus_specific for cplus symbols.
	(symbol_set_names): Pass objfile to symbol_set_demangled_name.
	* symtab.c (symbol_init_cplus_specific): New function.

diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 4510ccd..622331e 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -8674,7 +8674,9 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
 	 between gfortran, iFort etc.  */
       if (cu->language == language_fortran
           && symbol_get_demangled_name (&(sym->ginfo)) == NULL)
-	symbol_set_demangled_name (&(sym->ginfo), (char *) dwarf2_full_name (name, die, cu));
+	symbol_set_demangled_name (&(sym->ginfo),
+				   (char *) dwarf2_full_name (name, die, cu),
+	                           NULL);
 
       /* Default assumptions.
          Use the passed type or decode it from the die.  */
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 34492f1..ec0e809 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -340,20 +340,53 @@ gdb_mangle_name (struct type *type, int method_id, int signature_id)
   return (mangled_name);
 }
 
+/* Initialize the cplus_specific structure.  'cplus_specific' should
+   only be allocated for use with cplus symbols.  */
+
+static void
+symbol_init_cplus_specific (struct general_symbol_info *gsymbol,
+                           struct objfile *objfile)
+{
+  /* A language_specific structure should not have been previously
+     initialized.  */
+  gdb_assert (gsymbol->language_specific.cplus_specific == NULL);
+  gdb_assert (objfile != NULL);
+
+  gsymbol->language_specific.cplus_specific =
+      OBSTACK_ZALLOC (&objfile->objfile_obstack, struct cplus_specific);
+}
+
 /* Set the demangled name of GSYMBOL to NAME.  NAME must be already
-   correctly allocated.  */
+   correctly allocated.  For C++ symbols a cplus_specific struct is
+   allocated so OBJFILE must not be NULL. If this is a non C++ symbol
+   OBJFILE can be NULL.  */
 void
 symbol_set_demangled_name (struct general_symbol_info *gsymbol,
-                                 char *name)
+                           char *name,
+                           struct objfile *objfile)
 {
-  gsymbol->language_specific.mangled_lang.demangled_name = name;
+  if (gsymbol->language == language_cplus)
+    {
+      if (gsymbol->language_specific.cplus_specific == NULL)
+	symbol_init_cplus_specific (gsymbol, objfile);
+
+      gsymbol->language_specific.cplus_specific->demangled_name = name;
+    }
+  else
+    gsymbol->language_specific.mangled_lang.demangled_name = name;
 }
 
 /* Return the demangled name of GSYMBOL.  */
 char *
 symbol_get_demangled_name (const struct general_symbol_info *gsymbol)
 {
-  return gsymbol->language_specific.mangled_lang.demangled_name;
+  if (gsymbol->language == language_cplus)
+    {
+      gdb_assert (gsymbol->language_specific.cplus_specific != NULL);
+      return gsymbol->language_specific.cplus_specific->demangled_name;
+    }
+  else
+    return gsymbol->language_specific.mangled_lang.demangled_name;
 }
 
 \f
@@ -363,6 +396,7 @@ void
 symbol_init_language_specific (struct general_symbol_info *gsymbol,
 			       enum language language)
 {
+
   gsymbol->language = language;
   if (gsymbol->language == language_cplus
       || gsymbol->language == language_d
@@ -370,8 +404,10 @@ symbol_init_language_specific (struct general_symbol_info *gsymbol,
       || gsymbol->language == language_objc
       || gsymbol->language == language_fortran)
     {
-      symbol_set_demangled_name (gsymbol, NULL);
+      symbol_set_demangled_name (gsymbol, NULL, NULL);
     }
+  else if (gsymbol->language == language_cplus)
+    gsymbol->language_specific.cplus_specific = NULL;
   else
     {
       memset (&gsymbol->language_specific, 0,
@@ -553,7 +589,7 @@ symbol_set_names (struct general_symbol_info *gsymbol,
 	  memcpy (gsymbol->name, linkage_name, len);
 	  gsymbol->name[len] = '\0';
 	}
-      symbol_set_demangled_name (gsymbol, NULL);
+      symbol_set_demangled_name (gsymbol, NULL, NULL);
 
       return;
     }
@@ -649,9 +685,9 @@ symbol_set_names (struct general_symbol_info *gsymbol,
 
   gsymbol->name = (*slot)->mangled + lookup_len - len;
   if ((*slot)->demangled[0] != '\0')
-    symbol_set_demangled_name (gsymbol, (*slot)->demangled);
+    symbol_set_demangled_name (gsymbol, (*slot)->demangled, objfile);
   else
-    symbol_set_demangled_name (gsymbol, NULL);
+    symbol_set_demangled_name (gsymbol, NULL, objfile);
 }
 
 /* Return the source code name of a symbol.  In languages where
diff --git a/gdb/symtab.h b/gdb/symtab.h
index 9864302..2cad280 100644
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -75,7 +75,12 @@ struct program_space;
 
    --chastain 2003-08-21  */
 
+/* Struct for storing C++ specific information.  Allocated when needed.  */
 
+struct cplus_specific
+{
+  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,7 +125,7 @@ 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
   {
@@ -130,6 +135,8 @@ struct general_symbol_info
       char *demangled_name;
     }
     mangled_lang;
+
+    struct cplus_specific *cplus_specific;
   }
   language_specific;
 
@@ -154,7 +161,8 @@ struct general_symbol_info
 };
 
 extern void
-symbol_set_demangled_name (struct general_symbol_info *gsymbol, char *name);
+symbol_set_demangled_name (struct general_symbol_info *gsymbol, char *name,
+                           struct objfile *objfile);
 
 extern char*
 symbol_get_demangled_name (const struct general_symbol_info *symbol);

  parent reply	other threads:[~2010-07-12 18:08 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-26 16:05 [patch] " 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       ` sami wagiaalla [this message]
2010-07-13 17:38         ` [patch 3/3] " Tom Tromey
2010-07-16 14:15           ` sami wagiaalla
2010-07-16 15:29             ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4C3B5A1E.10602@redhat.com \
    --to=swagiaal@redhat.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox