[includes/hd_aprobe5-examples.htm]
 
Aprobe 5  

1. How do I apply a probe to a Linux user mode program?

The probe: hello.spc
--------------------------

probe thread
{
  probe "main"
  {
    on_entry 
    {
       sp_Printf ("sp_Printf: Enter main\n");
    }
    on_line (first + 2)
    {
       sp_Printf ("sp_Printf: In main, Local_Variable = %d\n", $Local_Variable);
    }
    on_exit
    {
       sp_Printf ("sp_Printf: Leave main, returning %d\n", $return);
    }
  }
  probe "printf" in "libc.so"
  {
    on_entry 
    {
       sp_Printf ("sp_Printf: Enter printf\n");
    }
  }
}


Main test: hello.c

#include <stdio.h>

int main (int argc, char** argv)
{
   int Local_Variable = 17;
   printf ("Hello, world!");
   return (100 + Local_Variable);
}


Compile the hello.c program to create hello.exe:
------------------------------------------------

gcc -g hello.c -o hello.exe


Compile the hello.spc probe to create hello.usm:
------------------------------------------------------

spc -t linux:x86 -x /lib/tls/libc.so.6 -x hello.exe hello.spc


The result:
-----------

Use sptool to run hello.exe program with hello.usm probe applied to it.

sptool -u hello.usm hello.exe

sp_Printf: Enter main
sp_Printf: In main, Local_Variable = 17
sp_Printf: Enter printf
Hello, world!
sp_Printf: Leave main, returning 117