diff options
-rw-r--r-- | gdb/testsuite/ChangeLog | 12 | ||||
-rw-r--r-- | gdb/testsuite/gdb.cp/call-method-register.cc | 66 | ||||
-rw-r--r-- | gdb/testsuite/gdb.cp/call-method-register.exp | 57 | ||||
-rw-r--r-- | gdb/testsuite/gdb.cp/classes.cc | 37 | ||||
-rw-r--r-- | gdb/testsuite/gdb.cp/classes.exp | 36 |
5 files changed, 136 insertions, 72 deletions
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 76c66ac..cd93827 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,5 +1,17 @@ 2020-09-13 Pedro Alves <pedro@palves.net> + * gdb.cp/classes.exp: No longer pass -Wno-deprecated-register. + (do_tests): Remove "calling method for small class" test. + * gdb.cp/classes.cc (class small, small::method, marker_reg1) + (register_class): Delete. + (main): Don't call register_class. + * gdb.cp/call-method-register.exp: New file, based on bits removed + from classes.exp. + * gdb.cp/call-method-register.cc: New file, based on bits removed + from classes.cc. + +2020-09-13 Pedro Alves <pedro@palves.net> + * gdb.base/msym-bp-2.c: New. * gdb.base/msym-bp-shl-lib.c: New file. * gdb.base/msym-bp-shl-main-2.c: New file. diff --git a/gdb/testsuite/gdb.cp/call-method-register.cc b/gdb/testsuite/gdb.cp/call-method-register.cc new file mode 100644 index 0000000..2beed47 --- /dev/null +++ b/gdb/testsuite/gdb.cp/call-method-register.cc @@ -0,0 +1,66 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 1993-2020 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 <http://www.gnu.org/licenses/>. */ + +#if defined __x86_64__ +# define ASM_REG "rax" +#elif defined __i386__ +# define ASM_REG "eax" +#else +# error "port me" +#endif + +/* A class small enough that it fits in a register. */ +struct small +{ + int x; + int method (); +}; + +int +small::method () +{ + return x + 5; +} + +int +register_class () +{ + /* Given the use of the GNU register-asm local variables extension, + the compiler puts this variable in a register. This means that + GDB can't call any methods for this variable, which is what we + want to test. */ + register small v asm (ASM_REG); + + int i; + + /* Perform a computation sufficiently complicated that optimizing + compilers won't optimize out the variable. If some compiler + constant-folds this whole loop, maybe using a parameter to this + function here would help. */ + v.x = 0; + for (i = 0; i < 13; ++i) + v.x += i; + --v.x; /* v.x is now 77 */ + return v.x + 5; /* set breakpoint here */ +} + +int +main () +{ + register_class (); + return 0; +} diff --git a/gdb/testsuite/gdb.cp/call-method-register.exp b/gdb/testsuite/gdb.cp/call-method-register.exp new file mode 100644 index 0000000..d12f0ef --- /dev/null +++ b/gdb/testsuite/gdb.cp/call-method-register.exp @@ -0,0 +1,57 @@ +# Copyright 1992-2020 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 <http://www.gnu.org/licenses/>. + +# Test callling a method on a variable that has been put in a +# register. + +if { [skip_cplus_tests] } { continue } + +load_lib "cp-support.exp" + +standard_testfile .cc + +if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug c++}]} { + return -1 +} + +proc test_call_register_class {} { + global gdb_prompt + + if ![runto_main] { + fail "couldn't run to main" + return + } + + set bp_location [gdb_get_line_number "set breakpoint here"] + gdb_breakpoint $bp_location + gdb_continue_to_breakpoint "break here" + + # This class is so small that an instance of it can fit in a register. + # When gdb tries to call a method, it gets embarrassed about taking + # the address of a register. + # + # That message is a PASS, not an XFAIL, because gdb prints an + # informative message and declines to do something impossible. + # + # The method call actually succeeds if the compiler allocates very + # small classes in memory instead of registers. If that happens, + # it's a FAIL, because the testcase is written in a form such that + # it should not happen. + gdb_test "print v.method ()" \ + "Address requested for identifier \"v\" which is in register .*" \ + "call method on register local" +} + +test_call_register_class diff --git a/gdb/testsuite/gdb.cp/classes.cc b/gdb/testsuite/gdb.cp/classes.cc index 5ea360e..e8bac54 100644 --- a/gdb/testsuite/gdb.cp/classes.cc +++ b/gdb/testsuite/gdb.cp/classes.cc @@ -532,19 +532,6 @@ typedef struct { } tagless_struct; tagless_struct v_tagless; -/* Try to get the compiler to allocate a class in a register. */ -class small { - public: - int x; - int method (); -}; - -int -small::method () -{ - return x + 5; -} - class class_with_typedefs { public: @@ -621,29 +608,6 @@ private: INT b; }; -void marker_reg1 () {} - -int -register_class () -{ - /* We don't call any methods for v, so gcc version cygnus-2.3.3-930220 - might put this variable in a register. This is a lose, though, because - it means that GDB can't call any methods for that variable. */ - register small v; - - int i; - - /* Perform a computation sufficiently complicated that optimizing compilers - won't optimized out the variable. If some compiler constant-folds this - whole loop, maybe using a parameter to this function here would help. */ - v.x = 0; - for (i = 0; i < 13; ++i) - v.x += i; - --v.x; /* v.x is now 77 */ - marker_reg1 (); - return v.x + 5; -} - void dummy() { v_bool = true; @@ -686,7 +650,6 @@ main() inheritance1 (); inheritance3 (); enums1 (); - register_class (); /* FIXME: pmi gets optimized out. Need to do some more computation with it or something. (No one notices, because the test is xfail'd anyway, diff --git a/gdb/testsuite/gdb.cp/classes.exp b/gdb/testsuite/gdb.cp/classes.exp index 4a2287a..ae4bf13 100644 --- a/gdb/testsuite/gdb.cp/classes.exp +++ b/gdb/testsuite/gdb.cp/classes.exp @@ -24,8 +24,7 @@ load_lib "cp-support.exp" standard_testfile .cc -if {[prepare_for_testing "failed to prepare" $testfile $srcfile \ - {debug c++ additional_flags=-Wno-deprecated-register}]} { +if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug c++}]} { return -1 } @@ -650,39 +649,6 @@ proc do_tests {} { # Now some random tests that were just thrown in here. - gdb_breakpoint marker_reg1 - gdb_test "continue" ".*Breakpoint .* marker_reg1.*" "" - gdb_test "finish" "Run till exit from.*" "finish from marker_reg1" - - # This class is so small that an instance of it can fit in a register. - # When gdb tries to call a method, it gets embarrassed about taking - # the address of a register. - # - # TODO: I think that message should be a PASS, not an XFAIL. - # gdb prints an informative message and declines to do something - # impossible. - # - # The method call actually succeeds if the compiler allocates very - # small classes in memory instead of registers. So this test does - # not tell us anything interesting if the call succeeds. - # - # -- chastain 2003-12-31 - gdb_test_multiple "print v.method ()" "calling method for small class" { - -re "\\$\[0-9\]+ = 82$nl$gdb_prompt $" { - # gcc 3.3.2 -gdwarf-2 - # gcc HEAD 2003-12-28 21:08:30 UTC -gdwarf-2 - # gcc 3.3.2 -gstabs+ - # gcc HEAD 2003-12-28 21:08:30 UTC -gstabs+ - pass "calling method for small class" - } - -re "Address requested for identifier \"v\" which is in register .*$nl$gdb_prompt $" { - # gcc 2.95.3 -gdwarf-2 - # gcc 2.95.3 -gstabs+ - setup_xfail "*-*-*" 2972 - fail "calling method for small class" - } - } - gdb_test "print base1::Base1" "<.*Base1.*>" "print ctor of typedef class" gdb_test "print base1::~Base1" "<.*~Base1(\\(\\))?>" \ "print dtor of typedef class" |