Blame SOURCES/gdb-rhbz1086894-incomplete-bt-coredump-signal-handler.patch

01917d
commit f2205de0080d999c9b67872c9db471c31b53e378
01917d
Author: Hui Zhu <teawater@gmail.com>
01917d
Date:   Tue May 20 13:19:06 2014 +0800
01917d
01917d
    Fix issue #15778: GDB Aarch64 signal frame unwinder issue
01917d
    
01917d
    The root cause of this issue is unwinder of "#3  <signal handler called>"
01917d
    doesn't supply right values of registers.
01917d
    When GDB want to get the previous frame of "#3  <signal handler called>",
01917d
    it will call cache init function of unwinder "aarch64_linux_sigframe_init".
01917d
    The address or the value of the registers is get from this function.
01917d
    So the bug is inside thie function.
01917d
    
01917d
    I check the asm code of "#3  <signal handler called>":
01917d
    (gdb) frame 3
01917d
    (gdb) p $pc
01917d
    $1 = (void (*)()) 0x7f931fa4d0
01917d
    (gdb) disassemble $pc, +10
01917d
    Dump of assembler code from 0x7f931fa4d0 to 0x7f931fa4da:
01917d
    => 0x0000007f931fa4d0:	mov	x8, #0x8b                  	// #139
01917d
       0x0000007f931fa4d4:	svc	#0x0
01917d
       0x0000007f931fa4d8:	nop
01917d
    
01917d
    This is the syscall sys_rt_sigreturn, Linux kernel function "restore_sigframe"
01917d
    will set the frame:
01917d
    	for (i = 0; i < 31; i++)
01917d
    		__get_user_error(regs->regs[i], &sf->uc.uc_mcontext.regs[i],
01917d
    				 err);
01917d
    	__get_user_error(regs->sp, &sf->uc.uc_mcontext.sp, err);
01917d
    	__get_user_error(regs->pc, &sf->uc.uc_mcontext.pc, err);
01917d
    The struct of uc_mcontext is:
01917d
    struct sigcontext {
01917d
    	__u64 fault_address;
01917d
    	/* AArch64 registers */
01917d
    	__u64 regs[31];
01917d
    	__u64 sp;
01917d
    	__u64 pc;
01917d
    	__u64 pstate;
01917d
    	/* 4K reserved for FP/SIMD state and future expansion */
01917d
    	__u8 __reserved[4096] __attribute__((__aligned__(16)));
01917d
    };
01917d
    
01917d
    But in GDB function "aarch64_linux_sigframe_init", the code the get address
01917d
    of registers is:
01917d
      for (i = 0; i < 31; i++)
01917d
        {
01917d
          trad_frame_set_reg_addr (this_cache,
01917d
    			       AARCH64_X0_REGNUM + i,
01917d
    			       sigcontext_addr + AARCH64_SIGCONTEXT_XO_OFFSET
01917d
    			       + i * AARCH64_SIGCONTEXT_REG_SIZE);
01917d
        }
01917d
    
01917d
      trad_frame_set_reg_addr (this_cache, AARCH64_FP_REGNUM, fp);
01917d
      trad_frame_set_reg_addr (this_cache, AARCH64_LR_REGNUM, fp + 8);
01917d
      trad_frame_set_reg_addr (this_cache, AARCH64_PC_REGNUM, fp + 8);
01917d
    
01917d
    The code that get pc and sp is not right, so I change the code according
01917d
    to Linux kernel code:
01917d
      trad_frame_set_reg_addr (this_cache, AARCH64_SP_REGNUM,
01917d
    			   sigcontext_addr + AARCH64_SIGCONTEXT_XO_OFFSET
01917d
    			     + 31 * AARCH64_SIGCONTEXT_REG_SIZE);
01917d
      trad_frame_set_reg_addr (this_cache, AARCH64_PC_REGNUM,
01917d
    			   sigcontext_addr + AARCH64_SIGCONTEXT_XO_OFFSET
01917d
    			     + 32 * AARCH64_SIGCONTEXT_REG_SIZE);
01917d
    
01917d
    The issue was fixed by this change, and I did the regression test.  It
01917d
    also fixed a lot of other XFAIL and FAIL.
01917d
    
01917d
    2014-05-20  Hui Zhu  <hui@codesourcery.com>
01917d
    	    Yao Qi  <yao@codesourcery.com>
