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

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