From: Alex Dowad <alexinbeijing@gmail.com>
To: musl@lists.openwall.com
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 [thread overview]
Message-ID: <1430134355-10228-1-git-send-email-alexinbeijing@gmail.com> (raw)
__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 <alexinbeijing@gmail.com>
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
next reply other threads:[~2015-04-27 11:32 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-27 11:32 Alex Dowad [this message]
2015-04-27 20:57 ` Rich Felker
2015-04-29 7:46 ` Timo Teras
2015-04-29 13:23 ` Rich Felker
2015-04-29 14:46 Alex Dowad
2015-04-29 16:51 Alex Dowad
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1430134355-10228-1-git-send-email-alexinbeijing@gmail.com \
--to=alexinbeijing@gmail.com \
--cc=musl@lists.openwall.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).