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