[includes/hd_aprobe5-examples.htm]
Aprobe 5

5. How do I log the contents of an array?

The probe: main.spc
-------------------------

probe thread
{
   probe "sum_10"
   {
      on_entry 
      {
         log ("Items = ", $Items[0..9]);
      }
   }
   probe "sum_n"
   {
      int n;
      on_entry 
      {
         for (n=0; $Dynamic[n] != 0; n++)
           ; /* final entry has 0 */
         log ("Dynamic = ", $Dynamic[0..n-1]);
      }
   }
}


Main test: main.c
-----------------

int Items[10];
int Dynamic[] = {1,2,3,4,5};

int sum_10 (int* My_Array)
{
  int i, sum = 0;

  for (i=0; i<10; i++)
  {
     sum += My_Array[i];
  }
  return sum;
}

int sum_n (int* My_Array)
{
  int i, sum = 0;

  for (i=0; My_Array[i] != 0; i++)
  {
     sum += My_Array[i];
  }
  return sum;
}

int main (int argc, char** argv)
{
  int i, total;

  for (i=0; i<10; i++)
  {
     Items[i] = 100 + i;
  }
  total = sum_10 (Items) + sum_n (Dynamic);
  return total;
}


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

gcc -g main.c -o main.exe


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

spc -t linux:x86 -x main.exe main.spc


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

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

sptool -u main.usm -if main.exe

Items = {
    [0] =  100
    [1] =  101
    [2] =  102
    [3] =  103
    [4] =  104
    [5] =  105
    [6] =  106
    [7] =  107
    [8] =  108
    [9] =  109
}
Dynamic = {
    [0] =  1
    [1] =  2
    [2] =  3
    [3] =  4
    [4] =  5
}