First off, here's the script:
pid$target::foo:entry
{
ustack();
self->arg0 = arg0;
self->arg1 = arg1;
printf("arg0 = 0x%x\n", self->arg0);
printf("*arg0 = %d\n", *(int *)copyin(self->arg0, 4));
printf("arg1 = 0x%x\n", self->arg1);
printf("*arg1 = %d\n", *(int *)copyin(self->arg1, 4));
}
pid$target::foo:return
{
ustack();
printf("arg0 = 0x%x\n", self->arg0);
printf("*arg0 = %d\n", *(int *)copyin(self->arg0, 4));
printf("arg1 = 0x%x\n", self->arg1);
printf("*arg1 = %d\n", *(int *)copyin(self->arg1, 4));
printf("return = %d\n", arg1);
}
How this works. ustack() prints the stack of the user process.
In an function entry, argN is the Nth argument to the function. Since the arguments are
pointers, you need to use copyin() to copy in the actual data before you dereference it.
For a function return, you no longer have access to the function arguments. So you save
the parameters for later use.
Finally, for a function return, you can access the value returned by the function with
arg1.