2004-01-09 David Carlton <carlton@kealia.com>

Checked in by Elena Zannoni  <ezannoni@redhat.com>.
        * dwarf2read.c (read_namespace): Pull out name-generating code
        into namespace_name. Rename previous_namespace to previous_prefix
        and processing_current_namespace to processing_current_prefix..
        (namespace_name): New function.
        (add_partial_symbol): Substitute uses of pdi->name with
        actual_name.
        * cp-support.h: Rename processing_current_namespace to
        processing_current_prefix.
        Update copyright year.
        * cp-namespace.c: Rename processing_current_namespace to
        processing_current_prefix.
        Update copyright year.
This commit is contained in:
Elena Zannoni 2004-01-09 22:22:07 +00:00
parent 0fb33ef4f8
commit 38d518c93e
4 changed files with 125 additions and 82 deletions

View file

@ -1,3 +1,19 @@
2004-01-09 David Carlton <carlton@kealia.com>
Checked in by Elena Zannoni <ezannoni@redhat.com>.
* dwarf2read.c (read_namespace): Pull out name-generating code
into namespace_name. Rename previous_namespace to previous_prefix
and processing_current_namespace to processing_current_prefix..
(namespace_name): New function.
(add_partial_symbol): Substitute uses of pdi->name with
actual_name.
* cp-support.h: Rename processing_current_namespace to
processing_current_prefix.
Update copyright year.
* cp-namespace.c: Rename processing_current_namespace to
processing_current_prefix.
Update copyright year.
2004-01-09 Andrew Cagney <cagney@redhat.com> 2004-01-09 Andrew Cagney <cagney@redhat.com>
* jv-valprint.c, ser-unix.c: Add missing copyright years. * jv-valprint.c, ser-unix.c: Add missing copyright years.

View file

