From 834379ef6381c83a51d9277617d49bc3d3b10c7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Thu, 17 Nov 2011 18:00:41 +0200 Subject: [PATCH] valgrind: New completion. --- completions/Makefile.am | 1 + completions/valgrind | 182 ++++++++++++++++++++++++++++++ test/completion/valgrind.exp | 1 + test/lib/completions/valgrind.exp | 25 ++++ 4 files changed, 209 insertions(+) create mode 100644 completions/valgrind create mode 100644 test/completion/valgrind.exp create mode 100644 test/lib/completions/valgrind.exp diff --git a/completions/Makefile.am b/completions/Makefile.am index c6ff1ec8..e2137edc 100644 --- a/completions/Makefile.am +++ b/completions/Makefile.am @@ -300,6 +300,7 @@ bashcomp_DATA = a2x \ useradd \ userdel \ usermod \ + valgrind \ vipw \ vncviewer \ vpnc \ diff --git a/completions/valgrind b/completions/valgrind new file mode 100644 index 00000000..bd1391b1 --- /dev/null +++ b/completions/valgrind @@ -0,0 +1,182 @@ +# valgrind(1) completion -*- shell-script -*- + +_valgrind() +{ + local cur prev words cword split + _init_completion -s || return + + local i + # Note: intentionally using COMP_WORDS and COMP_CWORD instead of + # words and cword here due to splitting on = causing index differences + # (_command_offset assumes the former). + for (( i=1; i <= COMP_CWORD; i++ )); do + if [[ ${COMP_WORDS[i]} != @([-=])* && ${COMP_WORDS[i-1]} != = ]]; then + _command_offset $i + return + fi + done + + case $prev in + -h|--help|--help-debug|--version|--log-fd|--log-socket|--xml-fd|\ + --xml-socket|--xml-user-comment|--num-callers|--error-exitcode|\ + --db-command|--input-fd|--max-strackframe|--main-stacksize|\ + --alignment) + return + ;; + --tool) + # Tools seem to be named e.g. like memcheck-amd64-linux from which + # we want to grab memcheck; the same dir may contain things like + # default.supp, vgpreload_*.so etc which we want to skip. + # TODO: probably needs adjustment to be more generic + COMPREPLY=( $( compgen -W "$( \ + command ls -1 /usr{,/local}/lib{,64}/valgrind 2>/dev/null | \ + sed -e '/\.so$/d' -ne 's/^\(.*\)-\([^-]*\)-\([^-]*\)/\1/p' )" \ + -- "$cur" ) ) + return + ;; + --trace-children|--child-silent-after-fork|--track-fds|--time-stamp|\ + --xml|--demangle|--error-limit|--show-below-main|--dsymutil|\ + --read-var-info|--run-libc-freeres|--show-emwarns) + COMPREPLY=( $( compgen -W 'yes no' -- "$cur" ) ) + return + ;; + --log-file|--xml-file|--suppressions|--db-attach) + _filedir + return + ;; + --gen-suppressions) + COMPREPLY=( $( compgen -W 'yes no all' -- "$cur" ) ) + return + ;; + --smc-check) + COMPREPLY=( $( compgen -W 'none stack all' -- "$cur" ) ) + return + ;; + --sim-hints) + COMPREPLY=( $( compgen -W 'lax-ioctls enable-outer' -- "$cur" ) ) + return + ;; + --kernel-variant) + COMPREPLY=( $( compgen -W 'bproc' -- "$cur" ) ) + return + ;; + # memcheck: + --leak-check) + COMPREPLY=( $( compgen -W 'no summary full' -- "$cur" ) ) + return + ;; + --leak-resolution) + COMPREPLY=( $( compgen -W 'low med high' -- "$cur" ) ) + return + ;; + --show-reachable|--undef-value-errors|--track-origins|\ + --partial-loads-ok|--workaround-gcc296-bugs) + COMPREPLY=( $( compgen -W 'yes no' -- "$cur" ) ) + return + ;; + --freelist-vol|--ignore-ranges|--malloc-fill|--free-fill) + return + ;; + # cachegrind: + --I1|--D1|--L2) + return + ;; + --cache-sim|--branch-sim) + COMPREPLY=( $( compgen -W 'yes no' -- "$cur" ) ) + return + ;; + --cachegrind-out-file) + _filedir + return + ;; + # callgrind (also --I1, --D1, and --L2 which are above in cachegrind): + --simulate-cache|--simulate-wb|--simulate-hwpref|--cacheuse) + COMPREPLY=( $( compgen -W 'yes no' -- "$cur" ) ) + return + ;; + # drd: + --trace-addr) + return + ;; + --trace-barrier|--trace-cond|--trace-fork-join|--trace-mutex|\ + --trace-rwlock|--trace-semaphore) + COMPREPLY=( $( compgen -W 'yes no' -- "$cur" ) ) + return + ;; + # exp-bbv: + --bb-out-file|--pc-out-file) + _filedir + return + ;; + --interval-size) + return + ;; + --instr-count-only) + COMPREPLY=( $( compgen -W 'yes no' -- "$cur" ) ) + return + ;; + # exp-ptrcheck (also --partial-loads-ok which is above in memcheck): + --enable-sg-checks) + COMPREPLY=( $( compgen -W 'yes no' -- "$cur" ) ) + return + ;; + # helgrind: + --track-lockorders) + COMPREPLY=( $( compgen -W 'yes no' -- "$cur" ) ) + return + ;; + --history-level) + COMPREPLY=( $( compgen -W 'none approx full' -- "$cur" ) ) + return + ;; + --conflict-cache-size) + return + ;; + # lackey: + --basic-counts|--detailed-counts|--trace-mem|--trace-superblock) + COMPREPLY=( $( compgen -W 'yes no' -- "$cur" ) ) + return + ;; + --fnname) + return + ;; + # massif: + --heap|--stacks) + COMPREPLY=( $( compgen -W 'yes no' -- "$cur" ) ) + return + ;; + --heap-admin|--depth|--alloc-fn|--ignore-fn|--threshold|\ + --peak-inaccuracy|--detailed-freq|--max-snapshots) + return + ;; + --time-unit) + COMPREPLY=( $( compgen -W 'i ms B' -- "$cur" ) ) + return + ;; + --massif-out-file) + _filedir + return + ;; + esac + + $split && return + + if [[ $cur == -* ]]; then + + local tool + for (( i=1; i < ${#words[@]}; i++ )); do + if [[ ${words[i]} == --tool=?* ]]; then + tool=${words[i]} + break + fi + done + + COMPREPLY=( $( compgen -W '$( _parse_help "$1" "--help $tool" )' \ + -- "$cur" ) ) + [[ $COMPREPLY == *= ]] && compopt -o nospace + return + fi +} && +complete -F _valgrind valgrind + +# ex: ts=4 sw=4 et filetype=sh diff --git a/test/completion/valgrind.exp b/test/completion/valgrind.exp new file mode 100644 index 00000000..aadd5a52 --- /dev/null +++ b/test/completion/valgrind.exp @@ -0,0 +1 @@ +assert_source_completions valgrind diff --git a/test/lib/completions/valgrind.exp b/test/lib/completions/valgrind.exp new file mode 100644 index 00000000..3e7799e7 --- /dev/null +++ b/test/lib/completions/valgrind.exp @@ -0,0 +1,25 @@ +proc setup {} { + save_env +} + + +proc teardown {} { + assert_env_unmodified +} + + +setup + + +# b: assuming we have at least bash that starts with b in $PATH +assert_complete_any "valgrind b" +sync_after_int + +assert_complete_any "valgrind -" +sync_after_int + +assert_complete_any "valgrind --tool=" +sync_after_int + + +teardown