LLVM  9.0.0svn
DWARFDebugLine.cpp
Go to the documentation of this file.
1 //===- DWARFDebugLine.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 
10 #include "llvm/ADT/Optional.h"
11 #include "llvm/ADT/SmallString.h"
12 #include "llvm/ADT/SmallVector.h"
13 #include "llvm/ADT/StringRef.h"
17 #include "llvm/Support/Errc.h"
18 #include "llvm/Support/Format.h"
19 #include "llvm/Support/Path.h"
20 #include "llvm/Support/WithColor.h"
22 #include <algorithm>
23 #include <cassert>
24 #include <cinttypes>
25 #include <cstdint>
26 #include <cstdio>
27 #include <utility>
28 
29 using namespace llvm;
30 using namespace dwarf;
31 
33 
34 namespace {
35 
36 struct ContentDescriptor {
39 };
40 
41 using ContentDescriptors = SmallVector<ContentDescriptor, 4>;
42 
43 } // end anonmyous namespace
44 
46  dwarf::LineNumberEntryFormat ContentType) {
47  switch (ContentType) {
48  case dwarf::DW_LNCT_timestamp:
49  HasModTime = true;
50  break;
51  case dwarf::DW_LNCT_size:
52  HasLength = true;
53  break;
54  case dwarf::DW_LNCT_MD5:
55  HasMD5 = true;
56  break;
57  case dwarf::DW_LNCT_LLVM_source:
58  HasSource = true;
59  break;
60  default:
61  // We only care about values we consider optional, and new values may be
62  // added in the vendor extension range, so we do not match exhaustively.
63  break;
64  }
65 }
66 
68 
70  TotalLength = PrologueLength = 0;
71  SegSelectorSize = 0;
72  MinInstLength = MaxOpsPerInst = DefaultIsStmt = LineBase = LineRange = 0;
73  OpcodeBase = 0;
75  ContentTypes = ContentTypeTracker();
76  StandardOpcodeLengths.clear();
77  IncludeDirectories.clear();
78  FileNames.clear();
79 }
80 
82  DIDumpOptions DumpOptions) const {
83  OS << "Line table prologue:\n"
84  << format(" total_length: 0x%8.8" PRIx64 "\n", TotalLength)
85  << format(" version: %u\n", getVersion());
86  if (getVersion() >= 5)
87  OS << format(" address_size: %u\n", getAddressSize())
88  << format(" seg_select_size: %u\n", SegSelectorSize);
89  OS << format(" prologue_length: 0x%8.8" PRIx64 "\n", PrologueLength)
90  << format(" min_inst_length: %u\n", MinInstLength)
91  << format(getVersion() >= 4 ? "max_ops_per_inst: %u\n" : "", MaxOpsPerInst)
92  << format(" default_is_stmt: %u\n", DefaultIsStmt)
93  << format(" line_base: %i\n", LineBase)
94  << format(" line_range: %u\n", LineRange)
95  << format(" opcode_base: %u\n", OpcodeBase);
96 
97  for (uint32_t I = 0; I != StandardOpcodeLengths.size(); ++I)
98  OS << format("standard_opcode_lengths[%s] = %u\n",
99  LNStandardString(I + 1).data(), StandardOpcodeLengths[I]);
100 
101  if (!IncludeDirectories.empty()) {
102  // DWARF v5 starts directory indexes at 0.
103  uint32_t DirBase = getVersion() >= 5 ? 0 : 1;
104  for (uint32_t I = 0; I != IncludeDirectories.size(); ++I) {
105  OS << format("include_directories[%3u] = ", I + DirBase);
106  IncludeDirectories[I].dump(OS, DumpOptions);
107  OS << '\n';
108  }
109  }
110 
111  if (!FileNames.empty()) {
112  // DWARF v5 starts file indexes at 0.
113  uint32_t FileBase = getVersion() >= 5 ? 0 : 1;
114  for (uint32_t I = 0; I != FileNames.size(); ++I) {
115  const FileNameEntry &FileEntry = FileNames[I];
116  OS << format("file_names[%3u]:\n", I + FileBase);
117  OS << " name: ";
118  FileEntry.Name.dump(OS, DumpOptions);
119  OS << '\n'
120  << format(" dir_index: %" PRIu64 "\n", FileEntry.DirIdx);
121  if (ContentTypes.HasMD5)
122  OS << " md5_checksum: " << FileEntry.Checksum.digest() << '\n';
123  if (ContentTypes.HasModTime)
124  OS << format(" mod_time: 0x%8.8" PRIx64 "\n", FileEntry.ModTime);
125  if (ContentTypes.HasLength)
126  OS << format(" length: 0x%8.8" PRIx64 "\n", FileEntry.Length);
127  if (ContentTypes.HasSource) {
128  OS << " source: ";
129  FileEntry.Source.dump(OS, DumpOptions);
130  OS << '\n';
131  }
132  }
133  }
134 }
135 
136 // Parse v2-v4 directory and file tables.
137 static void
139  uint32_t *OffsetPtr, uint64_t EndPrologueOffset,
141  std::vector<DWARFFormValue> &IncludeDirectories,
142  std::vector<DWARFDebugLine::FileNameEntry> &FileNames) {
143  while (*OffsetPtr < EndPrologueOffset) {
144  StringRef S = DebugLineData.getCStrRef(OffsetPtr);
145  if (S.empty())
146  break;
147  DWARFFormValue Dir =
148  DWARFFormValue::createFromPValue(dwarf::DW_FORM_string, S.data());
149  IncludeDirectories.push_back(Dir);
150  }
151 
152  while (*OffsetPtr < EndPrologueOffset) {
153  StringRef Name = DebugLineData.getCStrRef(OffsetPtr);
154  if (Name.empty())
155  break;
157  FileEntry.Name =
158  DWARFFormValue::createFromPValue(dwarf::DW_FORM_string, Name.data());
159  FileEntry.DirIdx = DebugLineData.getULEB128(OffsetPtr);
160  FileEntry.ModTime = DebugLineData.getULEB128(OffsetPtr);
161  FileEntry.Length = DebugLineData.getULEB128(OffsetPtr);
162  FileNames.push_back(FileEntry);
163  }
164 
165  ContentTypes.HasModTime = true;
166  ContentTypes.HasLength = true;
167 }
168 
169 // Parse v5 directory/file entry content descriptions.
170 // Returns the descriptors, or an empty vector if we did not find a path or
171 // ran off the end of the prologue.
172 static ContentDescriptors
174  *OffsetPtr, uint64_t EndPrologueOffset, DWARFDebugLine::ContentTypeTracker
175  *ContentTypes) {
176  ContentDescriptors Descriptors;
177  int FormatCount = DebugLineData.getU8(OffsetPtr);
178  bool HasPath = false;
179  for (int I = 0; I != FormatCount; ++I) {
180  if (*OffsetPtr >= EndPrologueOffset)
181  return ContentDescriptors();
182  ContentDescriptor Descriptor;
183  Descriptor.Type =
184  dwarf::LineNumberEntryFormat(DebugLineData.getULEB128(OffsetPtr));
185  Descriptor.Form = dwarf::Form(DebugLineData.getULEB128(OffsetPtr));
186  if (Descriptor.Type == dwarf::DW_LNCT_path)
187  HasPath = true;
188  if (ContentTypes)
189  ContentTypes->trackContentType(Descriptor.Type);
190  Descriptors.push_back(Descriptor);
191  }
192  return HasPath ? Descriptors : ContentDescriptors();
193 }
194 
195 static bool
197  uint32_t *OffsetPtr, uint64_t EndPrologueOffset,
199  const DWARFContext &Ctx, const DWARFUnit *U,
201  std::vector<DWARFFormValue> &IncludeDirectories,
202  std::vector<DWARFDebugLine::FileNameEntry> &FileNames) {
203  // Get the directory entry description.
204  ContentDescriptors DirDescriptors =
205  parseV5EntryFormat(DebugLineData, OffsetPtr, EndPrologueOffset, nullptr);
206  if (DirDescriptors.empty())
207  return false;
208 
209  // Get the directory entries, according to the format described above.
210  int DirEntryCount = DebugLineData.getU8(OffsetPtr);
211  for (int I = 0; I != DirEntryCount; ++I) {
212  if (*OffsetPtr >= EndPrologueOffset)
213  return false;
214  for (auto Descriptor : DirDescriptors) {
215  DWARFFormValue Value(Descriptor.Form);
216  switch (Descriptor.Type) {
217  case DW_LNCT_path:
218  if (!Value.extractValue(DebugLineData, OffsetPtr, FormParams, &Ctx, U))
219  return false;
220  IncludeDirectories.push_back(Value);
221  break;
222  default:
223  if (!Value.skipValue(DebugLineData, OffsetPtr, FormParams))
224  return false;
225  }
226  }
227  }
228 
229  // Get the file entry description.
230  ContentDescriptors FileDescriptors =
231  parseV5EntryFormat(DebugLineData, OffsetPtr, EndPrologueOffset,
232  &ContentTypes);
233  if (FileDescriptors.empty())
234  return false;
235 
236  // Get the file entries, according to the format described above.
237  int FileEntryCount = DebugLineData.getU8(OffsetPtr);
238  for (int I = 0; I != FileEntryCount; ++I) {
239  if (*OffsetPtr >= EndPrologueOffset)
240  return false;
242  for (auto Descriptor : FileDescriptors) {
243  DWARFFormValue Value(Descriptor.Form);
244  if (!Value.extractValue(DebugLineData, OffsetPtr, FormParams, &Ctx, U))
245  return false;
246  switch (Descriptor.Type) {
247  case DW_LNCT_path:
248  FileEntry.Name = Value;
249  break;
250  case DW_LNCT_LLVM_source:
251  FileEntry.Source = Value;
252  break;
253  case DW_LNCT_directory_index:
254  FileEntry.DirIdx = Value.getAsUnsignedConstant().getValue();
255  break;
256  case DW_LNCT_timestamp:
257  FileEntry.ModTime = Value.getAsUnsignedConstant().getValue();
258  break;
259  case DW_LNCT_size:
260  FileEntry.Length = Value.getAsUnsignedConstant().getValue();
261  break;
262  case DW_LNCT_MD5:
263  assert(Value.getAsBlock().getValue().size() == 16);
264  std::uninitialized_copy_n(Value.getAsBlock().getValue().begin(), 16,
265  FileEntry.Checksum.Bytes.begin());
266  break;
267  default:
268  break;
269  }
270  }
271  FileNames.push_back(FileEntry);
272  }
273  return true;
274 }
275 
277  uint32_t *OffsetPtr,
278  const DWARFContext &Ctx,
279  const DWARFUnit *U) {
280  const uint64_t PrologueOffset = *OffsetPtr;
281 
282  clear();
283  TotalLength = DebugLineData.getU32(OffsetPtr);
284  if (TotalLength == UINT32_MAX) {
286  TotalLength = DebugLineData.getU64(OffsetPtr);
287  } else if (TotalLength >= 0xffffff00) {
289  "parsing line table prologue at offset 0x%8.8" PRIx64
290  " unsupported reserved unit length found of value 0x%8.8" PRIx64,
291  PrologueOffset, TotalLength);
292  }
293  FormParams.Version = DebugLineData.getU16(OffsetPtr);
294  if (getVersion() < 2)
296  "parsing line table prologue at offset 0x%8.8" PRIx64
297  " found unsupported version 0x%2.2" PRIx16,
298  PrologueOffset, getVersion());
299 
300  if (getVersion() >= 5) {
301  FormParams.AddrSize = DebugLineData.getU8(OffsetPtr);
302  assert((DebugLineData.getAddressSize() == 0 ||
303  DebugLineData.getAddressSize() == getAddressSize()) &&
304  "Line table header and data extractor disagree");
305  SegSelectorSize = DebugLineData.getU8(OffsetPtr);
306  }
307 
308  PrologueLength = DebugLineData.getUnsigned(OffsetPtr, sizeofPrologueLength());
309  const uint64_t EndPrologueOffset = PrologueLength + *OffsetPtr;
310  MinInstLength = DebugLineData.getU8(OffsetPtr);
311  if (getVersion() >= 4)
312  MaxOpsPerInst = DebugLineData.getU8(OffsetPtr);
313  DefaultIsStmt = DebugLineData.getU8(OffsetPtr);
314  LineBase = DebugLineData.getU8(OffsetPtr);
315  LineRange = DebugLineData.getU8(OffsetPtr);
316  OpcodeBase = DebugLineData.getU8(OffsetPtr);
317 
318  StandardOpcodeLengths.reserve(OpcodeBase - 1);
319  for (uint32_t I = 1; I < OpcodeBase; ++I) {
320  uint8_t OpLen = DebugLineData.getU8(OffsetPtr);
321  StandardOpcodeLengths.push_back(OpLen);
322  }
323 
324  if (getVersion() >= 5) {
325  if (!parseV5DirFileTables(DebugLineData, OffsetPtr, EndPrologueOffset,
326  FormParams, Ctx, U, ContentTypes,
327  IncludeDirectories, FileNames)) {
329  "parsing line table prologue at 0x%8.8" PRIx64
330  " found an invalid directory or file table description at"
331  " 0x%8.8" PRIx64,
332  PrologueOffset, (uint64_t)*OffsetPtr);
333  }
334  } else
335  parseV2DirFileTables(DebugLineData, OffsetPtr, EndPrologueOffset,
336  ContentTypes, IncludeDirectories, FileNames);
337 
338  if (*OffsetPtr != EndPrologueOffset)
340  "parsing line table prologue at 0x%8.8" PRIx64
341  " should have ended at 0x%8.8" PRIx64
342  " but it ended at 0x%8.8" PRIx64,
343  PrologueOffset, EndPrologueOffset, (uint64_t)*OffsetPtr);
344  return Error::success();
345 }
346 
347 DWARFDebugLine::Row::Row(bool DefaultIsStmt) { reset(DefaultIsStmt); }
348 
350  BasicBlock = false;
351  PrologueEnd = false;
352  EpilogueBegin = false;
353 }
354 
355 void DWARFDebugLine::Row::reset(bool DefaultIsStmt) {
356  Address.Address = 0;
358  Line = 1;
359  Column = 0;
360  File = 1;
361  Isa = 0;
362  Discriminator = 0;
363  IsStmt = DefaultIsStmt;
364  BasicBlock = false;
365  EndSequence = false;
366  PrologueEnd = false;
367  EpilogueBegin = false;
368 }
369 
371  OS << "Address Line Column File ISA Discriminator Flags\n"
372  << "------------------ ------ ------ ------ --- ------------- "
373  "-------------\n";
374 }
375 
377  OS << format("0x%16.16" PRIx64 " %6u %6u", Address.Address, Line, Column)
378  << format(" %6u %3u %13u ", File, Isa, Discriminator)
379  << (IsStmt ? " is_stmt" : "") << (BasicBlock ? " basic_block" : "")
380  << (PrologueEnd ? " prologue_end" : "")
381  << (EpilogueBegin ? " epilogue_begin" : "")
382  << (EndSequence ? " end_sequence" : "") << '\n';
383 }
384 
386 
388  LowPC = 0;
389  HighPC = 0;
391  FirstRowIndex = 0;
392  LastRowIndex = 0;
393  Empty = true;
394 }
395 
397 
399  DIDumpOptions DumpOptions) const {
400  Prologue.dump(OS, DumpOptions);
401  OS << '\n';
402 
403  if (!Rows.empty()) {
404  Row::dumpTableHeader(OS);
405  for (const Row &R : Rows) {
406  R.dump(OS);
407  }
408  }
409 }
410 
412  Prologue.clear();
413  Rows.clear();
414  Sequences.clear();
415 }
416 
417 DWARFDebugLine::ParsingState::ParsingState(struct LineTable *LT)
418  : LineTable(LT) {
419  resetRowAndSequence();
420 }
421 
422 void DWARFDebugLine::ParsingState::resetRowAndSequence() {
424  Sequence.reset();
425 }
426 
427 void DWARFDebugLine::ParsingState::appendRowToMatrix(uint32_t Offset) {
428  if (Sequence.Empty) {
429  // Record the beginning of instruction sequence.
430  Sequence.Empty = false;
432  Sequence.FirstRowIndex = RowNumber;
433  }
434  ++RowNumber;
436  if (Row.EndSequence) {
437  // Record the end of instruction sequence.
439  Sequence.LastRowIndex = RowNumber;
441  if (Sequence.isValid())
443  Sequence.reset();
444  }
445  Row.postAppend();
446 }
447 
450  LineTableConstIter Pos = LineTableMap.find(Offset);
451  if (Pos != LineTableMap.end())
452  return &Pos->second;
453  return nullptr;
454 }
455 
457  DWARFDataExtractor &DebugLineData, uint32_t Offset, const DWARFContext &Ctx,
458  const DWARFUnit *U, std::function<void(Error)> RecoverableErrorCallback) {
459  if (!DebugLineData.isValidOffset(Offset))
460  return createStringError(errc::invalid_argument, "offset 0x%8.8" PRIx32
461  " is not a valid debug line section offset",
462  Offset);
463 
464  std::pair<LineTableIter, bool> Pos =
465  LineTableMap.insert(LineTableMapTy::value_type(Offset, LineTable()));
466  LineTable *LT = &Pos.first->second;
467  if (Pos.second) {
468  if (Error Err =
469  LT->parse(DebugLineData, &Offset, Ctx, U, RecoverableErrorCallback))
470  return std::move(Err);
471  return LT;
472  }
473  return LT;
474 }
475 
477  DWARFDataExtractor &DebugLineData, uint32_t *OffsetPtr,
478  const DWARFContext &Ctx, const DWARFUnit *U,
479  std::function<void(Error)> RecoverableErrorCallback, raw_ostream *OS) {
480  const uint32_t DebugLineOffset = *OffsetPtr;
481 
482  clear();
483 
484  Error PrologueErr = Prologue.parse(DebugLineData, OffsetPtr, Ctx, U);
485 
486  if (OS) {
487  // The presence of OS signals verbose dumping.
488  DIDumpOptions DumpOptions;
489  DumpOptions.Verbose = true;
490  Prologue.dump(*OS, DumpOptions);
491  }
492 
493  if (PrologueErr)
494  return PrologueErr;
495 
496  const uint32_t EndOffset =
497  DebugLineOffset + Prologue.TotalLength + Prologue.sizeofTotalLength();
498 
499  // See if we should tell the data extractor the address size.
500  if (DebugLineData.getAddressSize() == 0)
501  DebugLineData.setAddressSize(Prologue.getAddressSize());
502  else
503  assert(Prologue.getAddressSize() == 0 ||
504  Prologue.getAddressSize() == DebugLineData.getAddressSize());
505 
506  ParsingState State(this);
507 
508  while (*OffsetPtr < EndOffset) {
509  if (OS)
510  *OS << format("0x%08.08" PRIx32 ": ", *OffsetPtr);
511 
512  uint8_t Opcode = DebugLineData.getU8(OffsetPtr);
513 
514  if (OS)
515  *OS << format("%02.02" PRIx8 " ", Opcode);
516 
517  if (Opcode == 0) {
518  // Extended Opcodes always start with a zero opcode followed by
519  // a uleb128 length so you can skip ones you don't know about
520  uint64_t Len = DebugLineData.getULEB128(OffsetPtr);
521  uint32_t ExtOffset = *OffsetPtr;
522 
523  // Tolerate zero-length; assume length is correct and soldier on.
524  if (Len == 0) {
525  if (OS)
526  *OS << "Badly formed extended line op (length 0)\n";
527  continue;
528  }
529 
530  uint8_t SubOpcode = DebugLineData.getU8(OffsetPtr);
531  if (OS)
532  *OS << LNExtendedString(SubOpcode);
533  switch (SubOpcode) {
534  case DW_LNE_end_sequence:
535  // Set the end_sequence register of the state machine to true and
536  // append a row to the matrix using the current values of the
537  // state-machine registers. Then reset the registers to the initial
538  // values specified above. Every statement program sequence must end
539  // with a DW_LNE_end_sequence instruction which creates a row whose
540  // address is that of the byte after the last target machine instruction
541  // of the sequence.
542  State.Row.EndSequence = true;
543  State.appendRowToMatrix(*OffsetPtr);
544  if (OS) {
545  *OS << "\n";
546  OS->indent(12);
547  State.Row.dump(*OS);
548  }
549  State.resetRowAndSequence();
550  break;
551 
552  case DW_LNE_set_address:
553  // Takes a single relocatable address as an operand. The size of the
554  // operand is the size appropriate to hold an address on the target
555  // machine. Set the address register to the value given by the
556  // relocatable address. All of the other statement program opcodes
557  // that affect the address register add a delta to it. This instruction
558  // stores a relocatable value into it instead.
559  //
560  // Make sure the extractor knows the address size. If not, infer it
561  // from the size of the operand.
562  if (DebugLineData.getAddressSize() == 0)
563  DebugLineData.setAddressSize(Len - 1);
564  else if (DebugLineData.getAddressSize() != Len - 1) {
566  "mismatching address size at offset 0x%8.8" PRIx32
567  " expected 0x%2.2" PRIx8 " found 0x%2.2" PRIx64,
568  ExtOffset, DebugLineData.getAddressSize(),
569  Len - 1);
570  }
571  State.Row.Address.Address = DebugLineData.getRelocatedAddress(
572  OffsetPtr, &State.Row.Address.SectionIndex);
573  if (OS)
574  *OS << format(" (0x%16.16" PRIx64 ")", State.Row.Address.Address);
575  break;
576 
577  case DW_LNE_define_file:
578  // Takes 4 arguments. The first is a null terminated string containing
579  // a source file name. The second is an unsigned LEB128 number
580  // representing the directory index of the directory in which the file
581  // was found. The third is an unsigned LEB128 number representing the
582  // time of last modification of the file. The fourth is an unsigned
583  // LEB128 number representing the length in bytes of the file. The time
584  // and length fields may contain LEB128(0) if the information is not
585  // available.
586  //
587  // The directory index represents an entry in the include_directories
588  // section of the statement program prologue. The index is LEB128(0)
589  // if the file was found in the current directory of the compilation,
590  // LEB128(1) if it was found in the first directory in the
591  // include_directories section, and so on. The directory index is
592  // ignored for file names that represent full path names.
593  //
594  // The files are numbered, starting at 1, in the order in which they
595  // appear; the names in the prologue come before names defined by
596  // the DW_LNE_define_file instruction. These numbers are used in the
597  // the file register of the state machine.
598  {
599  FileNameEntry FileEntry;
600  const char *Name = DebugLineData.getCStr(OffsetPtr);
601  FileEntry.Name =
602  DWARFFormValue::createFromPValue(dwarf::DW_FORM_string, Name);
603  FileEntry.DirIdx = DebugLineData.getULEB128(OffsetPtr);
604  FileEntry.ModTime = DebugLineData.getULEB128(OffsetPtr);
605  FileEntry.Length = DebugLineData.getULEB128(OffsetPtr);
606  Prologue.FileNames.push_back(FileEntry);
607  if (OS)
608  *OS << " (" << Name << ", dir=" << FileEntry.DirIdx << ", mod_time="
609  << format("(0x%16.16" PRIx64 ")", FileEntry.ModTime)
610  << ", length=" << FileEntry.Length << ")";
611  }
612  break;
613 
614  case DW_LNE_set_discriminator:
615  State.Row.Discriminator = DebugLineData.getULEB128(OffsetPtr);
616  if (OS)
617  *OS << " (" << State.Row.Discriminator << ")";
618  break;
619 
620  default:
621  if (OS)
622  *OS << format("Unrecognized extended op 0x%02.02" PRIx8, SubOpcode)
623  << format(" length %" PRIx64, Len);
624  // Len doesn't include the zero opcode byte or the length itself, but
625  // it does include the sub_opcode, so we have to adjust for that.
626  (*OffsetPtr) += Len - 1;
627  break;
628  }
629  // Make sure the stated and parsed lengths are the same.
630  // Otherwise we have an unparseable line-number program.
631  if (*OffsetPtr - ExtOffset != Len)
633  "unexpected line op length at offset 0x%8.8" PRIx32
634  " expected 0x%2.2" PRIx64 " found 0x%2.2" PRIx32,
635  ExtOffset, Len, *OffsetPtr - ExtOffset);
636  } else if (Opcode < Prologue.OpcodeBase) {
637  if (OS)
638  *OS << LNStandardString(Opcode);
639  switch (Opcode) {
640  // Standard Opcodes
641  case DW_LNS_copy:
642  // Takes no arguments. Append a row to the matrix using the
643  // current values of the state-machine registers. Then set
644  // the basic_block register to false.
645  State.appendRowToMatrix(*OffsetPtr);
646  if (OS) {
647  *OS << "\n";
648  OS->indent(12);
649  State.Row.dump(*OS);
650  *OS << "\n";
651  }
652  break;
653 
654  case DW_LNS_advance_pc:
655  // Takes a single unsigned LEB128 operand, multiplies it by the
656  // min_inst_length field of the prologue, and adds the
657  // result to the address register of the state machine.
658  {
659  uint64_t AddrOffset =
660  DebugLineData.getULEB128(OffsetPtr) * Prologue.MinInstLength;
661  State.Row.Address.Address += AddrOffset;
662  if (OS)
663  *OS << " (" << AddrOffset << ")";
664  }
665  break;
666 
667  case DW_LNS_advance_line:
668  // Takes a single signed LEB128 operand and adds that value to
669  // the line register of the state machine.
670  State.Row.Line += DebugLineData.getSLEB128(OffsetPtr);
671  if (OS)
672  *OS << " (" << State.Row.Line << ")";
673  break;
674 
675  case DW_LNS_set_file:
676  // Takes a single unsigned LEB128 operand and stores it in the file
677  // register of the state machine.
678  State.Row.File = DebugLineData.getULEB128(OffsetPtr);
679  if (OS)
680  *OS << " (" << State.Row.File << ")";
681  break;
682 
683  case DW_LNS_set_column:
684  // Takes a single unsigned LEB128 operand and stores it in the
685  // column register of the state machine.
686  State.Row.Column = DebugLineData.getULEB128(OffsetPtr);
687  if (OS)
688  *OS << " (" << State.Row.Column << ")";
689  break;
690 
691  case DW_LNS_negate_stmt:
692  // Takes no arguments. Set the is_stmt register of the state
693  // machine to the logical negation of its current value.
694  State.Row.IsStmt = !State.Row.IsStmt;
695  break;
696 
697  case DW_LNS_set_basic_block:
698  // Takes no arguments. Set the basic_block register of the
699  // state machine to true
700  State.Row.BasicBlock = true;
701  break;
702 
703  case DW_LNS_const_add_pc:
704  // Takes no arguments. Add to the address register of the state
705  // machine the address increment value corresponding to special
706  // opcode 255. The motivation for DW_LNS_const_add_pc is this:
707  // when the statement program needs to advance the address by a
708  // small amount, it can use a single special opcode, which occupies
709  // a single byte. When it needs to advance the address by up to
710  // twice the range of the last special opcode, it can use
711  // DW_LNS_const_add_pc followed by a special opcode, for a total
712  // of two bytes. Only if it needs to advance the address by more
713  // than twice that range will it need to use both DW_LNS_advance_pc
714  // and a special opcode, requiring three or more bytes.
715  {
716  uint8_t AdjustOpcode = 255 - Prologue.OpcodeBase;
717  uint64_t AddrOffset =
718  (AdjustOpcode / Prologue.LineRange) * Prologue.MinInstLength;
719  State.Row.Address.Address += AddrOffset;
720  if (OS)
721  *OS
722  << format(" (0x%16.16" PRIx64 ")", AddrOffset);
723  }
724  break;
725 
726  case DW_LNS_fixed_advance_pc:
727  // Takes a single uhalf operand. Add to the address register of
728  // the state machine the value of the (unencoded) operand. This
729  // is the only extended opcode that takes an argument that is not
730  // a variable length number. The motivation for DW_LNS_fixed_advance_pc
731  // is this: existing assemblers cannot emit DW_LNS_advance_pc or
732  // special opcodes because they cannot encode LEB128 numbers or
733  // judge when the computation of a special opcode overflows and
734  // requires the use of DW_LNS_advance_pc. Such assemblers, however,
735  // can use DW_LNS_fixed_advance_pc instead, sacrificing compression.
736  {
737  uint16_t PCOffset = DebugLineData.getU16(OffsetPtr);
738  State.Row.Address.Address += PCOffset;
739  if (OS)
740  *OS
741  << format(" (0x%16.16" PRIx64 ")", PCOffset);
742  }
743  break;
744 
745  case DW_LNS_set_prologue_end:
746  // Takes no arguments. Set the prologue_end register of the
747  // state machine to true
748  State.Row.PrologueEnd = true;
749  break;
750 
751  case DW_LNS_set_epilogue_begin:
752  // Takes no arguments. Set the basic_block register of the
753  // state machine to true
754  State.Row.EpilogueBegin = true;
755  break;
756 
757  case DW_LNS_set_isa:
758  // Takes a single unsigned LEB128 operand and stores it in the
759  // column register of the state machine.
760  State.Row.Isa = DebugLineData.getULEB128(OffsetPtr);
761  if (OS)
762  *OS << " (" << State.Row.Isa << ")";
763  break;
764 
765  default:
766  // Handle any unknown standard opcodes here. We know the lengths
767  // of such opcodes because they are specified in the prologue
768  // as a multiple of LEB128 operands for each opcode.
769  {
770  assert(Opcode - 1U < Prologue.StandardOpcodeLengths.size());
771  uint8_t OpcodeLength = Prologue.StandardOpcodeLengths[Opcode - 1];
772  for (uint8_t I = 0; I < OpcodeLength; ++I) {
773  uint64_t Value = DebugLineData.getULEB128(OffsetPtr);
774  if (OS)
775  *OS << format("Skipping ULEB128 value: 0x%16.16" PRIx64 ")\n",
776  Value);
777  }
778  }
779  break;
780  }
781  } else {
782  // Special Opcodes
783 
784  // A special opcode value is chosen based on the amount that needs
785  // to be added to the line and address registers. The maximum line
786  // increment for a special opcode is the value of the line_base
787  // field in the header, plus the value of the line_range field,
788  // minus 1 (line base + line range - 1). If the desired line
789  // increment is greater than the maximum line increment, a standard
790  // opcode must be used instead of a special opcode. The "address
791  // advance" is calculated by dividing the desired address increment
792  // by the minimum_instruction_length field from the header. The
793  // special opcode is then calculated using the following formula:
794  //
795  // opcode = (desired line increment - line_base) +
796  // (line_range * address advance) + opcode_base
797  //
798  // If the resulting opcode is greater than 255, a standard opcode
799  // must be used instead.
800  //
801  // To decode a special opcode, subtract the opcode_base from the
802  // opcode itself to give the adjusted opcode. The amount to
803  // increment the address register is the result of the adjusted
804  // opcode divided by the line_range multiplied by the
805  // minimum_instruction_length field from the header. That is:
806  //
807  // address increment = (adjusted opcode / line_range) *
808  // minimum_instruction_length
809  //
810  // The amount to increment the line register is the line_base plus
811  // the result of the adjusted opcode modulo the line_range. That is:
812  //
813  // line increment = line_base + (adjusted opcode % line_range)
814 
815  uint8_t AdjustOpcode = Opcode - Prologue.OpcodeBase;
816  uint64_t AddrOffset =
817  (AdjustOpcode / Prologue.LineRange) * Prologue.MinInstLength;
818  int32_t LineOffset =
819  Prologue.LineBase + (AdjustOpcode % Prologue.LineRange);
820  State.Row.Line += LineOffset;
821  State.Row.Address.Address += AddrOffset;
822 
823  if (OS) {
824  *OS << "address += " << AddrOffset << ", line += " << LineOffset
825  << "\n";
826  OS->indent(12);
827  State.Row.dump(*OS);
828  }
829 
830  State.appendRowToMatrix(*OffsetPtr);
831  // Reset discriminator to 0.
832  State.Row.Discriminator = 0;
833  }
834  if(OS)
835  *OS << "\n";
836  }
837 
838  if (!State.Sequence.Empty)
839  RecoverableErrorCallback(
841  "last sequence in debug line table is not terminated!"));
842 
843  // Sort all sequences so that address lookup will work faster.
844  if (!Sequences.empty()) {
845  llvm::sort(Sequences, Sequence::orderByLowPC);
846  // Note: actually, instruction address ranges of sequences should not
847  // overlap (in shared objects and executables). If they do, the address
848  // lookup would still work, though, but result would be ambiguous.
849  // We don't report warning in this case. For example,
850  // sometimes .so compiled from multiple object files contains a few
851  // rudimentary sequences for address ranges [0x0, 0xsomething).
852  }
853 
854  return Error::success();
855 }
856 
857 uint32_t DWARFDebugLine::LineTable::findRowInSeq(
858  const DWARFDebugLine::Sequence &Seq,
860  if (!Seq.containsPC(Address))
861  return UnknownRowIndex;
862  assert(Seq.SectionIndex == Address.SectionIndex);
863  // Search for instruction address in the rows describing the sequence.
864  // Rows are stored in a vector, so we may use arithmetical operations with
865  // iterators.
867  Row.Address = Address;
868  RowIter FirstRow = Rows.begin() + Seq.FirstRowIndex;
869  RowIter LastRow = Rows.begin() + Seq.LastRowIndex;
871  FirstRow, LastRow, Row, DWARFDebugLine::Row::orderByAddress);
872  // Since Address is in Seq, FirstRow <= RowPos < LastRow.
873  assert(FirstRow <= RowPos && RowPos < LastRow);
874  assert(Seq.SectionIndex == RowPos->Address.SectionIndex);
875  if (RowPos->Address.Address != Address.Address) {
876  // lower_bound either lands on the RowPos with the same Address
877  // as the queried one, or on the first that's larger.
878  assert(RowPos->Address.Address > Address.Address);
879  // We know RowPos can't be FirstRow, in this case,
880  // because the queried Address is in Seq. So if it were
881  // FirstRow, then RowPos->Address.Address == Address.Address,
882  // and we wouldn't be here.
883  assert(RowPos != FirstRow);
884  --RowPos;
885  }
886  // In some cases, e.g. first instruction in a function, the compiler generates
887  // two entries, both with the same address. We want the last one.
888  // There are 2 cases wrt. RowPos and the addresses in records before/after it:
889  // 1) RowPos's address is the one we looked for. In this case, we want to
890  // skip any potential empty ranges.
891  // 2) RowPos's address is less than the one we looked for. In that case, we
892  // arrived here by finding the first range with a greater address,
893  // then decrementing 1. If the address of this range is part of a sequence of
894  // empty ones, it is the last one.
895  // In either case, the loop below lands on the correct RowPos.
896  while (RowPos->Address.Address == (RowPos + 1)->Address.Address) {
897  ++RowPos;
898  }
899 
900  assert(RowPos < LastRow);
901  uint32_t Index = Seq.FirstRowIndex + (RowPos - FirstRow);
902  return Index;
903 }
904 
906  object::SectionedAddress Address) const {
907 
908  // Search for relocatable addresses
909  uint32_t Result = lookupAddressImpl(Address);
910 
911  if (Result != UnknownRowIndex ||
913  return Result;
914 
915  // Search for absolute addresses
917  return lookupAddressImpl(Address);
918 }
919 
920 uint32_t DWARFDebugLine::LineTable::lookupAddressImpl(
921  object::SectionedAddress Address) const {
922  if (Sequences.empty())
923  return UnknownRowIndex;
924  // First, find an instruction sequence containing the given address.
926  Sequence.SectionIndex = Address.SectionIndex;
927  Sequence.LowPC = Address.Address;
928  SequenceIter FirstSeq = Sequences.begin();
929  SequenceIter LastSeq = Sequences.end();
931  FirstSeq, LastSeq, Sequence, DWARFDebugLine::Sequence::orderByLowPC);
932  DWARFDebugLine::Sequence FoundSeq;
933 
934  if (SeqPos == LastSeq) {
935  FoundSeq = Sequences.back();
936  } else if (SeqPos->LowPC == Address.Address &&
937  SeqPos->SectionIndex == Address.SectionIndex) {
938  FoundSeq = *SeqPos;
939  } else {
940  if (SeqPos == FirstSeq)
941  return UnknownRowIndex;
942  FoundSeq = *(SeqPos - 1);
943  }
944  if (FoundSeq.SectionIndex != Address.SectionIndex)
945  return UnknownRowIndex;
946  return findRowInSeq(FoundSeq, Address);
947 }
948 
950  object::SectionedAddress Address, uint64_t Size,
951  std::vector<uint32_t> &Result) const {
952 
953  // Search for relocatable addresses
954  if (lookupAddressRangeImpl(Address, Size, Result))
955  return true;
956 
958  return false;
959 
960  // Search for absolute addresses
962  return lookupAddressRangeImpl(Address, Size, Result);
963 }
964 
965 bool DWARFDebugLine::LineTable::lookupAddressRangeImpl(
966  object::SectionedAddress Address, uint64_t Size,
967  std::vector<uint32_t> &Result) const {
968  if (Sequences.empty())
969  return false;
970  uint64_t EndAddr = Address.Address + Size;
971  // First, find an instruction sequence containing the given address.
973  Sequence.SectionIndex = Address.SectionIndex;
974  Sequence.LowPC = Address.Address;
975  SequenceIter FirstSeq = Sequences.begin();
976  SequenceIter LastSeq = Sequences.end();
978  FirstSeq, LastSeq, Sequence, DWARFDebugLine::Sequence::orderByLowPC);
979  if (SeqPos == LastSeq || !SeqPos->containsPC(Address)) {
980  if (SeqPos == FirstSeq)
981  return false;
982  SeqPos--;
983  }
984  if (!SeqPos->containsPC(Address))
985  return false;
986 
987  SequenceIter StartPos = SeqPos;
988 
989  // Add the rows from the first sequence to the vector, starting with the
990  // index we just calculated
991 
992  while (SeqPos != LastSeq && SeqPos->LowPC < EndAddr) {
993  const DWARFDebugLine::Sequence &CurSeq = *SeqPos;
994  // For the first sequence, we need to find which row in the sequence is the
995  // first in our range.
996  uint32_t FirstRowIndex = CurSeq.FirstRowIndex;
997  if (SeqPos == StartPos)
998  FirstRowIndex = findRowInSeq(CurSeq, Address);
999 
1000  // Figure out the last row in the range.
1001  uint32_t LastRowIndex =
1002  findRowInSeq(CurSeq, {EndAddr - 1, Address.SectionIndex});
1003  if (LastRowIndex == UnknownRowIndex)
1004  LastRowIndex = CurSeq.LastRowIndex - 1;
1005 
1006  assert(FirstRowIndex != UnknownRowIndex);
1007  assert(LastRowIndex != UnknownRowIndex);
1008 
1009  for (uint32_t I = FirstRowIndex; I <= LastRowIndex; ++I) {
1010  Result.push_back(I);
1011  }
1012 
1013  ++SeqPos;
1014  }
1015 
1016  return true;
1017 }
1018 
1019 bool DWARFDebugLine::LineTable::hasFileAtIndex(uint64_t FileIndex) const {
1020  return FileIndex != 0 && FileIndex <= Prologue.FileNames.size();
1021 }
1022 
1023 Optional<StringRef> DWARFDebugLine::LineTable::getSourceByIndex(uint64_t FileIndex,
1024  FileLineInfoKind Kind) const {
1025  if (Kind == FileLineInfoKind::None || !hasFileAtIndex(FileIndex))
1026  return None;
1027  const FileNameEntry &Entry = Prologue.FileNames[FileIndex - 1];
1028  if (Optional<const char *> source = Entry.Source.getAsCString())
1029  return StringRef(*source);
1030  return None;
1031 }
1032 
1033 static bool isPathAbsoluteOnWindowsOrPosix(const Twine &Path) {
1034  // Debug info can contain paths from any OS, not necessarily
1035  // an OS we're currently running on. Moreover different compilation units can
1036  // be compiled on different operating systems and linked together later.
1039 }
1040 
1042  const char *CompDir,
1043  FileLineInfoKind Kind,
1044  std::string &Result) const {
1045  if (Kind == FileLineInfoKind::None || !hasFileAtIndex(FileIndex))
1046  return false;
1047  const FileNameEntry &Entry = Prologue.FileNames[FileIndex - 1];
1048  StringRef FileName = Entry.Name.getAsCString().getValue();
1049  if (Kind != FileLineInfoKind::AbsoluteFilePath ||
1050  isPathAbsoluteOnWindowsOrPosix(FileName)) {
1051  Result = FileName;
1052  return true;
1053  }
1054 
1055  SmallString<16> FilePath;
1056  uint64_t IncludeDirIndex = Entry.DirIdx;
1057  StringRef IncludeDir;
1058  // Be defensive about the contents of Entry.
1059  if (IncludeDirIndex > 0 &&
1060  IncludeDirIndex <= Prologue.IncludeDirectories.size())
1061  IncludeDir = Prologue.IncludeDirectories[IncludeDirIndex - 1]
1062  .getAsCString()
1063  .getValue();
1064 
1065  // We may still need to append compilation directory of compile unit.
1066  // We know that FileName is not absolute, the only way to have an
1067  // absolute path at this point would be if IncludeDir is absolute.
1068  if (CompDir && Kind == FileLineInfoKind::AbsoluteFilePath &&
1069  !isPathAbsoluteOnWindowsOrPosix(IncludeDir))
1070  sys::path::append(FilePath, CompDir);
1071 
1072  // sys::path::append skips empty strings.
1073  sys::path::append(FilePath, IncludeDir, FileName);
1074  Result = FilePath.str();
1075  return true;
1076 }
1077 
1079  object::SectionedAddress Address, const char *CompDir,
1080  FileLineInfoKind Kind, DILineInfo &Result) const {
1081  // Get the index of row we're looking for in the line table.
1082  uint32_t RowIndex = lookupAddress(Address);
1083  if (RowIndex == -1U)
1084  return false;
1085  // Take file number and line/column from the row.
1086  const auto &Row = Rows[RowIndex];
1087  if (!getFileNameByIndex(Row.File, CompDir, Kind, Result.FileName))
1088  return false;
1089  Result.Line = Row.Line;
1090  Result.Column = Row.Column;
1091  Result.Discriminator = Row.Discriminator;
1092  Result.Source = getSourceByIndex(Row.File, Kind);
1093  return true;
1094 }
1095 
1096 // We want to supply the Unit associated with a .debug_line[.dwo] table when
1097 // we dump it, if possible, but still dump the table even if there isn't a Unit.
1098 // Therefore, collect up handles on all the Units that point into the
1099 // line-table section.
1104  for (const auto &CU : CUs)
1105  if (auto CUDIE = CU->getUnitDIE())
1106  if (auto StmtOffset = toSectionOffset(CUDIE.find(DW_AT_stmt_list)))
1107  LineToUnit.insert(std::make_pair(*StmtOffset, &*CU));
1108  for (const auto &TU : TUs)
1109  if (auto TUDIE = TU->getUnitDIE())
1110  if (auto StmtOffset = toSectionOffset(TUDIE.find(DW_AT_stmt_list)))
1111  LineToUnit.insert(std::make_pair(*StmtOffset, &*TU));
1112  return LineToUnit;
1113 }
1114 
1116  const DWARFContext &C,
1117  cu_range CUs, tu_range TUs)
1118  : DebugLineData(Data), Context(C) {
1119  LineToUnit = buildLineToUnitMap(CUs, TUs);
1120  if (!DebugLineData.isValidOffset(Offset))
1121  Done = true;
1122 }
1123 
1125  return TotalLength == 0xffffffff || TotalLength < 0xffffff00;
1126 }
1127 
1129  function_ref<void(Error)> RecoverableErrorCallback,
1130  function_ref<void(Error)> UnrecoverableErrorCallback, raw_ostream *OS) {
1131  assert(DebugLineData.isValidOffset(Offset) &&
1132  "parsing should have terminated");
1133  DWARFUnit *U = prepareToParse(Offset);
1134  uint32_t OldOffset = Offset;
1135  LineTable LT;
1136  if (Error Err = LT.parse(DebugLineData, &Offset, Context, U,
1137  RecoverableErrorCallback, OS))
1138  UnrecoverableErrorCallback(std::move(Err));
1139  moveToNextTable(OldOffset, LT.Prologue);
1140  return LT;
1141 }
1142 
1144  function_ref<void(Error)> ErrorCallback) {
1145  assert(DebugLineData.isValidOffset(Offset) &&
1146  "parsing should have terminated");
1147  DWARFUnit *U = prepareToParse(Offset);
1148  uint32_t OldOffset = Offset;
1149  LineTable LT;
1150  if (Error Err = LT.Prologue.parse(DebugLineData, &Offset, Context, U))
1151  ErrorCallback(std::move(Err));
1152  moveToNextTable(OldOffset, LT.Prologue);
1153 }
1154 
1155 DWARFUnit *DWARFDebugLine::SectionParser::prepareToParse(uint32_t Offset) {
1156  DWARFUnit *U = nullptr;
1157  auto It = LineToUnit.find(Offset);
1158  if (It != LineToUnit.end())
1159  U = It->second;
1160  DebugLineData.setAddressSize(U ? U->getAddressByteSize() : 0);
1161  return U;
1162 }
1163 
1164 void DWARFDebugLine::SectionParser::moveToNextTable(uint32_t OldOffset,
1165  const Prologue &P) {
1166  // If the length field is not valid, we don't know where the next table is, so
1167  // cannot continue to parse. Mark the parser as done, and leave the Offset
1168  // value as it currently is. This will be the end of the bad length field.
1169  if (!P.totalLengthIsValid()) {
1170  Done = true;
1171  return;
1172  }
1173 
1174  Offset = OldOffset + P.TotalLength + P.sizeofTotalLength();
1175  if (!DebugLineData.isValidOffset(Offset)) {
1176  Done = true;
1177  }
1178 }
SequenceVector::const_iterator SequenceIter
void dump(raw_ostream &OS, DIDumpOptions DumpOpts=DIDumpOptions()) const
const NoneType None
Definition: None.h:23
uint64_t CallInst * C
uint32_t Discriminator
Definition: DIContext.h:39
A helper struct providing information about the byte size of DW_FORM values that vary in size dependi...
Definition: Dwarf.h:499
Optional< StringRef > Source
Definition: DIContext.h:33
uint64_t LowPC
Sequence describes instructions at address range [LowPC, HighPC) and is described by line table rows ...
std::string FileName
Definition: DIContext.h:31
LLVMContext & Context
uint64_t getULEB128(uint32_t *offset_ptr) const
Extract a unsigned LEB128 value from *offset_ptr.
This class represents lattice values for constants.
Definition: AllocatorList.h:23
Row(bool DefaultIsStmt=false)
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
uint32_t sizeofTotalLength() const
SmallString< 32 > digest() const
Definition: MD5.cpp:264
StringRef LNExtendedString(unsigned Encoding)
Definition: Dwarf.cpp:421
static bool orderByAddress(const Row &LHS, const Row &RHS)
StringRef LNStandardString(unsigned Standard)
Definition: Dwarf.cpp:410
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
Definition: Format.h:123
raw_ostream & indent(unsigned NumSpaces)
indent - Insert &#39;NumSpaces&#39; spaces.
uint8_t MinInstLength
The size in bytes of the smallest target machine instruction.
static const uint64_t UndefSection
Definition: ObjectFile.h:144
An efficient, type-erasing, non-owning reference to a callable.
Definition: STLExtras.h:116
uint32_t Line
An unsigned integer indicating a source line number.
SectionParser(DWARFDataExtractor &Data, const DWARFContext &C, cu_range CUs, tu_range TUs)
uint64_t getRelocatedAddress(uint32_t *Off, uint64_t *SecIx=nullptr) const
Extracts an address-sized value and applies a relocation to the result if one exists for the given of...
void dump(raw_ostream &OS, DIDumpOptions DumpOptions) const
bool getFileLineInfoForAddress(object::SectionedAddress Address, const char *CompDir, DILineInfoSpecifier::FileLineInfoKind Kind, DILineInfo &Result) const
Fills the Result argument with the file and line information corresponding to Address.
uint16_t getU16(uint32_t *offset_ptr) const
Extract a uint16_t value from *offset_ptr.
Error parse(const DWARFDataExtractor &DebugLineData, uint32_t *OffsetPtr, const DWARFContext &Ctx, const DWARFUnit *U=nullptr)
std::vector< DWARFFormValue > IncludeDirectories
A format-neutral container for source line information.
Definition: DIContext.h:30
object::SectionedAddress Address
The program-counter value corresponding to a machine instruction generated by the compiler and sectio...
void append(SmallVectorImpl< char > &path, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
Append to path.
Definition: Path.cpp:454
bool lookupAddressRange(object::SectionedAddress Address, uint64_t Size, std::vector< uint32_t > &Result) const
uint32_t getU32(uint32_t *offset_ptr) const
Extract a uint32_t value from *offset_ptr.
uint64_t SectionIndex
If relocation information is present then this is the index of the section which contains above addre...
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:80
Represents a series of contiguous machine instructions.
Optional< ArrayRef< uint8_t > > getAsBlock() const
bool hasFileAtIndex(uint64_t FileIndex) const
void postAppend()
Called after a row is appended to the matrix.
bool is_absolute(const Twine &path, Style style=Style::native)
Is path absolute?
Definition: Path.cpp:662
Tagged union holding either a T or a Error.
Definition: CachePruning.h:22
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:126
uint8_t LineRange
This parameter affects the meaning of the special opcodes. See below.
uint8_t getAddressByteSize() const
Definition: DWARFUnit.h:279
StringRef str() const
Explicit conversion to StringRef.
Definition: SmallString.h:266
uint8_t OpcodeBase
The number assigned to the first special opcode.
void reset(bool DefaultIsStmt)
const T & getValue() const LLVM_LVALUE_FUNCTION
Definition: Optional.h:255
uint64_t TotalLength
The size in bytes of the statement information for this compilation unit (not including the total_len...
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition: SmallString.h:25
auto lower_bound(R &&Range, ForwardIt I) -> decltype(adl_begin(Range))
Provide wrappers to std::lower_bound which take ranges instead of having to pass begin/end explicitly...
Definition: STLExtras.h:1281
bool HasModTime
Whether filename entries provide a modification timestamp.
int64_t getSLEB128(uint32_t *offset_ptr) const
Extract a signed LEB128 value from *offset_ptr.
Expected< const LineTable * > getOrParseLineTable(DWARFDataExtractor &DebugLineData, uint32_t Offset, const DWARFContext &Ctx, const DWARFUnit *U, std::function< void(Error)> RecoverableErrorCallback)
Container for dump options that control which debug information will be dumped.
Definition: DIContext.h:158
Optional< uint64_t > toSectionOffset(const Optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract an section offset.
uint8_t EndSequence
A boolean indicating that the current address is that of the first byte after the end of a sequence o...
#define P(N)
* if(!EatIfPresent(lltok::kw_thread_local)) return false
ParseOptionalThreadLocal := /*empty.
uint32_t Column
Definition: DIContext.h:35
void dump(raw_ostream &OS) const
LLVM Basic Block Representation.
Definition: BasicBlock.h:57
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:45
LineTable parseNext(function_ref< void(Error)> RecoverableErrorCallback, function_ref< void(Error)> UnrecoverableErrorCallback, raw_ostream *OS=nullptr)
Get the next line table from the section.
Instrumentation for Order File
uint16_t File
An unsigned integer indicating the identity of the source file corresponding to a machine instruction...
bool HasLength
Whether filename entries provide a file size.
Error parse(DWARFDataExtractor &DebugLineData, uint32_t *OffsetPtr, const DWARFContext &Ctx, const DWARFUnit *U, std::function< void(Error)> RecoverableErrorCallback, raw_ostream *OS=nullptr)
Parse prologue and all rows.
uint8_t getAddressSize() const
Get the address size for this extractor.
Definition: DataExtractor.h:58
static ContentDescriptors parseV5EntryFormat(const DWARFDataExtractor &DebugLineData, uint32_t *OffsetPtr, uint64_t EndPrologueOffset, DWARFDebugLine::ContentTypeTracker *ContentTypes)
uint8_t getU8(uint32_t *offset_ptr) const
Extract a uint8_t value from *offset_ptr.
Optional< uint64_t > getAsUnsignedConstant() const
bool skipValue(DataExtractor DebugInfoData, uint32_t *OffsetPtr, const dwarf::FormParams Params) const
Skip a form&#39;s value in DebugInfoData at the offset specified by OffsetPtr.
uint64_t getU64(uint32_t *offset_ptr) const
Extract a uint64_t value from *offset_ptr.
void appendSequence(const DWARFDebugLine::Sequence &S)
void dump(raw_ostream &OS, DIDumpOptions DumpOptions) const
Standard .debug_line state machine structure.
void sort(IteratorTy Start, IteratorTy End)
Definition: STLExtras.h:1115
A DataExtractor (typically for an in-memory copy of an object-file section) plus a relocation map for...
static bool parseV5DirFileTables(const DWARFDataExtractor &DebugLineData, uint32_t *OffsetPtr, uint64_t EndPrologueOffset, const dwarf::FormParams &FormParams, const DWARFContext &Ctx, const DWARFUnit *U, DWARFDebugLine::ContentTypeTracker &ContentTypes, std::vector< DWARFFormValue > &IncludeDirectories, std::vector< DWARFDebugLine::FileNameEntry > &FileNames)
uint16_t Column
An unsigned integer indicating a column number within a source line.
static ErrorSuccess success()
Create a success value.
Definition: Error.h:326
static DWARFDebugLine::SectionParser::LineToUnitMap buildLineToUnitMap(DWARFDebugLine::SectionParser::cu_range CUs, DWARFDebugLine::SectionParser::tu_range TUs)
std::map< uint64_t, DWARFUnit * > LineToUnitMap
uint32_t Line
Definition: DIContext.h:34
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:841
void appendRow(const DWARFDebugLine::Row &R)
DWARFContext This data structure is the top level entity that deals with dwarf debug information pars...
Definition: DWARFContext.h:58
uint32_t lookupAddress(object::SectionedAddress Address) const
Returns the index of the row with file/line info for a given address, or UnknownRowIndex if there is ...
static void dumpTableHeader(raw_ostream &OS)
void setAddressSize(uint8_t Size)
Set the address size for this extractor.
Definition: DataExtractor.h:60
std::vector< uint8_t > StandardOpcodeLengths
A range adaptor for a pair of iterators.
This file contains constants used for implementing Dwarf debug support.
static void clear(coro::Shape &Shape)
Definition: Coroutines.cpp:211
static DWARFFormValue createFromPValue(dwarf::Form F, const char *V)
bool extractValue(const DWARFDataExtractor &Data, uint32_t *OffsetPtr, dwarf::FormParams FormParams, const DWARFContext *Context=nullptr, const DWARFUnit *Unit=nullptr)
Extracts a value in Data at offset *OffsetPtr.
Tracks which optional content types are present in a DWARF file name entry format.
std::vector< FileNameEntry > FileNames
uint32_t Discriminator
An unsigned integer representing the DWARF path discriminator value for this location.
RowVector::const_iterator RowIter
uint64_t getUnsigned(uint32_t *offset_ptr, uint32_t byte_size) const
Extract an unsigned integer of size byte_size from *offset_ptr.
#define I(x, y, z)
Definition: MD5.cpp:58
static bool orderByLowPC(const Sequence &LHS, const Sequence &RHS)
Optional< const char * > getAsCString() const
Sequence
A sequence of states that a pointer may go through in which an objc_retain and objc_release are actua...
Definition: PtrState.h:40
const char * getCStr(uint32_t *offset_ptr) const
Extract a C string from *offset_ptr.
uint32_t Size
Definition: Profile.cpp:46
bool isValidOffset(uint32_t offset) const
Test the validity of offset.
uint8_t DefaultIsStmt
The initial value of theis_stmtregister.
LLVM_NODISCARD const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
Definition: StringRef.h:122
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
DwarfFormat Format
Definition: Dwarf.h:502
bool containsPC(object::SectionedAddress PC) const
std::array< uint8_t, 16 > Bytes
Definition: MD5.h:56
static bool isPathAbsoluteOnWindowsOrPosix(const Twine &Path)
int8_t LineBase
This parameter affects the meaning of the special opcodes. See below.
bool getFileNameByIndex(uint64_t FileIndex, const char *CompDir, DILineInfoSpecifier::FileLineInfoKind Kind, std::string &Result) const
Extracts filename by its index in filename table in prologue.
const LineTable * getLineTable(uint32_t Offset) const
LLVM Value Representation.
Definition: Value.h:72
StringRef getCStrRef(uint32_t *OffsetPtr) const
Extract a C string from *OffsetPtr.
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:45
static void parseV2DirFileTables(const DWARFDataExtractor &DebugLineData, uint32_t *OffsetPtr, uint64_t EndPrologueOffset, DWARFDebugLine::ContentTypeTracker &ContentTypes, std::vector< DWARFFormValue > &IncludeDirectories, std::vector< DWARFDebugLine::FileNameEntry > &FileNames)
print Print MemDeps of function
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48
void skip(function_ref< void(Error)> ErrorCallback)
Skip the current line table and go to the following line table (if present) immediately.
void trackContentType(dwarf::LineNumberEntryFormat ContentType)
Update tracked content types with ContentType.
LineNumberEntryFormat
Definition: Dwarf.h:244
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
Definition: Error.h:1163