packaging: Add python3-base dependency
[platform/upstream/gdb.git] / gdb / testsuite / gdb.python / py-xmethods.exp
1 # Copyright 2014-2023 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 # 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] } {
22     untested "skipping C++ tests"
23     return
24 }
25
26 standard_testfile py-xmethods.cc
27
28 if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug c++}]} {
29     return -1
30 }
31
32 # Skip all tests if Python scripting is not enabled.
33 if { [skip_python_tests] } {
34     untested "skipping Python tests"
35     return
36 }
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.
49 gdb_test "p a1 + a2" ".* = 15" "before: a1 + a2"
50 gdb_test "p a_plus_a" ".* = 1" "before: a_plus_a 1"
51
52 gdb_test "p a2 - a1" ".* = 5" "before: a2 - a1"
53 gdb_test "p a_minus_a" ".* = 1" "before: a_minus_a 1"
54
55 gdb_test "p b1 - a1" ".* = 25" "before: b1 - a1"
56 gdb_test "p a_minus_a" ".* = 2" "before: a_minus_a 2"
57
58 gdb_test "p a1.geta()" ".* = 5" "before: a1.geta()"
59 gdb_test "p a_geta" ".* = 1" "before: a_geta 1"
60
61 gdb_test "p ++a1" "No symbol.*" "before: ++a1"
62 gdb_test "p a1.getarrayind(5)" "Couldn't find method.*" \
63   "before: a1.getarrayind(5)"
64
65 gdb_test "p a_ptr->geta()" ".* = 60" "before: a_ptr->geta()"
66 gdb_test "p b_geta" ".* = 1" "before: b_geta 1"
67
68 gdb_test "p e.geta()" ".* = 100" "before: e.geta()"
69 gdb_test "p a_geta" ".* = 2" "before: a_geta 2"
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.
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"
75
76 gdb_test "p g.size_diff<unsigned long>()" "Couldn't find method.*" \
77   "before: g.size_diff<unsigned long>()"
78
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"
81
82 gdb_test "p g.size_mul<5>()" "Couldn't find method.*" \
83   "before: g.size_mul<5>()"
84
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"
87
88 gdb_test "p g.mul<char>('a')" "Couldn't find method.*" \
89   "before: g.mul<char>('a')"
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.
95 gdb_test "p a1 + a2" "From Python <A_plus_A>.*15" "after: a1 + a2"
96
97 gdb_test "p a2 - a1" ".* = 5" "after: a2 - a1"
98 gdb_test "p a_minus_a" ".* = 3" "after: a_minus_a 3"
99
100 gdb_test "p b1 + a1" "From Python <A_plus_A>.*35" "after: b1 + a1"
101
102 gdb_test "p b1 - a1" ".* = 25" "after: b1 - a1"
103 gdb_test "p a_minus_a" ".* = 4" "after: a_minus_a 4"
104
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"
107 gdb_test "p a1.getarrayind(5)" "From Python <A_getarrayind>.*5" \
108   "after: a1.getarrayind(5)"
109 gdb_test "p a1\[6\]" ".*int &.*6" "after a1\[\]"
110 gdb_test "p b1\[7\]" ".*const int &.*7" "after b1\[\]"
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.
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()"
118 gdb_test "p e.method(10)" "From Python <E_method_int>.* = void" \
119   "after: e.method(10)"
120 gdb_test "p e.method('a')" "From Python <E_method_char>.* = void" \
121   "after: e.method('a')"
122 gdb_test "p g.size_diff<float>  ()" "From Python G<>::size_diff.*" \
123   "after: g.size_diff<float>()"
124 gdb_test "p g.size_diff<  unsigned long  >()" "From Python G<>::size_diff.*" \
125   "after: g.size_diff<unsigned long>()"
126 gdb_test "p g.size_mul<2>()" "From Python G<>::size_mul.*" \
127   "after: g.size_mul<2>()"
128 gdb_test "p g.size_mul<  5  >()" "From Python G<>::size_mul.*" \
129   "after: g.size_mul<  5  >()"
130 gdb_test "p g.mul<double>(2.0)" "From Python G<>::mul.*" \
131   "after: g.mul<double>(2.0)"
132 gdb_test "p g.mul<char>('a')" "From Python G<>::mul.*" \
133   "after: g.mul<char>('a')"
134 gdb_test "p g_ptr->mul<char>('a')" "From Python G<>::mul.*" \
135   "after: g_ptr->mul<char>('a')"
136
137 # Tests for 'disable/enable xmethod' command.
138 gdb_test_no_output "disable xmethod progspace G_methods" \
139   "disable G_methods"
140 gdb_test "p g.mul<char>('a')" "Couldn't find method.*" \
141   "g.mul<char>('a') after disabling G_methods"
142 gdb_test_no_output "enable xmethod progspace G_methods" \
143   "dnable G_methods"
144 gdb_test "p g.mul<char>('a')" "From Python G<>::mul.*" \
145   "after enabling G_methods"
146 gdb_test_no_output "disable xmethod progspace G_methods;mul" \
147   "disable G_methods;mul"
148 gdb_test "p g.mul<char>('a')" "Couldn't find method.*" \
149   "g.mul<char>('a') after disabling G_methods;mul"
150 gdb_test_no_output "enable xmethod progspace G_methods;mul" \
151   "enable G_methods;mul"
152 gdb_test "p g.mul<char>('a')" "From Python G<>::mul.*" \
153   "after enabling G_methods;mul"
154
155 # Test for 'info xmethods' command
156 gdb_test "info xmethod global plus" "global.*plus_plus_A" \
157   "info xmethod global plus 1"
158 gdb_test_no_output "disable xmethod progspace E_methods;method_int" \
159   "disable xmethod progspace E_methods;method_int"
160 gdb_test "info xmethod progspace E_methods;method_int" ".* \\\[disabled\\\]" \
161   "info xmethod xmethods E_methods;method_int"
162 gdb_test_no_output "disable xmethod progspace G_methods" "disable G_methods 2"
163 gdb_test "info xmethod progspace" ".*G_methods \\\[disabled\\\].*"
164
165 # PR 18285
166 # First make sure both are enabled.
167 gdb_test_no_output "enable xmethod progspace E_methods;method_char"
168 gdb_test_no_output "enable xmethod progspace E_methods;method_int"
169 gdb_test "pt e.method('a')" "type = void"
170 gdb_test "pt e.method(10)" \
171     "NotImplementedError.*Error while fetching result type of an xmethod worker defined in Python."