gdb: Improve output from "info types" commad
[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                  "59:\[\t \]+CL;" \
61                  "21:\[\t \]+baz_t;" \
62                  "33:\[\t \]+enum_t;" \
63                  "28:\[\t \]+typedef baz_t baz;" \
64                  "31:\[\t \]+typedef baz_t \\* baz_ptr;" \
65                  "27:\[\t \]+typedef baz_t baz_t;" \
66                  "\[\t \]+double" \
67                  "\[\t \]+float" \
68                  "\[\t \]+int" \
69                  "64:\[\t \]+typedef CL my_cl;" \
70                  "38:\[\t \]+typedef enum_t my_enum_t;" \
71                  "17:\[\t \]+typedef float my_float_t;" \
72                  "16:\[\t \]+typedef int my_int_t;" \
73                  "65:\[\t \]+typedef CL \\* my_ptr;" \
74                  "30:\[\t \]+typedef baz_t nested_baz;" \
75                  "29:\[\t \]+typedef baz_t nested_baz_t;" \
76                  "39:\[\t \]+typedef enum_t nested_enum_t;" \
77                  "19:\[\t \]+typedef float nested_float_t;" \
78                  "18:\[\t \]+typedef int nested_int_t;" \
79                  "\[\t \]+unsigned int"]
80     } else {
81         set output_re \
82             [multi_line \
83                  "All defined types:" \
84                  "" \
85                  "File .*:" \
86                  "28:\[\t \]+typedef struct baz_t baz;" \
87                  "31:\[\t \]+typedef struct baz_t \\* baz_ptr;" \
88                  "21:\[\t \]+struct baz_t;" \
89                  "\[\t \]+double" \
90                  "33:\[\t \]+enum enum_t;" \
91                  "\[\t \]+float" \
92                  "\[\t \]+int" \
93                  "38:\[\t \]+typedef enum enum_t my_enum_t;" \
94                  "17:\[\t \]+typedef float my_float_t;" \
95                  "16:\[\t \]+typedef int my_int_t;" \
96                  "30:\[\t \]+typedef struct baz_t nested_baz;" \
97                  "29:\[\t \]+typedef struct baz_t nested_baz_t;" \
98                  "39:\[\t \]+typedef enum enum_t nested_enum_t;" \
99                  "19:\[\t \]+typedef float nested_float_t;" \
100                  "18:\[\t \]+typedef int nested_int_t;" \
101                  "\[\t \]+unsigned int" ]
102     }
103
104     gdb_test "info types" $output_re
105 }
106
107 foreach_with_prefix l $lang {
108     run_test $l
109 }