diff options
author | David Carlton <carlton@bactrian.org> | 2003-01-11 01:11:03 +0000 |
---|---|---|
committer | David Carlton <carlton@bactrian.org> | 2003-01-11 01:11:03 +0000 |
commit | c2bd69884bd873d5662482ab0b42b70d27b98e08 (patch) | |
tree | e5d6c4d3d380b0a296858e86524399bb1d7482ca | |
parent | db2e1f7a6bada59bb74b8f11d5d330a925554dc2 (diff) | |
download | gdb-c2bd69884bd873d5662482ab0b42b70d27b98e08.tar.gz |
2003-01-10 David Carlton <carlton@math.stanford.edu>
* objfiles.c (allocate_objfile): Always set name.
* dwarf2read.c (scan_partial_symbols): Don't call
add_partial_structure on unions.
(add_partial_structure): Look for enclosing namespace names.
(read_structure_scope): Look enclosing namespace/class names.
(new_symbol): For C++ structures, always grab the name from the
type's name.
2003-01-10 David Carlton <carlton@math.stanford.edu>
* gdb.c++/templates.exp (do_tests): Update some of the regexps to
be a bit more generous.
-rw-r--r-- | gdb/ChangeLog | 10 | ||||
-rw-r--r-- | gdb/dwarf2read.c | 74 | ||||
-rw-r--r-- | gdb/objfiles.c | 4 | ||||
-rw-r--r-- | gdb/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gdb/testsuite/gdb.c++/templates.exp | 13 |
5 files changed, 94 insertions, 12 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index a885af266dc..f932e7c90ff 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,13 @@ +2003-01-10 David Carlton <carlton@math.stanford.edu> + + * objfiles.c (allocate_objfile): Always set name. + * dwarf2read.c (scan_partial_symbols): Don't call + add_partial_structure on unions. + (add_partial_structure): Look for enclosing namespace names. + (read_structure_scope): Look enclosing namespace/class names. + (new_symbol): For C++ structures, always grab the name from the + type's name. + 2003-01-07 David Carlton <carlton@math.stanford.edu> * dwarf2read.c (add_partial_structure): New function. diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index 0302563ce40..fd7483a9a4e 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -1344,6 +1344,7 @@ scan_partial_symbols (char *info_ptr, struct objfile *objfile, break; case DW_TAG_variable: case DW_TAG_typedef: + case DW_TAG_union_type: if (!pdi.is_declaration) { add_partial_symbol (&pdi, objfile, cu_header, namespace); @@ -1351,7 +1352,6 @@ scan_partial_symbols (char *info_ptr, struct objfile *objfile, break; case DW_TAG_class_type: case DW_TAG_structure_type: - case DW_TAG_union_type: if (!pdi.is_declaration) { info_ptr = add_partial_structure (&pdi, info_ptr, @@ -1605,8 +1605,7 @@ add_partial_namespace (struct partial_die_info *pdi, char *info_ptr, return info_ptr; } -/* Read a partial die corresponding to a non-enumeration compound data - structure type. */ +/* Read a partial die corresponding to a class or structure. */ static char * add_partial_structure (struct partial_die_info *struct_pdi, char *info_ptr, @@ -1615,8 +1614,39 @@ add_partial_structure (struct partial_die_info *struct_pdi, char *info_ptr, const char *namespace) { bfd *abfd = objfile->obfd; + char *actual_class_name = NULL; + + if (cu_language == language_cplus + && namespace == NULL + && struct_pdi->name != NULL + && struct_pdi->has_children) + { + /* We don't have namespace debugging information, so see if we + can figure out if this structure lives in a namespace. Look + for a member function; its demangled name will contain + namespace info, if there is any. */ + char *next_child = info_ptr; + + while (1) + { + struct partial_die_info child_pdi; + + next_child = read_partial_die (&child_pdi, abfd, next_child, + cu_header); + if (!child_pdi.tag) + break; + if (child_pdi.tag == DW_TAG_subprogram) + { + actual_class_name = class_name_from_physname (child_pdi.name); + if (actual_class_name != NULL) + struct_pdi->name = actual_class_name; + break; + } + } + } add_partial_symbol (struct_pdi, objfile, cu_header, namespace); + xfree(actual_class_name); return locate_pdi_sibling (struct_pdi, info_ptr, abfd, cu_header); } @@ -2681,6 +2711,10 @@ read_structure_scope (struct die_info *die, struct objfile *objfile, struct attribute *attr; char *name; const char *previous_prefix = processing_current_prefix; + /* This says whether or not we want to try to update the structure's + name to include enclosing namespace/class information, if + any. */ + int need_to_update_name = 0; type = alloc_type (objfile); @@ -2707,6 +2741,7 @@ read_structure_scope (struct die_info *die, struct objfile *objfile, { TYPE_TAG_NAME (type) = obsavestring (name, strlen (name), &objfile->type_obstack); + need_to_update_name = (cu_language == language_cplus); } } @@ -2767,6 +2802,29 @@ read_structure_scope (struct die_info *die, struct objfile *objfile, /* C++ member function. */ process_die (child_die, objfile, cu_header); dwarf2_add_member_fn (&fi, child_die, type, objfile, cu_header); + if (need_to_update_name) + { + /* The demangled names of member functions contain + information about enclosing namespaces/classes, + if any. */ + + /* FIXME: carlton/2003-01-10: The excessive + demangling here is a bit wasteful, as is the + memory usage for names. */ + char *actual_class_name + = class_name_from_physname (dwarf2_linkage_name + (child_die)); + if (actual_class_name != NULL + && strcmp (actual_class_name, name) != 0) + { + TYPE_TAG_NAME (type) + = obsavestring (actual_class_name, + strlen (actual_class_name), + &objfile->type_obstack); + } + xfree (actual_class_name); + need_to_update_name = 0; + } } else if (child_die->tag == DW_TAG_inheritance) { @@ -5225,15 +5283,19 @@ new_symbol (struct die_info *die, struct type *type, struct objfile *objfile, SYMBOL_CLASS (sym) = LOC_TYPEDEF; SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE; - /* Make sure that the symbol includes appropriate - namespaces in its name. */ + /* Make sure that the symbol includes appropriate enclosing + classes/namespaces in its name. These are calculated in + read_structure_scope, and the correct name is saved in + the type. */ - if (processing_has_namespace_info) + if (cu_language == language_cplus) { struct type *type = SYMBOL_TYPE (sym); if (TYPE_TAG_NAME (type) != NULL) { + /* FIXME: carlton/2003-01-10: We're being a bit + profligate with memory names here. */ SYMBOL_NAME (sym) = obsavestring (TYPE_TAG_NAME (type), strlen (TYPE_TAG_NAME (type)), diff --git a/gdb/objfiles.c b/gdb/objfiles.c index 8f36f8af655..c333f4cfd97 100644 --- a/gdb/objfiles.c +++ b/gdb/objfiles.c @@ -307,6 +307,10 @@ allocate_objfile (bfd *abfd, int flags) objfile->name, bfd_errmsg (bfd_get_error ())); } } + else + { + objfile->name = "<<anonymous objfile>>"; + } /* Initialize the section indexes for this objfile, so that we can later detect if they are used w/o being properly assigned to. */ diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index d5e3fc8beb9..c25c4991336 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2003-01-10 David Carlton <carlton@math.stanford.edu> + + * gdb.c++/templates.exp (do_tests): Update some of the regexps to + be a bit more generous. + 2003-01-06 David Carlton <carlton@math.stanford.edu> * gdb.c++/namespace.exp: Test anonymous namespaces and multiple diff --git a/gdb/testsuite/gdb.c++/templates.exp b/gdb/testsuite/gdb.c++/templates.exp index a6d35fcb116..b0260bec11d 100644 --- a/gdb/testsuite/gdb.c++/templates.exp +++ b/gdb/testsuite/gdb.c++/templates.exp @@ -288,6 +288,7 @@ gdb_expect { send_gdb "ptype fvpchar\n" gdb_expect { -re "type = (class |)Foo<volatile char ?\\*> \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*.*char.*\\*t;\r\n\r\n\[ \t\]*.*char \\* foo\\(int,.*char.*\\*\\);\r\n\\}\r\n$gdb_prompt $" { pass "ptype fvpchar" } + -re "type = class Foo<char volatile\\*> \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*.*char.*\\*t;\r\n\r\n\[ \t\]*.*char \\* foo\\(int,.*char.*\\*\\);\r\n\\}\r\n$gdb_prompt $" { pass "ptype fvpchar" } -re "$gdb_prompt $" { fail "ptype fvpchar" } timeout { fail "(timeout) ptype fvpchar" } } @@ -319,7 +320,7 @@ gdb_expect { send_gdb "ptype bint\n" gdb_expect { - -re "type = (class |)Bar<int,(\\(int\\)|)33> \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*int t;\r\n\r\n\[ \t\]*.*int bar\\(int, int\\);\r\n\\}\r\n$gdb_prompt $" { pass "ptype bint" } + -re "type = (class |)Bar<int, ?(\\(int\\)|)33> \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*int t;\r\n\r\n\[ \t\]*.*int bar\\(int, int\\);\r\n\\}\r\n$gdb_prompt $" { pass "ptype bint" } -re "$gdb_prompt $" { fail "ptype bint" } timeout { fail "(timeout) ptype bint" } } @@ -328,7 +329,7 @@ gdb_expect { send_gdb "ptype bint2\n" gdb_expect { - -re "type = (class |)Bar<int,(\\(int\\)|)1> \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*int t;\r\n\r\n\[ \t\]*.*int bar\\(int, int\\);\r\n\\}\r\n$gdb_prompt $" { pass "ptype bint2" } + -re "type = (class |)Bar<int, ?(\\(int\\)|)1> \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*int t;\r\n\r\n\[ \t\]*.*int bar\\(int, int\\);\r\n\\}\r\n$gdb_prompt $" { pass "ptype bint2" } -re "$gdb_prompt $" { fail "ptype bint2" } timeout { fail "(timeout) ptype bint2" } } @@ -351,7 +352,7 @@ gdb_expect { send_gdb "ptype bazint\n" gdb_expect { - -re "type = (class |)Baz<int,(\\(char\\)|)(115|\\'s\\')> \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*int t;\r\n\r\n\[ \t\]*.*int baz\\(int, int\\);\r\n\\}\r\n$gdb_prompt $" { pass "ptype bazint" } + -re "type = (class |)Baz<int, ?(\\(char\\)|)(115|\\'s\\')> \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*int t;\r\n\r\n\[ \t\]*.*int baz\\(int, int\\);\r\n\\}\r\n$gdb_prompt $" { pass "ptype bazint" } -re "$gdb_prompt $" { fail "ptype bazint" } timeout { fail "(timeout) ptype bazint" } } @@ -360,7 +361,7 @@ gdb_expect { send_gdb "ptype bazint2\n" gdb_expect { - -re "type = (class |)Baz<char,(\\(char\\)|)(97|\\'a\\')> \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*char t;\r\n\r\n\[ \t\]*.*char baz\\(int, char\\);\r\n\\}\r\n$gdb_prompt $" { pass "ptype bazint2" } + -re "type = (class |)Baz<char, ?(\\(char\\)|)(97|\\'a\\')> \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*char t;\r\n\r\n\[ \t\]*.*char baz\\(int, char\\);\r\n\\}\r\n$gdb_prompt $" { pass "ptype bazint2" } -re "$gdb_prompt $" { fail "ptype bazint2" } timeout { fail "(timeout) ptype bazint2" } } @@ -380,7 +381,7 @@ gdb_expect { send_gdb "ptype quxint\n" gdb_expect { - -re "type = class Qux<int,&string> \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*int t;\r\n\r\n\[ \t\]*.*int qux\\(int, int\\);\r\n\\}\r\n$gdb_prompt $" { pass "ptype quxint" } + -re "type = class Qux<int, ?&\\(?string\\)?> \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*int t;\r\n\r\n\[ \t\]*.*int qux\\(int, int\\);\r\n\\}\r\n$gdb_prompt $" { pass "ptype quxint" } -re "$gdb_prompt $" { fail "ptype quxint" } timeout { fail "(timeout) ptype quxint" } } @@ -413,7 +414,7 @@ gdb_expect { send_gdb "ptype siip\n" gdb_expect { - -re "type = class Spec<int,int ?\\*> \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\r\n\[ \t\]*.*int spec\\(int ?\\*\\);\r\n\\}\r\n$gdb_prompt $" { pass "ptype siip" } + -re "type = class Spec<int, ?int ?\\*> \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\r\n\[ \t\]*.*int spec\\(int ?\\*\\);\r\n\\}\r\n$gdb_prompt $" { pass "ptype siip" } -re "$gdb_prompt $" { fail "ptype siip" } timeout { fail "(timeout) ptype siip" } } |