It's ok, solved it!
struct Test
{
uintptr_t msg;
};
:-D
Jono
-------- Original Message --------
Subject: reading std::string contents with dtrace?
Date: Wed, 25 Jun 2014 14:11:06 +1200
From: Jono Poff <jonathan.p...@taitradio.com>
To: dtrace-discuss@lists.dtrace.org
Hi,
I have 2 test setups (see below....). test0 reads the contents of a
struct and test1 reads the contents of a std::string.
these both work as expected, ie.....
====== test0
# dtrace -s test0.d -p `pgrep test0` -32 -q
dtrace: script 'test0.d' matched 2 probes
Z ...zzzz
Q ...qqqq
====== test1
# dtrace -s test1.d -p `pgrep test1` -32 -q
dtrace: script 'test1.d' matched 2 probes
XXXX
RRRR
======
However, what I actually require is a probe that can read a struct with
a std::string member, eg:
struct Test
{
std::string msg;
};
How can I declare this struct in the dtrace script and also how does
dtrace actually interpret the std::string layout. Is it magic or logic?
If it's possible, could I please have a worked example? :o)
Cheers,
Jono
====================================================================
test.cpp
#include<string>
#include <unistd.h>
using std::string;
enum{SZ=100};
struct Test
{
char c;
char msg[SZ];
};
Test *xxx(Test *t)
{
strncpy(t->msg, "qqqq", SZ-1);
t->c='Q';
return t;
}
int main()
{
Test test;
while(true)
{
strncpy(test.msg, "zzzz", SZ-1);
test.c='Z';
xxx(&test);
sleep(1);
}
}
==================================================================== test.d
enum{SZ=100};
struct Test
{
char c;
char msg[SZ];
};
pid$target::_Z3xxxP4Test:entry
{
this->test = (struct Test *) copyin ( arg0, sizeof ( struct
Test ) );
printf("\n%c ...%s ", this->test->c, this->test->msg);
}
pid$target::_Z3xxxP4Test:entry
{
this->test = (struct Test *) copyin ( arg0, sizeof ( struct
Test ) );
printf("\n%c ...%s ", this->test->c, this->test->msg);
}
pid$target::_Z3xxxP4Test:return
{
this->test = (struct Test *) copyin ( arg1, sizeof ( struct
Test ) );
printf("\n%c ...%s", this->test->c, this->test->msg);
}
====================================================================
====================================================================
====================================================================
====================================================================
test1.cpp
#include<string>
#include <unistd.h>
using std::string;
string xxx(string &t)
{
t = "RRRR";
return t;
}
int main()
{
string test;
while(true)
{
test = "XXXX";
xxx(test);
sleep(1);
}
}
====================================================================
test1.cpp
pid$target::_Z3xxxRSs:entry
{
this->str = *((uintptr_t*)copyin(arg0, sizeof(void*)));
printf("\n%s", copyinstr(this->str));
}
pid$target::_Z3xxxRSs:return
{
this->str = *((uintptr_t*)copyin(arg1, sizeof(void*)));
printf("\n%s", copyinstr(this->str));
}
====================================================================
====================================================================
====================================================================
====================================================================
--
------------------------------
This email, including any attachments, is only for the intended recipient.
It is subject to copyright, is confidential and may be the subject of legal
or other privilege, none of which is waived or lost by reason of this
transmission.
If you are not an intended recipient, you may not use, disseminate,
distribute or reproduce such email, any attachments, or any part thereof.
If you have received a message in error, please notify the sender
immediately and erase all copies of the message and any attachments.
Unfortunately, we cannot warrant that the email has not been altered or
corrupted during transmission nor can we guarantee that any email or any
attachments are free from computer viruses or other conditions which may
damage or interfere with recipient data, hardware or software. The
recipient relies upon its own procedures and assumes all risk of use and of
opening any attachments.
------------------------------
-------------------------------------------
dtrace-discuss
Archives: https://www.listbox.com/member/archive/184261/=now
RSS Feed: https://www.listbox.com/member/archive/rss/184261/25769126-e243886f
Modify Your Subscription:
https://www.listbox.com/member/?member_id=25769126&id_secret=25769126-8d47a7b2
Powered by Listbox: http://www.listbox.com