Ejemplo n.º 1
0
        public void ProgramHeaderOutsideDump()
        {
            var elfHeaderBytes = TestData.GetElfBytes(ElfHeader.Size + 1, ProgramHeader.Size, 1,
                                                      false);

            _fileSystem.AddFile(dumpPath, new MockFileData(elfHeaderBytes));
            DumpReadResult dump = _provider.GetModules(dumpPath);

            Assert.AreEqual(0, dump.Modules.Count());
            Assert.AreEqual(DumpReadWarning.FileIsTruncated, dump.Warning);
        }
Ejemplo n.º 2
0
        public void ManySectionsInBinaryFile()
        {
            // This test is checking a dump with the structure below. The elf module file in the
            // dump contains many sections to test that the code that looks for build ID can
            // find build IDs far in the file.
            //
            // Start position    Section name                       Section size in bytes
            //              0    Dump elf header                      64
            //             64    Program headers                      --
            //             64      File index note program header     56
            //            120      File header                        56
            //            176    File contents                      8156
            //           8332    File index                           68
            ushort programHeadersCount = 2;

            byte[] elfHeaderBytes = TestData.GetElfBytes(ElfHeader.Size, ProgramHeader.Size,
                                                         programHeadersCount, false);

            byte[] fileBytes  = GetElfFileBytesWithManySections(TestData.expectedId);
            ulong  fileOffset =
                (ulong)elfHeaderBytes.Length + programHeadersCount * (ulong)ProgramHeader.Size;
            ulong fileSize    = (ulong)fileBytes.Length;
            ulong fileAddress = 1000;

            ulong fileIndexOffset = fileOffset + fileSize;

            byte[] fileIndexBytes = TestData.GetNtFileSectionBytes(
                fileAddress, fileAddress + fileSize, 0ul, expectedFileName);
            byte[] fileIndexNoteBytes = TestData.GetNoteSectionBytes(
                NoteSection.CoreName, NoteSection.NtFileType, fileIndexBytes);

            byte[] fileIndexHeaderBytes = TestData.GetProgramHeaderBytes(
                ProgramHeader.Type.NoteSegment, fileIndexOffset, 0ul /* address */,
                (ulong)(fileIndexNoteBytes.Length));
            byte[] fileHeaderBytes = TestData.GetProgramHeaderBytes(
                ProgramHeader.Type.LoadableSegment, fileOffset, fileAddress, fileSize);
            byte[] headers =
                elfHeaderBytes.Concat(fileIndexHeaderBytes).Concat(fileHeaderBytes).ToArray();

            byte[] dumpFileBytes = headers.Concat(fileBytes).Concat(fileIndexNoteBytes).ToArray();
            _fileSystem.AddFile(dumpPath, new MockFileData(dumpFileBytes));

            DumpReadResult dump = _provider.GetModules(dumpPath);

            Assert.That(dump.Warning, Is.EqualTo(DumpReadWarning.None));
            Assert.That(dump.Modules.Count(), Is.EqualTo(1));
            Assert.That(dump.Modules.ElementAt(0).Path, Is.EqualTo(expectedFileName));
            Assert.That(dump.Modules.ElementAt(0).Id, Is.EqualTo(TestData.expectedId));
        }
Ejemplo n.º 3
0
        public void TwoModulesInIndexCorrect()
        {
            TestDumpFile dumpFile = CreateValidDumpFile();

            _fileSystem.AddFile(dumpPath, new MockFileData(dumpFile.Bytes));

            DumpReadResult dump = _provider.GetModules(dumpPath);

            Assert.That(dump.Warning, Is.EqualTo(DumpReadWarning.None));
            Assert.That(dump.Modules.Count(), Is.EqualTo(2));
            Assert.That(dump.Modules.ElementAt(0).Path, Is.EqualTo(expectedFileName));
            Assert.That(dump.Modules.ElementAt(0).Id, Is.EqualTo(TestData.expectedId));
            Assert.That(dump.Modules.ElementAt(1).Path, Is.EqualTo(anotherExpectedFileName));
            Assert.That(dump.Modules.ElementAt(1).Id, Is.EqualTo(TestData.anotherExpectedId));
        }
Ejemplo n.º 4
0
        public void TruncatedFileIndexReturnsEmptyModules()
        {
            TestDumpFile dumpFile = CreateValidDumpFile();

            // If the file is truncated before the end of the NtFile note segment, we should only
            // get empty module list back.
            for (ulong i = 0; i < dumpFile.NoteNtFileEnd; i += 10)
            {
                byte[] truncatedDumpBytes = dumpFile.Bytes.Take((int)i).ToArray();
                _fileSystem.AddFile(dumpPath, new MockFileData(truncatedDumpBytes));
                DumpReadResult dump = _provider.GetModules(dumpPath);
                Assert.That(dump.Modules.Count(), Is.EqualTo(0));
                Assert.That(dump.Warning, Is.AnyOf(DumpReadWarning.FileIsTruncated,
                                                   DumpReadWarning.ElfHeaderIsCorrupted));
            }
        }
