* [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
* Re: [patch] Change cplus_specific to an alocated struct
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
1 sibling, 0 replies; 16+ messages in thread
From: sami wagiaalla @ 2010-05-26 16:55 UTC (permalink / raw)
To: gdb-patches
On 05/26/2010 11:45 AM, sami wagiaalla wrote:
> 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);
> +
Changed char **resultp to char *result since demangled_name no longer
necessarily has an address. I didn't see why a pointer pointer was
needed so I hope I am not missing anything. My guess was that it is an
artifact left over from an earlier form of the function.
Also, both locations which call ada_decode_symbol (symbol_natural_name,
and symbol_demangled_name) check before call the function
cplus_specific.demangled_name. So, the check can perhaps be removed from
either the caller or callee.
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [patch] Change cplus_specific to an alocated struct
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
1 sibling, 1 reply; 16+ messages in thread
From: Tom Tromey @ 2010-06-08 17:02 UTC (permalink / raw)
To: sami wagiaalla; +Cc: gdb-patches
>>>>> "Sami" == sami wagiaalla <swagiaal@redhat.com> writes:
Sami> I plan to expand the cplus_specific struct to store template
Sami> information needed, of course, only for C++. Tom suggested that I move
Sami> the substruct out of struct general_symbol_info and change its
Sami> reference to a pointer to be assigned to the struct if allocated.
Sami> Thoughts ?
I think the idea is fine.
Sami> char *
Sami> ada_decode_symbol (const struct general_symbol_info *gsymbol)
Sami> {
Sami> - char **resultp =
Sami> - (char **) &gsymbol->language_specific.cplus_specific.demangled_name;
Sami> - if (*resultp == NULL)
Sami> + char *result = symbol_get_cplus_demangled_name (gsymbol);
I don't think this change is correct -- but FWIW I don't think the
existing code is correct, either.
The code is written this way because this function caches the demangled
name in the cplus_specific struct. Your change removes this caching.
However, this takes a general_symbol_info and so, presumably, can be
used for partial symbols. But, modifying a partial symbol is a no-no,
because they are stored in a bcache.
All this reminds me -- you should look at bcache utilization and memory
use before and after your changes to make sure we aren't hitting a
memory use regression here. There is some command that will show you
bcache statistics, though I forget what it is offhand.
Sami> +char *
Sami> +symbol_get_cplus_demangled_name (const struct general_symbol_info *gsymbol)
Sami> +{
Sami> + if (gsymbol->language_specific.cplus_specific != NULL)
Sami> + return gsymbol->language_specific.cplus_specific->demangled_name;
Sami> +
Sami> + return NULL;
Sami> +}
Perhaps we should have different types of structs in the
language_specific union, and have functions like this examine the
language field.
It seems to me that soon we're going to want to add a bunch of
C++-specific fields, and we don't want to unnecessarily penalize the
other languages with our baggage.
If you were planning that for a follow-on patch, that is fine -- but
also the sort of thing that it is handy to note in your submissions.
Sami> +/* Initialize the cplus_specific structure. 'cplus_specific' is intended to
Sami> + be allocated lazily. So this should only be called if the structure is
Sami> + needed. */
Sami> +static void
Sami> +symbol_init_cplus_specific (struct general_symbol_info *gsymbol,
Sami> + struct objfile *objfile)
Initializing lazily is usually good, but it breaks the bcache.
However perhaps this can be fixed by having the partial symbol code
force the issue.
Tom
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [patch] Change cplus_specific to an alocated struct
2010-06-08 17:02 ` Tom Tromey
@ 2010-06-14 19:29 ` sami wagiaalla
2010-06-15 22:56 ` Tom Tromey
0 siblings, 1 reply; 16+ messages in thread
From: sami wagiaalla @ 2010-06-14 19:29 UTC (permalink / raw)
To: tromey; +Cc: gdb-patches
> Sami> char *
> Sami> ada_decode_symbol (const struct general_symbol_info *gsymbol)
> Sami> {
> Sami> - char **resultp =
> Sami> - (char **)&gsymbol->language_specific.cplus_specific.demangled_name;
> Sami> - if (*resultp == NULL)
> Sami> + char *result = symbol_get_cplus_demangled_name (gsymbol);
>
> I don't think this change is correct -- but FWIW I don't think the
> existing code is correct, either.
>
> The code is written this way because this function caches the demangled
> name in the cplus_specific struct. Your change removes this caching.
>
Totally missed this :)
Badness of the original code aside my patch can be corrected by using
the setter function.
> All this reminds me -- you should look at bcache utilization and memory
> use before and after your changes to make sure we aren't hitting a
> memory use regression here. There is some command that will show you
> bcache statistics, though I forget what it is offhand.
>
I used "maint print statistics" there are no changes in the "Total
memory used for *" fields. But that differ seem to differ even between
runs of the same version. Here are the results of a couple of diffs:
$ diff before after
790c790
< Hash table population: 43%
---
> Hash table population: 44%
793c793
< Maximum hash chain length: 5
---
> Maximum hash chain length: 6
[swagiaal@toner build]$ diff before after
237c237
< Hash table population: 45%
---
> Hash table population: 44%
632c632
< Hash table population: 55%
---
> Hash table population: 53%
793c793
< Maximum hash chain length: 4
---
> Maximum hash chain length: 6
> Sami> +char *
> Sami> +symbol_get_cplus_demangled_name (const struct general_symbol_info *gsymbol)
> Sami> +{
> Sami> + if (gsymbol->language_specific.cplus_specific != NULL)
> Sami> + return gsymbol->language_specific.cplus_specific->demangled_name;
> Sami> +
> Sami> + return NULL;
> Sami> +}
>
> Perhaps we should have different types of structs in the
> language_specific union, and have functions like this examine the
> language field.
>
> It seems to me that soon we're going to want to add a bunch of
> C++-specific fields, and we don't want to unnecessarily penalize the
> other languages with our baggage.
>
> If you were planning that for a follow-on patch, that is fine -- but
> also the sort of thing that it is handy to note in your submissions.
>
I wasn't really planing one :D, but what do you think of this:
We leave the current struct as is and rename cplus_specific to
mangled_lang_specific (or just mangled_lang). And the the union we add a
cplus_specific that managed as things are in this patch, and is actually
cplus_specific ?
> Sami> +/* Initialize the cplus_specific structure. 'cplus_specific' is intended to
> Sami> + be allocated lazily. So this should only be called if the structure is
> Sami> + needed. */
> Sami> +static void
> Sami> +symbol_init_cplus_specific (struct general_symbol_info *gsymbol,
> Sami> + struct objfile *objfile)
>
> Initializing lazily is usually good, but it breaks the bcache.
> However perhaps this can be fixed by having the partial symbol code
> force the issue.
>
I think that is just a wrong use of lazy here. I meant to say initialize
it /if/ it is going to be used rather than when...
symbol_init_cplus_specific is called from symbol_set_names where the
bcache is updated.
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [patch] Change cplus_specific to an alocated struct
2010-06-14 19:29 ` sami wagiaalla
@ 2010-06-15 22:56 ` Tom Tromey
2010-07-12 18:03 ` [patch 1/3] " sami wagiaalla
` (2 more replies)
0 siblings, 3 replies; 16+ messages in thread
From: Tom Tromey @ 2010-06-15 22:56 UTC (permalink / raw)
To: sami wagiaalla; +Cc: gdb-patches
>>>>> "Sami" == sami wagiaalla <swagiaal@redhat.com> writes:
Tom> It seems to me that soon we're going to want to add a bunch of
Tom> C++-specific fields, and we don't want to unnecessarily penalize the
Tom> other languages with our baggage.
Sami> I wasn't really planing one :D, but what do you think of this:
Sami> We leave the current struct as is and rename cplus_specific to
Sami> mangled_lang_specific (or just mangled_lang). And the the union we add
Sami> a cplus_specific that managed as things are in this patch, and is
Sami> actually cplus_specific ?
That sounds ok to me.
Sami> I think that is just a wrong use of lazy here. I meant to say
Sami> initialize it /if/ it is going to be used rather than when...
Sami> symbol_init_cplus_specific is called from symbol_set_names where the
Sami> bcache is updated.
Aha, thanks.
Tom
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [patch 1/3] Change cplus_specific to an alocated struct
2010-06-15 22:56 ` Tom Tromey
@ 2010-07-12 18:03 ` sami wagiaalla
2010-07-13 17:16 ` Tom Tromey
2010-07-12 18:06 ` [patch 2/3] " sami wagiaalla
2010-07-12 18:08 ` [patch 3/3] " sami wagiaalla
2 siblings, 1 reply; 16+ messages in thread
From: sami wagiaalla @ 2010-07-12 18:03 UTC (permalink / raw)
To: gdb-patches
[-- Attachment #1: Type: text/plain, Size: 53 bytes --]
This patch cplus_specific is renamed to mangled_lang
[-- Attachment #2: dynamic-cplus_specific_1.patch --]
[-- Type: text/plain, Size: 5110 bytes --]
commit 91022b44617e9fbf1430280fa4f6b3476a4b015d
Author: Sami Wagiaalla <swagiaal@redhat.com>
Date: Wed Jul 7 13:45:46 2010 -0400
Rename cplus_specific mangled_lang.
2010-07-12 Sami Wagiaalla <swagiaal@redhat.com>
* symtab.h: Renamed cplus_specific to mangled_lang.
* symtab.c (symbol_init_language_specific): Updated.
(symbol_set_names): Updated.
(symbol_natural_name): Updated.
(symbol_demangled_name): Updated.
* ada-lang.c (ada_decode_symbol): Updated.
* dwarf2read.c (new_symbol): Updated.
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 1d4c38b..fabb272 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -1210,7 +1210,7 @@ char *
ada_decode_symbol (const struct general_symbol_info *gsymbol)
{
char **resultp =
- (char **) &gsymbol->language_specific.cplus_specific.demangled_name;
+ (char **) &gsymbol->language_specific.mangled_lang.demangled_name;
if (*resultp == NULL)
{
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index bab1fba..8dd239d 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -8673,8 +8673,8 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
/* Fortran does not have mangling standard and the mangling does differ
between gfortran, iFort etc. */
if (cu->language == language_fortran
- && sym->ginfo.language_specific.cplus_specific.demangled_name == NULL)
- sym->ginfo.language_specific.cplus_specific.demangled_name
+ && sym->ginfo.language_specific.mangled_lang.demangled_name == NULL)
+ sym->ginfo.language_specific.mangled_lang.demangled_name
= (char *) dwarf2_full_name (name, die, cu);
/* Default assumptions.
diff --git a/gdb/symtab.c b/gdb/symtab.c
index cada00e..7e9873e 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -354,7 +354,7 @@ symbol_init_language_specific (struct general_symbol_info *gsymbol,
|| gsymbol->language == language_objc
|| gsymbol->language == language_fortran)
{
- gsymbol->language_specific.cplus_specific.demangled_name = NULL;
+ gsymbol->language_specific.mangled_lang.demangled_name = NULL;
}
else
{
@@ -537,7 +537,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.mangled_lang.demangled_name = NULL;
return;
}
@@ -633,10 +633,10 @@ 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
+ gsymbol->language_specific.mangled_lang.demangled_name
= (*slot)->demangled;
else
- gsymbol->language_specific.cplus_specific.demangled_name = NULL;
+ gsymbol->language_specific.mangled_lang.demangled_name = NULL;
}
/* Return the source code name of a symbol. In languages where
@@ -652,12 +652,12 @@ symbol_natural_name (const struct general_symbol_info *gsymbol)
case language_java:
case language_objc:
case language_fortran:
- if (gsymbol->language_specific.cplus_specific.demangled_name != NULL)
- return gsymbol->language_specific.cplus_specific.demangled_name;
+ if (gsymbol->language_specific.mangled_lang.demangled_name != NULL)
+ return gsymbol->language_specific.mangled_lang.demangled_name;
break;
case language_ada:
- if (gsymbol->language_specific.cplus_specific.demangled_name != NULL)
- return gsymbol->language_specific.cplus_specific.demangled_name;
+ if (gsymbol->language_specific.mangled_lang.demangled_name != NULL)
+ return gsymbol->language_specific.mangled_lang.demangled_name;
else
return ada_decode_symbol (gsymbol);
break;
@@ -679,12 +679,12 @@ symbol_demangled_name (const struct general_symbol_info *gsymbol)
case language_java:
case language_objc:
case language_fortran:
- if (gsymbol->language_specific.cplus_specific.demangled_name != NULL)
- return gsymbol->language_specific.cplus_specific.demangled_name;
+ if (gsymbol->language_specific.mangled_lang.demangled_name != NULL)
+ return gsymbol->language_specific.mangled_lang.demangled_name;
break;
case language_ada:
- if (gsymbol->language_specific.cplus_specific.demangled_name != NULL)
- return gsymbol->language_specific.cplus_specific.demangled_name;
+ if (gsymbol->language_specific.mangled_lang.demangled_name != NULL)
+ return gsymbol->language_specific.mangled_lang.demangled_name;
else
return ada_decode_symbol (gsymbol);
break;
diff --git a/gdb/symtab.h b/gdb/symtab.h
index 5b109ce..ded0ae3 100644
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -124,12 +124,12 @@ struct general_symbol_info
union
{
- struct cplus_specific
+ struct mangled_lang
{
/* This is in fact used for C++, Java, and Objective C. */
char *demangled_name;
}
- cplus_specific;
+ mangled_lang;
}
language_specific;
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [patch 2/3] Change cplus_specific to an alocated struct
2010-06-15 22:56 ` Tom Tromey
2010-07-12 18:03 ` [patch 1/3] " sami wagiaalla
@ 2010-07-12 18:06 ` sami wagiaalla
2010-07-13 17:24 ` Tom Tromey
2010-07-12 18:08 ` [patch 3/3] " sami wagiaalla
2 siblings, 1 reply; 16+ messages in thread
From: sami wagiaalla @ 2010-07-12 18:06 UTC (permalink / raw)
To: gdb-patches
[-- Attachment #1: Type: text/plain, Size: 132 bytes --]
This patch creates setters and getters for the newly named mangled_lang
struct and changes all references to use these functions.
[-- Attachment #2: dynamic-cplus_specific_2.patch --]
[-- Type: text/plain, Size: 5324 bytes --]
Use setter and getter for demangled_name.
2010-07-12 Sami Wagiaalla <swagiaal@redhat.com>
* symtab.h (symbol_set_demangled_name): New function.
(symbol_get_demangled_name): New function.
* symtab.c (symbol_set_demangled_name): New function.
(symbol_get_demangled_name): New function.
(symbol_init_language_specific): Use demangled_name setter and getter.
(symbol_set_names): Ditto.
(symbol_natural_name): Ditto.
(symbol_demangled_name): Ditto.
* dwarf2read.c (new_symbol): Ditto.
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 8dd239d..4510ccd 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -8673,9 +8673,8 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
/* Fortran does not have mangling standard and the mangling does differ
between gfortran, iFort etc. */
if (cu->language == language_fortran
- && sym->ginfo.language_specific.mangled_lang.demangled_name == NULL)
- sym->ginfo.language_specific.mangled_lang.demangled_name
- = (char *) dwarf2_full_name (name, die, cu);
+ && symbol_get_demangled_name (&(sym->ginfo)) == NULL)
+ symbol_set_demangled_name (&(sym->ginfo), (char *) dwarf2_full_name (name, die, cu));
/* Default assumptions.
Use the passed type or decode it from the die. */
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 7e9873e..34492f1 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -340,6 +340,22 @@ gdb_mangle_name (struct type *type, int method_id, int signature_id)
return (mangled_name);
}
+/* Set the demangled name of GSYMBOL to NAME. NAME must be already
+ correctly allocated. */
+void
+symbol_set_demangled_name (struct general_symbol_info *gsymbol,
+ char *name)
+{
+ 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;
+}
+
\f
/* Initialize the language dependent portion of a symbol
depending upon the language for the symbol. */
@@ -354,7 +370,7 @@ symbol_init_language_specific (struct general_symbol_info *gsymbol,
|| gsymbol->language == language_objc
|| gsymbol->language == language_fortran)
{
- gsymbol->language_specific.mangled_lang.demangled_name = NULL;
+ symbol_set_demangled_name (gsymbol, NULL);
}
else
{
@@ -537,7 +553,7 @@ symbol_set_names (struct general_symbol_info *gsymbol,
memcpy (gsymbol->name, linkage_name, len);
gsymbol->name[len] = '\0';
}
- gsymbol->language_specific.mangled_lang.demangled_name = NULL;
+ symbol_set_demangled_name (gsymbol, NULL);
return;
}
@@ -633,10 +649,9 @@ symbol_set_names (struct general_symbol_info *gsymbol,
gsymbol->name = (*slot)->mangled + lookup_len - len;
if ((*slot)->demangled[0] != '\0')
- gsymbol->language_specific.mangled_lang.demangled_name
- = (*slot)->demangled;
+ symbol_set_demangled_name (gsymbol, (*slot)->demangled);
else
- gsymbol->language_specific.mangled_lang.demangled_name = NULL;
+ symbol_set_demangled_name (gsymbol, NULL);
}
/* Return the source code name of a symbol. In languages where
@@ -652,12 +667,12 @@ symbol_natural_name (const struct general_symbol_info *gsymbol)
case language_java:
case language_objc:
case language_fortran:
- if (gsymbol->language_specific.mangled_lang.demangled_name != NULL)
- return gsymbol->language_specific.mangled_lang.demangled_name;
+ if (symbol_get_demangled_name (gsymbol) != NULL)
+ return symbol_get_demangled_name (gsymbol);
break;
case language_ada:
- if (gsymbol->language_specific.mangled_lang.demangled_name != NULL)
- return gsymbol->language_specific.mangled_lang.demangled_name;
+ if (symbol_get_demangled_name (gsymbol) != NULL)
+ return symbol_get_demangled_name (gsymbol);
else
return ada_decode_symbol (gsymbol);
break;
@@ -679,12 +694,12 @@ symbol_demangled_name (const struct general_symbol_info *gsymbol)
case language_java:
case language_objc:
case language_fortran:
- if (gsymbol->language_specific.mangled_lang.demangled_name != NULL)
- return gsymbol->language_specific.mangled_lang.demangled_name;
+ if (symbol_get_demangled_name (gsymbol) != NULL)
+ return symbol_get_demangled_name (gsymbol);
break;
case language_ada:
- if (gsymbol->language_specific.mangled_lang.demangled_name != NULL)
- return gsymbol->language_specific.mangled_lang.demangled_name;
+ if (symbol_get_demangled_name (gsymbol) != NULL)
+ return symbol_get_demangled_name (gsymbol);
else
return ada_decode_symbol (gsymbol);
break;
diff --git a/gdb/symtab.h b/gdb/symtab.h
index ded0ae3..9864302 100644
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -153,6 +153,12 @@ struct general_symbol_info
struct obj_section *obj_section;
};
+extern void
+symbol_set_demangled_name (struct general_symbol_info *gsymbol, char *name);
+
+extern char*
+symbol_get_demangled_name (const struct general_symbol_info *symbol);
+
extern CORE_ADDR symbol_overlayed_address (CORE_ADDR, struct obj_section *);
/* Note that all the following SYMBOL_* macros are used with the
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [patch 3/3] Change cplus_specific to an alocated struct
2010-06-15 22:56 ` Tom Tromey
2010-07-12 18:03 ` [patch 1/3] " sami wagiaalla
2010-07-12 18:06 ` [patch 2/3] " sami wagiaalla
@ 2010-07-12 18:08 ` sami wagiaalla
2010-07-13 17:38 ` Tom Tromey
2 siblings, 1 reply; 16+ messages in thread
From: sami wagiaalla @ 2010-07-12 18:08 UTC (permalink / raw)
To: gdb-patches
[-- 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);
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [patch 1/3] Change cplus_specific to an alocated struct
2010-07-12 18:03 ` [patch 1/3] " sami wagiaalla
@ 2010-07-13 17:16 ` Tom Tromey
2010-07-16 14:15 ` sami wagiaalla
0 siblings, 1 reply; 16+ messages in thread
From: Tom Tromey @ 2010-07-13 17:16 UTC (permalink / raw)
To: sami wagiaalla; +Cc: gdb-patches
>>>>> "Sami" == sami wagiaalla <swagiaal@redhat.com> writes:
Sami> This patch cplus_specific is renamed to mangled_lang
Sami> - struct cplus_specific
Sami> + struct mangled_lang
I'm not super fond of this name, but I don't have a better suggestion.
Please add a new comment above the "struct" line that describes the
purpose of the struct.
Sami> {
Sami> /* This is in fact used for C++, Java, and Objective C. */
Sami> char *demangled_name;
Please rewrite this comment to describe the meaning of this field.
This is ok with those changes.
Tom
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [patch 2/3] Change cplus_specific to an alocated struct
2010-07-12 18:06 ` [patch 2/3] " sami wagiaalla
@ 2010-07-13 17:24 ` Tom Tromey
2010-07-16 14:15 ` sami wagiaalla
0 siblings, 1 reply; 16+ messages in thread
From: Tom Tromey @ 2010-07-13 17:24 UTC (permalink / raw)
To: sami wagiaalla; +Cc: gdb-patches
>>>>> "Sami" == sami wagiaalla <swagiaal@redhat.com> writes:
Sami> This patch creates setters and getters for the newly named
Sami> mangled_lang struct and changes all references to use these functions.
Sami> +extern void
Sami> +symbol_set_demangled_name (struct general_symbol_info *gsymbol, char *name);
In a declaration, we generally don't put a newline after the type.
You can break the line after a "," instead.
Sami> +extern char*
Space before the "*", as well as the line break thing.
This is ok with those changes. Thanks.
I was planning to ask for the new functions to be const-correct, but I
think that would be a big change, since things like symbol_natural_name
return a plain "char *" :-(
Tom
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [patch 3/3] Change cplus_specific to an alocated struct
2010-07-12 18:08 ` [patch 3/3] " sami wagiaalla
@ 2010-07-13 17:38 ` Tom Tromey
2010-07-16 14:15 ` sami wagiaalla
0 siblings, 1 reply; 16+ messages in thread
From: Tom Tromey @ 2010-07-13 17:38 UTC (permalink / raw)
To: sami wagiaalla; +Cc: gdb-patches
>>>>> "Sami" == sami wagiaalla <swagiaal@redhat.com> writes:
Sami> This patch moves the demangled name for cplus symbols to be stored and
Sami> retrieved from a dynamically allocated cplus_specific struct
Be sure to mention how you tested a patch series.
Sami> +/* Initialize the cplus_specific structure. 'cplus_specific' should
Sami> + only be allocated for use with cplus symbols. */
Change "cplus" to "C++" here.
Sami> symbol_init_language_specific (struct general_symbol_info *gsymbol,
Sami> enum language language)
Sami> {
Sami> +
Spurious newline addition, please remove.
This is ok with those changes. Thanks for doing this.
Tom
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [patch 1/3] Change cplus_specific to an alocated struct
2010-07-13 17:16 ` Tom Tromey
@ 2010-07-16 14:15 ` sami wagiaalla
2010-07-16 15:24 ` Tom Tromey
0 siblings, 1 reply; 16+ messages in thread
From: sami wagiaalla @ 2010-07-16 14:15 UTC (permalink / raw)
To: gdb-patches
[-- Attachment #1: Type: text/plain, Size: 436 bytes --]
On 07/13/2010 01:16 PM, Tom Tromey wrote:
>>>>>> "Sami" == sami wagiaalla<swagiaal@redhat.com> writes:
>
> Sami> This patch cplus_specific is renamed to mangled_lang
>
> Sami> - struct cplus_specific
> Sami> + struct mangled_lang
>
> I'm not super fond of this name, but I don't have a better suggestion.
>
Yeah I couldn't come up with anything either :)
I hope the new comment makes it less ugly.
Updated patch attached.
[-- Attachment #2: dynamic-cplus_specific_1.patch --]
[-- Type: text/plain, Size: 5063 bytes --]
Rename cplus_specific mangled_lang.
2010-07-15 Sami Wagiaalla <swagiaal@redhat.com>
* symtab.h: Renamed cplus_specific to mangled_lang.
* symtab.c (symbol_init_language_specific): Updated.
(symbol_set_names): Updated.
(symbol_natural_name): Updated.
(symbol_demangled_name): Updated.
* ada-lang.c (ada_decode_symbol): Updated.
* dwarf2read.c (new_symbol): Updated.
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 1d4c38b..fabb272 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -1210,7 +1210,7 @@ char *
ada_decode_symbol (const struct general_symbol_info *gsymbol)
{
char **resultp =
- (char **) &gsymbol->language_specific.cplus_specific.demangled_name;
+ (char **) &gsymbol->language_specific.mangled_lang.demangled_name;
if (*resultp == NULL)
{
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index bab1fba..8dd239d 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -8673,8 +8673,8 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
/* Fortran does not have mangling standard and the mangling does differ
between gfortran, iFort etc. */
if (cu->language == language_fortran
- && sym->ginfo.language_specific.cplus_specific.demangled_name == NULL)
- sym->ginfo.language_specific.cplus_specific.demangled_name
+ && sym->ginfo.language_specific.mangled_lang.demangled_name == NULL)
+ sym->ginfo.language_specific.mangled_lang.demangled_name
= (char *) dwarf2_full_name (name, die, cu);
/* Default assumptions.
diff --git a/gdb/symtab.c b/gdb/symtab.c
index cada00e..7e9873e 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -354,7 +354,7 @@ symbol_init_language_specific (struct general_symbol_info *gsymbol,
|| gsymbol->language == language_objc
|| gsymbol->language == language_fortran)
{
- gsymbol->language_specific.cplus_specific.demangled_name = NULL;
+ gsymbol->language_specific.mangled_lang.demangled_name = NULL;
}
else
{
@@ -537,7 +537,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.mangled_lang.demangled_name = NULL;
return;
}
@@ -633,10 +633,10 @@ 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
+ gsymbol->language_specific.mangled_lang.demangled_name
= (*slot)->demangled;
else
- gsymbol->language_specific.cplus_specific.demangled_name = NULL;
+ gsymbol->language_specific.mangled_lang.demangled_name = NULL;
}
/* Return the source code name of a symbol. In languages where
@@ -652,12 +652,12 @@ symbol_natural_name (const struct general_symbol_info *gsymbol)
case language_java:
case language_objc:
case language_fortran:
- if (gsymbol->language_specific.cplus_specific.demangled_name != NULL)
- return gsymbol->language_specific.cplus_specific.demangled_name;
+ if (gsymbol->language_specific.mangled_lang.demangled_name != NULL)
+ return gsymbol->language_specific.mangled_lang.demangled_name;
break;
case language_ada:
- if (gsymbol->language_specific.cplus_specific.demangled_name != NULL)
- return gsymbol->language_specific.cplus_specific.demangled_name;
+ if (gsymbol->language_specific.mangled_lang.demangled_name != NULL)
+ return gsymbol->language_specific.mangled_lang.demangled_name;
else
return ada_decode_symbol (gsymbol);
break;
@@ -679,12 +679,12 @@ symbol_demangled_name (const struct general_symbol_info *gsymbol)
case language_java:
case language_objc:
case language_fortran:
- if (gsymbol->language_specific.cplus_specific.demangled_name != NULL)
- return gsymbol->language_specific.cplus_specific.demangled_name;
+ if (gsymbol->language_specific.mangled_lang.demangled_name != NULL)
+ return gsymbol->language_specific.mangled_lang.demangled_name;
break;
case language_ada:
- if (gsymbol->language_specific.cplus_specific.demangled_name != NULL)
- return gsymbol->language_specific.cplus_specific.demangled_name;
+ if (gsymbol->language_specific.mangled_lang.demangled_name != NULL)
+ return gsymbol->language_specific.mangled_lang.demangled_name;
else
return ada_decode_symbol (gsymbol);
break;
diff --git a/gdb/symtab.h b/gdb/symtab.h
index 5b109ce..bad76dd 100644
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -124,12 +124,13 @@ struct general_symbol_info
union
{
- struct cplus_specific
+ /* This is used by languages which wish to store a demangled name.
+ currently used by Ada, Java, and Objective C.*/
+ struct mangled_lang
{
- /* This is in fact used for C++, Java, and Objective C. */
char *demangled_name;
}
- cplus_specific;
+ mangled_lang;
}
language_specific;
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [patch 2/3] Change cplus_specific to an alocated struct
2010-07-13 17:24 ` Tom Tromey
@ 2010-07-16 14:15 ` sami wagiaalla
0 siblings, 0 replies; 16+ messages in thread
From: sami wagiaalla @ 2010-07-16 14:15 UTC (permalink / raw)
To: gdb-patches
[-- Attachment #1: Type: text/plain, Size: 24 bytes --]
Update patch attached.
[-- Attachment #2: dynamic-cplus_specific_2.patch --]
[-- Type: text/plain, Size: 5292 bytes --]
Use setter and getter for demangled_name.
2010-07-15 Sami Wagiaalla <swagiaal@redhat.com>
* symtab.h (symbol_set_demangled_name): New function.
(symbol_get_demangled_name): New function.
* symtab.c (symbol_set_demangled_name): New function.
(symbol_get_demangled_name): New function.
(symbol_init_language_specific): Use demangled_name setter and getter.
(symbol_set_names): Ditto.
(symbol_natural_name): Ditto.
(symbol_demangled_name): Ditto.
* dwarf2read.c (new_symbol): Ditto.
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 8dd239d..4510ccd 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -8673,9 +8673,8 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
/* Fortran does not have mangling standard and the mangling does differ
between gfortran, iFort etc. */
if (cu->language == language_fortran
- && sym->ginfo.language_specific.mangled_lang.demangled_name == NULL)
- sym->ginfo.language_specific.mangled_lang.demangled_name
- = (char *) dwarf2_full_name (name, die, cu);
+ && symbol_get_demangled_name (&(sym->ginfo)) == NULL)
+ symbol_set_demangled_name (&(sym->ginfo), (char *) dwarf2_full_name (name, die, cu));
/* Default assumptions.
Use the passed type or decode it from the die. */
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 7e9873e..2ed1bad 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -340,6 +340,22 @@ gdb_mangle_name (struct type *type, int method_id, int signature_id)
return (mangled_name);
}
+/* Set the demangled name of GSYMBOL to NAME. NAME must be already
+ correctly allocated. */
+void
+symbol_set_demangled_name (struct general_symbol_info *gsymbol,
+ char *name)
+{
+ 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;
+}
+
\f
/* Initialize the language dependent portion of a symbol
depending upon the language for the symbol. */
@@ -354,7 +370,7 @@ symbol_init_language_specific (struct general_symbol_info *gsymbol,
|| gsymbol->language == language_objc
|| gsymbol->language == language_fortran)
{
- gsymbol->language_specific.mangled_lang.demangled_name = NULL;
+ symbol_set_demangled_name (gsymbol, NULL);
}
else
{
@@ -537,7 +553,7 @@ symbol_set_names (struct general_symbol_info *gsymbol,
memcpy (gsymbol->name, linkage_name, len);
gsymbol->name[len] = '\0';
}
- gsymbol->language_specific.mangled_lang.demangled_name = NULL;
+ symbol_set_demangled_name (gsymbol, NULL);
return;
}
@@ -633,10 +649,9 @@ symbol_set_names (struct general_symbol_info *gsymbol,
gsymbol->name = (*slot)->mangled + lookup_len - len;
if ((*slot)->demangled[0] != '\0')
- gsymbol->language_specific.mangled_lang.demangled_name
- = (*slot)->demangled;
+ symbol_set_demangled_name (gsymbol, (*slot)->demangled);
else
- gsymbol->language_specific.mangled_lang.demangled_name = NULL;
+ symbol_set_demangled_name (gsymbol, NULL);
}
/* Return the source code name of a symbol. In languages where
@@ -652,12 +667,12 @@ symbol_natural_name (const struct general_symbol_info *gsymbol)
case language_java:
case language_objc:
case language_fortran:
- if (gsymbol->language_specific.mangled_lang.demangled_name != NULL)
- return gsymbol->language_specific.mangled_lang.demangled_name;
+ if (symbol_get_demangled_name (gsymbol) != NULL)
+ return symbol_get_demangled_name (gsymbol);
break;
case language_ada:
- if (gsymbol->language_specific.mangled_lang.demangled_name != NULL)
- return gsymbol->language_specific.mangled_lang.demangled_name;
+ if (symbol_get_demangled_name (gsymbol) != NULL)
+ return symbol_get_demangled_name (gsymbol);
else
return ada_decode_symbol (gsymbol);
break;
@@ -679,12 +694,12 @@ symbol_demangled_name (const struct general_symbol_info *gsymbol)
case language_java:
case language_objc:
case language_fortran:
- if (gsymbol->language_specific.mangled_lang.demangled_name != NULL)
- return gsymbol->language_specific.mangled_lang.demangled_name;
+ if (symbol_get_demangled_name (gsymbol) != NULL)
+ return symbol_get_demangled_name (gsymbol);
break;
case language_ada:
- if (gsymbol->language_specific.mangled_lang.demangled_name != NULL)
- return gsymbol->language_specific.mangled_lang.demangled_name;
+ if (symbol_get_demangled_name (gsymbol) != NULL)
+ return symbol_get_demangled_name (gsymbol);
else
return ada_decode_symbol (gsymbol);
break;
diff --git a/gdb/symtab.h b/gdb/symtab.h
index bad76dd..ceffe2b 100644
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -154,6 +154,10 @@ struct general_symbol_info
struct obj_section *obj_section;
};
+extern void symbol_set_demangled_name (struct general_symbol_info *, char *);
+
+extern char *symbol_get_demangled_name (const struct general_symbol_info *);
+
extern CORE_ADDR symbol_overlayed_address (CORE_ADDR, struct obj_section *);
/* Note that all the following SYMBOL_* macros are used with the
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [patch 3/3] Change cplus_specific to an alocated struct
2010-07-13 17:38 ` Tom Tromey
@ 2010-07-16 14:15 ` sami wagiaalla
2010-07-16 15:29 ` Tom Tromey
0 siblings, 1 reply; 16+ messages in thread
From: sami wagiaalla @ 2010-07-16 14:15 UTC (permalink / raw)
To: gdb-patches
[-- Attachment #1: Type: text/plain, Size: 737 bytes --]
> Be sure to mention how you tested a patch series.
>
This was tested on Fedora 13 GCC 4.4.4 by running the test suit. No
regressions.
I also used "maint print statistics":
./gdb/gdb gdb/testsuite/gdb.cp/namespace -ex 'b main' -ex 'r' -ex 'maint
print statistics'
no changes in bcach but a couple of objfiles got bigger probably because
of the obstack allocations.
diff [...]/before after
[...]
< Total memory used for objfile obstack: 47475
---
> Total memory used for objfile obstack: 51539
70c70
< Total memory used for objfile obstack: 767363
---
> Total memory used for objfile obstack: 820195
[...]
The files were:
/usr/lib64/libstdc++.so.6 and
[...]/gdb/testsuite/gdb.cp/namespace
Updated patch attached.
[-- Attachment #2: dynamic-cplus_specific_3.patch --]
[-- Type: text/plain, Size: 6188 bytes --]
Use allocated cplus_specific for cplus symbols.
2010-07-15 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 2ed1bad..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 ceffe2b..e6ab26f 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
{
@@ -131,6 +136,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
struct obj_section *obj_section;
};
-extern void symbol_set_demangled_name (struct general_symbol_info *, char *);
+extern void symbol_set_demangled_name (struct general_symbol_info *, char *,
+ struct objfile *);
extern char *symbol_get_demangled_name (const struct general_symbol_info *);
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [patch 1/3] Change cplus_specific to an alocated struct
2010-07-16 14:15 ` sami wagiaalla
@ 2010-07-16 15:24 ` Tom Tromey
0 siblings, 0 replies; 16+ messages in thread
From: Tom Tromey @ 2010-07-16 15:24 UTC (permalink / raw)
To: sami wagiaalla; +Cc: gdb-patches
>>>>> "Sami" == sami wagiaalla <swagiaal@redhat.com> writes:
Sami> 2010-07-15 Sami Wagiaalla <swagiaal@redhat.com>
Sami> * symtab.h: Renamed cplus_specific to mangled_lang.
Sami> * symtab.c (symbol_init_language_specific): Updated.
Sami> (symbol_set_names): Updated.
Sami> (symbol_natural_name): Updated.
Sami> (symbol_demangled_name): Updated.
Sami> * ada-lang.c (ada_decode_symbol): Updated.
Sami> * dwarf2read.c (new_symbol): Updated.
Looks good, please check this in.
Tom
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [patch 3/3] Change cplus_specific to an alocated struct
2010-07-16 14:15 ` sami wagiaalla
@ 2010-07-16 15:29 ` Tom Tromey
0 siblings, 0 replies; 16+ messages in thread
From: Tom Tromey @ 2010-07-16 15:29 UTC (permalink / raw)
To: sami wagiaalla; +Cc: gdb-patches
>>>>> "Sami" == sami wagiaalla <swagiaal@redhat.com> writes:
Sami> This was tested on Fedora 13 GCC 4.4.4 by running the test suit. No
Sami> regressions.
Sami> I also used "maint print statistics":
[...]
Great, thank you.
Tom
^ 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).