Blame SOURCES/gdb-6.6-buildid-locate-misleading-warning-missing-debuginfo-rhbz981154.patch

4c2ad1
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
4c2ad1
From: Fedora GDB patches <invalid@email.com>
4c2ad1
Date: Fri, 27 Oct 2017 21:07:50 +0200
4c2ad1
Subject: 
4c2ad1
 gdb-6.6-buildid-locate-misleading-warning-missing-debuginfo-rhbz981154.patch
4c2ad1
4c2ad1
;; Fix 'gdb gives highly misleading error when debuginfo pkg is present,
4c2ad1
;; but not corresponding binary pkg' (RH BZ 981154).
4c2ad1
;;=push+jan
4c2ad1
4c2ad1
Comments by Sergio Durigan Junior <sergiodj@redhat.com>:
4c2ad1
4c2ad1
  This is the fix for RH BZ #981154
4c2ad1
4c2ad1
  It is mainly a testcase addition, but a minor fix in the gdb/build-id.c
4c2ad1
  file was also needed.
4c2ad1
4c2ad1
  gdb/build-id.c was added by:
4c2ad1
4c2ad1
  commit dc294be54c96414035eed7d53dafdea0a6f31a72
4c2ad1
  Author: Tom Tromey <tromey@redhat.com>
4c2ad1
  Date:   Tue Oct 8 19:56:15 2013 +0000
4c2ad1
4c2ad1
  and had a little thinko there.  The variable 'filename' needs to be set to
4c2ad1
  NULL after it is free'd, otherwise the code below thinks that it is still
4c2ad1
  valid and doesn't print the necessary warning ("Try: yum install ...").