@ -1,5 +1,5 @@
/* Helper routines for C++ support in GDB. /* Helper routines for C++ support in GDB.
Copyright 2003 Free Software Foundation, Inc. Copyright 2003, 2004 Free Software Foundation, Inc.
Contributed by David Carlton and by Kealia, Inc. Contributed by David Carlton and by Kealia, Inc.
@ -38,14 +38,22 @@
unsigned char processing_has_namespace_info; unsigned char processing_has_namespace_info;
/* If processing_has_namespace_info is nonzero, this string should /* This contains our best guess as to the name of the current
contain the name of the current namespace. The string is enclosing namespace(s)/class(es), if any. For example, if we're
temporary; copy it if you need it. */ within the method foo() in the following code:
/* FIXME: carlton/2003-06-12: This isn't entirely reliable: currently, namespace N {
we get mislead by DW_AT_specification. */ class C {
void foo () {
}
};
}
const char *processing_current_namespace; then processing_current_prefix should be set to "N::C". If
processing_has_namespace_info is false, then this variable might
not be reliable. */
const char *processing_current_prefix;
/* List of using directives that are active in the current file. */ /* List of using directives that are active in the current file. */
@ -223,8 +231,8 @@ cp_set_block_scope (const struct symbol *symbol,
if (processing_has_namespace_info) if (processing_has_namespace_info)
{ {
block_set_scope block_set_scope
(block, obsavestring (processing_current_namespace, (block, obsavestring (processing_current_prefix,
strlen (processing_current_namespace), strlen (processing_current_prefix),
obstack), obstack),
obstack); obstack);
} }

View file

@ -1,5 +1,5 @@
/* Helper routines for C++ support in GDB. /* Helper routines for C++ support in GDB.
Copyright 2002, 2003 Free Software Foundation, Inc. Copyright 2002, 2003, 2004 Free Software Foundation, Inc.
Contributed by MontaVista Software. Contributed by MontaVista Software.
Namespace support contributed by David Carlton. Namespace support contributed by David Carlton.
@ -69,7 +69,7 @@ extern struct type *cp_lookup_rtti_type (const char *name,
extern unsigned char processing_has_namespace_info; extern unsigned char processing_has_namespace_info;
extern const char *processing_current_namespace; extern const char *processing_current_prefix;
extern int cp_is_anonymous (const char *namespace); extern int cp_is_anonymous (const char *namespace);

View file

@ -809,6 +809,9 @@ static void read_common_block (struct die_info *, struct dwarf2_cu *);
static void read_namespace (struct die_info *die, struct dwarf2_cu *); static void read_namespace (struct die_info *die, struct dwarf2_cu *);
static const char *namespace_name (struct die_info *die,
int *is_anonymous);
static void read_enumeration (struct die_info *, struct dwarf2_cu *); static void read_enumeration (struct die_info *, struct dwarf2_cu *);
static struct type *dwarf_base_type (int, int, struct dwarf2_cu *); static struct type *dwarf_base_type (int, int, struct dwarf2_cu *);
@ -1424,6 +1427,7 @@ add_partial_symbol (struct partial_die_info *pdi,
{ {
struct objfile *objfile = cu->objfile; struct objfile *objfile = cu->objfile;
CORE_ADDR addr = 0; CORE_ADDR addr = 0;
char *actual_name = pdi->name;
const struct partial_symbol *psym = NULL; const struct partial_symbol *psym = NULL;
switch (pdi->tag) switch (pdi->tag)
@ -1431,9 +1435,9 @@ add_partial_symbol (struct partial_die_info *pdi,
case DW_TAG_subprogram: case DW_TAG_subprogram:
if (pdi->is_external) if (pdi->is_external)
{ {
/*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr, /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
mst_text, objfile); */ mst_text, objfile); */
psym = add_psymbol_to_list (pdi->name, strlen (pdi->name), psym = add_psymbol_to_list (actual_name, strlen (actual_name),
VAR_DOMAIN, LOC_BLOCK, VAR_DOMAIN, LOC_BLOCK,
&objfile->global_psymbols, &objfile->global_psymbols,
0, pdi->lowpc + baseaddr, 0, pdi->lowpc + baseaddr,
@ -1441,9 +1445,9 @@ add_partial_symbol (struct partial_die_info *pdi,
} }
else else
{ {
/*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr, /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
mst_file_text, objfile); */ mst_file_text, objfile); */
psym = add_psymbol_to_list (pdi->name, strlen (pdi->name), psym = add_psymbol_to_list (actual_name, strlen (actual_name),
VAR_DOMAIN, LOC_BLOCK, VAR_DOMAIN, LOC_BLOCK,
&objfile->static_psymbols, &objfile->static_psymbols,
0, pdi->lowpc + baseaddr, 0, pdi->lowpc + baseaddr,
@ -1469,7 +1473,7 @@ add_partial_symbol (struct partial_die_info *pdi,
if (pdi->locdesc) if (pdi->locdesc)
addr = decode_locdesc (pdi->locdesc, cu); addr = decode_locdesc (pdi->locdesc, cu);
if (pdi->locdesc || pdi->has_type) if (pdi->locdesc || pdi->has_type)
psym = add_psymbol_to_list (pdi->name, strlen (pdi->name), psym = add_psymbol_to_list (actual_name, strlen (actual_name),
VAR_DOMAIN, LOC_STATIC, VAR_DOMAIN, LOC_STATIC,
&objfile->global_psymbols, &objfile->global_psymbols,
0, addr + baseaddr, 0, addr + baseaddr,
@ -1481,9 +1485,9 @@ add_partial_symbol (struct partial_die_info *pdi,
if (pdi->locdesc == NULL) if (pdi->locdesc == NULL)
return; return;
addr = decode_locdesc (pdi->locdesc, cu); addr = decode_locdesc (pdi->locdesc, cu);
/*prim_record_minimal_symbol (pdi->name, addr + baseaddr, /*prim_record_minimal_symbol (actual_name, addr + baseaddr,
mst_file_data, objfile); */ mst_file_data, objfile); */
psym = add_psymbol_to_list (pdi->name, strlen (pdi->name), psym = add_psymbol_to_list (actual_name, strlen (actual_name),
VAR_DOMAIN, LOC_STATIC, VAR_DOMAIN, LOC_STATIC,
&objfile->static_psymbols, &objfile->static_psymbols,
0, addr + baseaddr, 0, addr + baseaddr,
@ -1492,7 +1496,7 @@ add_partial_symbol (struct partial_die_info *pdi,
break; break;
case DW_TAG_typedef: case DW_TAG_typedef:
case DW_TAG_base_type: case DW_TAG_base_type:
add_psymbol_to_list (pdi->name, strlen (pdi->name), add_psymbol_to_list (actual_name, strlen (actual_name),
VAR_DOMAIN, LOC_TYPEDEF, VAR_DOMAIN, LOC_TYPEDEF,
&objfile->static_psymbols, &objfile->static_psymbols,
0, (CORE_ADDR) 0, cu_language, objfile); 0, (CORE_ADDR) 0, cu_language, objfile);
@ -1505,7 +1509,7 @@ add_partial_symbol (struct partial_die_info *pdi,
references. */ references. */
if (pdi->has_children == 0) if (pdi->has_children == 0)
return; return;
add_psymbol_to_list (pdi->name, strlen (pdi->name), add_psymbol_to_list (actual_name, strlen (actual_name),
STRUCT_DOMAIN, LOC_TYPEDEF, STRUCT_DOMAIN, LOC_TYPEDEF,
&objfile->static_psymbols, &objfile->static_psymbols,
0, (CORE_ADDR) 0, cu_language, objfile); 0, (CORE_ADDR) 0, cu_language, objfile);
@ -1513,14 +1517,14 @@ add_partial_symbol (struct partial_die_info *pdi,
if (cu_language == language_cplus) if (cu_language == language_cplus)
{ {
/* For C++, these implicitly act as typedefs as well. */ /* For C++, these implicitly act as typedefs as well. */
add_psymbol_to_list (pdi->name, strlen (pdi->name), add_psymbol_to_list (actual_name, strlen (actual_name),
VAR_DOMAIN, LOC_TYPEDEF, VAR_DOMAIN, LOC_TYPEDEF,
&objfile->static_psymbols, &objfile->static_psymbols,
0, (CORE_ADDR) 0, cu_language, objfile); 0, (CORE_ADDR) 0, cu_language, objfile);
} }
break; break;
case DW_TAG_enumerator: case DW_TAG_enumerator:
add_psymbol_to_list (pdi->name, strlen (pdi->name), add_psymbol_to_list (actual_name, strlen (actual_name),
VAR_DOMAIN, LOC_CONST, VAR_DOMAIN, LOC_CONST,
&objfile->static_psymbols, &objfile->static_psymbols,
0, (CORE_ADDR) 0, cu_language, objfile); 0, (CORE_ADDR) 0, cu_language, objfile);
@ -1863,7 +1867,7 @@ process_die (struct die_info *die, struct dwarf2_cu *cu)
if (!processing_has_namespace_info) if (!processing_has_namespace_info)
{ {
processing_has_namespace_info = 1; processing_has_namespace_info = 1;
processing_current_namespace = ""; processing_current_prefix = "";
} }
read_namespace (die, cu); read_namespace (die, cu);
break; break;
@ -1878,7 +1882,7 @@ process_die (struct die_info *die, struct dwarf2_cu *cu)
if (!processing_has_namespace_info) if (!processing_has_namespace_info)
{ {
processing_has_namespace_info = 1; processing_has_namespace_info = 1;
processing_current_namespace = ""; processing_current_prefix = "";
} }
gdb_assert (die->child == NULL); gdb_assert (die->child == NULL);
break; break;
@ -3218,11 +3222,79 @@ static void
read_namespace (struct die_info *die, struct dwarf2_cu *cu) read_namespace (struct die_info *die, struct dwarf2_cu *cu)
{ {
struct objfile *objfile = cu->objfile; struct objfile *objfile = cu->objfile;
const char *previous_namespace = processing_current_namespace; const char *previous_prefix = processing_current_prefix;
const char *name = NULL; const char *name = NULL;
int is_anonymous; int is_anonymous;
struct die_info *current_die; struct die_info *current_die;
name = namespace_name (die, &is_anonymous);
/* Now build the name of the current namespace. */
if (previous_prefix[0] == '\0')
{
processing_current_prefix = name;
}
else
{
/* We need temp_name around because processing_current_prefix
is a const char *. */
char *temp_name = alloca (strlen (previous_prefix)
+ 2 + strlen(name) + 1);
strcpy (temp_name, previous_prefix);
strcat (temp_name, "::");
strcat (temp_name, name);
processing_current_prefix = temp_name;
}
/* Add a symbol associated to this if we haven't seen the namespace
before. Also, add a using directive if it's an anonymous
namespace. */
if (dwarf2_extension (die) == NULL)
{
struct type *type;
/* FIXME: carlton/2003-06-27: Once GDB is more const-correct,
this cast will hopefully become unnecessary. */
type = init_type (TYPE_CODE_NAMESPACE, 0, 0,
(char *) processing_current_prefix,
objfile);
TYPE_TAG_NAME (type) = TYPE_NAME (type);
new_symbol (die, type, cu);
if (is_anonymous)
cp_add_using_directive (processing_current_prefix,
strlen (previous_prefix),
strlen (processing_current_prefix));
}
if (die->child != NULL)
{
struct die_info *child_die = die->child;
while (child_die && child_die->tag)
{
process_die (child_die, cu);
child_die = sibling_die (child_die);
}
}
processing_current_prefix = previous_prefix;
}
/* Return the name of the namespace represented by DIE. Set
*IS_ANONYMOUS to tell whether or not the namespace is an anonymous
namespace. */
static const char *
namespace_name (struct die_info *die, int *is_anonymous)
{
struct die_info *current_die;
const char *name = NULL;
/* Loop through the extensions until we find a name. */ /* Loop through the extensions until we find a name. */
for (current_die = die; for (current_die = die;
@ -3236,64 +3308,11 @@ read_namespace (struct die_info *die, struct dwarf2_cu *cu)
/* Is it an anonymous namespace? */ /* Is it an anonymous namespace? */
is_anonymous = (name == NULL); *is_anonymous = (name == NULL);
if (is_anonymous) if (*is_anonymous)
name = "(anonymous namespace)"; name = "(anonymous namespace)";
/* Now build the name of the current namespace. */ return name;
if (previous_namespace[0] == '\0')
{
processing_current_namespace = name;
}
else
{
/* We need temp_name around because processing_current_namespace
is a const char *. */
char *temp_name = alloca (strlen (previous_namespace)
+ 2 + strlen(name) + 1);
strcpy (temp_name, previous_namespace);
strcat (temp_name, "::");
strcat (temp_name, name);
processing_current_namespace = temp_name;
}
/* Add a symbol associated to this if we haven't seen the namespace
before. Also, add a using directive if it's an anonymous
namespace. */
if (dwarf2_extension (die) == NULL)
{
struct type *type;
/* FIXME: carlton/2003-06-27: Once GDB is more const-correct,
this cast will hopefully become unnecessary. */
type = init_type (TYPE_CODE_NAMESPACE, 0, 0,
(char *) processing_current_namespace,
objfile);
TYPE_TAG_NAME (type) = TYPE_NAME (type);
new_symbol (die, type, cu);
if (is_anonymous)
cp_add_using_directive (processing_current_namespace,
strlen (previous_namespace),
strlen (processing_current_namespace));
}
if (die->child != NULL)
{
struct die_info *child_die = die->child;
while (child_die && child_die->tag)
{
process_die (child_die, cu);
child_die = sibling_die (child_die);
}
}
processing_current_namespace = previous_namespace;
} }
/* Extract all information from a DW_TAG_pointer_type DIE and add to /* Extract all information from a DW_TAG_pointer_type DIE and add to