2 Object
, ObjectSection
, ObjectSymbol
, SectionIndex
, SectionKind
, Symbol
, SymbolKind
,
5 use std
::collections
::HashMap
;
6 use std
::{env, fs, process}
;
9 let arg_len
= env
::args().len();
11 eprintln
!("Usage: {} <file> ...", env
::args().next().unwrap());
15 for file_path
in env
::args().skip(1) {
18 println
!("{}:", file_path
);
21 let file
= match fs
::File
::open(&file_path
) {
24 println
!("Failed to open file '{}': {}", file_path
, err
,);
28 let file
= match unsafe { memmap::Mmap::map(&file) }
{
31 println
!("Failed to map file '{}': {}", file_path
, err
,);
35 let file
= match object
::File
::parse(&*file
) {
38 println
!("Failed to parse file '{}': {}", file_path
, err
);
43 let section_kinds
= file
.sections().map(|s
| (s
.index(), s
.kind())).collect();
45 println
!("Debugging symbols:");
46 for symbol
in file
.symbols() {
47 print_symbol(&symbol
, §ion_kinds
);
51 println
!("Dynamic symbols:");
52 for symbol
in file
.dynamic_symbols() {
53 print_symbol(&symbol
, §ion_kinds
);
58 fn print_symbol(symbol
: &Symbol
<'_
, '_
>, section_kinds
: &HashMap
<SectionIndex
, SectionKind
>) {
59 if let SymbolKind
::Section
| SymbolKind
::File
= symbol
.kind() {
63 let mut kind
= match symbol
.section() {
64 SymbolSection
::Unknown
| SymbolSection
::None
=> '?'
,
65 SymbolSection
::Undefined
=> 'U'
,
66 SymbolSection
::Absolute
=> 'A'
,
67 SymbolSection
::Common
=> 'C'
,
68 SymbolSection
::Section(index
) => match section_kinds
.get(&index
) {
70 | Some(SectionKind
::Unknown
)
71 | Some(SectionKind
::Other
)
72 | Some(SectionKind
::OtherString
)
73 | Some(SectionKind
::Debug
)
74 | Some(SectionKind
::Linker
)
75 | Some(SectionKind
::Note
)
76 | Some(SectionKind
::Metadata
) => '?'
,
77 Some(SectionKind
::Text
) => 't'
,
78 Some(SectionKind
::Data
) | Some(SectionKind
::Tls
) | Some(SectionKind
::TlsVariables
) => {
81 Some(SectionKind
::ReadOnlyData
) | Some(SectionKind
::ReadOnlyString
) => 'r'
,
82 Some(SectionKind
::UninitializedData
) | Some(SectionKind
::UninitializedTls
) => 'b'
,
83 Some(SectionKind
::Common
) => 'C'
,
87 if symbol
.is_global() {
88 kind
= kind
.to_ascii_uppercase();
91 if symbol
.is_undefined() {
94 print
!("{:016x} ", symbol
.address());
100 symbol
.name().unwrap_or("<unknown>"),