xref: /freebsd/cddl/usr.sbin/dwatch/libexec/rw (revision ebacd8013fe5f7fdf9f6a5b286f6680dd2891036)
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
15case "$PROFILE" in
16rw) : ${PROBE:=syscall::read:entry, syscall::write:entry} ;;
17 *) : ${PROBE:=syscall::$PROFILE:entry}
18esac
19
20############################################################ ACTIONS
21
22exec 9<<EOF
23this size_t nbytes;
24this string bufstr;
25this string flow;
26this void * buf;
27this 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}
52EOF
53ACTIONS=$( cat <&9 )
54ID=$(( $ID + 1 ))
55
56############################################################ EVENT DETAILS
57
58if [ ! "$CUSTOM_DETAILS" ]; then
59exec 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");
68EOF
69EVENT_DETAILS=$( cat <&9 )
70fi
71
72################################################################################
73# END
74################################################################################
75