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

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