public inbox for systemtap@sourceware.org
 help / color / mirror / Atom feed
From: David McRay <mcmggradty1991@gmail.com>
To: systemtap@sourceware.org
Subject: It's confused that local variable's value not change in function.return probe.
Date: Wed, 6 Jan 2021 14:40:26 +0800	[thread overview]
Message-ID: <CAJnvFBJsAOd-8L+phK8AhspdvY9Ov3SCD7cCPhUXHdRMzF=2qA@mail.gmail.com> (raw)

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

             reply	other threads:[~2021-01-06  6:40 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-06  6:40 David McRay [this message]
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

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='CAJnvFBJsAOd-8L+phK8AhspdvY9Ov3SCD7cCPhUXHdRMzF=2qA@mail.gmail.com' \
    --to=mcmggradty1991@gmail.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).