-import sys, unittest
-from cStringIO import StringIO
+#-------------------------------------------------------------------------------
+# elftools tests
+#
+# Eli Bendersky (eliben@gmail.com)
+# This code is in the public domain
+#-------------------------------------------------------------------------------
+try:
+ import unittest2 as unittest
+except ImportError:
+ import unittest
-sys.path.extend(['.', '..'])
+from utils import setup_syspath; setup_syspath()
+from elftools.common.py3compat import BytesIO, iteritems
from elftools.dwarf.lineprogram import LineProgram, LineState, LineProgramEntry
from elftools.dwarf.structs import DWARFStructs
from elftools.dwarf.constants import *
"""
ds = DWARFStructs(little_endian=True, dwarf_format=32, address_size=4)
header = ds.Dwarf_lineprog_header.parse(
- '\x04\x10\x00\x00' + # initial lenght
- '\x03\x00' + # version
- '\x20\x00\x00\x00' + # header length
- '\x01\x01\x01\x0F' + # flags
- '\x0A' + # opcode_base
- '\x00\x01\x04\x08\x0C\x01\x01\x01\x00' + # standard_opcode_lengths
+ b'\x04\x10\x00\x00' + # initial lenght
+ b'\x03\x00' + # version
+ b'\x20\x00\x00\x00' + # header length
+ b'\x01\x01\x01\x0F' + # flags
+ b'\x0A' + # opcode_base
+ b'\x00\x01\x04\x08\x0C\x01\x01\x01\x00' + # standard_opcode_lengths
# 2 dir names followed by a NULL
- '\x61\x62\x00\x70\x00\x00' +
+ b'\x61\x62\x00\x70\x00\x00' +
# a file entry
- '\x61\x72\x00\x0C\x0D\x0F' +
+ b'\x61\x72\x00\x0C\x0D\x0F' +
# and another entry
- '\x45\x50\x51\x00\x86\x12\x07\x08' +
+ b'\x45\x50\x51\x00\x86\x12\x07\x08' +
# followed by NULL
- '\x00')
+ b'\x00')
lp = LineProgram(header, stream, ds, 0, len(stream.getvalue()))
return lp
-
+
def assertLineState(self, state, **kwargs):
""" Assert that the state attributes specified in kwargs have the given
values (the rest are default).
"""
- for k, v in kwargs.iteritems():
+ for k, v in iteritems(kwargs):
self.assertEqual(getattr(state, k), v)
-
+
def test_spec_sample_59(self):
# Sample in figure 59 of DWARFv3
- s = StringIO()
+ s = BytesIO()
s.write(
- '\x02\xb9\x04' +
- '\x0b' +
- '\x38' +
- '\x82' +
- '\x73' +
- '\x02\x02' +
- '\x00\x01\x01')
+ b'\x02\xb9\x04' +
+ b'\x0b' +
+ b'\x38' +
+ b'\x82' +
+ b'\x73' +
+ b'\x02\x02' +
+ b'\x00\x01\x01')
lp = self._make_program_in_stream(s)
linetable = lp.get_entries()
def test_spec_sample_60(self):
# Sample in figure 60 of DWARFv3
- s = StringIO()
+ s = BytesIO()
s.write(
- '\x09\x39\x02' +
- '\x0b' +
- '\x09\x03\x00' +
- '\x0b' +
- '\x09\x08\x00' +
- '\x0a' +
- '\x09\x07\x00' +
- '\x0a' +
- '\x09\x02\x00' +
- '\x00\x01\x01')
+ b'\x09\x39\x02' +
+ b'\x0b' +
+ b'\x09\x03\x00' +
+ b'\x0b' +
+ b'\x09\x08\x00' +
+ b'\x0a' +
+ b'\x09\x07\x00' +
+ b'\x0a' +
+ b'\x09\x02\x00' +
+ b'\x00\x01\x01')
lp = self._make_program_in_stream(s)
linetable = lp.get_entries()