From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 25472 invoked from network); 30 May 2020 03:40:10 -0000 Received: from ns1.primenet.com.au (HELO primenet.com.au) (203.24.36.2) by inbox.vuxu.org with ESMTPUTF8; 30 May 2020 03:40:10 -0000 Received: (qmail 5725 invoked by alias); 30 May 2020 03:40:03 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: List-Unsubscribe: X-Seq: 45940 Received: (qmail 2895 invoked by uid 1010); 30 May 2020 03:40:03 -0000 X-Qmail-Scanner-Diagnostics: from mail-oi1-f195.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.102.3/25821. spamassassin: 3.4.4. Clear:RC:0(209.85.167.195):SA:0(-1.8/5.0):. Processed in 0.668936 secs); 30 May 2020 03:40:03 -0000 X-Envelope-From: phy1729@gmail.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at _netblocks.google.com designates 209.85.167.195 as permitted sender) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:mail-followup-to :mime-version:content-disposition; bh=JL/FXbCy2YfSW4949zanKjRadsbq5r1qIvUnCfptqCM=; b=BDQLMMrZiBkWYMcgF7QOpL2yKZWGO05JXgrsMs2r9+huufcjKavBUkOWeJcJrV0mw2 PRJ5uo+Rk8jY2ZBnTb10J9sHK3US0FriJUuXB+hunvvZHMuloGK56cYHsYD+OcYhBtFo qBBa7d7Cho5sTwNI/SaNI8C2AVh16aYom6D+JCpspv77THAdRE0KLw6WsC4Zh06WgUGV HVkrpSRUveZjNiM5FyaouUCBCS5HvkfC9z8562oTvfTXNVq+8xWXyo8Q706VVZhQjsLg 4UmHkoO6XsQNXxXzeHE/P58ojRHYULiaewv3M5K4jyvRDDh6KSh4sK61k2421CftSlFB kHZg== X-Gm-Message-State: AOAM532pXnFu9muLdapVji17bvGzrj7sO3qe/IVJgXzfv7vjnhaOxq8D rTjOtg3oOhsguGpOLCRg+vW7A7OzBs4= X-Google-Smtp-Source: ABdhPJyU4dhj0q1i6hoaeXkNgZTZOt9q3WiM1qFno6EY0fC1YZtFFXQHLgHZMhaBkF+TiNlnKkEtqg== X-Received: by 2002:aca:488c:: with SMTP id v134mr8762742oia.103.1590809968431; Fri, 29 May 2020 20:39:28 -0700 (PDT) Date: Fri, 29 May 2020 22:39:26 -0500 From: Matthew Martin To: zsh-workers@zsh.org Subject: [PATCH 2/2] Add _kdump and _ktrace completers and supporting _ktrace_points type Message-ID: <20200530033926.GA84283@CptOrmolo.darkstar> Mail-Followup-To: zsh-workers@zsh.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline The kdump completer parses the ktrace file to show available pids and which process names were associated with that pid. If there's a better way to compute/show that I'm all ears. OpenBSD's kdump uses -R and -T for showing elapsed timestamps. Is there a way to change an option's description depending on if another option has been specified? I.e. if -T has been specified the description for -R should change from "display relative timestamps" to "display elapsed timestamps". Even without this I think it's ok to go in as is. In case anyone is very closely reviewing, while the DragonFly BSD man page claims that * is used for the default set of check points, it lies. https://github.com/DragonFlyBSD/DragonFlyBSD/blob/master/usr.bin/ktrace/subr.c#L67 --- Completion/BSD/Command/_kdump | 84 ++++++++++++++++++++++++++++++ Completion/BSD/Command/_ktrace | 30 +++++++++++ Completion/BSD/Type/_ktrace_points | 50 ++++++++++++++++++ 3 files changed, 164 insertions(+) create mode 100644 Completion/BSD/Command/_kdump create mode 100644 Completion/BSD/Command/_ktrace create mode 100644 Completion/BSD/Type/_ktrace_points 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 -- 2.26.2