blob: cda3e75fbc3e7ce56be8dfdc55a39327af8753a9 [file] [log] [blame]
Eugene Zelenkoe94042c2017-02-27 23:43:14 +00001//===- DWARFDebugLine.cpp -------------------------------------------------===//
Benjamin Kramer5acab502011-09-15 02:12:05 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Paul Robinson9d4eb692017-05-01 23:27:55 +000010#include "llvm/DebugInfo/DWARF/DWARFDebugLine.h"
Eugene Zelenkoe94042c2017-02-27 23:43:14 +000011#include "llvm/ADT/SmallString.h"
Zachary Turner264b5d92017-06-07 03:48:56 +000012#include "llvm/BinaryFormat/Dwarf.h"
George Rimarf8a96422017-04-21 09:12:18 +000013#include "llvm/DebugInfo/DWARF/DWARFContext.h"
Paul Robinson2bc38732017-05-02 21:40:47 +000014#include "llvm/DebugInfo/DWARF/DWARFFormValue.h"
Eugene Zelenkoe94042c2017-02-27 23:43:14 +000015#include "llvm/DebugInfo/DWARF/DWARFRelocMap.h"
Benjamin Kramer5acab502011-09-15 02:12:05 +000016#include "llvm/Support/Format.h"
Alexey Samsonov45be7932012-08-30 07:49:50 +000017#include "llvm/Support/Path.h"
Benjamin Kramer5acab502011-09-15 02:12:05 +000018#include "llvm/Support/raw_ostream.h"
Benjamin Kramera57c46a2011-09-15 02:19:33 +000019#include <algorithm>
Eugene Zelenkoe94042c2017-02-27 23:43:14 +000020#include <cassert>
21#include <cinttypes>
22#include <cstdint>
23#include <cstdio>
24#include <utility>
25
Benjamin Kramer5acab502011-09-15 02:12:05 +000026using namespace llvm;
27using namespace dwarf;
Eugene Zelenkoe94042c2017-02-27 23:43:14 +000028
Alexey Samsonovdce67342014-05-15 21:24:32 +000029typedef DILineInfoSpecifier::FileLineInfoKind FileLineInfoKind;
Paul Robinson2bc38732017-05-02 21:40:47 +000030namespace {
31struct ContentDescriptor {
32 dwarf::LineNumberEntryFormat Type;
33 dwarf::Form Form;
34};
35typedef SmallVector<ContentDescriptor, 4> ContentDescriptors;
36} // end anonmyous namespace
Benjamin Kramer5acab502011-09-15 02:12:05 +000037
Dehao Chen1b54fce2016-04-28 22:09:37 +000038DWARFDebugLine::Prologue::Prologue() { clear(); }
Alexey Samsonov836b1ae2014-04-29 21:28:13 +000039
40void DWARFDebugLine::Prologue::clear() {
41 TotalLength = Version = PrologueLength = 0;
Paul Robinson2bc38732017-05-02 21:40:47 +000042 AddressSize = SegSelectorSize = 0;
Alexey Samsonov836b1ae2014-04-29 21:28:13 +000043 MinInstLength = MaxOpsPerInst = DefaultIsStmt = LineBase = LineRange = 0;
44 OpcodeBase = 0;
Ed Maste6d0bee52015-05-28 15:38:17 +000045 IsDWARF64 = false;
Alexey Samsonov836b1ae2014-04-29 21:28:13 +000046 StandardOpcodeLengths.clear();
47 IncludeDirectories.clear();
48 FileNames.clear();
49}
50
Benjamin Kramer5acab502011-09-15 02:12:05 +000051void DWARFDebugLine::Prologue::dump(raw_ostream &OS) const {
52 OS << "Line table prologue:\n"
Ed Maste6d0bee52015-05-28 15:38:17 +000053 << format(" total_length: 0x%8.8" PRIx64 "\n", TotalLength)
David Blaikie1d4736e2014-02-24 23:58:54 +000054 << format(" version: %u\n", Version)
Paul Robinson2bc38732017-05-02 21:40:47 +000055 << format(Version >= 5 ? " address_size: %u\n" : "", AddressSize)
56 << format(Version >= 5 ? " seg_select_size: %u\n" : "", SegSelectorSize)
Ed Maste6d0bee52015-05-28 15:38:17 +000057 << format(" prologue_length: 0x%8.8" PRIx64 "\n", PrologueLength)
David Blaikie1d4736e2014-02-24 23:58:54 +000058 << format(" min_inst_length: %u\n", MinInstLength)
59 << format(Version >= 4 ? "max_ops_per_inst: %u\n" : "", MaxOpsPerInst)
60 << format(" default_is_stmt: %u\n", DefaultIsStmt)
61 << format(" line_base: %i\n", LineBase)
62 << format(" line_range: %u\n", LineRange)
63 << format(" opcode_base: %u\n", OpcodeBase);
Benjamin Kramer5acab502011-09-15 02:12:05 +000064
Paul Robinson9d4eb692017-05-01 23:27:55 +000065 for (uint32_t I = 0; I != StandardOpcodeLengths.size(); ++I)
Mehdi Amini149f6ea2016-10-05 05:59:29 +000066 OS << format("standard_opcode_lengths[%s] = %u\n",
Paul Robinson9d4eb692017-05-01 23:27:55 +000067 LNStandardString(I + 1).data(), StandardOpcodeLengths[I]);
Benjamin Kramer5acab502011-09-15 02:12:05 +000068
69 if (!IncludeDirectories.empty())
Paul Robinson9d4eb692017-05-01 23:27:55 +000070 for (uint32_t I = 0; I != IncludeDirectories.size(); ++I)
71 OS << format("include_directories[%3u] = '", I + 1)
72 << IncludeDirectories[I] << "'\n";
Benjamin Kramer5acab502011-09-15 02:12:05 +000073
74 if (!FileNames.empty()) {
75 OS << " Dir Mod Time File Len File Name\n"
76 << " ---- ---------- ---------- -----------"
77 "----------------\n";
Paul Robinson9d4eb692017-05-01 23:27:55 +000078 for (uint32_t I = 0; I != FileNames.size(); ++I) {
79 const FileNameEntry &FileEntry = FileNames[I];
80 OS << format("file_names[%3u] %4" PRIu64 " ", I + 1, FileEntry.DirIdx)
81 << format("0x%8.8" PRIx64 " 0x%8.8" PRIx64 " ", FileEntry.ModTime,
82 FileEntry.Length)
83 << FileEntry.Name << '\n';
Benjamin Kramer5acab502011-09-15 02:12:05 +000084 }
85 }
86}
87
Paul Robinson2bc38732017-05-02 21:40:47 +000088// Parse v2-v4 directory and file tables.
89static void
90parseV2DirFileTables(DataExtractor DebugLineData, uint32_t *OffsetPtr,
91 uint64_t EndPrologueOffset,
92 std::vector<StringRef> &IncludeDirectories,
93 std::vector<DWARFDebugLine::FileNameEntry> &FileNames) {
94 while (*OffsetPtr < EndPrologueOffset) {
95 StringRef S = DebugLineData.getCStrRef(OffsetPtr);
96 if (S.empty())
97 break;
98 IncludeDirectories.push_back(S);
99 }
100
101 while (*OffsetPtr < EndPrologueOffset) {
102 StringRef Name = DebugLineData.getCStrRef(OffsetPtr);
103 if (Name.empty())
104 break;
105 DWARFDebugLine::FileNameEntry FileEntry;
106 FileEntry.Name = Name;
107 FileEntry.DirIdx = DebugLineData.getULEB128(OffsetPtr);
108 FileEntry.ModTime = DebugLineData.getULEB128(OffsetPtr);
109 FileEntry.Length = DebugLineData.getULEB128(OffsetPtr);
110 FileNames.push_back(FileEntry);
111 }
112}
113
114// Parse v5 directory/file entry content descriptions.
115// Returns the descriptors, or an empty vector if we did not find a path or
116// ran off the end of the prologue.
117static ContentDescriptors
118parseV5EntryFormat(DataExtractor DebugLineData, uint32_t *OffsetPtr,
119 uint64_t EndPrologueOffset) {
120 ContentDescriptors Descriptors;
121 int FormatCount = DebugLineData.getU8(OffsetPtr);
122 bool HasPath = false;
123 for (int I = 0; I != FormatCount; ++I) {
124 if (*OffsetPtr >= EndPrologueOffset)
125 return ContentDescriptors();
126 ContentDescriptor Descriptor;
127 Descriptor.Type =
128 dwarf::LineNumberEntryFormat(DebugLineData.getULEB128(OffsetPtr));
129 Descriptor.Form = dwarf::Form(DebugLineData.getULEB128(OffsetPtr));
130 if (Descriptor.Type == dwarf::DW_LNCT_path)
131 HasPath = true;
132 Descriptors.push_back(Descriptor);
133 }
134 return HasPath ? Descriptors : ContentDescriptors();
135}
136
137static bool
138parseV5DirFileTables(DataExtractor DebugLineData, uint32_t *OffsetPtr,
139 uint64_t EndPrologueOffset,
140 std::vector<StringRef> &IncludeDirectories,
141 std::vector<DWARFDebugLine::FileNameEntry> &FileNames) {
142 // Get the directory entry description.
143 ContentDescriptors DirDescriptors =
144 parseV5EntryFormat(DebugLineData, OffsetPtr, EndPrologueOffset);
145 if (DirDescriptors.empty())
146 return false;
147
148 // Get the directory entries, according to the format described above.
149 int DirEntryCount = DebugLineData.getU8(OffsetPtr);
150 for (int I = 0; I != DirEntryCount; ++I) {
151 if (*OffsetPtr >= EndPrologueOffset)
152 return false;
153 for (auto Descriptor : DirDescriptors) {
154 DWARFFormValue Value(Descriptor.Form);
155 switch (Descriptor.Type) {
156 case DW_LNCT_path:
157 if (!Value.extractValue(DebugLineData, OffsetPtr, nullptr))
158 return false;
159 IncludeDirectories.push_back(Value.getAsCString().getValue());
160 break;
161 default:
162 if (!Value.skipValue(DebugLineData, OffsetPtr, nullptr))
163 return false;
164 }
165 }
166 }
167
168 // Get the file entry description.
169 ContentDescriptors FileDescriptors =
170 parseV5EntryFormat(DebugLineData, OffsetPtr, EndPrologueOffset);
171 if (FileDescriptors.empty())
172 return false;
173
174 // Get the file entries, according to the format described above.
175 int FileEntryCount = DebugLineData.getU8(OffsetPtr);
176 for (int I = 0; I != FileEntryCount; ++I) {
177 if (*OffsetPtr >= EndPrologueOffset)
178 return false;
179 DWARFDebugLine::FileNameEntry FileEntry;
180 for (auto Descriptor : FileDescriptors) {
181 DWARFFormValue Value(Descriptor.Form);
182 if (!Value.extractValue(DebugLineData, OffsetPtr, nullptr))
183 return false;
184 switch (Descriptor.Type) {
185 case DW_LNCT_path:
186 FileEntry.Name = Value.getAsCString().getValue();
187 break;
188 case DW_LNCT_directory_index:
189 FileEntry.DirIdx = Value.getAsUnsignedConstant().getValue();
190 break;
191 case DW_LNCT_timestamp:
192 FileEntry.ModTime = Value.getAsUnsignedConstant().getValue();
193 break;
194 case DW_LNCT_size:
195 FileEntry.Length = Value.getAsUnsignedConstant().getValue();
196 break;
197 // FIXME: Add MD5
198 default:
199 break;
200 }
201 }
202 FileNames.push_back(FileEntry);
203 }
204 return true;
205}
206
Paul Robinson9d4eb692017-05-01 23:27:55 +0000207bool DWARFDebugLine::Prologue::parse(DataExtractor DebugLineData,
208 uint32_t *OffsetPtr) {
209 const uint64_t PrologueOffset = *OffsetPtr;
Alexey Samsonov836b1ae2014-04-29 21:28:13 +0000210
211 clear();
Paul Robinson9d4eb692017-05-01 23:27:55 +0000212 TotalLength = DebugLineData.getU32(OffsetPtr);
Ed Maste6d0bee52015-05-28 15:38:17 +0000213 if (TotalLength == UINT32_MAX) {
214 IsDWARF64 = true;
Paul Robinson9d4eb692017-05-01 23:27:55 +0000215 TotalLength = DebugLineData.getU64(OffsetPtr);
Ed Maste6d0bee52015-05-28 15:38:17 +0000216 } else if (TotalLength > 0xffffff00) {
217 return false;
218 }
Paul Robinson9d4eb692017-05-01 23:27:55 +0000219 Version = DebugLineData.getU16(OffsetPtr);
Alexey Samsonov836b1ae2014-04-29 21:28:13 +0000220 if (Version < 2)
221 return false;
222
Paul Robinson2bc38732017-05-02 21:40:47 +0000223 if (Version >= 5) {
224 AddressSize = DebugLineData.getU8(OffsetPtr);
225 SegSelectorSize = DebugLineData.getU8(OffsetPtr);
226 }
227
Paul Robinson9d4eb692017-05-01 23:27:55 +0000228 PrologueLength = DebugLineData.getUnsigned(OffsetPtr, sizeofPrologueLength());
229 const uint64_t EndPrologueOffset = PrologueLength + *OffsetPtr;
230 MinInstLength = DebugLineData.getU8(OffsetPtr);
Alexey Samsonov836b1ae2014-04-29 21:28:13 +0000231 if (Version >= 4)
Paul Robinson9d4eb692017-05-01 23:27:55 +0000232 MaxOpsPerInst = DebugLineData.getU8(OffsetPtr);
233 DefaultIsStmt = DebugLineData.getU8(OffsetPtr);
234 LineBase = DebugLineData.getU8(OffsetPtr);
235 LineRange = DebugLineData.getU8(OffsetPtr);
236 OpcodeBase = DebugLineData.getU8(OffsetPtr);
Alexey Samsonov836b1ae2014-04-29 21:28:13 +0000237
238 StandardOpcodeLengths.reserve(OpcodeBase - 1);
Paul Robinson9d4eb692017-05-01 23:27:55 +0000239 for (uint32_t I = 1; I < OpcodeBase; ++I) {
240 uint8_t OpLen = DebugLineData.getU8(OffsetPtr);
241 StandardOpcodeLengths.push_back(OpLen);
Alexey Samsonov836b1ae2014-04-29 21:28:13 +0000242 }
243
Paul Robinson2bc38732017-05-02 21:40:47 +0000244 if (Version >= 5) {
245 if (!parseV5DirFileTables(DebugLineData, OffsetPtr, EndPrologueOffset,
246 IncludeDirectories, FileNames)) {
247 fprintf(stderr,
248 "warning: parsing line table prologue at 0x%8.8" PRIx64
249 " found an invalid directory or file table description at"
250 " 0x%8.8" PRIx64 "\n", PrologueOffset, (uint64_t)*OffsetPtr);
251 return false;
252 }
253 } else
254 parseV2DirFileTables(DebugLineData, OffsetPtr, EndPrologueOffset,
255 IncludeDirectories, FileNames);
Alexey Samsonov836b1ae2014-04-29 21:28:13 +0000256
Paul Robinson9d4eb692017-05-01 23:27:55 +0000257 if (*OffsetPtr != EndPrologueOffset) {
258 fprintf(stderr,
259 "warning: parsing line table prologue at 0x%8.8" PRIx64
260 " should have ended at 0x%8.8" PRIx64
261 " but it ended at 0x%8.8" PRIx64 "\n",
262 PrologueOffset, EndPrologueOffset, (uint64_t)*OffsetPtr);
Alexey Samsonov836b1ae2014-04-29 21:28:13 +0000263 return false;
264 }
265 return true;
266}
267
Paul Robinson9d4eb692017-05-01 23:27:55 +0000268DWARFDebugLine::Row::Row(bool DefaultIsStmt) { reset(DefaultIsStmt); }
Alexey Samsonov836b1ae2014-04-29 21:28:13 +0000269
Benjamin Kramer5acab502011-09-15 02:12:05 +0000270void DWARFDebugLine::Row::postAppend() {
271 BasicBlock = false;
272 PrologueEnd = false;
273 EpilogueBegin = false;
274}
275
Paul Robinson9d4eb692017-05-01 23:27:55 +0000276void DWARFDebugLine::Row::reset(bool DefaultIsStmt) {
Benjamin Kramer5acab502011-09-15 02:12:05 +0000277 Address = 0;
278 Line = 1;
279 Column = 0;
280 File = 1;
281 Isa = 0;
Diego Novillo5b5cf502014-02-14 19:27:53 +0000282 Discriminator = 0;
Paul Robinson9d4eb692017-05-01 23:27:55 +0000283 IsStmt = DefaultIsStmt;
Benjamin Kramer5acab502011-09-15 02:12:05 +0000284 BasicBlock = false;
285 EndSequence = false;
286 PrologueEnd = false;
287 EpilogueBegin = false;
288}
289
Greg Clayton67070462017-05-02 22:48:52 +0000290void DWARFDebugLine::Row::dumpTableHeader(raw_ostream &OS) {
291 OS << "Address Line Column File ISA Discriminator Flags\n"
292 << "------------------ ------ ------ ------ --- ------------- "
293 "-------------\n";
294}
295
Benjamin Kramer5acab502011-09-15 02:12:05 +0000296void DWARFDebugLine::Row::dump(raw_ostream &OS) const {
Benjamin Kramerf3da5292011-11-05 08:57:40 +0000297 OS << format("0x%16.16" PRIx64 " %6u %6u", Address, Line, Column)
Diego Novillo5b5cf502014-02-14 19:27:53 +0000298 << format(" %6u %3u %13u ", File, Isa, Discriminator)
Dehao Chen1b54fce2016-04-28 22:09:37 +0000299 << (IsStmt ? " is_stmt" : "") << (BasicBlock ? " basic_block" : "")
Benjamin Kramer5acab502011-09-15 02:12:05 +0000300 << (PrologueEnd ? " prologue_end" : "")
301 << (EpilogueBegin ? " epilogue_begin" : "")
Dehao Chen1b54fce2016-04-28 22:09:37 +0000302 << (EndSequence ? " end_sequence" : "") << '\n';
Benjamin Kramer5acab502011-09-15 02:12:05 +0000303}
304
Dehao Chen1b54fce2016-04-28 22:09:37 +0000305DWARFDebugLine::Sequence::Sequence() { reset(); }
Alexey Samsonov836b1ae2014-04-29 21:28:13 +0000306
307void DWARFDebugLine::Sequence::reset() {
308 LowPC = 0;
309 HighPC = 0;
310 FirstRowIndex = 0;
311 LastRowIndex = 0;
312 Empty = true;
313}
314
Dehao Chen1b54fce2016-04-28 22:09:37 +0000315DWARFDebugLine::LineTable::LineTable() { clear(); }
Alexey Samsonov836b1ae2014-04-29 21:28:13 +0000316
Benjamin Kramer5acab502011-09-15 02:12:05 +0000317void DWARFDebugLine::LineTable::dump(raw_ostream &OS) const {
318 Prologue.dump(OS);
319 OS << '\n';
320
321 if (!Rows.empty()) {
Greg Clayton67070462017-05-02 22:48:52 +0000322 Row::dumpTableHeader(OS);
Alexey Samsonov1eabf982014-03-13 07:52:54 +0000323 for (const Row &R : Rows) {
324 R.dump(OS);
325 }
Benjamin Kramer5acab502011-09-15 02:12:05 +0000326 }
327}
328
Alexey Samsonov836b1ae2014-04-29 21:28:13 +0000329void DWARFDebugLine::LineTable::clear() {
330 Prologue.clear();
331 Rows.clear();
332 Sequences.clear();
333}
334
Alexey Samsonov110d5952014-04-30 00:09:19 +0000335DWARFDebugLine::ParsingState::ParsingState(struct LineTable *LT)
336 : LineTable(LT), RowNumber(0) {
337 resetRowAndSequence();
338}
Nick Lewycky4d044922011-09-15 03:41:51 +0000339
Alexey Samsonov110d5952014-04-30 00:09:19 +0000340void DWARFDebugLine::ParsingState::resetRowAndSequence() {
341 Row.reset(LineTable->Prologue.DefaultIsStmt);
342 Sequence.reset();
343}
344
Paul Robinson9d4eb692017-05-01 23:27:55 +0000345void DWARFDebugLine::ParsingState::appendRowToMatrix(uint32_t Offset) {
Alexey Samsonov110d5952014-04-30 00:09:19 +0000346 if (Sequence.Empty) {
Alexey Samsonov947228c2012-08-07 11:46:57 +0000347 // Record the beginning of instruction sequence.
Alexey Samsonov110d5952014-04-30 00:09:19 +0000348 Sequence.Empty = false;
349 Sequence.LowPC = Row.Address;
350 Sequence.FirstRowIndex = RowNumber;
Alexey Samsonov947228c2012-08-07 11:46:57 +0000351 }
Alexey Samsonov110d5952014-04-30 00:09:19 +0000352 ++RowNumber;
353 LineTable->appendRow(Row);
354 if (Row.EndSequence) {
Alexey Samsonov947228c2012-08-07 11:46:57 +0000355 // Record the end of instruction sequence.
Alexey Samsonov110d5952014-04-30 00:09:19 +0000356 Sequence.HighPC = Row.Address;
357 Sequence.LastRowIndex = RowNumber;
358 if (Sequence.isValid())
359 LineTable->appendSequence(Sequence);
360 Sequence.reset();
Alexey Samsonov947228c2012-08-07 11:46:57 +0000361 }
Alexey Samsonov110d5952014-04-30 00:09:19 +0000362 Row.postAppend();
Benjamin Kramer5acab502011-09-15 02:12:05 +0000363}
364
Benjamin Kramer5acab502011-09-15 02:12:05 +0000365const DWARFDebugLine::LineTable *
Paul Robinson9d4eb692017-05-01 23:27:55 +0000366DWARFDebugLine::getLineTable(uint32_t Offset) const {
367 LineTableConstIter Pos = LineTableMap.find(Offset);
368 if (Pos != LineTableMap.end())
369 return &Pos->second;
Craig Topper2617dcc2014-04-15 06:32:26 +0000370 return nullptr;
Benjamin Kramer5acab502011-09-15 02:12:05 +0000371}
372
Benjamin Kramer679e1752011-09-15 20:43:18 +0000373const DWARFDebugLine::LineTable *
Paul Robinson9d4eb692017-05-01 23:27:55 +0000374DWARFDebugLine::getOrParseLineTable(DataExtractor DebugLineData,
375 uint32_t Offset) {
376 std::pair<LineTableIter, bool> Pos =
377 LineTableMap.insert(LineTableMapTy::value_type(Offset, LineTable()));
378 LineTable *LT = &Pos.first->second;
379 if (Pos.second) {
380 if (!LT->parse(DebugLineData, RelocMap, &Offset))
Craig Topper2617dcc2014-04-15 06:32:26 +0000381 return nullptr;
Benjamin Kramer679e1752011-09-15 20:43:18 +0000382 }
Alexey Samsonov110d5952014-04-30 00:09:19 +0000383 return LT;
Benjamin Kramer679e1752011-09-15 20:43:18 +0000384}
385
Paul Robinson9d4eb692017-05-01 23:27:55 +0000386bool DWARFDebugLine::LineTable::parse(DataExtractor DebugLineData,
Alexey Samsonov110d5952014-04-30 00:09:19 +0000387 const RelocAddrMap *RMap,
Paul Robinson9d4eb692017-05-01 23:27:55 +0000388 uint32_t *OffsetPtr) {
389 const uint32_t DebugLineOffset = *OffsetPtr;
Benjamin Kramer5acab502011-09-15 02:12:05 +0000390
Alexey Samsonov110d5952014-04-30 00:09:19 +0000391 clear();
Benjamin Kramer5acab502011-09-15 02:12:05 +0000392
Paul Robinson9d4eb692017-05-01 23:27:55 +0000393 if (!Prologue.parse(DebugLineData, OffsetPtr)) {
Benjamin Kramer5acab502011-09-15 02:12:05 +0000394 // Restore our offset and return false to indicate failure!
Paul Robinson9d4eb692017-05-01 23:27:55 +0000395 *OffsetPtr = DebugLineOffset;
Benjamin Kramer5acab502011-09-15 02:12:05 +0000396 return false;
397 }
398
Paul Robinson9d4eb692017-05-01 23:27:55 +0000399 const uint32_t EndOffset =
400 DebugLineOffset + Prologue.TotalLength + Prologue.sizeofTotalLength();
Benjamin Kramer5acab502011-09-15 02:12:05 +0000401
Alexey Samsonov110d5952014-04-30 00:09:19 +0000402 ParsingState State(this);
Benjamin Kramer112ec172011-09-15 21:59:13 +0000403
Paul Robinson9d4eb692017-05-01 23:27:55 +0000404 while (*OffsetPtr < EndOffset) {
405 uint8_t Opcode = DebugLineData.getU8(OffsetPtr);
Benjamin Kramer5acab502011-09-15 02:12:05 +0000406
Paul Robinson9d4eb692017-05-01 23:27:55 +0000407 if (Opcode == 0) {
Benjamin Kramer5acab502011-09-15 02:12:05 +0000408 // Extended Opcodes always start with a zero opcode followed by
409 // a uleb128 length so you can skip ones you don't know about
Paul Robinson9d4eb692017-05-01 23:27:55 +0000410 uint32_t ExtOffset = *OffsetPtr;
411 uint64_t Len = DebugLineData.getULEB128(OffsetPtr);
412 uint32_t ArgSize = Len - (*OffsetPtr - ExtOffset);
Benjamin Kramer5acab502011-09-15 02:12:05 +0000413
Paul Robinson9d4eb692017-05-01 23:27:55 +0000414 uint8_t SubOpcode = DebugLineData.getU8(OffsetPtr);
415 switch (SubOpcode) {
Benjamin Kramer5acab502011-09-15 02:12:05 +0000416 case DW_LNE_end_sequence:
417 // Set the end_sequence register of the state machine to true and
418 // append a row to the matrix using the current values of the
419 // state-machine registers. Then reset the registers to the initial
420 // values specified above. Every statement program sequence must end
421 // with a DW_LNE_end_sequence instruction which creates a row whose
422 // address is that of the byte after the last target machine instruction
423 // of the sequence.
Alexey Samsonov110d5952014-04-30 00:09:19 +0000424 State.Row.EndSequence = true;
Paul Robinson9d4eb692017-05-01 23:27:55 +0000425 State.appendRowToMatrix(*OffsetPtr);
Alexey Samsonov110d5952014-04-30 00:09:19 +0000426 State.resetRowAndSequence();
Benjamin Kramer5acab502011-09-15 02:12:05 +0000427 break;
428
429 case DW_LNE_set_address:
430 // Takes a single relocatable address as an operand. The size of the
431 // operand is the size appropriate to hold an address on the target
432 // machine. Set the address register to the value given by the
433 // relocatable address. All of the other statement program opcodes
434 // that affect the address register add a delta to it. This instruction
435 // stores a relocatable value into it instead.
Paul Robinson9d4eb692017-05-01 23:27:55 +0000436 State.Row.Address = getRelocatedValue(
437 DebugLineData, DebugLineData.getAddressSize(), OffsetPtr, RMap);
Benjamin Kramer5acab502011-09-15 02:12:05 +0000438 break;
439
440 case DW_LNE_define_file:
441 // Takes 4 arguments. The first is a null terminated string containing
442 // a source file name. The second is an unsigned LEB128 number
443 // representing the directory index of the directory in which the file
444 // was found. The third is an unsigned LEB128 number representing the
445 // time of last modification of the file. The fourth is an unsigned
446 // LEB128 number representing the length in bytes of the file. The time
447 // and length fields may contain LEB128(0) if the information is not
448 // available.
449 //
450 // The directory index represents an entry in the include_directories
451 // section of the statement program prologue. The index is LEB128(0)
452 // if the file was found in the current directory of the compilation,
453 // LEB128(1) if it was found in the first directory in the
454 // include_directories section, and so on. The directory index is
455 // ignored for file names that represent full path names.
456 //
457 // The files are numbered, starting at 1, in the order in which they
458 // appear; the names in the prologue come before names defined by
459 // the DW_LNE_define_file instruction. These numbers are used in the
460 // the file register of the state machine.
461 {
Paul Robinson9d4eb692017-05-01 23:27:55 +0000462 FileNameEntry FileEntry;
463 FileEntry.Name = DebugLineData.getCStr(OffsetPtr);
464 FileEntry.DirIdx = DebugLineData.getULEB128(OffsetPtr);
465 FileEntry.ModTime = DebugLineData.getULEB128(OffsetPtr);
466 FileEntry.Length = DebugLineData.getULEB128(OffsetPtr);
467 Prologue.FileNames.push_back(FileEntry);
Benjamin Kramer5acab502011-09-15 02:12:05 +0000468 }
469 break;
470
Diego Novillo5b5cf502014-02-14 19:27:53 +0000471 case DW_LNE_set_discriminator:
Paul Robinson9d4eb692017-05-01 23:27:55 +0000472 State.Row.Discriminator = DebugLineData.getULEB128(OffsetPtr);
Diego Novillo5b5cf502014-02-14 19:27:53 +0000473 break;
474
Benjamin Kramer5acab502011-09-15 02:12:05 +0000475 default:
476 // Length doesn't include the zero opcode byte or the length itself, but
477 // it does include the sub_opcode, so we have to adjust for that below
Paul Robinson9d4eb692017-05-01 23:27:55 +0000478 (*OffsetPtr) += ArgSize;
Benjamin Kramer5acab502011-09-15 02:12:05 +0000479 break;
480 }
Paul Robinson9d4eb692017-05-01 23:27:55 +0000481 } else if (Opcode < Prologue.OpcodeBase) {
482 switch (Opcode) {
Benjamin Kramer5acab502011-09-15 02:12:05 +0000483 // Standard Opcodes
484 case DW_LNS_copy:
485 // Takes no arguments. Append a row to the matrix using the
486 // current values of the state-machine registers. Then set
487 // the basic_block register to false.
Paul Robinson9d4eb692017-05-01 23:27:55 +0000488 State.appendRowToMatrix(*OffsetPtr);
Benjamin Kramer5acab502011-09-15 02:12:05 +0000489 break;
490
491 case DW_LNS_advance_pc:
492 // Takes a single unsigned LEB128 operand, multiplies it by the
493 // min_inst_length field of the prologue, and adds the
494 // result to the address register of the state machine.
Alexey Samsonov110d5952014-04-30 00:09:19 +0000495 State.Row.Address +=
Paul Robinson9d4eb692017-05-01 23:27:55 +0000496 DebugLineData.getULEB128(OffsetPtr) * Prologue.MinInstLength;
Benjamin Kramer5acab502011-09-15 02:12:05 +0000497 break;
498
499 case DW_LNS_advance_line:
500 // Takes a single signed LEB128 operand and adds that value to
501 // the line register of the state machine.
Paul Robinson9d4eb692017-05-01 23:27:55 +0000502 State.Row.Line += DebugLineData.getSLEB128(OffsetPtr);
Benjamin Kramer5acab502011-09-15 02:12:05 +0000503 break;
504
505 case DW_LNS_set_file:
506 // Takes a single unsigned LEB128 operand and stores it in the file
507 // register of the state machine.
Paul Robinson9d4eb692017-05-01 23:27:55 +0000508 State.Row.File = DebugLineData.getULEB128(OffsetPtr);
Benjamin Kramer5acab502011-09-15 02:12:05 +0000509 break;
510
511 case DW_LNS_set_column:
512 // Takes a single unsigned LEB128 operand and stores it in the
513 // column register of the state machine.
Paul Robinson9d4eb692017-05-01 23:27:55 +0000514 State.Row.Column = DebugLineData.getULEB128(OffsetPtr);
Benjamin Kramer5acab502011-09-15 02:12:05 +0000515 break;
516
517 case DW_LNS_negate_stmt:
518 // Takes no arguments. Set the is_stmt register of the state
519 // machine to the logical negation of its current value.
Alexey Samsonov110d5952014-04-30 00:09:19 +0000520 State.Row.IsStmt = !State.Row.IsStmt;
Benjamin Kramer5acab502011-09-15 02:12:05 +0000521 break;
522
523 case DW_LNS_set_basic_block:
524 // Takes no arguments. Set the basic_block register of the
525 // state machine to true
Alexey Samsonov110d5952014-04-30 00:09:19 +0000526 State.Row.BasicBlock = true;
Benjamin Kramer5acab502011-09-15 02:12:05 +0000527 break;
528
529 case DW_LNS_const_add_pc:
530 // Takes no arguments. Add to the address register of the state
531 // machine the address increment value corresponding to special
532 // opcode 255. The motivation for DW_LNS_const_add_pc is this:
533 // when the statement program needs to advance the address by a
534 // small amount, it can use a single special opcode, which occupies
535 // a single byte. When it needs to advance the address by up to
536 // twice the range of the last special opcode, it can use
537 // DW_LNS_const_add_pc followed by a special opcode, for a total
538 // of two bytes. Only if it needs to advance the address by more
539 // than twice that range will it need to use both DW_LNS_advance_pc
540 // and a special opcode, requiring three or more bytes.
541 {
Paul Robinson9d4eb692017-05-01 23:27:55 +0000542 uint8_t AdjustOpcode = 255 - Prologue.OpcodeBase;
543 uint64_t AddrOffset =
544 (AdjustOpcode / Prologue.LineRange) * Prologue.MinInstLength;
545 State.Row.Address += AddrOffset;
Benjamin Kramer5acab502011-09-15 02:12:05 +0000546 }
547 break;
548
549 case DW_LNS_fixed_advance_pc:
550 // Takes a single uhalf operand. Add to the address register of
551 // the state machine the value of the (unencoded) operand. This
552 // is the only extended opcode that takes an argument that is not
553 // a variable length number. The motivation for DW_LNS_fixed_advance_pc
554 // is this: existing assemblers cannot emit DW_LNS_advance_pc or
555 // special opcodes because they cannot encode LEB128 numbers or
556 // judge when the computation of a special opcode overflows and
557 // requires the use of DW_LNS_advance_pc. Such assemblers, however,
558 // can use DW_LNS_fixed_advance_pc instead, sacrificing compression.
Paul Robinson9d4eb692017-05-01 23:27:55 +0000559 State.Row.Address += DebugLineData.getU16(OffsetPtr);
Benjamin Kramer5acab502011-09-15 02:12:05 +0000560 break;
561
562 case DW_LNS_set_prologue_end:
563 // Takes no arguments. Set the prologue_end register of the
564 // state machine to true
Alexey Samsonov110d5952014-04-30 00:09:19 +0000565 State.Row.PrologueEnd = true;
Benjamin Kramer5acab502011-09-15 02:12:05 +0000566 break;
567
568 case DW_LNS_set_epilogue_begin:
569 // Takes no arguments. Set the basic_block register of the
570 // state machine to true
Alexey Samsonov110d5952014-04-30 00:09:19 +0000571 State.Row.EpilogueBegin = true;
Benjamin Kramer5acab502011-09-15 02:12:05 +0000572 break;
573
574 case DW_LNS_set_isa:
575 // Takes a single unsigned LEB128 operand and stores it in the
576 // column register of the state machine.
Paul Robinson9d4eb692017-05-01 23:27:55 +0000577 State.Row.Isa = DebugLineData.getULEB128(OffsetPtr);
Benjamin Kramer5acab502011-09-15 02:12:05 +0000578 break;
579
580 default:
581 // Handle any unknown standard opcodes here. We know the lengths
582 // of such opcodes because they are specified in the prologue
583 // as a multiple of LEB128 operands for each opcode.
584 {
Paul Robinson9d4eb692017-05-01 23:27:55 +0000585 assert(Opcode - 1U < Prologue.StandardOpcodeLengths.size());
586 uint8_t OpcodeLength = Prologue.StandardOpcodeLengths[Opcode - 1];
587 for (uint8_t I = 0; I < OpcodeLength; ++I)
588 DebugLineData.getULEB128(OffsetPtr);
Benjamin Kramer5acab502011-09-15 02:12:05 +0000589 }
590 break;
591 }
592 } else {
593 // Special Opcodes
594
595 // A special opcode value is chosen based on the amount that needs
596 // to be added to the line and address registers. The maximum line
597 // increment for a special opcode is the value of the line_base
598 // field in the header, plus the value of the line_range field,
599 // minus 1 (line base + line range - 1). If the desired line
600 // increment is greater than the maximum line increment, a standard
NAKAMURA Takumif9959852011-10-08 11:22:47 +0000601 // opcode must be used instead of a special opcode. The "address
602 // advance" is calculated by dividing the desired address increment
Benjamin Kramer5acab502011-09-15 02:12:05 +0000603 // by the minimum_instruction_length field from the header. The
604 // special opcode is then calculated using the following formula:
605 //
606 // opcode = (desired line increment - line_base) +
607 // (line_range * address advance) + opcode_base
608 //
609 // If the resulting opcode is greater than 255, a standard opcode
610 // must be used instead.
611 //
612 // To decode a special opcode, subtract the opcode_base from the
613 // opcode itself to give the adjusted opcode. The amount to
614 // increment the address register is the result of the adjusted
615 // opcode divided by the line_range multiplied by the
616 // minimum_instruction_length field from the header. That is:
617 //
618 // address increment = (adjusted opcode / line_range) *
619 // minimum_instruction_length
620 //
621 // The amount to increment the line register is the line_base plus
622 // the result of the adjusted opcode modulo the line_range. That is:
623 //
624 // line increment = line_base + (adjusted opcode % line_range)
625
Paul Robinson9d4eb692017-05-01 23:27:55 +0000626 uint8_t AdjustOpcode = Opcode - Prologue.OpcodeBase;
627 uint64_t AddrOffset =
628 (AdjustOpcode / Prologue.LineRange) * Prologue.MinInstLength;
629 int32_t LineOffset =
630 Prologue.LineBase + (AdjustOpcode % Prologue.LineRange);
631 State.Row.Line += LineOffset;
632 State.Row.Address += AddrOffset;
633 State.appendRowToMatrix(*OffsetPtr);
Dehao Chen1b54fce2016-04-28 22:09:37 +0000634 // Reset discriminator to 0.
635 State.Row.Discriminator = 0;
Benjamin Kramer5acab502011-09-15 02:12:05 +0000636 }
637 }
638
Alexey Samsonov110d5952014-04-30 00:09:19 +0000639 if (!State.Sequence.Empty) {
640 fprintf(stderr, "warning: last sequence in debug line table is not"
641 "terminated!\n");
642 }
643
644 // Sort all sequences so that address lookup will work faster.
645 if (!Sequences.empty()) {
646 std::sort(Sequences.begin(), Sequences.end(), Sequence::orderByLowPC);
647 // Note: actually, instruction address ranges of sequences should not
648 // overlap (in shared objects and executables). If they do, the address
649 // lookup would still work, though, but result would be ambiguous.
650 // We don't report warning in this case. For example,
651 // sometimes .so compiled from multiple object files contains a few
652 // rudimentary sequences for address ranges [0x0, 0xsomething).
653 }
Benjamin Kramer5acab502011-09-15 02:12:05 +0000654
Paul Robinson9d4eb692017-05-01 23:27:55 +0000655 return EndOffset;
Benjamin Kramer5acab502011-09-15 02:12:05 +0000656}
657
Keno Fischerc2c60182015-05-31 23:37:04 +0000658uint32_t
Paul Robinson9d4eb692017-05-01 23:27:55 +0000659DWARFDebugLine::LineTable::findRowInSeq(const DWARFDebugLine::Sequence &Seq,
660 uint64_t Address) const {
661 if (!Seq.containsPC(Address))
Keno Fischerc2c60182015-05-31 23:37:04 +0000662 return UnknownRowIndex;
663 // Search for instruction address in the rows describing the sequence.
664 // Rows are stored in a vector, so we may use arithmetical operations with
665 // iterators.
Paul Robinson9d4eb692017-05-01 23:27:55 +0000666 DWARFDebugLine::Row Row;
667 Row.Address = Address;
668 RowIter FirstRow = Rows.begin() + Seq.FirstRowIndex;
669 RowIter LastRow = Rows.begin() + Seq.LastRowIndex;
670 LineTable::RowIter RowPos = std::lower_bound(
671 FirstRow, LastRow, Row, DWARFDebugLine::Row::orderByAddress);
672 if (RowPos == LastRow) {
673 return Seq.LastRowIndex - 1;
Keno Fischerc2c60182015-05-31 23:37:04 +0000674 }
Paul Robinson9d4eb692017-05-01 23:27:55 +0000675 uint32_t Index = Seq.FirstRowIndex + (RowPos - FirstRow);
676 if (RowPos->Address > Address) {
677 if (RowPos == FirstRow)
Keno Fischerc2c60182015-05-31 23:37:04 +0000678 return UnknownRowIndex;
679 else
Paul Robinson9d4eb692017-05-01 23:27:55 +0000680 Index--;
Keno Fischerc2c60182015-05-31 23:37:04 +0000681 }
Paul Robinson9d4eb692017-05-01 23:27:55 +0000682 return Index;
Keno Fischerc2c60182015-05-31 23:37:04 +0000683}
684
Paul Robinson9d4eb692017-05-01 23:27:55 +0000685uint32_t DWARFDebugLine::LineTable::lookupAddress(uint64_t Address) const {
Alexey Samsonov947228c2012-08-07 11:46:57 +0000686 if (Sequences.empty())
Keno Fischerc2c60182015-05-31 23:37:04 +0000687 return UnknownRowIndex;
Alexey Samsonov947228c2012-08-07 11:46:57 +0000688 // First, find an instruction sequence containing the given address.
Paul Robinson9d4eb692017-05-01 23:27:55 +0000689 DWARFDebugLine::Sequence Sequence;
690 Sequence.LowPC = Address;
691 SequenceIter FirstSeq = Sequences.begin();
692 SequenceIter LastSeq = Sequences.end();
693 SequenceIter SeqPos = std::lower_bound(
694 FirstSeq, LastSeq, Sequence, DWARFDebugLine::Sequence::orderByLowPC);
695 DWARFDebugLine::Sequence FoundSeq;
696 if (SeqPos == LastSeq) {
697 FoundSeq = Sequences.back();
698 } else if (SeqPos->LowPC == Address) {
699 FoundSeq = *SeqPos;
Alexey Samsonov947228c2012-08-07 11:46:57 +0000700 } else {
Paul Robinson9d4eb692017-05-01 23:27:55 +0000701 if (SeqPos == FirstSeq)
Keno Fischerc2c60182015-05-31 23:37:04 +0000702 return UnknownRowIndex;
Paul Robinson9d4eb692017-05-01 23:27:55 +0000703 FoundSeq = *(SeqPos - 1);
Benjamin Kramer5acab502011-09-15 02:12:05 +0000704 }
Paul Robinson9d4eb692017-05-01 23:27:55 +0000705 return findRowInSeq(FoundSeq, Address);
Benjamin Kramer5acab502011-09-15 02:12:05 +0000706}
Alexey Samsonov45be7932012-08-30 07:49:50 +0000707
Alexey Samsonov836b1ae2014-04-29 21:28:13 +0000708bool DWARFDebugLine::LineTable::lookupAddressRange(
Paul Robinson9d4eb692017-05-01 23:27:55 +0000709 uint64_t Address, uint64_t Size, std::vector<uint32_t> &Result) const {
Andrew Kaylor9a8ff812013-01-26 00:28:05 +0000710 if (Sequences.empty())
711 return false;
Paul Robinson9d4eb692017-05-01 23:27:55 +0000712 uint64_t EndAddr = Address + Size;
Andrew Kaylor9a8ff812013-01-26 00:28:05 +0000713 // First, find an instruction sequence containing the given address.
Paul Robinson9d4eb692017-05-01 23:27:55 +0000714 DWARFDebugLine::Sequence Sequence;
715 Sequence.LowPC = Address;
716 SequenceIter FirstSeq = Sequences.begin();
717 SequenceIter LastSeq = Sequences.end();
718 SequenceIter SeqPos = std::lower_bound(
719 FirstSeq, LastSeq, Sequence, DWARFDebugLine::Sequence::orderByLowPC);
720 if (SeqPos == LastSeq || SeqPos->LowPC != Address) {
721 if (SeqPos == FirstSeq)
Andrew Kaylor9a8ff812013-01-26 00:28:05 +0000722 return false;
Paul Robinson9d4eb692017-05-01 23:27:55 +0000723 SeqPos--;
Andrew Kaylor9a8ff812013-01-26 00:28:05 +0000724 }
Paul Robinson9d4eb692017-05-01 23:27:55 +0000725 if (!SeqPos->containsPC(Address))
Andrew Kaylor9a8ff812013-01-26 00:28:05 +0000726 return false;
727
Paul Robinson9d4eb692017-05-01 23:27:55 +0000728 SequenceIter StartPos = SeqPos;
Andrew Kaylor9a8ff812013-01-26 00:28:05 +0000729
730 // Add the rows from the first sequence to the vector, starting with the
731 // index we just calculated
732
Paul Robinson9d4eb692017-05-01 23:27:55 +0000733 while (SeqPos != LastSeq && SeqPos->LowPC < EndAddr) {
734 const DWARFDebugLine::Sequence &CurSeq = *SeqPos;
Keno Fischerc2c60182015-05-31 23:37:04 +0000735 // For the first sequence, we need to find which row in the sequence is the
736 // first in our range.
Paul Robinson9d4eb692017-05-01 23:27:55 +0000737 uint32_t FirstRowIndex = CurSeq.FirstRowIndex;
738 if (SeqPos == StartPos)
739 FirstRowIndex = findRowInSeq(CurSeq, Address);
Andrew Kaylor9a8ff812013-01-26 00:28:05 +0000740
Keno Fischerc2c60182015-05-31 23:37:04 +0000741 // Figure out the last row in the range.
Paul Robinson9d4eb692017-05-01 23:27:55 +0000742 uint32_t LastRowIndex = findRowInSeq(CurSeq, EndAddr - 1);
743 if (LastRowIndex == UnknownRowIndex)
744 LastRowIndex = CurSeq.LastRowIndex - 1;
Andrew Kaylor9a8ff812013-01-26 00:28:05 +0000745
Paul Robinson9d4eb692017-05-01 23:27:55 +0000746 assert(FirstRowIndex != UnknownRowIndex);
747 assert(LastRowIndex != UnknownRowIndex);
Keno Fischerc2c60182015-05-31 23:37:04 +0000748
Paul Robinson9d4eb692017-05-01 23:27:55 +0000749 for (uint32_t I = FirstRowIndex; I <= LastRowIndex; ++I) {
750 Result.push_back(I);
Andrew Kaylor9a8ff812013-01-26 00:28:05 +0000751 }
752
Paul Robinson9d4eb692017-05-01 23:27:55 +0000753 ++SeqPos;
Andrew Kaylor9a8ff812013-01-26 00:28:05 +0000754 }
NAKAMURA Takumi4b86cdb2013-01-26 01:45:06 +0000755
756 return true;
Andrew Kaylor9a8ff812013-01-26 00:28:05 +0000757}
758
Paul Robinson9d4eb692017-05-01 23:27:55 +0000759bool DWARFDebugLine::LineTable::hasFileAtIndex(uint64_t FileIndex) const {
Pete Cooperb2ba7762016-07-22 01:41:32 +0000760 return FileIndex != 0 && FileIndex <= Prologue.FileNames.size();
761}
762
Paul Robinson9d4eb692017-05-01 23:27:55 +0000763bool DWARFDebugLine::LineTable::getFileNameByIndex(uint64_t FileIndex,
764 const char *CompDir,
765 FileLineInfoKind Kind,
766 std::string &Result) const {
Pete Cooperb2ba7762016-07-22 01:41:32 +0000767 if (Kind == FileLineInfoKind::None || !hasFileAtIndex(FileIndex))
Alexey Samsonov45be7932012-08-30 07:49:50 +0000768 return false;
769 const FileNameEntry &Entry = Prologue.FileNames[FileIndex - 1];
Paul Robinsonba1c9152017-05-02 17:37:32 +0000770 StringRef FileName = Entry.Name;
Alexey Samsonovdce67342014-05-15 21:24:32 +0000771 if (Kind != FileLineInfoKind::AbsoluteFilePath ||
Alexey Samsonov45be7932012-08-30 07:49:50 +0000772 sys::path::is_absolute(FileName)) {
773 Result = FileName;
774 return true;
775 }
Frederic Riss101b5e22014-09-19 15:11:51 +0000776
Alexey Samsonov45be7932012-08-30 07:49:50 +0000777 SmallString<16> FilePath;
778 uint64_t IncludeDirIndex = Entry.DirIdx;
Paul Robinsonba1c9152017-05-02 17:37:32 +0000779 StringRef IncludeDir;
Alexey Samsonov45be7932012-08-30 07:49:50 +0000780 // Be defensive about the contents of Entry.
781 if (IncludeDirIndex > 0 &&
Frederic Riss101b5e22014-09-19 15:11:51 +0000782 IncludeDirIndex <= Prologue.IncludeDirectories.size())
783 IncludeDir = Prologue.IncludeDirectories[IncludeDirIndex - 1];
784
785 // We may still need to append compilation directory of compile unit.
786 // We know that FileName is not absolute, the only way to have an
787 // absolute path at this point would be if IncludeDir is absolute.
788 if (CompDir && Kind == FileLineInfoKind::AbsoluteFilePath &&
789 sys::path::is_relative(IncludeDir))
790 sys::path::append(FilePath, CompDir);
791
792 // sys::path::append skips empty strings.
793 sys::path::append(FilePath, IncludeDir, FileName);
Alexey Samsonov45be7932012-08-30 07:49:50 +0000794 Result = FilePath.str();
795 return true;
796}
Frederic Riss101b5e22014-09-19 15:11:51 +0000797
Dehao Chen1b54fce2016-04-28 22:09:37 +0000798bool DWARFDebugLine::LineTable::getFileLineInfoForAddress(
799 uint64_t Address, const char *CompDir, FileLineInfoKind Kind,
800 DILineInfo &Result) const {
Frederic Riss101b5e22014-09-19 15:11:51 +0000801 // Get the index of row we're looking for in the line table.
802 uint32_t RowIndex = lookupAddress(Address);
803 if (RowIndex == -1U)
804 return false;
805 // Take file number and line/column from the row.
806 const auto &Row = Rows[RowIndex];
807 if (!getFileNameByIndex(Row.File, CompDir, Kind, Result.FileName))
808 return false;
809 Result.Line = Row.Line;
810 Result.Column = Row.Column;
Eric Christopherba1024c2016-12-14 18:29:39 +0000811 Result.Discriminator = Row.Discriminator;
Frederic Riss101b5e22014-09-19 15:11:51 +0000812 return true;
813}