01917d
    
01917d
    	PR backtrace/16558
01917d
    	* aarch64-linux-tdep.c (aarch64_linux_sigframe_init): Update comments
01917d
    	and change address of sp and pc.
01917d
01917d
Index: gdb-7.6.1/gdb/aarch64-linux-tdep.c
01917d
===================================================================
01917d
--- gdb-7.6.1.orig/gdb/aarch64-linux-tdep.c
01917d
+++ gdb-7.6.1/gdb/aarch64-linux-tdep.c
01917d
@@ -47,28 +47,30 @@
01917d
 
01917d
 /* Signal frame handling.
01917d
 
01917d
-      +----------+  ^
01917d
-      | saved lr |  |
01917d
-   +->| saved fp |--+
01917d
-   |  |          |
01917d
-   |  |          |
01917d
-   |  +----------+
01917d
-   |  | saved lr |
01917d
-   +--| saved fp |
01917d
-   ^  |          |
01917d
-   |  |          |
01917d
-   |  +----------+
01917d
-   ^  |          |
01917d
-   |  | signal   |
01917d
-   |  |          |
01917d
-   |  | saved lr |-->interrupted_function_pc
01917d
-   +--| saved fp |
01917d
-   |  +----------+
01917d
-   |  | saved lr |--> default_restorer (movz x8, NR_sys_rt_sigreturn; svc 0)
01917d
-   +--| saved fp |<- FP
01917d
-      |          |
01917d
-      |          |<- SP
01917d
-      +----------+
01917d
+      +------------+  ^
01917d
+      | saved lr   |  |
01917d
+   +->| saved fp   |--+
01917d
+   |  |            |
01917d
+   |  |            |
01917d
+   |  +------------+
01917d
+   |  | saved lr   |
01917d
+   +--| saved fp   |
01917d
+   ^  |            |
01917d
+   |  |            |
01917d
+   |  +------------+
01917d
+   ^  |            |
01917d
+   |  | signal     |
01917d
+   |  |            |        SIGTRAMP_FRAME (struct rt_sigframe)
01917d
+   |  | saved regs |
01917d
+   +--| saved sp   |--> interrupted_sp
01917d
+   |  | saved pc   |--> interrupted_pc
01917d
+   |  |            |
01917d
+   |  +------------+
01917d
+   |  | saved lr   |--> default_restorer (movz x8, NR_sys_rt_sigreturn; svc 0)
01917d
+   +--| saved fp   |<- FP
01917d
+      |            |         NORMAL_FRAME
01917d
+      |            |<- SP
01917d
+      +------------+
01917d
 
01917d
   On signal delivery, the kernel will create a signal handler stack
01917d
   frame and setup the return address in LR to point at restorer stub.
01917d
@@ -117,6 +119,8 @@
01917d
   d28015a8        movz    x8, #0xad
01917d
   d4000001        svc     #0x0
01917d
 
01917d
+  This is a system call sys_rt_sigreturn.
01917d
+
01917d
   We detect signal frames by snooping the return code for the restorer
01917d
   instruction sequence.
01917d
 
01917d
@@ -140,7 +144,6 @@ aarch64_linux_sigframe_init (const struc
01917d
 {
01917d
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
01917d
   CORE_ADDR sp = get_frame_register_unsigned (this_frame, AARCH64_SP_REGNUM);
01917d
-  CORE_ADDR fp = get_frame_register_unsigned (this_frame, AARCH64_FP_REGNUM);
01917d
   CORE_ADDR sigcontext_addr =
01917d
     sp
01917d
     + AARCH64_RT_SIGFRAME_UCONTEXT_OFFSET
01917d
@@ -154,12 +157,14 @@ aarch64_linux_sigframe_init (const struc
01917d
 			       sigcontext_addr + AARCH64_SIGCONTEXT_XO_OFFSET
01917d
 			       + i * AARCH64_SIGCONTEXT_REG_SIZE);
01917d
     }
01917d
+  trad_frame_set_reg_addr (this_cache, AARCH64_SP_REGNUM,
01917d
+			   sigcontext_addr + AARCH64_SIGCONTEXT_XO_OFFSET
01917d
+			     + 31 * AARCH64_SIGCONTEXT_REG_SIZE);
01917d
+  trad_frame_set_reg_addr (this_cache, AARCH64_PC_REGNUM,
01917d
+			   sigcontext_addr + AARCH64_SIGCONTEXT_XO_OFFSET
01917d
+			     + 32 * AARCH64_SIGCONTEXT_REG_SIZE);
01917d
 
01917d
-  trad_frame_set_reg_addr (this_cache, AARCH64_FP_REGNUM, fp);
01917d
-  trad_frame_set_reg_addr (this_cache, AARCH64_LR_REGNUM, fp + 8);
01917d
-  trad_frame_set_reg_addr (this_cache, AARCH64_PC_REGNUM, fp + 8);
01917d
-
01917d
-  trad_frame_set_id (this_cache, frame_id_build (fp, func));
01917d
+  trad_frame_set_id (this_cache, frame_id_build (sp, func));
01917d
 }
01917d
 
01917d
 static const struct tramp_frame aarch64_linux_rt_sigframe =
01917d
Index: gdb-7.6.1/gdb/testsuite/gdb.arch/aarch64-rhbz1086894-bt-signal-handler.exp
01917d
===================================================================
01917d
--- /dev/null
01917d
+++ gdb-7.6.1/gdb/testsuite/gdb.arch/aarch64-rhbz1086894-bt-signal-handler.exp
01917d
@@ -0,0 +1,35 @@
01917d
+# Copyright (C) 2014 Free Software Foundation, Inc.
01917d
+#
01917d
+# This program is free software; you can redistribute it and/or modify
01917d
+# it under the terms of the GNU General Public License as published by
01917d
+# the Free Software Foundation; either version 3 of the License, or
01917d
+# (at your option) any later version.
01917d
+#
01917d
+# This program is distributed in the hope that it will be useful,
01917d
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
01917d
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
01917d
+# GNU General Public License for more details.
01917d
+#
01917d
+# You should have received a copy of the GNU General Public License
01917d
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
01917d
+
01917d
+# Internal testing for RHEL-7.1.
01917d
+
01917d
+standard_testfile
01917d
+
01917d
+if { ![istarget "aarch64*"] } {
01917d
+        verbose "Skipping $testfile"
01917d
+        return
01917d
+}
01917d
+
01917d
+if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile}] } {
01917d
+        return -1
01917d
+}
01917d
+
01917d
+if ![runto_main] {
01917d
+        return -1
01917d
+}
01917d
+
01917d
+gdb_test "continue" "Continuing.\r\n\r\nProgram received signal SIGSEGV.*" "run until SIGSEGV"
01917d
+
01917d
+gdb_test "backtrace" "#$decimal\\s+$hex in pause .*from.*" "backtrace on signal handler"
01917d
Index: gdb-7.6.1/gdb/testsuite/gdb.arch/aarch64-rhbz1086894-bt-signal-handler.c
01917d
===================================================================
01917d
--- /dev/null
01917d
+++ gdb-7.6.1/gdb/testsuite/gdb.arch/aarch64-rhbz1086894-bt-signal-handler.c
01917d
@@ -0,0 +1,40 @@
01917d
+/* Copyright 2014 Free Software Foundation, Inc.
01917d
+
01917d
+   This file is part of GDB.
01917d
+
01917d
+   This program is free software; you can redistribute it and/or modify
01917d
+   it under the terms of the GNU General Public License as published by
01917d
+   the Free Software Foundation; either version 3 of the License, or
01917d
+   (at your option) any later version.
01917d
+
01917d
+   This program is distributed in the hope that it will be useful,
01917d
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
01917d
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
01917d
+   GNU General Public License for more details.
01917d
+
01917d
+   You should have received a copy of the GNU General Public License
01917d
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
01917d
+
01917d
+/* Internal test for RHEL-7.1.  */
01917d
+
01917d
+#include <sys/types.h>
01917d
+#include <signal.h>
01917d
+#include <unistd.h>
01917d
+#include <assert.h>
01917d
+
01917d
+static void
01917d
+handle_alrm(int signo)
01917d
+{
01917d
+  kill (getpid (), SIGSEGV);
01917d
+  assert (0);
01917d
+}
01917d
+
01917d
+int
01917d
+main (int argc, char *argv[])
01917d
+{
01917d
+  signal (SIGALRM, handle_alrm);
01917d
+  alarm (1);
01917d
+  pause ();
01917d
+  assert (0);
01917d
+  return 0;
01917d
+}