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

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