[dtrace-discuss] ustack() wrong in pid return probes?

James McIlree jmcilree at apple.com
Sat Jan 20 18:32:12 PST 2007


	I have a test program which has a call sequence of
a(), b(), c(), d().

	When I place a pid return probe on d(), I get a ustack that
looks like this:

               a.out`d+0x19
               a.out`b+0xd
               a.out`a+0xd
               a.out`main+0x3c
               a.out`_start+0x7a

	The c() method appears to be missing.

	I did some poking around and noticed that pid return probes
fire after the instruction being instrumented has executed.

	It seems to me that after a "ret", we're actually in
method c() now, not d(). However, there is this comment and code
in fasttrap_isa.c :

/*
  * Set the program counter to the address of the traced
  * instruction so that it looks right in ustack()
  * output. We had previously set it to the end of the
  * instruction to simplify %rip-relative addressing.
  */
rp->r_pc = pc;

	Is this correct? It seems like the correct ustack()
output would be if the pc was set to "new_pc". Does that break
invariants elsewhere in the code?

	I've included a ustackTest.c & ustack.d that demonstrates
what I'm seeing.

	James M

--------------------- ustackTest.c --------------------------

#include <stdio.h>
#include <unistd.h>

void d(int arg) {
         printf("Got arg of %d\n", arg);
}

void c(int arg) {
         d(arg+1);
}

void b(int arg) {
         c(arg+1);
}

void a(int arg) {
         b(arg+1);
}

int main(void)
{
   int value = 0;

   printf("PID is %u\n", getpid());

   while(1) {
     a(value++);
     sleep(1);
   }
}

------------------------- ustack.d -----------------------

pid$target::d:entry
{
         printf("entry stack...\n");
         ustack();
}

pid$target::d:return
{
         printf("return stack...\n");
         ustack();
}




More information about the dtrace-discuss mailing list