From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 103981 invoked by alias); 25 Apr 2019 08:13:59 -0000 Mailing-List: contact systemtap-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: systemtap-owner@sourceware.org Received: (qmail 103973 invoked by uid 89); 25 Apr 2019 08:13:58 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_PASS autolearn=ham version=3.3.1 spammy=H*r:sk:systemt X-HELO: mx1.suse.de Received: from mx2.suse.de (HELO mx1.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 25 Apr 2019 08:13:57 +0000 Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 54BF7ABD0 for ; Thu, 25 Apr 2019 08:13:55 +0000 (UTC) Message-ID: <1556180324.3080.5.camel@suse.cz> Subject: Re: Error when using @container_of From: Giovanni Gherdovich To: systemtap@sourceware.org Date: Thu, 25 Apr 2019 08:13:00 -0000 In-Reply-To: <1555927560.2268.2.camel@suse.cz> References: <1555927560.2268.2.camel@suse.cz> Content-Type: text/plain; charset="UTF-8" Mime-Version: 1.0 Content-Transfer-Encoding: 7bit X-IsSubscribed: yes X-SW-Source: 2019-q2/txt/msg00034.txt.bz2 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