Пример #1
0
        public async Task LoadSymbols_AlreadyLoadedAsync()
        {
            var mockModule = Substitute.For <SbModule>();

            mockModuleUtil.HasSymbolsLoaded(mockModule).Returns(true);

            Assert.IsTrue(await symbolLoader.LoadSymbolsAsync(mockModule, searchLog, true));

            Assert.IsEmpty(searchLog.ToString());
        }
Пример #2
0
        public void GetInfo()
        {
            ulong  testCodeLoadAddress   = 456;
            ulong  testCodeSize          = 789;
            string testSymbolFile        = "symbol file";
            string testSymbolDirectory   = "c:\\symbol\\dir";
            string testPlatformFile      = "platform file";
            string testPlatformDirectory = "/platform/dir";

            var mockPlatformFileSpec = Substitute.For <SbFileSpec>();

            mockPlatformFileSpec.GetFilename().Returns(testPlatformFile);
            mockPlatformFileSpec.GetDirectory().Returns(testPlatformDirectory);

            var mockSymbolFileSpec = Substitute.For <SbFileSpec>();

            mockSymbolFileSpec.GetFilename().Returns(testSymbolFile);
            mockSymbolFileSpec.GetDirectory().Returns(testSymbolDirectory);

            _mockModule.GetPlatformFileSpec().Returns(mockPlatformFileSpec);
            _mockModule.GetSymbolFileSpec().Returns(mockSymbolFileSpec);
            _mockModule.GetCodeLoadAddress().Returns(testCodeLoadAddress);
            _mockModule.GetCodeSize().Returns(testCodeSize);
            _mockModule.Is64Bit().Returns(true);
            _mockModuleUtil.HasSymbolsLoaded(_mockModule).Returns(true);

            var flags = enum_MODULE_INFO_FIELDS.MIF_NAME | enum_MODULE_INFO_FIELDS.MIF_URL |
                        enum_MODULE_INFO_FIELDS.MIF_URLSYMBOLLOCATION |
                        enum_MODULE_INFO_FIELDS.MIF_LOADADDRESS |
                        enum_MODULE_INFO_FIELDS.MIF_PREFFEREDADDRESS |
                        enum_MODULE_INFO_FIELDS.MIF_SIZE | enum_MODULE_INFO_FIELDS.MIF_LOADORDER |
                        enum_MODULE_INFO_FIELDS.MIF_FLAGS;
            var moduleInfo = new MODULE_INFO[1];

            Assert.Multiple(() =>
            {
                Assert.That(_debugModule.GetInfo(flags, moduleInfo), Is.EqualTo(VSConstants.S_OK));
                Assert.That(moduleInfo[0].dwValidFields, Is.EqualTo(flags));
                Assert.That(moduleInfo[0].m_bstrName, Is.EqualTo(testPlatformFile));
                Assert.That(moduleInfo[0].m_bstrUrl,
                            Is.EqualTo(testPlatformDirectory + "/" + testPlatformFile));
                Assert.That(moduleInfo[0].m_bstrUrlSymbolLocation,
                            Is.EqualTo(testSymbolDirectory + "\\" + testSymbolFile));
                Assert.That(moduleInfo[0].m_addrLoadAddress, Is.EqualTo(testCodeLoadAddress));
                Assert.That(moduleInfo[0].m_dwSize, Is.EqualTo(testCodeSize));
                Assert.That(moduleInfo[0].m_dwLoadOrder, Is.EqualTo(_testLoadOrder));
                Assert.That(moduleInfo[0].m_dwModuleFlags,
                            Is.EqualTo(enum_MODULE_FLAGS.MODULE_FLAG_64BIT |
                                       enum_MODULE_FLAGS.MODULE_FLAG_SYMBOLS));
            });
        }
