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