Blame SOURCES/gdb-6.6-buildid-locate-solib-missing-ids.patch

e1d87d
gdb returns an incorrect back trace when applying a debuginfo
e1d87d
https://bugzilla.redhat.com/show_bug.cgi?id=1339862
e1d87d
e1d87d
Index: gdb-7.9.90.20150709/gdb/solib-svr4.c
e1d87d
===================================================================
e1d87d
--- gdb-7.9.90.20150709.orig/gdb/solib-svr4.c	2015-07-09 18:18:54.526417766 +0200
e1d87d
+++ gdb-7.9.90.20150709/gdb/solib-svr4.c	2015-07-09 18:19:33.074746586 +0200
e1d87d
@@ -1381,14 +1381,27 @@ svr4_read_so_list (CORE_ADDR lm, CORE_AD
e1d87d
 	}
e1d87d
 
e1d87d
       {
e1d87d
-	struct bfd_build_id *build_id;
e1d87d
+	struct bfd_build_id *build_id = NULL;
e1d87d
 
e1d87d
 	strncpy (newobj->so_original_name, buffer, SO_NAME_MAX_PATH_SIZE - 1);
e1d87d
 	newobj->so_original_name[SO_NAME_MAX_PATH_SIZE - 1] = '\0';
e1d87d
 	/* May get overwritten below.  */
e1d87d
 	strcpy (newobj->so_name, newobj->so_original_name);
e1d87d
 
e1d87d
-	build_id = build_id_addr_get (newobj->lm_info->l_ld);
e1d87d
+	/* In the case the main executable was found according to its build-id
e1d87d
+	   (from a core file) prevent loading a different build of a library
e1d87d
+	   with accidentally the same SO_NAME.
e1d87d
+
e1d87d
+	   It suppresses bogus backtraces (and prints "??" there instead) if
e1d87d
+	   the on-disk files no longer match the running program version.
e1d87d
+
e1d87d
+	   If the main executable was not loaded according to its build-id do
e1d87d
+	   not do any build-id checking of the libraries.  There may be missing
e1d87d
+	   build-ids dumped in the core file and we would map all the libraries
e1d87d
+	   to the only existing file loaded that time - the executable.  */
e1d87d
+	if (symfile_objfile != NULL
e1d87d
+	    && (symfile_objfile->flags & OBJF_BUILD_ID_CORE_LOADED) != 0)
e1d87d
+	  build_id = build_id_addr_get (newobj->lm_info->l_ld);
e1d87d
 	if (build_id != NULL)
e1d87d
 	  {
e1d87d
 	    char *name, *build_id_filename;
e1d87d
@@ -1403,23 +1416,7 @@ svr4_read_so_list (CORE_ADDR lm, CORE_AD
e1d87d
 		xfree (name);
e1d87d
 	      }
e1d87d
 	    else
e1d87d
-	      {
e1d87d
-		debug_print_missing (newobj->so_name, build_id_filename);
e1d87d
-
e1d87d
-		/* In the case the main executable was found according to
e1d87d
-		   its build-id (from a core file) prevent loading
e1d87d
-		   a different build of a library with accidentally the
e1d87d
-		   same SO_NAME.
e1d87d
-
e1d87d
-		   It suppresses bogus backtraces (and prints "??" there
e1d87d
-		   instead) if the on-disk files no longer match the
e1d87d
-		   running program version.  */
e1d87d
-
e1d87d
-		if (symfile_objfile != NULL
e1d87d
-		    && (symfile_objfile->flags
e1d87d
-			& OBJF_BUILD_ID_CORE_LOADED) != 0)
e1d87d
-		  newobj->so_name[0] = 0;
e1d87d
-	      }
e1d87d
+	      debug_print_missing (newobj->so_name, build_id_filename);
e1d87d
 
e1d87d
 	    xfree (build_id_filename);
e1d87d
 	    xfree (build_id);
e1d87d
--- /dev/null	2016-07-02 20:29:01.679404943 +0200
e1d87d
+++ gdb-7.11.50.20160721/gdb/testsuite/gdb.base/gcore-buildid-exec-but-not-solib.exp	2016-07-31 23:04:49.062753722 +0200
e1d87d
@@ -0,0 +1,105 @@
e1d87d
+# Copyright 2016 Free Software Foundation, Inc.
e1d87d
+
e1d87d
+# This program is free software; you can redistribute it and/or modify
e1d87d
+# it under the terms of the GNU General Public License as published by
e1d87d
+# the Free Software Foundation; either version 3 of the License, or
e1d87d
+# (at your option) any later version.
e1d87d
+#
e1d87d
+# This program is distributed in the hope that it will be useful,
e1d87d
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
e1d87d
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
e1d87d
+# GNU General Public License for more details.
e1d87d
+#
e1d87d
+# You should have received a copy of the GNU General Public License
e1d87d
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
e1d87d
+
e1d87d
+if {[skip_shlib_tests]} {
e1d87d
+    return 0
e1d87d
+}
e1d87d
+
e1d87d
+set testfile "gcore-buildid-exec-but-not-solib"
e1d87d
+set srcmainfile ${testfile}-main.c
e1d87d
+set srclibfile ${testfile}-lib.c
e1d87d
+set libfile [standard_output_file ${testfile}-lib.so]
e1d87d
+set objfile [standard_output_file ${testfile}-main.o]
e1d87d
+set executable ${testfile}-main
e1d87d
+set binfile [standard_output_file ${executable}]
e1d87d
+set gcorefile [standard_output_file ${executable}.gcore]
e1d87d
+set outdir [file dirname $binfile]
e1d87d
+
e1d87d
+if { [gdb_compile_shlib ${srcdir}/${subdir}/${srclibfile} ${libfile} "debug additional_flags=-Wl,--build-id"] != ""
e1d87d
+     || [gdb_compile ${srcdir}/${subdir}/${srcmainfile} ${objfile} object {debug}] != "" } {
e1d87d
+     unsupported "-Wl,--build-id compilation failed"
e1d87d
+     return -1
e1d87d
+}
e1d87d
+set opts [list debug shlib=${libfile} "additional_flags=-Wl,--build-id"]
e1d87d
+if { [gdb_compile ${objfile} ${binfile} executable $opts] != "" } {
e1d87d
+     unsupported "-Wl,--build-id compilation failed"
e1d87d
+     return -1
e1d87d
+}
e1d87d
+
e1d87d
+clean_restart $executable
e1d87d
+gdb_load_shlib $libfile
e1d87d
+
e1d87d
+# Does this gdb support gcore?
e1d87d
+set test "help gcore"
e1d87d
+gdb_test_multiple $test $test {
e1d87d
+    -re "Undefined command: .gcore.*\r\n$gdb_prompt $" {
e1d87d
+	# gcore command not supported -- nothing to test here.
e1d87d
+	unsupported "gdb does not support gcore on this target"
e1d87d
+	return -1;
e1d87d
+    }
e1d87d
+    -re "Save a core file .*\r\n$gdb_prompt $" {
e1d87d
+	pass $test
e1d87d
+    }
e1d87d
+}
e1d87d
+
e1d87d
+if { ![runto lib] } then {
e1d87d
+    return -1
e1d87d
+}
e1d87d
+
e1d87d
+set escapedfilename [string_to_regexp ${gcorefile}]
e1d87d
+
e1d87d
+set test "save a corefile"
e1d87d
+gdb_test_multiple "gcore ${gcorefile}" $test {
e1d87d
+    -re "Saved corefile ${escapedfilename}\r\n$gdb_prompt $" {
e1d87d
+	pass $test
e1d87d
+    }
e1d87d
+    -re "Can't create a corefile\r\n$gdb_prompt $" {
e1d87d
+	unsupported $test
e1d87d
+	return -1
e1d87d
+    }
e1d87d
+}
e1d87d
+
e1d87d
+# Now restart gdb and load the corefile.
e1d87d
+
e1d87d
+clean_restart $executable
e1d87d
+gdb_load_shlib $libfile
e1d87d
+
e1d87d
+set buildid [build_id_debug_filename_get $libfile]
e1d87d
+
e1d87d
+regsub {\.debug$} $buildid {} buildid
e1d87d
+
e1d87d
+set debugdir [standard_output_file ${testfile}-debugdir]
e1d87d
+file delete -force -- $debugdir
e1d87d
+
e1d87d
+file mkdir $debugdir/[file dirname $libfile]
e1d87d
+file copy $libfile $debugdir/${libfile}
e1d87d
+
e1d87d
+file mkdir $debugdir/[file dirname $buildid]
e1d87d
+file copy $libfile $debugdir/${buildid}
e1d87d
+
e1d87d
+remote_exec build "ln -s /lib       ${debugdir}/"
e1d87d
+remote_exec build "ln -s /lib64     ${debugdir}/"
e1d87d
+# /usr is not needed, all the libs are in /lib64: libm.so.6 libc.so.6 ld-linux-x86-64.so.2
e1d87d
+
e1d87d
+gdb_test "set solib-absolute-prefix $debugdir"
e1d87d
+
e1d87d
+gdb_test_no_output "set debug-file-directory $debugdir" "set debug-file-directory"
e1d87d
+
e1d87d
+gdb_test "core ${gcorefile}" "Core was generated by .*" "re-load generated corefile"
e1d87d
+
e1d87d
+gdb_test "frame" "#0 \[^\r\n\]* lib .*" "library got loaded"
e1d87d
+
e1d87d
+gdb_test "bt"
e1d87d
+gdb_test "info shared"
e1d87d
--- /dev/null	2016-07-02 20:29:01.679404943 +0200
e1d87d
+++ gdb-7.11.50.20160721/gdb/testsuite/gdb.base/gcore-buildid-exec-but-not-solib-main.c	2016-07-28 21:06:40.977786922 +0200
e1d87d
@@ -0,0 +1,25 @@
e1d87d
+/* Copyright 2010 Free Software Foundation, Inc.
e1d87d
+
e1d87d
+   This file is part of GDB.
e1d87d
+
e1d87d
+   This program is free software; you can redistribute it and/or modify
e1d87d
+   it under the terms of the GNU General Public License as published by
e1d87d
+   the Free Software Foundation; either version 3 of the License, or
e1d87d
+   (at your option) any later version.
e1d87d
+
e1d87d
+   This program is distributed in the hope that it will be useful,
e1d87d
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
e1d87d
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
e1d87d
+   GNU General Public License for more details.
e1d87d
+
e1d87d
+   You should have received a copy of the GNU General Public License
e1d87d
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
e1d87d
+
e1d87d
+extern void lib (void);
e1d87d
+
e1d87d
+int
e1d87d
+main (void)
e1d87d
+{
e1d87d
+  lib ();
e1d87d
+  return 0;
e1d87d
+}
e1d87d
--- /dev/null	2016-07-02 20:29:01.679404943 +0200
e1d87d
+++ gdb-7.11.50.20160721/gdb/testsuite/gdb.base/gcore-buildid-exec-but-not-solib-lib.c	2016-07-28 21:06:40.977786922 +0200
e1d87d
@@ -0,0 +1,21 @@
e1d87d
+/* Copyright 2010 Free Software Foundation, Inc.
e1d87d
+
e1d87d
+   This file is part of GDB.
e1d87d
+
e1d87d
+   This program is free software; you can redistribute it and/or modify
e1d87d
+   it under the terms of the GNU General Public License as published by
e1d87d
+   the Free Software Foundation; either version 3 of the License, or
e1d87d
+   (at your option) any later version.
e1d87d
+
e1d87d
+   This program is distributed in the hope that it will be useful,
e1d87d
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
e1d87d
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
e1d87d
+   GNU General Public License for more details.
e1d87d
+
e1d87d
+   You should have received a copy of the GNU General Public License
e1d87d
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
e1d87d
+
e1d87d
+void
e1d87d
+lib (void)
e1d87d
+{
e1d87d
+}