X-Git-Url: https://git.jankratochvil.net/?p=nethome.git;a=blobdiff_plain;f=bin%2Fptracegrep;h=b33807fe7c0b1c6bdb0e7ea48a4b7d845b285921;hp=d4180fb58c9e8ac484b9cf65621f053a4ea240c3;hb=c36d3924d6aa4ea711f344e215e2f5b8525fd0a0;hpb=151255554e1863cc8ab9812d40d42fcf4b00e393 diff --git a/bin/ptracegrep b/bin/ptracegrep index d4180fb..b33807f 100755 --- a/bin/ptracegrep +++ b/bin/ptracegrep @@ -1,8 +1,24 @@ #! /bin/sh # $Id$ -PID=$(sed -n 's/^ptrace *([^,]*, *\([0-9]*\),.*$/\1/p' "$1"|sort|uniq -c|sort -nr|head -n1|awk '{print $2}') +if [ "$1" = "-n" ];then + n=true + shift +else + n=false +fi + +if [ -n "$2" ];then + PID="$2" +else + PIDS="$(sed -n 's/^ptrace *(PTRACE_ATTACH, *\([0-9]*\),.*$/\1/p' "$1"|sort -u)" + if [ -z "$PIDS" ];then + echo >&2 "No PIDS found!" + exit 1 + fi + PID='\('"$(echo "$PIDS"|tr '\n' ','|sed -e 's/,$//' -e 's/,/\\|/g')"'\)' +fi echo >&2 "PID=$PID" grep $PID $1 \ - | grep -v '^\(\(open\|read\) *(\|ptrace *( *PTRACE_\(PEEK\|POKE\)\)' \ - | sed -e 's/\<'$PID'\>/PID/g' -e 's/0x[0-9a-f]\{5,\}/HEX/g' + | grep -v '^\(\(open\|read\|write\) *(\|ptrace *( *PTRACE_\(PEEK\|POKE\)\)' \ + | if $n;then cat;else sed -e 's/\<'$PID'\>/PID/g' -e 's/0x[0-9a-f]\{5,\}/HEX/g';fi