Blame SOURCES/gdb-test-bt-cfi-without-die.patch

6240d7
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
6240d7
From: Fedora GDB patches <invalid@email.com>
6240d7
Date: Fri, 27 Oct 2017 21:07:50 +0200
6240d7
Subject: gdb-test-bt-cfi-without-die.patch
6240d7
6240d7
;; [delayed-symfile] Test a backtrace regression on CFIs without DIE (BZ 614604).
6240d7
;;=fedoratest
6240d7
6240d7
http://sourceware.org/ml/archer/2010-q3/msg00028.html
6240d7
6240d7
On Wed, 25 Feb 2009 00:14:29 +0100, Jan Kratochvil wrote:
6240d7
> commit 6a37c2b9962258ecf9299cc34a650e64a06acaa5
6240d7
>
6240d7
> There was a regression on gdb.base/savedregs.exp.
6240d7
>
6240d7
> quick_addrmap/require_partial_symbols should be used even for the unwind debug
6240d7
> info checking as its load has been also delayed by this branch.
6240d7
[...]
6240d7
> --- a/gdb/dwarf2-frame.c
6240d7
> +++ b/gdb/dwarf2-frame.c
6240d7
[...]
6240d7
> @@ -1499,6 +1500,14 @@ dwarf2_frame_find_fde (CORE_ADDR *pc)
6240d7
>        struct dwarf2_fde *fde;
6240d7
>        CORE_ADDR offset;
6240d7
>
6240d7
> +      if (objfile->quick_addrmap)
6240d7
> +	{
6240d7
> +	  if (!addrmap_find (objfile->quick_addrmap, *pc))
6240d7
> +	    continue;
6240d7
> +	}
6240d7
> +      /* FIXME: Read-in only .debug_frame/.eh_frame without .debug_info?  */
6240d7
> +      require_partial_symbols (objfile);
6240d7
> +
6240d7
6240d7
but this has caused a different regression (as discussed in the confcall).
6240d7
6240d7
QUICK_ADDRMAP is built only from .debug_aranges.  But we can have existing
6240d7
built .debug_aranges for CUs in OBJFILE but still some CUs do not need to have
6240d7
DWARF at all while they can feature CFIs (.eh_frame or .debug_frame).
6240d7
It has been described by Daniel Jacobowitz at:
6240d7
	Re: [2/4] RFC: check psymtabs_addrmap before reading FDEs
6240d7
	http://sourceware.org/ml/gdb-patches/2010-07/msg00012.html
6240d7
6240d7
Sorry for this regression by me (in that fix of a different regression).
6240d7
6240d7
Fixed it the "slow way" as this branch is now obsoleted by .gdb-index.
6240d7
6240d7
No regressions on {x86_64,x86_64-m32,i686}-fedora13-linux-gnu.
6240d7
6240d7
Checked-in.
6240d7
6240d7
Thanks,
6240d7
Jan
6240d7
6240d7
eb8df8566acc1ed963e3e9b77c13b9c2c3db03fb
6240d7
6240d7
Test CFI is parsed even for range (function) not described by any DIE.
6240d7
6240d7
https://bugzilla.redhat.com/show_bug.cgi?id=614028
6240d7
6240d7
gdb/
6240d7
	* dwarf2-frame.c (dwarf2_frame_find_fde): Remove the
6240d7
	OBJFILE->QUICK_ADDRMAP check.  New comment why.
6240d7
6240d7
gdb/testsuite/
6240d7
	* gdb.base/cfi-without-die.exp, gdb.base/cfi-without-die-main.c,
6240d7
	gdb.base/cfi-without-die-caller.c: New files.
