#include "sys/sdt.h"
-#include <string>
+extern "C" {
+#include <string.h>
+}
+
+class sClass
+{
+private:
+ const char *_str;
+ size_t _l;
+
+public:
+ sClass(const char *n) : _str(n)
+ {
+ _l = strlen(_str);
+ }
+
+ const char *name(void)
+ {
+ return _str;
+ }
+
+ size_t len(void) const
+ {
+ return _l;
+ }
+};
size_t
-length(const std::string& str)
+length(const sClass& str)
{
int res, r;
STAP_PROBE1(cast-scope, length, &str);
- r = str.length() * 2;
+ r = str.len() * 2;
STAP_PROBE(cast-scope, dummy); /* Just here to probe line +5. */
res = r / 2;
STAP_PROBE(cast-scope, dummy2); /* Just here prevent line reordering. */
int
main()
{
- std::string hello = "Hello World!";
+ sClass hello = sClass("Hello World!");
return 12 != length(hello);
}
set test "cast-scope"
-set ::result_string {function direct: {._M_dataplus={._M_p="Hello World!"}}
-function cast: {._M_dataplus={._M_p="Hello World!"}}
-mark cast: {._M_dataplus={._M_p="Hello World!"}}
-statement direct: {._M_dataplus={._M_p="Hello World!"}}
-statement cast: {._M_dataplus={._M_p="Hello World!"}}}
+set ::result_string {function direct: {._str="Hello World!", ._l=12}
+function cast: {._str="Hello World!", ._l=12}
+mark cast: {._str="Hello World!", ._l=12}
+statement direct: {._str="Hello World!", ._l=12}
+statement cast: {._str="Hello World!", ._l=12}}
set srcfile "$srcdir/$subdir/$test.cxx"
set stpfile "$srcdir/$subdir/$test.stp"
probe process.function("length@cast-scope.cxx")
{
function_string .= sprintf("function direct: %s\n", $str$$)
- function_string .= sprintf("function cast: %s\n", @cast($str, "std::string")$$)
+ function_string .= sprintf("function cast: %s\n", @cast($str, "sClass")$$)
}
probe process.statement("length@cast-scope.cxx+5")
{
statement_string .= sprintf("statement direct: %s\n", $str$$)
- statement_string .= sprintf("statement cast: %s\n", @cast($str, "std::string")$$)
+ statement_string .= sprintf("statement cast: %s\n", @cast($str, "sClass")$$)
}
probe process.mark("length")
{
- mark_string .= sprintf("mark cast: %s\n", @cast($arg1, "std::string")$$)
+ mark_string .= sprintf("mark cast: %s\n", @cast($arg1, "sClass")$$)
}
probe end