blob: 34f4bc5dd9caef2df5593ca065fe187899a8a771 [file] [log] [blame]
Eli Benderskyc4a4c072011-09-17 15:28:28 +03001# Just a script for playing around with pyelftools during testing
2# please ignore it!
3#
4
elibenc6db4c42011-09-20 16:03:59 +03005import sys, pprint
Eli Benderskye0735d52011-09-08 20:12:44 +03006from elftools.elf.structs import ELFStructs
7from elftools.elf.elffile import ELFFile
8from elftools.elf.sections import *
9
10# read a little-endian, 64-bit file
11es = ELFStructs(True, 64)
12
eliben7f13df22011-09-26 11:17:03 +030013stream = open('tests/testfiles/exe_simple64.elf', 'rb')
Eli Benderskye0735d52011-09-08 20:12:44 +030014#stream = open('binfiles/z32.elf', 'rb')
15
16efile = ELFFile(stream)
eliben033b44f2011-09-19 15:48:39 +030017print efile.elfclass, efile.little_endian
Eli Benderskye0735d52011-09-08 20:12:44 +030018print '===> %s sections!' % efile.num_sections()
eliben54e39b22011-09-19 13:10:57 +030019
eliben033b44f2011-09-19 15:48:39 +030020print efile.has_dwarf_info()
21
elibence5ec712011-09-20 10:20:32 +030022dwarfinfo = efile.get_dwarf_info()
eliben3b9ad822011-09-22 11:46:26 +030023
eliben8eff3ee2011-10-02 09:50:37 +020024cu = dwarfinfo.get_CU(3)
eliben3b9ad822011-09-22 11:46:26 +030025print 'CU header', cu.header
eliben8eb8e7f2011-09-22 13:17:07 +030026topdie = cu.get_top_DIE()
27
eliben8eff3ee2011-10-02 09:50:37 +020028c = topdie.iter_children().next()
29
30print c
31
32print 'siblings.....'
33
34for s in c.iter_siblings():
35 print s
36
Eli Benderskyebe51162011-10-27 17:34:02 +020037from elftools.dwarf.location_expr import _DW_OP_name2opcode, _DW_OP_opcode2name
eliben8eff3ee2011-10-02 09:50:37 +020038
Eli Benderskyebe51162011-10-27 17:34:02 +020039print hex(_DW_OP_name2opcode['DW_OP_lit14'])
40print _DW_OP_opcode2name[0x0e]
eliben8eff3ee2011-10-02 09:50:37 +020041
Eli Benderskya42f82d2011-09-09 06:02:47 +030042