public inbox for systemtap@sourceware.org
 help / color / mirror / Atom feed
* stap --dyninst with C++ applications
@ 2020-11-10 20:19 Siva N
  2021-01-19 19:38 ` Stan Cox
  0 siblings, 1 reply; 2+ messages in thread
From: Siva N @ 2020-11-10 20:19 UTC (permalink / raw)
  To: systemtap

Hi,

I am curious to understand how C++ object arguments are handled with USDT.

I have a C++ application. I have added probe points using the DTRACE_PROBE[n] macro. If I pass a reference/pointer to a C++ object as one of the arguments, I wonder how one accesses this inside the probe handler. I could treat the argument(s) as a void pointer, and if I managed create the actual C++ object layout, I guess I could access the data. But I was wondering if there were any other suggestions or examples.

Thanks!

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: stap --dyninst with C++ applications
  2020-11-10 20:19 stap --dyninst with C++ applications Siva N
@ 2021-01-19 19:38 ` Stan Cox
  0 siblings, 0 replies; 2+ messages in thread
From: Stan Cox @ 2021-01-19 19:38 UTC (permalink / raw)
  To: Siva N; +Cc: systemtap

> I am curious to understand how C++ object arguments are handled with USDT.
> 
> I have a C++ application. I have added probe points using the DTRACE_PROBE[n] macro. If I pass a reference/pointer to a C++ object as one of the arguments, I wonder how one accesses this inside the probe handler. I could treat the argument(s) as a void pointer, and if I managed create the actual C++ object layout

--dyninst should handle probe("NAME").mark("LABEL") probes fine.  If I 
have the small c++ sample:

> #include <string>
> #include <iostream>
> #include <tstclass.h>
> using namespace std;
> 
> struct A
> {
>   A();
>   long aa;
>   long bb;
>   string string1;
>   string string2;
> };
> 
> A::A ()
> {
>   aa = 10;
>   bb = 20;
>   string1 = "abc";
>   string2 = "xyz";
> }
> 
> int main()
> {
>   struct A anA;
>   SDT_MISC_TEST_PROBE_4(&anA);
>   std::cout << anA.aa << ' ' << anA.bb << ' ' << anA.string1 << ' ' << anA.string2 << ' ' << '\n';
> }

and the .d file:
> provider sdt_misc {
> 	probe test_probe_4 (struct A arg);
> };

Then the arg struct corresponding to SDT_MISC_TEST_PROBE_4 can be 
accessed via:
> function get_string:string (str)
> %{
>   char astr[32];
>   strcpy (astr,(char*)STAP_ARG_str);
>   STAP_RETURN (astr);
> %}
> 
> probe process("./tstclass.x").mark("test_probe_4") 
> { 
>   printf("%s aa=%#lx string1=%s\n",pp(),@cast($arg1,"struct A")->aa, 
> 	 get_string(@cast($arg1,"struct A")->string1->_M_dataplus->_M_p))
> }

The @cast interprets arg1 as a struct A so the members can be accessed. 
  The probes are translated to C so it uses internal knowledge to get at 
string1.  (Is there an easier way to do this?)  So that yields:
% stap --dyninst -g --disable-cache tstclass.stp -c ./tstclass.x
process("/this/dir/tstclass.x").statement(0x401283) aa=0xa string1=abc
10 20 abc xyz


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-01-19 19:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-10 20:19 stap --dyninst with C++ applications Siva N
2021-01-19 19:38 ` Stan Cox

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).