You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{"payload":{"allShortcutsEnabled":false,"fileTree":{"user":{"items":[{"name":"uprobe","path":"user/uprobe","contentType":"file"}],"totalCount":1},"":{"items":[{"name":"bin","path":"bin","contentType":"directory"},{"name":"deprecated","path":"deprecated","contentType":"directory"},{"name":"disk","path":"disk","contentType":"directory"},{"name":"examples","path":"examples","contentType":"directory"},{"name":"fs","path":"fs","contentType":"directory"},{"name":"kernel","path":"kernel","contentType":"directory"},{"name":"man","path":"man","contentType":"directory"},{"name":"misc","path":"misc","contentType":"directory"},{"name":"net","path":"net","contentType":"directory"},{"name":"system","path":"system","contentType":"directory"},{"name":"tools","path":"tools","contentType":"directory"},{"name":"user","path":"user","contentType":"directory"},{"name":"LICENSE","path":"LICENSE","contentType":"file"},{"name":"README.md","path":"README.md","contentType":"file"},{"name":"execsnoop","path":"execsnoop","contentType":"file"},{"name":"iolatency","path":"iolatency","contentType":"file"},{"name":"iosnoop","path":"iosnoop","contentType":"file"},{"name":"killsnoop","path":"killsnoop","contentType":"file"},{"name":"opensnoop","path":"opensnoop","contentType":"file"},{"name":"syscount","path":"syscount","contentType":"file"}],"totalCount":20}},"fileTreeProcessingTime":13.434756,"foldersToFetch":[],"incompleteFileTree":false,"repo":{"id":40962489,"defaultBranch":"master","name":"perf-tools","ownerLogin":"steafen","currentUserCanPush":false,"isFork":true,"isEmpty":false,"createdAt":"2015-08-18T09:18:11.000Z","ownerAvatar":"https://avatars.githubusercontent.com/u/4922269?v=4","public":true,"private":false,"isOrgOwned":false},"codeLineWrapEnabled":false,"symbolsExpanded":false,"treeExpanded":true,"refInfo":{"name":"master","listCacheKey":"v0:1640750189.351371","canEdit":false,"refType":"branch","currentOid":"5a2c24587b1f449e4a59c9e12c37d92bb46de1a9"},"path":"user/uprobe","currentUser":null,"blob":{"rawLines":["#!/bin/bash","#","# uprobe - trace a given uprobe definition. User-level dynamic tracing.","# Written using Linux ftrace. Experimental.","#","# This will create, trace, then destroy a given uprobe definition. See","# Documentation/trace/uprobetrace.txt in the Linux kernel source for the","# syntax of a uprobe definition, and \"uprobe -h\" for examples. With this tool,","# the probe alias is optional (it will default to something meaningful).","#","# USAGE: ./uprobe [-FhHsv] [-d secs] [-p pid] {-l target |","# uprobe_definition [filter]}","#","# Run \"uprobe -h\" for full usage.","#","# WARNING: This uses dynamic tracing of user-level functions, using some","# relatively new kernel code. I have seen this cause target processes to fail,","# either entering endless spin loops or crashing on illegal instructions. I","# believe newer kernels (post 4.0) are relatively safer, but use caution. Test","# in a lab environment, and know what you are doing, before use.","#","# Use extreme caution with the raw address mode: eg, \"p:libc:0xbf130\". uprobe","# does not check for instruction alignment, so tracing the wrong address (eg,","# mid-way through a multi-byte instruction) will corrupt the target's memory.","# Other tracers (eg, perf_events with debuginfo) check alignment.","#","# Also beware of widespread tracing that interferes with the operation of the","# system, eg, tracing libc:malloc, which by-default will trace _all_ processes.","# Test in a lab environment before use.","#","# I wrote this because I kept testing different custom uprobes at the command","# line, and wanted a way to automate the steps. For generic user-level","# tracing, use perf_events directly.","#","# REQUIREMENTS: FTRACE and UPROBE CONFIG, which you may already have on recent","# kernel versions, file(1), ldconfig(8), objdump(1), and some version of awk.","# Also, currently only executes on Linux 4.0+ (see WARNING) unless -F is used.","#","# From perf-tools: https://github.com/brendangregg/perf-tools","#","# See the uprobe(8) man page (in perf-tools) for more info.","#","# COPYRIGHT: Copyright (c) 2015 Brendan Gregg.","#","# This program is free software; you can redistribute it and/or","# modify it under the terms of the GNU General Public License","# as published by the Free Software Foundation; either version 2","# of the License, or (at your option) any later version.","#","# This program is distributed in the hope that it will be useful,","# but WITHOUT ANY WARRANTY; without even the implied warranty of","# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the","# GNU General Public License for more details.","#","# You should have received a copy of the GNU General Public License","# along with this program; if not, write to the Free Software Foundation,","# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.","#","# (http://www.gnu.org/copyleft/gpl.html)","#","# 27-Jul-2015\tBrendan Gregg\tCreated this.","","### default variables","tracing=/sys/kernel/debug/tracing","flock=/var/tmp/.ftrace-lock; wroteflock=0","opt_duration=0; duration=; opt_pid=0; pid=; opt_filter=0; filter=","opt_view=0; opt_headers=0; opt_stack=0; dmesg=2; debug=0; opt_force=0","opt_list=0; target=","PATH=$PATH:/usr/bin:/sbin\t# ensure we find objdump, ldconfig","trap ':' INT QUIT TERM PIPE HUP\t# sends execution to end tracing section","","function usage {","\tcat \u003c\u003c-END \u003e\u00262","\tUSAGE: uprobe [-FhHsv] [-d secs] [-p PID] {-l target |","\t uprobe_definition [filter]}","\t -F # force. trace despite warnings.","\t -d seconds # trace duration, and use buffers","\t -l target # list functions from this executable","\t -p PID # PID to match on events","\t -v # view format file (don't trace)","\t -H # include column headers","\t -s # show user stack traces","\t -h # this usage message","\t","\tNote that these examples may need modification to match your kernel","\tversion's function names and platform's register usage.","\t eg,","\t # trace readline() calls in all running \"bash\" executables:","\t uprobe p:bash:readline","\t # trace readline() with explicit executable path:","\t uprobe p:/bin/bash:readline","\t # trace the return of readline() with return value as a string:","\t uprobe 'r:bash:readline +0(\\$retval):string'","\t # trace sleep() calls in all running libc shared libraries:","\t uprobe p:libc:sleep","\t # trace sleep() with register %di (x86):","\t uprobe 'p:libc:sleep %di'","\t # trace this address (use caution: must be instruction aligned):","\t uprobe p:libc:0xbf130","\t # trace gettimeofday() for PID 1182 only:","\t uprobe -p 1182 p:libc:gettimeofday","\t # trace the return of fopen() only when it returns NULL:","\t uprobe 'r:libc:fopen file=\\$retval' 'file == 0'","","\tSee the man page and example file for more info.","END","\texit","}","","function warn {","\tif ! eval \"$@\"; then","\t\techo \u003e\u00262 \"WARNING: command failed \\\"$@\\\"\"","\tfi","}","","function end {","\t# disable tracing","\techo 2\u003e/dev/null","\techo \"Ending tracing...\" 2\u003e/dev/null","\tcd $tracing","\twarn \"echo 0 \u003e events/uprobes/$uname/enable\"","\tif (( opt_filter )); then","\t\twarn \"echo 0 \u003e events/uprobes/$uname/filter\"","\tfi","\twarn \"echo -:$uname \u003e\u003e uprobe_events\"","\t(( opt_stack )) \u0026\u0026 warn \"echo 0 \u003e options/userstacktrace\"","\twarn \"echo \u003e trace\"","\t(( wroteflock )) \u0026\u0026 warn \"rm $flock\"","}","","function die {","\techo \u003e\u00262 \"$@\"","\texit 1","}","","function edie {","\t# die with a quiet end()","\techo \u003e\u00262 \"$@\"","\texec \u003e/dev/null 2\u003e\u00261","\tend","\texit 1","}","","function set_path {","\tname=$1","","\tpath=$(which $name)","\tif [[ \"$path\" == \"\" ]]; then","\t\tpath=$(ldconfig -v 2\u003e/dev/null | awk -v lib=$name '","\t\t $1 ~ /:/ { sub(/:/, \"\", $1); path = $1 }","\t\t { sub(/\\..*/, \"\", $1); }","\t\t $1 == lib { print path \"/\" $3 }')","\t\tif [[ \"$path\" == \"\" ]]; then","\t\t\tdie \"ERROR: segment \\\"$name\\\" ambiguous.\" \\","\t\t\t \"Program or library? Try a full path.\"","\t\tfi","\tfi","","\tif [[ ! -x $path ]]; then","\t\tdie \"ERROR: resolved \\\"$name\\\" to \\\"$path\\\", but file missing\"","\tfi","}","","function set_addr {","\tpath=$1","\tname=$2","\tsym=$3","","\t[[ \"$path\" == \"\" ]] \u0026\u0026 die \"ERROR: missing symbol path.\"","\t[[ \"$sym\" == \"\" ]] \u0026\u0026 die \"ERROR: missing symbol for $path\"","","\taddr=$(objdump -tT $path | awk -v sym=$sym '","\t $NF == sym \u0026\u0026 $4 == \".text\" { print $1; exit }')","\t[[ \"$addr\" == \"\" ]] \u0026\u0026 die \"ERROR: missing symbol \\\"$sym\\\" in $path\"","\t(( 0x$addr == 0 )) \u0026\u0026 die \"ERROR: failed resolving \\\"$sym\\\" in $path.\" \\","\t \"Maybe it exists in a different target (eg, library)?\"","\taddr=0x$( printf \"%x\" 0x$addr )\t\t# strip leading zeros","","\ttype=$(file $path)","\tif [[ \"$type\" != *shared?object* ]]; then","\t\t# subtract the base mapping address. see Documentation/trace/","\t\t# uprobetracer.txt for background.","\t\tbase=$(objdump -x $path | awk '","\t\t $1 == \"LOAD\" \u0026\u0026 $3 ~ /^[0x]*$/ { print $5 }')","\t\t[[ \"$base\" != 0x* ]] \u0026\u0026 die \"ERROR: finding base load addr\"\\","\t\t \"for $path.\"","\t\taddr=$(( addr - base ))","\t\t(( addr \u003c 0 )) \u0026\u0026 die \"ERROR: transposed address for $sym\"\\","\t\t \"became negative: $addr\"","\t\taddr=0x$( printf \"%x\" $addr)","\tfi","}","","### process options","while getopts Fd:hHl:p:sv opt","do","\tcase $opt in","\tF)\topt_force=1 ;;","\td)\topt_duration=1; duration=$OPTARG ;;","\tp)\topt_pid=1; pid=$OPTARG ;;","\tl)\topt_list=1; target=$OPTARG ;;","\tH)\topt_headers=1 ;;","\ts)\topt_stack=1 ;;","\tv)\topt_view=1 ;;","\th|?)\tusage ;;","\tesac","done","shift $(( $OPTIND - 1 ))","uprobe=$1","shift","if (( $# )); then","\topt_filter=1","\tfilter=$1","fi","","### handle listing","[[ \"$opt_list\" == 1 \u0026\u0026 \"$uprobe\" != \"\" ]] \u0026\u0026 die \"ERROR: -l takes a target only\"","if (( opt_list )); then","\tif [[ \"$target\" != */* ]]; then","\t\tset_path $target","\t\ttarget=$path","\tfi","\tobjdump -tT $target | awk '$4 == \".text\" { print $NF }' | sort | uniq","\texit","fi","","### check kernel version","ver=$(uname -r)","maj=${ver%%.*}","if (( opt_force == 0 \u0026\u0026 $maj \u003c 4 )); then","\tcat \u003c\u003c-END \u003e\u00262","\tERROR: Kernel version \u003e= 4.0 preferred (you have $ver). Aborting.","\t","\tBackground: uprobes were first added in 3.5. I've tested them on 3.13,","\tand found them unsafe, as they can crash or lock up processes, which can","\teffectively lock up the system. On 4.0, uprobes seem much safer. You","\tcan use -F to force tracing, but you've been warned.","END","\texit","fi","","### check command dependencies","for cmd in file objdump ldconfig awk; do","\twhich $cmd \u003e /dev/null","\t(( $? != 0 )) \u0026\u0026 die \"ERROR: missing $cmd in \\$PATH. $0 needs\" \\","\t \"to use this command. Exiting.\"","done","","### option logic","[[ \"$uprobe\" == \"\" ]] \u0026\u0026 usage","(( opt_pid \u0026\u0026 opt_filter )) \u0026\u0026 die \"ERROR: use either -p or a filter.\"","(( opt_duration \u0026\u0026 opt_view )) \u0026\u0026 die \"ERROR: use either -d or -v.\"","if (( opt_pid )); then","\t# convert to filter","\topt_filter=1","\tfilter=\"common_pid == $pid\"","fi","if [[ \"$uprobe\" != p:* \u0026\u0026 \"$uprobe\" != r:* ]]; then","\techo \u003e\u00262 \"ERROR: invalid uprobe definition (should start with p: or r:)\"","\tusage","fi","#","# Parse the following:","# p:bash:readline","# p:my bash:readline","# p:bash:readline %si","# r:bash:readline $ret","# p:my bash:readline %si","# p:bash:readline si=%si","# p:my bash:readline si=%si","# r:bash:readline cmd=+0($retval):string","# ... and all of the above with /bin/bash instead of bash","# ... and all of the above with libc:sleep instead of ...","# ... and all of the above with /lib/x86_64-linux-gnu/libc.so.6:sleep ...","# ... and all of the above with symbol addresses","# ... and examples from USAGE message","# The following code is not as complicated as it looks.","#","utype=${uprobe%%:*}","urest=\"${uprobe#*:} \"","set -- $urest","if [[ $1 == *:* ]]; then","\tuname=; probe=$1; shift; uargs=\"$@\"","else","\t[[ $2 != *:* ]] \u0026\u0026 die \"ERROR: invalid probe. See usage (-h).\"","\tuname=$1; probe=$2; shift 2; uargs=\"$@\"","fi","path=$probe; path=${path%%:*}","addr=$probe; addr=${addr##*:}","","# set seg and fix path (eg, seg=bash, path=/bin/bash)","if [[ $path == */* ]]; then","\tseg=${path##*/}","\tseg=${seg%%.*}","else","\tseg=$path","\t# determine path, eg, given \"zsh\" or \"libc\"","\tset_path $path","fi","","# fix uname and addr (eg, uname=readline, addr=0x8db60)","if [[ \"$addr\" == 0x* ]]; then","\t# symbol unknown; default to seg+addr","\t[[ \"$uname\" == \"\" ]] \u0026\u0026 uname=${seg}_$addr","else","\t[[ \"$uname\" == \"\" ]] \u0026\u0026 uname=$addr","\tset_addr $path $seg $addr","fi","","# construct uprobe","uprobe=\"$utype:$uname $path:$addr\"","[[ \"$uargs\" != \"\" ]] \u0026\u0026 uprobe=\"$uprobe $uargs\"","","if (( debug )); then","\techo \"uname: \\\"$uname\\\", uprobe: \\\"$uprobe\\\"\"","fi","","### check permissions","cd $tracing || die \"ERROR: accessing tracing. Root user? Kernel has FTRACE?"," debugfs mounted? (mount -t debugfs debugfs /sys/kernel/debug)\"","","if (( !opt_view )); then","\tif (( opt_duration )); then","\t\techo \"Tracing uprobe $uname for $duration seconds (buffered)...\"","\telse","\t\techo \"Tracing uprobe $uname ($uprobe). Ctrl-C to end.\"","\tfi","fi","","### ftrace lock","[[ -e $flock ]] \u0026\u0026 die \"ERROR: ftrace may be in use by PID $(cat $flock) $flock\"","echo $$ \u003e $flock || die \"ERROR: unable to write $flock.\"","wroteflock=1","","### setup and begin tracing","echo nop \u003e current_tracer","if ! echo \"$uprobe\" \u003e\u003e uprobe_events; then","\techo \u003e\u00262 \"ERROR: adding uprobe \\\"$uprobe\\\".\"","\tif (( dmesg )); then","\t\techo \u003e\u00262 \"Last $dmesg dmesg entries (might contain reason):\"","\t\tdmesg | tail -$dmesg | sed 's/^/ /'","\tfi","\tedie \"Exiting.\"","fi","if (( opt_view )); then","\tcat events/uprobes/$uname/format","\tedie \"\"","fi","if (( opt_filter )); then","\tif ! echo \"$filter\" \u003e events/uprobes/$uname/filter; then","\t\tedie \"ERROR: setting filter or -p. Exiting.\"","\tfi","fi","if (( opt_stack )); then","\tif ! echo 1 \u003e options/userstacktrace; then","\t\tedie \"ERROR: enabling stack traces (-s). Exiting\"","\tfi","fi","if ! echo 1 \u003e events/uprobes/$uname/enable; then","\tedie \"ERROR: enabling uprobe $uname. Exiting.\"","fi","","### print trace buffer","warn \"echo \u003e trace\"","if (( opt_duration )); then","\tsleep $duration","\tif (( opt_headers )); then","\t\tcat trace","\telse","\t\tgrep -v '^#' trace","\tfi","else","\t# trace_pipe lack headers, so fetch them from trace","\t(( opt_headers )) \u0026\u0026 cat trace","\tcat trace_pipe","fi","","### end tracing","end"],"stylingDirectives":null,"colorizedLines":null,"csv":null,"csvError":null,"dependabotInfo":{"showConfigurationBanner":false,"configFilePath":null,"networkDependabotPath":"/steafen/perf-tools/network/updates","dismissConfigurationNoticePath":"/settings/dismiss-notice/dependabot_configuration_notice","configurationNoticeDismissed":null},"displayName":"uprobe","displayUrl":"https://github.com/steafen/perf-tools/blob/master/user/uprobe?raw=true","headerInfo":{"blobSize":"11.5 KB","deleteTooltip":"You must be signed in to make or propose changes","editTooltip":"You must be signed in to make or propose changes","ghDesktopPath":"https://desktop.github.com","isGitLfs":false,"onBranch":true,"shortPath":"baa11ee","siteNavLoginPath":"/login?return_to=https%3A%2F%2Fgithub.com%2Fsteafen%2Fperf-tools%2Fblob%2Fmaster%2Fuser%2Fuprobe","isCSV":false,"isRichtext":false,"toc":null,"lineInfo":{"truncatedLoc":"379","truncatedSloc":"348"},"mode":"executable file"},"image":false,"isCodeownersFile":null,"isPlain":false,"isValidLegacyIssueTemplate":false,"issueTemplate":null,"discussionTemplate":null,"language":"Shell","languageID":346,"large":false,"planSupportInfo":{"repoIsFork":null,"repoOwnedByCurrentUser":null,"requestFullPath":"/steafen/perf-tools/blob/master/user/uprobe","showFreeOrgGatedFeatureMessage":null,"showPlanSupportBanner":null,"upgradeDataAttributes":null,"upgradePath":null},"publishBannersInfo":{"dismissActionNoticePath":"/settings/dismiss-notice/publish_action_from_dockerfile","releasePath":"/steafen/perf-tools/releases/new?marketplace=true","showPublishActionBanner":false},"rawBlobUrl":"https://github.com/steafen/perf-tools/raw/refs/heads/master/user/uprobe","renderImageOrRaw":false,"richText":null,"renderedFileInfo":null,"shortPath":null,"symbolsEnabled":true,"tabSize":8,"topBannersInfo":{"overridingGlobalFundingFile":false,"globalPreferredFundingPath":null,"showInvalidCitationWarning":false,"citationHelpUrl":"https://docs.github.com/github/creating-cloning-and-archiving-repositories/creating-a-repository-on-github/about-citation-files","actionsOnboardingTip":null},"truncated":false,"viewable":true,"workflowRedirectUrl":null,"symbols":null},"copilotInfo":null,"copilotAccessAllowed":false,"modelsAccessAllowed":false,"modelsRepoIntegrationEnabled":false,"csrf_tokens":{"/steafen/perf-tools/branches":{"post":"fLK7SvXMJPDN1m7-ZiEM-rF9fHgSQSTlOMc56ddM-1dY2eocOBJwPkZ7fbki4htvN0IG2eLI06xyB_zxogPSMw"},"/repos/preferences":{"post":"Q-QgTBrqPMRtkvdKWG_TmdfxDJ79bBOYYvkGctkN2Or7fENPqlWx5Yp9H1xi5giySOVypV9WVcfj-PIbIo6rug"}}},"title":"perf-tools/user/uprobe at master · steafen/perf-tools","appPayload":{"helpUrl":"https://docs.github.com","findFileWorkerPath":"/assets-cdn/worker/find-file-worker-263cab1760dd.js","findInFileWorkerPath":"/assets-cdn/worker/find-in-file-worker-1b17b3e7786a.js","githubDevUrl":null,"enabled_features":{"code_nav_ui_events":false,"react_blob_overlay":false,"accessible_code_button":true}}}