""" Get a RangeLists object representing the .debug_ranges section of
the DWARF data, or None if this section doesn't exist.
"""
- return RangeLists(self.debug_ranges_sec.stream, self.structs)
+ # ".debug_ranges" section is optional
+ if self.debug_ranges_sec == None:
+ return None
+ else:
+ return RangeLists(self.debug_ranges_sec.stream, self.structs)
#------ PRIVATE ------#
# The range lists are extracted by DWARFInfo from the .debug_ranges
# section, and returned here as a RangeLists object.
range_lists = dwarfinfo.range_lists()
+ if range_lists == None:
+ print(' file has no .debug_ranges section')
+ return
for CU in dwarfinfo.iter_CUs():
# DWARFInfo allows to iterate over the compile units contained in
--- /dev/null
+#-------------------------------------------------------------------------------
+# elftools tests
+#
+# Eli Bendersky (eliben@gmail.com), Santhosh Kumar Mani (santhoshmani@gmail.com)
+# This code is in the public domain
+#-------------------------------------------------------------------------------
+try:
+ import unittest2 as unittest
+except ImportError:
+ import unittest
+import os
+
+from utils import setup_syspath; setup_syspath()
+from elftools.elf.elffile import ELFFile
+
+class TestRangeLists(unittest.TestCase):
+ # Test the absence of .debug_ranges section
+ def test_range_list_absence(self):
+ with open(os.path.join('test', 'testfiles_for_unittests',
+ 'arm_with_form_indirect.elf'), 'rb') as f:
+ elffile = ELFFile(f)
+ self.assertTrue(elffile.has_dwarf_info())
+
+ dwarfinfo = elffile.get_dwarf_info()
+ self.assertEqual(dwarfinfo.range_lists(), None)
+
+ # Test the presence of .debug_ranges section
+ def test_range_list_presence(self):
+ with open(os.path.join('test', 'testfiles_for_unittests',
+ 'sample_exe64.elf'), 'rb') as f:
+ elffile = ELFFile(f)
+ self.assertTrue(elffile.has_dwarf_info())
+
+ dwarfinfo = elffile.get_dwarf_info()
+ self.assertTrue(dwarfinfo.range_lists() != None)
+
+if __name__ == '__main__':
+ unittest.main()