From b50c861487bb7d71185777193a9246bac81e4f26 Mon Sep 17 00:00:00 2001 From: Keith Seitz Date: Mon, 14 Apr 2014 15:47:15 -0700 Subject: Remove symbol_matches_domain. This fixes PR c++/16253. symbol_matches_domain was permitting searches for a VAR_DOMAIN symbol to also match STRUCT_DOMAIN symbols for languages like C++ where STRUCT_DOMAIN symbols also define a typedef of the same name, e.g., "struct foo {}" introduces a typedef of the name "foo". Problems occur if there exists both a VAR_DOMAIN and STRUCT_DOMAIN symbol of the same name. Then it is essentially a race between which symbol is found first. The other symbol is obscurred. [This is a relatively common idiom: enum e { ... } e;] This patchset moves this "language defines a typedef" logic to lookup_symbol[_in_language], looking first for a symbol in the given domain and falling back to searching STRUCT_DOMAIN when/if appropriate. 2014-04-14 Keith Seitz PR c++/16253 * ada-lang.c (ada_symbol_matches_domain): Moved here and renamed from symbol_matches_domain in symtab.c. All local callers of symbol_matches_domain updated. (standard_lookup): If DOMAIN is VAR_DOMAIN and no symbol is found, search STRUCT_DOMAIN. (ada_find_any_type_symbol): Do not search STRUCT_DOMAIN independently. standard_lookup will do that automatically. * cp-namespace.c (cp_lookup_symbol_nonlocal): Explain when/why VAR_DOMAIN searches may return a STRUCT_DOMAIN match. (cp_lookup_symbol_in_namespace): Likewise. If no VAR_DOMAIN symbol is found, search STRUCT_DOMAIN. (cp_lookup_symbol_exports): Explain when/why VAR_DOMAIN searches may return a STRUCT_DOMAIN match. (lookup_symbol_file): Search for the class name in STRUCT_DOMAIN. * cp-support.c: Include language.h. (inspect_type): Explicitly search STRUCT_DOMAIN before searching VAR_DOMAIN. * psymtab.c (match_partial_symbol): Compare the requested domain with the symbol's domain directly. (lookup_partial_symbol): Likewise. * symtab.c (lookup_symbol_in_language): Explain when/why VAR_DOMAIN searches may return a STRUCT_DOMAIN match. If no VAR_DOMAIN symbol is found, search STRUCT_DOMAIN for appropriate languages. (symbol_matches_domain): Renamed `ada_symbol_matches_domain' and moved to ada-lang.c (lookup_block_symbol): Explain that this function only returns symbol matching the requested DOMAIN. Compare the requested domain with the symbol's domain directly. (iterate_over_symbols): Compare the requested domain with the symbol's domain directly. * symtab.h (symbol_matches_domain): Remove. 2014-04-14 Keith Seitz PR c++/16253 * gdb.cp/var-tag.cc: New file. * gdb.cp/var-tag.exp: New file. * gdb.dwarf2/dw2-ada-ffffffff.exp: Set the language to C++. * gdb.dwarf2/dw2-anon-mptr.exp: Likewise. * gdb.dwarf2/dw2-double-set-die-type.exp: Likewise. * gdb.dwarf2/dw2-inheritance.exp: Likewise. --- gdb/testsuite/gdb.cp/var-tag.cc | 44 ++++++++++++++++++ gdb/testsuite/gdb.cp/var-tag.exp | 99 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 143 insertions(+) create mode 100644 gdb/testsuite/gdb.cp/var-tag.cc create mode 100644 gdb/testsuite/gdb.cp/var-tag.exp (limited to 'gdb/testsuite/gdb.cp') diff --git a/gdb/testsuite/gdb.cp/var-tag.cc b/gdb/testsuite/gdb.cp/var-tag.cc new file mode 100644 index 0000000..93b9caf --- /dev/null +++ b/gdb/testsuite/gdb.cp/var-tag.cc @@ -0,0 +1,44 @@ +/* This testcase is part of GDB, the GNU debugger. + + 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 . */ + +int global = 3; + +class C { +public: + struct C1 {} C1; + enum E1 {a1, b1, c1} E1; + union U1 {int a1; char b1;} U1; + + C () : E1 (b1) {} + void global (void) const {} + int f (void) const { global (); return 0; } +} C; + +struct S {} S; +enum E {a, b, c} E; +union U {int a; char b;} U; + +class CC {} cc; +struct SS {} ss; +enum EE {ea, eb, ec} ee; +union UU {int aa; char bb;} uu; + +int +main (void) +{ + return C.f (); +} diff --git a/gdb/testsuite/gdb.cp/var-tag.exp b/gdb/testsuite/gdb.cp/var-tag.exp new file mode 100644 index 0000000..7869fa2 --- /dev/null +++ b/gdb/testsuite/gdb.cp/var-tag.exp @@ -0,0 +1,99 @@ +# 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 + +# Test expressions in which variable names shadow tag names. + +if {[skip_cplus_tests]} { continue } + +standard_testfile .cc + +if {[prepare_for_testing $testfile.exp $testfile $srcfile {debug c++}]} { + return -1 +} + +proc do_global_tests {lang} { + if {$lang == "c"} { + set invalid_print "No symbol \"%s\" in current context." + set ptypefmt $invalid_print + } else { + set invalid_print "Attempt to use a type name as an expression" + set ptypefmt "type = (class|enum|union|struct) %s {.*}" + } + + with_test_prefix $lang { + gdb_test_no_output "set language $lang" + gdb_test "ptype C" "type = class C {.*}" + gdb_test "print E" "= a" + gdb_test "ptype E" "type = enum E {.*}" + gdb_test "print S" "= {}" + gdb_test "ptype S" "type = struct S {.*}" + gdb_test "print U" "= {.*}" + gdb_test "ptype U" "type = union U {.*}" + gdb_test "print cc" "= {.*}" + gdb_test "ptype cc" "type = class CC {.*}" + gdb_test "print CC" [format $invalid_print "CC"] + gdb_test "ptype CC" [format $ptypefmt "CC"] + gdb_test "print ss" "= {}" + gdb_test "ptype ss" "type = struct SS {.*}" + gdb_test "print SS" [format $invalid_print "SS"] + gdb_test "ptype SS" [format $ptypefmt "SS"] + gdb_test "print ee" "= .*" + gdb_test "ptype ee" "type = enum EE {.*}" + gdb_test "print EE" [format $invalid_print "EE"] + gdb_test "ptype EE" [format $ptypefmt "EE"] + gdb_test "print uu" "= {.*}" + gdb_test "ptype uu" "type = union UU {.*}" + gdb_test "print UU" [format $invalid_print "UU"] + gdb_test "ptype UU" [format $ptypefmt "UU"] + } +} + +# First test expressions when there is no context. +with_test_prefix "before start" { + do_global_tests c++ + do_global_tests c +} + +# Run to main and test again. +if {![runto_main]} { + perror "couldn't run to main" + continue +} + +with_test_prefix "in main" { + do_global_tests c++ + do_global_tests c +} + +# Finally run to C::f and test again +gdb_breakpoint "C::f" +gdb_continue_to_breakpoint "continue to C::f" +with_test_prefix "in C::f" { + do_global_tests c++ + do_global_tests c +} + +# Another hard-to-guess-the-users-intent bug... +# It would be really nice if we could query the user! +with_test_prefix "global collision" { + gdb_test_no_output "set language c++" + setup_kfail "c++/16463" "*-*-*" + gdb_test "print global" "= 3" + + # ... with a simple workaround: + gdb_test "print ::global" "= 3" +} -- cgit v1.1