gdb: Show type summary for anonymous structures from c_print_typedef
[external/binutils.git] / gdb / testsuite / gdb.base / info-types.exp
1 # Copyright 2019 Free Software Foundation, Inc.
2 #
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
16 # Check that 'info types' produces the expected output for an inferior
17 # containing a number of different types.
18
19 # Only test C++ if we are able.  Always use C.
20 if { [skip_cplus_tests] || [get_compiler_info "c++"] } {
21     set lang {c}
22 } else {
23     set lang {c c++}
24 }
25
26 foreach l $lang {
27     set dir "$l"
28     remote_exec host "rm -rf [standard_output_file ${dir}]"
29     remote_exec host "mkdir -p [standard_output_file ${dir}]"
30 }
31
32 # Run 'info types' test, compiling the test file for language LANG,
33 # which should be either 'c' or 'c++'.
34 proc run_test { lang } {
35     global testfile
36     global srcfile
37     global binfile
38     global subdir
39     global srcdir
40     global compile_flags
41
42     standard_testfile .c
43
44     if {[prepare_for_testing "failed to prepare" \
45              "${lang}/${testfile}" $srcfile "debug $lang"]} {
46         return -1
47     }
48
49     if ![runto_main] then {
50         fail "can't run to main"
51         return 0
52     }
53
54     if { $lang == "c++" } {
55         set output_re \
56             [multi_line \
57                  "All defined types:" \
58                  "" \
59                  "File .*:" \
60                  "98:\[\t \]+CL;" \
61                  "42:\[\t \]+anon_struct_t;" \
62                  "65:\[\t \]+anon_union_t;" \
63                  "21:\[\t \]+baz_t;" \
64                  "33:\[\t \]+enum_t;" \
65                  "56:\[\t \]+union_t;" \
66                  "52:\[\t \]+typedef enum {\\.\\.\\.} anon_enum_t;" \
67                  "45:\[\t \]+typedef anon_struct_t anon_struct_t;" \
68                  "68:\[\t \]+typedef anon_union_t anon_union_t;" \
69                  "28:\[\t \]+typedef baz_t baz;" \
70                  "31:\[\t \]+typedef baz_t \\* baz_ptr;" \
71                  "27:\[\t \]+typedef baz_t baz_t;" \
72                  "\[\t \]+double" \
73                  "\[\t \]+float" \
74                  "\[\t \]+int" \
75                  "103:\[\t \]+typedef CL my_cl;" \
76                  "38:\[\t \]+typedef enum_t my_enum_t;" \
77                  "17:\[\t \]+typedef float my_float_t;" \
78                  "16:\[\t \]+typedef int my_int_t;" \
79                  "104:\[\t \]+typedef CL \\* my_ptr;" \
80                  "54:\[\t \]+typedef enum {\\.\\.\\.} nested_anon_enum_t;" \
81                  "47:\[\t \]+typedef anon_struct_t nested_anon_struct_t;" \
82                  "70:\[\t \]+typedef anon_union_t nested_anon_union_t;" \
83                  "30:\[\t \]+typedef baz_t nested_baz;" \
84                  "29:\[\t \]+typedef baz_t nested_baz_t;" \
85                  "39:\[\t \]+typedef enum_t nested_enum_t;" \
86                  "19:\[\t \]+typedef float nested_float_t;" \
87                  "18:\[\t \]+typedef int nested_int_t;" \
88                  "62:\[\t \]+typedef union_t nested_union_t;" \
89                  "\[\t \]+unsigned int"]
90     } else {
91         set output_re \
92             [multi_line \
93                  "All defined types:" \
94                  "" \
95                  "File .*:" \
96                  "52:\[\t \]+typedef enum {\\.\\.\\.} anon_enum_t;" \
97                  "45:\[\t \]+typedef struct {\\.\\.\\.} anon_struct_t;" \
98                  "68:\[\t \]+typedef union {\\.\\.\\.} anon_union_t;" \
99                  "28:\[\t \]+typedef struct baz_t baz;" \
100                  "31:\[\t \]+typedef struct baz_t \\* baz_ptr;" \
101                  "21:\[\t \]+struct baz_t;" \
102                  "\[\t \]+double" \
103                  "33:\[\t \]+enum enum_t;" \
104                  "\[\t \]+float" \
105                  "\[\t \]+int" \
106                  "38:\[\t \]+typedef enum enum_t my_enum_t;" \
107                  "17:\[\t \]+typedef float my_float_t;" \
108                  "16:\[\t \]+typedef int my_int_t;" \
109                  "54:\[\t \]+typedef enum {\\.\\.\\.} nested_anon_enum_t;" \
110                  "47:\[\t \]+typedef struct {\\.\\.\\.} nested_anon_struct_t;" \
111                  "70:\[\t \]+typedef union {\\.\\.\\.} nested_anon_union_t;" \
112                  "30:\[\t \]+typedef struct baz_t nested_baz;" \
113                  "29:\[\t \]+typedef struct baz_t nested_baz_t;" \
114                  "39:\[\t \]+typedef enum enum_t nested_enum_t;" \
115                  "19:\[\t \]+typedef float nested_float_t;" \
116                  "18:\[\t \]+typedef int nested_int_t;" \
117                  "62:\[\t \]+typedef union union_t nested_union_t;" \
118                  "56:\[\t \]+union union_t;" \
119                  "\[\t \]+unsigned int" ]
120     }
121
122     gdb_test "info types" $output_re
123 }
124
125 foreach_with_prefix l $lang {
126     run_test $l
127 }