]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.python/py-xmethods.exp
Automatic Copyright Year update after running gdb/copyright.py
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.python / py-xmethods.exp
CommitLineData
4a94e368 1# Copyright 2014-2022 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
19load_lib gdb-python.exp
20
23e82930
LM
21if { [skip_cplus_tests] } {
22 untested "skipping C++ tests"
23 return
24}
883964a7
SC
25
26standard_testfile py-xmethods.cc
27
5b362f04 28if {[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
33if { [skip_python_tests] } {
34 untested "skipping Python tests"
35 return
36}
883964a7
SC
37
38if ![runto_main] {
39 return -1
40}
41
42set xmethods_script [gdb_remote_download host \
43 ${srcdir}/${subdir}/${testfile}.py]
44
45gdb_breakpoint [gdb_get_line_number "Break here."]
46gdb_continue_to_breakpoint "Break here" ".*Break here.*"
47
48# Tests before loading the debug methods.
cdc7edd7
LM
49gdb_test "p a1 + a2" ".* = 15" "before: a1 + a2"
50gdb_test "p a_plus_a" ".* = 1" "before: a_plus_a 1"
5d376983 51
cdc7edd7
LM
52gdb_test "p a2 - a1" ".* = 5" "before: a2 - a1"
53gdb_test "p a_minus_a" ".* = 1" "before: a_minus_a 1"
5d376983 54
cdc7edd7
LM
55gdb_test "p b1 - a1" ".* = 25" "before: b1 - a1"
56gdb_test "p a_minus_a" ".* = 2" "before: a_minus_a 2"
5d376983 57
cdc7edd7
LM
58gdb_test "p a1.geta()" ".* = 5" "before: a1.geta()"
59gdb_test "p a_geta" ".* = 1" "before: a_geta 1"
5d376983 60
cdc7edd7 61gdb_test "p ++a1" "No symbol.*" "before: ++a1"
883964a7 62gdb_test "p a1.getarrayind(5)" "Couldn't find method.*" \
23e82930 63 "before: a1.getarrayind(5)"
5d376983 64
cdc7edd7
LM
65gdb_test "p a_ptr->geta()" ".* = 60" "before: a_ptr->geta()"
66gdb_test "p b_geta" ".* = 1" "before: b_geta 1"
5d376983 67
cdc7edd7
LM
68gdb_test "p e.geta()" ".* = 100" "before: e.geta()"
69gdb_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
73gdb_test "p g.size_diff<float>()" ".*" "before: call g.size_diff<float>()"
74gdb_test "p g_size_diff" ".* = 2" "before: g_size_diff 2"
5d376983 75
883964a7 76gdb_test "p g.size_diff<unsigned long>()" "Couldn't find method.*" \
23e82930 77 "before: g.size_diff<unsigned long>()"
5d376983 78
cdc7edd7
LM
79gdb_test "p g.size_mul<2>()" ".*" "before: g.size_mul<2>()"
80gdb_test "p g_size_mul" ".* = 2" "before: g_size_mul 2"
5d376983 81
883964a7 82gdb_test "p g.size_mul<5>()" "Couldn't find method.*" \
23e82930 83 "before: g.size_mul<5>()"
5d376983 84
cdc7edd7
LM
85gdb_test "p g.mul<double>(2.0)" ".* = 10" "before: g.mul<double>(2.0)"
86gdb_test "p g_mul" ".* = 2" "before: g_mul 2"
5d376983 87
883964a7 88gdb_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.
92gdb_test_no_output "source ${xmethods_script}" "load the script file"
93
94# Tests after loading debug methods.
cdc7edd7 95gdb_test "p a1 + a2" "From Python <A_plus_A>.*15" "after: a1 + a2"
5d376983 96
cdc7edd7
LM
97gdb_test "p a2 - a1" ".* = 5" "after: a2 - a1"
98gdb_test "p a_minus_a" ".* = 3" "after: a_minus_a 3"
5d376983 99
cdc7edd7 100gdb_test "p b1 + a1" "From Python <A_plus_A>.*35" "after: b1 + a1"
5d376983 101
cdc7edd7
LM
102gdb_test "p b1 - a1" ".* = 25" "after: b1 - a1"
103gdb_test "p a_minus_a" ".* = 4" "after: a_minus_a 4"
5d376983 104
cdc7edd7
LM
105gdb_test "p a1.geta()" "From Python <A_geta>.*5" "after: a1.geta()"
106gdb_test "p ++a1" "From Python <plus_plus_A>.*6" "after: ++a1"
883964a7 107gdb_test "p a1.getarrayind(5)" "From Python <A_getarrayind>.*5" \
23e82930 108 "after: a1.getarrayind(5)"
b964bee0
TT
109gdb_test "p a1\[6\]" ".*int &.*6" "after a1\[\]"
110gdb_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
114gdb_test "p a_ptr->geta()" "From Python <A_geta>.*30" "after: a_ptr->geta()"
115gdb_test "p e.geta()" "From Python <A_geta>.*100" "after: e.geta()"
116gdb_test "p e_ptr->geta()" "From Python <A_geta>.*100" "after: e_ptr->geta()"
117gdb_test "p e_ref.geta()" "From Python <A_geta>.*100" "after: e_ref.geta()"
2ce1cdbf 118gdb_test "p e.method(10)" "From Python <E_method_int>.* = void" \
23e82930 119 "after: e.method(10)"
2ce1cdbf 120gdb_test "p e.method('a')" "From Python <E_method_char>.* = void" \
23e82930 121 "after: e.method('a')"
883964a7 122gdb_test "p g.size_diff<float> ()" "From Python G<>::size_diff.*" \
23e82930 123 "after: g.size_diff<float>()"
883964a7 124gdb_test "p g.size_diff< unsigned long >()" "From Python G<>::size_diff.*" \
23e82930 125 "after: g.size_diff<unsigned long>()"
883964a7 126gdb_test "p g.size_mul<2>()" "From Python G<>::size_mul.*" \
23e82930 127 "after: g.size_mul<2>()"
883964a7 128gdb_test "p g.size_mul< 5 >()" "From Python G<>::size_mul.*" \
23e82930 129 "after: g.size_mul< 5 >()"
883964a7 130gdb_test "p g.mul<double>(2.0)" "From Python G<>::mul.*" \
23e82930 131 "after: g.mul<double>(2.0)"
883964a7
SC
132gdb_test "p g.mul<char>('a')" "From Python G<>::mul.*" \
133gdb_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 137gdb_test_no_output "disable xmethod progspace G_methods" \
23e82930 138 "disable G_methods"
883964a7
SC
139gdb_test "p g.mul<char>('a')" "Couldn't find method.*" \
140 "g.mul<char>('a') after disabling G_methods"
70afc5b7 141gdb_test_no_output "enable xmethod progspace G_methods" \
23e82930 142 "dnable G_methods"
883964a7 143gdb_test "p g.mul<char>('a')" "From Python G<>::mul.*" \
23e82930 144 "after enabling G_methods"
70afc5b7 145gdb_test_no_output "disable xmethod progspace G_methods;mul" \
23e82930 146 "disable G_methods;mul"
883964a7
SC
147gdb_test "p g.mul<char>('a')" "Couldn't find method.*" \
148 "g.mul<char>('a') after disabling G_methods;mul"
70afc5b7 149gdb_test_no_output "enable xmethod progspace G_methods;mul" \
23e82930 150 "enable G_methods;mul"
883964a7 151gdb_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
155gdb_test "info xmethod global plus" "global.*plus_plus_A" \
156 "info xmethod global plus 1"
70afc5b7
SC
157gdb_test_no_output "disable xmethod progspace E_methods;method_int" \
158 "disable xmethod progspace E_methods;method_int"
159gdb_test "info xmethod progspace E_methods;method_int" ".* \\\[disabled\\\]" \
883964a7 160 "info xmethod xmethods E_methods;method_int"
9f058c10 161gdb_test_no_output "disable xmethod progspace G_methods" "disable G_methods 2"
d1e36019 162gdb_test "info xmethod progspace" ".*G_methods \\\[disabled\\\].*"
2ce1cdbf
DE
163
164# PR 18285
165# First make sure both are enabled.
166gdb_test_no_output "enable xmethod progspace E_methods;method_char"
167gdb_test_no_output "enable xmethod progspace E_methods;method_int"
168gdb_test "pt e.method('a')" "type = void"
169gdb_test "pt e.method(10)" \
170 "NotImplementedError.*Error while fetching result type of an xmethod worker defined in Python."