Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Keith Seitz <keiths@redhat.com>
To: gdb-patches@sourceware.org
Cc: Pedro Alves <pedro@codesourcery.com>
Subject: Re: [RFA] c++/11734
Date: Tue, 22 Jun 2010 15:43:00 -0000	[thread overview]
Message-ID: <4C20DA1A.10301@redhat.com> (raw)
In-Reply-To: <201006221045.23196.pedro@codesourcery.com>

[-- Attachment #1: Type: text/plain, Size: 561 bytes --]

On 06/22/2010 02:45 AM, Pedro Alves wrote:
> It looks like `name' is invariant in
> this loop, so you could for example, move the `new' declaration
> out of the loop, initialized as NULL, and allocate it only once
> on first need.

I completely missed that. [Forest/trees kind of thing, I guess.]

I noticed that I also missed adding this logic to the linear search 
case. I've attached a revised patch which addresses this missed bit and 
moves the alloca out of the loop.

Good catch!

Keith

PS. In case it isn't well-known: regression-free on x86_64 linux.

[-- Attachment #2: pr11734-2.patch --]
[-- Type: text/plain, Size: 11880 bytes --]

Index: linespec.c
===================================================================
RCS file: /cvs/src/src/gdb/linespec.c,v
retrieving revision 1.103
diff -u -p -r1.103 linespec.c
--- linespec.c	14 May 2010 23:41:04 -0000	1.103
+++ linespec.c	22 Jun 2010 15:39:18 -0000
@@ -1217,6 +1217,19 @@ decode_compound (char **argptr, int funf
   struct type *t;
   char *saved_java_argptr = NULL;
 
+  /* Strip single quotes from SAVED_ARG.  This interferes with this function
+     which might, e.g., later call strcmp_iw with SYMBOL_LINKAGE_NAME
+     (which never contains quotes).  */
+  if (*saved_arg == '\'')
+    {
+      char *close = strrchr (saved_arg, '\'');
+      if (close)
+	{
+	  ++saved_arg;
+	  *close = '\0';
+	}
+    }
+
   /* 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
Index: psymtab.c
===================================================================
RCS file: /cvs/src/src/gdb/psymtab.c,v
retrieving revision 1.4
diff -u -p -r1.4 psymtab.c
--- psymtab.c	16 May 2010 01:27:02 -0000	1.4
+++ psymtab.c	22 Jun 2010 15:39:20 -0000
@@ -432,6 +432,7 @@ 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;
+  char *simple_name = NULL, *paren;
 
   if (length == 0)
     {
@@ -441,6 +442,14 @@ lookup_partial_symbol (struct partial_sy
 	   pst->objfile->global_psymbols.list + pst->globals_offset :
 	   pst->objfile->static_psymbols.list + pst->statics_offset);
 
+  paren = strchr (name, '(');
+  if (paren)
+    {
+      simple_name = alloca (strlen (name));
+      memcpy (simple_name, name, paren - name);
+      simple_name[name - paren] = '\0';
+    }
+
   if (global)			/* This means we can use a binary search. */
     {
       do_linear_search = 0;
@@ -476,12 +485,32 @@ lookup_partial_symbol (struct partial_sy
       if (!(top == bottom))
 	internal_error (__FILE__, __LINE__, _("failed internal consistency check"));
 
-      while (top <= real_top
-	     && SYMBOL_MATCHES_SEARCH_NAME (*top, name))
+      while (top <= real_top)
 	{
-	  if (symbol_matches_domain (SYMBOL_LANGUAGE (*top),
-				     SYMBOL_DOMAIN (*top), domain))
-	    return (*top);
+	  if (SYMBOL_MATCHES_SEARCH_NAME (*top, name))
+	    {
+	      if (symbol_matches_domain (SYMBOL_LANGUAGE (*top),
+					 SYMBOL_DOMAIN (*top), domain))
+		return (*top);
+	    }
+	  else
+	    {
+	      if (simple_name)
+		{
+		  /* NAME has overload information.  Partial symbols, however,
+		     do not.  This is a case of mistaken identity.
+
+		     Although hacky, this is fixed by expanding this psymtab,
+		     which will allow any subsequent symtab search to succeed.
+
+		     For more details/test case, please refer to c++/11734.  */
+
+		  if (SYMBOL_MATCHES_SEARCH_NAME (*top, simple_name))
+		    PSYMTAB_TO_SYMTAB (pst);
+		}
+	      else
+		break;
+	    }
 	  top++;
 	}
     }
@@ -497,6 +526,11 @@ lookup_partial_symbol (struct partial_sy
 				     SYMBOL_DOMAIN (*psym), domain)
 	      && SYMBOL_MATCHES_SEARCH_NAME (*psym, name))
 	    return (*psym);
+	  else if (simple_name && SYMBOL_MATCHES_SEARCH_NAME (*psym, simple_name))
+	    {
+	      PSYMTAB_TO_SYMTAB (pst);
+	      break;
+	    }
 	}
     }
 
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	22 Jun 2010 15:39:25 -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 <http://www.gnu.org/licenses/>.
+
+   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	22 Jun 2010 15:39:25 -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 <http://www.gnu.org/licenses/>.
+
+   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	22 Jun 2010 15:39:25 -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 <http://www.gnu.org/licenses/>.
+
+   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	22 Jun 2010 15:39:25 -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 <http://www.gnu.org/licenses/>.
+
+   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	22 Jun 2010 15:39:25 -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 <http://www.gnu.org/licenses/>.
+
+# 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	22 Jun 2010 15:39:25 -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 <http://www.gnu.org/licenses/>.
+
+   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 *);
+};
+

  reply	other threads:[~2010-06-22 15:43 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-06-22  1:22 Keith Seitz
2010-06-22  9:45 ` Pedro Alves
2010-06-22 15:43   ` Keith Seitz [this message]
2010-06-23 17:33     ` Keith Seitz
2010-06-24  2:25     ` Doug Evans
2010-06-24 11:39       ` Matt Rice
2010-06-24 16:05       ` Doug Evans
2010-06-24 20:01       ` Tom Tromey
2010-06-24 20:49         ` Doug Evans
2010-06-24 20:51       ` Keith Seitz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4C20DA1A.10301@redhat.com \
    --to=keiths@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=pedro@codesourcery.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox