llvm.org GIT mirror llvm / 698e829
pdbdump: print out COFF section headers. Unlike other sections that can grow to any size, the COFF section header stream has maximum length because each record is fixed size and the COFF file format limits the maximum number of sections. So I decided to not create a specific stream class for it. Instead, I added a member function to DbiStream class which returns a vector of COFF headers. Differential Revision: http://reviews.llvm.org/D20717 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@271557 91177308-0d34-0410-b5e6-96231b3b80d8 Rui Ueyama 4 years ago
4 changed file(s) with 178 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
2121 #include "llvm/Support/Error.h"
2222
2323 namespace llvm {
24 namespace object {
25 struct coff_section;
26 }
27
2428 namespace pdb {
2529 class PDBFile;
2630 class ISectionContribVisitor;
5559
5660 ArrayRef modules() const;
5761
62 codeview::FixedStreamArray getSectionHeaders();
63
5864 codeview::FixedStreamArray getSectionMap() const;
5965 void visitSectionContributions(ISectionContribVisitor &Visitor) const;
6066
6167 private:
6268 Error initializeSectionContributionData();
69 Error initializeSectionHeadersData();
6370 Error initializeSectionMapData();
6471 Error initializeFileInfo();
6572
8390 codeview::FixedStreamArray SectionContribs2;
8491 codeview::FixedStreamArray SectionMap;
8592
93 std::unique_ptr SectionHeaderStream;
94 codeview::FixedStreamArray SectionHeaders;
95
8696 const HeaderInfo *Header;
8797 };
8898 }
55 // License. See LICENSE.TXT for details.
66 //
77 //===----------------------------------------------------------------------===//
8
89 #include "llvm/DebugInfo/PDB/Raw/DbiStream.h"
910
1011 #include "llvm/DebugInfo/CodeView/StreamArray.h"
1718 #include "llvm/DebugInfo/PDB/Raw/RawConstants.h"
1819 #include "llvm/DebugInfo/PDB/Raw/RawError.h"
1920 #include "llvm/DebugInfo/PDB/Raw/RawTypes.h"
21 #include "llvm/Object/COFF.h"
2022
2123 using namespace llvm;
2224 using namespace llvm::codeview;
179181
180182 if (auto EC = initializeSectionContributionData())
181183 return EC;
182
184 if (auto EC = initializeSectionHeadersData())
185 return EC;
183186 if (auto EC = initializeSectionMapData())
184187 return EC;
185188
241244 PDB_Machine DbiStream::getMachineType() const {
242245 uint16_t Machine = Header->MachineType;
243246 return static_cast(Machine);
247 }
248
249 codeview::FixedStreamArray
250 DbiStream::getSectionHeaders() {
251 return SectionHeaders;
244252 }
245253
246254 ArrayRef DbiStream::modules() const { return ModuleInfos; }
271279
272280 return make_error(raw_error_code::feature_unsupported,
273281 "Unsupported DBI Section Contribution version");
282 }
283
284 // Initializes this->SectionHeaders.
285 Error DbiStream::initializeSectionHeadersData() {
286 uint32_t StreamNum = getDebugStreamIndex(DbgHeaderType::SectionHdr);
287 SectionHeaderStream.reset(new MappedBlockStream(StreamNum, Pdb));
288
289 size_t StreamLen = SectionHeaderStream->getLength();
290 if (StreamLen % sizeof(object::coff_section))
291 return make_error(raw_error_code::corrupt_file,
292 "Corrupted section header stream.");
293
294 size_t NumSections = StreamLen / sizeof(object::coff_section);
295 codeview::StreamReader Reader(*SectionHeaderStream);
296 if (auto EC = Reader.readArray(SectionHeaders, NumSections))
297 return make_error(raw_error_code::corrupt_file,
298 "Could not read a bitmap.");
299 return Error::success();
274300 }
275301
276302 Error DbiStream::initializeSectionMapData() {
0 ; RUN: llvm-pdbdump -raw-headers -raw-tpi-records -raw-tpi-record-bytes -raw-module-syms \
11 ; RUN: -raw-sym-record-bytes -raw-publics -raw-module-files -raw-stream-name=/names \
22 ; RUN: -raw-stream-summary -raw-stream-blocks -raw-ipi-records -raw-ipi-record-bytes \
3 ; RUN: -raw-section-contribs -raw-section-map %p/Inputs/empty.pdb \
3 ; RUN: -raw-section-contribs -raw-section-map -raw-section-headers %p/Inputs/empty.pdb \
44 ; RUN: | FileCheck -check-prefix=EMPTY %s
55 ; RUN: llvm-pdbdump -raw-all %p/Inputs/empty.pdb | FileCheck -check-prefix=ALL %s
66 ; RUN: llvm-pdbdump -raw-headers -raw-stream-name=/names -raw-modules -raw-module-files \
803803 ; EMPTY-NEXT: }
804804 ; EMPTY-NEXT: ]
805805 ; EMPTY-NEXT: }
806 ; EMPTY-NEXT: Section Headers [
807 ; EMPTY-NEXT: {
808 ; EMPTY-NEXT: Name: .text
809 ; EMPTY-NEXT: Virtual Size: 4122
810 ; EMPTY-NEXT: Virtual Address: 4096
811 ; EMPTY-NEXT: Size of Raw Data: 4608
812 ; EMPTY-NEXT: File Pointer to Raw Data: 1024
813 ; EMPTY-NEXT: File Pointer to Relocations: 0
814 ; EMPTY-NEXT: File Pointer to Linenumbers: 0
815 ; EMPTY-NEXT: Number of Relocations: 0
816 ; EMPTY-NEXT: Number of Linenumbers: 0
817 ; EMPTY-NEXT: Characteristics: 1610612768
818 ; EMPTY-NEXT: }
819 ; EMPTY-NEXT: {
820 ; EMPTY-NEXT: Name: .rdata
821 ; EMPTY-NEXT: Virtual Size: 690
822 ; EMPTY-NEXT: Virtual Address: 12288
823 ; EMPTY-NEXT: Size of Raw Data: 1024
824 ; EMPTY-NEXT: File Pointer to Raw Data: 5632
825 ; EMPTY-NEXT: File Pointer to Relocations: 0
826 ; EMPTY-NEXT: File Pointer to Linenumbers: 0
827 ; EMPTY-NEXT: Number of Relocations: 0
828 ; EMPTY-NEXT: Number of Linenumbers: 0
829 ; EMPTY-NEXT: Characteristics: 1073741888
830 ; EMPTY-NEXT: }
831 ; EMPTY-NEXT: {
832 ; EMPTY-NEXT: Name: .data
833 ; EMPTY-NEXT: Virtual Size: 4
834 ; EMPTY-NEXT: Virtual Address: 16384
835 ; EMPTY-NEXT: Size of Raw Data: 0
836 ; EMPTY-NEXT: File Pointer to Raw Data: 0
837 ; EMPTY-NEXT: File Pointer to Relocations: 0
838 ; EMPTY-NEXT: File Pointer to Linenumbers: 0
839 ; EMPTY-NEXT: Number of Relocations: 0
840 ; EMPTY-NEXT: Number of Linenumbers: 0
841 ; EMPTY-NEXT: Characteristics: 3221225536
842 ; EMPTY-NEXT: }
843 ; EMPTY-NEXT: {
844 ; EMPTY-NEXT: Name: .reloc
845 ; EMPTY-NEXT: Virtual Size: 8
846 ; EMPTY-NEXT: Virtual Address: 20480
847 ; EMPTY-NEXT: Size of Raw Data: 512
848 ; EMPTY-NEXT: File Pointer to Raw Data: 6656
849 ; EMPTY-NEXT: File Pointer to Relocations: 0
850 ; EMPTY-NEXT: File Pointer to Linenumbers: 0
851 ; EMPTY-NEXT: Number of Relocations: 0
852 ; EMPTY-NEXT: Number of Linenumbers: 0
853 ; EMPTY-NEXT: Characteristics: 1107296320
854 ; EMPTY-NEXT: }
855 ; EMPTY-NEXT: ]
806856
807857 ; ALL: FileHeaders {
808858 ; ALL: BlockSize: 4096
10841134 ; ALL: {
10851135 ; ALL: Name: * Linker *
10861136 ; ALL: Debug Stream Index: 14
1087 ; ALL: Object File Name:
1137 ; ALL: Object File Name:
10881138 ; ALL: Num Files: 0
10891139 ; ALL: Source File Name Idx: 0
10901140 ; ALL: Pdb File Name Idx: 1
14541504 ; ALL: }
14551505 ; ALL: ]
14561506 ; ALL: }
1507 ; ALL: Section Headers [
1508 ; ALL: {
1509 ; ALL: Name: .text
1510 ; ALL: Virtual Size: 4122
1511 ; ALL: Virtual Address: 4096
1512 ; ALL: Size of Raw Data: 4608
1513 ; ALL: File Pointer to Raw Data: 1024
1514 ; ALL: File Pointer to Relocations: 0
1515 ; ALL: File Pointer to Linenumbers: 0
1516 ; ALL: Number of Relocations: 0
1517 ; ALL: Number of Linenumbers: 0
1518 ; ALL: Characteristics: 1610612768
1519 ; ALL: }
1520 ; ALL: {
1521 ; ALL: Name: .rdata
1522 ; ALL: Virtual Size: 690
1523 ; ALL: Virtual Address: 12288
1524 ; ALL: Size of Raw Data: 1024
1525 ; ALL: File Pointer to Raw Data: 5632
1526 ; ALL: File Pointer to Relocations: 0
1527 ; ALL: File Pointer to Linenumbers: 0
1528 ; ALL: Number of Relocations: 0
1529 ; ALL: Number of Linenumbers: 0
1530 ; ALL: Characteristics: 1073741888
1531 ; ALL: }
1532 ; ALL: {
1533 ; ALL: Name: .data
1534 ; ALL: Virtual Size: 4
1535 ; ALL: Virtual Address: 16384
1536 ; ALL: Size of Raw Data: 0
1537 ; ALL: File Pointer to Raw Data: 0
1538 ; ALL: File Pointer to Relocations: 0
1539 ; ALL: File Pointer to Linenumbers: 0
1540 ; ALL: Number of Relocations: 0
1541 ; ALL: Number of Linenumbers: 0
1542 ; ALL: Characteristics: 3221225536
1543 ; ALL: }
1544 ; ALL: {
1545 ; ALL: Name: .reloc
1546 ; ALL: Virtual Size: 8
1547 ; ALL: Virtual Address: 20480
1548 ; ALL: Size of Raw Data: 512
1549 ; ALL: File Pointer to Raw Data: 6656
1550 ; ALL: File Pointer to Relocations: 0
1551 ; ALL: File Pointer to Linenumbers: 0
1552 ; ALL: Number of Relocations: 0
1553 ; ALL: Number of Linenumbers: 0
1554 ; ALL: Characteristics: 1107296320
1555 ; ALL: }
1556 ; ALL: ]
14571557
14581558 ; BIG: FileHeaders {
14591559 ; BIG-NEXT: BlockSize: 4096
5252 #include "llvm/DebugInfo/PDB/Raw/RawError.h"
5353 #include "llvm/DebugInfo/PDB/Raw/RawSession.h"
5454 #include "llvm/DebugInfo/PDB/Raw/TpiStream.h"
55 #include "llvm/Object/COFF.h"
5556 #include "llvm/Support/COM.h"
5657 #include "llvm/Support/CommandLine.h"
5758 #include "llvm/Support/ConvertUTF.h"
148149 DumpSymRecordBytes("raw-sym-record-bytes",
149150 cl::desc("dump CodeView symbol record raw bytes"),
150151 cl::cat(NativeOptions));
152 cl::opt DumpSectionHeaders("raw-section-headers",
153 cl::desc("dump section headers"),
154 cl::cat(NativeOptions));
155
151156 cl::opt
152157 RawAll("raw-all",
153158 cl::desc("Implies most other options in 'Native Options' category"),
690695 return Error::success();
691696 }
692697
698 static Error dumpSectionHeaders(ScopedPrinter &P, PDBFile &File,
699 codeview::CVTypeDumper &TD) {
700 if (!opts::DumpSectionHeaders)
701 return Error::success();
702
703 auto DbiS = File.getPDBDbiStream();
704 if (auto EC = DbiS.takeError())
705 return EC;
706 DbiStream &DS = DbiS.get();
707
708 ListScope D(P, "Section Headers");
709 for (const object::coff_section &Section : DS.getSectionHeaders()) {
710 DictScope DD(P, "");
711
712 // If a name is 8 characters long, there is no NUL character at end.
713 StringRef Name(Section.Name, strnlen(Section.Name, sizeof(Section.Name)));
714 P.printString("Name", Name);
715 P.printNumber("Virtual Size", Section.VirtualSize);
716 P.printNumber("Virtual Address", Section.VirtualAddress);
717 P.printNumber("Size of Raw Data", Section.SizeOfRawData);
718 P.printNumber("File Pointer to Raw Data", Section.PointerToRawData);
719 P.printNumber("File Pointer to Relocations", Section.PointerToRelocations);
720 P.printNumber("File Pointer to Linenumbers", Section.PointerToLinenumbers);
721 P.printNumber("Number of Relocations", Section.NumberOfRelocations);
722 P.printNumber("Number of Linenumbers", Section.NumberOfLinenumbers);
723 P.printNumber("Characteristics", Section.Characteristics);
724 }
725 return Error::success();
726 }
727
693728 static Error dumpStructure(RawSession &RS) {
694729 PDBFile &File = RS.getPDBFile();
695730 ScopedPrinter P(outs());
715750 codeview::CVTypeDumper TD(&P, false);
716751 if (auto EC = dumpTpiStream(P, File, TD, StreamTPI))
717752 return EC;
753
718754 if (auto EC = dumpTpiStream(P, File, TD, StreamIPI))
719755 return EC;
720756
730766 if (auto EC = dumpPublicsStream(P, File, TD))
731767 return EC;
732768
769 if (auto EC = dumpSectionHeaders(P, File, TD))
770 return EC;
733771 return Error::success();
734772 }
735773
926964 opts::DumpModuleFiles = true;
927965 opts::DumpModuleSyms = true;
928966 opts::DumpPublics = true;
967 opts::DumpSectionHeaders = true;
929968 opts::DumpStreamSummary = true;
930969 opts::DumpStreamBlocks = true;
931970 opts::DumpTpiRecords = true;