|
How do I print or change a GNAT Ada string value in my
probe?
An unconstrained string is represented as
a record with two components.
The first is a pointer to the string (which is not null-terminated) and
the second is a pointer to another record which contains the bounds
of the string.
Version 3.1.8 of the "apc" tool
recognizes this special type and displays
it appropriately, if debug information is available. Since its length is
known, ap_StringValue is not used.
For example:
probe thread
{
probe "hello.qualify_name"
{
on_entry
{
// log the input parameter then stub the routine itself
log("qualify_name called with: ", $1);
ap_StubRoutine;
}
}
}
In the absence of debug information
(e.g., for Ada.Text_IO.Put_Line), or
when you want to assign to an unconstrained string, you can use macros
defined in gnatstrings.h, first included in Aprobe 3.1.7. For example:
#include "gnatstrings.h"
probe thread
{
probe "hello.qualify_name"
{
on_exit
{
// return what we want to:
ap_SetGnatUCString(
$return,
ap_CatenateStrings(
"/home/ocs/",
ap_ExtractGnatUCString($1),
NULL));
}
}
}
|