From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6906 invoked by alias); 30 Dec 2003 21:03:26 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 6887 invoked from network); 30 Dec 2003 21:03:23 -0000 Received: from unknown (HELO nevyn.them.org) (66.93.172.17) by sources.redhat.com with SMTP; 30 Dec 2003 21:03:23 -0000 Received: from drow by nevyn.them.org with local (Exim 4.30 #1 (Debian)) id 1AbR1P-00040l-3v for ; Tue, 30 Dec 2003 16:03:23 -0500 Date: Tue, 30 Dec 2003 21:03:00 -0000 From: Daniel Jacobowitz To: gdb-patches@sources.redhat.com Subject: [cplus] An initial use of the canonicalizer Message-ID: <20031230210323.GA15366@nevyn.them.org> Mail-Followup-To: gdb-patches@sources.redhat.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.1i X-SW-Source: 2003-12/txt/msg00522.txt.bz2 One of the historical warts I've wanted to correct: the compiler formats template-ids differently in DW_AT_name than the demangler does in the symbol table. So we get debug info for Foo::foo and an implementation for Foo::foo. This is a first step towards knowing that they're the same. Next I'm taking a detour through the type-printer. -- Daniel Jacobowitz MontaVista Software Debian GNU/Linux Developer 2003-12-30 Daniel Jacobowitz * gdb.cp/templates.exp: Formatting changes to match demangler style for template names. New tests for member variable Foo::x with different spellings of the template argument. 2003-12-30 Daniel Jacobowitz * cp-names.y (yylex): Fix thinko for character constants. * dwarf2read.c: Include "cp-names.h". (read_structure_scope): Canonicalize class names. Index: cp-names.y =================================================================== RCS file: /cvs/src/src/gdb/Attic/cp-names.y,v retrieving revision 1.1.2.14 diff -u -p -r1.1.2.14 cp-names.y --- cp-names.y 24 Dec 2003 22:35:25 -0000 1.1.2.14 +++ cp-names.y 30 Dec 2003 20:54:07 -0000 @@ -1597,12 +1597,17 @@ yylex (void) "character set `%s'.", tok, target_charset ()); } - yylval.typed_val_int.val = c; - yylval.typed_val_int.type = d_builtin_type ('c' - 'a'); - c = *lexptr++; if (c != '\'') error ("Invalid character constant."); + + /* FIXME: We should refer to a canonical form of the character, + presumably the same one that appears in manglings - the decimal + representation. But if that isn't in our input then we have to + allocate memory for it somewhere. */ + yylval.comp = d_make_comp (di, D_COMP_LITERAL, + d_builtin_type ('c' - 'a'), + d_make_name (di, tokstart, lexptr - tokstart)); return INT; Index: dwarf2read.c =================================================================== RCS file: /cvs/src/src/gdb/dwarf2read.c,v retrieving revision 1.67.2.4 diff -u -p -r1.67.2.4 dwarf2read.c --- dwarf2read.c 14 Dec 2003 20:27:11 -0000 1.67.2.4 +++ dwarf2read.c 30 Dec 2003 20:54:08 -0000 @@ -44,6 +44,7 @@ #include "dwarf2expr.h" #include "dwarf2loc.h" #include "cp-support.h" +#include "cp-names.h" #include #include "gdb_string.h" @@ -2779,9 +2780,15 @@ read_structure_scope (struct die_info *d attr = dwarf_attr (die, DW_AT_name); if (attr && DW_STRING (attr)) { - TYPE_TAG_NAME (type) = obsavestring (DW_STRING (attr), - strlen (DW_STRING (attr)), + /* FIXME: This should be in a more general location. */ + char *name; + name = cp_canonicalize_string (DW_STRING (attr)); + if (name == NULL) + name = DW_STRING (attr); + TYPE_TAG_NAME (type) = obsavestring (name, strlen (name), &objfile->type_obstack); + if (name != DW_STRING (attr)) + free (name); } if (die->tag == DW_TAG_structure_type) Index: testsuite/gdb.cp/templates.exp =================================================================== RCS file: /cvs/src/src/gdb/testsuite/gdb.cp/templates.exp,v retrieving revision 1.2.2.2 diff -u -p -r1.2.2.2 templates.exp --- testsuite/gdb.cp/templates.exp 15 Dec 2003 02:11:47 -0000 1.2.2.2 +++ testsuite/gdb.cp/templates.exp 30 Dec 2003 20:54:09 -0000 @@ -311,7 +311,7 @@ gdb_expect { send_gdb "ptype fvpchar\n" gdb_expect { - -re "type = (class |)Foo \\{\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.* ?\\*> \\{\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" } } @@ -323,7 +323,7 @@ gdb_expect { send_gdb "print Foo::foo\n" gdb_expect { - -re "\\$\[0-9\]* = \\{.*char \\*\\((class |)Foo \\*(| const), int, .*char \\*\\)\\} $hex ::foo\\(int, .*char.*\\*\\)>\r\n$gdb_prompt $" { pass "print Foo::foo" } + -re "\\$\[0-9\]* = \\{.*char.* \\*\\((class |)Foo \\*(| const), int, .*char.* \\*\\)\\} $hex ::foo\\(int, .*char.*\\*\\)>\r\n$gdb_prompt $" { pass "print Foo::foo" } -re "No symbol \"Foo\" in current context.\r\n$gdb_prompt $" { # This used to be a kfail gdb/33, but it shouldn't occur any more now. @@ -335,7 +335,7 @@ gdb_expect { send_gdb "print Foo::foo\n" gdb_expect { - -re "\\$\[0-9\]* = \\{.*char \\*\\((class |)Foo \\*(| const), int, .*char \\*\\)\\} $hex ::foo\\(int, .*char.*\\*\\)>\r\n$gdb_prompt $" { pass "print Foo::foo" } + -re "\\$\[0-9\]* = \\{.*char.* \\*\\((class |)Foo \\*(| const), int, .*char.* \\*\\)\\} $hex ::foo\\(int, .*char.*\\*\\)>\r\n$gdb_prompt $" { pass "print Foo::foo" } -re "No symbol \"Foo\" in current context.\r\n$gdb_prompt $" { # This used to be a kfail gdb/33, but it shouldn't occur any more now. @@ -345,6 +345,12 @@ gdb_expect { timeout { fail "(timeout) print Foo::foo" } } +# Verify that we get the same results for Foo for some equivalent +# template arguments. +gdb_test "ptype Foo::x" "type = int \\( Foo<.*char.*\\*>::&\\)" +gdb_test "ptype Foo::x" "type = int \\( Foo<.*char.*\\*>::&\\)" +gdb_test "ptype Foo::x" "type = int \\( Foo<.*char.*\\*>::&\\)" + # Template Bar # same as Foo for g++ @@ -352,7 +358,7 @@ send_gdb "ptype Bar\n" gdb_expect { -re "type = template <(class |)T, (class |)sz> (class |)Bar \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*T t;\r\n\\}\r\ntemplate instantiations:\r\n\[ \t\]*(class |)Bar\r\n\[ \t\]*(class |)Bar\r\n$gdb_prompt $" { pass "ptype Bar" } -re "type = <(class |)T, (class |)sz> (class |)Bar \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*T t;\r\n\\}\r\n$gdb_prompt $" { xfail "ptype Bar" } - -re "ptype Bar\r\ntype = class Bar {\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 $" + -re "ptype Bar\r\ntype = class Bar {\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 $" { # GCC 3.1, DWARF-2 output. kfail "gdb/57" "ptype Bar" } -re "No symbol \"Bar\" in current context.\r\n$gdb_prompt $" @@ -367,7 +373,7 @@ gdb_expect { send_gdb "ptype bint\n" gdb_expect { - -re "type = (class |)Bar \\{\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 \\{\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" } } @@ -376,7 +382,7 @@ gdb_expect { send_gdb "ptype bint2\n" gdb_expect { - -re "type = (class |)Bar \\{\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 \\{\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" } } @@ -388,7 +394,7 @@ send_gdb "ptype Baz\n" gdb_expect { -re "type = template <(class |)T, (class |)sz> (class |)Baz \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*T t;\r\n\\}\r\ntemplate instantiations:\r\n\[ \t\]*(class |)Baz\r\n\[ \t\]*(class |)Baz\r\n$gdb_prompt $" { pass "ptype Baz" } -re "type = <(class |)T, (class |)sz> (class |)Baz \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*T t;\r\n\\}\r\n$gdb_prompt $" { xfail "ptype Baz" } - -re "type = class Baz {\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 $" + -re "type = class Baz {\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 $" { # GCC 3.1, DWARF-2 output. kfail "gdb/57" "ptype Baz" } -re "No symbol \"Baz\" in current context.\r\n$gdb_prompt $" @@ -403,7 +409,7 @@ gdb_expect { send_gdb "ptype bazint\n" gdb_expect { - -re "type = (class |)Baz \\{\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 \\{\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" } } @@ -412,7 +418,7 @@ gdb_expect { send_gdb "ptype bazint2\n" gdb_expect { - -re "type = (class |)Baz \\{\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 \\{\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" } } @@ -423,7 +429,7 @@ send_gdb "ptype Qux\n" gdb_expect { -re "type = template <(class |)T, (class |)sz> (class |)Qux \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*T t;\r\n\\}\r\ntemplate instantiations:\r\n\[ \t\]*(class |)Qux\r\n\[ \t\]*(class |)Qux\r\n$gdb_prompt $" { pass "ptype Qux" } -re ".*type = template <(class |)T.*, (class |)sz> (class |)Qux \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*T t;\r\n\\}.*$gdb_prompt $" { pass "ptype Qux" } - -re "type = class Qux {\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*char t;\r\n\r\n\[ \t\]*char qux\\(int, char\\);\r\n}\r\n$gdb_prompt $" + -re "type = class Qux {\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*char t;\r\n\r\n\[ \t\]*char qux\\(int, char\\);\r\n}\r\n$gdb_prompt $" { # GCC 3.1, DWARF-2 output. kfail "gdb/57" "ptype Qux" } -re "No symbol \"Qux\" in current context.\r\n$gdb_prompt $" @@ -437,7 +443,7 @@ gdb_expect { send_gdb "ptype quxint\n" gdb_expect { - -re "type = class Qux \\{\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 \\{\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" } } @@ -448,7 +454,7 @@ gdb_expect { # templates.exp -- ovidiu # send_gdb "ptype quxint2\n" # gdb_expect { -# -re "type = class Qux \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*char t;\r\n\r\n\[ \t\]*char qux\\(int, char\\);\r\n\\}\r\n$gdb_prompt $" { pass "ptype quxint2" } +# -re "type = class Qux \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*char t;\r\n\r\n\[ \t\]*char qux\\(int, char\\);\r\n\\}\r\n$gdb_prompt $" { pass "ptype quxint2" } # -re "$gdb_prompt $" { fail "ptype quxint2" } # timeout { fail "(timeout) ptype quxint2" } # } @@ -460,7 +466,7 @@ send_gdb "ptype Spec\n" gdb_expect { -re "type = template <(class |)T1, (class |)T2> (class |)Spec \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\\}\r\ntemplate instantiations:\r\n\[ \t\]*(class |)Spec\r\n\[ \t\]*(class |)Spec\r\n$gdb_prompt $" { pass "ptype Spec" } -re "type = <(class |)T1, (class |)T2> (class |)Spec \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\\}\r\n$gdb_prompt $" { xfail "ptype Spec" } - -re "type = class Spec {\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\r\n\[ \t\]*int spec\\(char\\);\r\n}\r\n$gdb_prompt $" + -re "type = class Spec {\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\r\n\[ \t\]*int spec\\(char\\);\r\n}\r\n$gdb_prompt $" { # GCC 3.1, DWARF-2 output. kfail "gdb/57" "ptype Spec" } -re "No symbol \"Spec\" in current context.\r\n$gdb_prompt $" @@ -474,7 +480,7 @@ gdb_expect { send_gdb "ptype siip\n" gdb_expect { - -re "type = class Spec \\{\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 \\{\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" } }