# Copyright 2014 Free Software Foundation, Inc. # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # This file is part of the GDB testsuite. It tests the debug methods # feature in the Python extension language. load_lib gdb-python.exp if { [skip_cplus_tests] } { continue } standard_testfile py-xmethods.cc if {[prepare_for_testing $testfile.exp $testfile $srcfile {debug c++}]} { return -1 } # Skip all tests if Python scripting is not enabled. if { [skip_python_tests] } { continue } if ![runto_main] { return -1 } set xmethods_script [gdb_remote_download host \ ${srcdir}/${subdir}/${testfile}.py] gdb_breakpoint [gdb_get_line_number "Break here."] gdb_continue_to_breakpoint "Break here" ".*Break here.*" # Tests before loading the debug methods. gdb_test "p a1 + a2" "From CC .*15" "Before: a1 + a2" gdb_test "p a2 - a1" "From CC .*5" "Before: a1 - a2" gdb_test "p b1 - a1" "From CC .*25" "Before: b1 - a1" gdb_test "p a1.geta()" "From CC A::geta.*5" "Before: a1.geta()" gdb_test "p ++a1" "No symbol.*" "Before: ++a1" gdb_test "p a1.getarrayind(5)" "Couldn't find method.*" \ "Before: a1.getarrayind(5)" gdb_test "p a_ptr->geta()" "From CC B::geta.*60" "Before: a_ptr->geta()" gdb_test "p e.geta()" "From CC A::geta.*100" "Before: e.geta()" gdb_test "p g.size_diff()" "From CC G<>::size_diff.*" \ "Before: g.size_diff()" gdb_test "p g.size_diff()" "Couldn't find method.*" \ "Before: g.size_diff()" gdb_test "p g.size_mul<2>()" "From CC G<>::size_mul.*" \ "Before: g.size_mul<2>()" gdb_test "p g.size_mul<5>()" "Couldn't find method.*" \ "Before: g.size_mul<5>()" gdb_test "p g.mul(2.0)" "From CC G<>::mul.*" \ "Before: g.mul(2.0)" gdb_test "p g.mul('a')" "Couldn't find method.*" \ "Before: g.mul('a')" # Load the script which adds the debug methods. gdb_test_no_output "source ${xmethods_script}" "load the script file" # Tests after loading debug methods. gdb_test "p a1 + a2" "From Python .*15" "After: a1 + a2" gdb_test "p a2 - a1" "From CC .*5" "After: a1 - a2" gdb_test "p b1 + a1" "From Python .*35" "After: b1 + a1" gdb_test "p b1 - a1" "From CC .*25" "After: b1 - a1" gdb_test "p a1.geta()" "From Python .*5" "After: a1.geta()" gdb_test "p ++a1" "From Python .*6" "After: ++a1" gdb_test "p a1.getarrayind(5)" "From Python .*5" \ "After: a1.getarrayind(5)" # Note the following test. Xmethods on dynamc types are not looked up # currently. Hence, even though a_ptr points to a B object, the xmethod # defined for A objects is invoked. gdb_test "p a_ptr->geta()" "From Python .*30" "After: a_ptr->geta()" gdb_test "p e.geta()" "From Python .*100" "After: e.geta()" gdb_test "p e_ptr->geta()" "From Python .*100" "After: e_ptr->geta()" gdb_test "p e_ref.geta()" "From Python .*100" "After: e_ref.geta()" gdb_test "p e.method(10)" "From Python .*" "After: e.method(10)" gdb_test "p e.method('a')" "From Python .*" \ "After: e.method('a')" gdb_test "p g.size_diff ()" "From Python G<>::size_diff.*" \ "After: g.size_diff()" gdb_test "p g.size_diff< unsigned long >()" "From Python G<>::size_diff.*" \ "After: g.size_diff()" gdb_test "p g.size_mul<2>()" "From Python G<>::size_mul.*" \ "After: g.size_mul<2>()" gdb_test "p g.size_mul< 5 >()" "From Python G<>::size_mul.*" \ "After: g.size_mul< 5 >()" gdb_test "p g.mul(2.0)" "From Python G<>::mul.*" \ "After: g.mul(2.0)" gdb_test "p g.mul('a')" "From Python G<>::mul.*" \ gdb_test "p g_ptr->mul('a')" "From Python G<>::mul.*" \ "After: g_ptr->mul('a')" # Tests for 'disable/enable xmethod' command. gdb_test_no_output "disable xmethod progspace G_methods" \ "Disable G_methods" gdb_test "p g.mul('a')" "Couldn't find method.*" \ "g.mul('a') after disabling G_methods" gdb_test_no_output "enable xmethod progspace G_methods" \ "Enable G_methods" gdb_test "p g.mul('a')" "From Python G<>::mul.*" \ "After enabling G_methods" gdb_test_no_output "disable xmethod progspace G_methods;mul" \ "Disable G_methods;mul" gdb_test "p g.mul('a')" "Couldn't find method.*" \ "g.mul('a') after disabling G_methods;mul" gdb_test_no_output "enable xmethod progspace G_methods;mul" \ "Enable G_methods;mul" gdb_test "p g.mul('a')" "From Python G<>::mul.*" \ "After enabling G_methods;mul" # Test for 'info xmethods' command gdb_test "info xmethod global plus" "global.*plus_plus_A" \ "info xmethod global plus 1" gdb_test_no_output "disable xmethod progspace E_methods;method_int" \ "disable xmethod progspace E_methods;method_int" gdb_test "info xmethod progspace E_methods;method_int" ".* \\\[disabled\\\]" \ "info xmethod xmethods E_methods;method_int" remote_file host delete ${xmethods_script}