Ejemplo n.º 5
0
        public void NoteSectionOutsideDump()
        {
            var elfHeaderBytes = TestData.GetElfBytes(ElfHeader.Size, ProgramHeader.Size, 1,
                                                      false);

            var positionOutsideFile = 1000ul;
            var programHeader       = TestData.GetProgramHeaderBytes(
                ProgramHeader.Type.NoteSegment, positionOutsideFile, positionOutsideFile, 10);

            var data = elfHeaderBytes.Concat(programHeader).ToArray();

            _fileSystem.AddFile(dumpPath, new MockFileData(data));
            DumpReadResult dump = _provider.GetModules(dumpPath);

            Assert.AreEqual(0, dump.Modules.Count());
            Assert.AreEqual(DumpReadWarning.FileIsTruncated, dump.Warning);
        }
Ejemplo n.º 6
0
        public void TruncatedFileNotInModules()
        {
            TestDumpFile dumpFile = CreateValidDumpFile();

            // If the embedded module file is truncated after the NtFile note but before the end of
            // the build ID of the second file, we should only get back the non-truncated module.
            for (int i = (int)dumpFile.NoteNtFileEnd; i < dumpFile.Bytes.Length; i += 10)
            {
                byte[] truncatedDumpBytes = dumpFile.Bytes.Take(i).ToArray();
                _fileSystem.AddFile(dumpPath, new MockFileData(truncatedDumpBytes));
                DumpReadResult dump = _provider.GetModules(dumpPath);
                Assert.That(dump.Modules.Count(), Is.EqualTo(1));
                Assert.That(dump.Modules.ElementAt(0).Path, Is.EqualTo(expectedFileName));
                Assert.That(dump.Modules.ElementAt(0).Id, Is.EqualTo(TestData.expectedId));
                Assert.That(dump.Warning, Is.EqualTo(DumpReadWarning.FileIsTruncated));
            }
        }
Ejemplo n.º 7
0
        void ProcessModules(string filename)
        {
            if (_modules == null)
            {
                _modules = new List <ModuleNode>();
                var            moduleProvider = new DumpModulesProvider(new FileSystem());
                DumpReadResult dumpModules    = moduleProvider.GetModules(filename);

                foreach (DumpModule dumpModule in dumpModules.Modules)
                {
                    var module = new ModuleNode(dumpModule);
                    if (module.IsExecutable)
                    {
                        ProgramNameValue = $"{module.ModuleName} : {module.ModuleGroup}";
                    }

                    _modules.Add(module);
                }
            }

            Modules = CollectionViewSource.GetDefaultView(_modules);
        }
Ejemplo n.º 8
0
        SbProcess LoadCore(RemoteTarget lldbTarget, IAction loadCoreAction)
        {
            var moduleFileLoadRecorder = _moduleFileLoadRecorderFactory.Create(loadCoreAction);

            moduleFileLoadRecorder.RecordBeforeLoad(Array.Empty <SbModule>());

            bool isFullDump = _coreFilePath.EndsWith(".core");

            if (isFullDump)
            {
                string combinedPath = _taskContext.Factory.Run(async() =>
                {
                    await _taskContext.Factory.SwitchToMainThreadAsync();
                    _symbolSettingsProvider.GetStorePaths(out string paths, out string cache);
                    return(SymbolUtils.GetCombinedLookupPaths(paths, cache));
                });

                _moduleFileFinder.SetSearchPaths(combinedPath);

                TextWriter     searchLog = new StringWriter();
                DumpReadResult dump      = _dumpModulesProvider.GetModules(_coreFilePath);

                DumpModule[] executableModules =
                    dump.Modules.Where(module => module.IsExecutable).ToArray();
                DumpModule[] nonExecutableModules =
                    dump.Modules.Where(module => !module.IsExecutable).ToArray();

                // We should not pre-load non executable modules if there wasn't any successfully
                // loaded executable modules. Otherwise lldb will not upgrade image list during the
                // attachment to the core dump and will try to resolve the executable on the
                // developer machine. See (internal)
                if (executableModules.Any() &&
                    executableModules.All(module =>
                                          TryPreloadModule(lldbTarget, searchLog, module)))
                {
                    foreach (DumpModule module in nonExecutableModules)
                    {
                        TryPreloadModule(lldbTarget, searchLog, module);
                    }
                }

                if (dump.Warning == DumpReadWarning.None && !executableModules.Any())
                {
                    dump.Warning = DumpReadWarning.ExecutableBuildIdMissing;
                }
                if (dump.Warning != DumpReadWarning.None)
                {
                    var shouldAttach = _taskContext.Factory.Run(
                        async() => await _warningDialog.ShouldAttachToIncosistentCoreFileAsync(
                            dump.Warning));
                    if (!shouldAttach)
                    {
                        throw new CoreAttachStoppedException();
                    }
                }
            }

            SbProcess lldbDebuggerProcess = lldbTarget.LoadCore(_coreFilePath);

            if (lldbDebuggerProcess == null)
            {
                throw new AttachException(VSConstants.E_ABORT,
                                          ErrorStrings.FailedToLoadCore(_coreFilePath));
            }

            RecordModules(lldbTarget, moduleFileLoadRecorder);
            return(lldbDebuggerProcess);
        }
