1#compdef nm eu-nm
2
3local args files variant
4
5files="*:object file:_object_files"
6args=(
7  '(-A -o --print-file-name)'{-A,-o,--print-file-name}'[print name of input file on each line]'
8  '(--demangle --no-demangle)-C[decode symbol names]'
9  '(-D --dynamic)'{-D,--dynamic}'[display dynamic symbols instead of normal ones]'
10  '(-g --extern-only)'{-g,--extern-only}'[display only global symbols]'
11  '(-t --radix -o -x)'{-t,--radix}'[specify radix for numeric values]:radix:((d\:decimal o\:octal x\:hexadecimal))'
12)
13
14if _pick_variant -r variant binutils=GNU elftoolchain=elftoolchain elfutils=elfutils unix -V; then
15  args+=(
16    '(- *)--help[display help information]'
17    '(- *)'{-V,--version}'[display version information]'
18    '(-f --format -P --portability)-B[same as --format=bsd]'
19    '(-u --undefined-only)--defined-only[display only defined symbols]'
20    '(-f --format -P)--format=[specify output format]:format:(bsd sysv posix)'
21    '(-n --numeric-sort -p --no-sort --size-sort -v)'{-n,--numeric-sort}'[sort symbols numerically by address]'
22    '(-p --no-sort -n -v --numeric-sort -r --reverse-sort --size-sort)'{-p,--no-sort}'[do not sort symbols]'
23    '(-P --portability -B -f --format)'{-P,--portability}'[same as --format=posix]'
24    '(-r --reverse-sort -p --no-sort)'{-r,--reverse-sort}'[reverse sort order]'
25    '(-u --undefined-only --defined-only)'{-u,--undefined-only}'[display only undefined symbols]'
26    '(-a --debug-syms)'{-a,--debug-syms}'[display debugger-only symbols]'
27    '(-S --print-size)'{-S,--print-size}'[print size of defined symbols]'
28    '(-s --print-armap)'{-s,--print-armap}'[include index for symbols from archive members]'
29  )
30  case $variant in
31    elftoolchain|binutils)
32      args+=(
33	'(-l --line-numbers)'{-l,--line-numbers}'[display source file and line numbers from debug information]'
34	"(-C --demangle)--no-demangle[don't decode symbol names]"
35	'(-p --no-sort -n -v --numeric-sort)--size-sort[sort symbols by size]'
36	'(-n --numeric-sort -p --no-sort --size-sort)-v[sort symbols numerically by address]'
37	'(- *)-h[display help information]'
38      )
39    ;|
40    elftoolchain)
41      args=( ${args:#*(-C|-o|--portability)\[*}
42	'(-C --demangle)'{-C,--demangle=-}'[decode symbol names]::style:(auto gnu-v2 gnu-v3 arm)'
43	'(-g --extern-only)-e[only display global and static symbols]'
44	'(--format -P)-F+[specify output format]:format:(bsd sysv posix)'
45	'-o[with -P, same as -t o; otherwise same as -A]'
46	'(-t --radix)-x[print values in hexadecimal]'
47      )
48    ;;
49    elfutils)
50      args+=(
51        '--mark-special[mark special symbols]'
52	'--color=[use color in output]:color:(always auto never)'
53	'(-C)--demangle[decode symbol names]'
54	'(--format -P)-f+[specify output format]:format:(bsd sysv posix)'
55	'(- *)--usage[give a short usage message]'
56	'(- *)-\\?[display help information]'
57      )
58    ;;
59    binutils)
60      compset -P '@' && files='*:options file:_files'
61      args+=(
62        '!(--no-recurse-limit)--recurse-limit'
63        '--no-recurse-limit[disable demangling recursion limit]'
64	'(-f --format -P)-f+[specify output format]:format:(bsd sysv posix)'
65	'(-C --no-demangle)--demangle=-[decode symbol names]::style:(auto gnu lucid arm hp edg gnu-v3 java gnat rust dlang)'
66	'--plugin[load specified plugin]:plugin'
67	'--special-syms[include special symbols in the output]'
68	'--synthetic[display synthetic symbols as well]'
69	"--target=[target object format]:targets:(${${(@M)${(f)$(_call_program targets nm --help)}:#*supported targets:*}##*: })"
70	'--with-symbol-versions[display version strings after symbol names]'
71      )
72    ;;
73  esac
74else
75  case $OSTYPE in
76    (darwin*|openbsd*)
77      args=(
78	'(-A -o)'{-A,-o}'[prepend file name to each output line]'
79	'(-g)-a[display all symbols including those for debuggers]'
80	'(-a)-g[display only global symbols]'
81	'(-U)-u[display only undefined symbols]'
82	'(-p)-n[sort numerically rather than alphabetically]'
83	"(-n -r)-p[don't sort; display in symbol-table order]"
84	'(-p)-r[sort in reverse order]'
85	'(-j)-P[print information in a portable format]'
86	'(-j)-t[specify radix for numeric values (used with -P)]:radix:((d\:decimal o\:octal x\:hexadecimal))'
87      );|
88    (darwin*)
89      args+=(
90	"(-u)-U[don't display undefined symbols]"
91	'-f[display symbol table of dynamic library flat]'
92	'(-P -t -m)-j[just display symbol names (no value or type)]'
93	'-l[display .section_start if no symbol is in the section (used with -s)]'
94	'(-j)-m[use verbose format for Mach-O symbols]'
95	'-s[list only symbols in the specified section]:segment name: :section name: '
96	"-x[display symbol table entry's fields in hexadecimal]"
97	'*-arch[select architecture from universal file]:architecture:(all i386 x86_64)'
98      );;
99    (openbsd*)
100      args+=(
101	'-C[decode low-level symbol names]'
102	'-D[display dynamic symbol table instead of normal symbol table]'
103	'-e[output extended information]'
104	'-s[show archive index]'
105	'-w[warn about non-object archive members]'
106      );;
107    (solaris*)
108      args=( ${args:#(|*\)(\*|))-[o-]*}
109	"-h[don't display column headers]"
110	'-l[distinguish WEAK symbols with * character]'
111	'(-t -x)-o[print values in octal]'
112	'(-v)-n[sort symbols by name]'
113	'(-P)-p[produce parsable output]'
114	'(-p)-P[portable output format]'
115	'(-r)-R[print archive name, object file and symbol name]'
116	'-r[prepend name of input file to each symbol name]'
117	'-s[print section name instead of index]'
118	'-u[print undefined symbols only]'
119	'(-n)-v[sort external symbols by value]'
120	'-V[display version of the nm command]'
121	'(-o -t)-x[print values in hexadecimal]'
122      );;
123    (*)
124      # minimal POSIX
125      args=(
126	'-A[print name of input file on each line]'
127	'(-u)-g[display only global symbols]'
128	'-P[print information in a portable format]'
129	'-t[specify radix for numeric values]:radix:((d\:decimal o\:octal x\:hexadecimal))'
130	'(-g)-u[display only undefined symbols]'
131	'-v[sort symbols by value instead of by name]'
132      );;
133  esac
134fi
135
136_arguments -s -S : "$args[@]" $files
137