public inbox for systemtap@sourceware.org
 help / color / mirror / Atom feed
From: Giovanni Gherdovich <ggherdovich@suse.cz>
To: systemtap@sourceware.org
Subject: Re: Error when using @container_of
Date: Thu, 25 Apr 2019 08:13:00 -0000	[thread overview]
Message-ID: <1556180324.3080.5.camel@suse.cz> (raw)
In-Reply-To: <1555927560.2268.2.camel@suse.cz>

On Mon, 2019-04-22 at 12:06 +0200, Giovanni Gherdovich wrote:
> Hello,
> 
> when I use the macro @container_of in systemtap I'm getting an error I don't
> understand.
> 
> This is my tapset:
> 
>     #!/root/systemtap-latest/bin/stap
> 
>     probe kernel.function("__update_load_avg_se") {
>             printf("%x\n", @container_of($se, "struct task_struct", se));
>             exit();
>     }
> 
> and this is the error:
> 
>     # ./repro.stp
>     semantic error: 'struct task_struct' (./include/linux/sched.h:602) is being
>     accessed instead of a member such as '->acct_rss_mem1': operator '@cast' at
>     /root/systemtap-latest/share/systemtap/tapset/container_of.stpm:2:5
> 
>             source:     @cast(@ptr - @offsetof(@type, @member), @type)
>                         ^
>             in expansion of macro: operator '@container_of' at ./repro.stp:4:17
>             source:         printf("%x\n", @container_of($se, "struct task_struct", se));
>                                            ^
> 
>     Pass 2: analysis failed.  [man error::pass2]

Hi again,

I'm posting here for future reference: I've been explained that my mistake was
to not use the address-of operator '&' after @container_of. Since my original
goal was to get the PID of a sched entity, the snipped above can be fixed
with:

    probe kernel.function("__update_load_avg_se") {
	    p = &@container_of($se, "struct task_struct", se);
	    printf("pid: %d\n", p->pid);
	    exit();
    }

or even by chaining a field access with -> without using '&' like:

    probe kernel.function("__update_load_avg_se") {
	    printf("pid: %d\n", @container_of($se, "struct task_struct", se)->pid);
	    exit();
    }

In hindsight I should say that the error message makes perfect sense: "you're
accessing the struct itself, you should access a field instead!". What I missed
is that I had to take the address of the struct.


Regards,
Giovanni Gherdovich

      reply	other threads:[~2019-04-25  8:13 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-22 10:01 Giovanni Gherdovich
2019-04-25  8:13 ` Giovanni Gherdovich [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=1556180324.3080.5.camel@suse.cz \
    --to=ggherdovich@suse.cz \
    --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).