<commit_before>#-*- coding: utf-8 -*-

import os

from elftools.elf.elffile import ELFFile

class DwarfExtractor(object):

    def __init__(self):
        self.types_cache = dict()

    def extract(self, binary):
        protos = dict()
        with open(binary, 'rb') as f:
            elf_file = ELFFile(f)

            if not elf_file.has_dwarf_info():
                print('    File has no debug info (DWARF format expected) !')
                return

            dwarf_info = elf_file.get_dwarf_info()
            for CU in dwarf_info.iter_CUs():
                for DIE in CU.iter_DIEs():
                    self.__extract_DIE(CU, DIE, protos)

        return protos


    def __extract_DIE(self, CU, DIE, protos):
        if DIE.tag == 'DW_TAG_subprogram':
            if ('DW_AT_name' not in DIE.attributes
                    or 'DW_AT_declaration' in DIE.attributes):
                return
<commit_msg>Fix dwarf extractor without dwarf info<commit_after>#-*- coding: utf-8 -*-

import os

from elftools.elf.elffile import ELFFile

class DwarfExtractor(object):

    def __init__(self):
        self.types_cache = dict()

    def extract(self, binary):
        protos = dict()
        with open(binary, 'rb') as f:
            elf_file = ELFFile(f)

            if not elf_file.has_dwarf_info():
                print('    File has no debug info (DWARF format expected) !')
                return protos

            dwarf_info = elf_file.get_dwarf_info()
            for CU in dwarf_info.iter_CUs():
                for DIE in CU.iter_DIEs():
                    self.__extract_DIE(CU, DIE, protos)

        return protos


    def __extract_DIE(self, CU, DIE, protos):
        if DIE.tag == 'DW_TAG_subprogram':
            if ('DW_AT_name' not in DIE.attributes
                    or 'DW_AT_declaration' in DIE.attributes):
                return

{'fraction_non_alphanumeric': 0.09549356223175966, 'fraction_numerical': 0.001072961373390558, 'mean_word_length': 1.8386605783866057, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6323198', 'n_tokens_mistral': 613, 'n_tokens_neox': 574, 'n_words': 152}