public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Masami Hiramatsu <mhiramat@redhat.com>
To: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>, Steven Rostedt <rostedt@goodmis.org>,
	Ananth N Mavinakayanahalli <ananth@in.ibm.com>,
	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: Thu, 19 Mar 2009 23:40:17 -0400	[thread overview]
Message-ID: <49C31021.5020305@redhat.com> (raw)
In-Reply-To: <20090320005135.GC6895@nowhere>

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.

Thank you,

-- 
Masami Hiramatsu

Software Engineer
Hitachi Computer Products (America) Inc.
Software Solutions Division

e-mail: mhiramat@redhat.com


  reply	other threads:[~2009-03-20  3:40 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-19 21:10 [RFC][PATCH -tip 7/9] tracing: kprobe-tracer plugin supports arguments Masami Hiramatsu
2009-03-20  0:51 ` Frederic Weisbecker
2009-03-20  3:40   ` Masami Hiramatsu [this message]
2009-03-20  4:41     ` Ananth N Mavinakayanahalli
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=49C31021.5020305@redhat.com \
    --to=mhiramat@redhat.com \
    --cc=ananth@in.ibm.com \
    --cc=fweisbec@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --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