summaryrefslogtreecommitdiffstats
path: root/testsuite/systemtap.base/cast.stp
blob: 33a14a28c0c08cff29e7bf6159ea1dfb092099ee (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
probe begin
{
    curr = task_current()

    // Compare PIDs
    pid = pid()
    cast_pid = @cast(curr, "task_struct")->tgid
    if (pid == cast_pid)
        println("PID OK")
    else
        printf("PID %d != %d\n", pid, cast_pid)

    // Compare PIDs using a generated kernel module
    cast_pid = @cast(curr, "task_struct", "kmod<linux/sched.h>")->tgid
    if (pid == cast_pid)
        println("PID2 OK")
    else
        printf("PID2 %d != %d\n", pid, cast_pid)

    // Compare execnames
    name = execname()
    cast_name = kernel_string(@cast(curr, "task_struct")->comm)
    if (name == cast_name)
        println("execname OK")
    else
        printf("execname \"%s\" != \"%s\"\n", name, cast_name)

    // Compare tv_sec using a generated user module
    sec = 42
    cast_sec = @cast(get_timeval(sec), "timeval", "umod<sys/time.h>")->tv_sec
    if (sec == cast_sec)
        println("tv_sec OK")
    else
        printf("tv_sec %d != %d\n", sec, cast_sec)

    exit()
}

function get_timeval:long(sec:long) %{
    static struct timeval mytime = {0};
    mytime.tv_sec = THIS->sec;
    THIS->__retvalue = (long)&mytime;
%}