Пример #3
0
        public void RecordBeforeLoad(IList <SbModule> modules)
        {
            var loadSymbolDataBuilder = new LoadSymbolData();

            moduleFileFinder.RecordMetrics(loadSymbolDataBuilder);
            loadSymbolDataBuilder.ModulesBeforeCount = modules.Count;
            loadSymbolDataBuilder.ModulesWithSymbolsLoadedBeforeCount =
                modules.Count(m => moduleUtil.HasSymbolsLoaded(m));
            loadSymbolDataBuilder.BinariesLoadedBeforeCount =
                modules.Count(m => moduleUtil.HasBinaryLoaded(m));
            action.UpdateEvent(new DeveloperLogEvent
            {
                LoadSymbolData = loadSymbolDataBuilder
            });
        }
Пример #4
0
        /// <summary>
        /// Creates a new mock module, and configures the values that mockModuleUtil returns in
        /// regards to said module.
        /// </summary>
        SbModule CreateMockModule(bool binaryLoaded, bool symbolsLoaded)
        {
            var module = Substitute.For <SbModule>();

            mockModuleUtil.HasSymbolsLoaded(module).Returns(symbolsLoaded);
            mockModuleUtil.HasBinaryLoaded(module).Returns(binaryLoaded);
            return(module);
        }
Пример #5
0
        public void SetUp()
        {
            searchLog = new StringWriter();

            mockBinaryFileUtil = Substitute.For <IBinaryFileUtil>();

            mockSuccessCommandReturnObject = Substitute.For <SbCommandReturnObject>();
            mockSuccessCommandReturnObject.GetOutput().Returns(LLDB_OUTPUT);
            mockSuccessCommandReturnObject.GetDescription().Returns("Success: " + LLDB_OUTPUT);
            mockSuccessCommandReturnObject.Succeeded().Returns(true);

            mockCommandInterpreter = Substitute.For <SbCommandInterpreter>();
            SetHandleCommandReturnValue(mockCommandInterpreter, COMMAND_WITH_MODULE_PATH,
                                        ReturnStatus.SuccessFinishResult,
                                        mockSuccessCommandReturnObject);

            mockPlatformFileSpec = Substitute.For <SbFileSpec>();
            mockPlatformFileSpec.GetDirectory().Returns(PLATFORM_DIRECTORY);
            mockPlatformFileSpec.GetFilename().Returns(BINARY_FILENAME);

            mockSymbolFileSpec = Substitute.For <SbFileSpec>();
            mockSymbolFileSpec.GetDirectory().Returns("");
            mockSymbolFileSpec.GetFilename().Returns(SYMBOL_FILE_NAME);

            mockBinaryFileSpec = Substitute.For <SbFileSpec>();
            mockBinaryFileSpec.GetDirectory().Returns(BINARY_DIRECTORY);
            mockBinaryFileSpec.GetFilename().Returns(BINARY_FILENAME);

            mockModuleFileFinder = Substitute.For <IModuleFileFinder>();
            SetFindFileReturnValue(PATH_IN_STORE);
            mockModuleUtil = Substitute.For <ILldbModuleUtil>();
            mockModuleUtil.HasSymbolsLoaded(Arg.Any <SbModule>()).Returns(false);

            symbolLoader = new SymbolLoader(mockModuleUtil, mockBinaryFileUtil,
                                            mockModuleFileFinder, mockCommandInterpreter);

            symbolFileInStore = Substitute.For <IFileReference>();
            symbolFileInStore.IsFilesystemLocation.Returns(true);
            symbolFileInStore.Location.Returns(PATH_IN_STORE);

            logSpy = new LogSpy();
            logSpy.Attach();
        }
