]>
Commit | Line | Data |
---|---|---|
213516ef | 1 | # Copyright 2020-2023 Free Software Foundation, Inc. |
f68f85b5 PA |
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 | # This file tests GDB's ability to replace typedefs in C++ symbols | |
17 | # when setting breakpoints, particularly around templates in | |
18 | # namespaces. | |
19 | ||
20 | load_lib completion-support.exp | |
21 | ||
22 | standard_testfile .cc | |
23 | ||
24 | if {[prepare_for_testing "failed to prepare" $testfile $srcfile \ | |
25 | {debug c++ additional_flags=-std=c++11}]} { | |
26 | return -1 | |
27 | } | |
28 | ||
29 | # Disable the completion limit for the whole testcase. | |
30 | gdb_test_no_output "set max-completions unlimited" | |
31 | ||
32 | # Confirm that the important global namespace typedefs were indeed | |
33 | # emited in the debug info. | |
34 | gdb_test "ptype NS2" "type = int" | |
35 | gdb_test "ptype object" "type = struct NS1::NS2::object {.*" | |
36 | gdb_test "ptype Templ1" "type = struct NS1::NS2::Templ1<unsigned int> .*" | |
37 | gdb_test "ptype AliasTempl" "type = struct NS1::NS2::Templ2<int, int> .*" | |
38 | ||
39 | # Wrapper around check_bp_locations_match_list that expect a single | |
40 | # location in the set breakpoint, instead of a list of locations. If | |
41 | # the set location isn't specified, then it is assumed to be the exact | |
42 | # same as the input location. | |
43 | proc check_bp {location_in {location_out ""}} { | |
44 | if {$location_out == ""} { | |
45 | set location_out $location_in | |
46 | } | |
47 | check_bp_locations_match_list "b $location_in" [list $location_out] | |
48 | } | |
49 | ||
50 | # These used to crash GDB with infinite recursion because GDB would | |
51 | # confuse the "Templ1" typedef in the global namespace with the "Templ1" | |
52 | # template in within NS1::NS2. | |
53 | test_gdb_complete_unique \ | |
54 | "break NS1::NS2::Templ1<int>::Tem" \ | |
55 | "break NS1::NS2::Templ1<int>::Templ1(NS1::NS2::object*)" | |
56 | check_bp "NS1::NS2::Templ1<int>::Templ1(NS1::NS2::object*)" | |
57 | ||
58 | # Similar test, but without a template. This would not crash. | |
59 | test_gdb_complete_unique \ | |
60 | "break NS1::NS2::object::obj" \ | |
61 | "break NS1::NS2::object::object()" | |
62 | check_bp "NS1::NS2::object::object()" | |
63 | ||
64 | # Test some non-template typedef replacing within a namespace. | |
65 | test_gdb_complete_unique \ | |
66 | "break NS1::NS2::object_p_f" \ | |
67 | "break NS1::NS2::object_p_func(NS1::NS2::object*)" | |
68 | check_bp \ | |
69 | "NS1::NS2::object_p_func(NS1::NS2::object_p)" \ | |
70 | "NS1::NS2::object_p_func(NS1::NS2::object*)" | |
71 | ||
72 | # Make sure the "NS2" in the template argument list is resolved as | |
73 | # being a global typedef for int. | |
74 | foreach loc { | |
75 | "NS1::NS2::Templ1<int>::static_method<int>(NS1::NS2::object*)" | |
76 | "NS1::NS2::Templ1<int>::static_method<NS2>(NS1::NS2::object*)" | |
77 | "NS1::NS2::Templ1<NS2>::static_method<int>(NS1::NS2::object*)" | |
78 | "NS1::NS2::Templ1<NS2>::static_method<NS2>(NS1::NS2::object*)" | |
79 | } { | |
80 | check_bp $loc "NS1::NS2::Templ1<int>::static_method<int>(NS1::NS2::object*)" | |
81 | } | |
82 | ||
83 | foreach loc { | |
84 | "NS1::NS2::Templ2<int, int>::static_method<int>(NS1::NS2::object*)" | |
85 | "NS1::NS2::Templ2<int, int>::static_method<int>(NS1::NS2::object_p)" | |
86 | } { | |
87 | check_bp $loc "NS1::NS2::Templ2<int, int>::static_method<int>(NS1::NS2::object*)" | |
88 | } | |
89 | ||
90 | # Check that GDB expands the "NS1::NS2::AliasTempl<int>" as | |
91 | # "NS1::NS2::Templ2<int, int>". | |
92 | foreach loc { | |
93 | "NS1::NS2::AliasTempl<int>::static_method<int>(NS1::NS2::object*)" | |
94 | "NS1::NS2::AliasTempl<int>::static_method<int>(NS1::NS2::object_p)" | |
95 | } { | |
96 | if [test_compiler_info gcc*] { | |
97 | # While Clang emits "AliasTempl<int>" (etc.) typedefs, GCC | |
98 | # emits "AliasTempl" typedefs with no template parameter info. | |
99 | setup_xfail gcc/95437 *-*-* | |
100 | } | |
101 | check_bp $loc "NS1::NS2::Templ2<int, int>::static_method<int>(NS1::NS2::object*)" | |
102 | ||
103 | # Check that setting the breakpoint with GCC really failed, | |
104 | # instead of succeeding with e.g., "AliasTempl<int>" preserved in | |
105 | # the location text. If that ever happens, we'll need to update | |
106 | # these tests. | |
107 | if [test_compiler_info gcc*] { | |
108 | check_setting_bp_fails "b $loc" | |
109 | } | |
110 | } | |
111 | ||
112 | # Check typedef substitution in a template in a qualified name in a | |
113 | # function parameter list. These used to crash GDB with recursion | |
114 | # around "Templ1", because there's a "Templ1" typedef in the global | |
115 | # namespace. | |
116 | foreach loc { | |
117 | "NS1::NS2::int_Templ1_t_func(NS1::NS2::int_Templ1_t*)" | |
118 | "NS1::NS2::int_Templ1_t_func(NS1::NS2::Templ1<int>*)" | |
119 | } { | |
120 | check_bp $loc "NS1::NS2::int_Templ1_t_func(NS1::NS2::Templ1<int>*)" | |
121 | } |