From e8db803129822d3df8e773f28dd99105a84d881d Mon Sep 17 00:00:00 2001 From: Christina Schimpe Date: Mon, 25 Oct 2021 17:08:32 +0200 Subject: gdb: Use a typedef's scoped type name to identify local typedefs GDB prints the wrong type for typedefs in case there is another typedef available for the same raw type (gdb/16040). The reason is that the current hashmap based substitution mechanism always compares the target type of a typedef and not its scoped name. The original output of GDB for a program like ~~~~ namespace ns { typedef double scoped_double; } typedef double global_double; class TypedefHolder { public: double a; ns::scoped_double b; global_double c; private: typedef double class_double; class_double d; double method1(ns::scoped_double) { return 24.0; } double method2(global_double) { return 24.0; } }; int main() { TypedefHolder th; return 0; } ~~~~ is ~~~~ (gdb) b 27 Breakpoint 1 at 0x1131: file TypedefHolder.cc, line 27. (gdb) r Starting program: /tmp/typedefholder Breakpoint 1, main () at TypedefHolder.cc:27 27 return 0; (gdb) ptype th type = class TypedefHolder { public: class_double a; class_double b; class_double c; private: class_double d; class_double method1(class_double); class_double method2(class_double); typedef double class_double; } ~~~~ Basically all attributes of a class which have the raw type "double" are substituted by "class_double". With the patch the output is the following ~~~~ type = class TypedefHolder { public: double a; ns::scoped_double b; global_double c; private: class_double d; double method1(ns::scoped_double); double method2(global_double); typedef double class_double; } ~~~~ --- gdb/typeprint.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'gdb/typeprint.c') diff --git a/gdb/typeprint.c b/gdb/typeprint.c index 8cb34ad1921..0282ff632f1 100644 --- a/gdb/typeprint.c +++ b/gdb/typeprint.c @@ -201,9 +201,8 @@ static hashval_t hash_typedef_field (const void *p) { const struct decl_field *tf = (const struct decl_field *) p; - struct type *t = check_typedef (tf->type); - return htab_hash_string (TYPE_SAFE_NAME (t)); + return htab_hash_string (TYPE_SAFE_NAME (tf->type)); } /* An equality function for a typedef field. */ -- cgit v1.2.1