summaryrefslogtreecommitdiffstats
path: root/testsuite/systemtap.base/cxxclass.cxx
blob: 492a97f99047766b1cf01a64b1ff88486179b9c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include "sys/sdt.h"

#include <stdio.h>

class ProbeClass
{
private:
  int& ref;
  const char *name;

public:
  ProbeClass(int& v, const char *n) : ref(v), name(n)
  {
    STAP_PROBE2(_test_, cons, name, ref);
  }

  void method(int min)
  {
    STAP_PROBE3(_test_, meth, name, ref, min);
    ref -= min;
  }
  
  ~ProbeClass()
  {
    STAP_PROBE2(_test_, dest, name, ref);
  }
}; 

static void
call()
{
  int i = 64;
  STAP_PROBE1(_test_, call, i);
  ProbeClass inst = ProbeClass(i, "call");
  inst.method(24);
  i += 2;
  // Here the destructor goes out of scope and uses i as ref one last time.
}

static void
call2()
{
  int j = 24;
  STAP_PROBE1(_test_, call2, j);
  ProbeClass inst = ProbeClass(j, "call2");
  inst.method(40);
  j += 58;
  // Here the destructor goes out of scope and uses i as ref one last time.
}

int
main (int argc, char **argv)
{
  STAP_PROBE(_test_, main_enter);
  call();
  call2();
  STAP_PROBE(_test_, main_exit);
  return 0;
}