Blame SOURCES/gdb-rhbz809179-global-variable-nested-dso.patch

2c2fa1
This bug is already fixed in the RHEL-7.1 GDB version.  However, it is
2c2fa1
also important to add a testcase, so the following is a patch to add
2c2fa1
this test.
2c2fa1
2c2fa1
This is the original message submitted to gdb-patches:
2c2fa1
2c2fa1
    From: Sergio Durigan Junior <sergiodj at redhat dot com>
2c2fa1
    To: GDB Patches <gdb-patches at sourceware dot org>
2c2fa1
    Subject: [PATCH] Add test for global variable that is nested by another DSO
2c2fa1
    Date: Thu,  4 Sep 2014 17:32:53 -0400
2c2fa1
    Message-Id: <1409866373-16413-1-git-send-email-sergiodj@redhat.com>
2c2fa1
2c2fa1
    This is just a testcase addition that I am proposing for upstream GDB.
2c2fa1
    We have this in our internal tree, and the related RH bug is:
2c2fa1
    
2c2fa1
      <https://bugzilla.redhat.com/show_bug.cgi?id=809179>
2c2fa1
    
2c2fa1
    (You might not be able to see all the comments without privileges.)
2c2fa1
    
2c2fa1
    This bug is about a global variable that got incorrectly displayed by
2c2fa1
    GDB.  This bug has already been fixed a long time ago by Joel's
2c2fa1
    commit:
2c2fa1
    
2c2fa1
      commit 19630284f570790ebf6d50bfb43caa1f125ee88a
2c2fa1
      Author: Joel Brobecker <brobecker@gnat.com>
2c2fa1
      Date:   Tue Jun 5 13:50:50 2012 +0000
2c2fa1
    
2c2fa1
    But I think a testcase for it wouldn't hurt.
2c2fa1
    
2c2fa1
    So, consider the following scenario:
2c2fa1
    
2c2fa1
      $ cat solib1.c
2c2fa1
      int test;
2c2fa1
      void c_main (void)
2c2fa1
      {
2c2fa1
        test = 42;
2c2fa1
      }
2c2fa1
    
2c2fa1
      $ cat solib2.c
2c2fa1
      int test;
2c2fa1
      void b_main (void)
2c2fa1
      {
2c2fa1
        test = 42;
2c2fa1
      }
2c2fa1
    
2c2fa1
      $ cat main.c
2c2fa1
      int main (int argc, char *argv[])
2c2fa1
      {
2c2fa1
        c_main ();
2c2fa1
        b_main ();
2c2fa1
        return 0;
2c2fa1
      }
2c2fa1
    
2c2fa1
      $ gcc -g -fPIC -shared -o libSO1.so -c solib1.c
2c2fa1
      $ gcc -g -fPIC -shared -o libSO2.so -c solib2.c
2c2fa1
      $ gcc -g -o main -L$PWD -lSO1 -lSO2 main.c
2c2fa1
      $ LD_LIBRARY_PATH=. gdb -q -batch -ex 'b c_main' -ex r -ex n -ex 'p test' ./main
2c2fa1
      ...
2c2fa1
      $1 = 0
2c2fa1
    
2c2fa1
    This happened with GDB before Joel's commit above.  Now, things work
2c2fa1
    and GDB is able to correctly display the nested global variable:
2c2fa1
    
2c2fa1
      $ LD_LIBRARY_PATH=. gdb -q -batch -ex 'b c_main' -ex r -ex n -ex 'p test' ./main
2c2fa1
      ...
2c2fa1
      $1 = 42
2c2fa1
    
2c2fa1
    The testcase attached tests this behavior.
2c2fa1
    
2c2fa1
    gdb/testsuite/ChangeLog:
2c2fa1
    2014-09-04  Sergio Durigan Junior  <sergiodj@redhat.com>
2c2fa1
    
2c2fa1
    	* gdb.base/global-var-nested-by-dso-solib1.c: New file.
2c2fa1
    	* gdb.base/global-var-nested-by-dso-solib2.c: Likewise.
2c2fa1
    	* gdb.base/global-var-nested-by-dso.c: Likewise.
2c2fa1
    	* gdb.base/global-var-nested-by-dso.exp: Likewise.
