File: | build/source/llvm/lib/DebugInfo/LogicalView/Readers/LVBinaryReader.cpp |
Warning: | line 450, column 3 Potential leak of memory pointed to by 'Instructions' |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | //===-- LVBinaryReader.cpp ------------------------------------------------===// | |||
2 | // | |||
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | |||
4 | // See https://llvm.org/LICENSE.txt for license information. | |||
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | |||
6 | // | |||
7 | //===----------------------------------------------------------------------===// | |||
8 | // | |||
9 | // This implements the LVBinaryReader class. | |||
10 | // | |||
11 | //===----------------------------------------------------------------------===// | |||
12 | ||||
13 | #include "llvm/DebugInfo/LogicalView/Readers/LVBinaryReader.h" | |||
14 | #include "llvm/Support/Errc.h" | |||
15 | #include "llvm/Support/FormatAdapters.h" | |||
16 | #include "llvm/Support/FormatVariadic.h" | |||
17 | ||||
18 | using namespace llvm; | |||
19 | using namespace llvm::logicalview; | |||
20 | ||||
21 | #define DEBUG_TYPE"BinaryReader" "BinaryReader" | |||
22 | ||||
23 | // Function names extracted from the object symbol table. | |||
24 | void LVSymbolTable::add(StringRef Name, LVScope *Function, | |||
25 | LVSectionIndex SectionIndex) { | |||
26 | std::string SymbolName(Name); | |||
27 | if (SymbolNames.find(SymbolName) == SymbolNames.end()) { | |||
28 | SymbolNames.emplace( | |||
29 | std::piecewise_construct, std::forward_as_tuple(SymbolName), | |||
30 | std::forward_as_tuple(Function, 0, SectionIndex, false)); | |||
31 | } else { | |||
32 | // Update a recorded entry with its logical scope and section index. | |||
33 | SymbolNames[SymbolName].Scope = Function; | |||
34 | if (SectionIndex) | |||
35 | SymbolNames[SymbolName].SectionIndex = SectionIndex; | |||
36 | } | |||
37 | ||||
38 | if (Function && SymbolNames[SymbolName].IsComdat) | |||
39 | Function->setIsComdat(); | |||
40 | ||||
41 | LLVM_DEBUG({ print(dbgs()); })do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { print(dbgs()); }; } } while (false); | |||
42 | } | |||
43 | ||||
44 | void LVSymbolTable::add(StringRef Name, LVAddress Address, | |||
45 | LVSectionIndex SectionIndex, bool IsComdat) { | |||
46 | std::string SymbolName(Name); | |||
47 | if (SymbolNames.find(SymbolName) == SymbolNames.end()) | |||
48 | SymbolNames.emplace( | |||
49 | std::piecewise_construct, std::forward_as_tuple(SymbolName), | |||
50 | std::forward_as_tuple(nullptr, Address, SectionIndex, IsComdat)); | |||
51 | else | |||
52 | // Update a recorded symbol name with its logical scope. | |||
53 | SymbolNames[SymbolName].Address = Address; | |||
54 | ||||
55 | LVScope *Function = SymbolNames[SymbolName].Scope; | |||
56 | if (Function && IsComdat) | |||
57 | Function->setIsComdat(); | |||
58 | LLVM_DEBUG({ print(dbgs()); })do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { print(dbgs()); }; } } while (false); | |||
59 | } | |||
60 | ||||
61 | LVSectionIndex LVSymbolTable::update(LVScope *Function) { | |||
62 | LVSectionIndex SectionIndex = getReader().getDotTextSectionIndex(); | |||
63 | StringRef Name = Function->getLinkageName(); | |||
64 | if (Name.empty()) | |||
65 | Name = Function->getName(); | |||
66 | std::string SymbolName(Name); | |||
67 | ||||
68 | if (SymbolName.empty() || (SymbolNames.find(SymbolName) == SymbolNames.end())) | |||
69 | return SectionIndex; | |||
70 | ||||
71 | // Update a recorded entry with its logical scope, only if the scope has | |||
72 | // ranges. That is the case when in DWARF there are 2 DIEs connected via | |||
73 | // the DW_AT_specification. | |||
74 | if (Function->getHasRanges()) { | |||
75 | SymbolNames[SymbolName].Scope = Function; | |||
76 | SectionIndex = SymbolNames[SymbolName].SectionIndex; | |||
77 | } else { | |||
78 | SectionIndex = UndefinedSectionIndex; | |||
79 | } | |||
80 | ||||
81 | if (SymbolNames[SymbolName].IsComdat) | |||
82 | Function->setIsComdat(); | |||
83 | ||||
84 | LLVM_DEBUG({ print(dbgs()); })do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { print(dbgs()); }; } } while (false); | |||
85 | return SectionIndex; | |||
86 | } | |||
87 | ||||
88 | const LVSymbolTableEntry &LVSymbolTable::getEntry(StringRef Name) { | |||
89 | static LVSymbolTableEntry Empty = LVSymbolTableEntry(); | |||
90 | LVSymbolNames::iterator Iter = SymbolNames.find(std::string(Name)); | |||
91 | return Iter != SymbolNames.end() ? Iter->second : Empty; | |||
92 | } | |||
93 | LVAddress LVSymbolTable::getAddress(StringRef Name) { | |||
94 | LVSymbolNames::iterator Iter = SymbolNames.find(std::string(Name)); | |||
95 | return Iter != SymbolNames.end() ? Iter->second.Address : 0; | |||
96 | } | |||
97 | LVSectionIndex LVSymbolTable::getIndex(StringRef Name) { | |||
98 | LVSymbolNames::iterator Iter = SymbolNames.find(std::string(Name)); | |||
99 | return Iter != SymbolNames.end() ? Iter->second.SectionIndex | |||
100 | : getReader().getDotTextSectionIndex(); | |||
101 | } | |||
102 | bool LVSymbolTable::getIsComdat(StringRef Name) { | |||
103 | LVSymbolNames::iterator Iter = SymbolNames.find(std::string(Name)); | |||
104 | return Iter != SymbolNames.end() ? Iter->second.IsComdat : false; | |||
105 | } | |||
106 | ||||
107 | void LVSymbolTable::print(raw_ostream &OS) { | |||
108 | OS << "Symbol Table\n"; | |||
109 | for (LVSymbolNames::reference Entry : SymbolNames) { | |||
110 | LVSymbolTableEntry &SymbolName = Entry.second; | |||
111 | LVScope *Scope = SymbolName.Scope; | |||
112 | LVOffset Offset = Scope ? Scope->getOffset() : 0; | |||
113 | OS << "Index: " << hexValue(SymbolName.SectionIndex, 5) | |||
114 | << " Comdat: " << (SymbolName.IsComdat ? "Y" : "N") | |||
115 | << " Scope: " << hexValue(Offset) | |||
116 | << " Address: " << hexValue(SymbolName.Address) | |||
117 | << " Name: " << Entry.first << "\n"; | |||
118 | } | |||
119 | } | |||
120 | ||||
121 | void LVBinaryReader::addToSymbolTable(StringRef Name, LVScope *Function, | |||
122 | LVSectionIndex SectionIndex) { | |||
123 | SymbolTable.add(Name, Function, SectionIndex); | |||
124 | } | |||
125 | void LVBinaryReader::addToSymbolTable(StringRef Name, LVAddress Address, | |||
126 | LVSectionIndex SectionIndex, | |||
127 | bool IsComdat) { | |||
128 | SymbolTable.add(Name, Address, SectionIndex, IsComdat); | |||
129 | } | |||
130 | LVSectionIndex LVBinaryReader::updateSymbolTable(LVScope *Function) { | |||
131 | return SymbolTable.update(Function); | |||
132 | } | |||
133 | ||||
134 | const LVSymbolTableEntry &LVBinaryReader::getSymbolTableEntry(StringRef Name) { | |||
135 | return SymbolTable.getEntry(Name); | |||
136 | } | |||
137 | LVAddress LVBinaryReader::getSymbolTableAddress(StringRef Name) { | |||
138 | return SymbolTable.getAddress(Name); | |||
139 | } | |||
140 | LVSectionIndex LVBinaryReader::getSymbolTableIndex(StringRef Name) { | |||
141 | return SymbolTable.getIndex(Name); | |||
142 | } | |||
143 | bool LVBinaryReader::getSymbolTableIsComdat(StringRef Name) { | |||
144 | return SymbolTable.getIsComdat(Name); | |||
145 | } | |||
146 | ||||
147 | void LVBinaryReader::mapVirtualAddress(const object::ObjectFile &Obj) { | |||
148 | for (const object::SectionRef &Section : Obj.sections()) { | |||
149 | if (!Section.isText() || Section.isVirtual() || !Section.getSize()) | |||
150 | continue; | |||
151 | ||||
152 | // Record section information required for symbol resolution. | |||
153 | // Note: The section index returned by 'getIndex()' is one based. | |||
154 | Sections.emplace(Section.getIndex(), Section); | |||
155 | addSectionAddress(Section); | |||
156 | ||||
157 | // Identify the ".text" section. | |||
158 | Expected<StringRef> SectionNameOrErr = Section.getName(); | |||
159 | if (!SectionNameOrErr) { | |||
160 | consumeError(SectionNameOrErr.takeError()); | |||
161 | continue; | |||
162 | } | |||
163 | if ((*SectionNameOrErr).equals(".text") || | |||
164 | (*SectionNameOrErr).equals(".code")) | |||
165 | DotTextSectionIndex = Section.getIndex(); | |||
166 | } | |||
167 | ||||
168 | // Process the symbol table. | |||
169 | mapRangeAddress(Obj); | |||
170 | ||||
171 | LLVM_DEBUG({do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { dbgs() << "\nSections Information:\n" ; for (LVSections::reference Entry : Sections) { LVSectionIndex SectionIndex = Entry.first; const object::SectionRef Section = Entry.second; Expected<StringRef> SectionNameOrErr = Section.getName(); if (!SectionNameOrErr) consumeError(SectionNameOrErr .takeError()); dbgs() << "\nIndex: " << format_decimal (SectionIndex, 3) << " Name: " << *SectionNameOrErr << "\n" << "Size: " << hexValue(Section.getSize ()) << "\n" << "VirtualAddress: " << hexValue (VirtualAddress) << "\n" << "SectionAddress: " << hexValue(Section.getAddress()) << "\n"; } dbgs() << "\nObject Section Information:\n"; for (LVSectionAddresses:: const_reference Entry : SectionAddresses) dbgs() << "[" << hexValue(Entry.first) << ":" << hexValue (Entry.first + Entry.second.getSize()) << "] Size: " << hexValue(Entry.second.getSize()) << "\n"; }; } } while (false) | |||
172 | dbgs() << "\nSections Information:\n";do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { dbgs() << "\nSections Information:\n" ; for (LVSections::reference Entry : Sections) { LVSectionIndex SectionIndex = Entry.first; const object::SectionRef Section = Entry.second; Expected<StringRef> SectionNameOrErr = Section.getName(); if (!SectionNameOrErr) consumeError(SectionNameOrErr .takeError()); dbgs() << "\nIndex: " << format_decimal (SectionIndex, 3) << " Name: " << *SectionNameOrErr << "\n" << "Size: " << hexValue(Section.getSize ()) << "\n" << "VirtualAddress: " << hexValue (VirtualAddress) << "\n" << "SectionAddress: " << hexValue(Section.getAddress()) << "\n"; } dbgs() << "\nObject Section Information:\n"; for (LVSectionAddresses:: const_reference Entry : SectionAddresses) dbgs() << "[" << hexValue(Entry.first) << ":" << hexValue (Entry.first + Entry.second.getSize()) << "] Size: " << hexValue(Entry.second.getSize()) << "\n"; }; } } while (false) | |||
173 | for (LVSections::reference Entry : Sections) {do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { dbgs() << "\nSections Information:\n" ; for (LVSections::reference Entry : Sections) { LVSectionIndex SectionIndex = Entry.first; const object::SectionRef Section = Entry.second; Expected<StringRef> SectionNameOrErr = Section.getName(); if (!SectionNameOrErr) consumeError(SectionNameOrErr .takeError()); dbgs() << "\nIndex: " << format_decimal (SectionIndex, 3) << " Name: " << *SectionNameOrErr << "\n" << "Size: " << hexValue(Section.getSize ()) << "\n" << "VirtualAddress: " << hexValue (VirtualAddress) << "\n" << "SectionAddress: " << hexValue(Section.getAddress()) << "\n"; } dbgs() << "\nObject Section Information:\n"; for (LVSectionAddresses:: const_reference Entry : SectionAddresses) dbgs() << "[" << hexValue(Entry.first) << ":" << hexValue (Entry.first + Entry.second.getSize()) << "] Size: " << hexValue(Entry.second.getSize()) << "\n"; }; } } while (false) | |||
174 | LVSectionIndex SectionIndex = Entry.first;do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { dbgs() << "\nSections Information:\n" ; for (LVSections::reference Entry : Sections) { LVSectionIndex SectionIndex = Entry.first; const object::SectionRef Section = Entry.second; Expected<StringRef> SectionNameOrErr = Section.getName(); if (!SectionNameOrErr) consumeError(SectionNameOrErr .takeError()); dbgs() << "\nIndex: " << format_decimal (SectionIndex, 3) << " Name: " << *SectionNameOrErr << "\n" << "Size: " << hexValue(Section.getSize ()) << "\n" << "VirtualAddress: " << hexValue (VirtualAddress) << "\n" << "SectionAddress: " << hexValue(Section.getAddress()) << "\n"; } dbgs() << "\nObject Section Information:\n"; for (LVSectionAddresses:: const_reference Entry : SectionAddresses) dbgs() << "[" << hexValue(Entry.first) << ":" << hexValue (Entry.first + Entry.second.getSize()) << "] Size: " << hexValue(Entry.second.getSize()) << "\n"; }; } } while (false) | |||
175 | const object::SectionRef Section = Entry.second;do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { dbgs() << "\nSections Information:\n" ; for (LVSections::reference Entry : Sections) { LVSectionIndex SectionIndex = Entry.first; const object::SectionRef Section = Entry.second; Expected<StringRef> SectionNameOrErr = Section.getName(); if (!SectionNameOrErr) consumeError(SectionNameOrErr .takeError()); dbgs() << "\nIndex: " << format_decimal (SectionIndex, 3) << " Name: " << *SectionNameOrErr << "\n" << "Size: " << hexValue(Section.getSize ()) << "\n" << "VirtualAddress: " << hexValue (VirtualAddress) << "\n" << "SectionAddress: " << hexValue(Section.getAddress()) << "\n"; } dbgs() << "\nObject Section Information:\n"; for (LVSectionAddresses:: const_reference Entry : SectionAddresses) dbgs() << "[" << hexValue(Entry.first) << ":" << hexValue (Entry.first + Entry.second.getSize()) << "] Size: " << hexValue(Entry.second.getSize()) << "\n"; }; } } while (false) | |||
176 | Expected<StringRef> SectionNameOrErr = Section.getName();do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { dbgs() << "\nSections Information:\n" ; for (LVSections::reference Entry : Sections) { LVSectionIndex SectionIndex = Entry.first; const object::SectionRef Section = Entry.second; Expected<StringRef> SectionNameOrErr = Section.getName(); if (!SectionNameOrErr) consumeError(SectionNameOrErr .takeError()); dbgs() << "\nIndex: " << format_decimal (SectionIndex, 3) << " Name: " << *SectionNameOrErr << "\n" << "Size: " << hexValue(Section.getSize ()) << "\n" << "VirtualAddress: " << hexValue (VirtualAddress) << "\n" << "SectionAddress: " << hexValue(Section.getAddress()) << "\n"; } dbgs() << "\nObject Section Information:\n"; for (LVSectionAddresses:: const_reference Entry : SectionAddresses) dbgs() << "[" << hexValue(Entry.first) << ":" << hexValue (Entry.first + Entry.second.getSize()) << "] Size: " << hexValue(Entry.second.getSize()) << "\n"; }; } } while (false) | |||
177 | if (!SectionNameOrErr)do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { dbgs() << "\nSections Information:\n" ; for (LVSections::reference Entry : Sections) { LVSectionIndex SectionIndex = Entry.first; const object::SectionRef Section = Entry.second; Expected<StringRef> SectionNameOrErr = Section.getName(); if (!SectionNameOrErr) consumeError(SectionNameOrErr .takeError()); dbgs() << "\nIndex: " << format_decimal (SectionIndex, 3) << " Name: " << *SectionNameOrErr << "\n" << "Size: " << hexValue(Section.getSize ()) << "\n" << "VirtualAddress: " << hexValue (VirtualAddress) << "\n" << "SectionAddress: " << hexValue(Section.getAddress()) << "\n"; } dbgs() << "\nObject Section Information:\n"; for (LVSectionAddresses:: const_reference Entry : SectionAddresses) dbgs() << "[" << hexValue(Entry.first) << ":" << hexValue (Entry.first + Entry.second.getSize()) << "] Size: " << hexValue(Entry.second.getSize()) << "\n"; }; } } while (false) | |||
178 | consumeError(SectionNameOrErr.takeError());do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { dbgs() << "\nSections Information:\n" ; for (LVSections::reference Entry : Sections) { LVSectionIndex SectionIndex = Entry.first; const object::SectionRef Section = Entry.second; Expected<StringRef> SectionNameOrErr = Section.getName(); if (!SectionNameOrErr) consumeError(SectionNameOrErr .takeError()); dbgs() << "\nIndex: " << format_decimal (SectionIndex, 3) << " Name: " << *SectionNameOrErr << "\n" << "Size: " << hexValue(Section.getSize ()) << "\n" << "VirtualAddress: " << hexValue (VirtualAddress) << "\n" << "SectionAddress: " << hexValue(Section.getAddress()) << "\n"; } dbgs() << "\nObject Section Information:\n"; for (LVSectionAddresses:: const_reference Entry : SectionAddresses) dbgs() << "[" << hexValue(Entry.first) << ":" << hexValue (Entry.first + Entry.second.getSize()) << "] Size: " << hexValue(Entry.second.getSize()) << "\n"; }; } } while (false) | |||
179 | dbgs() << "\nIndex: " << format_decimal(SectionIndex, 3)do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { dbgs() << "\nSections Information:\n" ; for (LVSections::reference Entry : Sections) { LVSectionIndex SectionIndex = Entry.first; const object::SectionRef Section = Entry.second; Expected<StringRef> SectionNameOrErr = Section.getName(); if (!SectionNameOrErr) consumeError(SectionNameOrErr .takeError()); dbgs() << "\nIndex: " << format_decimal (SectionIndex, 3) << " Name: " << *SectionNameOrErr << "\n" << "Size: " << hexValue(Section.getSize ()) << "\n" << "VirtualAddress: " << hexValue (VirtualAddress) << "\n" << "SectionAddress: " << hexValue(Section.getAddress()) << "\n"; } dbgs() << "\nObject Section Information:\n"; for (LVSectionAddresses:: const_reference Entry : SectionAddresses) dbgs() << "[" << hexValue(Entry.first) << ":" << hexValue (Entry.first + Entry.second.getSize()) << "] Size: " << hexValue(Entry.second.getSize()) << "\n"; }; } } while (false) | |||
180 | << " Name: " << *SectionNameOrErr << "\n"do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { dbgs() << "\nSections Information:\n" ; for (LVSections::reference Entry : Sections) { LVSectionIndex SectionIndex = Entry.first; const object::SectionRef Section = Entry.second; Expected<StringRef> SectionNameOrErr = Section.getName(); if (!SectionNameOrErr) consumeError(SectionNameOrErr .takeError()); dbgs() << "\nIndex: " << format_decimal (SectionIndex, 3) << " Name: " << *SectionNameOrErr << "\n" << "Size: " << hexValue(Section.getSize ()) << "\n" << "VirtualAddress: " << hexValue (VirtualAddress) << "\n" << "SectionAddress: " << hexValue(Section.getAddress()) << "\n"; } dbgs() << "\nObject Section Information:\n"; for (LVSectionAddresses:: const_reference Entry : SectionAddresses) dbgs() << "[" << hexValue(Entry.first) << ":" << hexValue (Entry.first + Entry.second.getSize()) << "] Size: " << hexValue(Entry.second.getSize()) << "\n"; }; } } while (false) | |||
181 | << "Size: " << hexValue(Section.getSize()) << "\n"do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { dbgs() << "\nSections Information:\n" ; for (LVSections::reference Entry : Sections) { LVSectionIndex SectionIndex = Entry.first; const object::SectionRef Section = Entry.second; Expected<StringRef> SectionNameOrErr = Section.getName(); if (!SectionNameOrErr) consumeError(SectionNameOrErr .takeError()); dbgs() << "\nIndex: " << format_decimal (SectionIndex, 3) << " Name: " << *SectionNameOrErr << "\n" << "Size: " << hexValue(Section.getSize ()) << "\n" << "VirtualAddress: " << hexValue (VirtualAddress) << "\n" << "SectionAddress: " << hexValue(Section.getAddress()) << "\n"; } dbgs() << "\nObject Section Information:\n"; for (LVSectionAddresses:: const_reference Entry : SectionAddresses) dbgs() << "[" << hexValue(Entry.first) << ":" << hexValue (Entry.first + Entry.second.getSize()) << "] Size: " << hexValue(Entry.second.getSize()) << "\n"; }; } } while (false) | |||
182 | << "VirtualAddress: " << hexValue(VirtualAddress) << "\n"do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { dbgs() << "\nSections Information:\n" ; for (LVSections::reference Entry : Sections) { LVSectionIndex SectionIndex = Entry.first; const object::SectionRef Section = Entry.second; Expected<StringRef> SectionNameOrErr = Section.getName(); if (!SectionNameOrErr) consumeError(SectionNameOrErr .takeError()); dbgs() << "\nIndex: " << format_decimal (SectionIndex, 3) << " Name: " << *SectionNameOrErr << "\n" << "Size: " << hexValue(Section.getSize ()) << "\n" << "VirtualAddress: " << hexValue (VirtualAddress) << "\n" << "SectionAddress: " << hexValue(Section.getAddress()) << "\n"; } dbgs() << "\nObject Section Information:\n"; for (LVSectionAddresses:: const_reference Entry : SectionAddresses) dbgs() << "[" << hexValue(Entry.first) << ":" << hexValue (Entry.first + Entry.second.getSize()) << "] Size: " << hexValue(Entry.second.getSize()) << "\n"; }; } } while (false) | |||
183 | << "SectionAddress: " << hexValue(Section.getAddress()) << "\n";do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { dbgs() << "\nSections Information:\n" ; for (LVSections::reference Entry : Sections) { LVSectionIndex SectionIndex = Entry.first; const object::SectionRef Section = Entry.second; Expected<StringRef> SectionNameOrErr = Section.getName(); if (!SectionNameOrErr) consumeError(SectionNameOrErr .takeError()); dbgs() << "\nIndex: " << format_decimal (SectionIndex, 3) << " Name: " << *SectionNameOrErr << "\n" << "Size: " << hexValue(Section.getSize ()) << "\n" << "VirtualAddress: " << hexValue (VirtualAddress) << "\n" << "SectionAddress: " << hexValue(Section.getAddress()) << "\n"; } dbgs() << "\nObject Section Information:\n"; for (LVSectionAddresses:: const_reference Entry : SectionAddresses) dbgs() << "[" << hexValue(Entry.first) << ":" << hexValue (Entry.first + Entry.second.getSize()) << "] Size: " << hexValue(Entry.second.getSize()) << "\n"; }; } } while (false) | |||
184 | }do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { dbgs() << "\nSections Information:\n" ; for (LVSections::reference Entry : Sections) { LVSectionIndex SectionIndex = Entry.first; const object::SectionRef Section = Entry.second; Expected<StringRef> SectionNameOrErr = Section.getName(); if (!SectionNameOrErr) consumeError(SectionNameOrErr .takeError()); dbgs() << "\nIndex: " << format_decimal (SectionIndex, 3) << " Name: " << *SectionNameOrErr << "\n" << "Size: " << hexValue(Section.getSize ()) << "\n" << "VirtualAddress: " << hexValue (VirtualAddress) << "\n" << "SectionAddress: " << hexValue(Section.getAddress()) << "\n"; } dbgs() << "\nObject Section Information:\n"; for (LVSectionAddresses:: const_reference Entry : SectionAddresses) dbgs() << "[" << hexValue(Entry.first) << ":" << hexValue (Entry.first + Entry.second.getSize()) << "] Size: " << hexValue(Entry.second.getSize()) << "\n"; }; } } while (false) | |||
185 | dbgs() << "\nObject Section Information:\n";do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { dbgs() << "\nSections Information:\n" ; for (LVSections::reference Entry : Sections) { LVSectionIndex SectionIndex = Entry.first; const object::SectionRef Section = Entry.second; Expected<StringRef> SectionNameOrErr = Section.getName(); if (!SectionNameOrErr) consumeError(SectionNameOrErr .takeError()); dbgs() << "\nIndex: " << format_decimal (SectionIndex, 3) << " Name: " << *SectionNameOrErr << "\n" << "Size: " << hexValue(Section.getSize ()) << "\n" << "VirtualAddress: " << hexValue (VirtualAddress) << "\n" << "SectionAddress: " << hexValue(Section.getAddress()) << "\n"; } dbgs() << "\nObject Section Information:\n"; for (LVSectionAddresses:: const_reference Entry : SectionAddresses) dbgs() << "[" << hexValue(Entry.first) << ":" << hexValue (Entry.first + Entry.second.getSize()) << "] Size: " << hexValue(Entry.second.getSize()) << "\n"; }; } } while (false) | |||
186 | for (LVSectionAddresses::const_reference Entry : SectionAddresses)do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { dbgs() << "\nSections Information:\n" ; for (LVSections::reference Entry : Sections) { LVSectionIndex SectionIndex = Entry.first; const object::SectionRef Section = Entry.second; Expected<StringRef> SectionNameOrErr = Section.getName(); if (!SectionNameOrErr) consumeError(SectionNameOrErr .takeError()); dbgs() << "\nIndex: " << format_decimal (SectionIndex, 3) << " Name: " << *SectionNameOrErr << "\n" << "Size: " << hexValue(Section.getSize ()) << "\n" << "VirtualAddress: " << hexValue (VirtualAddress) << "\n" << "SectionAddress: " << hexValue(Section.getAddress()) << "\n"; } dbgs() << "\nObject Section Information:\n"; for (LVSectionAddresses:: const_reference Entry : SectionAddresses) dbgs() << "[" << hexValue(Entry.first) << ":" << hexValue (Entry.first + Entry.second.getSize()) << "] Size: " << hexValue(Entry.second.getSize()) << "\n"; }; } } while (false) | |||
187 | dbgs() << "[" << hexValue(Entry.first) << ":"do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { dbgs() << "\nSections Information:\n" ; for (LVSections::reference Entry : Sections) { LVSectionIndex SectionIndex = Entry.first; const object::SectionRef Section = Entry.second; Expected<StringRef> SectionNameOrErr = Section.getName(); if (!SectionNameOrErr) consumeError(SectionNameOrErr .takeError()); dbgs() << "\nIndex: " << format_decimal (SectionIndex, 3) << " Name: " << *SectionNameOrErr << "\n" << "Size: " << hexValue(Section.getSize ()) << "\n" << "VirtualAddress: " << hexValue (VirtualAddress) << "\n" << "SectionAddress: " << hexValue(Section.getAddress()) << "\n"; } dbgs() << "\nObject Section Information:\n"; for (LVSectionAddresses:: const_reference Entry : SectionAddresses) dbgs() << "[" << hexValue(Entry.first) << ":" << hexValue (Entry.first + Entry.second.getSize()) << "] Size: " << hexValue(Entry.second.getSize()) << "\n"; }; } } while (false) | |||
188 | << hexValue(Entry.first + Entry.second.getSize())do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { dbgs() << "\nSections Information:\n" ; for (LVSections::reference Entry : Sections) { LVSectionIndex SectionIndex = Entry.first; const object::SectionRef Section = Entry.second; Expected<StringRef> SectionNameOrErr = Section.getName(); if (!SectionNameOrErr) consumeError(SectionNameOrErr .takeError()); dbgs() << "\nIndex: " << format_decimal (SectionIndex, 3) << " Name: " << *SectionNameOrErr << "\n" << "Size: " << hexValue(Section.getSize ()) << "\n" << "VirtualAddress: " << hexValue (VirtualAddress) << "\n" << "SectionAddress: " << hexValue(Section.getAddress()) << "\n"; } dbgs() << "\nObject Section Information:\n"; for (LVSectionAddresses:: const_reference Entry : SectionAddresses) dbgs() << "[" << hexValue(Entry.first) << ":" << hexValue (Entry.first + Entry.second.getSize()) << "] Size: " << hexValue(Entry.second.getSize()) << "\n"; }; } } while (false) | |||
189 | << "] Size: " << hexValue(Entry.second.getSize()) << "\n";do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { dbgs() << "\nSections Information:\n" ; for (LVSections::reference Entry : Sections) { LVSectionIndex SectionIndex = Entry.first; const object::SectionRef Section = Entry.second; Expected<StringRef> SectionNameOrErr = Section.getName(); if (!SectionNameOrErr) consumeError(SectionNameOrErr .takeError()); dbgs() << "\nIndex: " << format_decimal (SectionIndex, 3) << " Name: " << *SectionNameOrErr << "\n" << "Size: " << hexValue(Section.getSize ()) << "\n" << "VirtualAddress: " << hexValue (VirtualAddress) << "\n" << "SectionAddress: " << hexValue(Section.getAddress()) << "\n"; } dbgs() << "\nObject Section Information:\n"; for (LVSectionAddresses:: const_reference Entry : SectionAddresses) dbgs() << "[" << hexValue(Entry.first) << ":" << hexValue (Entry.first + Entry.second.getSize()) << "] Size: " << hexValue(Entry.second.getSize()) << "\n"; }; } } while (false) | |||
190 | })do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { dbgs() << "\nSections Information:\n" ; for (LVSections::reference Entry : Sections) { LVSectionIndex SectionIndex = Entry.first; const object::SectionRef Section = Entry.second; Expected<StringRef> SectionNameOrErr = Section.getName(); if (!SectionNameOrErr) consumeError(SectionNameOrErr .takeError()); dbgs() << "\nIndex: " << format_decimal (SectionIndex, 3) << " Name: " << *SectionNameOrErr << "\n" << "Size: " << hexValue(Section.getSize ()) << "\n" << "VirtualAddress: " << hexValue (VirtualAddress) << "\n" << "SectionAddress: " << hexValue(Section.getAddress()) << "\n"; } dbgs() << "\nObject Section Information:\n"; for (LVSectionAddresses:: const_reference Entry : SectionAddresses) dbgs() << "[" << hexValue(Entry.first) << ":" << hexValue (Entry.first + Entry.second.getSize()) << "] Size: " << hexValue(Entry.second.getSize()) << "\n"; }; } } while (false); | |||
191 | } | |||
192 | ||||
193 | Error LVBinaryReader::loadGenericTargetInfo(StringRef TheTriple, | |||
194 | StringRef TheFeatures) { | |||
195 | std::string TargetLookupError; | |||
196 | const Target *TheTarget = | |||
197 | TargetRegistry::lookupTarget(std::string(TheTriple), TargetLookupError); | |||
198 | if (!TheTarget) | |||
199 | return createStringError(errc::invalid_argument, TargetLookupError.c_str()); | |||
200 | ||||
201 | // Register information. | |||
202 | MCRegisterInfo *RegisterInfo = TheTarget->createMCRegInfo(TheTriple); | |||
203 | if (!RegisterInfo) | |||
204 | return createStringError(errc::invalid_argument, | |||
205 | "no register info for target " + TheTriple); | |||
206 | MRI.reset(RegisterInfo); | |||
207 | ||||
208 | // Assembler properties and features. | |||
209 | MCTargetOptions MCOptions; | |||
210 | MCAsmInfo *AsmInfo(TheTarget->createMCAsmInfo(*MRI, TheTriple, MCOptions)); | |||
211 | if (!AsmInfo) | |||
212 | return createStringError(errc::invalid_argument, | |||
213 | "no assembly info for target " + TheTriple); | |||
214 | MAI.reset(AsmInfo); | |||
215 | ||||
216 | // Target subtargets. | |||
217 | StringRef CPU; | |||
218 | MCSubtargetInfo *SubtargetInfo( | |||
219 | TheTarget->createMCSubtargetInfo(TheTriple, CPU, TheFeatures)); | |||
220 | if (!SubtargetInfo) | |||
221 | return createStringError(errc::invalid_argument, | |||
222 | "no subtarget info for target " + TheTriple); | |||
223 | STI.reset(SubtargetInfo); | |||
224 | ||||
225 | // Instructions Info. | |||
226 | MCInstrInfo *InstructionInfo(TheTarget->createMCInstrInfo()); | |||
227 | if (!InstructionInfo) | |||
228 | return createStringError(errc::invalid_argument, | |||
229 | "no instruction info for target " + TheTriple); | |||
230 | MII.reset(InstructionInfo); | |||
231 | ||||
232 | MC = std::make_unique<MCContext>(Triple(TheTriple), MAI.get(), MRI.get(), | |||
233 | STI.get()); | |||
234 | ||||
235 | // Assembler. | |||
236 | MCDisassembler *DisAsm(TheTarget->createMCDisassembler(*STI, *MC)); | |||
237 | if (!DisAsm) | |||
238 | return createStringError(errc::invalid_argument, | |||
239 | "no disassembler for target " + TheTriple); | |||
240 | MD.reset(DisAsm); | |||
241 | ||||
242 | MCInstPrinter *InstructionPrinter(TheTarget->createMCInstPrinter( | |||
243 | Triple(TheTriple), AsmInfo->getAssemblerDialect(), *MAI, *MII, *MRI)); | |||
244 | if (!InstructionPrinter) | |||
245 | return createStringError(errc::invalid_argument, | |||
246 | "no target assembly language printer for target " + | |||
247 | TheTriple); | |||
248 | MIP.reset(InstructionPrinter); | |||
249 | InstructionPrinter->setPrintImmHex(true); | |||
250 | ||||
251 | return Error::success(); | |||
252 | } | |||
253 | ||||
254 | Expected<std::pair<uint64_t, object::SectionRef>> | |||
255 | LVBinaryReader::getSection(LVScope *Scope, LVAddress Address, | |||
256 | LVSectionIndex SectionIndex) { | |||
257 | // Return the 'text' section with the code for this logical scope. | |||
258 | // COFF: SectionIndex is zero. Use 'SectionAddresses' data. | |||
259 | // ELF: SectionIndex is the section index in the file. | |||
260 | if (SectionIndex) { | |||
261 | LVSections::iterator Iter = Sections.find(SectionIndex); | |||
262 | if (Iter == Sections.end()) { | |||
263 | return createStringError(errc::invalid_argument, | |||
264 | "invalid section index for: '%s'", | |||
265 | Scope->getName().str().c_str()); | |||
266 | } | |||
267 | const object::SectionRef Section = Iter->second; | |||
268 | return std::make_pair(Section.getAddress(), Section); | |||
269 | } | |||
270 | ||||
271 | // Ensure a valid starting address for the public names. | |||
272 | LVSectionAddresses::const_iterator Iter = | |||
273 | SectionAddresses.upper_bound(Address); | |||
274 | if (Iter == SectionAddresses.begin()) | |||
275 | return createStringError(errc::invalid_argument, | |||
276 | "invalid section address for: '%s'", | |||
277 | Scope->getName().str().c_str()); | |||
278 | ||||
279 | // Get section that contains the code for this function. | |||
280 | Iter = SectionAddresses.lower_bound(Address); | |||
281 | if (Iter != SectionAddresses.begin()) | |||
282 | --Iter; | |||
283 | return std::make_pair(Iter->first, Iter->second); | |||
284 | } | |||
285 | ||||
286 | void LVBinaryReader::addSectionRange(LVSectionIndex SectionIndex, | |||
287 | LVScope *Scope) { | |||
288 | LVRange *ScopesWithRanges = getSectionRanges(SectionIndex); | |||
289 | ScopesWithRanges->addEntry(Scope); | |||
290 | } | |||
291 | ||||
292 | void LVBinaryReader::addSectionRange(LVSectionIndex SectionIndex, | |||
293 | LVScope *Scope, LVAddress LowerAddress, | |||
294 | LVAddress UpperAddress) { | |||
295 | LVRange *ScopesWithRanges = getSectionRanges(SectionIndex); | |||
296 | ScopesWithRanges->addEntry(Scope, LowerAddress, UpperAddress); | |||
297 | } | |||
298 | ||||
299 | LVRange *LVBinaryReader::getSectionRanges(LVSectionIndex SectionIndex) { | |||
300 | LVRange *Range = nullptr; | |||
301 | // Check if we already have a mapping for this section index. | |||
302 | LVSectionRanges::iterator IterSection = SectionRanges.find(SectionIndex); | |||
303 | if (IterSection == SectionRanges.end()) { | |||
304 | Range = new LVRange(); | |||
305 | SectionRanges.emplace(SectionIndex, Range); | |||
306 | } else { | |||
307 | Range = IterSection->second; | |||
308 | } | |||
309 | assert(Range && "Range is null.")(static_cast <bool> (Range && "Range is null.") ? void (0) : __assert_fail ("Range && \"Range is null.\"" , "llvm/lib/DebugInfo/LogicalView/Readers/LVBinaryReader.cpp" , 309, __extension__ __PRETTY_FUNCTION__)); | |||
310 | return Range; | |||
311 | } | |||
312 | ||||
313 | LVBinaryReader::~LVBinaryReader() { | |||
314 | // Delete the lines created by 'createInstructions'. | |||
315 | std::vector<LVLines *> AllInstructionLines = ScopeInstructions.find(); | |||
316 | for (LVLines *Entry : AllInstructionLines) | |||
317 | delete Entry; | |||
318 | // Delete the ranges created by 'getSectionRanges'. | |||
319 | for (LVSectionRanges::reference Entry : SectionRanges) | |||
320 | delete Entry.second; | |||
321 | } | |||
322 | ||||
323 | Error LVBinaryReader::createInstructions(LVScope *Scope, | |||
324 | LVSectionIndex SectionIndex, | |||
325 | const LVNameInfo &NameInfo) { | |||
326 | assert(Scope && "Scope is null.")(static_cast <bool> (Scope && "Scope is null.") ? void (0) : __assert_fail ("Scope && \"Scope is null.\"" , "llvm/lib/DebugInfo/LogicalView/Readers/LVBinaryReader.cpp" , 326, __extension__ __PRETTY_FUNCTION__)); | |||
327 | ||||
328 | // Skip stripped functions. | |||
329 | if (Scope->getIsDiscarded()) | |||
330 | return Error::success(); | |||
331 | ||||
332 | // Find associated address and size for the given function entry point. | |||
333 | LVAddress Address = NameInfo.first; | |||
334 | uint64_t Size = NameInfo.second; | |||
335 | ||||
336 | LLVM_DEBUG({do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { dbgs() << "\nPublic Name instructions: '" << Scope->getName() << "' / '" << Scope ->getLinkageName() << "'\n" << "DIE Offset: " << hexValue(Scope->getOffset()) << " Range: [" << hexValue(Address) << ":" << hexValue(Address + Size ) << "]\n"; }; } } while (false) | |||
337 | dbgs() << "\nPublic Name instructions: '" << Scope->getName() << "' / '"do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { dbgs() << "\nPublic Name instructions: '" << Scope->getName() << "' / '" << Scope ->getLinkageName() << "'\n" << "DIE Offset: " << hexValue(Scope->getOffset()) << " Range: [" << hexValue(Address) << ":" << hexValue(Address + Size ) << "]\n"; }; } } while (false) | |||
338 | << Scope->getLinkageName() << "'\n"do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { dbgs() << "\nPublic Name instructions: '" << Scope->getName() << "' / '" << Scope ->getLinkageName() << "'\n" << "DIE Offset: " << hexValue(Scope->getOffset()) << " Range: [" << hexValue(Address) << ":" << hexValue(Address + Size ) << "]\n"; }; } } while (false) | |||
339 | << "DIE Offset: " << hexValue(Scope->getOffset()) << " Range: ["do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { dbgs() << "\nPublic Name instructions: '" << Scope->getName() << "' / '" << Scope ->getLinkageName() << "'\n" << "DIE Offset: " << hexValue(Scope->getOffset()) << " Range: [" << hexValue(Address) << ":" << hexValue(Address + Size ) << "]\n"; }; } } while (false) | |||
340 | << hexValue(Address) << ":" << hexValue(Address + Size) << "]\n";do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { dbgs() << "\nPublic Name instructions: '" << Scope->getName() << "' / '" << Scope ->getLinkageName() << "'\n" << "DIE Offset: " << hexValue(Scope->getOffset()) << " Range: [" << hexValue(Address) << ":" << hexValue(Address + Size ) << "]\n"; }; } } while (false) | |||
341 | })do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { dbgs() << "\nPublic Name instructions: '" << Scope->getName() << "' / '" << Scope ->getLinkageName() << "'\n" << "DIE Offset: " << hexValue(Scope->getOffset()) << " Range: [" << hexValue(Address) << ":" << hexValue(Address + Size ) << "]\n"; }; } } while (false); | |||
342 | ||||
343 | Expected<std::pair<uint64_t, const object::SectionRef>> SectionOrErr = | |||
344 | getSection(Scope, Address, SectionIndex); | |||
345 | if (!SectionOrErr) | |||
346 | return SectionOrErr.takeError(); | |||
347 | const object::SectionRef Section = (*SectionOrErr).second; | |||
348 | uint64_t SectionAddress = (*SectionOrErr).first; | |||
349 | ||||
350 | Expected<StringRef> SectionContentsOrErr = Section.getContents(); | |||
351 | if (!SectionContentsOrErr) | |||
352 | return SectionOrErr.takeError(); | |||
353 | ||||
354 | // There are cases where the section size is smaller than the [LowPC,HighPC] | |||
355 | // range; it causes us to decode invalid addresses. The recorded size in the | |||
356 | // logical scope is one less than the real size. | |||
357 | LLVM_DEBUG({do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { dbgs() << " Size: " << hexValue (Size) << ", Section Size: " << hexValue(Section. getSize()) << "\n"; }; } } while (false) | |||
358 | dbgs() << " Size: " << hexValue(Size)do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { dbgs() << " Size: " << hexValue (Size) << ", Section Size: " << hexValue(Section. getSize()) << "\n"; }; } } while (false) | |||
359 | << ", Section Size: " << hexValue(Section.getSize()) << "\n";do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { dbgs() << " Size: " << hexValue (Size) << ", Section Size: " << hexValue(Section. getSize()) << "\n"; }; } } while (false) | |||
360 | })do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { dbgs() << " Size: " << hexValue (Size) << ", Section Size: " << hexValue(Section. getSize()) << "\n"; }; } } while (false); | |||
361 | Size = std::min(Size + 1, Section.getSize()); | |||
362 | ||||
363 | ArrayRef<uint8_t> Bytes = arrayRefFromStringRef(*SectionContentsOrErr); | |||
364 | uint64_t Offset = Address - SectionAddress; | |||
365 | uint8_t const *Begin = Bytes.data() + Offset; | |||
366 | uint8_t const *End = Bytes.data() + Offset + Size; | |||
367 | ||||
368 | LLVM_DEBUG({do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { Expected<StringRef> SectionNameOrErr = Section.getName(); if (!SectionNameOrErr) consumeError(SectionNameOrErr .takeError()); else dbgs() << "Section Index: " << hexValue(Section.getIndex()) << " [" << hexValue ((uint64_t)Section.getAddress()) << ":" << hexValue ((uint64_t)Section.getAddress() + Section.getSize(), 10) << "] Name: '" << *SectionNameOrErr << "'\n" << "Begin: " << hexValue((uint64_t)Begin) << ", End: " << hexValue((uint64_t)End) << "\n"; }; } } while (false) | |||
369 | Expected<StringRef> SectionNameOrErr = Section.getName();do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { Expected<StringRef> SectionNameOrErr = Section.getName(); if (!SectionNameOrErr) consumeError(SectionNameOrErr .takeError()); else dbgs() << "Section Index: " << hexValue(Section.getIndex()) << " [" << hexValue ((uint64_t)Section.getAddress()) << ":" << hexValue ((uint64_t)Section.getAddress() + Section.getSize(), 10) << "] Name: '" << *SectionNameOrErr << "'\n" << "Begin: " << hexValue((uint64_t)Begin) << ", End: " << hexValue((uint64_t)End) << "\n"; }; } } while (false) | |||
370 | if (!SectionNameOrErr)do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { Expected<StringRef> SectionNameOrErr = Section.getName(); if (!SectionNameOrErr) consumeError(SectionNameOrErr .takeError()); else dbgs() << "Section Index: " << hexValue(Section.getIndex()) << " [" << hexValue ((uint64_t)Section.getAddress()) << ":" << hexValue ((uint64_t)Section.getAddress() + Section.getSize(), 10) << "] Name: '" << *SectionNameOrErr << "'\n" << "Begin: " << hexValue((uint64_t)Begin) << ", End: " << hexValue((uint64_t)End) << "\n"; }; } } while (false) | |||
371 | consumeError(SectionNameOrErr.takeError());do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { Expected<StringRef> SectionNameOrErr = Section.getName(); if (!SectionNameOrErr) consumeError(SectionNameOrErr .takeError()); else dbgs() << "Section Index: " << hexValue(Section.getIndex()) << " [" << hexValue ((uint64_t)Section.getAddress()) << ":" << hexValue ((uint64_t)Section.getAddress() + Section.getSize(), 10) << "] Name: '" << *SectionNameOrErr << "'\n" << "Begin: " << hexValue((uint64_t)Begin) << ", End: " << hexValue((uint64_t)End) << "\n"; }; } } while (false) | |||
372 | elsedo { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { Expected<StringRef> SectionNameOrErr = Section.getName(); if (!SectionNameOrErr) consumeError(SectionNameOrErr .takeError()); else dbgs() << "Section Index: " << hexValue(Section.getIndex()) << " [" << hexValue ((uint64_t)Section.getAddress()) << ":" << hexValue ((uint64_t)Section.getAddress() + Section.getSize(), 10) << "] Name: '" << *SectionNameOrErr << "'\n" << "Begin: " << hexValue((uint64_t)Begin) << ", End: " << hexValue((uint64_t)End) << "\n"; }; } } while (false) | |||
373 | dbgs() << "Section Index: " << hexValue(Section.getIndex()) << " ["do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { Expected<StringRef> SectionNameOrErr = Section.getName(); if (!SectionNameOrErr) consumeError(SectionNameOrErr .takeError()); else dbgs() << "Section Index: " << hexValue(Section.getIndex()) << " [" << hexValue ((uint64_t)Section.getAddress()) << ":" << hexValue ((uint64_t)Section.getAddress() + Section.getSize(), 10) << "] Name: '" << *SectionNameOrErr << "'\n" << "Begin: " << hexValue((uint64_t)Begin) << ", End: " << hexValue((uint64_t)End) << "\n"; }; } } while (false) | |||
374 | << hexValue((uint64_t)Section.getAddress()) << ":"do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { Expected<StringRef> SectionNameOrErr = Section.getName(); if (!SectionNameOrErr) consumeError(SectionNameOrErr .takeError()); else dbgs() << "Section Index: " << hexValue(Section.getIndex()) << " [" << hexValue ((uint64_t)Section.getAddress()) << ":" << hexValue ((uint64_t)Section.getAddress() + Section.getSize(), 10) << "] Name: '" << *SectionNameOrErr << "'\n" << "Begin: " << hexValue((uint64_t)Begin) << ", End: " << hexValue((uint64_t)End) << "\n"; }; } } while (false) | |||
375 | << hexValue((uint64_t)Section.getAddress() + Section.getSize(), 10)do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { Expected<StringRef> SectionNameOrErr = Section.getName(); if (!SectionNameOrErr) consumeError(SectionNameOrErr .takeError()); else dbgs() << "Section Index: " << hexValue(Section.getIndex()) << " [" << hexValue ((uint64_t)Section.getAddress()) << ":" << hexValue ((uint64_t)Section.getAddress() + Section.getSize(), 10) << "] Name: '" << *SectionNameOrErr << "'\n" << "Begin: " << hexValue((uint64_t)Begin) << ", End: " << hexValue((uint64_t)End) << "\n"; }; } } while (false) | |||
376 | << "] Name: '" << *SectionNameOrErr << "'\n"do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { Expected<StringRef> SectionNameOrErr = Section.getName(); if (!SectionNameOrErr) consumeError(SectionNameOrErr .takeError()); else dbgs() << "Section Index: " << hexValue(Section.getIndex()) << " [" << hexValue ((uint64_t)Section.getAddress()) << ":" << hexValue ((uint64_t)Section.getAddress() + Section.getSize(), 10) << "] Name: '" << *SectionNameOrErr << "'\n" << "Begin: " << hexValue((uint64_t)Begin) << ", End: " << hexValue((uint64_t)End) << "\n"; }; } } while (false) | |||
377 | << "Begin: " << hexValue((uint64_t)Begin)do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { Expected<StringRef> SectionNameOrErr = Section.getName(); if (!SectionNameOrErr) consumeError(SectionNameOrErr .takeError()); else dbgs() << "Section Index: " << hexValue(Section.getIndex()) << " [" << hexValue ((uint64_t)Section.getAddress()) << ":" << hexValue ((uint64_t)Section.getAddress() + Section.getSize(), 10) << "] Name: '" << *SectionNameOrErr << "'\n" << "Begin: " << hexValue((uint64_t)Begin) << ", End: " << hexValue((uint64_t)End) << "\n"; }; } } while (false) | |||
378 | << ", End: " << hexValue((uint64_t)End) << "\n";do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { Expected<StringRef> SectionNameOrErr = Section.getName(); if (!SectionNameOrErr) consumeError(SectionNameOrErr .takeError()); else dbgs() << "Section Index: " << hexValue(Section.getIndex()) << " [" << hexValue ((uint64_t)Section.getAddress()) << ":" << hexValue ((uint64_t)Section.getAddress() + Section.getSize(), 10) << "] Name: '" << *SectionNameOrErr << "'\n" << "Begin: " << hexValue((uint64_t)Begin) << ", End: " << hexValue((uint64_t)End) << "\n"; }; } } while (false) | |||
379 | })do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { Expected<StringRef> SectionNameOrErr = Section.getName(); if (!SectionNameOrErr) consumeError(SectionNameOrErr .takeError()); else dbgs() << "Section Index: " << hexValue(Section.getIndex()) << " [" << hexValue ((uint64_t)Section.getAddress()) << ":" << hexValue ((uint64_t)Section.getAddress() + Section.getSize(), 10) << "] Name: '" << *SectionNameOrErr << "'\n" << "Begin: " << hexValue((uint64_t)Begin) << ", End: " << hexValue((uint64_t)End) << "\n"; }; } } while (false); | |||
380 | ||||
381 | // Address for first instruction line. | |||
382 | LVAddress FirstAddress = Address; | |||
383 | LVLines *Instructions = new LVLines(); | |||
384 | ||||
385 | while (Begin < End) { | |||
386 | MCInst Instruction; | |||
387 | uint64_t BytesConsumed = 0; | |||
388 | SmallVector<char, 64> InsnStr; | |||
389 | raw_svector_ostream Annotations(InsnStr); | |||
390 | MCDisassembler::DecodeStatus const S = | |||
391 | MD->getInstruction(Instruction, BytesConsumed, | |||
392 | ArrayRef<uint8_t>(Begin, End), Address, outs()); | |||
393 | switch (S) { | |||
394 | case MCDisassembler::Fail: | |||
395 | LLVM_DEBUG({ dbgs() << "Invalid instruction\n"; })do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { dbgs() << "Invalid instruction\n" ; }; } } while (false); | |||
396 | if (BytesConsumed == 0) | |||
397 | // Skip invalid bytes | |||
398 | BytesConsumed = 1; | |||
399 | break; | |||
400 | case MCDisassembler::SoftFail: | |||
401 | LLVM_DEBUG({ dbgs() << "Potentially undefined instruction:"; })do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { dbgs() << "Potentially undefined instruction:" ; }; } } while (false); | |||
402 | LLVM_FALLTHROUGH[[fallthrough]]; | |||
403 | case MCDisassembler::Success: { | |||
404 | std::string Buffer; | |||
405 | raw_string_ostream Stream(Buffer); | |||
406 | StringRef AnnotationsStr = Annotations.str(); | |||
407 | MIP.get()->printInst(&Instruction, Address, AnnotationsStr, *STI, Stream); | |||
408 | LLVM_DEBUG({do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { std::string BufferCodes; raw_string_ostream StreamCodes(BufferCodes); StreamCodes << format_bytes( ArrayRef<uint8_t>(Begin, Begin + BytesConsumed), None, 16, 16); dbgs() << "[" << hexValue((uint64_t)Begin ) << "] " << "Size: " << format_decimal(BytesConsumed , 2) << " (" << formatv("{0}", fmt_align(StreamCodes .str(), AlignStyle::Left, 32)) << ") " << hexValue ((uint64_t)Address) << ": " << Stream.str() << "\n"; }; } } while (false) | |||
409 | std::string BufferCodes;do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { std::string BufferCodes; raw_string_ostream StreamCodes(BufferCodes); StreamCodes << format_bytes( ArrayRef<uint8_t>(Begin, Begin + BytesConsumed), None, 16, 16); dbgs() << "[" << hexValue((uint64_t)Begin ) << "] " << "Size: " << format_decimal(BytesConsumed , 2) << " (" << formatv("{0}", fmt_align(StreamCodes .str(), AlignStyle::Left, 32)) << ") " << hexValue ((uint64_t)Address) << ": " << Stream.str() << "\n"; }; } } while (false) | |||
410 | raw_string_ostream StreamCodes(BufferCodes);do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { std::string BufferCodes; raw_string_ostream StreamCodes(BufferCodes); StreamCodes << format_bytes( ArrayRef<uint8_t>(Begin, Begin + BytesConsumed), None, 16, 16); dbgs() << "[" << hexValue((uint64_t)Begin ) << "] " << "Size: " << format_decimal(BytesConsumed , 2) << " (" << formatv("{0}", fmt_align(StreamCodes .str(), AlignStyle::Left, 32)) << ") " << hexValue ((uint64_t)Address) << ": " << Stream.str() << "\n"; }; } } while (false) | |||
411 | StreamCodes << format_bytes(do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { std::string BufferCodes; raw_string_ostream StreamCodes(BufferCodes); StreamCodes << format_bytes( ArrayRef<uint8_t>(Begin, Begin + BytesConsumed), None, 16, 16); dbgs() << "[" << hexValue((uint64_t)Begin ) << "] " << "Size: " << format_decimal(BytesConsumed , 2) << " (" << formatv("{0}", fmt_align(StreamCodes .str(), AlignStyle::Left, 32)) << ") " << hexValue ((uint64_t)Address) << ": " << Stream.str() << "\n"; }; } } while (false) | |||
412 | ArrayRef<uint8_t>(Begin, Begin + BytesConsumed), None, 16, 16);do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { std::string BufferCodes; raw_string_ostream StreamCodes(BufferCodes); StreamCodes << format_bytes( ArrayRef<uint8_t>(Begin, Begin + BytesConsumed), None, 16, 16); dbgs() << "[" << hexValue((uint64_t)Begin ) << "] " << "Size: " << format_decimal(BytesConsumed , 2) << " (" << formatv("{0}", fmt_align(StreamCodes .str(), AlignStyle::Left, 32)) << ") " << hexValue ((uint64_t)Address) << ": " << Stream.str() << "\n"; }; } } while (false) | |||
413 | dbgs() << "[" << hexValue((uint64_t)Begin) << "] "do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { std::string BufferCodes; raw_string_ostream StreamCodes(BufferCodes); StreamCodes << format_bytes( ArrayRef<uint8_t>(Begin, Begin + BytesConsumed), None, 16, 16); dbgs() << "[" << hexValue((uint64_t)Begin ) << "] " << "Size: " << format_decimal(BytesConsumed , 2) << " (" << formatv("{0}", fmt_align(StreamCodes .str(), AlignStyle::Left, 32)) << ") " << hexValue ((uint64_t)Address) << ": " << Stream.str() << "\n"; }; } } while (false) | |||
414 | << "Size: " << format_decimal(BytesConsumed, 2) << " ("do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { std::string BufferCodes; raw_string_ostream StreamCodes(BufferCodes); StreamCodes << format_bytes( ArrayRef<uint8_t>(Begin, Begin + BytesConsumed), None, 16, 16); dbgs() << "[" << hexValue((uint64_t)Begin ) << "] " << "Size: " << format_decimal(BytesConsumed , 2) << " (" << formatv("{0}", fmt_align(StreamCodes .str(), AlignStyle::Left, 32)) << ") " << hexValue ((uint64_t)Address) << ": " << Stream.str() << "\n"; }; } } while (false) | |||
415 | << formatv("{0}",do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { std::string BufferCodes; raw_string_ostream StreamCodes(BufferCodes); StreamCodes << format_bytes( ArrayRef<uint8_t>(Begin, Begin + BytesConsumed), None, 16, 16); dbgs() << "[" << hexValue((uint64_t)Begin ) << "] " << "Size: " << format_decimal(BytesConsumed , 2) << " (" << formatv("{0}", fmt_align(StreamCodes .str(), AlignStyle::Left, 32)) << ") " << hexValue ((uint64_t)Address) << ": " << Stream.str() << "\n"; }; } } while (false) | |||
416 | fmt_align(StreamCodes.str(), AlignStyle::Left, 32))do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { std::string BufferCodes; raw_string_ostream StreamCodes(BufferCodes); StreamCodes << format_bytes( ArrayRef<uint8_t>(Begin, Begin + BytesConsumed), None, 16, 16); dbgs() << "[" << hexValue((uint64_t)Begin ) << "] " << "Size: " << format_decimal(BytesConsumed , 2) << " (" << formatv("{0}", fmt_align(StreamCodes .str(), AlignStyle::Left, 32)) << ") " << hexValue ((uint64_t)Address) << ": " << Stream.str() << "\n"; }; } } while (false) | |||
417 | << ") " << hexValue((uint64_t)Address) << ": " << Stream.str()do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { std::string BufferCodes; raw_string_ostream StreamCodes(BufferCodes); StreamCodes << format_bytes( ArrayRef<uint8_t>(Begin, Begin + BytesConsumed), None, 16, 16); dbgs() << "[" << hexValue((uint64_t)Begin ) << "] " << "Size: " << format_decimal(BytesConsumed , 2) << " (" << formatv("{0}", fmt_align(StreamCodes .str(), AlignStyle::Left, 32)) << ") " << hexValue ((uint64_t)Address) << ": " << Stream.str() << "\n"; }; } } while (false) | |||
418 | << "\n";do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { std::string BufferCodes; raw_string_ostream StreamCodes(BufferCodes); StreamCodes << format_bytes( ArrayRef<uint8_t>(Begin, Begin + BytesConsumed), None, 16, 16); dbgs() << "[" << hexValue((uint64_t)Begin ) << "] " << "Size: " << format_decimal(BytesConsumed , 2) << " (" << formatv("{0}", fmt_align(StreamCodes .str(), AlignStyle::Left, 32)) << ") " << hexValue ((uint64_t)Address) << ": " << Stream.str() << "\n"; }; } } while (false) | |||
419 | })do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { std::string BufferCodes; raw_string_ostream StreamCodes(BufferCodes); StreamCodes << format_bytes( ArrayRef<uint8_t>(Begin, Begin + BytesConsumed), None, 16, 16); dbgs() << "[" << hexValue((uint64_t)Begin ) << "] " << "Size: " << format_decimal(BytesConsumed , 2) << " (" << formatv("{0}", fmt_align(StreamCodes .str(), AlignStyle::Left, 32)) << ") " << hexValue ((uint64_t)Address) << ": " << Stream.str() << "\n"; }; } } while (false); | |||
420 | // Here we add logical lines to the Instructions. Later on, | |||
421 | // the 'processLines()' function will move each created logical line | |||
422 | // to its enclosing logical scope, using the debug ranges information | |||
423 | // and they will be released when its scope parent is deleted. | |||
424 | LVLineAssembler *Line = new LVLineAssembler(); | |||
425 | Line->setAddress(Address); | |||
426 | Line->setName(StringRef(Stream.str()).trim()); | |||
427 | Instructions->push_back(Line); | |||
428 | break; | |||
429 | } | |||
430 | } | |||
431 | Address += BytesConsumed; | |||
432 | Begin += BytesConsumed; | |||
433 | } | |||
434 | ||||
435 | LLVM_DEBUG({do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { size_t Index = 0; dbgs() << "\nSectionIndex: " << format_decimal(SectionIndex, 3) << " Scope DIE: " << hexValue(Scope->getOffset()) << "\n" << "Address: " << hexValue(FirstAddress) << format( " - Collected instructions lines: %d\n", Instructions->size ()); for (const LVLine *Line : *Instructions) dbgs() << format_decimal(++Index, 5) << ": " << hexValue(Line ->getOffset()) << ", (" << Line->getName() << ")\n"; }; } } while (false) | |||
436 | size_t Index = 0;do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { size_t Index = 0; dbgs() << "\nSectionIndex: " << format_decimal(SectionIndex, 3) << " Scope DIE: " << hexValue(Scope->getOffset()) << "\n" << "Address: " << hexValue(FirstAddress) << format( " - Collected instructions lines: %d\n", Instructions->size ()); for (const LVLine *Line : *Instructions) dbgs() << format_decimal(++Index, 5) << ": " << hexValue(Line ->getOffset()) << ", (" << Line->getName() << ")\n"; }; } } while (false) | |||
437 | dbgs() << "\nSectionIndex: " << format_decimal(SectionIndex, 3)do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { size_t Index = 0; dbgs() << "\nSectionIndex: " << format_decimal(SectionIndex, 3) << " Scope DIE: " << hexValue(Scope->getOffset()) << "\n" << "Address: " << hexValue(FirstAddress) << format( " - Collected instructions lines: %d\n", Instructions->size ()); for (const LVLine *Line : *Instructions) dbgs() << format_decimal(++Index, 5) << ": " << hexValue(Line ->getOffset()) << ", (" << Line->getName() << ")\n"; }; } } while (false) | |||
438 | << " Scope DIE: " << hexValue(Scope->getOffset()) << "\n"do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { size_t Index = 0; dbgs() << "\nSectionIndex: " << format_decimal(SectionIndex, 3) << " Scope DIE: " << hexValue(Scope->getOffset()) << "\n" << "Address: " << hexValue(FirstAddress) << format( " - Collected instructions lines: %d\n", Instructions->size ()); for (const LVLine *Line : *Instructions) dbgs() << format_decimal(++Index, 5) << ": " << hexValue(Line ->getOffset()) << ", (" << Line->getName() << ")\n"; }; } } while (false) | |||
439 | << "Address: " << hexValue(FirstAddress)do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { size_t Index = 0; dbgs() << "\nSectionIndex: " << format_decimal(SectionIndex, 3) << " Scope DIE: " << hexValue(Scope->getOffset()) << "\n" << "Address: " << hexValue(FirstAddress) << format( " - Collected instructions lines: %d\n", Instructions->size ()); for (const LVLine *Line : *Instructions) dbgs() << format_decimal(++Index, 5) << ": " << hexValue(Line ->getOffset()) << ", (" << Line->getName() << ")\n"; }; } } while (false) | |||
440 | << format(" - Collected instructions lines: %d\n",do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { size_t Index = 0; dbgs() << "\nSectionIndex: " << format_decimal(SectionIndex, 3) << " Scope DIE: " << hexValue(Scope->getOffset()) << "\n" << "Address: " << hexValue(FirstAddress) << format( " - Collected instructions lines: %d\n", Instructions->size ()); for (const LVLine *Line : *Instructions) dbgs() << format_decimal(++Index, 5) << ": " << hexValue(Line ->getOffset()) << ", (" << Line->getName() << ")\n"; }; } } while (false) | |||
441 | Instructions->size());do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { size_t Index = 0; dbgs() << "\nSectionIndex: " << format_decimal(SectionIndex, 3) << " Scope DIE: " << hexValue(Scope->getOffset()) << "\n" << "Address: " << hexValue(FirstAddress) << format( " - Collected instructions lines: %d\n", Instructions->size ()); for (const LVLine *Line : *Instructions) dbgs() << format_decimal(++Index, 5) << ": " << hexValue(Line ->getOffset()) << ", (" << Line->getName() << ")\n"; }; } } while (false) | |||
442 | for (const LVLine *Line : *Instructions)do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { size_t Index = 0; dbgs() << "\nSectionIndex: " << format_decimal(SectionIndex, 3) << " Scope DIE: " << hexValue(Scope->getOffset()) << "\n" << "Address: " << hexValue(FirstAddress) << format( " - Collected instructions lines: %d\n", Instructions->size ()); for (const LVLine *Line : *Instructions) dbgs() << format_decimal(++Index, 5) << ": " << hexValue(Line ->getOffset()) << ", (" << Line->getName() << ")\n"; }; } } while (false) | |||
443 | dbgs() << format_decimal(++Index, 5) << ": "do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { size_t Index = 0; dbgs() << "\nSectionIndex: " << format_decimal(SectionIndex, 3) << " Scope DIE: " << hexValue(Scope->getOffset()) << "\n" << "Address: " << hexValue(FirstAddress) << format( " - Collected instructions lines: %d\n", Instructions->size ()); for (const LVLine *Line : *Instructions) dbgs() << format_decimal(++Index, 5) << ": " << hexValue(Line ->getOffset()) << ", (" << Line->getName() << ")\n"; }; } } while (false) | |||
444 | << hexValue(Line->getOffset()) << ", (" << Line->getName()do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { size_t Index = 0; dbgs() << "\nSectionIndex: " << format_decimal(SectionIndex, 3) << " Scope DIE: " << hexValue(Scope->getOffset()) << "\n" << "Address: " << hexValue(FirstAddress) << format( " - Collected instructions lines: %d\n", Instructions->size ()); for (const LVLine *Line : *Instructions) dbgs() << format_decimal(++Index, 5) << ": " << hexValue(Line ->getOffset()) << ", (" << Line->getName() << ")\n"; }; } } while (false) | |||
445 | << ")\n";do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { size_t Index = 0; dbgs() << "\nSectionIndex: " << format_decimal(SectionIndex, 3) << " Scope DIE: " << hexValue(Scope->getOffset()) << "\n" << "Address: " << hexValue(FirstAddress) << format( " - Collected instructions lines: %d\n", Instructions->size ()); for (const LVLine *Line : *Instructions) dbgs() << format_decimal(++Index, 5) << ": " << hexValue(Line ->getOffset()) << ", (" << Line->getName() << ")\n"; }; } } while (false) | |||
446 | })do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { size_t Index = 0; dbgs() << "\nSectionIndex: " << format_decimal(SectionIndex, 3) << " Scope DIE: " << hexValue(Scope->getOffset()) << "\n" << "Address: " << hexValue(FirstAddress) << format( " - Collected instructions lines: %d\n", Instructions->size ()); for (const LVLine *Line : *Instructions) dbgs() << format_decimal(++Index, 5) << ": " << hexValue(Line ->getOffset()) << ", (" << Line->getName() << ")\n"; }; } } while (false); | |||
447 | ||||
448 | // The scope in the assembler names is linked to its own instructions. | |||
449 | ScopeInstructions.add(SectionIndex, Scope, Instructions); | |||
450 | AssemblerMappings.add(SectionIndex, FirstAddress, Scope); | |||
| ||||
451 | ||||
452 | return Error::success(); | |||
453 | } | |||
454 | ||||
455 | Error LVBinaryReader::createInstructions(LVScope *Function, | |||
456 | LVSectionIndex SectionIndex) { | |||
457 | if (!options().getPrintInstructions()) | |||
| ||||
458 | return Error::success(); | |||
459 | ||||
460 | LVNameInfo Name = CompileUnit->findPublicName(Function); | |||
461 | if (Name.first != LVAddress(UINT64_MAX(18446744073709551615UL))) | |||
462 | return createInstructions(Function, SectionIndex, Name); | |||
463 | ||||
464 | return Error::success(); | |||
465 | } | |||
466 | ||||
467 | Error LVBinaryReader::createInstructions() { | |||
468 | if (!options().getPrintInstructions()) | |||
469 | return Error::success(); | |||
470 | ||||
471 | LLVM_DEBUG({do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { size_t Index = 1; dbgs() << "\nPublic Names (Scope):\n" ; for (LVPublicNames::const_reference Name : CompileUnit-> getPublicNames()) { LVScope *Scope = Name.first; const LVNameInfo &NameInfo = Name.second; LVAddress Address = NameInfo.first ; uint64_t Size = NameInfo.second; dbgs() << format_decimal (Index++, 5) << ": " << "DIE Offset: " << hexValue (Scope->getOffset()) << " Range: [" << hexValue (Address) << ":" << hexValue(Address + Size) << "] " << "Name: '" << Scope->getName() << "' / '" << Scope->getLinkageName() << "'\n"; } }; } } while (false) | |||
472 | size_t Index = 1;do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { size_t Index = 1; dbgs() << "\nPublic Names (Scope):\n" ; for (LVPublicNames::const_reference Name : CompileUnit-> getPublicNames()) { LVScope *Scope = Name.first; const LVNameInfo &NameInfo = Name.second; LVAddress Address = NameInfo.first ; uint64_t Size = NameInfo.second; dbgs() << format_decimal (Index++, 5) << ": " << "DIE Offset: " << hexValue (Scope->getOffset()) << " Range: [" << hexValue (Address) << ":" << hexValue(Address + Size) << "] " << "Name: '" << Scope->getName() << "' / '" << Scope->getLinkageName() << "'\n"; } }; } } while (false) | |||
473 | dbgs() << "\nPublic Names (Scope):\n";do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { size_t Index = 1; dbgs() << "\nPublic Names (Scope):\n" ; for (LVPublicNames::const_reference Name : CompileUnit-> getPublicNames()) { LVScope *Scope = Name.first; const LVNameInfo &NameInfo = Name.second; LVAddress Address = NameInfo.first ; uint64_t Size = NameInfo.second; dbgs() << format_decimal (Index++, 5) << ": " << "DIE Offset: " << hexValue (Scope->getOffset()) << " Range: [" << hexValue (Address) << ":" << hexValue(Address + Size) << "] " << "Name: '" << Scope->getName() << "' / '" << Scope->getLinkageName() << "'\n"; } }; } } while (false) | |||
474 | for (LVPublicNames::const_reference Name : CompileUnit->getPublicNames()) {do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { size_t Index = 1; dbgs() << "\nPublic Names (Scope):\n" ; for (LVPublicNames::const_reference Name : CompileUnit-> getPublicNames()) { LVScope *Scope = Name.first; const LVNameInfo &NameInfo = Name.second; LVAddress Address = NameInfo.first ; uint64_t Size = NameInfo.second; dbgs() << format_decimal (Index++, 5) << ": " << "DIE Offset: " << hexValue (Scope->getOffset()) << " Range: [" << hexValue (Address) << ":" << hexValue(Address + Size) << "] " << "Name: '" << Scope->getName() << "' / '" << Scope->getLinkageName() << "'\n"; } }; } } while (false) | |||
475 | LVScope *Scope = Name.first;do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { size_t Index = 1; dbgs() << "\nPublic Names (Scope):\n" ; for (LVPublicNames::const_reference Name : CompileUnit-> getPublicNames()) { LVScope *Scope = Name.first; const LVNameInfo &NameInfo = Name.second; LVAddress Address = NameInfo.first ; uint64_t Size = NameInfo.second; dbgs() << format_decimal (Index++, 5) << ": " << "DIE Offset: " << hexValue (Scope->getOffset()) << " Range: [" << hexValue (Address) << ":" << hexValue(Address + Size) << "] " << "Name: '" << Scope->getName() << "' / '" << Scope->getLinkageName() << "'\n"; } }; } } while (false) | |||
476 | const LVNameInfo &NameInfo = Name.second;do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { size_t Index = 1; dbgs() << "\nPublic Names (Scope):\n" ; for (LVPublicNames::const_reference Name : CompileUnit-> getPublicNames()) { LVScope *Scope = Name.first; const LVNameInfo &NameInfo = Name.second; LVAddress Address = NameInfo.first ; uint64_t Size = NameInfo.second; dbgs() << format_decimal (Index++, 5) << ": " << "DIE Offset: " << hexValue (Scope->getOffset()) << " Range: [" << hexValue (Address) << ":" << hexValue(Address + Size) << "] " << "Name: '" << Scope->getName() << "' / '" << Scope->getLinkageName() << "'\n"; } }; } } while (false) | |||
477 | LVAddress Address = NameInfo.first;do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { size_t Index = 1; dbgs() << "\nPublic Names (Scope):\n" ; for (LVPublicNames::const_reference Name : CompileUnit-> getPublicNames()) { LVScope *Scope = Name.first; const LVNameInfo &NameInfo = Name.second; LVAddress Address = NameInfo.first ; uint64_t Size = NameInfo.second; dbgs() << format_decimal (Index++, 5) << ": " << "DIE Offset: " << hexValue (Scope->getOffset()) << " Range: [" << hexValue (Address) << ":" << hexValue(Address + Size) << "] " << "Name: '" << Scope->getName() << "' / '" << Scope->getLinkageName() << "'\n"; } }; } } while (false) | |||
478 | uint64_t Size = NameInfo.second;do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { size_t Index = 1; dbgs() << "\nPublic Names (Scope):\n" ; for (LVPublicNames::const_reference Name : CompileUnit-> getPublicNames()) { LVScope *Scope = Name.first; const LVNameInfo &NameInfo = Name.second; LVAddress Address = NameInfo.first ; uint64_t Size = NameInfo.second; dbgs() << format_decimal (Index++, 5) << ": " << "DIE Offset: " << hexValue (Scope->getOffset()) << " Range: [" << hexValue (Address) << ":" << hexValue(Address + Size) << "] " << "Name: '" << Scope->getName() << "' / '" << Scope->getLinkageName() << "'\n"; } }; } } while (false) | |||
479 | dbgs() << format_decimal(Index++, 5) << ": "do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { size_t Index = 1; dbgs() << "\nPublic Names (Scope):\n" ; for (LVPublicNames::const_reference Name : CompileUnit-> getPublicNames()) { LVScope *Scope = Name.first; const LVNameInfo &NameInfo = Name.second; LVAddress Address = NameInfo.first ; uint64_t Size = NameInfo.second; dbgs() << format_decimal (Index++, 5) << ": " << "DIE Offset: " << hexValue (Scope->getOffset()) << " Range: [" << hexValue (Address) << ":" << hexValue(Address + Size) << "] " << "Name: '" << Scope->getName() << "' / '" << Scope->getLinkageName() << "'\n"; } }; } } while (false) | |||
480 | << "DIE Offset: " << hexValue(Scope->getOffset()) << " Range: ["do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { size_t Index = 1; dbgs() << "\nPublic Names (Scope):\n" ; for (LVPublicNames::const_reference Name : CompileUnit-> getPublicNames()) { LVScope *Scope = Name.first; const LVNameInfo &NameInfo = Name.second; LVAddress Address = NameInfo.first ; uint64_t Size = NameInfo.second; dbgs() << format_decimal (Index++, 5) << ": " << "DIE Offset: " << hexValue (Scope->getOffset()) << " Range: [" << hexValue (Address) << ":" << hexValue(Address + Size) << "] " << "Name: '" << Scope->getName() << "' / '" << Scope->getLinkageName() << "'\n"; } }; } } while (false) | |||
481 | << hexValue(Address) << ":" << hexValue(Address + Size) << "] "do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { size_t Index = 1; dbgs() << "\nPublic Names (Scope):\n" ; for (LVPublicNames::const_reference Name : CompileUnit-> getPublicNames()) { LVScope *Scope = Name.first; const LVNameInfo &NameInfo = Name.second; LVAddress Address = NameInfo.first ; uint64_t Size = NameInfo.second; dbgs() << format_decimal (Index++, 5) << ": " << "DIE Offset: " << hexValue (Scope->getOffset()) << " Range: [" << hexValue (Address) << ":" << hexValue(Address + Size) << "] " << "Name: '" << Scope->getName() << "' / '" << Scope->getLinkageName() << "'\n"; } }; } } while (false) | |||
482 | << "Name: '" << Scope->getName() << "' / '"do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { size_t Index = 1; dbgs() << "\nPublic Names (Scope):\n" ; for (LVPublicNames::const_reference Name : CompileUnit-> getPublicNames()) { LVScope *Scope = Name.first; const LVNameInfo &NameInfo = Name.second; LVAddress Address = NameInfo.first ; uint64_t Size = NameInfo.second; dbgs() << format_decimal (Index++, 5) << ": " << "DIE Offset: " << hexValue (Scope->getOffset()) << " Range: [" << hexValue (Address) << ":" << hexValue(Address + Size) << "] " << "Name: '" << Scope->getName() << "' / '" << Scope->getLinkageName() << "'\n"; } }; } } while (false) | |||
483 | << Scope->getLinkageName() << "'\n";do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { size_t Index = 1; dbgs() << "\nPublic Names (Scope):\n" ; for (LVPublicNames::const_reference Name : CompileUnit-> getPublicNames()) { LVScope *Scope = Name.first; const LVNameInfo &NameInfo = Name.second; LVAddress Address = NameInfo.first ; uint64_t Size = NameInfo.second; dbgs() << format_decimal (Index++, 5) << ": " << "DIE Offset: " << hexValue (Scope->getOffset()) << " Range: [" << hexValue (Address) << ":" << hexValue(Address + Size) << "] " << "Name: '" << Scope->getName() << "' / '" << Scope->getLinkageName() << "'\n"; } }; } } while (false) | |||
484 | }do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { size_t Index = 1; dbgs() << "\nPublic Names (Scope):\n" ; for (LVPublicNames::const_reference Name : CompileUnit-> getPublicNames()) { LVScope *Scope = Name.first; const LVNameInfo &NameInfo = Name.second; LVAddress Address = NameInfo.first ; uint64_t Size = NameInfo.second; dbgs() << format_decimal (Index++, 5) << ": " << "DIE Offset: " << hexValue (Scope->getOffset()) << " Range: [" << hexValue (Address) << ":" << hexValue(Address + Size) << "] " << "Name: '" << Scope->getName() << "' / '" << Scope->getLinkageName() << "'\n"; } }; } } while (false) | |||
485 | })do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { size_t Index = 1; dbgs() << "\nPublic Names (Scope):\n" ; for (LVPublicNames::const_reference Name : CompileUnit-> getPublicNames()) { LVScope *Scope = Name.first; const LVNameInfo &NameInfo = Name.second; LVAddress Address = NameInfo.first ; uint64_t Size = NameInfo.second; dbgs() << format_decimal (Index++, 5) << ": " << "DIE Offset: " << hexValue (Scope->getOffset()) << " Range: [" << hexValue (Address) << ":" << hexValue(Address + Size) << "] " << "Name: '" << Scope->getName() << "' / '" << Scope->getLinkageName() << "'\n"; } }; } } while (false); | |||
486 | ||||
487 | // For each public name in the current compile unit, create the line | |||
488 | // records that represent the executable instructions. | |||
489 | for (LVPublicNames::const_reference Name : CompileUnit->getPublicNames()) { | |||
490 | LVScope *Scope = Name.first; | |||
491 | // The symbol table extracted from the object file always contains a | |||
492 | // non-empty name (linkage name). However, the logical scope does not | |||
493 | // guarantee to have a name for the linkage name (main is one case). | |||
494 | // For those cases, set the linkage name the same as the name. | |||
495 | if (!Scope->getLinkageNameIndex()) | |||
496 | Scope->setLinkageName(Scope->getName()); | |||
497 | LVSectionIndex SectionIndex = getSymbolTableIndex(Scope->getLinkageName()); | |||
498 | if (Error Err = createInstructions(Scope, SectionIndex, Name.second)) | |||
499 | return Err; | |||
500 | } | |||
501 | ||||
502 | return Error::success(); | |||
503 | } | |||
504 | ||||
505 | // During the traversal of the debug information sections, we created the | |||
506 | // logical lines representing the disassembled instructions from the text | |||
507 | // section and the logical lines representing the line records from the | |||
508 | // debug line section. Using the ranges associated with the logical scopes, | |||
509 | // we will allocate those logical lines to their logical scopes. | |||
510 | void LVBinaryReader::processLines(LVLines *DebugLines, | |||
511 | LVSectionIndex SectionIndex, | |||
512 | LVScope *Function) { | |||
513 | assert(DebugLines && "DebugLines is null.")(static_cast <bool> (DebugLines && "DebugLines is null." ) ? void (0) : __assert_fail ("DebugLines && \"DebugLines is null.\"" , "llvm/lib/DebugInfo/LogicalView/Readers/LVBinaryReader.cpp" , 513, __extension__ __PRETTY_FUNCTION__)); | |||
514 | ||||
515 | // Just return if this compilation unit does not have any line records | |||
516 | // and no instruction lines were created. | |||
517 | if (DebugLines->empty() && !options().getPrintInstructions()) | |||
518 | return; | |||
519 | ||||
520 | // Merge the debug lines and instruction lines using their text address; | |||
521 | // the logical line representing the debug line record is followed by the | |||
522 | // line(s) representing the disassembled instructions, whose addresses are | |||
523 | // equal or greater that the line address and less than the address of the | |||
524 | // next debug line record. | |||
525 | LLVM_DEBUG({do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { size_t Index = 1; size_t PerLine = 4; dbgs () << format("\nProcess debug lines: %d\n", DebugLines-> size()); for (const LVLine *Line : *DebugLines) { dbgs() << format_decimal(Index, 5) << ": " << hexValue(Line ->getOffset()) << ", (" << Line->getLineNumber () << ")" << ((Index % PerLine) ? " " : "\n"); ++ Index; } dbgs() << ((Index % PerLine) ? "\n" : ""); }; } } while (false) | |||
526 | size_t Index = 1;do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { size_t Index = 1; size_t PerLine = 4; dbgs () << format("\nProcess debug lines: %d\n", DebugLines-> size()); for (const LVLine *Line : *DebugLines) { dbgs() << format_decimal(Index, 5) << ": " << hexValue(Line ->getOffset()) << ", (" << Line->getLineNumber () << ")" << ((Index % PerLine) ? " " : "\n"); ++ Index; } dbgs() << ((Index % PerLine) ? "\n" : ""); }; } } while (false) | |||
527 | size_t PerLine = 4;do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { size_t Index = 1; size_t PerLine = 4; dbgs () << format("\nProcess debug lines: %d\n", DebugLines-> size()); for (const LVLine *Line : *DebugLines) { dbgs() << format_decimal(Index, 5) << ": " << hexValue(Line ->getOffset()) << ", (" << Line->getLineNumber () << ")" << ((Index % PerLine) ? " " : "\n"); ++ Index; } dbgs() << ((Index % PerLine) ? "\n" : ""); }; } } while (false) | |||
528 | dbgs() << format("\nProcess debug lines: %d\n", DebugLines->size());do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { size_t Index = 1; size_t PerLine = 4; dbgs () << format("\nProcess debug lines: %d\n", DebugLines-> size()); for (const LVLine *Line : *DebugLines) { dbgs() << format_decimal(Index, 5) << ": " << hexValue(Line ->getOffset()) << ", (" << Line->getLineNumber () << ")" << ((Index % PerLine) ? " " : "\n"); ++ Index; } dbgs() << ((Index % PerLine) ? "\n" : ""); }; } } while (false) | |||
529 | for (const LVLine *Line : *DebugLines) {do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { size_t Index = 1; size_t PerLine = 4; dbgs () << format("\nProcess debug lines: %d\n", DebugLines-> size()); for (const LVLine *Line : *DebugLines) { dbgs() << format_decimal(Index, 5) << ": " << hexValue(Line ->getOffset()) << ", (" << Line->getLineNumber () << ")" << ((Index % PerLine) ? " " : "\n"); ++ Index; } dbgs() << ((Index % PerLine) ? "\n" : ""); }; } } while (false) | |||
530 | dbgs() << format_decimal(Index, 5) << ": " << hexValue(Line->getOffset())do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { size_t Index = 1; size_t PerLine = 4; dbgs () << format("\nProcess debug lines: %d\n", DebugLines-> size()); for (const LVLine *Line : *DebugLines) { dbgs() << format_decimal(Index, 5) << ": " << hexValue(Line ->getOffset()) << ", (" << Line->getLineNumber () << ")" << ((Index % PerLine) ? " " : "\n"); ++ Index; } dbgs() << ((Index % PerLine) ? "\n" : ""); }; } } while (false) | |||
531 | << ", (" << Line->getLineNumber() << ")"do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { size_t Index = 1; size_t PerLine = 4; dbgs () << format("\nProcess debug lines: %d\n", DebugLines-> size()); for (const LVLine *Line : *DebugLines) { dbgs() << format_decimal(Index, 5) << ": " << hexValue(Line ->getOffset()) << ", (" << Line->getLineNumber () << ")" << ((Index % PerLine) ? " " : "\n"); ++ Index; } dbgs() << ((Index % PerLine) ? "\n" : ""); }; } } while (false) | |||
532 | << ((Index % PerLine) ? " " : "\n");do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { size_t Index = 1; size_t PerLine = 4; dbgs () << format("\nProcess debug lines: %d\n", DebugLines-> size()); for (const LVLine *Line : *DebugLines) { dbgs() << format_decimal(Index, 5) << ": " << hexValue(Line ->getOffset()) << ", (" << Line->getLineNumber () << ")" << ((Index % PerLine) ? " " : "\n"); ++ Index; } dbgs() << ((Index % PerLine) ? "\n" : ""); }; } } while (false) | |||
533 | ++Index;do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { size_t Index = 1; size_t PerLine = 4; dbgs () << format("\nProcess debug lines: %d\n", DebugLines-> size()); for (const LVLine *Line : *DebugLines) { dbgs() << format_decimal(Index, 5) << ": " << hexValue(Line ->getOffset()) << ", (" << Line->getLineNumber () << ")" << ((Index % PerLine) ? " " : "\n"); ++ Index; } dbgs() << ((Index % PerLine) ? "\n" : ""); }; } } while (false) | |||
534 | }do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { size_t Index = 1; size_t PerLine = 4; dbgs () << format("\nProcess debug lines: %d\n", DebugLines-> size()); for (const LVLine *Line : *DebugLines) { dbgs() << format_decimal(Index, 5) << ": " << hexValue(Line ->getOffset()) << ", (" << Line->getLineNumber () << ")" << ((Index % PerLine) ? " " : "\n"); ++ Index; } dbgs() << ((Index % PerLine) ? "\n" : ""); }; } } while (false) | |||
535 | dbgs() << ((Index % PerLine) ? "\n" : "");do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { size_t Index = 1; size_t PerLine = 4; dbgs () << format("\nProcess debug lines: %d\n", DebugLines-> size()); for (const LVLine *Line : *DebugLines) { dbgs() << format_decimal(Index, 5) << ": " << hexValue(Line ->getOffset()) << ", (" << Line->getLineNumber () << ")" << ((Index % PerLine) ? " " : "\n"); ++ Index; } dbgs() << ((Index % PerLine) ? "\n" : ""); }; } } while (false) | |||
536 | })do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { size_t Index = 1; size_t PerLine = 4; dbgs () << format("\nProcess debug lines: %d\n", DebugLines-> size()); for (const LVLine *Line : *DebugLines) { dbgs() << format_decimal(Index, 5) << ": " << hexValue(Line ->getOffset()) << ", (" << Line->getLineNumber () << ")" << ((Index % PerLine) ? " " : "\n"); ++ Index; } dbgs() << ((Index % PerLine) ? "\n" : ""); }; } } while (false); | |||
537 | ||||
538 | bool TraverseLines = true; | |||
539 | LVLines::iterator Iter = DebugLines->begin(); | |||
540 | while (TraverseLines && Iter != DebugLines->end()) { | |||
541 | uint64_t DebugAddress = (*Iter)->getAddress(); | |||
542 | ||||
543 | // Get the function with an entry point that matches this line and | |||
544 | // its associated assembler entries. In the case of COMDAT, the input | |||
545 | // 'Function' is not null. Use it to find its address ranges. | |||
546 | LVScope *Scope = Function; | |||
547 | if (!Function) { | |||
548 | Scope = AssemblerMappings.find(SectionIndex, DebugAddress); | |||
549 | if (!Scope) { | |||
550 | ++Iter; | |||
551 | continue; | |||
552 | } | |||
553 | } | |||
554 | ||||
555 | // Get the associated instructions for the found 'Scope'. | |||
556 | LVLines InstructionLines; | |||
557 | LVLines *Lines = ScopeInstructions.find(SectionIndex, Scope); | |||
558 | if (Lines) | |||
559 | InstructionLines = std::move(*Lines); | |||
560 | ||||
561 | LLVM_DEBUG({do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { size_t Index = 0; dbgs() << "\nSectionIndex: " << format_decimal(SectionIndex, 3) << " Scope DIE: " << hexValue(Scope->getOffset()) << "\n" << format("Process instruction lines: %d\n", InstructionLines.size ()); for (const LVLine *Line : InstructionLines) dbgs() << format_decimal(++Index, 5) << ": " << hexValue(Line ->getOffset()) << ", (" << Line->getName() << ")\n"; }; } } while (false) | |||
562 | size_t Index = 0;do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { size_t Index = 0; dbgs() << "\nSectionIndex: " << format_decimal(SectionIndex, 3) << " Scope DIE: " << hexValue(Scope->getOffset()) << "\n" << format("Process instruction lines: %d\n", InstructionLines.size ()); for (const LVLine *Line : InstructionLines) dbgs() << format_decimal(++Index, 5) << ": " << hexValue(Line ->getOffset()) << ", (" << Line->getName() << ")\n"; }; } } while (false) | |||
563 | dbgs() << "\nSectionIndex: " << format_decimal(SectionIndex, 3)do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { size_t Index = 0; dbgs() << "\nSectionIndex: " << format_decimal(SectionIndex, 3) << " Scope DIE: " << hexValue(Scope->getOffset()) << "\n" << format("Process instruction lines: %d\n", InstructionLines.size ()); for (const LVLine *Line : InstructionLines) dbgs() << format_decimal(++Index, 5) << ": " << hexValue(Line ->getOffset()) << ", (" << Line->getName() << ")\n"; }; } } while (false) | |||
564 | << " Scope DIE: " << hexValue(Scope->getOffset()) << "\n"do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { size_t Index = 0; dbgs() << "\nSectionIndex: " << format_decimal(SectionIndex, 3) << " Scope DIE: " << hexValue(Scope->getOffset()) << "\n" << format("Process instruction lines: %d\n", InstructionLines.size ()); for (const LVLine *Line : InstructionLines) dbgs() << format_decimal(++Index, 5) << ": " << hexValue(Line ->getOffset()) << ", (" << Line->getName() << ")\n"; }; } } while (false) | |||
565 | << format("Process instruction lines: %d\n",do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { size_t Index = 0; dbgs() << "\nSectionIndex: " << format_decimal(SectionIndex, 3) << " Scope DIE: " << hexValue(Scope->getOffset()) << "\n" << format("Process instruction lines: %d\n", InstructionLines.size ()); for (const LVLine *Line : InstructionLines) dbgs() << format_decimal(++Index, 5) << ": " << hexValue(Line ->getOffset()) << ", (" << Line->getName() << ")\n"; }; } } while (false) | |||
566 | InstructionLines.size());do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { size_t Index = 0; dbgs() << "\nSectionIndex: " << format_decimal(SectionIndex, 3) << " Scope DIE: " << hexValue(Scope->getOffset()) << "\n" << format("Process instruction lines: %d\n", InstructionLines.size ()); for (const LVLine *Line : InstructionLines) dbgs() << format_decimal(++Index, 5) << ": " << hexValue(Line ->getOffset()) << ", (" << Line->getName() << ")\n"; }; } } while (false) | |||
567 | for (const LVLine *Line : InstructionLines)do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { size_t Index = 0; dbgs() << "\nSectionIndex: " << format_decimal(SectionIndex, 3) << " Scope DIE: " << hexValue(Scope->getOffset()) << "\n" << format("Process instruction lines: %d\n", InstructionLines.size ()); for (const LVLine *Line : InstructionLines) dbgs() << format_decimal(++Index, 5) << ": " << hexValue(Line ->getOffset()) << ", (" << Line->getName() << ")\n"; }; } } while (false) | |||
568 | dbgs() << format_decimal(++Index, 5) << ": "do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { size_t Index = 0; dbgs() << "\nSectionIndex: " << format_decimal(SectionIndex, 3) << " Scope DIE: " << hexValue(Scope->getOffset()) << "\n" << format("Process instruction lines: %d\n", InstructionLines.size ()); for (const LVLine *Line : InstructionLines) dbgs() << format_decimal(++Index, 5) << ": " << hexValue(Line ->getOffset()) << ", (" << Line->getName() << ")\n"; }; } } while (false) | |||
569 | << hexValue(Line->getOffset()) << ", (" << Line->getName()do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { size_t Index = 0; dbgs() << "\nSectionIndex: " << format_decimal(SectionIndex, 3) << " Scope DIE: " << hexValue(Scope->getOffset()) << "\n" << format("Process instruction lines: %d\n", InstructionLines.size ()); for (const LVLine *Line : InstructionLines) dbgs() << format_decimal(++Index, 5) << ": " << hexValue(Line ->getOffset()) << ", (" << Line->getName() << ")\n"; }; } } while (false) | |||
570 | << ")\n";do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { size_t Index = 0; dbgs() << "\nSectionIndex: " << format_decimal(SectionIndex, 3) << " Scope DIE: " << hexValue(Scope->getOffset()) << "\n" << format("Process instruction lines: %d\n", InstructionLines.size ()); for (const LVLine *Line : InstructionLines) dbgs() << format_decimal(++Index, 5) << ": " << hexValue(Line ->getOffset()) << ", (" << Line->getName() << ")\n"; }; } } while (false) | |||
571 | })do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { size_t Index = 0; dbgs() << "\nSectionIndex: " << format_decimal(SectionIndex, 3) << " Scope DIE: " << hexValue(Scope->getOffset()) << "\n" << format("Process instruction lines: %d\n", InstructionLines.size ()); for (const LVLine *Line : InstructionLines) dbgs() << format_decimal(++Index, 5) << ": " << hexValue(Line ->getOffset()) << ", (" << Line->getName() << ")\n"; }; } } while (false); | |||
572 | ||||
573 | // Continue with next debug line if there are not instructions lines. | |||
574 | if (InstructionLines.empty()) { | |||
575 | ++Iter; | |||
576 | continue; | |||
577 | } | |||
578 | ||||
579 | for (LVLine *InstructionLine : InstructionLines) { | |||
580 | uint64_t InstructionAddress = InstructionLine->getAddress(); | |||
581 | LLVM_DEBUG({do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { dbgs() << "Instruction address: " << hexValue(InstructionAddress) << "\n"; }; } } while (false) | |||
582 | dbgs() << "Instruction address: " << hexValue(InstructionAddress)do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { dbgs() << "Instruction address: " << hexValue(InstructionAddress) << "\n"; }; } } while (false) | |||
583 | << "\n";do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { dbgs() << "Instruction address: " << hexValue(InstructionAddress) << "\n"; }; } } while (false) | |||
584 | })do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { dbgs() << "Instruction address: " << hexValue(InstructionAddress) << "\n"; }; } } while (false); | |||
585 | if (TraverseLines) { | |||
586 | while (Iter != DebugLines->end()) { | |||
587 | DebugAddress = (*Iter)->getAddress(); | |||
588 | LLVM_DEBUG({do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { bool IsDebug = (*Iter)->getIsLineDebug (); dbgs() << "Line " << (IsDebug ? "dbg:" : "ins:" ) << " [" << hexValue(DebugAddress) << "]"; if (IsDebug) dbgs() << format(" %d", (*Iter)->getLineNumber ()); dbgs() << "\n"; }; } } while (false) | |||
589 | bool IsDebug = (*Iter)->getIsLineDebug();do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { bool IsDebug = (*Iter)->getIsLineDebug (); dbgs() << "Line " << (IsDebug ? "dbg:" : "ins:" ) << " [" << hexValue(DebugAddress) << "]"; if (IsDebug) dbgs() << format(" %d", (*Iter)->getLineNumber ()); dbgs() << "\n"; }; } } while (false) | |||
590 | dbgs() << "Line " << (IsDebug ? "dbg:" : "ins:") << " ["do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { bool IsDebug = (*Iter)->getIsLineDebug (); dbgs() << "Line " << (IsDebug ? "dbg:" : "ins:" ) << " [" << hexValue(DebugAddress) << "]"; if (IsDebug) dbgs() << format(" %d", (*Iter)->getLineNumber ()); dbgs() << "\n"; }; } } while (false) | |||
591 | << hexValue(DebugAddress) << "]";do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { bool IsDebug = (*Iter)->getIsLineDebug (); dbgs() << "Line " << (IsDebug ? "dbg:" : "ins:" ) << " [" << hexValue(DebugAddress) << "]"; if (IsDebug) dbgs() << format(" %d", (*Iter)->getLineNumber ()); dbgs() << "\n"; }; } } while (false) | |||
592 | if (IsDebug)do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { bool IsDebug = (*Iter)->getIsLineDebug (); dbgs() << "Line " << (IsDebug ? "dbg:" : "ins:" ) << " [" << hexValue(DebugAddress) << "]"; if (IsDebug) dbgs() << format(" %d", (*Iter)->getLineNumber ()); dbgs() << "\n"; }; } } while (false) | |||
593 | dbgs() << format(" %d", (*Iter)->getLineNumber());do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { bool IsDebug = (*Iter)->getIsLineDebug (); dbgs() << "Line " << (IsDebug ? "dbg:" : "ins:" ) << " [" << hexValue(DebugAddress) << "]"; if (IsDebug) dbgs() << format(" %d", (*Iter)->getLineNumber ()); dbgs() << "\n"; }; } } while (false) | |||
594 | dbgs() << "\n";do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { bool IsDebug = (*Iter)->getIsLineDebug (); dbgs() << "Line " << (IsDebug ? "dbg:" : "ins:" ) << " [" << hexValue(DebugAddress) << "]"; if (IsDebug) dbgs() << format(" %d", (*Iter)->getLineNumber ()); dbgs() << "\n"; }; } } while (false) | |||
595 | })do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { bool IsDebug = (*Iter)->getIsLineDebug (); dbgs() << "Line " << (IsDebug ? "dbg:" : "ins:" ) << " [" << hexValue(DebugAddress) << "]"; if (IsDebug) dbgs() << format(" %d", (*Iter)->getLineNumber ()); dbgs() << "\n"; }; } } while (false); | |||
596 | // Instruction address before debug line. | |||
597 | if (InstructionAddress < DebugAddress) { | |||
598 | LLVM_DEBUG({do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { dbgs() << "Inserted instruction address: " << hexValue(InstructionAddress) << " before line: " << format("%d", (*Iter)->getLineNumber()) << " [" << hexValue(DebugAddress) << "]\n"; }; } } while (false) | |||
599 | dbgs() << "Inserted instruction address: "do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { dbgs() << "Inserted instruction address: " << hexValue(InstructionAddress) << " before line: " << format("%d", (*Iter)->getLineNumber()) << " [" << hexValue(DebugAddress) << "]\n"; }; } } while (false) | |||
600 | << hexValue(InstructionAddress) << " before line: "do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { dbgs() << "Inserted instruction address: " << hexValue(InstructionAddress) << " before line: " << format("%d", (*Iter)->getLineNumber()) << " [" << hexValue(DebugAddress) << "]\n"; }; } } while (false) | |||
601 | << format("%d", (*Iter)->getLineNumber()) << " ["do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { dbgs() << "Inserted instruction address: " << hexValue(InstructionAddress) << " before line: " << format("%d", (*Iter)->getLineNumber()) << " [" << hexValue(DebugAddress) << "]\n"; }; } } while (false) | |||
602 | << hexValue(DebugAddress) << "]\n";do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { dbgs() << "Inserted instruction address: " << hexValue(InstructionAddress) << " before line: " << format("%d", (*Iter)->getLineNumber()) << " [" << hexValue(DebugAddress) << "]\n"; }; } } while (false) | |||
603 | })do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { dbgs() << "Inserted instruction address: " << hexValue(InstructionAddress) << " before line: " << format("%d", (*Iter)->getLineNumber()) << " [" << hexValue(DebugAddress) << "]\n"; }; } } while (false); | |||
604 | Iter = DebugLines->insert(Iter, InstructionLine); | |||
605 | // The returned iterator points to the inserted instruction. | |||
606 | // Skip it and point to the line acting as reference. | |||
607 | ++Iter; | |||
608 | break; | |||
609 | } | |||
610 | ++Iter; | |||
611 | } | |||
612 | if (Iter == DebugLines->end()) { | |||
613 | // We have reached the end of the source lines and the current | |||
614 | // instruction line address is greater than the last source line. | |||
615 | TraverseLines = false; | |||
616 | DebugLines->push_back(InstructionLine); | |||
617 | } | |||
618 | } else { | |||
619 | DebugLines->push_back(InstructionLine); | |||
620 | } | |||
621 | } | |||
622 | } | |||
623 | ||||
624 | LLVM_DEBUG({do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { dbgs() << format("Lines after merge: %d\n" , DebugLines->size()); size_t Index = 0; for (const LVLine *Line : *DebugLines) { dbgs() << format_decimal(++Index , 5) << ": " << hexValue(Line->getOffset()) << ", (" << ((Line->getIsLineDebug()) ? Line->lineNumberAsStringStripped ( true) : Line->getName()) << ")\n"; } }; } } while ( false) | |||
625 | dbgs() << format("Lines after merge: %d\n", DebugLines->size());do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { dbgs() << format("Lines after merge: %d\n" , DebugLines->size()); size_t Index = 0; for (const LVLine *Line : *DebugLines) { dbgs() << format_decimal(++Index , 5) << ": " << hexValue(Line->getOffset()) << ", (" << ((Line->getIsLineDebug()) ? Line->lineNumberAsStringStripped ( true) : Line->getName()) << ")\n"; } }; } } while ( false) | |||
626 | size_t Index = 0;do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { dbgs() << format("Lines after merge: %d\n" , DebugLines->size()); size_t Index = 0; for (const LVLine *Line : *DebugLines) { dbgs() << format_decimal(++Index , 5) << ": " << hexValue(Line->getOffset()) << ", (" << ((Line->getIsLineDebug()) ? Line->lineNumberAsStringStripped ( true) : Line->getName()) << ")\n"; } }; } } while ( false) | |||
627 | for (const LVLine *Line : *DebugLines) {do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { dbgs() << format("Lines after merge: %d\n" , DebugLines->size()); size_t Index = 0; for (const LVLine *Line : *DebugLines) { dbgs() << format_decimal(++Index , 5) << ": " << hexValue(Line->getOffset()) << ", (" << ((Line->getIsLineDebug()) ? Line->lineNumberAsStringStripped ( true) : Line->getName()) << ")\n"; } }; } } while ( false) | |||
628 | dbgs() << format_decimal(++Index, 5) << ": "do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { dbgs() << format("Lines after merge: %d\n" , DebugLines->size()); size_t Index = 0; for (const LVLine *Line : *DebugLines) { dbgs() << format_decimal(++Index , 5) << ": " << hexValue(Line->getOffset()) << ", (" << ((Line->getIsLineDebug()) ? Line->lineNumberAsStringStripped ( true) : Line->getName()) << ")\n"; } }; } } while ( false) | |||
629 | << hexValue(Line->getOffset()) << ", ("do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { dbgs() << format("Lines after merge: %d\n" , DebugLines->size()); size_t Index = 0; for (const LVLine *Line : *DebugLines) { dbgs() << format_decimal(++Index , 5) << ": " << hexValue(Line->getOffset()) << ", (" << ((Line->getIsLineDebug()) ? Line->lineNumberAsStringStripped ( true) : Line->getName()) << ")\n"; } }; } } while ( false) | |||
630 | << ((Line->getIsLineDebug())do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { dbgs() << format("Lines after merge: %d\n" , DebugLines->size()); size_t Index = 0; for (const LVLine *Line : *DebugLines) { dbgs() << format_decimal(++Index , 5) << ": " << hexValue(Line->getOffset()) << ", (" << ((Line->getIsLineDebug()) ? Line->lineNumberAsStringStripped ( true) : Line->getName()) << ")\n"; } }; } } while ( false) | |||
631 | ? Line->lineNumberAsStringStripped(/*ShowZero=*/true)do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { dbgs() << format("Lines after merge: %d\n" , DebugLines->size()); size_t Index = 0; for (const LVLine *Line : *DebugLines) { dbgs() << format_decimal(++Index , 5) << ": " << hexValue(Line->getOffset()) << ", (" << ((Line->getIsLineDebug()) ? Line->lineNumberAsStringStripped ( true) : Line->getName()) << ")\n"; } }; } } while ( false) | |||
632 | : Line->getName())do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { dbgs() << format("Lines after merge: %d\n" , DebugLines->size()); size_t Index = 0; for (const LVLine *Line : *DebugLines) { dbgs() << format_decimal(++Index , 5) << ": " << hexValue(Line->getOffset()) << ", (" << ((Line->getIsLineDebug()) ? Line->lineNumberAsStringStripped ( true) : Line->getName()) << ")\n"; } }; } } while ( false) | |||
633 | << ")\n";do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { dbgs() << format("Lines after merge: %d\n" , DebugLines->size()); size_t Index = 0; for (const LVLine *Line : *DebugLines) { dbgs() << format_decimal(++Index , 5) << ": " << hexValue(Line->getOffset()) << ", (" << ((Line->getIsLineDebug()) ? Line->lineNumberAsStringStripped ( true) : Line->getName()) << ")\n"; } }; } } while ( false) | |||
634 | }do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { dbgs() << format("Lines after merge: %d\n" , DebugLines->size()); size_t Index = 0; for (const LVLine *Line : *DebugLines) { dbgs() << format_decimal(++Index , 5) << ": " << hexValue(Line->getOffset()) << ", (" << ((Line->getIsLineDebug()) ? Line->lineNumberAsStringStripped ( true) : Line->getName()) << ")\n"; } }; } } while ( false) | |||
635 | })do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { dbgs() << format("Lines after merge: %d\n" , DebugLines->size()); size_t Index = 0; for (const LVLine *Line : *DebugLines) { dbgs() << format_decimal(++Index , 5) << ": " << hexValue(Line->getOffset()) << ", (" << ((Line->getIsLineDebug()) ? Line->lineNumberAsStringStripped ( true) : Line->getName()) << ")\n"; } }; } } while ( false); | |||
636 | ||||
637 | // If this compilation unit does not have line records, traverse its scopes | |||
638 | // and take any collected instruction lines as the working set in order | |||
639 | // to move them to their associated scope. | |||
640 | if (DebugLines->empty()) { | |||
641 | if (const LVScopes *Scopes = CompileUnit->getScopes()) | |||
642 | for (LVScope *Scope : *Scopes) { | |||
643 | LVLines *Lines = ScopeInstructions.find(Scope); | |||
644 | if (Lines) { | |||
645 | ||||
646 | LLVM_DEBUG({do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { size_t Index = 0; dbgs() << "\nSectionIndex: " << format_decimal(SectionIndex, 3) << " Scope DIE: " << hexValue(Scope->getOffset()) << "\n" << format("Instruction lines: %d\n", Lines->size()); for (const LVLine *Line : *Lines) dbgs() << format_decimal(++Index , 5) << ": " << hexValue(Line->getOffset()) << ", (" << Line->getName() << ")\n"; }; } } while (false) | |||
647 | size_t Index = 0;do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { size_t Index = 0; dbgs() << "\nSectionIndex: " << format_decimal(SectionIndex, 3) << " Scope DIE: " << hexValue(Scope->getOffset()) << "\n" << format("Instruction lines: %d\n", Lines->size()); for (const LVLine *Line : *Lines) dbgs() << format_decimal(++Index , 5) << ": " << hexValue(Line->getOffset()) << ", (" << Line->getName() << ")\n"; }; } } while (false) | |||
648 | dbgs() << "\nSectionIndex: " << format_decimal(SectionIndex, 3)do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { size_t Index = 0; dbgs() << "\nSectionIndex: " << format_decimal(SectionIndex, 3) << " Scope DIE: " << hexValue(Scope->getOffset()) << "\n" << format("Instruction lines: %d\n", Lines->size()); for (const LVLine *Line : *Lines) dbgs() << format_decimal(++Index , 5) << ": " << hexValue(Line->getOffset()) << ", (" << Line->getName() << ")\n"; }; } } while (false) | |||
649 | << " Scope DIE: " << hexValue(Scope->getOffset()) << "\n"do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { size_t Index = 0; dbgs() << "\nSectionIndex: " << format_decimal(SectionIndex, 3) << " Scope DIE: " << hexValue(Scope->getOffset()) << "\n" << format("Instruction lines: %d\n", Lines->size()); for (const LVLine *Line : *Lines) dbgs() << format_decimal(++Index , 5) << ": " << hexValue(Line->getOffset()) << ", (" << Line->getName() << ")\n"; }; } } while (false) | |||
650 | << format("Instruction lines: %d\n", Lines->size());do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { size_t Index = 0; dbgs() << "\nSectionIndex: " << format_decimal(SectionIndex, 3) << " Scope DIE: " << hexValue(Scope->getOffset()) << "\n" << format("Instruction lines: %d\n", Lines->size()); for (const LVLine *Line : *Lines) dbgs() << format_decimal(++Index , 5) << ": " << hexValue(Line->getOffset()) << ", (" << Line->getName() << ")\n"; }; } } while (false) | |||
651 | for (const LVLine *Line : *Lines)do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { size_t Index = 0; dbgs() << "\nSectionIndex: " << format_decimal(SectionIndex, 3) << " Scope DIE: " << hexValue(Scope->getOffset()) << "\n" << format("Instruction lines: %d\n", Lines->size()); for (const LVLine *Line : *Lines) dbgs() << format_decimal(++Index , 5) << ": " << hexValue(Line->getOffset()) << ", (" << Line->getName() << ")\n"; }; } } while (false) | |||
652 | dbgs() << format_decimal(++Index, 5) << ": "do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { size_t Index = 0; dbgs() << "\nSectionIndex: " << format_decimal(SectionIndex, 3) << " Scope DIE: " << hexValue(Scope->getOffset()) << "\n" << format("Instruction lines: %d\n", Lines->size()); for (const LVLine *Line : *Lines) dbgs() << format_decimal(++Index , 5) << ": " << hexValue(Line->getOffset()) << ", (" << Line->getName() << ")\n"; }; } } while (false) | |||
653 | << hexValue(Line->getOffset()) << ", (" << Line->getName()do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { size_t Index = 0; dbgs() << "\nSectionIndex: " << format_decimal(SectionIndex, 3) << " Scope DIE: " << hexValue(Scope->getOffset()) << "\n" << format("Instruction lines: %d\n", Lines->size()); for (const LVLine *Line : *Lines) dbgs() << format_decimal(++Index , 5) << ": " << hexValue(Line->getOffset()) << ", (" << Line->getName() << ")\n"; }; } } while (false) | |||
654 | << ")\n";do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { size_t Index = 0; dbgs() << "\nSectionIndex: " << format_decimal(SectionIndex, 3) << " Scope DIE: " << hexValue(Scope->getOffset()) << "\n" << format("Instruction lines: %d\n", Lines->size()); for (const LVLine *Line : *Lines) dbgs() << format_decimal(++Index , 5) << ": " << hexValue(Line->getOffset()) << ", (" << Line->getName() << ")\n"; }; } } while (false) | |||
655 | })do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { size_t Index = 0; dbgs() << "\nSectionIndex: " << format_decimal(SectionIndex, 3) << " Scope DIE: " << hexValue(Scope->getOffset()) << "\n" << format("Instruction lines: %d\n", Lines->size()); for (const LVLine *Line : *Lines) dbgs() << format_decimal(++Index , 5) << ": " << hexValue(Line->getOffset()) << ", (" << Line->getName() << ")\n"; }; } } while (false); | |||
656 | ||||
657 | if (Scope->getIsArtificial()) { | |||
658 | // Add the instruction lines to their artificial scope. | |||
659 | for (LVLine *Line : *Lines) | |||
660 | Scope->addElement(Line); | |||
661 | } else { | |||
662 | DebugLines->append(*Lines); | |||
663 | } | |||
664 | Lines->clear(); | |||
665 | } | |||
666 | } | |||
667 | } | |||
668 | ||||
669 | LVRange *ScopesWithRanges = getSectionRanges(SectionIndex); | |||
670 | ScopesWithRanges->startSearch(); | |||
671 | ||||
672 | // Process collected lines. | |||
673 | LVScope *Scope; | |||
674 | for (LVLine *Line : *DebugLines) { | |||
675 | // Using the current line address, get its associated lexical scope and | |||
676 | // add the line information to it. | |||
677 | Scope = ScopesWithRanges->getEntry(Line->getAddress()); | |||
678 | if (!Scope) { | |||
679 | // If missing scope, use the compile unit. | |||
680 | Scope = CompileUnit; | |||
681 | LLVM_DEBUG({do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { dbgs() << "Adding line to CU: " << hexValue(Line->getOffset()) << ", (" << ((Line ->getIsLineDebug()) ? Line->lineNumberAsStringStripped( true) : Line->getName()) << ")\n"; }; } } while (false ) | |||
682 | dbgs() << "Adding line to CU: " << hexValue(Line->getOffset()) << ", ("do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { dbgs() << "Adding line to CU: " << hexValue(Line->getOffset()) << ", (" << ((Line ->getIsLineDebug()) ? Line->lineNumberAsStringStripped( true) : Line->getName()) << ")\n"; }; } } while (false ) | |||
683 | << ((Line->getIsLineDebug())do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { dbgs() << "Adding line to CU: " << hexValue(Line->getOffset()) << ", (" << ((Line ->getIsLineDebug()) ? Line->lineNumberAsStringStripped( true) : Line->getName()) << ")\n"; }; } } while (false ) | |||
684 | ? Line->lineNumberAsStringStripped(/*ShowZero=*/true)do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { dbgs() << "Adding line to CU: " << hexValue(Line->getOffset()) << ", (" << ((Line ->getIsLineDebug()) ? Line->lineNumberAsStringStripped( true) : Line->getName()) << ")\n"; }; } } while (false ) | |||
685 | : Line->getName())do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { dbgs() << "Adding line to CU: " << hexValue(Line->getOffset()) << ", (" << ((Line ->getIsLineDebug()) ? Line->lineNumberAsStringStripped( true) : Line->getName()) << ")\n"; }; } } while (false ) | |||
686 | << ")\n";do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { dbgs() << "Adding line to CU: " << hexValue(Line->getOffset()) << ", (" << ((Line ->getIsLineDebug()) ? Line->lineNumberAsStringStripped( true) : Line->getName()) << ")\n"; }; } } while (false ) | |||
687 | })do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { dbgs() << "Adding line to CU: " << hexValue(Line->getOffset()) << ", (" << ((Line ->getIsLineDebug()) ? Line->lineNumberAsStringStripped( true) : Line->getName()) << ")\n"; }; } } while (false ); | |||
688 | } | |||
689 | ||||
690 | // Add line object to scope. | |||
691 | Scope->addElement(Line); | |||
692 | ||||
693 | // Report any line zero. | |||
694 | if (options().getWarningLines() && Line->getIsLineDebug() && | |||
695 | !Line->getLineNumber()) | |||
696 | CompileUnit->addLineZero(Line); | |||
697 | ||||
698 | // Some compilers generate ranges in the compile unit; other compilers | |||
699 | // only DW_AT_low_pc/DW_AT_high_pc. In order to correctly map global | |||
700 | // variables, we need to generate the map ranges for the compile unit. | |||
701 | // If we use the ranges stored at the scope level, there are cases where | |||
702 | // the address referenced by a symbol location, is not in the enclosing | |||
703 | // scope, but in an outer one. By using the ranges stored in the compile | |||
704 | // unit, we can catch all those addresses. | |||
705 | if (Line->getIsLineDebug()) | |||
706 | CompileUnit->addMapping(Line, SectionIndex); | |||
707 | ||||
708 | // Resolve any given pattern. | |||
709 | patterns().resolvePatternMatch(Line); | |||
710 | } | |||
711 | ||||
712 | ScopesWithRanges->endSearch(); | |||
713 | } | |||
714 | ||||
715 | void LVBinaryReader::processLines(LVLines *DebugLines, | |||
716 | LVSectionIndex SectionIndex) { | |||
717 | assert(DebugLines && "DebugLines is null.")(static_cast <bool> (DebugLines && "DebugLines is null." ) ? void (0) : __assert_fail ("DebugLines && \"DebugLines is null.\"" , "llvm/lib/DebugInfo/LogicalView/Readers/LVBinaryReader.cpp" , 717, __extension__ __PRETTY_FUNCTION__)); | |||
718 | if (DebugLines->empty() && !ScopeInstructions.findMap(SectionIndex)) | |||
719 | return; | |||
720 | ||||
721 | // If the Compile Unit does not contain comdat functions, use the whole | |||
722 | // set of debug lines, as the addresses don't have conflicts. | |||
723 | if (!CompileUnit->getHasComdatScopes()) { | |||
724 | processLines(DebugLines, SectionIndex, nullptr); | |||
725 | return; | |||
726 | } | |||
727 | ||||
728 | // Find the indexes for the lines whose address is zero. | |||
729 | std::vector<size_t> AddressZero; | |||
730 | LVLines::iterator It = | |||
731 | std::find_if(std::begin(*DebugLines), std::end(*DebugLines), | |||
732 | [](LVLine *Line) { return !Line->getAddress(); }); | |||
733 | while (It != std::end(*DebugLines)) { | |||
734 | AddressZero.emplace_back(std::distance(std::begin(*DebugLines), It)); | |||
735 | It = std::find_if(std::next(It), std::end(*DebugLines), | |||
736 | [](LVLine *Line) { return !Line->getAddress(); }); | |||
737 | } | |||
738 | ||||
739 | // If the set of debug lines does not contain any line with address zero, | |||
740 | // use the whole set. It means we are dealing with an initialization | |||
741 | // section from a fully linked binary. | |||
742 | if (AddressZero.empty()) { | |||
743 | processLines(DebugLines, SectionIndex, nullptr); | |||
744 | return; | |||
745 | } | |||
746 | ||||
747 | // The Compile unit contains comdat functions. Traverse the collected | |||
748 | // debug lines and identify logical groups based on their start and | |||
749 | // address. Each group starts with a zero address. | |||
750 | // Begin, End, Address, IsDone. | |||
751 | using LVBucket = std::tuple<size_t, size_t, LVAddress, bool>; | |||
752 | std::vector<LVBucket> Buckets; | |||
753 | ||||
754 | LVAddress Address; | |||
755 | size_t Begin = 0; | |||
756 | size_t End = 0; | |||
757 | size_t Index = 0; | |||
758 | for (Index = 0; Index < AddressZero.size() - 1; ++Index) { | |||
759 | Begin = AddressZero[Index]; | |||
760 | End = AddressZero[Index + 1] - 1; | |||
761 | Address = (*DebugLines)[End]->getAddress(); | |||
762 | Buckets.emplace_back(Begin, End, Address, false); | |||
763 | } | |||
764 | ||||
765 | // Add the last bucket. | |||
766 | if (Index) { | |||
767 | Begin = AddressZero[Index]; | |||
768 | End = DebugLines->size() - 1; | |||
769 | Address = (*DebugLines)[End]->getAddress(); | |||
770 | Buckets.emplace_back(Begin, End, Address, false); | |||
771 | } | |||
772 | ||||
773 | LLVM_DEBUG({do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { dbgs() << "\nDebug Lines buckets: " << Buckets.size() << "\n"; for (LVBucket &Bucket : Buckets) { dbgs() << "Begin: " << format_decimal (std::get<0>(Bucket), 5) << ", " << "End: " << format_decimal(std::get<1>(Bucket), 5) << ", " << "Address: " << hexValue(std::get<2> (Bucket)) << "\n"; } }; } } while (false) | |||
774 | dbgs() << "\nDebug Lines buckets: " << Buckets.size() << "\n";do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { dbgs() << "\nDebug Lines buckets: " << Buckets.size() << "\n"; for (LVBucket &Bucket : Buckets) { dbgs() << "Begin: " << format_decimal (std::get<0>(Bucket), 5) << ", " << "End: " << format_decimal(std::get<1>(Bucket), 5) << ", " << "Address: " << hexValue(std::get<2> (Bucket)) << "\n"; } }; } } while (false) | |||
775 | for (LVBucket &Bucket : Buckets) {do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { dbgs() << "\nDebug Lines buckets: " << Buckets.size() << "\n"; for (LVBucket &Bucket : Buckets) { dbgs() << "Begin: " << format_decimal (std::get<0>(Bucket), 5) << ", " << "End: " << format_decimal(std::get<1>(Bucket), 5) << ", " << "Address: " << hexValue(std::get<2> (Bucket)) << "\n"; } }; } } while (false) | |||
776 | dbgs() << "Begin: " << format_decimal(std::get<0>(Bucket), 5) << ", "do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { dbgs() << "\nDebug Lines buckets: " << Buckets.size() << "\n"; for (LVBucket &Bucket : Buckets) { dbgs() << "Begin: " << format_decimal (std::get<0>(Bucket), 5) << ", " << "End: " << format_decimal(std::get<1>(Bucket), 5) << ", " << "Address: " << hexValue(std::get<2> (Bucket)) << "\n"; } }; } } while (false) | |||
777 | << "End: " << format_decimal(std::get<1>(Bucket), 5) << ", "do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { dbgs() << "\nDebug Lines buckets: " << Buckets.size() << "\n"; for (LVBucket &Bucket : Buckets) { dbgs() << "Begin: " << format_decimal (std::get<0>(Bucket), 5) << ", " << "End: " << format_decimal(std::get<1>(Bucket), 5) << ", " << "Address: " << hexValue(std::get<2> (Bucket)) << "\n"; } }; } } while (false) | |||
778 | << "Address: " << hexValue(std::get<2>(Bucket)) << "\n";do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { dbgs() << "\nDebug Lines buckets: " << Buckets.size() << "\n"; for (LVBucket &Bucket : Buckets) { dbgs() << "Begin: " << format_decimal (std::get<0>(Bucket), 5) << ", " << "End: " << format_decimal(std::get<1>(Bucket), 5) << ", " << "Address: " << hexValue(std::get<2> (Bucket)) << "\n"; } }; } } while (false) | |||
779 | }do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { dbgs() << "\nDebug Lines buckets: " << Buckets.size() << "\n"; for (LVBucket &Bucket : Buckets) { dbgs() << "Begin: " << format_decimal (std::get<0>(Bucket), 5) << ", " << "End: " << format_decimal(std::get<1>(Bucket), 5) << ", " << "Address: " << hexValue(std::get<2> (Bucket)) << "\n"; } }; } } while (false) | |||
780 | })do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { dbgs() << "\nDebug Lines buckets: " << Buckets.size() << "\n"; for (LVBucket &Bucket : Buckets) { dbgs() << "Begin: " << format_decimal (std::get<0>(Bucket), 5) << ", " << "End: " << format_decimal(std::get<1>(Bucket), 5) << ", " << "Address: " << hexValue(std::get<2> (Bucket)) << "\n"; } }; } } while (false); | |||
781 | ||||
782 | // Traverse the sections and buckets looking for matches on the section | |||
783 | // sizes. In the unlikely event of different buckets with the same size | |||
784 | // process them in order and mark them as done. | |||
785 | LVLines Group; | |||
786 | for (LVSections::reference Entry : Sections) { | |||
787 | LVSectionIndex SectionIndex = Entry.first; | |||
788 | const object::SectionRef Section = Entry.second; | |||
789 | uint64_t Size = Section.getSize(); | |||
790 | LLVM_DEBUG({do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { dbgs() << "\nSection Index: " << format_decimal(SectionIndex, 3) << " , Section Size: " << hexValue(Section.getSize()) << " , Section Address: " << hexValue(Section.getAddress()) << "\n"; }; } } while (false) | |||
791 | dbgs() << "\nSection Index: " << format_decimal(SectionIndex, 3)do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { dbgs() << "\nSection Index: " << format_decimal(SectionIndex, 3) << " , Section Size: " << hexValue(Section.getSize()) << " , Section Address: " << hexValue(Section.getAddress()) << "\n"; }; } } while (false) | |||
792 | << " , Section Size: " << hexValue(Section.getSize())do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { dbgs() << "\nSection Index: " << format_decimal(SectionIndex, 3) << " , Section Size: " << hexValue(Section.getSize()) << " , Section Address: " << hexValue(Section.getAddress()) << "\n"; }; } } while (false) | |||
793 | << " , Section Address: " << hexValue(Section.getAddress())do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { dbgs() << "\nSection Index: " << format_decimal(SectionIndex, 3) << " , Section Size: " << hexValue(Section.getSize()) << " , Section Address: " << hexValue(Section.getAddress()) << "\n"; }; } } while (false) | |||
794 | << "\n";do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { dbgs() << "\nSection Index: " << format_decimal(SectionIndex, 3) << " , Section Size: " << hexValue(Section.getSize()) << " , Section Address: " << hexValue(Section.getAddress()) << "\n"; }; } } while (false) | |||
795 | })do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { { dbgs() << "\nSection Index: " << format_decimal(SectionIndex, 3) << " , Section Size: " << hexValue(Section.getSize()) << " , Section Address: " << hexValue(Section.getAddress()) << "\n"; }; } } while (false); | |||
796 | ||||
797 | for (LVBucket &Bucket : Buckets) { | |||
798 | if (std::get<3>(Bucket)) | |||
799 | // Already done for previous section. | |||
800 | continue; | |||
801 | if (Size == std::get<2>(Bucket)) { | |||
802 | // We have a match on the section size. | |||
803 | Group.clear(); | |||
804 | LVLines::iterator IterStart = DebugLines->begin() + std::get<0>(Bucket); | |||
805 | LVLines::iterator IterEnd = | |||
806 | DebugLines->begin() + std::get<1>(Bucket) + 1; | |||
807 | for (LVLines::iterator Iter = IterStart; Iter < IterEnd; ++Iter) | |||
808 | Group.push_back(*Iter); | |||
809 | processLines(&Group, SectionIndex, /*Function=*/nullptr); | |||
810 | std::get<3>(Bucket) = true; | |||
811 | break; | |||
812 | } | |||
813 | } | |||
814 | } | |||
815 | } | |||
816 | ||||
817 | void LVBinaryReader::print(raw_ostream &OS) const { | |||
818 | OS << "LVBinaryReader\n"; | |||
819 | LLVM_DEBUG(dbgs() << "PrintReader\n")do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType ("BinaryReader")) { dbgs() << "PrintReader\n"; } } while (false); | |||
820 | } |