From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19121 invoked by alias); 23 Sep 2010 14:48:26 -0000 Received: (qmail 19108 invoked by uid 22791); 23 Sep 2010 14:48:24 -0000 X-SWARE-Spam-Status: No, hits=-5.4 required=5.0 tests=AWL,BAYES_00,KAM_STOCKGEN,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,TW_BJ,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; Thu, 23 Sep 2010 14:48:06 +0000 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o8NEm56p027101 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 23 Sep 2010 10:48:05 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o8NEm4kF013604 for ; Thu, 23 Sep 2010 10:48:04 -0400 Received: from [10.15.16.129] (dhcp-10-15-16-129.yyz.redhat.com [10.15.16.129]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id o8NEm3T9015279 for ; Thu, 23 Sep 2010 10:48:03 -0400 Message-ID: <4C9B68A4.3090708@redhat.com> Date: Thu, 23 Sep 2010 18:43:00 -0000 From: sami wagiaalla User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.8) Gecko/20100806 Fedora/3.1.2-1.fc13 Lightning/1.0b2pre Thunderbird/3.1.2 MIME-Version: 1.0 To: gdb-patches@sourceware.org Subject: Re: [patch 4/4] Template Lookup References: <4C446F1C.60507@redhat.com> <4C460A3E.2040004@redhat.com> <4C7690B4.7020504@redhat.com> In-Reply-To: Content-Type: multipart/mixed; boundary="------------030105010305000801060204" 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: 2010-09/txt/msg00408.txt.bz2 This is a multi-part message in MIME format. --------------030105010305000801060204 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-length: 585 On 08/31/2010 06:05 PM, Tom Tromey wrote: >>>>>> "Sami" == sami wagiaalla writes: > > Sami> Hmm.. can you give me an example of this ? I tried to construct an > Sami> example with an extern function but I learned that cplus does not > Sami> allow extern template functions. > > Ordinarily, to make a test involving psymtab expansion, you have to make > two compilation units. > [...] Thanks for the compact example. I made it into a test case and added partial symbol support. The attached patch was regression tested on x8664 with gcc-4.4.4-10.f13 Sami --------------030105010305000801060204 Content-Type: text/x-patch; name="template_lookup_4.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="template_lookup_4.patch" Content-length: 6183 Template Lookup 4: Support template lookup for partial symbols. 2010-09-17 Sami Wagiaalla * psymtab.c (lookup_partial_symbol): Support search of template symbols. * dwarf2read.c (add_partial_symbol): set search name for template symbols. 2010-09-17 Sami Wagiaalla * gdb.cp/partial.exp: New file. * gdb.cp/partial2.cc: New file. * gdb.cp/partial1.cc: New file. diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index 0d3a34b..b9e3ecb 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -3869,6 +3869,14 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu) break; } + /* For C++ if the name contains template parameters remove them, and set + the cleaned up name to be the search name. */ + if (psym + && cu->language == language_cplus + && actual_name + && cp_name_has_template_parameters (actual_name)) + set_template_symbol_search_name (&((struct partial_symbol *) psym)->ginfo, objfile); + if (built_actual_name) xfree (actual_name); } diff --git a/gdb/psymtab.c b/gdb/psymtab.c index 6b29e85..07656cc 100644 --- a/gdb/psymtab.c +++ b/gdb/psymtab.c @@ -32,6 +32,8 @@ #include "command.h" #include "readline/readline.h" #include "gdb_regex.h" +#include "cp-support.h" +#include "language.h" #ifndef DEV_TTY #define DEV_TTY "/dev/tty" @@ -451,6 +453,7 @@ lookup_partial_symbol (struct partial_symtab *pst, const char *name, struct partial_symbol **top, **real_top, **bottom, **center; int length = (global ? pst->n_global_syms : pst->n_static_syms); int do_linear_search = 1; + const char *template_name = NULL; if (length == 0) { @@ -460,6 +463,17 @@ lookup_partial_symbol (struct partial_symtab *pst, const char *name, pst->objfile->global_psymbols.list + pst->globals_offset : pst->objfile->static_psymbols.list + pst->statics_offset); + if (current_language->la_language == language_cplus + && cp_name_has_template_parameters (name)) + { + template_name = name; + name = cp_remove_template_params (name); + + if (name == NULL) + /* Not a legal C++ name. */ + return NULL; + } + if (global) /* This means we can use a binary search. */ { do_linear_search = 0; @@ -498,6 +512,10 @@ lookup_partial_symbol (struct partial_symtab *pst, const char *name, while (top <= real_top && SYMBOL_MATCHES_SEARCH_NAME (*top, name)) { + if (template_name != NULL + && !SYMBOL_MATCHES_TEMPLATE_NAME (*top, template_name)) + continue; + if (symbol_matches_domain (SYMBOL_LANGUAGE (*top), SYMBOL_DOMAIN (*top), domain)) return (*top); @@ -512,6 +530,10 @@ lookup_partial_symbol (struct partial_symtab *pst, const char *name, { for (psym = start; psym < start + length; psym++) { + if (template_name != NULL + && !SYMBOL_MATCHES_TEMPLATE_NAME (*psym, template_name)) + continue; + if (symbol_matches_domain (SYMBOL_LANGUAGE (*psym), SYMBOL_DOMAIN (*psym), domain) && SYMBOL_MATCHES_SEARCH_NAME (*psym, name)) diff --git a/gdb/testsuite/gdb.cp/partial.exp b/gdb/testsuite/gdb.cp/partial.exp new file mode 100644 index 0000000..86ac84a --- /dev/null +++ b/gdb/testsuite/gdb.cp/partial.exp @@ -0,0 +1,68 @@ +# Copyright 2008 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 . + +# Test evaluation of template function for partial symbols. + +set testfile "partial" + +set srcfile1 "${testfile}1.cc" +set srcfile2 "${testfile}2.cc" +set objfile1 "${testfile}1.o" +set objfile2 "${testfile}2.o" + +set binfile "${objdir}/${subdir}/${testfile}" + +if { [gdb_compile "$srcdir/$subdir/$srcfile1" "$objdir/$subdir/$objfile1" object {debug c++}] != "" } { + untested m-static.exp + return -1 +} + +if { [gdb_compile "$srcdir/$subdir/$srcfile2" "$objdir/$subdir/$objfile2" object {debug c++}] != "" } { + untested m-static.exp + return -1 +} + +if { [gdb_compile "$objdir/$subdir/$objfile1 $objdir/$subdir/$objfile2" "${binfile}" executable {debug c++}] != "" } { + untested m-static.exp + return -1 +} + +gdb_exit +gdb_start +gdb_reinitialize_dir $srcdir/$subdir +gdb_load ${binfile} + +if ![runto_main] then { + perror "couldn't run to breakpoint" + continue +} + +# Test proper printing of template function. +gdb_test "p foo(11)" "= 11" + +# Test printing of template function by including +# template argument. +gdb_test "p foo(11)" "= 11" + +# Test printing of template function by including +# template argument. +gdb_test "p foo(11)" {No symbol "foo" in current context.} + +# Same as above but with some overloading. +gdb_test "p bar(1,1)" "= 22" +gdb_test "p bar('a','a')" "= 33" + +gdb_test "ptype bar" {= double \(int, int\)} +gdb_test "ptype bar" {= double \(char, char\)} diff --git a/gdb/testsuite/gdb.cp/partial1.cc b/gdb/testsuite/gdb.cp/partial1.cc new file mode 100644 index 0000000..2251680 --- /dev/null +++ b/gdb/testsuite/gdb.cp/partial1.cc @@ -0,0 +1,6 @@ +extern int g(void); + +int main() +{ + return g(); +} diff --git a/gdb/testsuite/gdb.cp/partial2.cc b/gdb/testsuite/gdb.cp/partial2.cc new file mode 100644 index 0000000..708c8f4 --- /dev/null +++ b/gdb/testsuite/gdb.cp/partial2.cc @@ -0,0 +1,10 @@ + +template double foo (T x) { return x; } +template double bar (T x, int) { return 22; } +template double bar (T x, char) { return 33; } + +int g (void) +{ + return foo(1.0) + foo(2) + + bar(1,1) + bar('a','a'); +} --------------030105010305000801060204--