public inbox for systemtap@sourceware.org
 help / color / mirror / Atom feed
* It's confused that local variable's value not change in function.return probe.
@ 2021-01-06  6:40 David McRay
  2021-01-10 17:20 ` Frank Ch. Eigler
  0 siblings, 1 reply; 5+ messages in thread
From: David McRay @ 2021-01-06  6:40 UTC (permalink / raw)
  To: systemtap

It's confused that local variable's value not change in function.return
probe.
I need to track a function behavior of my userspace program, so two probe
(function.call and function.return) are setted up.
In function I would change the value of a variable, but in function.call
and function.return I found the value of the variable are just the same as
 it is before this function is called. BUT the value should be changed at
return moment.

Below is a sample demonstrate that. Is there something wrong or it's as
expected ?

>>>>> TestStap.c <<<<
#include <stdio.h>
#include <string.h>

struct Co {
  int id_;
  char* data_;
};
void setmbuf(const char *str);

void Run (struct Co* a) {
  printf("before: %2d %s\n", a->id_, a->data_);
  a->id_ = -1;         // change the value!
  setmbuf("kkkkkkk");  // change the value!
  printf("after : %2d %s\n", a->id_, a->data_);
}

char buf[100];

void setmbuf(const char *str)
{
  int i = 0;
  int l = strlen(str) - 1;
  for (i = 0; i <= l; i++) {
    buf[i] = str[i];
  }
  buf[i] = '\0';
}

int main() {
  struct Co a;
  a.id_ = 0;
  a.data_ = buf;
  setmbuf("aaaaaa");
  Run(&a);
  return 0;
}


>>> tracker.stp <<<
probe begin {
  printf ("probe begin: pid is %d\n", pid())
}
probe end {
  printf ("probe end\n")
}
probe process("build/TestStapC").function("Run@tests/TestStap.c").call {
  printf("call   a: %s\n", $a$)
}
probe process("build/TestStapC").function("Run@tests/TestStap.c").return {
  printf("return a: %s\n", $a$)
}


>>>> running stap <<<<
gcc tests/TestStap.c -O0 -o build/TestStapC -ggdb -gdwarf

# stap tracker.stp -c ./build/TestStapC
WARNING: confusing usage, consider @entry($a->$) in .return probe:
identifier '$a$' at scripts/track_cplusplus/track_c.stp:11:28
 source:   printf("return a: %s\n", $a$)
                                    ^
before:  0 aaaaaa
after : -1 kkkkkkk
probe begin: pid is 387944
call   a: {.id_=0, .data_="aaaaaa"}
return a: {.id_=0, .data_="aaaaaa"}
probe end

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

* Re: It's confused that local variable's value not change in function.return probe.
  2021-01-06  6:40 It's confused that local variable's value not change in function.return probe David McRay
@ 2021-01-10 17:20 ` Frank Ch. Eigler
  2021-01-13  4:37   ` Craig Ringer
  0 siblings, 1 reply; 5+ messages in thread
From: Frank Ch. Eigler @ 2021-01-10 17:20 UTC (permalink / raw)
  To: David McRay; +Cc: systemtap


David McRay wrote:

> It's confused that local variable's value not change in function.return
> probe. [...]
>>>>> running stap <<<<
> gcc tests/TestStap.c -O0 -o build/TestStapC -ggdb -gdwarf
>
> # stap tracker.stp -c ./build/TestStapC
> WARNING: confusing usage, consider @entry($a->$) in .return probe:
> identifier '$a$' at scripts/track_cplusplus/track_c.stp:11:28
>  source:   printf("return a: %s\n", $a$)

The warning message is on topic.  If in a .return probe, you access a
general $context variable, this refers to a saved snapshot of the
variable as evaluated at function-entry time.  See also [man stapprobes]
If you wish to look at the fields of a->* -after- the function returns,
you can use something like:

    @cast(@entry(&$a),"Co")$
instead of
    $a$
which works by saving only the address of $a, and 
dereferencing/pretty-printing it at return time.

... though we should be able to automate that, in the future, down to
    @entry(&$a)$
with a little better dwarf type inference.


- FChE


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

* Re: It's confused that local variable's value not change in function.return probe.
  2021-01-10 17:20 ` Frank Ch. Eigler
