Ejemplo n.º 1
0
    def setUp(self):
        # Create a configuration
        self.config = Config.Config()
        self.config["library"] = "testlib"

        # Create a basic library for testing
        self.library = Library.Library("test")

        voidType = Library.Type("void")
        intType = Library.Type("int")

        f = Library.Function("func1", voidType)
        p = Library.Parameter("parameter", intType)
        f.parameters[p.name] = p
        self.library.functions[f.name] = f

        f = Library.Function("func2", intType)
        p1 = Library.Parameter("p1", intType)
        p2 = Library.Parameter("p2", intType)
        f.parameters[p1.name] = p1
        f.parameters[p2.name] = p2
        self.library.functions[f.name] = f

        # Register some types
        self.library.typeMap["int"] = "int"
        self.library.typeMap["void"] = "void"

        # Define platform properties
        self.platform = SymbianPlatform(self.config)
Ejemplo n.º 2
0
    def testDefFile(self):
        l = Parser.parseSource(testHeader)

        # FIXME: hardcode the function pointer since we don't parse those yet
        l.functions["funcPointer"] = Library.Function("funcPointer", "void")

        for function, ordinal in Parser.parseDefFile(testDefFile):
            l.functions[function].ordinal = ordinal

        # check that all ordinals were read
        for f in l.functions.values():
            assert f.ordinal is not None

        # check overlapping ordinals in input
        try:
            Parser.parseDefFile(testBadDefFile)
            self.fail("ValueError not raised.")
        except ValueError:
            pass
Ejemplo n.º 3
0
    def loadSymbolMap(self):
        config = self.config
        lib = self.library
        demangler = Tools.SymbolDecoder(config)

        # Set default library name
        if "library" in config:
            for function in lib.functions.values():
                function.libName = config.library

        # Read in the export ordinals
        if "deffiles" in config:
            for defFile in config.deffiles:
                for function, ordinal in Parser.parseDefFile(
                        open(config.getRelativePath(defFile)).read()):
                    if function in lib.functions:
                        lib.functions[function].exportOrdinal = ordinal
                        Log.debug("%s is exported at %d" % (function, ordinal))
                    # The function was not found in the library, so let's check whether it is a C++ symbol
                    elif demangler.isMangled(function):
                        function = demangler.decode(function)
                        if function in lib.functions:
                            # Save the ordinal and mark the function as C++
                            lib.functions[function].exportOrdinal = ordinal
                            lib.functions[function].language = "c++"
                            Log.debug("%s is exported at %d" %
                                      (function, ordinal))

        # Read the link ordinals and DLL information
        if "symbol_map" in config:
            defaultLibName = None
            for fileName, libName in config.symbol_map.items():
                if fileName == "default":
                    defaultLibName = libName
                    continue

                # Is it a .DEF file
                if fileName.endswith(".def"):
                    for function, ordinal in Parser.parseDefFile(
                            open(config.getRelativePath(fileName)).read()):
                        if function in lib.functions:
                            lib.functions[function].ordinal = ordinal
                            lib.functions[function].libName = libName
                            Log.debug("%s is at %s:%d" %
                                      (function, libName, ordinal))
                        # The function was not found in the library, so let's check whether it is a C++ symbol
                        elif demangler.isMangled(function):
                            function = demangler.decode(function)
                            if function in lib.functions:
                                # Save the ordinal and mark the function as C++
                                lib.functions[function].ordinal = ordinal
                                lib.functions[function].libName = libName
                                lib.functions[function].language = "c++"
                                Log.debug("%s is at %s:%d" %
                                          (function, libName, ordinal))
                else:  # it's a header file
                    assert fileName.endswith(".h")
                    for function in lib.functions.values():
                        if function.headerName == fileName:
                            function.libName = libName
            # Generate passthrough functions for internal symbols
            if defaultLibName:
                assert self.project.platform.requireOrdinals, "Default symbol mapping can only be used in platforms that use symbol ordinals"
                assert "max_internal_ordinal" in config, "max_internal_ordinal must be defined when using a default symbol mapping"
                ordinals = range(1, int(config["max_internal_ordinal"]) + 1)
                for function in lib.functions.values():
                    if function.exportOrdinal in ordinals:
                        ordinals.remove(function.exportOrdinal)
                for ordinal in ordinals:
                    name = "_trInternal%d" % ordinal
                    f = Library.Function(name, Library.Type("void"))
                    f.language = "c"
                    f.ordinal = ordinal
                    f.exportOrdinal = ordinal
                    f.libName = defaultLibName
                    lib.functions[name] = f
                    Log.debug("%s is at %s:%d" %
                              (name, defaultLibName, ordinal))