Some cleanup after the last merges.
authorEli Bendersky <eliben@gmail.com>
Tue, 3 Jun 2014 17:32:33 +0000 (10:32 -0700)
committerEli Bendersky <eliben@gmail.com>
Tue, 3 Jun 2014 17:32:33 +0000 (10:32 -0700)
elftools/elf/elffile.py
test/test_elffile.py

index 660cca9a724c754c7a4a1fb8ac82a9d6e7d19f8b..15aa07e7f95bfac4314332162b7eb14550ad591a 100644 (file)
@@ -107,15 +107,17 @@ class ELFFile(object):
         """
         for i in range(self.num_segments()):
             yield self.get_segment(i)
-    
+
     def address_offsets(self, start, size=1):
-        """ Yield a file offset for each ELF segment matching a memory region
+        """ Yield a file offset for each ELF segment containing a memory region.
+
+            A memory region is defined by the range [start...start+size). The
+            offset of the region is yielded.
         """
         end = start + size
         for seg in self.iter_segments():
             if (start >= seg['p_vaddr'] and
-                    end <= seg['p_vaddr'] + seg['p_filesz']):
-                # Region is contained completely within this segment
+                end <= seg['p_vaddr'] + seg['p_filesz']):
                 yield start - seg['p_vaddr'] + seg['p_offset']
 
     def has_dwarf_info(self):
index 662d5185ee3044a628e8c560142a3cd93f9e52c2..5c7b2b8b44e9fdb459b3b61059389e74e45a1023 100644 (file)
@@ -13,7 +13,7 @@ from utils import setup_syspath; setup_syspath()
 from elftools.elf.elffile import ELFFile
 
 class TestMap(unittest.TestCase):
-    def runTest(self):
+    def test_address_offsets(self):
         class MockELF(ELFFile):
             __init__ = object.__init__
             def iter_segments(self):
@@ -21,16 +21,16 @@ class TestMap(unittest.TestCase):
                     dict(p_vaddr=0x10200, p_filesz=0x200, p_offset=0x100),
                     dict(p_vaddr=0x10100, p_filesz=0x100, p_offset=0x400),
                 ))
-        
+
         elf = MockELF()
-        
+
         self.assertEqual(tuple(elf.address_offsets(0x10100)), (0x400,))
         self.assertEqual(tuple(elf.address_offsets(0x10120)), (0x420,))
         self.assertEqual(tuple(elf.address_offsets(0x101FF)), (0x4FF,))
         self.assertEqual(tuple(elf.address_offsets(0x10200)), (0x100,))
         self.assertEqual(tuple(elf.address_offsets(0x100FF)), ())
         self.assertEqual(tuple(elf.address_offsets(0x10400)), ())
-        
+
         self.assertEqual(
             tuple(elf.address_offsets(0x10100, 0x100)), (0x400,))
         self.assertEqual(tuple(elf.address_offsets(0x10100, 4)), (0x400,))