6240d7
6240d7
diff --git a/gdb/testsuite/gdb.base/cfi-without-die-caller.c b/gdb/testsuite/gdb.base/cfi-without-die-caller.c
6240d7
new file mode 100644
6240d7
--- /dev/null
6240d7
+++ b/gdb/testsuite/gdb.base/cfi-without-die-caller.c
6240d7
@@ -0,0 +1,28 @@
6240d7
+/* This testcase is part of GDB, the GNU debugger.
6240d7
+
6240d7
+   Copyright 2005, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
6240d7
+
6240d7
+   This program is free software; you can redistribute it and/or modify
6240d7
+   it under the terms of the GNU General Public License as published by
6240d7
+   the Free Software Foundation; either version 3 of the License, or
6240d7
+   (at your option) any later version.
6240d7
+
6240d7
+   This program is distributed in the hope that it will be useful,
6240d7
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
6240d7
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
6240d7
+   GNU General Public License for more details.
6240d7
+
6240d7
+   You should have received a copy of the GNU General Public License
6240d7
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
6240d7
+
6240d7
+typedef int (*callback_t) (void);
6240d7
+
6240d7
+int
6240d7
+caller (callback_t callback)
6240d7
+{
6240d7
+  /* Ensure some frame content to push away the return address.  */
6240d7
+  volatile const long one = 1;
6240d7
+
6240d7
+  /* Modify the return value to prevent any tail-call optimization.  */
6240d7
+  return (*callback) () - one;
6240d7
+}
6240d7
diff --git a/gdb/testsuite/gdb.base/cfi-without-die-main.c b/gdb/testsuite/gdb.base/cfi-without-die-main.c
6240d7
new file mode 100644
6240d7
--- /dev/null
6240d7
+++ b/gdb/testsuite/gdb.base/cfi-without-die-main.c
6240d7
@@ -0,0 +1,32 @@
6240d7
+/* This testcase is part of GDB, the GNU debugger.
6240d7
+
6240d7
+   Copyright 2005, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
6240d7
+
6240d7
+   This program is free software; you can redistribute it and/or modify
6240d7
+   it under the terms of the GNU General Public License as published by
6240d7
+   the Free Software Foundation; either version 3 of the License, or
6240d7
+   (at your option) any later version.
6240d7
+
6240d7
+   This program is distributed in the hope that it will be useful,
6240d7
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
6240d7
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
6240d7
+   GNU General Public License for more details.
6240d7
+
6240d7
+   You should have received a copy of the GNU General Public License
6240d7
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
6240d7
+
6240d7
+typedef int (*callback_t) (void);
6240d7
+
6240d7
+extern int caller (callback_t callback);
6240d7
+
6240d7
+int
6240d7
+callback (void)
6240d7
+{
6240d7
+  return 1;
6240d7
+}
6240d7
+
6240d7
+int
6240d7
+main (void)
6240d7
+{
6240d7
+  return caller (callback);
6240d7
+}
6240d7
diff --git a/gdb/testsuite/gdb.base/cfi-without-die.exp b/gdb/testsuite/gdb.base/cfi-without-die.exp
6240d7
new file mode 100644
6240d7
--- /dev/null
6240d7
+++ b/gdb/testsuite/gdb.base/cfi-without-die.exp
6240d7
@@ -0,0 +1,71 @@
6240d7
+# Copyright 2010 Free Software Foundation, Inc.
6240d7
+
6240d7
+# This program is free software; you can redistribute it and/or modify
6240d7
+# it under the terms of the GNU General Public License as published by
6240d7
+# the Free Software Foundation; either version 3 of the License, or
6240d7
+# (at your option) any later version.
6240d7
+#
6240d7
+# This program is distributed in the hope that it will be useful,
6240d7
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
6240d7
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
6240d7
+# GNU General Public License for more details.
6240d7
+#
6240d7
+# You should have received a copy of the GNU General Public License
6240d7
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
6240d7
+
6240d7
+# Test CFI is parsed even for range (function) not described by any DIE.
6240d7
+
6240d7
+set testfile cfi-without-die
6240d7
+set srcmainfile ${testfile}-main.c
6240d7
+set srccallerfile ${testfile}-caller.c
6240d7
+set executable ${testfile}
6240d7
+set objmainfile [standard_output_file ${testfile}-main.o]
6240d7
+set objcallerfile [standard_output_file ${testfile}-caller.o]
6240d7
+set binfile [standard_output_file ${executable}]
6240d7
+
6240d7
+if { [gdb_compile "${srcdir}/${subdir}/${srccallerfile}" ${objcallerfile} \
6240d7
+      object [list {additional_flags=-fomit-frame-pointer -fno-unwind-tables -fno-asynchronous-unwind-tables}]] != ""
6240d7
+     || [gdb_compile "${srcdir}/${subdir}/${srcmainfile}" ${objmainfile} object {debug}] != ""
6240d7
+     || [gdb_compile "${objmainfile} ${objcallerfile}" ${binfile} executable {}] != "" } {
6240d7
+     untested ${testfile}.exp
6240d7
+     return -1
6240d7
+}
6240d7
+
6240d7
+clean_restart $executable
6240d7
+
6240d7
+if ![runto callback] then {
6240d7
+   fail "verify unwinding: Can't run to callback"
6240d7
+   return 0
6240d7
+}
6240d7
+set test "verify unwinding breaks without CFI"
6240d7
+gdb_test_multiple "bt" $test {
6240d7
+    -re " in \[?\]\[?\] .*\r\n$gdb_prompt $" {
6240d7
+	# It may backtrace through some random frames even to main().
6240d7
+	pass $test
6240d7
+    }
6240d7
+    -re " in main .*\r\n$gdb_prompt $" {
6240d7
+	fail $test
6240d7
+    }
6240d7
+    -re "\r\n$gdb_prompt $" {
6240d7
+	pass $test
6240d7
+    }
6240d7
+}
6240d7
+
6240d7
+if { [gdb_compile "${srcdir}/${subdir}/${srccallerfile}" ${objcallerfile} \
6240d7
+      object [list {additional_flags=-fomit-frame-pointer -funwind-tables -fasynchronous-unwind-tables}]] != ""
6240d7
+     || [gdb_compile "${srcdir}/${subdir}/${srcmainfile}" ${objmainfile} object {debug}] != ""
6240d7
+     || [gdb_compile "${objmainfile} ${objcallerfile}" ${binfile} executable {}] != "" } {
6240d7
+     untested ${testfile}.exp
6240d7
+     return -1
6240d7
+}
6240d7
+
6240d7
+clean_restart $executable
6240d7
+
6240d7
+if ![runto callback] then {
6240d7
+   fail "test CFI without DIEs: Can't run to callback"
6240d7
+   return 0
6240d7
+}
6240d7
+# #0  callback () at ...
6240d7
+# #1  0x00000000004004e9 in caller ()
6240d7
+# #2  0x00000000004004cd in main () at ...
6240d7
+gdb_test "bt" "#0 +callback \[^\r\n\]+\r\n#1 \[^\r\n\]+ in caller \[^\r\n\]+\r\n#2 \[^\r\n\]+ in main \[^\r\n\]+" "verify unwindin works for CFI without DIEs"