Bug Summary

File:build/source/llvm/lib/DebugInfo/LogicalView/Readers/LVBinaryReader.cpp
Warning:line 451, column 3
Potential leak of memory pointed to by 'Instructions'

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name LVBinaryReader.cpp -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -analyzer-config-compatibility-mode=true -mrelocation-model pic -pic-level 2 -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -ffunction-sections -fdata-sections -fcoverage-compilation-dir=/build/source/build-llvm/tools/clang/stage2-bins -resource-dir /usr/lib/llvm-17/lib/clang/17 -I lib/DebugInfo/LogicalView -I /build/source/llvm/lib/DebugInfo/LogicalView -I include -I /build/source/llvm/include -D _DEBUG -D _GLIBCXX_ASSERTIONS -D _GNU_SOURCE -D _LIBCPP_ENABLE_ASSERTIONS -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -D _FORTIFY_SOURCE=2 -D NDEBUG -U NDEBUG -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/x86_64-linux-gnu/c++/10 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/backward -internal-isystem /usr/lib/llvm-17/lib/clang/17/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fmacro-prefix-map=/build/source/build-llvm/tools/clang/stage2-bins=build-llvm/tools/clang/stage2-bins -fmacro-prefix-map=/build/source/= -fcoverage-prefix-map=/build/source/build-llvm/tools/clang/stage2-bins=build-llvm/tools/clang/stage2-bins -fcoverage-prefix-map=/build/source/= -source-date-epoch 1676498946 -O2 -Wno-unused-command-line-argument -Wno-unused-parameter -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -Wno-maybe-uninitialized -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wno-comment -Wno-misleading-indentation -std=c++17 -fdeprecated-macro -fdebug-compilation-dir=/build/source/build-llvm/tools/clang/stage2-bins -fdebug-prefix-map=/build/source/build-llvm/tools/clang/stage2-bins=build-llvm/tools/clang/stage2-bins -fdebug-prefix-map=/build/source/= -ferror-limit 19 -fvisibility-inlines-hidden -stack-protector 2 -fgnuc-version=4.2.1 -fcolor-diagnostics -vectorize-loops -vectorize-slp -analyzer-output=html -analyzer-config stable-report-filename=true -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/scan-build-2023-02-15-234951-16494-1 -x c++ /build/source/llvm/lib/DebugInfo/LogicalView/Readers/LVBinaryReader.cpp
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
18using namespace llvm;
19using namespace llvm::logicalview;
20
21#define DEBUG_TYPE"BinaryReader" "BinaryReader"
22
23// Function names extracted from the object symbol table.
24void 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
44void 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
61LVSectionIndex 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
88const 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}
93LVAddress LVSymbolTable::getAddress(StringRef Name) {
94 LVSymbolNames::iterator Iter = SymbolNames.find(std::string(Name));
95 return Iter != SymbolNames.end() ? Iter->second.Address : 0;
96}
97LVSectionIndex 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}
102bool LVSymbolTable::getIsComdat(StringRef Name) {
103 LVSymbolNames::iterator Iter = SymbolNames.find(std::string(Name));
104 return Iter != SymbolNames.end() ? Iter->second.IsComdat : false;
105}
106
107void 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
121void LVBinaryReader::addToSymbolTable(StringRef Name, LVScope *Function,
122 LVSectionIndex SectionIndex) {
123 SymbolTable.add(Name, Function, SectionIndex);
124}
125void LVBinaryReader::addToSymbolTable(StringRef Name, LVAddress Address,
126 LVSectionIndex SectionIndex,
127 bool IsComdat) {
128 SymbolTable.add(Name, Address, SectionIndex, IsComdat);
129}
130LVSectionIndex LVBinaryReader::updateSymbolTable(LVScope *Function) {
131 return SymbolTable.update(Function);
132}
133
134const LVSymbolTableEntry &LVBinaryReader::getSymbolTableEntry(StringRef Name) {
135 return SymbolTable.getEntry(Name);
136}
137LVAddress LVBinaryReader::getSymbolTableAddress(StringRef Name) {
138 return SymbolTable.getAddress(Name);
139}
140LVSectionIndex LVBinaryReader::getSymbolTableIndex(StringRef Name) {
141 return SymbolTable.getIndex(Name);
142}
143bool LVBinaryReader::getSymbolTableIsComdat(StringRef Name) {
144 return SymbolTable.getIsComdat(Name);
145}
146
147void 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
193Error 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
254Expected<std::pair<uint64_t, object::SectionRef>>
255LVBinaryReader::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
286void LVBinaryReader::addSectionRange(LVSectionIndex SectionIndex,
287 LVScope *Scope) {
288 LVRange *ScopesWithRanges = getSectionRanges(SectionIndex);
289 ScopesWithRanges->addEntry(Scope);
290}
291
292void 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
299LVRange *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
313LVBinaryReader::~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
323Error 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__))
;
5
Assuming 'Scope' is non-null
6
'?' condition is true
327
328 // Skip stripped functions.
329 if (Scope->getIsDiscarded())
7
Taking false branch
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)
8
Assuming 'DebugFlag' is false
9
Loop condition is false. Exiting loop
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)
10
Taking false branch
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)
11
Taking false branch
12
Assuming 'DebugFlag' is false
13
Loop condition is false. Exiting loop
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)
14
Assuming 'DebugFlag' is false
15
Loop condition is false. Exiting loop
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();
16
Memory is allocated
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->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), std::
nullopt, 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), std::
nullopt, 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), std::
nullopt, 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), std::
nullopt, 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), std::nullopt, 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), std::
nullopt, 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 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), std::
nullopt, 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 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), std::
nullopt, 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 << "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), std::
nullopt, 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 << 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), std::
nullopt, 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 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), std::
nullopt, 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 << ") " << 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), std::
nullopt, 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 << "\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), std::
nullopt, 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 })do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType
("BinaryReader")) { { std::string BufferCodes; raw_string_ostream
StreamCodes(BufferCodes); StreamCodes << format_bytes(
ArrayRef<uint8_t>(Begin, Begin + BytesConsumed), std::
nullopt, 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)
;
421 // Here we add logical lines to the Instructions. Later on,
422 // the 'processLines()' function will move each created logical line
423 // to its enclosing logical scope, using the debug ranges information
424 // and they will be released when its scope parent is deleted.
425 LVLineAssembler *Line = new LVLineAssembler();
426 Line->setAddress(Address);
427 Line->setName(StringRef(Stream.str()).trim());
428 Instructions->push_back(Line);
429 break;
430 }
431 }
432 Address += BytesConsumed;
433 Begin += BytesConsumed;
434 }
435
436 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)
17
Loop condition is false. Execution continues on line 436
18
Assuming 'DebugFlag' is false
19
Loop condition is false. Exiting loop
437 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)
438 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)
439 << " 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)
440 << "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)
441 << 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)
442 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)
443 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)
444 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)
445 << 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)
446 << ")\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)
447 })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)
;
448
449 // The scope in the assembler names is linked to its own instructions.
450 ScopeInstructions.add(SectionIndex, Scope, Instructions);
451 AssemblerMappings.add(SectionIndex, FirstAddress, Scope);
20
Potential leak of memory pointed to by 'Instructions'
452
453 return Error::success();
454}
455
456Error LVBinaryReader::createInstructions(LVScope *Function,
457 LVSectionIndex SectionIndex) {
458 if (!options().getPrintInstructions())
1
Taking false branch
459 return Error::success();
460
461 LVNameInfo Name = CompileUnit->findPublicName(Function);
462 if (Name.first != LVAddress(UINT64_MAX(18446744073709551615UL)))
2
Assuming field 'first' is not equal to -1
3
Taking true branch
463 return createInstructions(Function, SectionIndex, Name);
4
Calling 'LVBinaryReader::createInstructions'
464
465 return Error::success();
466}
467
468Error LVBinaryReader::createInstructions() {
469 if (!options().getPrintInstructions())
470 return Error::success();
471
472 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)
473 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)
474 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)
475 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)
476 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)
477 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)
478 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)
479 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)
480 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)
481 << "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)
482 << 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)
483 << "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)
484 << 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)
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 })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)
;
487
488 // For each public name in the current compile unit, create the line
489 // records that represent the executable instructions.
490 for (LVPublicNames::const_reference Name : CompileUnit->getPublicNames()) {
491 LVScope *Scope = Name.first;
492 // The symbol table extracted from the object file always contains a
493 // non-empty name (linkage name). However, the logical scope does not
494 // guarantee to have a name for the linkage name (main is one case).
495 // For those cases, set the linkage name the same as the name.
496 if (!Scope->getLinkageNameIndex())
497 Scope->setLinkageName(Scope->getName());
498 LVSectionIndex SectionIndex = getSymbolTableIndex(Scope->getLinkageName());
499 if (Error Err = createInstructions(Scope, SectionIndex, Name.second))
500 return Err;
501 }
502
503 return Error::success();
504}
505
506// During the traversal of the debug information sections, we created the
507// logical lines representing the disassembled instructions from the text
508// section and the logical lines representing the line records from the
509// debug line section. Using the ranges associated with the logical scopes,
510// we will allocate those logical lines to their logical scopes.
511void LVBinaryReader::processLines(LVLines *DebugLines,
512 LVSectionIndex SectionIndex,
513 LVScope *Function) {
514 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"
, 514, __extension__ __PRETTY_FUNCTION__))
;
515
516 // Just return if this compilation unit does not have any line records
517 // and no instruction lines were created.
518 if (DebugLines->empty() && !options().getPrintInstructions())
519 return;
520
521 // Merge the debug lines and instruction lines using their text address;
522 // the logical line representing the debug line record is followed by the
523 // line(s) representing the disassembled instructions, whose addresses are
524 // equal or greater that the line address and less than the address of the
525 // next debug line record.
526 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)
527 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)
528 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)
529 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)
530 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)
531 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)
532 << ", (" << 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)
533 << ((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)
534 ++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)
535 }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 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)
537 })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)
;
538
539 bool TraverseLines = true;
540 LVLines::iterator Iter = DebugLines->begin();
541 while (TraverseLines && Iter != DebugLines->end()) {
542 uint64_t DebugAddress = (*Iter)->getAddress();
543
544 // Get the function with an entry point that matches this line and
545 // its associated assembler entries. In the case of COMDAT, the input
546 // 'Function' is not null. Use it to find its address ranges.
547 LVScope *Scope = Function;
548 if (!Function) {
549 Scope = AssemblerMappings.find(SectionIndex, DebugAddress);
550 if (!Scope) {
551 ++Iter;
552 continue;
553 }
554 }
555
556 // Get the associated instructions for the found 'Scope'.
557 LVLines InstructionLines;
558 LVLines *Lines = ScopeInstructions.find(SectionIndex, Scope);
559 if (Lines)
560 InstructionLines = std::move(*Lines);
561
562 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)
563 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)
564 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)
565 << " 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)
566 << 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)
567 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)
568 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)
569 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)
570 << 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)
571 << ")\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)
572 })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)
;
573
574 // Continue with next debug line if there are not instructions lines.
575 if (InstructionLines.empty()) {
576 ++Iter;
577 continue;
578 }
579
580 for (LVLine *InstructionLine : InstructionLines) {
581 uint64_t InstructionAddress = InstructionLine->getAddress();
582 LLVM_DEBUG({do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType
("BinaryReader")) { { dbgs() << "Instruction address: "
<< hexValue(InstructionAddress) << "\n"; }; } } while
(false)
583 dbgs() << "Instruction address: " << hexValue(InstructionAddress)do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType
("BinaryReader")) { { dbgs() << "Instruction address: "
<< hexValue(InstructionAddress) << "\n"; }; } } while
(false)
584 << "\n";do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType
("BinaryReader")) { { dbgs() << "Instruction address: "
<< hexValue(InstructionAddress) << "\n"; }; } } while
(false)
585 })do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType
("BinaryReader")) { { dbgs() << "Instruction address: "
<< hexValue(InstructionAddress) << "\n"; }; } } while
(false)
;
586 if (TraverseLines) {
587 while (Iter != DebugLines->end()) {
588 DebugAddress = (*Iter)->getAddress();
589 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)
590 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)
591 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)
592 << 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)
593 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)
594 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)
595 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)
596 })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)
;
597 // Instruction address before debug line.
598 if (InstructionAddress < DebugAddress) {
599 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)
600 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)
601 << 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)
602 << 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)
603 << 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)
604 })do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType
("BinaryReader")) { { dbgs() << "Inserted instruction address: "
<< hexValue(InstructionAddress) << " before line: "
<< format("%d", (*Iter)->getLineNumber()) << " ["
<< hexValue(DebugAddress) << "]\n"; }; } } while
(false)
;
605 Iter = DebugLines->insert(Iter, InstructionLine);
606 // The returned iterator points to the inserted instruction.
607 // Skip it and point to the line acting as reference.
608 ++Iter;
609 break;
610 }
611 ++Iter;
612 }
613 if (Iter == DebugLines->end()) {
614 // We have reached the end of the source lines and the current
615 // instruction line address is greater than the last source line.
616 TraverseLines = false;
617 DebugLines->push_back(InstructionLine);
618 }
619 } else {
620 DebugLines->push_back(InstructionLine);
621 }
622 }
623 }
624
625 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)
626 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)
627 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)
628 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)
629 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)
630 << 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)
631 << ((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)
632 ? 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)
633 : 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)
634 << ")\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)
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 })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)
;
637
638 // If this compilation unit does not have line records, traverse its scopes
639 // and take any collected instruction lines as the working set in order
640 // to move them to their associated scope.
641 if (DebugLines->empty()) {
642 if (const LVScopes *Scopes = CompileUnit->getScopes())
643 for (LVScope *Scope : *Scopes) {
644 LVLines *Lines = ScopeInstructions.find(Scope);
645 if (Lines) {
646
647 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)
648 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)
649 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)
650 << " 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)
651 << 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)
652 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)
653 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)
654 << 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)
655 << ")\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)
656 })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)
;
657
658 if (Scope->getIsArtificial()) {
659 // Add the instruction lines to their artificial scope.
660 for (LVLine *Line : *Lines)
661 Scope->addElement(Line);
662 } else {
663 DebugLines->append(*Lines);
664 }
665 Lines->clear();
666 }
667 }
668 }
669
670 LVRange *ScopesWithRanges = getSectionRanges(SectionIndex);
671 ScopesWithRanges->startSearch();
672
673 // Process collected lines.
674 LVScope *Scope;
675 for (LVLine *Line : *DebugLines) {
676 // Using the current line address, get its associated lexical scope and
677 // add the line information to it.
678 Scope = ScopesWithRanges->getEntry(Line->getAddress());
679 if (!Scope) {
680 // If missing scope, use the compile unit.
681 Scope = CompileUnit;
682 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
)
683 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
)
684 << ((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
)
685 ? 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
)
686 : 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
)
687 << ")\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
)
688 })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
)
;
689 }
690
691 // Add line object to scope.
692 Scope->addElement(Line);
693
694 // Report any line zero.
695 if (options().getWarningLines() && Line->getIsLineDebug() &&
696 !Line->getLineNumber())
697 CompileUnit->addLineZero(Line);
698
699 // Some compilers generate ranges in the compile unit; other compilers
700 // only DW_AT_low_pc/DW_AT_high_pc. In order to correctly map global
701 // variables, we need to generate the map ranges for the compile unit.
702 // If we use the ranges stored at the scope level, there are cases where
703 // the address referenced by a symbol location, is not in the enclosing
704 // scope, but in an outer one. By using the ranges stored in the compile
705 // unit, we can catch all those addresses.
706 if (Line->getIsLineDebug())
707 CompileUnit->addMapping(Line, SectionIndex);
708
709 // Resolve any given pattern.
710 patterns().resolvePatternMatch(Line);
711 }
712
713 ScopesWithRanges->endSearch();
714}
715
716void LVBinaryReader::processLines(LVLines *DebugLines,
717 LVSectionIndex SectionIndex) {
718 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"
, 718, __extension__ __PRETTY_FUNCTION__))
;
719 if (DebugLines->empty() && !ScopeInstructions.findMap(SectionIndex))
720 return;
721
722 // If the Compile Unit does not contain comdat functions, use the whole
723 // set of debug lines, as the addresses don't have conflicts.
724 if (!CompileUnit->getHasComdatScopes()) {
725 processLines(DebugLines, SectionIndex, nullptr);
726 return;
727 }
728
729 // Find the indexes for the lines whose address is zero.
730 std::vector<size_t> AddressZero;
731 LVLines::iterator It =
732 std::find_if(std::begin(*DebugLines), std::end(*DebugLines),
733 [](LVLine *Line) { return !Line->getAddress(); });
734 while (It != std::end(*DebugLines)) {
735 AddressZero.emplace_back(std::distance(std::begin(*DebugLines), It));
736 It = std::find_if(std::next(It), std::end(*DebugLines),
737 [](LVLine *Line) { return !Line->getAddress(); });
738 }
739
740 // If the set of debug lines does not contain any line with address zero,
741 // use the whole set. It means we are dealing with an initialization
742 // section from a fully linked binary.
743 if (AddressZero.empty()) {
744 processLines(DebugLines, SectionIndex, nullptr);
745 return;
746 }
747
748 // The Compile unit contains comdat functions. Traverse the collected
749 // debug lines and identify logical groups based on their start and
750 // address. Each group starts with a zero address.
751 // Begin, End, Address, IsDone.
752 using LVBucket = std::tuple<size_t, size_t, LVAddress, bool>;
753 std::vector<LVBucket> Buckets;
754
755 LVAddress Address;
756 size_t Begin = 0;
757 size_t End = 0;
758 size_t Index = 0;
759 for (Index = 0; Index < AddressZero.size() - 1; ++Index) {
760 Begin = AddressZero[Index];
761 End = AddressZero[Index + 1] - 1;
762 Address = (*DebugLines)[End]->getAddress();
763 Buckets.emplace_back(Begin, End, Address, false);
764 }
765
766 // Add the last bucket.
767 if (Index) {
768 Begin = AddressZero[Index];
769 End = DebugLines->size() - 1;
770 Address = (*DebugLines)[End]->getAddress();
771 Buckets.emplace_back(Begin, End, Address, false);
772 }
773
774 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)
775 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)
776 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)
777 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)
778 << "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)
779 << "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)
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 })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)
;
782
783 // Traverse the sections and buckets looking for matches on the section
784 // sizes. In the unlikely event of different buckets with the same size
785 // process them in order and mark them as done.
786 LVLines Group;
787 for (LVSections::reference Entry : Sections) {
788 LVSectionIndex SectionIndex = Entry.first;
789 const object::SectionRef Section = Entry.second;
790 uint64_t Size = Section.getSize();
791 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)
792 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)
793 << " , 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)
794 << " , 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)
795 << "\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)
796 })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)
;
797
798 for (LVBucket &Bucket : Buckets) {
799 if (std::get<3>(Bucket))
800 // Already done for previous section.
801 continue;
802 if (Size == std::get<2>(Bucket)) {
803 // We have a match on the section size.
804 Group.clear();
805 LVLines::iterator IterStart = DebugLines->begin() + std::get<0>(Bucket);
806 LVLines::iterator IterEnd =
807 DebugLines->begin() + std::get<1>(Bucket) + 1;
808 for (LVLines::iterator Iter = IterStart; Iter < IterEnd; ++Iter)
809 Group.push_back(*Iter);
810 processLines(&Group, SectionIndex, /*Function=*/nullptr);
811 std::get<3>(Bucket) = true;
812 break;
813 }
814 }
815 }
816}
817
818void LVBinaryReader::print(raw_ostream &OS) const {
819 OS << "LVBinaryReader\n";
820 LLVM_DEBUG(dbgs() << "PrintReader\n")do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType
("BinaryReader")) { dbgs() << "PrintReader\n"; } } while
(false)
;
821}