Пример #6
0
        public void SetUp()
        {
            _mockCancelableTaskFactory = Substitute.For <CancelableTask.Factory>();
            _mockModuleUtil            = Substitute.For <ILldbModuleUtil>();
            _mockModuleUtil.HasSymbolsLoaded(Arg.Any <SbModule>()).Returns(false);
            _mockModuleFileLoader      = Substitute.For <IModuleFileLoader>();
            _mockModuleSearchLogHolder = Substitute.For <IModuleSearchLogHolder>();
            _mockModule         = Substitute.For <SbModule>();
            _mockActionRecorder = Substitute.For <ActionRecorder>(null, null);
            var mockModuleFileLoadRecorderFactory =
                Substitute.For <ModuleFileLoadMetricsRecorder.Factory>();

            _mockEngineHandler          = Substitute.For <IDebugEngineHandler>();
            _mockDebugProgram           = Substitute.For <IGgpDebugProgram>();
            _mockSymbolSettingsProvider = Substitute.For <ISymbolSettingsProvider>();
            _debugModule =
                new DebugModule
                .Factory(_mockCancelableTaskFactory, _mockActionRecorder,
                         mockModuleFileLoadRecorderFactory, _mockModuleUtil,
                         _mockSymbolSettingsProvider)
                .Create(_mockModuleFileLoader, _mockModuleSearchLogHolder, _mockModule,
                        _testLoadOrder, _mockEngineHandler, _mockDebugProgram);
        }
Пример #7
0
        public int GetInfo(enum_MODULE_INFO_FIELDS fields, MODULE_INFO[] moduleInfo)
        {
            var        info             = new MODULE_INFO();
            SbFileSpec platformFileSpec = _lldbModule.GetPlatformFileSpec();

            if ((enum_MODULE_INFO_FIELDS.MIF_NAME & fields) != 0)
            {
                if (platformFileSpec != null)
                {
                    info.m_bstrName     = platformFileSpec.GetFilename();
                    info.dwValidFields |= enum_MODULE_INFO_FIELDS.MIF_NAME;
                }
            }

            // "URL" fills in the "Path" column in the Modules window.
            if ((enum_MODULE_INFO_FIELDS.MIF_URL & fields) != 0)
            {
                // The module paths are for remote files (on Linux).
                if (platformFileSpec != null)
                {
                    info.m_bstrUrl = FileUtil.PathCombineLinux(
                        platformFileSpec.GetDirectory(), platformFileSpec.GetFilename());
                }

                info.dwValidFields |= enum_MODULE_INFO_FIELDS.MIF_URL;
            }

            // "URLSYMBOLLOCATION" fills in the Symbol File Location column.
            if ((enum_MODULE_INFO_FIELDS.MIF_URLSYMBOLLOCATION & fields) != 0)
            {
                if (_moduleUtil.HasSymbolsLoaded(_lldbModule))
                {
                    // The symbol paths are for local files (on Windows).
                    SbFileSpec symbolFileSpec = _lldbModule.GetSymbolFileSpec();
                    if (symbolFileSpec != null)
                    {
                        info.m_bstrUrlSymbolLocation = Path.Combine(
                            symbolFileSpec.GetDirectory(), symbolFileSpec.GetFilename());
                        info.dwValidFields |= enum_MODULE_INFO_FIELDS.MIF_URLSYMBOLLOCATION;
                    }
                }
            }

            if ((enum_MODULE_INFO_FIELDS.MIF_LOADADDRESS & fields) != 0)
            {
                info.m_addrLoadAddress = _lldbModule.GetCodeLoadAddress();
                info.dwValidFields    |= enum_MODULE_INFO_FIELDS.MIF_LOADADDRESS;
            }

            if ((enum_MODULE_INFO_FIELDS.MIF_PREFFEREDADDRESS & fields) != 0)
            {
                // TODO: Find the actual preferred load address rather than
                // pretending the module is loaded in the right place.
                // We may choose to ignore this, as samples do: extracting the preferred base
                // address from the library / executable seems nontrivial.
                // If m_addrLoadAddress is a different value, VS will show a warning on the icons
                // in the Modules window.
                info.m_addrPreferredLoadAddress = info.m_addrLoadAddress;
                info.dwValidFields |= enum_MODULE_INFO_FIELDS.MIF_PREFFEREDADDRESS;
            }

            if ((enum_MODULE_INFO_FIELDS.MIF_SIZE & fields) != 0)
            {
                info.m_dwSize       = (uint)_lldbModule.GetCodeSize();
                info.dwValidFields |= enum_MODULE_INFO_FIELDS.MIF_SIZE;
            }

            if ((enum_MODULE_INFO_FIELDS.MIF_LOADORDER & fields) != 0)
            {
                info.m_dwLoadOrder  = _loadOrder;
                info.dwValidFields |= enum_MODULE_INFO_FIELDS.MIF_LOADORDER;
            }

            if ((enum_MODULE_INFO_FIELDS.MIF_FLAGS & fields) != 0)
            {
                info.m_dwModuleFlags = 0;
                if (_moduleUtil.HasSymbolsLoaded(_lldbModule))
                {
                    info.m_dwModuleFlags |= enum_MODULE_FLAGS.MODULE_FLAG_SYMBOLS;
                }

                if (_lldbModule.Is64Bit())
                {
                    info.m_dwModuleFlags |= enum_MODULE_FLAGS.MODULE_FLAG_64BIT;
                }

                info.dwValidFields |= enum_MODULE_INFO_FIELDS.MIF_FLAGS;
            }

            if ((enum_MODULE_INFO_FIELDS.MIF_DEBUGMESSAGE & fields) != 0)
            {
                if (!_moduleUtil.HasSymbolsLoaded(_lldbModule))
                {
                    var inclusionSetting = _symbolSettingsProvider.GetInclusionSettings();
                    if (!inclusionSetting.IsModuleIncluded(ModuleName))
                    {
                        info.m_bstrDebugMessage = SymbolInclusionSettings.ModuleExcludedMessage;
                    }
                }

                info.dwValidFields |= enum_MODULE_INFO_FIELDS.MIF_DEBUGMESSAGE;
            }

            moduleInfo[0] = info;
            return(VSConstants.S_OK);
        }