4c2ad1
4c2ad1
diff --git a/gdb/build-id.c b/gdb/build-id.c
4c2ad1
--- a/gdb/build-id.c
4c2ad1
+++ b/gdb/build-id.c
4c2ad1
@@ -581,7 +581,10 @@ build_id_to_debug_bfd (size_t build_id_len, const bfd_byte *build_id,
4c2ad1
 	  do_cleanups (inner);
4c2ad1
 
4c2ad1
 	  if (abfd == NULL)
4c2ad1
-	    continue;
4c2ad1
+	    {
4c2ad1
+	      filename = NULL;
4c2ad1
+	      continue;
4c2ad1
+	    }
4c2ad1
 
4c2ad1
 	  if (build_id_verify (abfd.get(), build_id_len, build_id))
4c2ad1
 	    break;
4c2ad1
diff --git a/gdb/testsuite/gdb.base/rhbz981154-misleading-yum-install-warning.exp b/gdb/testsuite/gdb.base/rhbz981154-misleading-yum-install-warning.exp
4c2ad1
new file mode 100644
4c2ad1
--- /dev/null
4c2ad1
+++ b/gdb/testsuite/gdb.base/rhbz981154-misleading-yum-install-warning.exp
4c2ad1
@@ -0,0 +1,97 @@
4c2ad1
+#   Copyright (C) 2014  Free Software Foundation, Inc.
4c2ad1
+
4c2ad1
+# This program is free software; you can redistribute it and/or modify
4c2ad1
+# it under the terms of the GNU General Public License as published by
4c2ad1
+# the Free Software Foundation; either version 3 of the License, or
4c2ad1
+# (at your option) any later version.
4c2ad1
+#
4c2ad1
+# This program is distributed in the hope that it will be useful,
4c2ad1
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
4c2ad1
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
4c2ad1
+# GNU General Public License for more details.
4c2ad1
+#
4c2ad1
+# You should have received a copy of the GNU General Public License
4c2ad1
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
4c2ad1
+
4c2ad1
+standard_testfile "normal.c"
4c2ad1
+
4c2ad1
+if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile}] } {
4c2ad1
+    return -1
4c2ad1
+}
4c2ad1
+
4c2ad1
+# Get the build-id of the file
4c2ad1
+set build_id_debug_file [build_id_debug_filename_get $binfile]
4c2ad1
+regsub -all ".debug$" $build_id_debug_file "" build_id_without_debug
4c2ad1
+
4c2ad1
+# Run to main
4c2ad1
+if { ![runto_main] } {
4c2ad1
+    return -1
4c2ad1
+}
4c2ad1
+
4c2ad1
+# We first need to generate a corefile
4c2ad1
+set escapedfilename [string_to_regexp [standard_output_file gcore.test]]
4c2ad1
+set core_supported 0
4c2ad1
+gdb_test_multiple "gcore [standard_output_file gcore.test]" \
4c2ad1
+	"save a corefile" \
4c2ad1
+{
4c2ad1
+  -re "Saved corefile ${escapedfilename}\[\r\n\]+$gdb_prompt $" {
4c2ad1
+    pass "save a corefile"
4c2ad1
+    global core_supported
4c2ad1
+    set core_supported 1
4c2ad1
+  }
4c2ad1
+  -re "Can't create a corefile\[\r\n\]+$gdb_prompt $" {
4c2ad1
+    unsupported "save a corefile"
4c2ad1
+    global core_supported
4c2ad1
+    set core_supported 0
4c2ad1
+  }
4c2ad1
+}
4c2ad1
+
4c2ad1
+if {!$core_supported} {
4c2ad1
+  return -1
4c2ad1
+}
4c2ad1
+
4c2ad1
+# Move the binfile to a temporary name
4c2ad1
+remote_exec build "mv $binfile ${binfile}.old"
4c2ad1
+
4c2ad1
+# Reinitialize GDB and see if we get a yum/dnf warning
4c2ad1
+gdb_exit
4c2ad1
+gdb_start
4c2ad1
+gdb_reinitialize_dir $srcdir/$subdir
4c2ad1
+
4c2ad1
+with_test_prefix "first run:" {
4c2ad1
+    gdb_test "set build-id-verbose 1" "" \
4c2ad1
+	"set build-id-verbose"
4c2ad1
+
4c2ad1
+    gdb_test "set debug-file-directory [file dirname [standard_output_file gcore.test]]" "" \
4c2ad1
+	"set debug-file-directory"
4c2ad1
+
4c2ad1
+    gdb_test "core-file [standard_output_file gcore.test]" \
4c2ad1
+	"Missing separate debuginfo for the main executable file\r\nTry: (yum|dnf) --enablerepo='\\*debug\\*' install [standard_output_file $build_id_without_debug]\r\n.*" \
4c2ad1
+	"test first yum/dnf warning"
4c2ad1
+}
4c2ad1
+
4c2ad1
+# Now we define and create our .build-id
4c2ad1
+file mkdir [file dirname [standard_output_file ${build_id_without_debug}]]
4c2ad1
+# Cannot use "file link" (from TCL) because it requires the target file to
4c2ad1
+# exist.
4c2ad1
+remote_exec build "ln -s $binfile [standard_output_file ${build_id_without_debug}]"
4c2ad1
+
4c2ad1
+# Reinitialize GDB to get the second yum/dnf warning
4c2ad1
+gdb_exit
4c2ad1
+gdb_start
4c2ad1
+gdb_reinitialize_dir $srcdir/$subdir
4c2ad1
+
4c2ad1
+with_test_prefix "second run:" {
4c2ad1
+    gdb_test "set build-id-verbose 1" "" \
4c2ad1
+	"set build-id-verbose"
4c2ad1
+
4c2ad1
+    gdb_test "set debug-file-directory [file dirname [standard_output_file gcore.test]]" "" \
4c2ad1
+	"set debug-file-directory"
4c2ad1
+
4c2ad1
+    gdb_test "core-file [standard_output_file gcore.test]" \
4c2ad1
+	"Missing separate debuginfo for the main executable file\r\nTry: (yum|dnf) --enablerepo='\\*debug\\*' install $binfile\r\n.*" \
4c2ad1
+	"test second yum/dnf warning"
4c2ad1
+}
4c2ad1
+
4c2ad1
+# Leaving the link there will cause breakage in the next run.
4c2ad1
+remote_exec build "rm -f [standard_output_file ${build_id_without_debug}]"