Package: valgrind
Version: 1:3.4.1-1
Severity: wishlist
Tags: patch

valgrind has a lot of options. Remember all of them can be difficult.
And type completely all of them is such a pain. Provide a good
completion for the valgrind bash line could be a good improvement.

I include a script with this bug report. This script provides:
 - a completion of ~ 70% of the options.
 - a completion for the tools. i.e. typing --tool=<TAB> list all the
    tools present in /usr/lib/valgrind/x86-linux
 - once a tool is selected, e.g. --tool=cachegrind, options like "--I1=
    --D1= --L2= " now appear
 - the "yes no" options are completed
 - --log-file= is completed by listing the directory

Actually, I think the script covers 70% of the options. It should be
completed, adding the missing options, maybe providing more precise
completion for some options. Furthermore, the packager should specify the
directory in the script where the tools are searched (I think it depends
of the platform) => /usr/lib/valgrind/x86-linux

However, this script seems to be a good skeleton to implement a good
completion.

-- System Information:
Debian Release: squeeze/sid
  APT prefers testing
  APT policy: (900, 'testing'), (800, 'stable'), (700, 'unstable'), (600, 
'experimental')
Architecture: i386 (i686)

Kernel: Linux 2.6.26-2-686 (SMP w/2 CPU cores)
Locale: LANG=en_US.UTF-8, LC_CTYPE=fr_FR.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash

Versions of packages valgrind depends on:
ii  libc6                         2.9-12     GNU C Library: Shared libraries

Versions of packages valgrind recommends:
ii  gdb                           6.8-3      The GNU Debugger

Versions of packages valgrind suggests:
pn  alleyoop                      <none>     (no description available)
ii  kcachegrind                   4:4.2.4-1  visualisation tool for the Valgrin
ii  libc6-dbg                     2.9-12     GNU C Library: detached debugging 

-- no debconf information
have valgrind &&
_valgrind()
{
    local cur prev opts yesno tools choosen_tool
    
# list of options with yes|no answer
    yesno="--trace-children\= --child-silent-after-fork\= --track-fds\= 
--time-stamp\= --log-fd\=  --log-socket\="

    opts="--tool\= "
    opts+="-h --help --help-debug --version -q --quiet -v --verbose 
--log-file\= "


    COMPREPLY=()

# we check if a tool has been defined 
    for (( i=0; i < ${#comp_wor...@]}-1; i++ )); do
      if [[ ${COMP_WORDS[i]} == "--tool" ]]; then
          choosen_tool=${COMP_WORDS[i+2]}
      fi
    done
# if so, we add its options for the completion
    case $choosen_tool in
      'callgrind')
        opts+="--callgrind-out-file\= --dump-every-bb\= --dump-before\= 
--zero-before\= --dump-after\= --toggle-collect\= --separate-recs\= 
--separate-callers\= --fn-skip\= --fn-group< --separate-recs< 
--separate-callers< "
        yesno+="--dump-instr\= --dump-line\= --compress-strings\= 
--compress-pos\= --combine-dumps\= --instr-atstart\= --collect-atstart\= 
--collect-jumps\= --separate-threads\= --skip-plt\= --simulate-cache\= 
--simulate-hwpref\= "
        ;; 
      'cachegrind')
        opts+="--I1\= --D1\= --L2\= --cachegrind-out-file\= "
        yesno+="--cache-sim\= --branch-sim\= "
        ;;
# as memcheck is the tool by default, we show its options if no tool is 
specified
      'memcheck')
          yesno+="--undef-value-errors\= --track-origins\= --show-reachable\= 
--workaround-gcc296-bugs\= --partial-loads-ok\= "
          opts+="--leak-check\= --leak-resolution\= --freelist-vol\= 
--malloc-fill\= --free-fill\= "
       ;;
      *)
          yesno+="--undef-value-errors\= --track-origins\= --show-reachable\= 
--workaround-gcc296-bugs\= --partial-loads-ok\= "
          opts+="--leak-check\= --leak-resolution\= --freelist-vol\= 
--malloc-fill\= --free-fill\= "
      ;;
    esac
    
    opts+="$yesno "

    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD - 1]}"
# COMPREPLY considers '=' as a word. For $prev we prefer the word before the 
actual "="
    if [[ "$prev" == "=" ]]
    then
        prev="${COMP_WORDS[COMP_CWORD - 2]}"
    elif [[ "$cur" == "=" ]]
    then
        cur=""
    fi


# autocompletion for the tool names, e.g. memcheck, callgrind
    if [[ "$prev" == "--tool" ]]
    then
# the list is automatically built 
# it is composed of all the executable file in
# /usr/lib/valgrind/x86-linux
# TODO: correct the path during the installation, according to the platform
            tools=`find /usr/lib/valgrind/x86-linux -executable -type f -exec 
basename {} \; | sed -e 's,\./,,g' | tr '\n' ' '`
            COMPREPLY=( $(compgen -W "$tools" -- $cur ) )
            COMPREPLY+=" "
            return 0
    fi

    if [[ "${yesno}" == *$prev* ]] 
    then
        COMPREPLY=( $(compgen -W "yes no" -- $cur ) )
        COMPREPLY+=" "
        return 0
    fi

    case "$prev" in
        --log-file)
            _filedir
            return 0
            ;;
        *)
            ;;
    esac
 
# Look for options without an argument.
    if [[ "$cur" == -* ]]
    then
        COMPREPLY=( $(compgen -W "$opts" -- $cur) )
        return 0
    else
        _filedir
        return 0
    fi
}
complete -o nospace -F _valgrind valgrind

Reply via email to