This is the mail archive of the
systemtap@sourceware.org
mailing list for the systemtap project.
User Stack Trace
- From: grundym at us dot ibm dot com (grundy)
- To: systemtap at sources dot redhat dot com
- Date: Mon, 16 Apr 2007 16:51:52 -0400
- Subject: User Stack Trace
Hi Folks -
Yeah, I'm on this mission again. I took the concept from the jprobe code
I previously posted (in which I just boosted a bunch of oprofile code
and made it work in the module). This is x86 specific (if you want to
test on x86_64 change the nregs->ebp to nregs->rdp), but I figure it's a
starting point.
I imagine it would be nice to have a version that returns strings, and a
version that prints (like the kernel stack ones). But, before I go
fiddling with that, I'm trying to get the vma name and offset for each
address on the stack. That way you wouldn't have to capture
/proc/[pid]/maps for every process (for symbol resolution afterwards).
In this form, a good test is to fire it up in a text console, then log
in from gdm. Just as easy to switch syscall.ipc to syscall.exit for
testing.
Thanks
Mike
--
#!/usr/bin/env stap
/* Prints the user stack backtrace
* Concept and frame_head structure from Oprofile which is
* (c) 2002 OProfile authors, John Levon, David Smith
*/
function ustack_print:long ()
%{
struct frame_head {
struct frame_head * ebp;
unsigned long ret;
} __attribute__((packed)) stack_frame[2], *head;
struct pt_regs *nregs = task_pt_regs(current);
_stp_printf("[user] <%p>\n", nregs->eip);
head = (struct frame_head *)nregs->ebp;
if (user_mode_vm(nregs)) {
do {
_stp_printf ("[user] <%p>\n", head->ret);
_stp_copy_from_user ((char *)stack_frame,
(const char __user *) head->ebp,
sizeof(stack_frame));
head = stack_frame;
} while (head->ebp);
_stp_printf ("[user] <%p>\n", head->ret);
}
THIS->__retvalue = 0;
%}
probe syscall.ipc {
printf("%s:%d sys_ipc user backtrace: \n", execname(), pid());
ustack_print();
}