Difference between revisions of "Setting String Parameters"

From OC Systems Wiki!
Jump to: navigation, search
(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...")
 
m
Line 76: Line 76:
 
Will modify the C++ string parameter "str" before the method is executed.
 
Will modify the C++ string parameter "str" before the method is executed.
  
See [[http://www.ocsystems.com/w/index.php/Aprobe_FAQ section:Aprobe FAQ]] 17.65 for directions on building ,<code>cppstring.ual</code>.
+
See [[http://www.ocsystems.com/w/index.php/Aprobe_FAQ:Aprobe FAQ]] section 17.65 for directions on building <code>cppstring.ual</code>.
  
 
==Ada Example==
 
==Ada Example==
  
For GNAT Ada code like this:
+
See [[Setting Ada String Parameters]] for Ada examples.
 
 
<source lang="ada">
 
 
 
  -- Ada procedure with string parameter
 
  procedure P1(S : in String) is
 
  begin
 
    Text_Io.Put_Line("p1, " & S);
 
  end P1;
 
</source>
 
 
 
This probe:
 
 
 
<source lang="c">
 
 
 
#include "gnatstrings.h"
 
 
 
probe thread
 
{
 
  probe "pkg.p1"
 
  {
 
      on_entry
 
      {
 
        // modify unconstrained Gnat string using macro
 
        ap_SetGnatUCString($s, "new value");
 
      }
 
  }
 
}
 
 
 
</source>
 
 
 
Will modify the string before the procedure executes.
 
  
 
[[Category:FAQ]]
 
[[Category:FAQ]]
 
[[Category:Strings]]
 
[[Category:Strings]]
 
[[Category:Modifying]]
 
[[Category:Modifying]]

Revision as of 00:21, 9 March 2021

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 [FAQ] section 17.65 for directions on building cppstring.ual.

Ada Example

See Setting Ada String Parameters for Ada examples.