diff options
author | Tom Tromey <tromey@redhat.com> | 2013-04-15 17:36:14 +0000 |
---|---|---|
committer | Tom Tromey <tromey@redhat.com> | 2013-04-15 17:36:14 +0000 |
commit | 6e72ca205c018b9906fa2047ffb1be7f546e0643 (patch) | |
tree | f3a97011f1f148c9d0609bf241e87ef54e32779d /gdb/testsuite | |
parent | 715c6909e29a233406d54739976bb8674fa6b836 (diff) | |
download | gdb-6e72ca205c018b9906fa2047ffb1be7f546e0643.zip gdb-6e72ca205c018b9906fa2047ffb1be7f546e0643.tar.gz gdb-6e72ca205c018b9906fa2047ffb1be7f546e0643.tar.bz2 |
PR c++/9065:
* NEWS: Update.
* breakpoint.c (watchpoint_exp_is_const): Add OP_TYPEID.
* c-exp.y (TYPEID): New token.
(exp): Add new TYPEID productions.
(ident_tokens): Add "typeid".
* cp-abi.c (cplus_typeid, cplus_typeid_type): New functions.
* cp-abi.h (cplus_typeid, cplus_typeid_type): Declare.
(struct cp_abi_ops) <get_typeid, get_typeid_type>: New fields.
* eval.c (evaluate_subexp_standard) <OP_TYPEID>: New case.
* expprint.c (dump_subexp_body_standard) <OP_TYPEID>: New
case.
* gnu-v3-abi.c (std_type_info_gdbarch_data): New global.
(build_std_type_info_type, gnuv3_get_typeid_type)
(gnuv3_get_typeid): New functions.
(init_gnuv3_ops): Initialize std_type_info_gdbarch_data. Set
new fields on ABI object.
* parse.c (operator_length_standard) <OP_TYPEID>: New case.
* std-operator.def (OP_TYPEID): New.
gdb/testsuite
* gdb.cp/typeid.cc: New file.
* gdb.cp/typeid.exp: New file.
Diffstat (limited to 'gdb/testsuite')
-rw-r--r-- | gdb/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gdb/testsuite/gdb.cp/typeid.cc | 60 | ||||
-rw-r--r-- | gdb/testsuite/gdb.cp/typeid.exp | 67 |
3 files changed, 132 insertions, 0 deletions
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 6526980..7da3ff0 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,5 +1,10 @@ 2013-04-15 Tom Tromey <tromey@redhat.com> + * gdb.cp/typeid.cc: New file. + * gdb.cp/typeid.exp: New file. + +2013-04-15 Tom Tromey <tromey@redhat.com> + * gdb.cp/exception.exp: Add "catch rethrow" tests. 2013-04-13 Yao Qi <yao@codesourcery.com> diff --git a/gdb/testsuite/gdb.cp/typeid.cc b/gdb/testsuite/gdb.cp/typeid.cc new file mode 100644 index 0000000..7120031 --- /dev/null +++ b/gdb/testsuite/gdb.cp/typeid.cc @@ -0,0 +1,60 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2013 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/>. */ + +#include <typeinfo> + +int i; +char *cp; +const char *ccp; +char ca[5]; + +struct Base +{ + virtual ~Base() { } +}; + +struct VB1 : public virtual Base +{ +}; + +struct VB2 : public virtual Base +{ +}; + +struct Derived : public VB1, VB2 +{ +}; + +Derived d; + +Base *b = &d; +VB1 *vb1 = &d; +VB1 *vb2 = &d; + +const Base *bv = &d; + +int main () +{ + const std::type_info &xi = typeid(i); + const std::type_info &xcp = typeid(cp); + const std::type_info &xccp = typeid(ccp); + const std::type_info &xca = typeid(ca); + const std::type_info &xd = typeid(d); + const std::type_info &xb = typeid(b); + + return 0; +} diff --git a/gdb/testsuite/gdb.cp/typeid.exp b/gdb/testsuite/gdb.cp/typeid.exp new file mode 100644 index 0000000..2096ad9 --- /dev/null +++ b/gdb/testsuite/gdb.cp/typeid.exp @@ -0,0 +1,67 @@ +# Copyright 2013 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/>. + +standard_testfile .cc + +if {[skip_cplus_tests]} { + return -1 +} + +if {[prepare_for_testing $testfile.exp $testfile $srcfile {debug c++}]} { + return -1 +} + +proc do_typeid_tests {started} { + global hex + + # We might see the standard type or gdb's internal type. + set type_re "(std::type_info|struct gdb_gnu_v3_type_info)" + + + foreach simple_var {i cp ccp ca b} { + gdb_test "print &typeid($simple_var)" \ + " = \\($type_re \\*\\) $hex.*" + + # Note that we test pointer equality rather than object + # equality here. That is because std::type_info's operator== + # is not present in the libstdc++ .so. + gdb_test "print &typeid($simple_var) == &typeid(typeof($simple_var))" \ + " = true" + } + + # typeid for these is Derived. Don't try these tests until the + # inferior has started. + if {$started} { + foreach der_var {*b *vb1 *vb2 *bv d {const Derived} {const Derived &}} { + gdb_test "print &typeid($der_var)" \ + " = \\($type_re \\*\\) $hex.*" + gdb_test "print &typeid($der_var) == &typeid(d)" \ + " = true" + } + } +} + +with_test_prefix "before starting" { + do_typeid_tests 0 +} + +if ![runto_main] { + untested typeid + return -1 +} + +with_test_prefix "after starting" { + do_typeid_tests 1 +} |