Lines Matching +full:data +full:- +full:mapping
1 //===- CoverageMappingReader.cpp - Code coverage mapping reader -----------===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file contains support for reading coverage mapping data for
12 //===----------------------------------------------------------------------===//
45 #define DEBUG_TYPE "coverage-mapping"
56 if (auto E = Reader->readNextRecord(Record))
66 if (Data.empty())
69 Result = decodeULEB128(Data.bytes_begin(), &N);
70 if (N > Data.size())
73 Data = Data.substr(N);
90 if (Result > Data.size())
100 Result = Data.substr(0, Length);
101 Data = Data.substr(Length);
135 StringRef CompressedFilenames = Data.substr(0, CompressedLen);
136 Data = Data.substr(CompressedLen);
203 Tag -= Counter::Expression;
235 /// Read the sub-array of regions for the given inferred file id.
248 // They are stored as internal values plus 1 (min is -1)
319 static_cast<int16_t>(static_cast<int16_t>(ID1) - 1),
320 {static_cast<int16_t>(static_cast<int16_t>(FID1) - 1),
321 static_cast<int16_t>(static_cast<int16_t>(TID1) - 1)}};
363 // column range (1 -> std::numeric_limits<unsigned>::max()), but because
365 // we set the column range to (0 -> 0) to ensure that the column start and
376 << ColumnStart << " -> " << (LineStart + NumLines) << ":"
391 "counter mapping region locations are incorrect");
398 // Read the virtual file mapping.
410 // Construct the files using unique filenames and virtual file mapping.
432 // Read the mapping regions sub-arrays.
456 FileIDExpansionRegionMapping[R.FileID]->Count = R.Count;
466 // A dummy coverage mapping data consists of just one region with zero count.
499 Data = *DataOrErr;
507 if (isa<COFFObjectFile>(Obj) && !Obj->isRelocatableObject())
510 Data = Data.drop_front(1);
518 auto Offset = Pointer - Address;
519 if (Offset + Size > Data.size())
521 return Data.substr(Pointer - Address, Size);
524 // Check if the mapping data is a dummy, i.e. is emitted for an unused function.
525 static Expected<bool> isCoverageMappingDummy(uint64_t Hash, StringRef Mapping) {
526 // The hash value of dummy mapping records is always zero.
529 return RawCoverageMappingDummyChecker(Mapping).isDummy();
533 /// filenames in a vector-like container.
547 /// The interface to read coverage mapping function records for a module.
554 // mapping data associated with the module.
584 // A class for reading coverage mapping function records for a module.
606 // In addition, prefer records with real coverage mapping data to dummy
610 StringRef Mapping,
613 uint64_t FuncHash = CFR->template getFuncHash<Endian>();
614 NameRefType NameRef = CFR->template getFuncNameRef<Endian>();
619 if (Error Err = CFR->template getFuncName<Endian>(ProfileNames, FuncName))
625 Records.emplace_back(Version, FuncName, FuncHash, Mapping,
630 size_t OldRecordIndex = InsertResult.first->second;
640 isCoverageMappingDummy(FuncHash, Mapping);
647 OldRecord.CoverageMapping = Mapping;
669 "coverage mapping header section is larger than buffer size");
671 uint32_t NRecords = CovHeader->getNRecords<Endian>();
672 uint32_t FilenamesSize = CovHeader->getFilenamesSize<Endian>();
673 uint32_t CoverageSize = CovHeader->getCoverageSize<Endian>();
674 assert((CovMapVersion)CovHeader->getVersion<Endian>() == Version);
678 // This is a no-op in Version4 (function records are read after all headers
700 FilenameRange FileRange(FilenamesBegin, Filenames.size() - FilenamesBegin);
713 FilenameRange &OrigRange = Insert.first->getSecond();
726 // We'll read the coverage mapping records in the loop below.
727 // This is a no-op in Version4 (coverage mappings are not affixed to the
732 "coverage mapping size is not zero");
761 // Validate the length of the coverage mapping for this function.
765 CFR->template advanceByOne<Endian>(OutOfLineMappingBuf);
770 "next mapping buffer is larger than buffer size");
777 uint64_t FilenamesRef = CFR->template getFilenamesRef<Endian>();
785 FileRange = It->getSecond();
788 // Now, read the coverage data.
789 if (FileRange && !FileRange->isInvalid()) {
790 StringRef Mapping =
791 CFR->template getCoverageMapping<Endian>(OutOfLineMappingBuf);
793 Mapping.data() + Mapping.size() > FuncRecBufEnd)
796 "coverage mapping data is larger than buffer size");
797 if (Error Err = insertFunctionRecordIfNeeded(CFR, Mapping, *FileRange))
826 // Decompress the name data.
858 // Read the records in the coverage data section.
860 reinterpret_cast<const CovMapHeader *>(CovMap.data());
861 CovMapVersion Version = (CovMapVersion)CovHeader->getVersion<Endian>();
870 const char *CovBuf = CovMap.data();
872 const char *FuncRecBuf = FuncRecords.data();
873 const char *FuncRecBufEnd = FuncRecords.data() + FuncRecords.size();
875 // Read the current coverage header & filename data.
881 auto NextOrErr = Reader->readCoverageHeader(CovBuf, CovBufEnd);
889 return Reader->readFunctionRecords(FuncRecBuf, FuncRecBufEnd, std::nullopt,
904 InstrProfSymtab &ProfileNames = *Reader->ProfileNames;
905 StringRef FuncRecordsRef = Reader->FuncRecords->getBuffer();
908 ProfileNames, Coverage, FuncRecordsRef, Reader->MappingRecords,
909 CompilationDir, Reader->Filenames))
913 ProfileNames, Coverage, FuncRecordsRef, Reader->MappingRecords,
914 CompilationDir, Reader->Filenames))
918 ProfileNames, Coverage, FuncRecordsRef, Reader->MappingRecords,
919 CompilationDir, Reader->Filenames))
923 ProfileNames, Coverage, FuncRecordsRef, Reader->MappingRecords,
924 CompilationDir, Reader->Filenames))
934 loadTestingFormat(StringRef Data, StringRef CompilationDir) {
939 Data = Data.substr(sizeof(TestingFormatMagic));
940 if (Data.size() < sizeof(uint64_t))
942 "the size of data is too small");
945 *reinterpret_cast<const uint64_t *>(Data.data()));
946 Data = Data.substr(sizeof(uint64_t));
948 // Read the ProfileNames data.
949 if (Data.empty())
952 uint64_t ProfileNamesSize = decodeULEB128(Data.bytes_begin(), &N);
953 if (N > Data.size())
957 Data = Data.substr(N);
958 if (Data.empty())
961 uint64_t Address = decodeULEB128(Data.bytes_begin(), &N);
962 if (N > Data.size())
965 Data = Data.substr(N);
966 if (Data.size() < ProfileNamesSize)
970 if (Error E = ProfileNames->create(Data.substr(0, ProfileNamesSize), Address))
972 Data = Data.substr(ProfileNamesSize);
978 CoverageMappingSize = decodeULEB128(Data.bytes_begin(), &N);
979 if (N > Data.size())
982 Data = Data.substr(N);
991 // Skip the padding bytes because coverage map data has an alignment of 8.
992 auto Pad = offsetToAlignedAddr(Data.data(), Align(8));
993 if (Data.size() < Pad)
996 Data = Data.substr(Pad);
997 if (Data.size() < sizeof(CovMapHeader))
1000 "coverage mapping header section is larger than data size");
1002 Data.substr(0, sizeof(CovMapHeader)).data());
1004 CovMapVersion(CovHeader->getVersion<llvm::endianness::little>());
1009 CoverageMappingSize = Data.size();
1012 CovHeader->getFilenamesSize<llvm::endianness::little>();
1017 auto CoverageMapping = Data.substr(0, CoverageMappingSize);
1018 Data = Data.substr(CoverageMappingSize);
1020 // Read the CoverageRecords data.
1022 if (!Data.empty())
1024 "data is not empty");
1026 // Skip the padding bytes because coverage records data has an alignment
1028 Pad = offsetToAlignedAddr(Data.data(), Align(8));
1029 if (Data.size() < Pad)
1032 Data = Data.substr(Pad);
1035 MemoryBuffer::getMemBuffer(Data);
1084 auto ObjectFileOrErr = Universal->getMachOObjectForArch(Arch);
1092 if (!Arch.empty() && OF->getArch() != Triple(Arch).getArch())
1100 uint8_t BytesInAddress = OF->getBytesInAddress();
1102 OF->isLittleEndian() ? llvm::endianness::little : llvm::endianness::big;
1121 "the size of coverage mapping section is not one");
1122 if (Error E = ProfileNames->create(NamesSectionRefs.back()))
1155 FuncRecordsSize += alignTo(CoverageRecordsOrErr->size(), RecordAlignment);
1159 char *FuncRecordsBuffer = WritableBuffer->getBufferStart();
1172 alignAddr(FuncRecordsBuffer, RecordAlignment) -
1176 assert(FuncRecordsBuffer == WritableBuffer->getBufferEnd() &&
1194 for (auto &ObjForArch : Universal->objects())
1236 for (auto &ObjForArch : Universal->objects()) {
1250 ArchiveOrErr.get()->getMemoryBufferRef(), Arch, ObjectFileBuffers,
1258 for (auto &Child : Ar->children(Err)) {
1277 if (Ar->isThin())
1278 for (auto &Buffer : Ar->takeThinBuffers())
1291 BinaryIDs->push_back(BinaryID);