This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
[PATCH/commit/ob] dwarf2read.c cleanups
- From: Elena Zannoni <ezannoni at redhat dot com>
- To: carlton at kealia dot com, gdb-patches at sources dot redhat dot com
- Date: Fri, 9 Jan 2004 17:14:04 -0500
- Subject: [PATCH/commit/ob] dwarf2read.c cleanups
This is the mechanical part of the patch by David, as I suggested in
http://sources.redhat.com/ml/gdb-patches/2004-01/msg00213.html
I'll post the remaining diffs in a separate message.
elena
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.
* cp-namespace.c: Rename processing_current_namespace to
processing_current_prefix.
Index: cp-namespace.c
===================================================================
RCS file: /cvs/src/src/gdb/cp-namespace.c,v
retrieving revision 1.7
diff -u -p -r1.7 cp-namespace.c
--- cp-namespace.c 13 Nov 2003 19:34:02 -0000 1.7
+++ cp-namespace.c 9 Jan 2004 21:14:37 -0000
@@ -38,14 +38,22 @@
unsigned char processing_has_namespace_info;
-/* If processing_has_namespace_info is nonzero, this string should
- contain the name of the current namespace. The string is
- temporary; copy it if you need it. */
+/* This contains our best guess as to the name of the current
+ enclosing namespace(s)/class(es), if any. For example, if we're
+ within the method foo() in the following code:
+
+ namespace N {
+ class C {
+ void foo () {
+ }
+ };
+ }
-/* FIXME: carlton/2003-06-12: This isn't entirely reliable: currently,
- we get mislead by DW_AT_specification. */
+ 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_namespace;
+const char *processing_current_prefix;
/* List of using directives that are active in the current file. */
@@ -223,8 +231,8 @@ cp_set_block_scope (const struct symbol
if (processing_has_namespace_info)
{
block_set_scope
- (block, obsavestring (processing_current_namespace,
- strlen (processing_current_namespace),
+ (block, obsavestring (processing_current_prefix,
+ strlen (processing_current_prefix),
obstack),
obstack);
}
Index: cp-support.h
===================================================================
RCS file: /cvs/src/src/gdb/cp-support.h,v
retrieving revision 1.10
diff -u -p -r1.10 cp-support.h
--- cp-support.h 5 Dec 2003 04:25:09 -0000 1.10
+++ cp-support.h 9 Jan 2004 21:14:48 -0000
@@ -69,7 +69,7 @@ extern struct type *cp_lookup_rtti_type
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);
Index: dwarf2read.c
===================================================================
RCS file: /cvs/src/src/gdb/dwarf2read.c,v
retrieving revision 1.118
diff -u -p -r1.118 dwarf2read.c
--- dwarf2read.c 9 Jan 2004 15:33:15 -0000 1.118
+++ dwarf2read.c 9 Jan 2004 21:15:03 -0000
@@ -809,6 +809,9 @@ static void read_common_block (struct di
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 struct type *dwarf_base_type (int, int, struct dwarf2_cu *);
@@ -1424,6 +1427,7 @@ add_partial_symbol (struct partial_die_i
{
struct objfile *objfile = cu->objfile;
CORE_ADDR addr = 0;
+ char *actual_name = pdi->name;
const struct partial_symbol *psym = NULL;
switch (pdi->tag)
@@ -1431,9 +1435,9 @@ add_partial_symbol (struct partial_die_i
case DW_TAG_subprogram:
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); */
- psym = add_psymbol_to_list (pdi->name, strlen (pdi->name),
+ psym = add_psymbol_to_list (actual_name, strlen (actual_name),
VAR_DOMAIN, LOC_BLOCK,
&objfile->global_psymbols,
0, pdi->lowpc + baseaddr,
@@ -1441,9 +1445,9 @@ add_partial_symbol (struct partial_die_i
}
else
{
- /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
+ /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
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,
&objfile->static_psymbols,
0, pdi->lowpc + baseaddr,
@@ -1469,7 +1473,7 @@ add_partial_symbol (struct partial_die_i
if (pdi->locdesc)
addr = decode_locdesc (pdi->locdesc, cu);
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,
&objfile->global_psymbols,
0, addr + baseaddr,
@@ -1481,9 +1485,9 @@ add_partial_symbol (struct partial_die_i
if (pdi->locdesc == NULL)
return;
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); */
- psym = add_psymbol_to_list (pdi->name, strlen (pdi->name),
+ psym = add_psymbol_to_list (actual_name, strlen (actual_name),
VAR_DOMAIN, LOC_STATIC,
&objfile->static_psymbols,
0, addr + baseaddr,
@@ -1492,7 +1496,7 @@ add_partial_symbol (struct partial_die_i
break;
case DW_TAG_typedef:
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,
&objfile->static_psymbols,
0, (CORE_ADDR) 0, cu_language, objfile);
@@ -1505,7 +1509,7 @@ add_partial_symbol (struct partial_die_i
references. */
if (pdi->has_children == 0)
return;
- add_psymbol_to_list (pdi->name, strlen (pdi->name),
+ add_psymbol_to_list (actual_name, strlen (actual_name),
STRUCT_DOMAIN, LOC_TYPEDEF,
&objfile->static_psymbols,
0, (CORE_ADDR) 0, cu_language, objfile);
@@ -1513,14 +1517,14 @@ add_partial_symbol (struct partial_die_i
if (cu_language == language_cplus)
{
/* 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,
&objfile->static_psymbols,
0, (CORE_ADDR) 0, cu_language, objfile);
}
break;
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,
&objfile->static_psymbols,
0, (CORE_ADDR) 0, cu_language, objfile);
@@ -1863,7 +1867,7 @@ process_die (struct die_info *die, struc
if (!processing_has_namespace_info)
{
processing_has_namespace_info = 1;
- processing_current_namespace = "";
+ processing_current_prefix = "";
}
read_namespace (die, cu);
break;
@@ -1878,7 +1882,7 @@ process_die (struct die_info *die, struc
if (!processing_has_namespace_info)
{
processing_has_namespace_info = 1;
- processing_current_namespace = "";
+ processing_current_prefix = "";
}
gdb_assert (die->child == NULL);
break;
@@ -3218,45 +3222,30 @@ static void
read_namespace (struct die_info *die, struct dwarf2_cu *cu)
{
struct objfile *objfile = cu->objfile;
- const char *previous_namespace = processing_current_namespace;
+ const char *previous_prefix = processing_current_prefix;
const char *name = NULL;
int is_anonymous;
struct die_info *current_die;
- /* Loop through the extensions until we find a name. */
-
- for (current_die = die;
- current_die != NULL;
- current_die = dwarf2_extension (die))
- {
- name = dwarf2_name (current_die);
- if (name != NULL)
- break;
- }
-
- /* Is it an anonymous namespace? */
-
- is_anonymous = (name == NULL);
- if (is_anonymous)
- name = "(anonymous namespace)";
+ name = namespace_name (die, &is_anonymous);
/* Now build the name of the current namespace. */
- if (previous_namespace[0] == '\0')
+ if (previous_prefix[0] == '\0')
{
- processing_current_namespace = name;
+ processing_current_prefix = name;
}
else
{
- /* We need temp_name around because processing_current_namespace
+ /* We need temp_name around because processing_current_prefix
is a const char *. */
- char *temp_name = alloca (strlen (previous_namespace)
+ char *temp_name = alloca (strlen (previous_prefix)
+ 2 + strlen(name) + 1);
- strcpy (temp_name, previous_namespace);
+ strcpy (temp_name, previous_prefix);
strcat (temp_name, "::");
strcat (temp_name, name);
- processing_current_namespace = temp_name;
+ processing_current_prefix = temp_name;
}
/* Add a symbol associated to this if we haven't seen the namespace
@@ -3270,16 +3259,16 @@ read_namespace (struct die_info *die, st
/* 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,
+ (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_namespace,
- strlen (previous_namespace),
- strlen (processing_current_namespace));
+ cp_add_using_directive (processing_current_prefix,
+ strlen (previous_prefix),
+ strlen (processing_current_prefix));
}
if (die->child != NULL)
@@ -3293,7 +3282,37 @@ read_namespace (struct die_info *die, st
}
}
- processing_current_namespace = previous_namespace;
+ 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. */
+
+ for (current_die = die;
+ current_die != NULL;
+ current_die = dwarf2_extension (die))
+ {
+ name = dwarf2_name (current_die);
+ if (name != NULL)
+ break;
+ }
+
+ /* Is it an anonymous namespace? */
+
+ *is_anonymous = (name == NULL);
+ if (*is_anonymous)
+ name = "(anonymous namespace)";
+
+ return name;
}
/* Extract all information from a DW_TAG_pointer_type DIE and add to