]> gitweb.factorcode.org Git - factor.git/blob - extra/elf/nm/nm.factor
52e1c66902e3c7f1d87d46a914cb0803bb0f4cca
[factor.git] / extra / elf / nm / nm.factor
1 ! Copyright (C) 2010 Erik Charlebois.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors combinators elf formatting io.mmap kernel sequences ;
4 IN: elf.nm
5
6 : print-symbol ( sections symbol -- )
7     [ sym>> st_value>> "%016x " printf ]
8     [
9         sym>> st_shndx>>
10         {
11             { SHN_UNDEF [ drop "undefined" ] }
12             { SHN_ABS [ drop "absolute" ] }
13             { SHN_COMMON [ drop "common" ] }
14             [ swap nth name>> ]
15         } case "%-16s " printf
16     ]
17     [ name>> "%s\n" printf ] tri ;
18     
19 : elf-nm ( path -- )
20     [
21         sections dup ".symtab" find-section
22         symbols [ name>> empty? not ] filter
23         [ print-symbol ] with each
24     ] with-mapped-elf ;