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

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