]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - cddl/usr.sbin/dwatch/libexec/rw
Merge ^/vendor/lvm-project/master up to its last change (upstream commit
[FreeBSD/FreeBSD.git] / cddl / usr.sbin / dwatch / libexec / rw
1 # -*- tab-width: 4 -*- ;; Emacs
2 # vi: set filetype=sh tabstop=8 shiftwidth=8 noexpandtab :: Vi/ViM
3 ############################################################ IDENT(1)
4 #
5 # $Title: dwatch(8) module for read(2), write(2), or similar entry $
6 # $Copyright: 2014-2018 Devin Teske. All rights reserved. $
7 # $FreeBSD$
8 #
9 ############################################################ DESCRIPTION
10 #
11 # Display data sent/received when read(2)/write(2) occurs
12 #
13 ############################################################ PROBE
14
15 case "$PROFILE" in
16 rw) : ${PROBE:=syscall::read:entry, syscall::write:entry} ;;
17  *) : ${PROBE:=syscall::$PROFILE:entry}
18 esac
19
20 ############################################################ ACTIONS
21
22 exec 9<<EOF
23 this size_t nbytes;
24 this string bufstr;
25 this string flow;
26 this void * buf;
27 this void * data;
28
29 $PROBE /* probe ID $ID */
30 {${TRACE:+
31         printf("<$ID>");
32 }
33         /*
34          * R/W
35          */
36         this->flow = probefunc == "read" ? "<-" : "->";
37         this->buf = (void *)arg1;
38         this->nbytes = (size_t)arg2;
39
40         /*
41          * Allocate temporary memory for, copy, and NUL-terminate the data
42          */
43         this->data = alloca(this->nbytes + 1);
44         copyinto((uintptr_t)this->buf, this->nbytes, this->data);
45         bcopy("\0", (void *)((uintptr_t)this->data + this->nbytes), 1);
46
47         /*
48          * Extract string from temporary memory
49          */
50         this->bufstr = stringof(this->data);
51 }
52 EOF
53 ACTIONS=$( cat <&9 )
54 ID=$(( $ID + 1 ))
55
56 ############################################################ EVENT DETAILS
57
58 if [ ! "$CUSTOM_DETAILS" ]; then
59 exec 9<<EOF
60         /*
61          * Print read/write details
62          */
63         printf("%s \"%s\" %d byte%s",
64                 this->flow,
65                 this->bufstr,
66                 this->nbytes,
67                 this->nbytes == 1 ? "" : "s");
68 EOF
69 EVENT_DETAILS=$( cat <&9 )
70 fi
71
72 ################################################################################
73 # END
74 ################################################################################