Setting String Parameters

From OC Systems Wiki!
Revision as of 00:16, 9 March 2021 by Swn (talk | contribs) (Created page with " Modifying string parameters from applications can be confusing because different languages have different string formats. Here are some examples for modifying different kind...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Modifying string parameters from applications can be confusing because different languages have different string formats. Here are some examples for modifying 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
      {
         // modify string directly 
         $str = "string value";
      }
   }
}

Will modify the string parameter "str" before it is used in the function.

C++ Example

For a C++ program like this:

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

This probe:

#include "cppstring.h"

probe thread
{
   probe "p1"
   {
      on_entry
      {
         // modify string using macro
         AP_SET_CPP_STR($str, "new value");
      }
   }
}

Compiled with this command:

apc -x my program.exe myprobe.apc cppstring.ual
 

Will modify the C++ string parameter "str" before the method is executed.

See [section:Aprobe FAQ] 17.65 for directions on building ,cppstring.ual.

Ada Example

For GNAT Ada code like this:

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

This probe:

#include "gnatstrings.h"

probe thread
{
   probe "pkg.p1"
   {
      on_entry
      {
         // modify unconstrained Gnat string using macro
         ap_SetGnatUCString($s, "new value");
      }
   }
}

Will modify the string before the procedure executes.