This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[commit+commit 7.3] [patch] physname-related CU expansion issue for C++ (PR 12708)


On Thu, 28 Apr 2011 21:51:29 +0200, Jan Kratochvil wrote:
> gdb/
> 2011-04-28  Jan Kratochvil  <jan.kratochvil@redhat.com>
> 
>     
> 	* symtab.c (compare_symbol_name): New function.
> 	(completion_list_add_name, expand_partial_symbol_name): Call it,
> 	remove the variable ncmp.
> 	(default_make_symbol_completion_list_break_on): Reduce SYM_TEXT_LEN,
> 	gdb_assert it.
> 
> Gdb/testsuite/
> 2011-04-28  Jan Kratochvil  <jan.kratochvil@redhat.com>
> 
> 	* gdb.cp/psymtab-parameter.cc: New file.
> 	* gdb.cp/psymtab-parameter.exp: New file.

As this is was a regression checked it in after 7 days without comments:
	http://sourceware.org/ml/gdb-cvs/2011-05/msg00040.html

For gdb_7_3-branch checked in and the slightly modified variant (as there is
no case insensitive lookup support) attached:
	http://sourceware.org/ml/gdb-cvs/2011-05/msg00041.html


Thanks,
Jan


http://sourceware.org/ml/gdb-cvs/2011-05/msg00041.html

--- src/gdb/ChangeLog	2011/05/03 16:25:18	1.12887.2.19
+++ src/gdb/ChangeLog	2011/05/06 13:53:14	1.12887.2.20
@@ -1,3 +1,11 @@
+2011-05-06  Jan Kratochvil  <jan.kratochvil@redhat.com>
+
+	* symtab.c (compare_symbol_name): New function.
+	(completion_list_add_name, expand_partial_symbol_name): Call it,
+	remove the variable ncmp.
+	(default_make_symbol_completion_list_break_on): Reduce SYM_TEXT_LEN,
+	gdb_assert it.
+
 2011-05-03  Joel Brobecker <brobecker@adacore.com>
 
         Revert:
--- src/gdb/symtab.c	2011/04/20 20:10:29	1.262.2.1
+++ src/gdb/symtab.c	2011/05/06 13:53:15	1.262.2.2
@@ -3481,6 +3481,36 @@
 }
 
 
+/* Evaluate if NAME matches SYM_TEXT and SYM_TEXT_LEN.
+
+   Either sym_text[sym_text_len] != '(' and then we search for any
+   symbol starting with SYM_TEXT text.
+
+   Otherwise sym_text[sym_text_len] == '(' and then we require symbol name to
+   be terminated at that point.  Partial symbol tables do not have parameters
+   information.  */
+
+static int
+compare_symbol_name (const char *name, const char *sym_text, int sym_text_len)
+{
+  if (strncmp (name, sym_text, sym_text_len) != 0)
+    return 0;
+
+  if (sym_text[sym_text_len] == '(')
+    {
+      /* User searches for `name(someth...'.  Require NAME to be terminated.
+	 Normally psymtabs and gdbindex have no parameter types so '\0' will be
+	 present but accept even parameters presence.  In this case this
+	 function is in fact strcmp_iw but whitespace skipping is not supported
+	 for tab completion.  */
+
+      if (name[sym_text_len] != '\0' && name[sym_text_len] != '(')
+	return 0;
+    }
+
+  return 1;
+}
+
 /* Helper routine for make_symbol_completion_list.  */
 
 static int return_val_size;
@@ -3502,11 +3532,8 @@
   int newsize;
 
   /* Clip symbols that cannot match.  */
-
-  if (strncmp (symname, sym_text, sym_text_len) != 0)
-    {
-      return;
-    }
+  if (!compare_symbol_name (symname, sym_text, sym_text_len))
+    return;
 
   /* We have a match for a completion, so add SYMNAME to the current list
      of matches.  Note that the name is moved to freshly malloc'd space.  */
@@ -3697,7 +3724,7 @@
 {
   struct add_name_data *datum = (struct add_name_data *) user_data;
 
-  return strncmp (name, datum->sym_text, datum->sym_text_len) == 0;
+  return compare_symbol_name (name, datum->sym_text, datum->sym_text_len);
 }
 
 char **
@@ -3776,6 +3803,22 @@
 
   sym_text_len = strlen (sym_text);
 
+  /* Prepare SYM_TEXT_LEN for compare_symbol_name.  */
+
+  if (current_language->la_language == language_cplus
+      || current_language->la_language == language_java
+      || current_language->la_language == language_fortran)
+    {
+      /* These languages may have parameters entered by user but they are never
+	 present in the partial symbol tables.  */
+
+      const char *cs = memchr (sym_text, '(', sym_text_len);
+
+      if (cs)
+	sym_text_len = cs - sym_text;
+    }
+  gdb_assert (sym_text[sym_text_len] == '\0' || sym_text[sym_text_len] == '(');
+
   return_val_size = 100;
   return_val_index = 0;
   return_val = (char **) xmalloc ((return_val_size + 1) * sizeof (char *));
--- src/gdb/testsuite/ChangeLog	2011/04/29 12:50:38	1.2655.2.6
+++ src/gdb/testsuite/ChangeLog	2011/05/06 13:53:15	1.2655.2.7
@@ -1,3 +1,8 @@
+2011-05-06  Jan Kratochvil  <jan.kratochvil@redhat.com>
+
+	* gdb.cp/psymtab-parameter.cc: New file.
+	* gdb.cp/psymtab-parameter.exp: New file.
+
 2011-04-29  Phil Muldoon  <pmuldoon@redhat.com>
 
 	PR mi/12531
--- src/gdb/testsuite/gdb.cp/psymtab-parameter.cc
+++ src/gdb/testsuite/gdb.cp/psymtab-parameter.cc	2011-05-06 13:54:46.271069000 +0000
@@ -0,0 +1,22 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2009, 2010, 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 <http://www.gnu.org/licenses/>.
+   */
+
+typedef int typedefed;
+void func (typedefed param)
+{
+}
--- src/gdb/testsuite/gdb.cp/psymtab-parameter.exp
+++ src/gdb/testsuite/gdb.cp/psymtab-parameter.exp	2011-05-06 13:54:46.669342000 +0000
@@ -0,0 +1,39 @@
+# 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 <http://www.gnu.org/licenses/>.
+
+if { [skip_cplus_tests] } { continue }
+
+
+set testfile psymtab-parameter
+set executable ${testfile}.x
+set srcfile ${testfile}.cc
+set binfile ${objdir}/${subdir}/${executable}
+
+if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" object {debug c++}] != "" } {
+    untested ${testfile}.exp
+    return -1
+}
+
+clean_restart $executable
+
+# As `main' is not present GDB fails to find the proper inferior language.
+gdb_test_no_output "set language c++"
+
+# The goal is to keep the CU (Compilation Unit) unexpanded.  It would be rather
+# XFAIL than FAIL here.  For example -readnow breaks it.
+gdb_test_no_output "maintenance info symtabs"
+
+# GDB has shown only the `func(int)' entry before.
+gdb_test "complete break 'func(" "break 'func\\(int\\)\r\nbreak 'func\\(typedefed\\)"


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]