From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/7526 Path: news.gmane.org!not-for-mail From: Alex Dowad Newsgroups: gmane.linux.lib.musl.general Subject: [PATCH] generate debug_frame info for __syscall_cp_asm (i386) so gdb can get backtrace Date: Mon, 27 Apr 2015 13:32:35 +0200 Message-ID: <1430134355-10228-1-git-send-email-alexinbeijing@gmail.com> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org X-Trace: ger.gmane.org 1430163348 2484 80.91.229.3 (27 Apr 2015 19:35:48 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 27 Apr 2015 19:35:48 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-7539-gllmg-musl=m.gmane.org@lists.openwall.com Mon Apr 27 21:35:48 2015 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1Ymooj-0006lc-Mm for gllmg-musl@m.gmane.org; Mon, 27 Apr 2015 21:35:45 +0200 Original-Received: (qmail 10005 invoked by uid 550); 27 Apr 2015 19:35:31 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 15687 invoked from network); 27 Apr 2015 11:32:55 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:date:message-id; bh=8JKaQWTsFrYmJ/Ss9CP4+JxvPTCXZGMI4RkcmnHtPpA=; b=p87W9MEVxCBLYOxb2WH5ZkjC9nguFW1G+oBN9VKyGxMJl5b8pCfVydMdz+W26REli2 /2LHSKBqjBIOiew7l4MrODLTumxP7uWDba0Cm/nQdNG4uWbF1tT5jDxhHq8+WDXcK7q5 uobwmcwimDvrCypWysvpdodWXILfJCoQ7DxLm1X1uR32OL4u4rcTo2jq6avdWbEQC0ro QEWJGwrhMS+5HtdQ1iCm6jJcp7Y/FUxA/31XewkEGKGaZJCgcSDqsLae0M6k1BfbeFxC OrTLFktSxR1Kpxl/RAuEBTaoee7AuPphozb6XZBfW+49XKjQvDzxXmubk8Mh4eEMuz5I su0g== X-Received: by 10.180.186.99 with SMTP id fj3mr20163633wic.10.1430134364522; Mon, 27 Apr 2015 04:32:44 -0700 (PDT) X-Mailer: git-send-email 2.0.0.GIT Xref: news.gmane.org gmane.linux.lib.musl.general:7526 Archived-At: __syscall_cp_asm needs to use EBP to pass the 6th argument to syscalls with 6 arguments, so it can't use it for a frame pointer. Without frame pointers, GDB can only show backtraces if it gets CFI information from a .debug_frame or .eh_frame section. GCC automatically generates .debug_frame info for all the functions implemented in C, so GDB can get backtraces for them. But the assembler can't generate .debug_frame info for functions implemented in asm, unless you tell it how to find the call frame. With no backtraces, GDB's "catch syscall" is almost useless for syscalls which are implemented using syscall_cp, like close and writev. Adding the CFI info makes it possible to catch these syscalls and find out exactly where a program is using them from. --- src/thread/i386/syscall_cp.s | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) Dear musl devs, Please have a look at this patch, and CC me on any discussion. (I've never worked on musl before and haven't joined the mailing list.) Your feedback will be appreciated. (Just to let you know, I have build-tested this code and tried it in gdb.) If you would like to add similar stack frame debug information to other asm functions, I would be happy to send more patches. The CFI directives can be made more concise using asm macros if desired. By the way, I absolutely and utterly LOVE your Makefile and configure scripts. They're so... so SANE. I never thought a configure script could make me this happy! Thank you! Regards, Alex Dowad diff --git a/src/thread/i386/syscall_cp.s b/src/thread/i386/syscall_cp.s index 7dce1eb..baba145 100644 --- a/src/thread/i386/syscall_cp.s +++ b/src/thread/i386/syscall_cp.s @@ -9,12 +9,23 @@ .global __syscall_cp_asm .hidden __syscall_cp_asm .type __syscall_cp_asm,@function +.cfi_sections .debug_frame +.cfi_startproc __syscall_cp_asm: mov 4(%esp),%ecx pushl %ebx +.cfi_adjust_cfa_offset 4 +.cfi_offset ebx,-8 pushl %esi +.cfi_adjust_cfa_offset 4 +.cfi_offset esi,-12 pushl %edi +.cfi_adjust_cfa_offset 4 +.cfi_offset edi,-16 pushl %ebp +.cfi_adjust_cfa_offset 4 +.cfi_offset ebp,-20 __cp_begin: movl (%ecx),%eax testl %eax,%eax @@ -29,10 +40,19 @@ __cp_begin: int $128 __cp_end: popl %ebp +.cfi_adjust_cfa_offset -4 +.cfi_restore ebp popl %edi +.cfi_adjust_cfa_offset -4 +.cfi_restore edi popl %esi +.cfi_adjust_cfa_offset -4 +.cfi_restore esi popl %ebx +.cfi_adjust_cfa_offset -4 +.cfi_restore ebx ret +.cfi_endproc __cp_cancel: popl %ebp popl %edi -- 2.0.0.GIT