# bash completion for valgrind(1) _valgrind() { local cur prev words cword _init_completion -n :,=_\'\" || return if [[ $DEBUG ]]; then echo -e "\n* $cword:" for (( i=0; i <= cword; i++ )); do echo "[${words[i]}]" done fi local offset i offset=0 for (( i=1; i <= cword; i++ )); do if [[ ${words[i]} != --* ]]; then offset=$i break fi done if [[ $offset -gt 0 && $offset -lt $cword ]]; then local j local cowords=( "${COMP_WORDS[@]}" ) i=0; j=0 while [[ $i -lt $offset ]]; do [[ $DEBUG ]] && echo "[$i, $j] <${#words[i]}, ${#cowords[j]}> ${words[i]} ${cowords[j]}" if [[ ${#words[i]} -lt ${#cowords[j]} ]]; then cowords[j]=${cowords[j]#"${words[i]}"} words[i]= ((i++)) [[ ${cowords[j]} ]] || ((j++)) else words[i]=${words[i]#"${cowords[j]}"} cowords[j]= ((j++)) [[ ${words[i]} ]] || ((i++)) fi done [[ $DEBUG ]] && echo -e "** new offset: $j ${COMP_WORDS[j]}" _command_offset $j return fi local split=false _split_longopt && split=true case "$prev" in ## Valgrind options ## --tool) # exp- tools are not listed COMPREPLY=( $( compgen -W 'memcheck cachegrind callgrind massif lackey helgrind drd none' -- "$cur" ) ) return ;; --trace-children|--child-silent-after-fork|--track-fds|--time-stamp|\ --xml|--demangle|--error-limit|--show-below-main|--db-attach|--dsymutil|\ --read-var-info|--vgdb-shadow-registers|--run-libc-freeres|--show-emwarns) COMPREPLY=( $( compgen -W 'yes no' -- "$cur" ) ) return ;; --vgdb) COMPREPLY=( $( compgen -W 'yes no full' -- "$cur" ) ) return ;; --gen-suppressions) COMPREPLY=( $( compgen -W 'yes no all' -- "$cur" ) ) return ;; --smc-check) COMPREPLY=( $( compgen -W 'none stack all all-non-file' -- "$cur") ) return ;; --log-fd|--xml-fd|--input-fd|--num-callers|--max-stackframe|\ --main-stacksize|--alignment|--vgdb-poll|--vgdb-error|--error-exitcode) # expect number COMPREPLY=( $(compgen -W '{0..9}') ) compopt -o nospace return ;; --sim-hints) COMPREPLY=( $( compgen -W 'lax-ioctls enable-outer fuse-compatible'\ -- "$cur") ) return ;; --log-file|--xml-file|--suppressions|--vgdb-prefix) _filedir return ;; --log-socket|--xml-socket) # expect ipaddr:port (host names are not supported) # FIXME return ;; --trace-children-skip|--trace-children-skip-by-arg|--xml-user-comment|\ --db-command|--fullpath-after|--kernel-variant|--require-text-symbol) # argument required but no completions available return ;; ## Cachegrind options ## --cache-sim|--branch-sim) COMPREPLY=( $( compgen -W 'yes no' -- "$cur" ) ) return ;; --cachegrind-out-file) _filedir return ;; --I1|--D1|--LL) # argument required but no completions available return ;; ## Callgrind options ## --dump-line|--dump-instr|--compress-strings|--compress-pos|\ --combine-dumps|--instr-atstart|--collect-atstart|--collect-jumps|\ --collect-bus|--collect-systime|--separate-threads|--skip-plt|\ --skip-direct-rec|--branch-sim|--cache-sim|--simulate-wb|\ --simulate-hwpref|--cacheuse) COMPREPLY=( $( compgen -W 'yes no' -- "$cur" ) ) return ;; --callgrind-out-file) _filedir return ;; --dump-every-bb|--separate-callers|--separate-recs) # expect number COMPREPLY=( $(compgen -W '{0..9}') ) compopt -o nospace return ;; --dump-before|--zero-before|--dump-after|--toggle-collect|\ --separate-callers[:digit:]|--separate-recs[:digit:]|--fn-skip|\ --I1|--D1|--LL) # argument required but no completions available return ;; ## DRD ## --check-stack-var|--first-race-only|--free-is-write|\ --report-signal-unlocked|--segment-merging|--show-confl-seg|\ --show-stack-usage|--trace-alloc|--trace-barrier|--trace-cond|\ --trace-fork-join|--trace-hb|--trace-mutex|--trace-rwlock|\ --trace-semaphore) COMPREPLY=( $( compgen -W 'yes no' -- "$cur" ) ) return ;; --exclusive-threshold|--join-list-vol|--segment-merging-interval|\ --shared-threshold) # expect number COMPREPLY=( $(compgen -W '{0..9}') ) compopt -o nospace return ;; --trace-addr) # argument required but no completions available return ;; ## Helgrind options ## --free-is-write|--track-lockorders|--check-stack-refs) COMPREPLY=( $( compgen -W 'yes no' -- "$cur" ) ) return ;; --history-level) COMPREPLY=( $( compgen -W 'none approx full' -- "$cur" ) ) return ;; --conflict-cache-size) # expect number COMPREPLY=( $(compgen -W '{0..9}') ) compopt -o nospace return ;; ## Lackey options ## --basic-counts|--detailed-counts|--trace-mem|--trace-superblocks) COMPREPLY=( $( compgen -W 'yes no' -- "$cur" ) ) return ;; --fnname) # argument required but no completions available return ;; ## Massif options ## --heap|--stacks|--pages-as-heap) COMPREPLY=( $( compgen -W 'yes no' -- "$cur" ) ) return ;; --time-unit) COMPREPLY=( $( compgen -W 'i ms B' -- "$cur" ) ) return ;; --heap-admin|--depth|--detailed-freq|--max-snapshots) # expect number COMPREPLY=( $(compgen -W '{0..9}') ) compopt -o nospace return ;; --threshold|--peak-inaccuracy) # expect f.f if [[ $cur && "$cur" != *.* ]]; then COMPREPLY=( . ) fi COMPREPLY+=( $(compgen -W "{0..9}") ) compopt -o nospace return ;; --massif-out-file) _filedir return ;; --alloc-fn|--ignore-fn) # argument required but no completions available return ;; ## Memcheck options ## --leak-check) COMPREPLY=( $( compgen -W 'no summary full' -- "$cur" ) ) return ;; --leak-resolution) COMPREPLY=( $( compgen -W 'low med high' -- "$cur" ) ) return ;; --show-reachable|--show-possibly-lost|--undef-value-errors|\ --track-origins|--partial-loads-ok|--workaround-gcc296-bugs) COMPREPLY=( $( compgen -W 'yes no' -- "$cur" ) ) return ;; --freelist-vol|--freelist-big-blocks) # expect number COMPREPLY=( $(compgen -W '{0..9}') ) compopt -o nospace return ;; --malloc-fill|--free-fill) # expect hex number if [[ $cur == 0x* ]]; then if [[ $cur == 0x??* ]]; then # 0xff is a maximum COMPREPLY=( "$cur" ) else COMPREPLY=( $(compgen -W "{0..9} {a..f}") ) compopt -o nospace fi else COMPREPLY=( $(compgen -W "{0..255}" -- "$cur") ) fi return ;; --ignore-ranges) # argument required but no completions available return ;; ## exp-bbv options ## --bb-out-file|--pc-out-file) _filedir return ;; --interval-size) # expect number COMPREPLY=( $(compgen -W '{0..9}') ) compopt -o nospace return ;; --instr-count-only) COMPREPLY=( $( compgen -W 'yes no' -- "$cur" ) ) return ;; ## exp-dhat options ## --show-top-n) # expect number COMPREPLY=( $(compgen -W '{0..9}') ) compopt -o nospace return ;; --sort-by) COMPREPLY=( $( compgen -W 'max-bytes-live tot-bytes-allocd max-blocks-live' -- "$cur" ) ) return ;; ## exp-sgcheck options ## --partial-loads-ok|--enable-sg-checks) COMPREPLY=( $( compgen -W 'yes no' -- "$cur" ) ) return ;; esac $split && return if [[ $cur == -* ]]; then local tool= # search for tool for (( i=${#words[@]}-1; i>0; i-- )); do # valgrind can't handle --tool TOOL, only --tool=TOOL if [[ ${words[i]} == --tool=* ]]; then tool="${words[i]}" break fi done # FIXME --help or --help-debug ? COMPREPLY=( $( compgen -W \ '$( _parse_help "$1" "$tool --help" )' -- "$cur" ) ) [[ $COMPREPLY == *= ]] && compopt -o nospace [[ $COMPREPLY ]] && return fi local IFS=$'\n' compopt -o filenames COMPREPLY=( $( compgen -d -c -- "$cur" ) ) } && complete -F _valgrind valgrind # ex: ts=4 sw=4 et filetype=sh