From: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
To: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>,
Ingo Molnar <mingo@elte.hu>, Steven Rostedt <rostedt@goodmis.org>,
systemtap-ml <systemtap@sources.redhat.com>,
LKML <linux-kernel@vger.kernel.org>
Subject: Re: [RFC][PATCH -tip 7/9] tracing: kprobe-tracer plugin supports arguments
Date: Fri, 20 Mar 2009 10:11:25 +0530 [thread overview]
Message-ID: <20090320044125.GB6398@in.ibm.com> (raw)
In-Reply-To: <49C31021.5020305@redhat.com>
On Thu, Mar 19, 2009 at 11:40:17PM -0400, Masami Hiramatsu wrote:
> Frederic Weisbecker wrote:
> >> diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
> >> index 33bb355..e801e8c 100644
> >> --- a/kernel/trace/trace_kprobe.c
> >> +++ b/kernel/trace/trace_kprobe.c
> >> @@ -27,15 +27,124 @@
> >> #include <linux/types.h>
> >> #include <linux/string.h>
> >> #include <linux/ctype.h>
> >> +#include <linux/ptrace.h>
> >>
> >> #include <linux/ftrace.h>
> >> #include "trace.h"
> >>
> >> +/* TODO: Move these functions to arch/XXX/include/asm/ptrace.h */
> >> +#define STACK_MASK (THREAD_SIZE - 1)
> >> +#define valid_stack_addr(regs, addr) \
> >> + (((addr) & ~STACK_MASK) == (kernel_trap_sp(regs) & ~STACK_MASK))
> >> +
> >> +#if defined(__i386__)
> >> +#define MAX_REG_NUM 15
> >> +#elif defined(__x86_64__)
> >> +#define MAX_REG_NUM 21
> >> +#else
> >> +#define MAX_REG_NUM (sizeof(struct pt_regs)/sizeof(unsigned long))
> >> +#endif
> >> +
> >> +static unsigned long fetch_register(struct pt_regs *regs, void *num)
> >> +{
> >> + if (unlikely((unsigned)num > MAX_REG_NUM))
> >> + return 0;
> >> + return *((unsigned long *)regs + (unsigned)num);
> >> +}
> >> +
> >> +static unsigned long fetch_stack(struct pt_regs *regs, void *num)
> >> +{
> >> + unsigned long *addr = (unsigned long *)kernel_trap_sp(regs);
> >> + addr += (unsigned)num;
> >> + if (valid_stack_addr(regs, (unsigned long)addr))
> >> + return *addr;
> >> + else
> >> + return 0;
> >> +}
> >> +
> >> +static unsigned long fetch_memory(struct pt_regs *regs, void *addr)
> >> +{
> >> + unsigned long retval;
> >> + probe_kernel_address(addr, retval);
> >> + return retval;
> >> +}
> >
> >
> > It will return a random value.
>
> ah, thanks. I'll check the retval of probe_kernel_address().
>
> >> +
> >> +#if defined(__i386__)
> >> +#define REGPARMS 3
> >> +static unsigned long fetch_argument(struct pt_regs *regs, void *data)
> >> +{
> >> + unsigned long n = (unsigned long)data;
> >> + if (n > REGPARMS) {
> >> + /*
> >> + * The typical case: arg n is on the stack.
> >> + * stack[0] = return address
> >> + */
> >> + return fetch_stack(regs, (void *)(n - REGPARMS));
> >> + } else {
> >> + switch (n) {
> >> + case 1: return regs->ax;
> >> + case 2: return regs->dx;
> >> + case 3: return regs->cx;
> >> + }
> >> + return 0;
> >> + }
> >> +}
> >> +#elif define(__x86_64__)
> >> +#define REGPARMS 6
> >
> >
> > These helpers could be defined in the appropriate arch directory.
> > They may even be reused by further debugging engines.
>
> Agreed. Since we don't have any those infrastructure (arch/*/lib/debug.c ?)
> yet, I just put it in trace_kprobe.c.
A better option could be to generalize syscall_get_arguments() to work
for functions other than just syscalls where pt_regs are available.
Ananth
next prev parent reply other threads:[~2009-03-20 4:41 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-03-19 21:10 Masami Hiramatsu
2009-03-20 0:51 ` Frederic Weisbecker
2009-03-20 3:40 ` Masami Hiramatsu
2009-03-20 4:41 ` Ananth N Mavinakayanahalli [this message]
2009-03-20 19:30 ` Roland McGrath
2009-03-20 8:19 ` Ananth N Mavinakayanahalli
2009-03-20 11:29 ` Masami Hiramatsu
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=20090320044125.GB6398@in.ibm.com \
--to=ananth@in.ibm.com \
--cc=fweisbec@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mhiramat@redhat.com \
--cc=mingo@elte.hu \
--cc=rostedt@goodmis.org \
--cc=systemtap@sources.redhat.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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®