15bf5ca77SDevin Teske# -*- tab-width: 4 -*- ;; Emacs 25bf5ca77SDevin Teske# vi: set filetype=sh tabstop=8 shiftwidth=8 noexpandtab :: Vi/ViM 35bf5ca77SDevin Teske############################################################ IDENT(1) 45bf5ca77SDevin Teske# 55bf5ca77SDevin Teske# $Title: dwatch(8) module for read(2), write(2), or similar entry $ 65bf5ca77SDevin Teske# $Copyright: 2014-2018 Devin Teske. All rights reserved. $ 75bf5ca77SDevin Teske# 85bf5ca77SDevin Teske############################################################ DESCRIPTION 95bf5ca77SDevin Teske# 105bf5ca77SDevin Teske# Display data sent/received when read(2)/write(2) occurs 115bf5ca77SDevin Teske# 125bf5ca77SDevin Teske############################################################ PROBE 135bf5ca77SDevin Teske 145bf5ca77SDevin Teskecase "$PROFILE" in 155bf5ca77SDevin Teskerw) : ${PROBE:=syscall::read:entry, syscall::write:entry} ;; 165bf5ca77SDevin Teske *) : ${PROBE:=syscall::$PROFILE:entry} 175bf5ca77SDevin Teskeesac 185bf5ca77SDevin Teske 195bf5ca77SDevin Teske############################################################ ACTIONS 205bf5ca77SDevin Teske 215bf5ca77SDevin Teskeexec 9<<EOF 225bf5ca77SDevin Teskethis size_t nbytes; 235bf5ca77SDevin Teskethis string bufstr; 245bf5ca77SDevin Teskethis string flow; 255bf5ca77SDevin Teskethis void * buf; 265bf5ca77SDevin Teskethis void * data; 275bf5ca77SDevin Teske 285bf5ca77SDevin Teske$PROBE /* probe ID $ID */ 295bf5ca77SDevin Teske{${TRACE:+ 305bf5ca77SDevin Teske printf("<$ID>"); 315bf5ca77SDevin Teske} 325bf5ca77SDevin Teske /* 335bf5ca77SDevin Teske * R/W 345bf5ca77SDevin Teske */ 355bf5ca77SDevin Teske this->flow = probefunc == "read" ? "<-" : "->"; 365bf5ca77SDevin Teske this->buf = (void *)arg1; 375bf5ca77SDevin Teske this->nbytes = (size_t)arg2; 385bf5ca77SDevin Teske 395bf5ca77SDevin Teske /* 405bf5ca77SDevin Teske * Allocate temporary memory for, copy, and NUL-terminate the data 415bf5ca77SDevin Teske */ 425bf5ca77SDevin Teske this->data = alloca(this->nbytes + 1); 435bf5ca77SDevin Teske copyinto((uintptr_t)this->buf, this->nbytes, this->data); 445bf5ca77SDevin Teske bcopy("\0", (void *)((uintptr_t)this->data + this->nbytes), 1); 455bf5ca77SDevin Teske 465bf5ca77SDevin Teske /* 475bf5ca77SDevin Teske * Extract string from temporary memory 485bf5ca77SDevin Teske */ 495bf5ca77SDevin Teske this->bufstr = stringof(this->data); 505bf5ca77SDevin Teske} 515bf5ca77SDevin TeskeEOF 525bf5ca77SDevin TeskeACTIONS=$( cat <&9 ) 535bf5ca77SDevin TeskeID=$(( $ID + 1 )) 545bf5ca77SDevin Teske 555bf5ca77SDevin Teske############################################################ EVENT DETAILS 565bf5ca77SDevin Teske 57*a061d970SDevin Teskeif [ ! "$CUSTOM_DETAILS" ]; then 585bf5ca77SDevin Teskeexec 9<<EOF 595bf5ca77SDevin Teske /* 605bf5ca77SDevin Teske * Print read/write details 615bf5ca77SDevin Teske */ 625bf5ca77SDevin Teske printf("%s \"%s\" %d byte%s", 635bf5ca77SDevin Teske this->flow, 645bf5ca77SDevin Teske this->bufstr, 655bf5ca77SDevin Teske this->nbytes, 665bf5ca77SDevin Teske this->nbytes == 1 ? "" : "s"); 675bf5ca77SDevin TeskeEOF 685bf5ca77SDevin TeskeEVENT_DETAILS=$( cat <&9 ) 69*a061d970SDevin Teskefi 705bf5ca77SDevin Teske 715bf5ca77SDevin Teske################################################################################ 725bf5ca77SDevin Teske# END 735bf5ca77SDevin Teske################################################################################ 74