Exemple #1
0
        public void GetAndApplyPlaceholderProperties(ulong fileBaseAddress)
        {
            long slide = (long)BASE_LOAD_ADDRESS - (long)fileBaseAddress;

            SbModule placeholderModule = CreatePlaceholderModule();

            var headerAddress = Substitute.For <SbAddress>();

            headerAddress.GetFileAddress().Returns(fileBaseAddress);

            var containerSection = Substitute.For <SbSection>();

            containerSection.GetSectionType().Returns(SectionType.Container);

            var otherModule = Substitute.For <SbModule>();

            otherModule.GetObjectFileHeaderAddress().Returns(headerAddress);
            otherModule.SetPlatformFileSpec(Arg.Any <SbFileSpec>()).Returns(true);

            PlaceholderModuleProperties properties =
                moduleUtil.GetPlaceholderProperties(placeholderModule, mockTarget);

            Assert.IsNotNull(properties);
            Assert.AreEqual(slide + (long)fileBaseAddress, properties.Slide);
            Assert.AreEqual(mockPlatformFileSpec, properties.PlatformFileSpec);

            Assert.True(
                moduleUtil.ApplyPlaceholderProperties(otherModule, properties, mockTarget));

            otherModule.Received().SetPlatformFileSpec(mockPlatformFileSpec);
            mockTarget.Received().SetModuleLoadAddress(otherModule, slide);
        }
        public void SetUp()
        {
            searchLog = new StringWriter();

            mockTarget            = Substitute.For <RemoteTarget>();
            moduleReplacedHandler = Substitute.For <EventHandler <LldbModuleReplacedEventArgs> >();

            mockModuleFileFinder = Substitute.For <IModuleFileFinder>();
            mockModuleFileFinder.FindFileAsync(BINARY_FILENAME, UUID, false, searchLog)
            .Returns(Task.FromResult(PATH_IN_STORE));

            placeholderModule = Substitute.For <SbModule>();
            placeholderModule.GetPlatformFileSpec().GetFilename().Returns(BINARY_FILENAME);
            placeholderModule.GetUUIDString().Returns(UUID.ToString());

            placeholderProperties =
                new PlaceholderModuleProperties(MODULE_SLIDE, Substitute.For <SbFileSpec>());

            mockModuleUtil = Substitute.For <ILldbModuleUtil>();
            mockModuleUtil.IsPlaceholderModule(placeholderModule).Returns(true);
            mockModuleUtil.GetPlaceholderProperties(Arg.Any <SbModule>(), Arg.Any <RemoteTarget>())
            .ReturnsForAnyArgs(placeholderProperties);
            mockModuleUtil.ApplyPlaceholderProperties(
                Arg.Any <SbModule>(), Arg.Any <PlaceholderModuleProperties>(),
                Arg.Any <RemoteTarget>())
            .ReturnsForAnyArgs(true);


            binaryLoader = new BinaryLoader(mockModuleUtil, mockModuleFileFinder,
                                            mockTarget);
            binaryLoader.LldbModuleReplaced += moduleReplacedHandler;
        }
        public virtual async Task <(SbModule, bool)> LoadBinaryAsync(
            SbModule lldbModule, TextWriter searchLog)
        {
            if (lldbModule == null)
            {
                throw new ArgumentNullException(nameof(lldbModule));
            }
            searchLog = searchLog ?? TextWriter.Null;

            if (!moduleUtil.IsPlaceholderModule(lldbModule))
            {
                return(lldbModule, true);
            }

            var binaryName = lldbModule.GetPlatformFileSpec()?.GetFilename();

            if (string.IsNullOrEmpty(binaryName))
            {
                await searchLog.WriteLineAsync(ErrorStrings.BinaryFileNameUnknown);

                Trace.WriteLine(ErrorStrings.BinaryFileNameUnknown);
                return(lldbModule, false);
            }

            var binaryPath = await moduleFileFinder.FindFileAsync(
                binaryName, new BuildId(lldbModule.GetUUIDString()), false, searchLog);

            if (binaryPath == null)
            {
                return(lldbModule, false);
            }

            PlaceholderModuleProperties properties =
                moduleUtil.GetPlaceholderProperties(lldbModule, lldbTarget);

            if (properties == null)
            {
                return(lldbModule, false);
            }
            RemoveModule(lldbModule);

            var newModule = AddModule(binaryPath, lldbModule.GetUUIDString(), searchLog);

            if (newModule == null)
            {
                return(lldbModule, false);
            }

            if (!moduleUtil.ApplyPlaceholderProperties(newModule, properties, lldbTarget))
            {
                return(lldbModule, false);
            }

            LldbModuleReplaced?.Invoke(Self,
                                       new LldbModuleReplacedEventArgs(newModule, lldbModule));

            return(newModule, true);
        }