@ 2021-01-13  4:37   ` Craig Ringer
  2021-01-13  8:59     ` David McRay
  2021-01-14 21:47     ` Frank Ch. Eigler
  0 siblings, 2 replies; 5+ messages in thread
From: Craig Ringer @ 2021-01-13  4:37 UTC (permalink / raw)
  To: Frank Ch. Eigler; +Cc: David McRay, systemtap

On Mon, 11 Jan 2021 at 01:21, Frank Ch. Eigler via Systemtap <
systemtap@sourceware.org> wrote:

>
> David McRay wrote:
>
> > It's confused that local variable's value not change in function.return
> > probe. [...]
> >>>>> running stap <<<<
> > gcc tests/TestStap.c -O0 -o build/TestStapC -ggdb -gdwarf
> >
> > # stap tracker.stp -c ./build/TestStapC
> > WARNING: confusing usage, consider @entry($a->$) in .return probe:
> > identifier '$a$' at scripts/track_cplusplus/track_c.stp:11:28
> >  source:   printf("return a: %s\n", $a$)
>
> The warning message is on topic.  If in a .return probe, you access a
> general $context variable, this refers to a saved snapshot of the
> variable as evaluated at function-entry time.  See also [man stapprobes]
>

I never found that especially confusing, but I can see how the message
might be improved.

- WARNING: confusing usage, consider @entry($a->$)
+ WARNING: value of  $a is captured at function entry and will not reflect
any changes made since; consider explicitly using @entry($a->$)

or something like that?

Or a subhead hint in "man stapprobes" like "See also [man stapprobes]
heading MORE ON RETURN PROBES".

-- 
 Craig Ringer                   http://www.2ndQuadrant.com/
 2ndQuadrant - PostgreSQL Solutions for the Enterprise

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

* Re: It's confused that local variable's value not change in function.return probe.
  2021-01-13  4:37   ` Craig Ringer
@ 2021-01-13  8:59     ` David McRay
  2021-01-14 21:47     ` Frank Ch. Eigler
  1 sibling, 0 replies; 5+ messages in thread
From: David McRay @ 2021-01-13  8:59 UTC (permalink / raw)
  To: Craig Ringer; +Cc: Frank Ch. Eigler, systemtap

Thanks.Got that.

Craig Ringer <craig@2ndquadrant.com> 于2021年1月13日周三 下午12:37写道:

> On Mon, 11 Jan 2021 at 01:21, Frank Ch. Eigler via Systemtap <
> systemtap@sourceware.org> wrote:
>
>>
>> David McRay wrote:
>>
>> > It's confused that local variable's value not change in function.return
>> > probe. [...]
>> >>>>> running stap <<<<
>> > gcc tests/TestStap.c -O0 -o build/TestStapC -ggdb -gdwarf
>> >
>> > # stap tracker.stp -c ./build/TestStapC
>> > WARNING: confusing usage, consider @entry($a->$) in .return probe:
>> > identifier '$a$' at scripts/track_cplusplus/track_c.stp:11:28
>> >  source:   printf("return a: %s\n", $a$)
>>
>> The warning message is on topic.  If in a .return probe, you access a
>> general $context variable, this refers to a saved snapshot of the
>> variable as evaluated at function-entry time.  See also [man stapprobes]
>>
>
> I never found that especially confusing, but I can see how the message
> might be improved.
>
> - WARNING: confusing usage, consider @entry($a->$)
> + WARNING: value of  $a is captured at function entry and will not reflect
> any changes made since; consider explicitly using @entry($a->$)
>
> or something like that?
>
> Or a subhead hint in "man stapprobes" like "See also [man stapprobes]
> heading MORE ON RETURN PROBES".
>
> --
>  Craig Ringer                   http://www.2ndQuadrant.com/
>  2ndQuadrant - PostgreSQL Solutions for the Enterprise
>

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

* Re: It's confused that local variable's value not change in function.return probe.
  2021-01-13  4:37   ` Craig Ringer
  2021-01-13  8:59     ` David McRay
@ 2021-01-14 21:47     ` Frank Ch. Eigler
  1 sibling, 0 replies; 5+ messages in thread
From: Frank Ch. Eigler @ 2021-01-14 21:47 UTC (permalink / raw)
  To: Craig Ringer; +Cc: David McRay, systemtap

Hi -

> I never found that especially confusing, but I can see how the message
> might be improved.
> 
> - WARNING: confusing usage, consider @entry($a->$)
> + WARNING: value of  $a is captured at function entry and will not reflect
> any changes made since; consider explicitly using @entry($a->$)
> 
> or something like that?

Done, thanks for the idea.
The message is relatively long, but less confusing. 

- FChE


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

end of thread, other threads:[~2021-01-14 21:47 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-06  6:40 It's confused that local variable's value not change in function.return probe David McRay
2021-01-10 17:20 ` Frank Ch. Eigler
2021-01-13  4:37   ` Craig Ringer
2021-01-13  8:59     ` David McRay
2021-01-14 21:47     ` Frank Ch. Eigler

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).