String logging

From OC Systems Wiki!
Revision as of 00:35, 30 March 2017 by Swn (talk | contribs) (Created page with " Logging strings from applications can be confusing because different languages have different string formats. Here are some examples for logging different kinds of strings....")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Logging strings from applications can be confusing because different languages have different string formats. Here are some examples for logging different kinds of strings.

C Example

For a C program like this:

/* C function with string parameter */
void p1(const char *str)
{
  printf("str = %s\n", str);
}

This probe:

probe thread
{
   probe "p1"
   {
      on_entry
      {
         // log whole string
         log ("\"str\" = ", ap_StringValue($str));
      }
   }
}

Will produce this output:

"str" = hello
"str" = 1234567890

C++ Example

For a C++ program like this:

void p1(std::string str)
{
  std::cout << "str = " << str << std::endl;
}

This probe:

probe thread
{
   probe "p1"
   {
      on_entry
      {
         // log whole string
#ifdef _AIX
         // on AIX dig into the str::string object
         log ("\"str\" = ", $str._Ptr);
#else
         log ("\"str\" = ", $str);
#endif
      }
   }
}

Will produce this output:

"str" = hello
"str" = 1234567890

Ada Example

For Ada code like thist:

  -- Ada procedure with string parameter
  procedure P1(S : in String) is
  begin
    Text_Io.Put_Line("p1, " & S);
  end P1;

This probe:

probe thread
{
   probe "pkg.p1"
   {
      on_entry
      {
         // log whole string
         log ("\"s\" = ", $s);
         // log a slice
         log ("\"s[1..3]\" = ", $s[1..3]);
      }
   }
}

Will produce this output:

"s" = xxxxxxxxxx
"s[1..3]" = xxx
"s" = Hello there.
"s[1..3]" = Hel