Skip to content

Commit

Permalink
Added license snippet to all files in the code. Whitespace cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
eliben committed Mar 23, 2013
1 parent bb03c86 commit db51f26
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 26 deletions.
6 changes: 6 additions & 0 deletions elftools/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
#-------------------------------------------------------------------------------
# elftools
#
# Eli Bendersky ([email protected])
# This code is in the public domain
#-------------------------------------------------------------------------------
__version__ = '0.21'


12 changes: 5 additions & 7 deletions elftools/common/ordereddict.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
# http://code.activestate.com/recipes/576693/ (r9)
# Created by Raymond Hettinger on Wed, 18 Mar 2009 (MIT)
#-------------------------------------------------------------------------------
# elftools: port of OrderedDict to work on Python < 2.7
#
# Backport of OrderedDict() class that runs on Python 2.4, 2.5, 2.6, 2.7
# and pypy.
# Passes Python2.7's test suite and incorporates all the latest updates.
#

# Taken from http://code.activestate.com/recipes/576693/ , revision 9
# Code by Raymond Hettinger. License: MIT
#-------------------------------------------------------------------------------
try:
from thread import get_ident as _get_ident
except ImportError:
Expand Down
18 changes: 12 additions & 6 deletions test/run_readelf_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
testlog.setLevel(logging.DEBUG)
testlog.addHandler(logging.StreamHandler(sys.stdout))

# Set the path for calling readelf. By default this is the system readelf.
#
READELF_PATH = 'readelf'
READELF_PATH = '/home/eliben/test/binutils-2.23.52/binutils/readelf'


