diff --git a/gdb/testsuite/gdb.cp/meth-typedefs.cc b/gdb/testsuite/gdb.cp/meth-typedefs.cc new file mode 100644 index 0000000..4055382 --- /dev/null +++ b/gdb/testsuite/gdb.cp/meth-typedefs.cc @@ -0,0 +1,94 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2011 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 . + + Contributed by Red Hat, originally written by Keith Seitz. */ + +#include + +typedef const char* const* my_type; +typedef int my_type_2; +typedef my_type my_other_type; +typedef my_type_2 my_other_type_2; +typedef unsigned long CORE_ADDR; + +typedef void (*fptr1) (my_other_type); +typedef void (*fptr2) (fptr1, my_other_type_2); +typedef void (*fptr3) (fptr2, my_other_type); + +namespace A +{ + class foo + { + public: + foo (void) { } + foo (my_other_type a) { } // A::foo::foo(my_other_type) + foo (my_other_type_2 a) { } // A::foo::foo(my_other_type_2) + foo (my_other_type_2 a, const my_other_type b) { } // A::foo::foo(my_other_type_2, const my_other_type) + foo (fptr3) { } // A::foo::foo(fptr3) + foo (fptr1 *a) { } // A::foo::foo(fptr1*) + foo (CORE_ADDR (*) [10]) { } // A::foo::foo(CORE_ADDR (*) [10]) + + void test (my_other_type a) { } // A::foo::test(my_other_type) + void test (my_other_type_2 a) { } // A::foo::test(my_other_type_2) + void test (my_other_type_2 a, const my_other_type b) { } // A::foo::test(my_other_type_2, const my_other_type) + void test (fptr3 a) { } // A::foo::test(fptr3) + void test (fptr1 *a) { } // A::foo::test(fptr1*) + void test (CORE_ADDR (*) [10]) { } // A::foo::test(CORE_ADDR (*) [10]) + }; +}; + +namespace B +{ + void + test (my_other_type foo) { } // B::test(my_other_type) + + void + test (my_other_type foo, my_other_type_2) { } // B::test(my_other_type, my_other_type_2) +}; + +void +test (my_other_type foo) { } // test(my_other_type) + +void +test (my_other_type foo, my_other_type_2) { } // test(my_other_type, my_other_type_2) + +int +main (void) +{ + A::foo f; + fptr1 fptr; + + f.test (static_cast (NULL)); + f.test (0); + f.test (0, static_cast (NULL)); + f.test (static_cast (NULL)); + f.test (&fptr); + f.test (static_cast (0)); + B::test (static_cast (NULL)); + B::test (static_cast (NULL), 0); + test (static_cast (NULL)); + test (static_cast (NULL), 0); + + A::foo w (static_cast (NULL)); + A::foo x (0); + A::foo y (0, static_cast (NULL)); + A::foo z (static_cast (NULL)); + A::foo a (&fptr); + A::foo b (static_cast (0)); + + return 0; +} diff --git a/gdb/testsuite/gdb.cp/meth-typedefs.exp b/gdb/testsuite/gdb.cp/meth-typedefs.exp new file mode 100644 index 0000000..bdeb8a5 --- /dev/null +++ b/gdb/testsuite/gdb.cp/meth-typedefs.exp @@ -0,0 +1,132 @@ +# Copyright 2011 Free Software Foundation, Inc. +# +# Contributed by Red Hat, originally written by Keith Seitz. +# +# 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. + +proc add {var name params expected} { + upvar $var result + set expect ".*// ${name}\\($expected\\)" + lappend result [list "${name}($params)" $expect] +} + +if {[skip_cplus_tests]} { continue } + +# Tests for c++/12266 et al +set testfile "meth-typedefs" +set srcfile $testfile.cc + +if {[prepare_for_testing $testfile $testfile $srcfile {c++ debug}]} { + return -1 +} + +if {![runto_main]} { + perror "couldn't run to breakpoint" + continue +} + +array set typedefs { + "my_other_type" {"my_other_type" "my_type" "const char* const*"} + "my_other_type_2" {"my_other_type_2" "my_type_2" "int"} + "CORE_ADDR" { "CORE_ADDR" "unsigned long" } +} + +set methods {} + +# Add the simple, one-parameter methods +foreach method {A::foo::test A::foo::foo} { + foreach type {my_other_type my_other_type_2} { + foreach t $typedefs($type) { + add methods $method $t $type + } + } +} + +# Add two-parameter methods +foreach method {A::foo::test A::foo::foo} { + set type "my_other_type_2, const my_other_type" + foreach t1 $typedefs(my_other_type_2) { + foreach t2 $typedefs(my_other_type) { + add methods $method "$t1, const $t2" $type + add methods $method "$t1, $t2" $type + } + } +} + +# Add the array-of-function pointer methods +set type "fptr1\\*" +foreach method {A::foo::test A::foo::foo} { + add methods $method "fptr1*" $type + foreach t $typedefs(my_other_type) { + add methods $method "void (**) ($t)" $type + } +} + +# Add the function pointer methods +set type "fptr3" +foreach method {A::foo::test A::foo::foo} { + add methods $method "fptr3" $type + + foreach t1 $typedefs(my_other_type) { + add methods $method "void (*)(fptr2, $t1)" $type + foreach t2 $typedefs(my_other_type_2) { + add methods $method "void (*)(void (*)(fptr1, $t2), $t1)" $type + foreach t3 $typedefs(my_other_type) { + add methods $method \ + "void (*)(void (*)(void (*) ($t3), $t2), $t1)" $type + } + } + } +} + +# Miscellaneous tests +set type {CORE_ADDR \(\*\) \[10\]} +foreach method {A::foo::foo A::foo::test} { + foreach t $typedefs(CORE_ADDR) { + add methods $method "$t (*) \[10\]" $type + } +} + +# Add non-method tests +set type1 "my_other_type" +set type2 "my_other_type, my_other_type_2" +foreach method {"test" "B::test"} { + foreach t1 $typedefs(my_other_type) { + add methods $method $t1 $type1 + foreach t2 $typedefs(my_other_type_2) { + add methods $method "$t1, $t2" $type2 + } + } +} + +gdb_test_no_output "set listsize 1" "" + +# Finally, for each method in the list METHODS, check whether +# the user can "list" it and "break" on it (both quoted and unquoted). +foreach test $methods { + set func [lindex $test 0] + set result [lindex $test 1] + gdb_test "list $func" $result + if {[gdb_breakpoint $func]} { + pass "break $func" + } + if {[gdb_breakpoint '$func']} { + pass "break '$func'" + } +} + +gdb_exit +return 0