From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25037 invoked by alias); 18 Feb 2011 15:58:02 -0000 Received: (qmail 25025 invoked by uid 22791); 18 Feb 2011 15:58:01 -0000 X-SWARE-Spam-Status: No, hits=-6.3 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 18 Feb 2011 15:57:56 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p1IFvtHa021813 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 18 Feb 2011 10:57:55 -0500 Received: from host1.dyn.jankratochvil.net (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p1IFvqmE003145 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Fri, 18 Feb 2011 10:57:54 -0500 Received: from host1.dyn.jankratochvil.net (localhost [127.0.0.1]) by host1.dyn.jankratochvil.net (8.14.4/8.14.4) with ESMTP id p1IFvqqu005896 for ; Fri, 18 Feb 2011 16:57:52 +0100 Received: (from jkratoch@localhost) by host1.dyn.jankratochvil.net (8.14.4/8.14.4/Submit) id p1IFvq6I005895 for gdb-patches@sourceware.org; Fri, 18 Feb 2011 16:57:52 +0100 Date: Fri, 18 Feb 2011 16:00:00 -0000 From: Jan Kratochvil To: gdb-patches@sourceware.org Subject: [patch] C++ operators do not resolve through typedefs Message-ID: <20110218155751.GA3139@host1.dyn.jankratochvil.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2011-02/txt/msg00470.txt.bz2 Hi, https://bugzilla.redhat.com/show_bug.cgi?id=678454 operators do not get resolved through a typedef. The other unrelated part is that GDB crashes when trying to resolve operator without running inferior. I did not split it to a separate mail as I find it separated here well enough. No regressions on {x86_64,x86_64-m32,i686}-fedora15-linux-gnu. I find it safe enough so I will check it in in some time. Thanks, Jan gdb/ 2011-02-18 Jan Kratochvil * cp-support.c (make_symbol_overload_list_namespace) Do not call make_symbol_overload_list_block with NULL BLOCK. * valarith.c (unop_user_defined_p): Resolve also TYPE_CODE_TYPEDEF. gdb/testsuite/ 2011-02-18 Jan Kratochvil * gdb.cp/typedef-operator.exp: New file. * gdb.cp/typedef-operator.cc: New file. --- a/gdb/cp-support.c +++ b/gdb/cp-support.c @@ -778,11 +778,13 @@ make_symbol_overload_list_namespace (const char *func_name, /* Look in the static block. */ block = block_static_block (get_selected_block (0)); - make_symbol_overload_list_block (name, block); + if (block) + make_symbol_overload_list_block (name, block); /* Look in the global block. */ block = block_global_block (block); - make_symbol_overload_list_block (name, block); + if (block) + make_symbol_overload_list_block (name, block); } --- a/gdb/valarith.c +++ b/gdb/valarith.c @@ -315,15 +315,26 @@ unop_user_defined_p (enum exp_opcode op, struct value *arg1) if (op == UNOP_ADDR) return 0; type1 = check_typedef (value_type (arg1)); - for (;;) + while (type1) { if (TYPE_CODE (type1) == TYPE_CODE_STRUCT) return 1; else if (TYPE_CODE (type1) == TYPE_CODE_REF) type1 = TYPE_TARGET_TYPE (type1); + else if (TYPE_CODE (type1) == TYPE_CODE_TYPEDEF) + { + struct type *type2 = check_typedef (type1); + + /* Abort if this TYPE_CODE_TYPEDEF cannot be resolved. */ + if (type2 == type1) + break; + + type1 = type2; + } else - return 0; + break; } + return 0; } /* Try to find an operator named OPERATOR which takes NARGS arguments --- /dev/null +++ b/gdb/testsuite/gdb.cp/typedef-operator.cc @@ -0,0 +1,29 @@ +/* This test case 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 . */ + +class C +{ +public: + int operator* () { return 42; } +}; +typedef C D; +D u; +D &v = u; +int main () +{ + return *v; +} --- /dev/null +++ b/gdb/testsuite/gdb.cp/typedef-operator.exp @@ -0,0 +1,33 @@ +# 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 . + +# This file is part of the gdb testsuite. + +if {[skip_cplus_tests]} { continue } + +set testfile "typedef-operator" +if [prepare_for_testing $testfile $testfile $testfile.cc {c++ debug}] { + return -1 +} + +gdb_test_no_output "set language c++" + +gdb_test "p *u" {You can't do that without a process to debug.} "test crash" + +if ![runto_main] { + return -1 +} + +gdb_test "p *v" " = 42" "test typedef"