try
{
if (startswith (type_name, "struct "))
- type = lookup_struct (type_name + 7, NULL);
+ type = lookup_struct (type_name + 7, block);
else if (startswith (type_name, "union "))
- type = lookup_union (type_name + 6, NULL);
+ type = lookup_union (type_name + 6, block);
else if (startswith (type_name, "enum "))
- type = lookup_enum (type_name + 5, NULL);
+ type = lookup_enum (type_name + 5, block);
else
type = lookup_typename (current_language,
type_name, block, 0);
--- /dev/null
+# Copyright (C) 2025 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# Test the 'block' argument to gdb.lookup_type.
+
+load_lib gdb-python.exp
+
+require allow_python_tests
+
+standard_testfile lookup1.c lookup2.c
+
+if {[prepare_for_testing "failed to prepare" ${testfile} \
+ [list $srcfile $srcfile2]]} {
+ return
+}
+
+proc check_type {which type_name} {
+ if {$which == "one"} {
+ set fn_name function
+ } else {
+ set fn_name main
+ }
+
+ gdb_test_no_output \
+ "python block = gdb.decode_line(\"$fn_name\")\[1\]\[0\].symtab.static_block()" \
+ "compute block"
+ gdb_test_no_output \
+ "python ty = gdb.lookup_type(\"$type_name\", block).strip_typedefs()" \
+ "find the type"
+ gdb_test "python print(ty.fields()\[0\].name)" \
+ "$which" \
+ "examine first field"
+}
+
+proc check_all_types {} {
+ foreach_with_prefix which {one two} {
+ foreach_with_prefix type_name {
+ "struct the_struct"
+ "enum the_enum"
+ "union the_union"
+ "the_typedef"
+ } {
+ check_type $which $type_name
+ }
+ }
+}
+
+check_all_types
+
+if {![runto_main]} {
+ return
+}
+
+with_test_prefix "while running" {
+ check_all_types
+}
--- /dev/null
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2025 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+struct the_struct {
+ int one;
+};
+
+struct the_struct struct1;
+
+enum the_enum {
+ one
+};
+
+enum the_enum enum1;
+
+union the_union {
+ int one;
+ void *ptr;
+};
+
+union the_union union1;
+
+typedef struct the_struct the_typedef;
+
+the_typedef typedef1;
+
+int function (void)
+{
+ return 0;
+}
--- /dev/null
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2025 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+struct the_struct {
+ int two;
+};
+
+struct the_struct struct2;
+
+enum the_enum {
+ two
+};
+
+enum the_enum enum2;
+
+union the_union {
+ int two;
+ void *ptr;
+};
+
+union the_union union2;
+
+typedef struct the_struct the_typedef;
+
+the_typedef typedef2;
+
+extern int function (void);
+
+int main (void)
+{
+ return function ();
+}