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

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