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

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