Debian Codegraph @

doc/SystemTap_Beginners_Guide/testsuite/systemtap.base/setjmp.stp

raw
1 global jmp_buf, jmp_target, jmp_backtrace
2
3 function callers:string()
4 {
5 bt = ubacktrace();
6 // Skip the first caller, which is setjmp or longjmp itself.
7 callers = "";
8 token = tokenize(bt, " ");
9 while ((token = tokenize("", " ")) != "")
10 callers = callers . " " . token;
11 return callers;
12 }
13
14 function nth_caller:long(n, bt)
15 {
16 token = tokenize(bt, " ");
17 while (n-- > 0)
18 token = tokenize("", " ");
19 return strtol(token, 16);
20 }
21
22 global started = 0
23 probe process(@1).function("main")
24 {
25 started = 1;
26 }
27
28 probe process("/lib*/libc.so.*").mark("setjmp")
29 {
30 if (!started) next;
31
32 jmp_buf[tid()] = $arg1;
33 jmp_target[tid()] = $arg3;
34 bt = jmp_backtrace[tid()] = callers();
35 for (i = 0; i < 5; ++i)
36 if (usymname(nth_caller(i, bt)) == "setter")
37 next;
38 printf("setjmp backtrace doesn't include setter:\n");
39 print_ubacktrace();
40 }
41
42 function check_jmp(buf, target)
43 {
44 if (jmp_buf[tid()] != buf)
45 printf("longjmp env %p, expected %p\n", buf, jmp_buf[tid()]);
46 if (jmp_target[tid()] != target)
47 printf("longjmp target %p, expected %p\n", target, jmp_target[tid()]);
48 }
49
50 probe process("/lib*/libc.so.*").mark("longjmp")
51 {
52 if (!started) next;
53
54 check_jmp($arg1, $arg3);
55 bt = callers();
56 if (bt == jmp_backtrace[tid()])
57 printf("longjmp backtrace matches setjmp backtrace!\n");
58 for (i = 0; i < 5; ++i)
59 if (usymname(nth_caller(i, bt)) == "jumper")
60 next;
61 printf("longjmp backtrace doesn't include jumper:\n");
62 print_ubacktrace();
63 }
64
65 probe process("/lib*/libc.so.*").mark("longjmp_target")
66 {
67 if (!started) next;
68
69 check_jmp($arg1, $arg3);
70 bt = callers();
71 if (bt != jmp_backtrace[tid()])
72 printf("longjmp_target backtrace does not match setjmp:\n\t%s\nvs\t%s",
73 sprint_usyms(jmp_backtrace[tid()]), sprint_usyms(bt));
74
75 printf("hit longjmp_target\n");
76 }