about summary refs log tree commit diff
path: root/Completion/User/_gprof
blob: cbc3623317a032d33ac1c236976ba099415ba5ce (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#compdef gprof

local context state line ret=1
typeset -A opt_args

_arguments -s -{a,b,c,D,h,i,l,L,s,T,v,w,x,y,z} \
           -{A,C,e,E,f,F,J,n,N,O,p,P,q,Q,Z}:'function name:->funcs' \
	   '-I:directory:_dir_list' \
	   '-d-:debug level:' '-k:function names:->pair' \
	   '-m:minimum execution count:' \
	   ':executable:_files -g \*\(\*\)' \
	   ':profile file:_files -g gmon.\*' \
	   -- -s '(#--[no-] --)' \
           '*=name*:function name:->funcs' \
	   '*=dirs*:directory:_dir_list' && ret=0

if [[ -n "$state" ]]; then
  local cmd pair expl

  _tags "${context}" functions || return 1

  [[ "$state" = pair ]] && pair=yes

  if [[ $#line -gt 1 ]]; then
    cmd="$line[2]"
  else
    return 1
  fi

  if [[ -n "$cmd" ]]; then
    if [[ "$cmd" = /* ]]; then
      tmp="$cmd"
    else
      tmp="$PWD/$cmd"
    fi

    if [[ "$tmp" != "$_gprof_command" ]]; then
      _gprof_command="$tmp"
      _gprof_funcs=( "${(@)${(@M)${(@f)$(nm $cmd)}:#[^ ]# [tT] ([^_]|_[^_])*}##* }" )
    fi
  
    if [[ -n "$pair" ]]; then
      if compset -P '*/'; then
        _description expl 'call arc to function'
      else
        _description expl 'call arc from function'
      fi
    else
      _description expl function
    fi
    compadd "$expl[@]" -M 'r:|_=* r:|=*' - "$_gprof_funcs[@]" && ret=0
  else
    return 1
  fi
fi

return ret