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=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 17736 invoked from network); 23 Mar 2021 22:43:31 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 23 Mar 2021 22:43:31 -0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20200801; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Message-ID:Date:Content-ID: Content-Type:MIME-Version:Subject:To:From:Reply-To:Cc: Content-Transfer-Encoding:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References; bh=/spJrc7JDxLC/0bpFjVqt3VB4ZMnc6n2QipUcFzgE40=; b=URi9BEETGT6U0WyAAlik4IOMm6 7pk0HMNAM5LFdXTUjxi2wIRb+Vl81fHAUvcc7fgmmz1GJlAHzKqVlpWrZOxfetHnaW57pncIyDGdz n5heOd04xjaLWDml83qABiEhTlg4feLirjfoxsmCPJC/g7ndT2lpPJMrlpBzfkEJdlEWdSLwhptDF xCbGoT3Nj+RZh4tZaqkezxL92/ZzlyEabu/PVMaskJ+VSyClxrlBeB5pOsB2sl6gQ0ihmR/qTgqMj 3MMlXF6wMJrner5/gozjhWUjVRQF+dDXpLCHkI3gVDeN61+tToc4SkYjzTB9MKgmvcTBjr1qa9c8T YfMi8ZPg==; Received: from authenticated user by zero.zsh.org with local id 1lOpkG-000JVm-HE; Tue, 23 Mar 2021 22:43:28 +0000 Received: from authenticated user by zero.zsh.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1lOpk1-000JND-Sx; Tue, 23 Mar 2021 22:43:14 +0000 Received: from [192.168.178.21] (helo=hydra) by mail.kiddle.eu with esmtp(Exim 4.93.0.4) (envelope-from ) id 1lOpk0-0009Hv-7P for zsh-workers@zsh.org; Tue, 23 Mar 2021 23:43:12 +0100 From: Oliver Kiddle To: Zsh workers Subject: PATCH: complete probes for dtrace completion MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <35705.1616539392.1@hydra> Date: Tue, 23 Mar 2021 23:43:12 +0100 Message-ID: <35706-1616539392.227174@49wn.5333.Rj93> X-Seq: 48230 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: Archived-At: This adds completion of dtrace probes with the -P -m -f and -n options. Runtime options with the -x option are also now completed. Aside from runtime options, the main options don't appear to have changed. I lack proper access to macOS but managed to ascertain that dtrace -l there lists some functions where the names contain colons, spaces and square brackets. The names look like Objective C stuff and are perhaps just unmangled forms. I have no idea how these might be specified or used but for the purposes of the completion, I have simply filtered them out. Separating the four fields in the output is tricky enough anyway - the module and function fields can be blank and column alignment can't be relied upon. runtime options (-x) may also differ on macOS. The probes could also be completed for -c but that has a somewhat different form with all four fields being specified, wildcards being allowed and is followed by a full D script. Oliver diff --git a/Completion/Solaris/Command/_dtrace b/Completion/Solaris/Command/_dtrace index a095589eb..bb5193163 100644 --- a/Completion/Solaris/Command/_dtrace +++ b/Completion/Solaris/Command/_dtrace @@ -1,41 +1,99 @@ #compdef dtrace -# Synced with Nevada build 160 man pages -_dtrace() { - _arguments -s \ - '-32[generate 32-bit D programs and ELF files]' \ - '-64[generate 64-bit D programs and ELF files]' \ - '-a[claim anonymous tracing state]' \ - '-A[generate driver.conf(4) directives for anonymous tracing]' \ - '-b[set trace buffer size]' \ - '-c[run specified command and exit upon its completion]' \ - '-C[run cpp(1) preprocessor on script files]' \ - '-D[define symbol when invoking preprocessor]' \ - '-e[exit after compiling request but prior to enabling probes]' \ - '-f[enable or list probes matching the specified function name]:function: ' \ - '-F[coalesce trace output by function]' \ - '-G[generate an ELF file containing embedded dtrace program]' \ - '-H[print included files when invoking preprocessor]' \ - '-h[Generate a header file]' \ - '-i[enable or list probes matching the specified probe id]' \ - '-I[add include directory to preprocessor search path]:include dir:_files -/' \ - '-L[Add directory to search path for DTrace libraries]:lib dir:_files -/' \ - '-l[list probes matching specified criteria]' \ - '-m[enable or list probes matching the specified module name]:module: ' \ - '-n[enable or list probes matching the specified probe name]:name: ' \ - '-o[set output file]:output file:_files' \ - '-p[grab specified process-ID and cache its symbol tables]:pid:_pids' \ - '-P[enable or list probes matching the specified provider name]:provider: ' \ - '-q[set quiet mode (only output explicitly traced data)]' \ - '-s[enable or list probes according to the specified D script]' \ - '-S[print D compiler intermediate code]' \ - '-U[undefine symbol when invoking preprocessor]' \ - '-v[set verbose mode (report program stability attributes)]' \ - '-V[report DTrace API version]' \ - '-w[permit destructive actions]' \ - '-x[enable or modify compiler and tracing options]' \ - '-X[specify ISO C conformance settings for preprocessor]:ISO C conformance:((a\:"ISO plus K&R extensions (default)" c\:"Strictly conformant ISO C" s\:"K&R C only" t\:"ISO plus K&R extensions"))' \ - '-Z[permit probe descriptions that match zero probes]' -} +local curcontext="$curcontext" ret=1 +local -a state line args -_dtrace "$@" +case $OSTYPE in + ^darwin*) + args=( + '-32[generate 32-bit D programs and ELF files]' + '-64[generate 64-bit D programs and ELF files]' + '(-A -h -l -V)-G[generate an ELF file containing embedded dtrace program]' + ) + ;; + darwin*) + args=( + '*-W[wait for the named process to launch]:name' + ) + ;; +esac + +_arguments -C -s $args \ + '-a[claim anonymous tracing state]' \ + '(-G -h -l -V)-A[generate driver.conf(4) directives for anonymous tracing]' \ + '-b+[set trace buffer size]:size' \ + '*-c+[run specified command and exit upon its completion]:command' \ + '-C[run cpp(1) preprocessor on script files]' \ + '*-D+[define symbol when invoking preprocessor]:name' \ + '-e[exit after compiling request but prior to enabling probes]' \ + '-f+[enable or list probes matching the specified function name]:function:->functions' \ + '-F[coalesce trace output by function]' \ + '-H[print included files when invoking preprocessor]' \ + '(-A -G -l -V)-h[generate a header file]' \ + '*-i+[enable or list probes matching the specified probe id]:probe-id' \ + '-I+[add include directory to preprocessor search path]:path:_directories' \ + '(-A -G -h -V)-l[list probes instead of enabling them]' \ + '-L+[add directory to search path for DTrace libraries]:path:_directories' \ + '*-m+[trace or list probes matching the specified module name]:module:->modules' \ + '*-n+[trace or list probes matching the specified probe name]:name:->probes' \ + '-o+[set output file]:output file:_files' \ + '-p+[grab specified process-ID and cache its symbol tables]:pid:_pids' \ + '*-P+[trace or list probes matching the specified provider name]:provider:->providers' \ + '-q[set quiet mode (only output explicitly traced data)]' \ + '*-s+[enable or list probes according to the specified D script]:script file:_files' \ + '-S[print D compiler intermediate code]' \ + '*-U+[undefine symbol when invoking preprocessor]:name' \ + '-v[set verbose mode (report program stability attributes)]' \ + '(-A -G -h -l)-V[report DTrace API version]' \ + '-w[permit destructive actions]' \ + '*-x+[enable or modify compiler and tracing options]: : _values option + "aggrate[rate of aggregation reading]\:time" + "aggsize[aggregation buffer size]\:size" + "ustackframes[number of user stack frames]\:scalar" + "bufpolicy[specify the buffer policy for the principal buffer]\:policy\:(fill switch ring)" + "bufresize[buffer resizing policy]\:policy\:(auto manual)" + "bufsize[size of the per-CPU principal buffer]\:size" + "cleanrate[cleaning rate (hz)]\:time" + "cpu[specify the CPU on which to enable tracing]\:scalar" + "defaultargs[allow references to unspecified macro arguments]" + "destructive[allow destructive actions]" + "dynvarsize[size of the dynamic variable space]\:size" + "flowindent[turn on flow indentation]" + "grabanon[claim anonymous state]" + "jstackframes[number of default stack frames for jstack()]\:scalar" + "jstackstrsize[default string space size for jstack()]\:scalar" + "nspec[number of speculations]\:scalar" + "quiet[set quiet mode]" + "specsize[size of the speculation buffer]\:size" + "strsize[maximum size of strings]\:size" + "stackframes[maximum number of kernelspace stack frames to unwind for stack()]\:scalar" + "stackindent[whitespace characters to use when indenting stack() and ustack() output]\:scalar" + "statusrate[rate of status checking]\:time" + "switchrate[rate of buffer switching]\:time" + "ustackframes[maximum number of userspace stack frames to unwind for ustack()]\:scalar"' \ + '-X+[specify ISO C conformance settings for preprocessor]:ISO C conformance:((a\:"ISO plus K&R extensions (default)" c\:"Strictly conformant ISO C" s\:"K&R C only" t\:"ISO plus K&R extensions"))' \ + '-Z[permit probe descriptions that match zero probes]' && return + +if [[ -n $state ]]; then + local -a fields=( providers modules functions probes ) + local -a suf=( : : : ) + typeset -ga _cache_dtrace_probes + (( $#_cache_dtrace_probes )) || _cache_dtrace_probes=( + ${${${${(f)"$(_call_program dtrace-probes dtrace -l)"}[2,-1]}:#*[:[]}/(#b) #<-> #([^ ]#) #([^ ]#) #([^ ]#) ##([^ ]##)/${match[1]}:${match[3]:+$match[2]}:${match[3]:-$match[2]}:$match[4]} + ) # filtering out those containing : and [, they occur on macos but may just be unmangled forms and not directly usable + suf[${fields[(i)$state]}]=( "${compstate[quote][-1]} " ) # field matching the state gets a space suffix + while compset -P 1 '*:'; do + shift fields # each already listed field reduces one being possible + done + _tags dtrace-${^fields[1,(r)$state]} + while _tags; do + _requested dtrace-probes expl 'probe name' compadd -S "$suf[4]" - ${${(M)_cache_dtrace_probes:#((#s)|*:)${IPREFIX}[^:]#(#e)}##*:} && ret=0 + _requested dtrace-functions expl 'function' compadd -S "$suf[3]" - ${${${(M)_cache_dtrace_probes:#((#s)|*:)${IPREFIX}[^:]#:[^:]#(#e)}%:*}##*:} && ret=0 + _requested dtrace-modules expl 'module' compadd -S "$suf[2]" - ${${${(M)_cache_dtrace_probes:#((#s)|*:)${IPREFIX}[^:]#:[^:]#:[^:]#(#e)}#*:}%%:*} && ret=0 + _requested dtrace-providers expl 'provider' compadd -S "$suf[1]" - ${_cache_dtrace_probes%%:*} && ret=0 + + (( ret )) || return 0 + done +fi + +return 1