1 Reply Latest reply on Oct 14, 2011 5:04 PM by 877216

    How to get a value if arg0 is a pointer?

      I catch function and arg0 is a pointer.
      example: 0xFFFFFFFF7CF67FB0

      I used following:
      I need to get (just print) value from this pointer. Could anybody helps?
        • 1. Re: How to get a value if arg0 is a pointer?

          Depends what your first argument points to. I've created a simple testcase where it's an <tt>int</tt>:
          #include <stdio.h>
          #include <stdlib.h>
          int func(int* first, char* second, float* third, void* fourth) {
                  printf("Called func\n");
          int main(int argc, char** argv) {
                  int a=3;
                  char b='p';
                  float c=4.565564;
                  func(&a, &b, &c, (void*) &main);
                  return EXIT_SUCCESS;
          Then, it's a simple matter of using <tt>copyin</tt> to make a copy of the value pointed to by arg0 in DTrace's scratch buffer, so we may dereference it safely in the call to <tt>printf</tt>:
          $ cc ./testcase.c -o testcase
          $ pfexec dtrace -n 'pid$target::func:entry{ first_arg=(int*) copyin(arg0,sizeof(int)); printf("%s(arg0=0x%X, *arg0=%d)\n", probefunc, arg0,*first_arg);  }' -c ./testcase
          dtrace: description 'pid$target::func:entry' matched 1 probe
          Called func
          dtrace: pid 5575 has exited
          CPU     ID                    FUNCTION:NAME
            1  84302                       func:entry func(arg0=0x80477D0, *arg0=3)