2c2fa1
2c2fa1
2c2fa1
Index: gdb-7.6.1/gdb/testsuite/gdb.base/global-var-nested-by-dso-solib1.c
2c2fa1
===================================================================
2c2fa1
--- /dev/null
2c2fa1
+++ gdb-7.6.1/gdb/testsuite/gdb.base/global-var-nested-by-dso-solib1.c
2c2fa1
@@ -0,0 +1,24 @@
2c2fa1
+/* Copyright 2014 Free Software Foundation, Inc.
2c2fa1
+
2c2fa1
+   This file is part of GDB.
2c2fa1
+
2c2fa1
+   This program is free software; you can redistribute it and/or modify
2c2fa1
+   it under the terms of the GNU General Public License as published by
2c2fa1
+   the Free Software Foundation; either version 3 of the License, or
2c2fa1
+   (at your option) any later version.
2c2fa1
+
2c2fa1
+   This program is distributed in the hope that it will be useful,
2c2fa1
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
2c2fa1
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
2c2fa1
+   GNU General Public License for more details.
2c2fa1
+
2c2fa1
+   You should have received a copy of the GNU General Public License
2c2fa1
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
2c2fa1
+
2c2fa1
+int test;
2c2fa1
+
2c2fa1
+void
2c2fa1
+c_main (void)
2c2fa1
+{
2c2fa1
+  test = 42;
2c2fa1
+}
2c2fa1
Index: gdb-7.6.1/gdb/testsuite/gdb.base/global-var-nested-by-dso-solib2.c
2c2fa1
===================================================================
2c2fa1
--- /dev/null
2c2fa1
+++ gdb-7.6.1/gdb/testsuite/gdb.base/global-var-nested-by-dso-solib2.c
2c2fa1
@@ -0,0 +1,24 @@
2c2fa1
+/* Copyright 2014 Free Software Foundation, Inc.
2c2fa1
+
2c2fa1
+   This file is part of GDB.
2c2fa1
+
2c2fa1
+   This program is free software; you can redistribute it and/or modify
2c2fa1
+   it under the terms of the GNU General Public License as published by
2c2fa1
+   the Free Software Foundation; either version 3 of the License, or
2c2fa1
+   (at your option) any later version.
2c2fa1
+
2c2fa1
+   This program is distributed in the hope that it will be useful,
2c2fa1
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
2c2fa1
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
2c2fa1
+   GNU General Public License for more details.
2c2fa1
+
2c2fa1
+   You should have received a copy of the GNU General Public License
2c2fa1
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
2c2fa1
+
2c2fa1
+int test;
2c2fa1
+
2c2fa1
+void
2c2fa1
+b_main (void)
2c2fa1
+{
2c2fa1
+  test = 42;
2c2fa1
+}
2c2fa1
Index: gdb-7.6.1/gdb/testsuite/gdb.base/global-var-nested-by-dso.c
2c2fa1
===================================================================
2c2fa1
--- /dev/null
2c2fa1
+++ gdb-7.6.1/gdb/testsuite/gdb.base/global-var-nested-by-dso.c
2c2fa1
@@ -0,0 +1,24 @@
2c2fa1
+/* Copyright 2014 Free Software Foundation, Inc.
2c2fa1
+
2c2fa1
+   This file is part of GDB.
2c2fa1
+
2c2fa1
+   This program is free software; you can redistribute it and/or modify
2c2fa1
+   it under the terms of the GNU General Public License as published by
2c2fa1
+   the Free Software Foundation; either version 3 of the License, or
2c2fa1
+   (at your option) any later version.
2c2fa1
+
2c2fa1
+   This program is distributed in the hope that it will be useful,
2c2fa1
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
2c2fa1
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
2c2fa1
+   GNU General Public License for more details.
2c2fa1
+
2c2fa1
+   You should have received a copy of the GNU General Public License
2c2fa1
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
2c2fa1
+
2c2fa1
+int
2c2fa1
+main (int argc, char *argv[])
2c2fa1
+{
2c2fa1
+  c_main ();
2c2fa1
+  b_main ();
2c2fa1
+  return 0;
2c2fa1
+}
2c2fa1
Index: gdb-7.6.1/gdb/testsuite/gdb.base/global-var-nested-by-dso.exp
2c2fa1
===================================================================
2c2fa1
--- /dev/null
2c2fa1
+++ gdb-7.6.1/gdb/testsuite/gdb.base/global-var-nested-by-dso.exp
2c2fa1
@@ -0,0 +1,55 @@
2c2fa1
+# Copyright 2014 Free Software Foundation, Inc.
2c2fa1
+
2c2fa1
+# This program is free software; you can redistribute it and/or modify
2c2fa1
+# it under the terms of the GNU General Public License as published by
2c2fa1
+# the Free Software Foundation; either version 3 of the License, or
2c2fa1
+# (at your option) any later version.
2c2fa1
+#
2c2fa1
+# This program is distributed in the hope that it will be useful,
2c2fa1
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
2c2fa1
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
2c2fa1
+# GNU General Public License for more details.
2c2fa1
+#
2c2fa1
+# You should have received a copy of the GNU General Public License
2c2fa1
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
2c2fa1
+
2c2fa1
+if { [skip_shlib_tests] } {
2c2fa1
+    return 0
2c2fa1
+}
2c2fa1
+
2c2fa1
+standard_testfile
2c2fa1
+
2c2fa1
+set lib1name $testfile-solib1
2c2fa1
+set srcfile_lib1 $srcdir/$subdir/$lib1name.c
2c2fa1
+set binfile_lib1 [standard_output_file $lib1name.so]
2c2fa1
+
2c2fa1
+set lib2name $testfile-solib2
2c2fa1
+set srcfile_lib2 $srcdir/$subdir/$lib2name.c
2c2fa1
+set binfile_lib2 [standard_output_file $lib2name.so]
2c2fa1
+
2c2fa1
+if { [gdb_compile_shlib $srcfile_lib1 $binfile_lib1 \
2c2fa1
+	[list debug additional_flags=-fPIC]] != "" } {
2c2fa1
+  untested "Could not compile $binfile_lib1."
2c2fa1
+  return -1
2c2fa1
+}
2c2fa1
+
2c2fa1
+if { [gdb_compile_shlib $srcfile_lib2 $binfile_lib2 \
2c2fa1
+	[list debug additional_flags=-fPIC]] != "" } {
2c2fa1
+  untested "Could not compile $binfile_lib2."
2c2fa1
+  return -1
2c2fa1
+}
2c2fa1
+
2c2fa1
+if { [gdb_compile $srcdir/$subdir/$srcfile $binfile executable \
2c2fa1
+	[list debug shlib=$binfile_lib1 shlib=$binfile_lib2]] != "" } {
2c2fa1
+  return -1
2c2fa1
+}
2c2fa1
+
2c2fa1
+clean_restart $binfile
2c2fa1
+
2c2fa1
+if { ![runto_main] } {
2c2fa1
+  return -1
2c2fa1
+}
2c2fa1
+
2c2fa1
+gdb_test "next" "$decimal.*b_main \\(\\);"
2c2fa1
+gdb_test "next" "$decimal.*return 0;"
2c2fa1
+gdb_test "print test" " = 42"