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

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