Commit | Line | Data |
---|---|---|
11bc5fe4 | 1 | # Copyright 2014-2020 Free Software Foundation, Inc. |
883964a7 SC |
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 is part of the GDB testsuite. It tests the debug methods | |
17 | # feature in the Python extension language. | |
18 | ||
19 | load_lib gdb-python.exp | |
20 | ||
23e82930 LM |
21 | if { [skip_cplus_tests] } { |
22 | untested "skipping C++ tests" | |
23 | return | |
24 | } | |
883964a7 SC |
25 | |
26 | standard_testfile py-xmethods.cc | |
27 | ||
5b362f04 | 28 | if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug c++}]} { |
883964a7 SC |
29 | return -1 |
30 | } | |
31 | ||
32 | # Skip all tests if Python scripting is not enabled. | |
23e82930 LM |
33 | if { [skip_python_tests] } { |
34 | untested "skipping Python tests" | |
35 | return | |
36 | } | |
883964a7 SC |
37 | |
38 | if ![runto_main] { | |
39 | return -1 | |
40 | } | |
41 | ||
42 | set xmethods_script [gdb_remote_download host \ | |
43 | ${srcdir}/${subdir}/${testfile}.py] | |
44 | ||
45 | gdb_breakpoint [gdb_get_line_number "Break here."] | |
46 | gdb_continue_to_breakpoint "Break here" ".*Break here.*" | |
47 | ||
48 | # Tests before loading the debug methods. | |
cdc7edd7 LM |
49 | gdb_test "p a1 + a2" ".* = 15" "before: a1 + a2" |
50 | gdb_test "p a_plus_a" ".* = 1" "before: a_plus_a 1" | |
5d376983 | 51 | |
cdc7edd7 LM |
52 | gdb_test "p a2 - a1" ".* = 5" "before: a2 - a1" |
53 | gdb_test "p a_minus_a" ".* = 1" "before: a_minus_a 1" | |
5d376983 | 54 | |
cdc7edd7 LM |
55 | gdb_test "p b1 - a1" ".* = 25" "before: b1 - a1" |
56 | gdb_test "p a_minus_a" ".* = 2" "before: a_minus_a 2" | |
5d376983 | 57 | |
cdc7edd7 LM |
58 | gdb_test "p a1.geta()" ".* = 5" "before: a1.geta()" |
59 | gdb_test "p a_geta" ".* = 1" "before: a_geta 1" | |
5d376983 | 60 | |
cdc7edd7 | 61 | gdb_test "p ++a1" "No symbol.*" "before: ++a1" |
883964a7 | 62 | gdb_test "p a1.getarrayind(5)" "Couldn't find method.*" \ |
23e82930 | 63 | "before: a1.getarrayind(5)" |
5d376983 | 64 | |
cdc7edd7 LM |
65 | gdb_test "p a_ptr->geta()" ".* = 60" "before: a_ptr->geta()" |
66 | gdb_test "p b_geta" ".* = 1" "before: b_geta 1" | |
5d376983 | 67 | |
cdc7edd7 LM |
68 | gdb_test "p e.geta()" ".* = 100" "before: e.geta()" |
69 | gdb_test "p a_geta" ".* = 2" "before: a_geta 2" | |
5d376983 SC |
70 | |
71 | # Since g.size_diff operates of sizes of int and float, do not check for | |
72 | # actual result value as it could be different on different platforms. | |
cdc7edd7 LM |
73 | gdb_test "p g.size_diff<float>()" ".*" "before: call g.size_diff<float>()" |
74 | gdb_test "p g_size_diff" ".* = 2" "before: g_size_diff 2" | |
5d376983 | 75 | |
883964a7 | 76 | gdb_test "p g.size_diff<unsigned long>()" "Couldn't find method.*" \ |
23e82930 | 77 | "before: g.size_diff<unsigned long>()" |
5d376983 | 78 | |
cdc7edd7 LM |
79 | gdb_test "p g.size_mul<2>()" ".*" "before: g.size_mul<2>()" |
80 | gdb_test "p g_size_mul" ".* = 2" "before: g_size_mul 2" | |
5d376983 | 81 | |
883964a7 | 82 | gdb_test "p g.size_mul<5>()" "Couldn't find method.*" \ |
23e82930 | 83 | "before: g.size_mul<5>()" |
5d376983 | 84 | |
cdc7edd7 LM |
85 | gdb_test "p g.mul<double>(2.0)" ".* = 10" "before: g.mul<double>(2.0)" |
86 | gdb_test "p g_mul" ".* = 2" "before: g_mul 2" | |
5d376983 | 87 | |
883964a7 | 88 | gdb_test "p g.mul<char>('a')" "Couldn't find method.*" \ |
23e82930 | 89 | "before: g.mul<char>('a')" |
883964a7 SC |
90 | |
91 | # Load the script which adds the debug methods. | |
92 | gdb_test_no_output "source ${xmethods_script}" "load the script file" | |
93 | ||
94 | # Tests after loading debug methods. | |
cdc7edd7 | 95 | gdb_test "p a1 + a2" "From Python <A_plus_A>.*15" "after: a1 + a2" |
5d376983 | 96 | |
cdc7edd7 LM |
97 | gdb_test "p a2 - a1" ".* = 5" "after: a2 - a1" |
98 | gdb_test "p a_minus_a" ".* = 3" "after: a_minus_a 3" | |
5d376983 | 99 | |
cdc7edd7 | 100 | gdb_test "p b1 + a1" "From Python <A_plus_A>.*35" "after: b1 + a1" |
5d376983 | 101 | |
cdc7edd7 LM |
102 | gdb_test "p b1 - a1" ".* = 25" "after: b1 - a1" |
103 | gdb_test "p a_minus_a" ".* = 4" "after: a_minus_a 4" | |
5d376983 | 104 | |
cdc7edd7 LM |
105 | gdb_test "p a1.geta()" "From Python <A_geta>.*5" "after: a1.geta()" |
106 | gdb_test "p ++a1" "From Python <plus_plus_A>.*6" "after: ++a1" | |
883964a7 | 107 | gdb_test "p a1.getarrayind(5)" "From Python <A_getarrayind>.*5" \ |
23e82930 | 108 | "after: a1.getarrayind(5)" |
b964bee0 TT |
109 | gdb_test "p a1\[6\]" ".*int &.*6" "after a1\[\]" |
110 | gdb_test "p b1\[7\]" ".*const int &.*7" "after b1\[\]" | |
883964a7 SC |
111 | # Note the following test. Xmethods on dynamc types are not looked up |
112 | # currently. Hence, even though a_ptr points to a B object, the xmethod | |
113 | # defined for A objects is invoked. | |
cdc7edd7 LM |
114 | gdb_test "p a_ptr->geta()" "From Python <A_geta>.*30" "after: a_ptr->geta()" |
115 | gdb_test "p e.geta()" "From Python <A_geta>.*100" "after: e.geta()" | |
116 | gdb_test "p e_ptr->geta()" "From Python <A_geta>.*100" "after: e_ptr->geta()" | |
117 | gdb_test "p e_ref.geta()" "From Python <A_geta>.*100" "after: e_ref.geta()" | |
2ce1cdbf | 118 | gdb_test "p e.method(10)" "From Python <E_method_int>.* = void" \ |
23e82930 | 119 | "after: e.method(10)" |
2ce1cdbf | 120 | gdb_test "p e.method('a')" "From Python <E_method_char>.* = void" \ |
23e82930 | 121 | "after: e.method('a')" |
883964a7 | 122 | gdb_test "p g.size_diff<float> ()" "From Python G<>::size_diff.*" \ |
23e82930 | 123 | "after: g.size_diff<float>()" |
883964a7 | 124 | gdb_test "p g.size_diff< unsigned long >()" "From Python G<>::size_diff.*" \ |
23e82930 | 125 | "after: g.size_diff<unsigned long>()" |
883964a7 | 126 | gdb_test "p g.size_mul<2>()" "From Python G<>::size_mul.*" \ |
23e82930 | 127 | "after: g.size_mul<2>()" |
883964a7 | 128 | gdb_test "p g.size_mul< 5 >()" "From Python G<>::size_mul.*" \ |
23e82930 | 129 | "after: g.size_mul< 5 >()" |
883964a7 | 130 | gdb_test "p g.mul<double>(2.0)" "From Python G<>::mul.*" \ |
23e82930 | 131 | "after: g.mul<double>(2.0)" |
883964a7 SC |
132 | gdb_test "p g.mul<char>('a')" "From Python G<>::mul.*" \ |
133 | gdb_test "p g_ptr->mul<char>('a')" "From Python G<>::mul.*" \ | |
bb95117e | 134 | "after: g_ptr->mul<char>('a')" |
883964a7 SC |
135 | |
136 | # Tests for 'disable/enable xmethod' command. | |
70afc5b7 | 137 | gdb_test_no_output "disable xmethod progspace G_methods" \ |
23e82930 | 138 | "disable G_methods" |
883964a7 SC |
139 | gdb_test "p g.mul<char>('a')" "Couldn't find method.*" \ |
140 | "g.mul<char>('a') after disabling G_methods" | |
70afc5b7 | 141 | gdb_test_no_output "enable xmethod progspace G_methods" \ |
23e82930 | 142 | "dnable G_methods" |
883964a7 | 143 | gdb_test "p g.mul<char>('a')" "From Python G<>::mul.*" \ |
23e82930 | 144 | "after enabling G_methods" |
70afc5b7 | 145 | gdb_test_no_output "disable xmethod progspace G_methods;mul" \ |
23e82930 | 146 | "disable G_methods;mul" |
883964a7 SC |
147 | gdb_test "p g.mul<char>('a')" "Couldn't find method.*" \ |
148 | "g.mul<char>('a') after disabling G_methods;mul" | |
70afc5b7 | 149 | gdb_test_no_output "enable xmethod progspace G_methods;mul" \ |
23e82930 | 150 | "enable G_methods;mul" |
883964a7 | 151 | gdb_test "p g.mul<char>('a')" "From Python G<>::mul.*" \ |
23e82930 | 152 | "after enabling G_methods;mul" |
883964a7 SC |
153 | |
154 | # Test for 'info xmethods' command | |
155 | gdb_test "info xmethod global plus" "global.*plus_plus_A" \ | |
156 | "info xmethod global plus 1" | |
70afc5b7 SC |
157 | gdb_test_no_output "disable xmethod progspace E_methods;method_int" \ |
158 | "disable xmethod progspace E_methods;method_int" | |
159 | gdb_test "info xmethod progspace E_methods;method_int" ".* \\\[disabled\\\]" \ | |
883964a7 | 160 | "info xmethod xmethods E_methods;method_int" |
9f058c10 | 161 | gdb_test_no_output "disable xmethod progspace G_methods" "disable G_methods 2" |
d1e36019 | 162 | gdb_test "info xmethod progspace" ".*G_methods \\\[disabled\\\].*" |
2ce1cdbf DE |
163 | |
164 | # PR 18285 | |
165 | # First make sure both are enabled. | |
166 | gdb_test_no_output "enable xmethod progspace E_methods;method_char" | |
167 | gdb_test_no_output "enable xmethod progspace E_methods;method_int" | |
168 | gdb_test "pt e.method('a')" "type = void" | |
169 | gdb_test "pt e.method(10)" \ | |
170 | "NotImplementedError.*Error while fetching result type of an xmethod worker defined in Python." |