+#-------------------------------------------------------------------------------
+# elftools
+#
+# Eli Bendersky (eliben@gmail.com)
+# This code is in the public domain
+#-------------------------------------------------------------------------------
 __version__ = '0.21'
 
 
 
-# http://code.activestate.com/recipes/576693/ (r9)\r
-#      Created by Raymond Hettinger on Wed, 18 Mar 2009 (MIT) \r
+#-------------------------------------------------------------------------------\r
+# elftools: port of OrderedDict to work on Python < 2.7\r
 #\r
-# Backport of OrderedDict() class that runs on Python 2.4, 2.5, 2.6, 2.7 \r
-# and pypy.\r
-# Passes Python2.7's test suite and incorporates all the latest updates.\r
-#\r
-\r
+# Taken from http://code.activestate.com/recipes/576693/ , revision 9\r
+# Code by Raymond Hettinger. License: MIT\r
+#-------------------------------------------------------------------------------\r
 try:\r
     from thread import get_ident as _get_ident\r
 except ImportError:\r
 
 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.
             '--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)))
             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
             if not filter_out:
                 if not line.startswith('unknown: length'):
                     yield line
-        
+
     lines1 = prepare_lines(s1)
     lines2 = prepare_lines(s2)
 
             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]] == '@'):
             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
     for filename in filenames:
         if success:
             success = success and run_test_on_file(
-                                    filename, 
+                                    filename,
                                     verbose=options.verbose)
 
     if success:
 
+#-------------------------------------------------------------------------------
+# elftools tests
+#
+# Eli Bendersky (eliben@gmail.com)
+# This code is in the public domain
+#-------------------------------------------------------------------------------
 try:
     import unittest2 as unittest
 except ImportError:
 
+#-------------------------------------------------------------------------------
+# elftools tests
+#
+# Eli Bendersky (eliben@gmail.com)
+# This code is in the public domain
+#-------------------------------------------------------------------------------
 try:
     import unittest2 as unittest
 except ImportError:
         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()
             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)
         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
 
         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'))
 
 
 
+#-------------------------------------------------------------------------------
+# elftools tests
+#
+# Eli Bendersky (eliben@gmail.com)
+# This code is in the public domain
+#-------------------------------------------------------------------------------
 try:
     import unittest2 as unittest
 except ImportError:
         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(),
 
+#-------------------------------------------------------------------------------
+# elftools tests
+#
+# Eli Bendersky (eliben@gmail.com)
+# This code is in the public domain
+#-------------------------------------------------------------------------------
 try:
     import unittest2 as unittest
 except ImportError:
             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
 
         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()
 
+#-------------------------------------------------------------------------------
+# elftools tests
+#
+# Eli Bendersky (eliben@gmail.com)
+# This code is in the public domain
+#-------------------------------------------------------------------------------
 try:
     import unittest2 as unittest
 except ImportError:
             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
 
+#-------------------------------------------------------------------------------
+# elftools tests
+#
+# Eli Bendersky (eliben@gmail.com)
+# This code is in the public domain
+#-------------------------------------------------------------------------------
 try:
     import unittest2 as unittest
 except ImportError:
 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')
 
+#-------------------------------------------------------------------------------
+# elftools
+#
+# Eli Bendersky (eliben@gmail.com)
+# This code is in the public domain
+#-------------------------------------------------------------------------------
+
 # Just a script for playing around with pyelftools during testing
 # please ignore it!
 #