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