1 #-------------------------------------------------------------------------------
4 # Eli Bendersky (eliben@gmail.com), Milton Miller <miltonm@us.ibm.com>
5 # This code is in the public domain
6 #-------------------------------------------------------------------------------
10 from elftools
.elf
.elffile
import ELFFile
11 from elftools
.common
.utils
import bytes2str
13 class TestCacheLUTandDIEref(unittest
.TestCase
):
14 def dprint(self
, list):
18 def oprint(self
, list):
22 def test_die_from_LUTentry(self
):
24 with
open(os
.path
.join('test', 'testfiles_for_unittests',
25 'lambda.elf'), 'rb') as f
:
27 self
.assertTrue(elffile
.has_dwarf_info())
29 dwarf
= elffile
.get_dwarf_info()
30 pt
= dwarf
.get_pubnames()
31 for (k
, v
) in pt
.items():
32 ndie
= dwarf
.get_DIE_from_lut_entry(v
)
34 if not 'DW_AT_type' in ndie
.attributes
:
36 if not 'DW_AT_name' in ndie
.attributes
:
38 name
= bytes2str(ndie
.attributes
['DW_AT_name'].value
)
42 tdie
= tdie
.get_DIE_from_attribute('DW_AT_type')
45 if isinstance(ttag
, int):
46 ttag
= 'TAG(0x%x)' % ttag
48 if 'DW_AT_name' in tdie
.attributes
:
50 tlist
.append(bytes2str(tdie
.attributes
['DW_AT_name'].value
))
51 tname
= ' '.join(tlist
)
52 line
= "%s DIE at %s is of type %s" % (
53 ndie
.tag
, ndie
.offset
, tname
)
57 self
.oprint('\n'.join(lines
))
58 self
.assertGreater(len(lines
), 1)