gdb: Show type summary for anonymous structures from c_print_typedef
[external/binutils.git] / gdb / testsuite / gdb.ada / info_auto_lang.exp
1 # Copyright 2018-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 load_lib "ada.exp"
17
18 # This test verifies that the commands
19 #   info [functions|variables|types]
20 # respect the 'set language auto|ada|c' setting, whatever the language
21 # of the current frame.
22 # Similarly, checks that rbreak reports its results respecting
23 # the language mode.
24
25 standard_ada_testfile proc_in_ada
26 set cfile "some_c"
27 # gnat normalizes proc_in_ada source file when compiling.
28 # As the 'info' commands results are sorted by absolute path names, also normalize
29 # the some_c source file to ensure that the 'info' results are always
30 # giving Ada results first.
31 set csrcfile [file normalize ${srcdir}/${subdir}/${testdir}/${cfile}.c]
32 set cobject [standard_output_file ${cfile}.o]
33
34 if { [gdb_compile "${csrcfile}" "${cobject}" object [list debug]] != "" } {
35     untested "failed to compile"
36     return -1
37 }
38 if {[gdb_compile_ada "${srcfile}" "${binfile}" executable [list debug]] != "" } {
39     untested "failed to compile"
40     return -1
41 }
42
43 clean_restart ${testfile}
44
45 set bp_location [gdb_get_line_number "STOP" ${testdir}/some_c.c]
46 if ![runto "some_c.c:$bp_location"] then {
47     fail "can't run to some_c.c STOP location"
48     return
49 }
50
51 set func_in_c(c_syntax)      "${decimal}:       void proc_in_c\\\(void\\\);"
52 set func_in_c(ada_syntax)    "${decimal}:       procedure proc_in_c;"
53 set func_in_ada(c_syntax)    "${decimal}:       void proc_in_ada\\\(void\\\);"
54 set func_in_ada(ada_syntax)  "${decimal}:       procedure proc_in_ada;"
55
56 set type_in_c(c_syntax) "${decimal}:    typedef struct {\\.\\.\\.} some_type_in_c;"
57 set type_in_c(ada_syntax) [multi_line \
58                               "${decimal}:      record" \
59                               "    some_component_in_c: int;" \
60                               "end record" ]
61 set type_in_ada(c_syntax) "${decimal}:  struct global_pack__some_type_in_ada;"
62 set type_in_ada(ada_syntax)  "${decimal}:       global_pack.some_type_in_ada;"
63
64 set var_in_c(c_syntax)     "${decimal}: some_type_in_c some_struct_in_c;"
65 set var_in_c(ada_syntax)   "${decimal}: some_struct_in_c: some_type_in_c;"
66 set var_in_ada(c_syntax)   "${decimal}: struct global_pack__some_type_in_ada global_pack.some_struct_in_ada;"
67 set var_in_ada(ada_syntax) "${decimal}: global_pack.some_struct_in_ada: global_pack.some_type_in_ada;"
68
69 set rbreak_func_in_c(c_syntax)      "void proc_in_c\\\(void\\\);"
70 set rbreak_func_in_c(ada_syntax)    "procedure proc_in_c;"
71 set rbreak_func_in_ada(c_syntax)    "void proc_in_ada\\\(void\\\);"
72 set rbreak_func_in_ada(ada_syntax)  "procedure proc_in_ada;"
73
74
75 foreach_with_prefix language_choice { "auto" "ada" "c" } {
76
77     # Check that switching to the desired language_choice when the selected
78     # frame has the same language (or the desired language is auto) gives no
79     # warning.  Also set the expected matches for the various commands
80     # tested afterwards.
81     if {$language_choice == "auto"} {
82         gdb_test "frame 0" "#0 .*" "select frame with lang c"
83         set c_match c_syntax
84         set ada_match ada_syntax
85     } elseif {$language_choice == "ada"} {
86         gdb_test "frame 1" "#1 .*" "select frame with lang ada"
87         set c_match ada_syntax
88         set ada_match ada_syntax
89     } elseif {$language_choice == "c"} {
90         gdb_test "frame 0" "#0 .*" "select frame with lang c"
91         set c_match c_syntax
92         set ada_match c_syntax
93     } else {
94         error "unexpected language choice"
95     }
96     gdb_test_no_output "set language $language_choice" "set language language_choice"
97
98     foreach frame {
99         "0"
100         "1" } {
101         if { $frame == 0 } {
102             set frame_lang "c"
103         } else {
104             set frame_lang "ada"
105         }
106
107         with_test_prefix "frame=$frame, frame_lang=$frame_lang" {
108
109             gdb_test "frame $frame" "#$frame .*" "select frame"
110
111             gdb_test "info functions proc_in_" \
112                 [multi_line \
113                      "All functions matching regular expression \"proc_in_\":" \
114                      "" \
115                      "File .*proc_in_ada.adb:" \
116                      $func_in_ada($ada_match) \
117                      "" \
118                      "File .*some_c.c:" \
119                      $func_in_c($c_match)
120                 ]
121
122             gdb_test "info types some_type" \
123                 [multi_line \
124                      "All types matching regular expression \"some_type\":"  \
125                      "" \
126                      "File .*global_pack.ads:" \
127                      $type_in_ada($ada_match)\
128                      "" \
129                      "File .*some_c.c:" \
130                      $type_in_c($c_match)
131                 ]
132
133             gdb_test "info variables some_struct" \
134                 [multi_line \
135                      "All variables matching regular expression \"some_struct\":" \
136                      "" \
137                      "File .*global_pack.ads:" \
138                      $var_in_ada($ada_match) \
139                      "" \
140                      "File .*some_c.c:" \
141                      $var_in_c($c_match)
142                 ]
143
144             gdb_test "rbreak proc_in_" \
145                 [multi_line \
146                      "Breakpoint.*file .*proc_in_ada.adb,.*" \
147                      $rbreak_func_in_ada($ada_match) \
148                      "Breakpoint.*file .*some_c.c,.*" \
149                      $rbreak_func_in_c($c_match)
150                 ]
151             delete_breakpoints
152         }
153     }
154 }
155