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

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