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

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