Imported Upstream version 7.9
[platform/upstream/gdb.git] / gdb / testsuite / gdb.python / py-xmethods.exp
1 # Copyright 2014-2015 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] } { 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.
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
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)"
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
70 gdb_test "p g.size_diff<unsigned long>()" "Couldn't find method.*" \
71   "Before: g.size_diff<unsigned long>()"
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
76 gdb_test "p g.size_mul<5>()" "Couldn't find method.*" \
77   "Before: g.size_mul<5>()"
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
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"
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
94 gdb_test "p b1 + a1" "From Python <A_plus_A>.*35" "After: b1 + a1"
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
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)"
103 # Note the following test.  Xmethods on dynamc types are not looked up
104 # currently.  Hence, even though a_ptr points to a B object, the xmethod
105 # defined for A objects is invoked.
106 gdb_test "p a_ptr->geta()" "From Python <A_geta>.*30" "After: a_ptr->geta()"
107 gdb_test "p e.geta()" "From Python <A_geta>.*100" "After: e.geta()"
108 gdb_test "p e_ptr->geta()" "From Python <A_geta>.*100" "After: e_ptr->geta()"
109 gdb_test "p e_ref.geta()" "From Python <A_geta>.*100" "After: e_ref.geta()"
110 gdb_test "p e.method(10)" "From Python <E_method_int>.*" "After: e.method(10)"
111 gdb_test "p e.method('a')" "From Python <E_method_char>.*" \
112   "After: e.method('a')"
113 gdb_test "p g.size_diff<float>  ()" "From Python G<>::size_diff.*" \
114   "After: g.size_diff<float>()"
115 gdb_test "p g.size_diff<  unsigned long  >()" "From Python G<>::size_diff.*" \
116   "After: g.size_diff<unsigned long>()"
117 gdb_test "p g.size_mul<2>()" "From Python G<>::size_mul.*" \
118   "After: g.size_mul<2>()"
119 gdb_test "p g.size_mul<  5  >()" "From Python G<>::size_mul.*" \
120   "After: g.size_mul<  5  >()"
121 gdb_test "p g.mul<double>(2.0)" "From Python G<>::mul.*" \
122   "After: g.mul<double>(2.0)"
123 gdb_test "p g.mul<char>('a')" "From Python G<>::mul.*" \
124 gdb_test "p g_ptr->mul<char>('a')" "From Python G<>::mul.*" \
125   "After: g_ptr->mul<char>('a')"
126
127 # Tests for 'disable/enable xmethod' command.
128 gdb_test_no_output "disable xmethod progspace G_methods" \
129   "Disable G_methods"
130 gdb_test "p g.mul<char>('a')" "Couldn't find method.*" \
131   "g.mul<char>('a') after disabling G_methods"
132 gdb_test_no_output "enable xmethod progspace G_methods" \
133   "Enable G_methods"
134 gdb_test "p g.mul<char>('a')" "From Python G<>::mul.*" \
135   "After enabling G_methods"
136 gdb_test_no_output "disable xmethod progspace G_methods;mul" \
137   "Disable G_methods;mul"
138 gdb_test "p g.mul<char>('a')" "Couldn't find method.*" \
139   "g.mul<char>('a') after disabling G_methods;mul"
140 gdb_test_no_output "enable xmethod progspace G_methods;mul" \
141   "Enable G_methods;mul"
142 gdb_test "p g.mul<char>('a')" "From Python G<>::mul.*" \
143   "After enabling G_methods;mul"
144
145 # Test for 'info xmethods' command
146 gdb_test "info xmethod global plus" "global.*plus_plus_A" \
147   "info xmethod global plus 1"
148 gdb_test_no_output "disable xmethod progspace E_methods;method_int" \
149   "disable xmethod progspace E_methods;method_int"
150 gdb_test "info xmethod progspace E_methods;method_int" ".* \\\[disabled\\\]" \
151   "info xmethod xmethods E_methods;method_int"