]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Fix gdb.lookup_type for function-local types
authorHannes Domani <ssbssa@yahoo.de>
Mon, 24 Jun 2024 16:45:37 +0000 (18:45 +0200)
committerHannes Domani <ssbssa@yahoo.de>
Mon, 24 Jun 2024 16:45:37 +0000 (18:45 +0200)
Looking for a type defined locally in a function doesn't work
any more since the introduction of TYPE_DOMAIN:
```
(gdb) python print (gdb.lookup_type ('main()::Local'))
Python Exception <class 'gdb.error'>: No type named main()::Local.
Error occurred in Python: No type named main()::Local.
```

cp_search_static_and_baseclasses was simply missing a check for
SEARCH_TYPE_DOMAIN, now it works again:
```
(gdb) python print (gdb.lookup_type ('main()::Local'))
Local
```

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31922
Approved-By: Tom Tromey <tom@tromey.com>
gdb/cp-namespace.c
gdb/testsuite/gdb.python/py-type.c
gdb/testsuite/gdb.python/py-type.exp

index 89c1bbd9a59db82d6d6a11aad255dd4fac11c7f8..9d86fe2722863e6dccc197b2dff4f3ba1d0852b1 100644 (file)
@@ -287,10 +287,10 @@ cp_search_static_and_baseclasses (const char *name,
   struct type *scope_type = scope_sym.symbol->type ();
 
   /* If the scope is a function/method, then look up NESTED as a local
-     static variable.  E.g., "print 'function()::static_var'".  */
+     static variable or type.  E.g., "print 'function()::static_var'".  */
   if ((scope_type->code () == TYPE_CODE_FUNC
        || scope_type->code () == TYPE_CODE_METHOD)
-      && (domain & SEARCH_VAR_DOMAIN) != 0)
+      && (domain & (SEARCH_VAR_DOMAIN | SEARCH_TYPE_DOMAIN)) != 0)
     return lookup_symbol (nested, scope_sym.symbol->value_block (),
                          domain, NULL);
 
index bedabc68758c49917b3dc14d2665d893bd039a1d..7a0df8ad80b06c06d8253fc9860bf15a8de3ced8 100644 (file)
@@ -118,6 +118,11 @@ main ()
   c.a_method (0, 1);
   c.a_const_method (0, 1);
   C::a_static_method (0, 1);
+
+  struct Local { int g; } l;
+  l.g = 5;
+  typedef int IntType;
+  IntType it = 6;
 #endif
   enum E e;
 
index 74e123441c4509c9e24a02c70d4f7292e2e6cd12..e524959e3a0140122773652fdc24636bee2f0a7e 100644 (file)
@@ -85,6 +85,12 @@ proc test_fields {lang} {
       gdb_test "python print (gdb.parse_and_eval ('C::a_static_method').type.fields ()\[0\].type)" "int"
       gdb_test "python print (gdb.parse_and_eval ('C::a_static_method').type.fields ()\[1\].type)" "char"
       gdb_test "python print (gdb.parse_and_eval ('c')\['a_static_method'\].type.fields ()\[0\].type)" "int"
+
+      # Test function-local types.
+      gdb_test "python print (gdb.lookup_type ('main()::Local'))" "Local"
+      gdb_test "python print (gdb.lookup_type ('main()::Local').fields ()\[0\].type)" "int"
+      gdb_test "python print (gdb.lookup_type ('main()::IntType'))" "IntType"
+      gdb_test "python print (gdb.lookup_type ('main()::IntType').target ())" "int"
     }
 
     # Test normal fields usage in structs.