Ejemplo n.º 9
0
        public void CorrectModules()
        {
            ushort programHeadersCount = 4;
            var    elfHeaderBytes      = TestData.GetElfBytes(ElfHeader.Size, ProgramHeader.Size,
                                                              programHeadersCount, false);

            ulong firstFileOffset = ElfHeader.Size +
                                    (ulong)programHeadersCount * ProgramHeader.Size;

            var firstFileBytes  = TestData.GetElfFileBytesFromBuildId(TestData.expectedId);
            var secondFileBytes = TestData.GetElfFileBytesFromBuildId(TestData.anotherExpectedId);

            var firstFileHeaderBytes = TestData.GetProgramHeaderBytes(
                ProgramHeader.Type.LoadableSegment, firstFileOffset, firstFileOffset,
                (ulong)firstFileBytes.Length);

            var firstFileIndexOffset = firstFileOffset + (ulong)firstFileBytes.Length;
            var fileIndexBytes       = TestData.GetNtFileSectionBytes(
                firstFileOffset, firstFileIndexOffset, 0ul, expectedFileName);

            var firstFileIndexNoteBytes = TestData.GetNoteSectionBytes(
                NoteSection.CoreName, NoteSection.NtFileType, fileIndexBytes);

            var firstFileIndexHeaderBytes = TestData.GetProgramHeaderBytes(
                ProgramHeader.Type.NoteSegment, firstFileIndexOffset, firstFileIndexOffset,
                (ulong)firstFileBytes.Length);

            ulong secondFileIndexOffset = firstFileIndexOffset +
                                          (ulong)firstFileIndexNoteBytes.Length;
            ulong secondFileOffset  = secondFileIndexOffset + (ulong)firstFileIndexNoteBytes.Length;
            ulong secondFileDataEnd = secondFileOffset + (ulong)secondFileBytes.Length;

            var secondIndexBytes = TestData.GetNtFileSectionBytes(
                secondFileOffset, secondFileDataEnd, 0ul, anotherExpectedFileName);

            var secondFileIndexHeaderBytes = TestData.GetProgramHeaderBytes(
                ProgramHeader.Type.NoteSegment, secondFileIndexOffset, secondFileIndexOffset,
                (ulong)secondIndexBytes.Length);

            var secondFileIndexNoteBytes = TestData.GetNoteSectionBytes(
                NoteSection.CoreName, NoteSection.NtFileType, secondIndexBytes);

            var secondFileHeaderBytes = TestData.GetProgramHeaderBytes(
                ProgramHeader.Type.LoadableSegment, secondFileOffset, secondFileOffset,
                (ulong)secondFileBytes.Length);

            var dumpBytes = elfHeaderBytes.Concat(firstFileHeaderBytes)
                            .Concat(firstFileIndexHeaderBytes).Concat(secondFileIndexHeaderBytes)
                            .Concat(secondFileHeaderBytes).Concat(firstFileBytes)
                            .Concat(firstFileIndexNoteBytes).Concat(secondFileIndexNoteBytes)
                            .Concat(secondFileBytes).ToArray();

            _fileSystem.AddFile(dumpPath, new MockFileData(dumpBytes));

            DumpReadResult dump = _provider.GetModules(dumpPath);

            Assert.AreEqual(2, dump.Modules.Count());

            var firstModule = dump.Modules.First();

            Assert.AreEqual(expectedFileName, firstModule.Path);
            Assert.AreEqual(TestData.expectedId, firstModule.Id);

            var lastModule = dump.Modules.Last();

            Assert.AreEqual(anotherExpectedFileName, lastModule.Path);
            Assert.AreEqual(TestData.anotherExpectedId, lastModule.Id);
        }