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