Debian Codegraph @

testsuite/systemtap.speculate/speculate.stp

raw
1 #! stap -p4
2
3 # test to exercise the speculative.stp tapset
4 # shows file operations for a file that later had a read or write problem.
5
6 global file_desc
7 global tid_filename%, tid_fd%, tid_buf%, tid_count%
8
9 probe syscall.open, syscall.openat
10 {
11 if (pid() != target()) next
12 tid_filename[tid()] = filename
13 }
14
15 probe syscall.open.return, syscall.openat.return
16 {
17 if (pid() != target()) next
18 file_desc[retval] = speculation()
19 speculate(file_desc[retval], sprintf("open(%s) = %d\n",
20 tid_filename[tid()], retval))
21 }
22
23 probe syscall.close
24 {
25 if (pid() != target()) next
26 tid_fd[tid()] = fd
27 }
28
29 probe syscall.close.return
30 {
31 if (pid() != target()) next
32 fd = tid_fd[tid()]
33 if (! (fd in file_desc)) next
34
35 if (retval < 0)
36 commit(file_desc[fd])
37 else
38 discard(file_desc[fd])
39 delete file_desc[fd]
40 }
41
42 probe syscall.read, syscall.write
43 {
44 if (pid() != target()) next
45 tid_fd[tid()] = fd
46 tid_buf[tid()] = buf_uaddr
47 tid_count[tid()] = count
48 }
49
50 probe syscall.read.return {
51 if (pid() != target()) next
52 if (! (tid_fd[tid()] in file_desc)) next
53
54 speculate(file_desc[tid_fd[tid()]], sprintf("read(%d, %p, %d) = %d\n",
55 tid_fd[tid()], tid_buf[tid()], tid_count[tid()], retval))
56 if (retval < 0) commit(file_desc[tid_fd[tid()]])
57 }
58
59 probe syscall.write.return {
60 if (pid() != target()) next
61 if (! (tid_fd[tid()] in file_desc)) next
62
63 speculate(file_desc[tid_fd[pid()]], sprintf("write(%d, %p, %d) = %d\n",
64 tid_fd[tid()], tid_buf[tid()], tid_count[tid()], retval))
65 if (retval < 0) commit(file_desc[tid_fd[tid()]])
66 }