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