From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25933 invoked by alias); 9 Dec 2010 00:50:51 -0000 Received: (qmail 25895 invoked by uid 22791); 9 Dec 2010 00:50:47 -0000 X-SWARE-Spam-Status: No, hits=-4.9 required=5.0 tests=AWL,BAYES_00,KAM_STOCKGEN,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,TW_BJ,TW_CP,TW_CX,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, 09 Dec 2010 00:50:40 +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.13.8/8.13.8) with ESMTP id oB90oc8t030328 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 8 Dec 2010 19:50:38 -0500 Received: from valrhona.uglyboxes.com (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 oB90oYOH011903 (version=TLSv1/SSLv3 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO) for ; Wed, 8 Dec 2010 19:50:36 -0500 Message-ID: <4D002672.5090504@redhat.com> Date: Thu, 09 Dec 2010 00:50:00 -0000 From: Keith Seitz User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.12) Gecko/20101103 Fedora/1.0-0.33.b2pre.fc13 Lightning/1.0b3pre Thunderbird/3.1.6 MIME-Version: 1.0 To: gdb-patches@sourceware.org Subject: [RFA] c++/11734 revisited Content-Type: multipart/mixed; boundary="------------070705060409060107060108" 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-12/txt/msg00100.txt.bz2 This is a multi-part message in MIME format. --------------070705060409060107060108 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-length: 1925 Hi, Refresher: This is the bug that relates to psymtabs not having overload information and how gdb can't find the right psymtab to expand. I originally proposed fixing this by switching to pre-expansion. Tom reports that this really mucks up indexing. As a result, I have rewritten this patch. I *think* I have addressed almost all of the original issues that were reported. One that I have not addressed is Doug's complaint about removing the single-quote in decode_compound. Quite frankly, the single/double quote handling is a mess. It's such a nightmare, it would actually a primary reason to rewrite linespec.c entirely. One of these days, I'll find the time to do it. [Although with the countless hours I've spent on linespec.c in the past year, I'm sure I could have rewritten it three times already.] This patch also fixes Jan's expand-psymtabs-cxx test which he posted on 11/21. Yes, I realize this is actually two patches, one for psymtab.c and one for linespec.c, but the linespec.c patch is really small this time and the tests for both are in the same file (because that's how I discovered the linespec bug). Tested on x86_64-linux. No regressions. Comments? Keith ChangeLog 2010-12-08 Keith Seitz * linespec.c (decode_compound): Rename SAVED_ARG to THE_REAL_SAVED_ARG. Make a copy of THE_REAL_SAVED_ARG in SAVED_ARG and strip single-quotes. * psymtab.c (lookup_symbol_aux_psymtabs): Don't assume that the psymtab we found was the right one. Search for the desired symbol in the symtab to be certain. (psymtab_search_name): New function. (lookup_partial_symbol): Use psymtab_search_name. testsuite/ChangeLog 2010-12-08 Keith Seitz * gdb.cp/pr11734.exp: New test. * gdb.cp/pr11734.h: New file. * gdb.cp/pr11734-1.cc: New file. * gdb.cp/pr11734-2.cc: New file. * gdb.cp/pr11734-3.cc: New file. * gdb.cp/pr11734-4.cc: New file. --------------070705060409060107060108 Content-Type: text/plain; name="pr11734-4.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="pr11734-4.patch" Content-length: 14475 Index: linespec.c =================================================================== RCS file: /cvs/src/src/gdb/linespec.c,v retrieving revision 1.105 diff -u -p -r1.105 linespec.c --- linespec.c 2 Dec 2010 20:05:59 -0000 1.105 +++ linespec.c 9 Dec 2010 00:49:09 -0000 @@ -1219,7 +1219,7 @@ decode_objc (char **argptr, int funfirst static struct symtabs_and_lines decode_compound (char **argptr, int funfirstline, char ***canonical, - char *saved_arg, char *p, int *not_found_ptr) + char *the_real_saved_arg, char *p, int *not_found_ptr) { struct symtabs_and_lines values; char *p2; @@ -1230,7 +1230,23 @@ decode_compound (char **argptr, int funf struct symbol *sym_class; struct type *t; char *saved_java_argptr = NULL; + char *saved_arg; + /* THE_REAL_SAVED_ARG cannot be altered, so make a copy that can be. */ + saved_arg = alloca (strlen (the_real_saved_arg) + 1); + strcpy (saved_arg, the_real_saved_arg); + + /* If the user specified "'foo::bar(baz)'" (note the qutoes -- often + added to workaround completer issues) -- saved_arg will be + encapsulated in single-quotes. They are superfluous, so just strip + them off. */ + if (*saved_arg == '\'') + { + char *end = skip_quoted (saved_arg); + memcpy (saved_arg, saved_arg + 1, end - saved_arg); + memcpy (end - 2, end, strlen (saved_arg) + 1); + } + /* First check for "global" namespace specification, of the form "::foo". If found, skip over the colons and jump to normal symbol processing. I.e. the whole line specification starts with @@ -1481,7 +1497,7 @@ decode_compound (char **argptr, int funf up. The quotes are important if copy is empty. */ if (not_found_ptr) *not_found_ptr = 1; - cplusplus_error (saved_arg, + cplusplus_error (the_real_saved_arg, "Can't find member of namespace, class, struct, or union named \"%s\"\n", copy); } Index: psymtab.c =================================================================== RCS file: /cvs/src/src/gdb/psymtab.c,v retrieving revision 1.19 diff -u -p -r1.19 psymtab.c --- psymtab.c 24 Nov 2010 19:01:51 -0000 1.19 +++ psymtab.c 9 Dec 2010 00:49:10 -0000 @@ -33,6 +33,8 @@ #include "readline/readline.h" #include "gdb_regex.h" #include "dictionary.h" +#include "language.h" +#include "cp-support.h" #ifndef DEV_TTY #define DEV_TTY "/dev/tty" @@ -426,7 +428,26 @@ lookup_symbol_aux_psymtabs (struct objfi ALL_OBJFILE_PSYMTABS (objfile, ps) { if (!ps->readin && lookup_partial_symbol (ps, name, psymtab_index, domain)) - return PSYMTAB_TO_SYMTAB (ps); + { + struct symbol *sym; + struct symtab *stab = PSYMTAB_TO_SYMTAB (ps); + sym = NULL; + + /* Some caution must be observed with overloaded functions + and methods, since the psymtab will not contain any overload + information (but NAME might contain it). */ + if (stab->primary) + { + struct blockvector *bv = BLOCKVECTOR (stab); + struct block *block = BLOCKVECTOR_BLOCK (bv, block_index); + sym = lookup_block_symbol (block, name, domain); + } + + if (sym && strcmp_iw (SYMBOL_SEARCH_NAME (sym), name) == 0) + return stab; + + /* Keep looking through other psymtabs. */ + } } return NULL; @@ -519,6 +540,37 @@ pre_expand_symtabs_matching_psymtabs (st /* Nothing. */ } +/* Returns the name used to search psymtabs. Unlike symtabs, psymtabs do + not contain any method/function instance information (since this would + force reading type information while reading psymtabs). Therefore, + if NAME contains overload information, it must be stripped before searching + psymtabs. + + The caller is responsible for freeing the return result. */ + +static const char * +psymtab_search_name (const char *name) +{ + switch (current_language->la_language) + { + case language_cplus: + case language_java: + { + if (strchr (name, '(')) + { + char *ret = cp_remove_params (name); + if (ret) + return ret; + } + } + + default: + break; + } + + return xstrdup (name); +} + /* Look, in partial_symtab PST, for symbol whose natural name is NAME. Check the global symbols if GLOBAL, the static symbols if not. */ @@ -530,11 +582,16 @@ lookup_partial_symbol (struct partial_sy 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 *search_name; + struct cleanup *cleanup; if (length == 0) { return (NULL); } + + search_name = psymtab_search_name (name); + cleanup = make_cleanup (xfree, (void *) search_name); start = (global ? pst->objfile->global_psymbols.list + pst->globals_offset : pst->objfile->static_psymbols.list + pst->statics_offset); @@ -562,7 +619,8 @@ lookup_partial_symbol (struct partial_sy { do_linear_search = 1; } - if (strcmp_iw_ordered (SYMBOL_SEARCH_NAME (*center), name) >= 0) + if (strcmp_iw_ordered (SYMBOL_SEARCH_NAME (*center), + search_name) >= 0) { top = center; } @@ -575,11 +633,14 @@ lookup_partial_symbol (struct partial_sy internal_error (__FILE__, __LINE__, _("failed internal consistency check")); while (top <= real_top - && SYMBOL_MATCHES_SEARCH_NAME (*top, name)) + && SYMBOL_MATCHES_SEARCH_NAME (*top, search_name)) { if (symbol_matches_domain (SYMBOL_LANGUAGE (*top), SYMBOL_DOMAIN (*top), domain)) - return (*top); + { + do_cleanups (cleanup); + return (*top); + } top++; } } @@ -594,10 +655,14 @@ lookup_partial_symbol (struct partial_sy if (symbol_matches_domain (SYMBOL_LANGUAGE (*psym), SYMBOL_DOMAIN (*psym), domain) && SYMBOL_MATCHES_SEARCH_NAME (*psym, name)) - return (*psym); + { + do_cleanups (cleanup); + return (*psym); + } } } + do_cleanups (cleanup); return (NULL); } Index: testsuite/gdb.cp/pr11734-1.cc =================================================================== RCS file: testsuite/gdb.cp/pr11734-1.cc diff -N testsuite/gdb.cp/pr11734-1.cc --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ testsuite/gdb.cp/pr11734-1.cc 9 Dec 2010 00:49:10 -0000 @@ -0,0 +1,30 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2010 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 . + + Please email any bugs, comments, and/or additions to this file to: + bug-gdb@gnu.org */ + +#include "pr11734.h" + +int +main () +{ + pr11734 *p = new pr11734; + p->foo (); + return 0; +} + Index: testsuite/gdb.cp/pr11734-2.cc =================================================================== RCS file: testsuite/gdb.cp/pr11734-2.cc diff -N testsuite/gdb.cp/pr11734-2.cc --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ testsuite/gdb.cp/pr11734-2.cc 9 Dec 2010 00:49:10 -0000 @@ -0,0 +1,27 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2010 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 . + + Please email any bugs, comments, and/or additions to this file to: + bug-gdb@gnu.org */ + +#include "pr11734.h" + +void +pr11734::foo(void) +{ +} + Index: testsuite/gdb.cp/pr11734-3.cc =================================================================== RCS file: testsuite/gdb.cp/pr11734-3.cc diff -N testsuite/gdb.cp/pr11734-3.cc --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ testsuite/gdb.cp/pr11734-3.cc 9 Dec 2010 00:49:10 -0000 @@ -0,0 +1,27 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2010 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 . + + Please email any bugs, comments, and/or additions to this file to: + bug-gdb@gnu.org */ + +#include "pr11734.h" + +void +pr11734::foo (int a) +{ +} + Index: testsuite/gdb.cp/pr11734-4.cc =================================================================== RCS file: testsuite/gdb.cp/pr11734-4.cc diff -N testsuite/gdb.cp/pr11734-4.cc --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ testsuite/gdb.cp/pr11734-4.cc 9 Dec 2010 00:49:10 -0000 @@ -0,0 +1,27 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2010 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 . + + Please email any bugs, comments, and/or additions to this file to: + bug-gdb@gnu.org */ + +#include "pr11734.h" + +void +pr11734::foo (char *a) +{ +} + Index: testsuite/gdb.cp/pr11734.exp =================================================================== RCS file: testsuite/gdb.cp/pr11734.exp diff -N testsuite/gdb.cp/pr11734.exp --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ testsuite/gdb.cp/pr11734.exp 9 Dec 2010 00:49:10 -0000 @@ -0,0 +1,67 @@ +# Copyright 2010 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. + +if { [skip_cplus_tests] } { continue } + +set testfile "pr11734" +set class $testfile +set binfile [file join $objdir $subdir $testfile] + +set srcfiles {} +for {set i 1} {$i < 5} {incr i} { + lappend srcfiles [file join $srcdir $subdir $testfile-$i.cc] +} +if {[gdb_compile $srcfiles $binfile executable {debug c++}] != "" } { + untested pr11734.exp + return -1 +} + +if {[get_compiler_info $binfile "c++"]} { + return -1 +} + +gdb_exit +gdb_start +gdb_reinitialize_dir $srcdir/$subdir +gdb_load $binfile + +if {![runto_main]} { + perror "couldn't run to breakpoint" + continue +} + +# An array holding the overload types for the method pr11734::foo. The +# first element is the overloaded method parameter. The second element +# is the expected source file number, e.g. "pr11734-?.cc". +array set tests { + "char*" 4 + "int" 3 + "" 2 +} + +# Test each overload instance twice: once quoted, once unquoted +foreach ovld [array names tests] { + set method "${class}::foo\($ovld\)" + set result "Breakpoint (\[0-9\]).*file .*/$class-$tests($ovld).*" + gdb_test "break $method" $result + gdb_test "break '$method'" $result +} + +gdb_exit +return 0 Index: testsuite/gdb.cp/pr11734.h =================================================================== RCS file: testsuite/gdb.cp/pr11734.h diff -N testsuite/gdb.cp/pr11734.h --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ testsuite/gdb.cp/pr11734.h 9 Dec 2010 00:49:10 -0000 @@ -0,0 +1,28 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2010 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 . + + Please email any bugs, comments, and/or additions to this file to: + bug-gdb@gnu.org */ + +class pr11734 +{ + public: + void foo (); + void foo (int); + void foo (char *); +}; + --------------070705060409060107060108--