public inbox for systemtap@sourceware.org
 help / color / mirror / Atom feed
* Newbie: Access stack avriables in a kernel module
@ 2010-08-25 14:40 Wolfram Gettert
  2010-08-25 15:31 ` Josh Stone
  0 siblings, 1 reply; 3+ messages in thread
From: Wolfram Gettert @ 2010-08-25 14:40 UTC (permalink / raw)
  To: systemtap

Hi all,
I am quite new to Systemtap. I have read the tutorial. Now I am trying to
do some examples on my own. I like to access some variables inside a
kernel module.

I understand that with $xxx in the probe I can access a variable xxx in the
kernel module. I have managed that for static int variable of the module.

Now, I want to a access a parameter in a function of the kernel module.
I created the following probe:

probe module("mplex").function("mplex_fop_ioctl").return
{
  printf("Call %s arg=%u, res=%i, return=%i\n", probefunc(),$arg, $res,
$return)
}

The code of the function in the kernel is:

static int mplex_fop_ioctl(struct inode *inode, struct file *filp,
                           unsigned int cmd, unsigned long arg)
{
  int res=0;

  struct mplex_dev *mplex=filp->private_data;

  PRINTK_DEBUG("entering mplex_fop_ioctl(), minor=%i\n",
MINOR(mplex->cdev.dev));

  /* Check that there is no IOCTL() confict */
  if ((_IOC_TYPE(cmd) != MPLEX_IOC_MAGIC) || (_IOC_NR(cmd) >
MPLEX_IOC_MAXNR)) {
    PRINTK_ERR("inappropriate ioctl() for device\n");
    return -ENOTTY;
  }
  PRINTK_INFO("cmd: %i", cmd);
  switch (cmd)
  {
    case MIOQPRIV1:
      PRINTK_INFO("*mp: %p\n", mplex);
      PRINTK_INFO("minor: %u, priv1=%u\n", MINOR(mplex->cdev.dev),
mplex->priv1);
      return mplex->priv1;
      break;

    case MIOTPRIV1:
      mplex->priv1=arg;
      break;

    default:
        return -ENOTTY;
  }

  return res;
}


The ouput I get from stap is:

Call mplex_fop_ioctl arg=10, res=96, return=0
Call mplex_fop_ioctl arg=20, res=96, return=0
Call mplex_fop_ioctl arg=30, res=96, return=0
Call mplex_fop_ioctl arg=40, res=96, return=0
Call mplex_fop_ioctl arg=40, res=96, return=10
Call mplex_fop_ioctl arg=40, res=96, return=20
Call mplex_fop_ioctl arg=40, res=96, return=30
Call mplex_fop_ioctl arg=40, res=96, return=40

The values of arg and return are Ok. But as you see in the code of the
function above, res is initialized with 0. But the probe prints another
value. Why?

Is it bug? Have I missunderstood something?

Thanks for any comment on that.

I am using
SystemTap translator/driver (version 1.0/0.143 Debian version 1.0-2)
on a x86 2.6.32-24-generic #41-Ubuntu SMP.


Wolfram

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Newbie: Access stack avriables in a kernel module
  2010-08-25 14:40 Newbie: Access stack avriables in a kernel module Wolfram Gettert
@ 2010-08-25 15:31 ` Josh Stone
  2010-08-26 13:39   ` Wolfram Gettert (News)
  0 siblings, 1 reply; 3+ messages in thread
From: Josh Stone @ 2010-08-25 15:31 UTC (permalink / raw)
  To: wolfram.gettert; +Cc: systemtap

Hi-

On 08/25/2010 07:40 AM, Wolfram Gettert wrote:
> probe module("mplex").function("mplex_fop_ioctl").return
> {
>   printf("Call %s arg=%u, res=%i, return=%i\n", probefunc(),$arg, $res,
> $return)
> }

First, I hope you're aware that accessing variables in a .return probe
means you get the value from the *entry* time of the function.  That
might be interesting for $arg, but I think $res won't be helpful.

> The code of the function in the kernel is:
> 
> static int mplex_fop_ioctl(struct inode *inode, struct file *filp,
>                            unsigned int cmd, unsigned long arg)
> {
>   int res=0;
[...]
> The values of arg and return are Ok. But as you see in the code of the
> function above, res is initialized with 0. But the probe prints another
> value. Why?

res=0 is the first thing the function does, but the probe is placed
before the function has done anything at all.  So the value you're
reading is probably whatever happened to be in that location already,
whether it's a register or on the stack.


Josh

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Newbie: Access stack avriables in a kernel module
  2010-08-25 15:31 ` Josh Stone
@ 2010-08-26 13:39   ` Wolfram Gettert (News)
  0 siblings, 0 replies; 3+ messages in thread
From: Wolfram Gettert (News) @ 2010-08-26 13:39 UTC (permalink / raw)
  To: systemtap

Hi Josh,
thanks for the quick response.

> First, I hope you're aware that accessing variables in a .return probe
> means you get the value from the *entry* time of the function.  That
> might be interesting for $arg, but I think $res won't be helpful.
Understood, I was not aware about that.

>
>> The code of the function in the kernel is:
>>
>> static int mplex_fop_ioctl(struct inode *inode, struct file *filp,
>>                            unsigned int cmd, unsigned long arg)
>> {
>>   int res=0;
> [...]
>> The values of arg and return are Ok. But as you see in the code of the
>> function above, res is initialized with 0. But the probe prints another
>> value. Why?
>
> res=0 is the first thing the function does, but the probe is placed
> before the function has done anything at all.  So the value you're
> reading is probably whatever happened to be in that location already,
> whether it's a register or on the stack.
>
Understood.


Thanks a lot.

Wolfram

-- 


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-08-26 13:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-25 14:40 Newbie: Access stack avriables in a kernel module Wolfram Gettert
2010-08-25 15:31 ` Josh Stone
2010-08-26 13:39   ` Wolfram Gettert (News)

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 read-only IMAP folder(s) and NNTP newsgroup(s).