File: test_dwarf_phantombytes.py

package info (click to toggle)
python-pyelftools 0.32-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, trixie
  • size: 68,964 kB
  • sloc: python: 15,903; ansic: 298; asm: 86; makefile: 24; cpp: 18; sh: 4
file content (26 lines) | stat: -rw-r--r-- 1,022 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#------------------------------------------------------------------------------
# elftools tests
#
# Seva Alekseyev (sevaa@sprynet.com)
# This code is in the public domain
#------------------------------------------------------------------------------

import unittest
import os, sys, io

from elftools.elf.elffile import ELFFile

class TestPhantomBytes(unittest.TestCase):
    # Prior to 11/17/2023, trying to get DWARF from binaries built by
    # the XC16 compiler for PIC microcontrollers would crash
    def _test_file(self, filename):
        filepath = os.path.join('test', 'testfiles_for_unittests', filename)
        with open(filepath, 'rb') as f:
            elffile = ELFFile(f)
            self.assertTrue(elffile.has_phantom_bytes())
            dwarfinfo = elffile.get_dwarf_info()
            for CU in dwarfinfo.iter_CUs():
                self.assertEqual(CU.get_top_DIE().tag, 'DW_TAG_compile_unit')
                        
    def test_main(self):
        self._test_file('dwarf_phantombytes.elf')