From: Stan Cox <scox@redhat.com>
To: Siva N <harnan@outlook.com>
Cc: systemtap@sourceware.org
Subject: Re: stap --dyninst with C++ applications
Date: Tue, 19 Jan 2021 14:38:03 -0500 [thread overview]
Message-ID: <9e49ec35-f18b-2a52-39c9-4be844905ed8@redhat.com> (raw)
In-Reply-To: <CS1PR8401MB0903E324E417D28ED3108F22C6E90@CS1PR8401MB0903.NAMPRD84.PROD.OUTLOOK.COM>
> 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
prev parent reply other threads:[~2021-01-19 19:38 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-10 20:19 Siva N
2021-01-19 19:38 ` Stan Cox [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=9e49ec35-f18b-2a52-39c9-4be844905ed8@redhat.com \
--to=scox@redhat.com \
--cc=harnan@outlook.com \
--cc=systemtap@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).