Received: from eggs.gnu.org ([2001:4830:134:3::10]:52718) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b6JLY-0005bG-PM for qemu-devel@nongnu.org; Fri, 27 May 2016 11:06:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b6JLW-0001bQ-LU for qemu-devel@nongnu.org; Fri, 27 May 2016 11:06:43 -0400 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:57421) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b6JLW-0001b6-Ch for qemu-devel@nongnu.org; Fri, 27 May 2016 11:06:42 -0400 From: Peter Maydell Date: Fri, 27 May 2016 16:06:38 +0100 Message-Id: <1464361598-30776-1-git-send-email-peter.maydell@linaro.org> Subject: [Qemu-devel] [PATCH] linux-user: provide frame information in x86-64 safe_syscall List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: patches@linaro.org, Riku Voipio , Richard Henderson Use cfi directives in the x86-64 safe_syscall to allow gdb to get backtraces right from within it. (In particular this will be quite a common situation if the user interrupts QEMU while it's in a blocked safe-syscall: at the point of the syscall insn RBP is in use for something else, and so gdb can't find the frame then without assistance.) Signed-off-by: Peter Maydell --- The requirements for frame information annotations seem to be a bit of an undocumented black art, but I think I have these right. At any rate, gdb now gives correct backtraces from all points in the routine as far as I can see. Review appreciated... linux-user/host/x86_64/safe-syscall.inc.S | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/linux-user/host/x86_64/safe-syscall.inc.S b/linux-user/host/x86_64/safe-syscall.inc.S index dde434c..bbb1eca 100644 --- a/linux-user/host/x86_64/safe-syscall.inc.S +++ b/linux-user/host/x86_64/safe-syscall.inc.S @@ -24,6 +24,7 @@ * -1-and-errno-set convention is done by the calling wrapper. */ safe_syscall_base: + .cfi_startproc /* This saves a frame pointer and aligns the stack for the syscall. * (It's unclear if the syscall ABI has the same stack alignment * requirements as the userspace function call ABI, but better safe than @@ -31,6 +32,8 @@ safe_syscall_base: * does not list any ABI differences regarding stack alignment.) */ push %rbp + .cfi_def_cfa_offset 16 + .cfi_offset rbp,-16 /* The syscall calling convention isn't the same as the * C one: @@ -70,12 +73,19 @@ safe_syscall_start: safe_syscall_end: /* code path for having successfully executed the syscall */ pop %rbp + .cfi_remember_state + .cfi_def_cfa_offset 8 + .cfi_restore ebp ret return_ERESTARTSYS: /* code path when we didn't execute the syscall */ + .cfi_restore_state mov $-TARGET_ERESTARTSYS, %rax pop %rbp + .cfi_def_cfa_offset 8 + .cfi_restore ebp ret + .cfi_endproc .size safe_syscall_base, .-safe_syscall_base -- 1.9.1