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/Ada] wrong value returned by ada-lang.c:compare_names


The ada-lang.c:compare_names function returns the wrong value
when the first string starts with the same contents as the second
string, followed by '_' and then some characters that do not make
a symbol name suffix.  For instance:

    string1 = "generics__test_generics__instance__print"
    string2 = "generics__test_generics"

In that case, compare_names (string1, string2) return -1, when
clearly, string1 is greater than string2.

A consequence of this problem is that GDB may fail to lookup
"generics.test_generics" from our partial symtabs, because
partial symbols are ordered by strcmp_iw_ordered:

    (gdb) b generics.test_generics
    Function "generics.test_generics" not defined.
    Make breakpoint pending on future shared library load? (y or [n])

gdb/ChangeLog:

        * ada-lang.c (compare_names): Fix wrong return value in case
        string1 starts with the same contents as string2, followed
        by an underscore that do not start a symbol name suffix.

gdb/testsuite/ChangeLog:

        * gdb.ada/fullname_bp: New testcase.

Tested on x86_64-linux. Checked in.

---
 gdb/ChangeLog                             |    6 +++++
 gdb/ada-lang.c                            |    2 +-
 gdb/testsuite/ChangeLog                   |    4 +++
 gdb/testsuite/gdb.ada/fullname_bp.exp     |   34 ++++++++++++++++++++++++++++
 gdb/testsuite/gdb.ada/fullname_bp/dn.adb  |   21 +++++++++++++++++
 gdb/testsuite/gdb.ada/fullname_bp/dn.ads  |   19 +++++++++++++++
 gdb/testsuite/gdb.ada/fullname_bp/foo.adb |   21 +++++++++++++++++
 gdb/testsuite/gdb.ada/fullname_bp/pck.adb |   35 +++++++++++++++++++++++++++++
 gdb/testsuite/gdb.ada/fullname_bp/pck.ads |   22 ++++++++++++++++++
 9 files changed, 163 insertions(+), 1 deletions(-)
 create mode 100644 gdb/testsuite/gdb.ada/fullname_bp.exp
 create mode 100644 gdb/testsuite/gdb.ada/fullname_bp/dn.adb
 create mode 100644 gdb/testsuite/gdb.ada/fullname_bp/dn.ads
 create mode 100644 gdb/testsuite/gdb.ada/fullname_bp/foo.adb
 create mode 100644 gdb/testsuite/gdb.ada/fullname_bp/pck.adb
 create mode 100644 gdb/testsuite/gdb.ada/fullname_bp/pck.ads

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 7a6aaea..cf90f8b 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,9 @@
+2011-11-28  Joel Brobecker  <brobecker@adacore.com>
+
+	* ada-lang.c (compare_names): Fix wrong return value in case
+	string1 starts with the same contents as string2, followed
+	by an underscore that do not start a symbol name suffix.
+
 2011-11-28  Phil Muldoon  <pmuldoon@redhat.com>
 
 	PR python/13369
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index a9b2f24..e9494ae 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -4894,7 +4894,7 @@ compare_names (const char *string1, const char *string2)
 	  if (is_name_suffix (string1))
 	    return 0;
 	  else
-	    return -1;
+	    return 1;
 	}
       /* FALLTHROUGH */
     default:
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 8c0c1c0..04da9f5 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2011-11-28  Joel Brobecker  <brobecker@adacore.com>
+
+	* gdb.ada/fullname_bp: New testcase.
+
 2011-11-25  Jan Kratochvil  <jan.kratochvil@redhat.com>
 
 	PR testsuite/12649
diff --git a/gdb/testsuite/gdb.ada/fullname_bp.exp b/gdb/testsuite/gdb.ada/fullname_bp.exp
new file mode 100644
index 0000000..faf63b9
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/fullname_bp.exp
@@ -0,0 +1,34 @@
+# 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/>.
+
+load_lib "ada.exp"
+
+set testdir "fullname_bp"
+set testfile "${testdir}/foo"
+set srcfile ${srcdir}/${subdir}/${testfile}.adb
+set binfile ${objdir}/${subdir}/${testfile}
+
+file mkdir ${objdir}/${subdir}/${testdir}
+if {[gdb_compile_ada "${srcfile}" "${binfile}" executable [list debug ]] != "" } {
+  return -1
+}
+
+clean_restart ${testfile}
+
+# Break on "pck.hello" rather than just "hello" to make sure we trigger
+# the non-wild symbol lookup.
+gdb_test "break pck.hello" \
+         "Breakpoint \[0-9\]+ at 0x\[0-9a-f\]+: file .*pck.adb, line \[0-9\]+."
+
diff --git a/gdb/testsuite/gdb.ada/fullname_bp/dn.adb b/gdb/testsuite/gdb.ada/fullname_bp/dn.adb
new file mode 100644
index 0000000..e66c420
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/fullname_bp/dn.adb
@@ -0,0 +1,21 @@
+--  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/>.
+
+package body Dn is
+   procedure Do_Nothing (A : System.Address) is
+   begin
+      null;
+   end Do_Nothing;
+end Dn;
diff --git a/gdb/testsuite/gdb.ada/fullname_bp/dn.ads b/gdb/testsuite/gdb.ada/fullname_bp/dn.ads
new file mode 100644
index 0000000..2dcf355
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/fullname_bp/dn.ads
@@ -0,0 +1,19 @@
+--  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/>.
+
+with System;
+package Dn is
+   procedure Do_Nothing (A : System.Address);
+end Dn;
diff --git a/gdb/testsuite/gdb.ada/fullname_bp/foo.adb b/gdb/testsuite/gdb.ada/fullname_bp/foo.adb
new file mode 100644
index 0000000..5614eb8
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/fullname_bp/foo.adb
@@ -0,0 +1,21 @@
+--  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/>.
+
+with Pck; use Pck;
+procedure Foo is
+begin
+   Hello;
+   There;
+end Foo;
diff --git a/gdb/testsuite/gdb.ada/fullname_bp/pck.adb b/gdb/testsuite/gdb.ada/fullname_bp/pck.adb
new file mode 100644
index 0000000..1ec2baa
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/fullname_bp/pck.adb
@@ -0,0 +1,35 @@
+--  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/>.
+
+with Dn; use Dn;
+
+package body Pck is
+   procedure Hello is
+      procedure Nested is
+         I : Integer := 0;
+      begin
+         Do_Nothing (I'Address);
+      end Nested;
+   begin
+      Nested;
+   end Hello;
+
+   procedure There is
+   begin
+      null;
+   end There;
+end Pck;
+
+
diff --git a/gdb/testsuite/gdb.ada/fullname_bp/pck.ads b/gdb/testsuite/gdb.ada/fullname_bp/pck.ads
new file mode 100644
index 0000000..cb714ef
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/fullname_bp/pck.ads
@@ -0,0 +1,22 @@
+--  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/>.
+
+package Pck is
+   procedure Hello;
+   procedure There;
+   --  The name of that procedure needs to be greater (in terms
+   --  of alphabetical order) than the name of the procedure above.
+end Pck;
+
-- 
1.7.1


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