factor/extra/elf/nm/nm.factor

25 lines
710 B
Factor
Raw Permalink Normal View History

2010-04-12 22:10:20 -04:00
! Copyright (C) 2010 Erik Charlebois.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors combinators elf formatting io.mmap kernel sequences ;
IN: elf.nm
: print-symbol ( sections symbol -- )
[ sym>> st_value>> "%016x " printf ]
2010-04-12 22:10:20 -04:00
[
sym>> st_shndx>>
{
{ SHN_UNDEF [ drop "undefined" ] }
{ SHN_ABS [ drop "absolute" ] }
{ SHN_COMMON [ drop "common" ] }
[ swap nth name>> ]
} case "%-16s " printf
]
[ name>> "%s\n" printf ] tri ;
: elf-nm ( path -- )
2010-04-12 22:10:20 -04:00
[
2010-04-13 00:23:26 -04:00
sections dup ".symtab" find-section
symbols [ name>> empty? ] reject
2010-04-12 22:10:20 -04:00
[ print-symbol ] with each
2010-04-13 00:23:26 -04:00
] with-mapped-elf ;