Пример #8
0
        public virtual async Task <bool> LoadSymbolsAsync(
            SbModule lldbModule, TextWriter searchLog, bool useSymbolStores)
        {
            if (lldbModule == null)
            {
                throw new ArgumentNullException(nameof(lldbModule));
            }
            searchLog = searchLog ?? TextWriter.Null;

            // Return early if symbols are already loaded
            if (moduleUtil.HasSymbolsLoaded(lldbModule))
            {
                return(true);
            }

            var(symbolFileDir, symbolFileName) =
                await GetSymbolFileDirAndNameAsync(lldbModule, searchLog);

            if (string.IsNullOrEmpty(symbolFileName))
            {
                await searchLog.WriteLineAsync(ErrorStrings.SymbolFileNameUnknown);

                Trace.WriteLine(ErrorStrings.SymbolFileNameUnknown);
                return(false);
            }
            BuildId uuid = new BuildId(lldbModule.GetUUIDString());

            // If we have a search directory, let us look up the symbol file in there.
            if (!string.IsNullOrEmpty(symbolFileDir))
            {
                string symbolFilePath = string.Empty;
                try
                {
                    symbolFilePath = Path.Combine(symbolFileDir, symbolFileName);
                    BuildId fileUUID = await binaryFileUtil.ReadBuildIdAsync(symbolFilePath);

                    if (fileUUID == uuid)
                    {
                        return(AddSymbolFile(symbolFilePath, lldbModule, searchLog));
                    }
                }
                catch (Exception e) when(e is InvalidBuildIdException ||
                                         e is BinaryFileUtilException || e is ArgumentException)
                {
                    // Just ignore the symbol file path if we could not read the build Id.
                    Trace.WriteLine($"Could not read build Id from {symbolFilePath} " +
                                    $"for module {lldbModule.GetFileSpec().GetFilename()} " +
                                    $"(Message: {e.Message}).");
                }
            }

            var filepath = useSymbolStores
                               ? await moduleFileFinder.FindFileAsync(
                symbolFileName, uuid, true, searchLog)
                               : null;

            if (filepath == null)
            {
                return(false);
            }

            return(AddSymbolFile(filepath, lldbModule, searchLog));
        }
Пример #9
0
        public void HasSymbolsLoaded(bool hasCompileUnits)
        {
            mockModule.HasCompileUnits().Returns(hasCompileUnits);

            Assert.AreEqual(hasCompileUnits, moduleUtil.HasSymbolsLoaded(mockModule));
        }