summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Martin <phy1729@gmail.com>2020-05-29 22:27:08 -0500
committerMatthew Martin <phy1729@gmail.com>2020-06-01 21:18:25 -0500
commitc479107f70d75ec4522cb9d97c2c178ead4607dd (patch)
tree3ff64e67f147265187d09f9fcd1b0486f5f6b462
parent7ec05332a281ab0229a864bb4ccc4571e4f8ca1b (diff)
downloadzsh-c479107f70d75ec4522cb9d97c2c178ead4607dd.tar.gz
zsh-c479107f70d75ec4522cb9d97c2c178ead4607dd.zip
45940: Add _kdump and _ktrace completers and supporting _ktrace_points type
-rw-r--r--ChangeLog5
-rw-r--r--Completion/BSD/Command/_kdump84
-rw-r--r--Completion/BSD/Command/_ktrace30
-rw-r--r--Completion/BSD/Type/_ktrace_points50
4 files changed, 169 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index ac6ccc445..e014a58d6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
2020-06-01 Matthew Martin <phy1729@gmail.com>
+ * 45940: Completion/BSD/Command/_kdump,
+ Completion/BSD/Command/_ktrace,
+ Completion/BSD/Type/_ktrace_points: Add _kdump and _ktrace
+ completers and supporting _ktrace_points type.
+
* 45939: Completion/Linux/Command/_ionice,
Completion/Unix/Command/_lsof, Completion/Unix/Command/_pgrep,
Completion/Unix/Command/_renice, Completion/Unix/Type/_pgids:
diff --git a/Completion/BSD/Command/_kdump b/Completion/BSD/Command/_kdump
new file mode 100644
index 000000000..669260eee
--- /dev/null
+++ b/Completion/BSD/Command/_kdump
@@ -0,0 +1,84 @@
+#compdef kdump
+
+_kdump_pid() {
+ local -a args pids
+ local -A assoc_pids
+
+ if (( $+opt_args[-f] )); then
+ args=(-f $opt_args[-f])
+ fi
+ pids=(${${${(f)"$(_call_program kdump-pids kdump $args)"}:#($'\t'| )*}## #})
+ [[ $OSTYPE == netbsd* ]] && pids=(${pids/ ##[0-9]##/})
+ pids=(${(u)${pids/ /:}%% *})
+ for 1 in $pids; do
+ local pid=${1%%:*} process=${1#*:}
+ if (( $+assoc_pids[$pid] )); then
+ assoc_pids[$pid]+=", $process"
+ else
+ assoc_pids[$pid]=$process
+ fi
+ done
+ pids=()
+ for pid procs in ${(kv)assoc_pids}; do
+ pids+=($pid:$procs)
+ done
+ _describe -t kdump-pids 'kdump pid' pids
+}
+
+local args=(
+ '-d[display numbers in decimal]'
+ '-f+[use the specified file (- for stdin)]:dump file:_files'
+ '-l[loop reading the trace file]'
+ '-m+[maximum I/O bytes to display]:max data bytes:'
+ '-n[supress ad hoc translations]'
+ '-p+[show output only for the specified pid]: :_kdump_pid'
+ '(-E -T)-R[display relative timestamps]'
+ '(-E -R )-T[display absolute timestamps]'
+ '-t[select which tracepoints to display]: :_ktrace_points'
+)
+
+case $OSTYPE; in
+ freebsd*|netbsd*)
+ args+=(
+ '(-R -T)-E[display elapsed timestamps]'
+ )
+ ;|
+ freebsd*|openbsd*)
+ args+=(
+ '-H[display thread identifiers]'
+ )
+ ;|
+ dragonfly*)
+ args+=(
+ '(-c -R)-a[display full human readable output]'
+ '-c[display the CPU the thread is running on]'
+ '-j[use a fixed format output]'
+ )
+ ;;
+ freebsd*)
+ args+=(
+ '-A[display description of the ABI of traced process]'
+ '-r[symbolically display structure members]'
+ '-S[display system call numbers]'
+ '-s[suppress display of I/O data]'
+ )
+ ;;
+ netbsd*)
+ args+=(
+ '-e[interpret system call maps using the specified emulation]:emulation:'
+ '-N[suppress system call name translation]'
+ '-X[Display GIO data in hex and ascii in groups of specified size]:size:(1 2 4 8 16)'
+ '-x[Display GIO data in hex and ascii]
+ '1:dump file:_files'
+ )
+ ;;
+ openbsd*)
+ args+=(
+ # XXX handle -TR
+ '-X[display I/O data in hex and ASCII]'
+ '-x[display I/O data in hex]'
+ )
+ ;;
+esac
+
+_arguments -s -S -A '-*' : $args
diff --git a/Completion/BSD/Command/_ktrace b/Completion/BSD/Command/_ktrace
new file mode 100644
index 000000000..13c11f15d
--- /dev/null
+++ b/Completion/BSD/Command/_ktrace
@@ -0,0 +1,30 @@
+#compdef ktrace
+
+local args=(
+ '-a[append to the trace file]'
+ '(*)-C[disable tracing on all user owned processes or all processes if executed by root]'
+ '-c[clear the trace points]'
+ '-d[trace current decendants]'
+ '-f+[log trace to specified file]:trace file:_files'
+ '(-p *)-g+[enable/disable tracing on specified process group]:pgid:_pgids'
+ '-i[inherit trace flags on future children]'
+ '(-g *)-p+[enable/disable tracing on specified PID]: :_pids'
+ '-t+[select information to include in dump]:trace string:_ktrace_points'
+ '*:: : _normal -p ktrace'
+)
+
+case $OSTYPE; in
+ openbsd*)
+ args+=(
+ '-B[process relocations immediately]'
+ )
+ ;;
+ netbsd*)
+ args+=(
+ '-n[stop tracing if writes to the trace file would block]'
+ '-s[write to the trace file with synchronized I/O]'
+ )
+ ;;
+esac
+
+_arguments -s -S -A '-*' : $args
diff --git a/Completion/BSD/Type/_ktrace_points b/Completion/BSD/Type/_ktrace_points
new file mode 100644
index 000000000..1993c8d7b
--- /dev/null
+++ b/Completion/BSD/Type/_ktrace_points
@@ -0,0 +1,50 @@
+#autoload
+
+local points=(
+ 'c[trace system calls]'
+ 'i[trace I/O]'
+ 'n[trace namei translations]'
+ 's[trace signal processing]'
+ 'u[trace user data]'
+ '+[trace the default points]'
+)
+
+case $OSTYPE in
+ dragonfly*|freebsd*|netbsd*)
+ points+=(
+ 'w[context switches]'
+ )
+ ;|
+ freebsd*|openbsd*)
+ points+=(
+ 't[trace various structures]'
+ )
+ ;|
+ freebsd*)
+ points+=(
+ 'f[trace page faults]'
+ 'p[trace capability check failures]'
+ 'y[trace sysctl(3) requests]'
+ )
+ ;;
+ netbsd*)
+ points+=(
+ 'A[trace all tracepoints]'
+ 'a[trace exec arguments]'
+ 'e[trace emulation changes]'
+ 'f[trace open file descriptors after exec]'
+ 'S[trace MIB access (sysctl)]'
+ 'v[trace exec environment]'
+ '-[do not trace following trace points]'
+ )
+ ;;
+ openbsd*)
+ points+=(
+ 'p[trace violation of pledge(2) restrictions]'
+ 'x[trace argument vector in execve(2)]'
+ 'X[trace environment in execve(2)]'
+ )
+ ;;
+easc
+
+_values -s '' 'ktrace point' $points