コード例 #1
0
ファイル: struct_share.py プロジェクト: wangyufeng86/qcc3040
    def __init__(self, header_file, o_file, struct_filter_list):

        self.header_name = header_file
        self.object_file_path = o_file
        self.struct_filter_list = struct_filter_list

        self.library_name = os.path.split(self.object_file_path)[1].split('.')[0]

        # Import kalelfreader
        if sys.platform.startswith('linux'):
            sys.path.append(os.path.join(os.sep, 'home', 'devtools', 'kal-python-tools', 'linux',
                                         '1.1.6', 'kal_python_tools_linux64_1.1.6'))
        elif sys.platform.startswith('win'):
            sys.path.append(os.path.join(os.environ["DEVKIT_ROOT"], 'tools', 'pythontools'))
        else:
            # Unsupported OS so assert
            raise OSError
        import kalelfreader_lib_wrappers as kerlib


        # Extract from object file
        ker = kerlib.Ker()
        obj_path1 = os.path.normcase(self.object_file_path)
        self.obj_info = ker.loadelf(obj_path1)

        self.read_enum()
        self.read_struct()

        if  not self.enums and not self.structs:
            print("Warning: no enum or struct definitions in ", o_file)
        else:
            self.header_print(self.enums, self.structs)
コード例 #2
0
    def load(self, filename=""):
        """
        Parses the symbol information in the specified KLO/ELF (.klo, .elf) file and stores it
        for the other Kalimba debug functions to make use of.
        If the specified filename is a directory, that directory is searched for KLO/ELF files.
        If no KLO/ELF file is specified, we search the current directory for one.
        """
        path = os.getcwd()
        if os.path.isdir(filename):
            print "Searching", filename, "for KLO/ELF files..."
            path = filename
            filename = ""

        if filename == "":
            # The caller didn't specify a file, so lets go fishing for one
            file_list = glob(os.path.join(path, "*.klo"))
            file_list.extend(glob(os.path.join(path, "*.elf")))
            file_index = 0

            if len(file_list) == 0:
                raise IOError("No KLO/ELF files present in this directory")
            elif len(file_list) > 1:
                print "Enter the number of the KLO/ELF file to load:\n"
                for index, file in enumerate(file_list):
                    print "%s. %s" % (index + 1, file)
                print "\n? ",
                try:
                    user_input = int(sys.stdin.readline().strip())
                    file_index = user_input - 1
                    filename = file_list[file_index]  # Test validity of index
                except:
                    raise InvalidChoice
            filename = file_list[file_index]

        print "Loading", filename

        if not os.path.exists(filename):
            raise IOError("File (or path) not found '%s'" % filename)

        if filename[-4:] == ".klo":
            (self.constants, self.source_lines, self.variables, self.labels,
             self.static_dm, self.static_pm) = read_klo.load_klo_file(filename)
            self.dm_data_width = 24
            self.pm_data_width = 32
        elif filename[-4:] == ".elf" or filename[-2:] == ".o":
            ker = kalelfreader_lib_wrappers.Ker()
            (self.symfile_dsp_rev, self.constants, self.source_lines,
             self.variables, self.labels, self.static_dm, self.static_pm,
             machine_id, self.is_big_endian, self.addr_width,
             self.dm_data_width, self.pm_data_width, self.types, self.enums,
             self.loadsym_reports, self.elf_sec_headers, self.funcs,
             self.dm_octet_addressing,
             self.pm_octet_addressing) = ker.loadelf(filename)
        else:
            raise IOError(
                "Specified filename must end with .klo, .elf or .o.\n" +
                "Alternatively, just specify the directory containing the symbol file and a search will be performed."
            )

        print "Symbols loaded"
コード例 #3
0
    def get_version(self):
        """Returns a tuple containing the version of these Python tools, the version of the 
           underlying kalaccess library, and the version of the kalelfreader library."""
        our_version = "kalaccess.py - $Change: 2449179 $"

        kalaccess_version = self.get_ka_version()
        ker = kalelfreader_lib_wrappers.Ker()
        kalelfreader_version = ker.get_version()
        return (our_version, kalaccess_version, kalelfreader_version)
コード例 #4
0
    def load(self, filename=""):
        """
        Parses the symbol information in the specified KLO/ELF (.klo, .elf) file and stores it
        for the other Kalimba debug functions to make use of.
        If the specified filename is a directory, that directory is searched for KLO/ELF files.
        If no KLO/ELF file is specified, we search the current directory for one.
        """
        path = os.getcwd()
        if os.path.isdir(filename):
            print("Searching {0} for KLO/ELF files...".format(filename))
            path = filename
            filename = ""

        if filename == "":
            # The caller didn't specify a file, so lets go fishing for one
            file_list = glob(os.path.join(path, "*.klo"))
            file_list.extend(glob(os.path.join(path, "*.elf")))
            file_index = 0

            if len(file_list) == 0:
                raise IOError("No KLO/ELF files present in this directory")

            if len(file_list) > 1:
                print("Enter the number of the KLO/ELF file to load:\n")
                for index, symbol_file in enumerate(file_list):
                    print("{0}. {1}".format(index + 1, symbol_file))
                print("\n? ", end=' ')
                try:
                    user_input = int(sys.stdin.readline().strip())
                    file_index = user_input - 1
                    # noinspection PyStatementEffect
                    file_list[file_index]  # Test validity of index
                except IndexError:
                    raise InvalidChoice

            filename = file_list[file_index]

        print("Loading", filename)

        if not os.path.exists(filename):
            if sys.platform.startswith("win32"):
                esc_index = self._matches_simple_escape_sequences(filename)
                if esc_index >= 0:
                    window_start = max(esc_index - 5, 0)
                    window_end = min(esc_index + 6, len(filename))
                    raise WindowsPathError(
                        "File not found:\n  {0}\n"
                        "Likely escaped character found around '{1}'. Escape backslashes in Windows paths, use a raw "
                        "string ('r' prefix), or use forward slashes.".format(
                            filename, filename[window_start:window_end]))

            raise IOError("File not found:\n  {0}".format(filename))

        if filename[-4:] == ".klo":
            (self.constants, self.source_lines, self.variables, self.labels,
             self.static_dm, self.static_pm) = read_klo.load_klo_file(filename)
            self.dm_data_width = 24
            self.pm_data_width = 32
        elif filename[-4:] == ".elf" or filename[-2:] == ".o":
            ker = kalelfreader_lib_wrappers.Ker()
            (self.symfile_dsp_rev, self.constants, self.source_lines,
             self.variables, self.labels, self.static_dm, self.static_pm,
             machine_id, self.is_big_endian, self.addr_width,
             self.dm_data_width, self.pm_data_width, self.types, self.enums,
             self.loadsym_reports, self.elf_sec_headers, self.funcs,
             self.dm_octet_addressing, self.pm_octet_addressing,
             self.all_symbols) = ker.loadelf(filename)
        else:
            raise IOError(
                "Specified filename must end with .klo, .elf or .o.\nAlternatively, just specify the "
                "directory containing the symbol file and a search will be performed."
            )

        print("Symbols loaded")