def discover_testfiles(rootdir):
""" Discover test files in the given directory. Yield them one by one.
Expand All @@ -44,10 +49,10 @@ def run_test_on_file(filename, verbose=False):
'--debug-dump=info', '--debug-dump=decodedline',
'--debug-dump=frames', '--debug-dump=frames-interp']:
if verbose: testlog.info("..option='%s'" % option)
# stdouts will be a 2-element list: output of readelf and output
# stdouts will be a 2-element list: output of readelf and output
# of scripts/readelf.py
stdouts = []
for exe_path in ['readelf', 'scripts/readelf.py']:
for exe_path in [READELF_PATH, 'scripts/readelf.py']:
args = [option, filename]
if verbose: testlog.info("....executing: '%s %s'" % (
exe_path, ' '.join(args)))
Expand All @@ -64,6 +69,7 @@ def run_test_on_file(filename, verbose=False):
success = False
testlog.info('.......................FAIL')
testlog.info('....for option "%s"' % option)
testlog.info('....Output #1 is readelf, Output #2 is pyelftools')
testlog.info('@@ ' + errmsg)
dump_output_to_temp_files(testlog, *stdouts)
return success
Expand Down Expand Up @@ -95,7 +101,7 @@ def filter_readelf_lines(lines):
if not filter_out:
if not line.startswith('unknown: length'):
yield line

lines1 = prepare_lines(s1)
lines2 = prepare_lines(s2)

Expand All @@ -120,7 +126,7 @@ def filter_readelf_lines(lines):
sm.set_seqs(lines1[i], lines2[i])
changes = sm.get_opcodes()
if flag_after_symtable:
# Detect readelf's adding @ with lib and version after
# Detect readelf's adding @ with lib and version after
# symbol name.
if ( len(changes) == 2 and changes[1][0] == 'delete' and
lines1[i][changes[1][1]] == '@'):
Expand All @@ -134,7 +140,7 @@ def filter_readelf_lines(lines):
elif 'os/abi' in lines1[i]:
if 'unix - gnu' in lines1[i] and 'unix - linux' in lines2[i]:
ok = True
else:
else:
for s in ('t (tls)', 'l (large)'):
if s in lines1[i] or s in lines2[i]:
ok = True
Expand Down Expand Up @@ -175,7 +181,7 @@ def main():
for filename in filenames:
if success:
success = success and run_test_on_file(
filename,
filename,
verbose=options.verbose)

if success:
Expand Down
6 changes: 6 additions & 0 deletions test/test_arm_support.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
#-------------------------------------------------------------------------------
# elftools tests
#
# Eli Bendersky ([email protected])
# This code is in the public domain
#-------------------------------------------------------------------------------
try:
import unittest2 as unittest
except ImportError:
Expand Down
14 changes: 10 additions & 4 deletions test/test_callframe.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
#-------------------------------------------------------------------------------
# elftools tests
#
# Eli Bendersky ([email protected])
# This code is in the public domain
#-------------------------------------------------------------------------------
try:
import unittest2 as unittest
except ImportError:
Expand All @@ -19,7 +25,7 @@ def assertInstruction(self, instr, name, args):
self.assertIsInstance(instr, CallFrameInstruction)
self.assertEqual(instruction_name(instr.opcode), name)
self.assertEqual(instr.args, args)

def test_spec_sample_d6(self):
# D.6 sample in DWARFv3
s = BytesIO()
Expand All @@ -40,7 +46,7 @@ def test_spec_sample_d6(self):
b'\x08\x07' +
b'\x09\x08\x01' +
b'\x00' +

# then comes the FDE
b'\x28\x00\x00\x00' + # length
b'\x00\x00\x00\x00' + # CIE_pointer (to CIE at 0)
Expand Down Expand Up @@ -125,7 +131,7 @@ def test_spec_sample_d6(self):
self.assertEqual(decoded_FDE.table[9]['pc'], 0x11223344 + 76)

def test_describe_CFI_instructions(self):
# The data here represents a single CIE
# The data here represents a single CIE
data = (b'' +
b'\x16\x00\x00\x00' + # length
b'\xff\xff\xff\xff' + # CIE_id
Expand All @@ -141,7 +147,7 @@ def test_describe_CFI_instructions(self):

set_global_machine_arch('x86')
self.assertEqual(describe_CFI_instructions(entries[0]),
( ' DW_CFA_def_cfa: r7 (edi) ofs 2\n' +
( ' DW_CFA_def_cfa: r7 (edi) ofs 2\n' +
' DW_CFA_expression: r2 (edx) (DW_OP_addr: 201; DW_OP_deref; DW_OP_deref)\n'))


Expand Down
10 changes: 8 additions & 2 deletions test/test_dwarf_expr.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
#-------------------------------------------------------------------------------
# elftools tests
#
# Eli Bendersky ([email protected])
# This code is in the public domain
#-------------------------------------------------------------------------------
try:
import unittest2 as unittest
except ImportError:
Expand All @@ -23,12 +29,12 @@ def test_basic_single(self):
self.visitor.process_expr([0x1b])
self.assertEqual(self.visitor.get_str(),
'DW_OP_div')

self.setUp()
self.visitor.process_expr([0x74, 0x82, 0x01])
self.assertEqual(self.visitor.get_str(),
'DW_OP_breg4 (rsi): 130')

self.setUp()
self.visitor.process_expr([0x91, 0x82, 0x01])
self.assertEqual(self.visitor.get_str(),
Expand Down
14 changes: 10 additions & 4 deletions test/test_dwarf_lineprogram.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
#-------------------------------------------------------------------------------
# elftools tests
#
# Eli Bendersky ([email protected])
# This code is in the public domain
#-------------------------------------------------------------------------------
try:
import unittest2 as unittest
except ImportError:
Expand All @@ -24,24 +30,24 @@ def _make_program_in_stream(self, stream):
b'\x0A' + # opcode_base
b'\x00\x01\x04\x08\x0C\x01\x01\x01\x00' + # standard_opcode_lengths
# 2 dir names followed by a NULL
b'\x61\x62\x00\x70\x00\x00' +
b'\x61\x62\x00\x70\x00\x00' +
# a file entry
b'\x61\x72\x00\x0C\x0D\x0F' +
b'\x61\x72\x00\x0C\x0D\x0F' +
# and another entry
b'\x45\x50\x51\x00\x86\x12\x07\x08' +
# followed by NULL
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 iteritems(kwargs):
self.assertEqual(getattr(state, k), v)

def test_spec_sample_59(self):
# Sample in figure 59 of DWARFv3
s = BytesIO()
Expand Down
10 changes: 8 additions & 2 deletions test/test_dwarf_structs.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
#-------------------------------------------------------------------------------
# elftools tests
#
# Eli Bendersky ([email protected])
# This code is in the public domain
#-------------------------------------------------------------------------------
try:
import unittest2 as unittest
except ImportError:
Expand All @@ -20,9 +26,9 @@ def test_lineprog_header(self):
b'\x06' + # opcode_base
b'\x00\x01\x04\x08\x0C' + # standard_opcode_lengths
# 2 dir names followed by a NULL
b'\x61\x62\x00\x70\x00\x00' +
b'\x61\x62\x00\x70\x00\x00' +
# a file entry
b'\x61\x72\x00\x0C\x0D\x0F' +
b'\x61\x72\x00\x0C\x0D\x0F' +
# and another entry
b'\x45\x50\x51\x00\x86\x12\x07\x08' +
# followed by NULL
Expand Down
8 changes: 7 additions & 1 deletion test/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
#-------------------------------------------------------------------------------
# elftools tests
#
# Eli Bendersky ([email protected])
# This code is in the public domain
#-------------------------------------------------------------------------------
try:
import unittest2 as unittest
except ImportError:
Expand All @@ -14,7 +20,7 @@
class Test_parse_cstring_from_stream(unittest.TestCase):
def _make_random_bytes(self, n):
return b''.join(int2byte(randint(32, 127)) for i in range(n))

def test_small1(self):
sio = BytesIO(b'abcdefgh\x0012345')
self.assertEqual(parse_cstring_from_stream(sio), b'abcdefgh')
Expand Down
7 changes: 7 additions & 0 deletions z.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
#-------------------------------------------------------------------------------
# elftools
#
# Eli Bendersky ([email protected])
# This code is in the public domain
#-------------------------------------------------------------------------------

# Just a script for playing around with pyelftools during testing
# please ignore it!
#
Expand Down

0 comments on commit db51f26

Please sign in to comment.