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 
69 bool DWARFDebugLine::Prologue::hasFileAtIndex(uint64_t FileIndex) const {
70  uint16_t DwarfVersion = getVersion();
71  assert(DwarfVersion != 0 &&
72  "line table prologue has no dwarf version information");
73  if (DwarfVersion >= 5)
74  return FileIndex < FileNames.size();
75  return FileIndex != 0 && FileIndex <= FileNames.size();
76 }
77 
80  uint16_t DwarfVersion = getVersion();
81  assert(DwarfVersion != 0 &&
82  "line table prologue has no dwarf version information");
83  // In DWARF v5 the file names are 0-indexed.
84  if (DwarfVersion >= 5)
85  return FileNames[Index];
86  return FileNames[Index - 1];
87 }
88 
90  TotalLength = PrologueLength = 0;
91  SegSelectorSize = 0;
92  MinInstLength = MaxOpsPerInst = DefaultIsStmt = LineBase = LineRange = 0;
93  OpcodeBase = 0;
95  ContentTypes = ContentTypeTracker();
96  StandardOpcodeLengths.clear();
97  IncludeDirectories.clear();
98  FileNames.clear();
99 }
100 
102  DIDumpOptions DumpOptions) const {
103  OS << "Line table prologue:\n"
104  << format(" total_length: 0x%8.8" PRIx64 "\n", TotalLength)
105  << format(" version: %u\n", getVersion());
106  if (getVersion() >= 5)
107  OS << format(" address_size: %u\n", getAddressSize())
108  << format(" seg_select_size: %u\n", SegSelectorSize);
109  OS << format(" prologue_length: 0x%8.8" PRIx64 "\n", PrologueLength)
110  << format(" min_inst_length: %u\n", MinInstLength)
111  << format(getVersion() >= 4 ? "max_ops_per_inst: %u\n" : "", MaxOpsPerInst)
112  << format(" default_is_stmt: %u\n", DefaultIsStmt)
113  << format(" line_base: %i\n", LineBase)
114  << format(" line_range: %u\n", LineRange)
115  << format(" opcode_base: %u\n", OpcodeBase);
116 
117  for (uint32_t I = 0; I != StandardOpcodeLengths.size(); ++I)
118  OS << format("standard_opcode_lengths[%s] = %u\n",
119  LNStandardString(I + 1).data(), StandardOpcodeLengths[I]);
120 
121  if (!IncludeDirectories.empty()) {
122  // DWARF v5 starts directory indexes at 0.
123  uint32_t DirBase = getVersion() >= 5 ? 0 : 1;
124  for (uint32_t I = 0; I != IncludeDirectories.size(); ++I) {
125  OS << format("include_directories[%3u] = ", I + DirBase);
126  IncludeDirectories[I].dump(OS, DumpOptions);
127  OS << '\n';
128  }
129  }
130 
131  if (!FileNames.empty()) {
132  // DWARF v5 starts file indexes at 0.
133  uint32_t FileBase = getVersion() >= 5 ? 0 : 1;
134  for (uint32_t I = 0; I != FileNames.size(); ++I) {
135  const FileNameEntry &FileEntry = FileNames[I];
136  OS << format("file_names[%3u]:\n", I + FileBase);
137  OS << " name: ";
138  FileEntry.Name.dump(OS, DumpOptions);
139  OS << '\n'
140  << format(" dir_index: %" PRIu64 "\n", FileEntry.DirIdx);
141  if (ContentTypes.HasMD5)
142  OS << " md5_checksum: " << FileEntry.Checksum.digest() << '\n';
143  if (ContentTypes.HasModTime)
144  OS << format(" mod_time: 0x%8.8" PRIx64 "\n", FileEntry.ModTime);
145  if (ContentTypes.HasLength)
146  OS << format(" length: 0x%8.8" PRIx64 "\n", FileEntry.Length);
147  if (ContentTypes.HasSource) {
148  OS << " source: ";
149  FileEntry.Source.dump(OS, DumpOptions);
150  OS << '\n';
151  }
152  }
153  }
154 }
155 
156 // Parse v2-v4 directory and file tables.
157 static void
159  uint32_t *OffsetPtr, uint64_t EndPrologueOffset,
161  std::vector<DWARFFormValue> &IncludeDirectories,
162  std::vector<DWARFDebugLine::FileNameEntry> &FileNames) {
163  while (*OffsetPtr < EndPrologueOffset) {
164  StringRef S = DebugLineData.getCStrRef(OffsetPtr);
165  if (S.empty())
166  break;
167  DWARFFormValue Dir =
168  DWARFFormValue::createFromPValue(dwarf::DW_FORM_string, S.data());
169  IncludeDirectories.push_back(Dir);
170  }
171 
172  while (*OffsetPtr < EndPrologueOffset) {
173  StringRef Name = DebugLineData.getCStrRef(OffsetPtr);
174  if (Name.empty())
175  break;
177  FileEntry.Name =
178  DWARFFormValue::createFromPValue(dwarf::DW_FORM_string, Name.data());
179  FileEntry.DirIdx = DebugLineData.getULEB128(OffsetPtr);
180  FileEntry.ModTime = DebugLineData.getULEB128(OffsetPtr);
181  FileEntry.Length = DebugLineData.getULEB128(OffsetPtr);
182  FileNames.push_back(FileEntry);
183  }
184 
185  ContentTypes.HasModTime = true;
186  ContentTypes.HasLength = true;
187 }
188 
189 // Parse v5 directory/file entry content descriptions.
190 // Returns the descriptors, or an empty vector if we did not find a path or
191 // ran off the end of the prologue.
192 static ContentDescriptors
194  *OffsetPtr, uint64_t EndPrologueOffset, DWARFDebugLine::ContentTypeTracker
195  *ContentTypes) {
196  ContentDescriptors Descriptors;
197  int FormatCount = DebugLineData.getU8(OffsetPtr);
198  bool HasPath = false;
199  for (int I = 0; I != FormatCount; ++I) {
200  if (*OffsetPtr >= EndPrologueOffset)
201  return ContentDescriptors();
202  ContentDescriptor Descriptor;
203  Descriptor.Type =
204  dwarf::LineNumberEntryFormat(DebugLineData.getULEB128(OffsetPtr));
205  Descriptor.Form = dwarf::Form(DebugLineData.getULEB128(OffsetPtr));
206  if (Descriptor.Type == dwarf::DW_LNCT_path)
207  HasPath = true;
208  if (ContentTypes)
209  ContentTypes->trackContentType(Descriptor.Type);
210  Descriptors.push_back(Descriptor);
211  }
212  return HasPath ? Descriptors : ContentDescriptors();
213 }
214 
215 static bool
217  uint32_t *OffsetPtr, uint64_t EndPrologueOffset,
219  const DWARFContext &Ctx, const DWARFUnit *U,
221  std::vector<DWARFFormValue> &IncludeDirectories,
222  std::vector<DWARFDebugLine::FileNameEntry> &FileNames) {
223  // Get the directory entry description.
224  ContentDescriptors DirDescriptors =
225  parseV5EntryFormat(DebugLineData, OffsetPtr, EndPrologueOffset, nullptr);
226  if (DirDescriptors.empty())
227  return false;
228 
229  // Get the directory entries, according to the format described above.
230  int DirEntryCount = DebugLineData.getU8(OffsetPtr);
231  for (int I = 0; I != DirEntryCount; ++I) {
232  if (*OffsetPtr >= EndPrologueOffset)
233  return false;
234  for (auto Descriptor : DirDescriptors) {
235  DWARFFormValue Value(Descriptor.Form);
236  switch (Descriptor.Type) {
237  case DW_LNCT_path:
238  if (!Value.extractValue(DebugLineData, OffsetPtr, FormParams, &Ctx, U))
239  return false;
240  IncludeDirectories.push_back(Value);
241  break;
242  default:
243  if (!Value.skipValue(DebugLineData, OffsetPtr, FormParams))
244  return false;
245  }
246  }
247  }
248 
249  // Get the file entry description.
250  ContentDescriptors FileDescriptors =
251  parseV5EntryFormat(DebugLineData, OffsetPtr, EndPrologueOffset,
252  &ContentTypes);
253  if (FileDescriptors.empty())
254  return false;
255 
256  // Get the file entries, according to the format described above.
257  int FileEntryCount = DebugLineData.getU8(OffsetPtr);
258  for (int I = 0; I != FileEntryCount; ++I) {
259  if (*OffsetPtr >= EndPrologueOffset)
260  return false;
262  for (auto Descriptor : FileDescriptors) {
263  DWARFFormValue Value(Descriptor.Form);
264  if (!Value.extractValue(DebugLineData, OffsetPtr, FormParams, &Ctx, U))
265  return false;
266  switch (Descriptor.Type) {
267  case DW_LNCT_path:
268  FileEntry.Name = Value;
269  break;
270  case DW_LNCT_LLVM_source:
271  FileEntry.Source = Value;
272  break;
273  case DW_LNCT_directory_index:
274  FileEntry.DirIdx = Value.getAsUnsignedConstant().getValue();
275  break;
276  case DW_LNCT_timestamp:
277  FileEntry.ModTime = Value.getAsUnsignedConstant().getValue();
278  break;
279  case DW_LNCT_size:
280  FileEntry.Length = Value.getAsUnsignedConstant().getValue();
281  break;
282  case DW_LNCT_MD5:
283  assert(Value.getAsBlock().getValue().size() == 16);
284  std::uninitialized_copy_n(Value.getAsBlock().getValue().begin(), 16,
285  FileEntry.Checksum.Bytes.begin());
286  break;
287  default:
288  break;
289  }
290  }
291  FileNames.push_back(FileEntry);
292  }
293  return true;
294 }
295 
297  uint32_t *OffsetPtr,
298  const DWARFContext &Ctx,
299  const DWARFUnit *U) {
300  const uint64_t PrologueOffset = *OffsetPtr;
301 
302  clear();
303  TotalLength = DebugLineData.getRelocatedValue(4, OffsetPtr);
304  if (TotalLength == UINT32_MAX) {
306  TotalLength = DebugLineData.getU64(OffsetPtr);
307  } else if (TotalLength >= 0xfffffff0) {
309  "parsing line table prologue at offset 0x%8.8" PRIx64
310  " unsupported reserved unit length found of value 0x%8.8" PRIx64,
311  PrologueOffset, TotalLength);
312  }
313  FormParams.Version = DebugLineData.getU16(OffsetPtr);
314  if (getVersion() < 2)
316  "parsing line table prologue at offset 0x%8.8" PRIx64
317  " found unsupported version 0x%2.2" PRIx16,
318  PrologueOffset, getVersion());
319 
320  if (getVersion() >= 5) {
321  FormParams.AddrSize = DebugLineData.getU8(OffsetPtr);
322  assert((DebugLineData.getAddressSize() == 0 ||
323  DebugLineData.getAddressSize() == getAddressSize()) &&
324  "Line table header and data extractor disagree");
325  SegSelectorSize = DebugLineData.getU8(OffsetPtr);
326  }
327 
328  PrologueLength =
329  DebugLineData.getRelocatedValue(sizeofPrologueLength(), OffsetPtr);
330  const uint64_t EndPrologueOffset = PrologueLength + *OffsetPtr;
331  MinInstLength = DebugLineData.getU8(OffsetPtr);
332  if (getVersion() >= 4)
333  MaxOpsPerInst = DebugLineData.getU8(OffsetPtr);
334  DefaultIsStmt = DebugLineData.getU8(OffsetPtr);
335  LineBase = DebugLineData.getU8(OffsetPtr);
336  LineRange = DebugLineData.getU8(OffsetPtr);
337  OpcodeBase = DebugLineData.getU8(OffsetPtr);
338 
339  StandardOpcodeLengths.reserve(OpcodeBase - 1);
340  for (uint32_t I = 1; I < OpcodeBase; ++I) {
341  uint8_t OpLen = DebugLineData.getU8(OffsetPtr);
342  StandardOpcodeLengths.push_back(OpLen);
343  }
344 
345  if (getVersion() >= 5) {
346  if (!parseV5DirFileTables(DebugLineData, OffsetPtr, EndPrologueOffset,
347  FormParams, Ctx, U, ContentTypes,
348  IncludeDirectories, FileNames)) {
350  "parsing line table prologue at 0x%8.8" PRIx64
351  " found an invalid directory or file table description at"
352  " 0x%8.8" PRIx64,
353  PrologueOffset, (uint64_t)*OffsetPtr);
354  }
355  } else
356  parseV2DirFileTables(DebugLineData, OffsetPtr, EndPrologueOffset,
357  ContentTypes, IncludeDirectories, FileNames);
358 
359  if (*OffsetPtr != EndPrologueOffset)
361  "parsing line table prologue at 0x%8.8" PRIx64
362  " should have ended at 0x%8.8" PRIx64
363  " but it ended at 0x%8.8" PRIx64,
364  PrologueOffset, EndPrologueOffset, (uint64_t)*OffsetPtr);
365  return Error::success();
366 }
367 
368 DWARFDebugLine::Row::Row(bool DefaultIsStmt) { reset(DefaultIsStmt); }
369 
371  Discriminator = 0;
372  BasicBlock = false;
373  PrologueEnd = false;
374  EpilogueBegin = false;
375 }
376 
377 void DWARFDebugLine::Row::reset(bool DefaultIsStmt) {
378  Address.Address = 0;
380  Line = 1;
381  Column = 0;
382  File = 1;
383  Isa = 0;
384  Discriminator = 0;
385  IsStmt = DefaultIsStmt;
386  BasicBlock = false;
387  EndSequence = false;
388  PrologueEnd = false;
389  EpilogueBegin = false;
390 }
391 
393  OS << "Address Line Column File ISA Discriminator Flags\n"
394  << "------------------ ------ ------ ------ --- ------------- "
395  "-------------\n";
396 }
397 
399  OS << format("0x%16.16" PRIx64 " %6u %6u", Address.Address, Line, Column)
400  << format(" %6u %3u %13u ", File, Isa, Discriminator)
401  << (IsStmt ? " is_stmt" : "") << (BasicBlock ? " basic_block" : "")
402  << (PrologueEnd ? " prologue_end" : "")
403  << (EpilogueBegin ? " epilogue_begin" : "")
404  << (EndSequence ? " end_sequence" : "") << '\n';
405 }
406 
408 
410  LowPC = 0;
411  HighPC = 0;
413  FirstRowIndex = 0;
414  LastRowIndex = 0;
415  Empty = true;
416 }
417 
419 
421  DIDumpOptions DumpOptions) const {
422  Prologue.dump(OS, DumpOptions);
423  OS << '\n';
424 
425  if (!Rows.empty()) {
426  Row::dumpTableHeader(OS);
427  for (const Row &R : Rows) {
428  R.dump(OS);
429  }
430  }
431 }
432 
434  Prologue.clear();
435  Rows.clear();
436  Sequences.clear();
437 }
438 
439 DWARFDebugLine::ParsingState::ParsingState(struct LineTable *LT)
440  : LineTable(LT) {
441  resetRowAndSequence();
442 }
443 
444 void DWARFDebugLine::ParsingState::resetRowAndSequence() {
446  Sequence.reset();
447 }
448 
449 void DWARFDebugLine::ParsingState::appendRowToMatrix() {
450  unsigned RowNumber = LineTable->Rows.size();
451  if (Sequence.Empty) {
452  // Record the beginning of instruction sequence.
453  Sequence.Empty = false;
455  Sequence.FirstRowIndex = RowNumber;
456  }
458  if (Row.EndSequence) {
459  // Record the end of instruction sequence.
461  Sequence.LastRowIndex = RowNumber + 1;
463  if (Sequence.isValid())
465  Sequence.reset();
466  }
467  Row.postAppend();
468 }
469 
472  LineTableConstIter Pos = LineTableMap.find(Offset);
473  if (Pos != LineTableMap.end())
474  return &Pos->second;
475  return nullptr;
476 }
477 
479  DWARFDataExtractor &DebugLineData, uint32_t Offset, const DWARFContext &Ctx,
480  const DWARFUnit *U, std::function<void(Error)> RecoverableErrorCallback) {
481  if (!DebugLineData.isValidOffset(Offset))
482  return createStringError(errc::invalid_argument, "offset 0x%8.8" PRIx32
483  " is not a valid debug line section offset",
484  Offset);
485 
486  std::pair<LineTableIter, bool> Pos =
487  LineTableMap.insert(LineTableMapTy::value_type(Offset, LineTable()));
488  LineTable *LT = &Pos.first->second;
489  if (Pos.second) {
490  if (Error Err =
491  LT->parse(DebugLineData, &Offset, Ctx, U, RecoverableErrorCallback))
492  return std::move(Err);
493  return LT;
494  }
495  return LT;
496 }
497 
499  DWARFDataExtractor &DebugLineData, uint32_t *OffsetPtr,
500  const DWARFContext &Ctx, const DWARFUnit *U,
501  std::function<void(Error)> RecoverableErrorCallback, raw_ostream *OS) {
502  const uint32_t DebugLineOffset = *OffsetPtr;
503 
504  clear();
505 
506  Error PrologueErr = Prologue.parse(DebugLineData, OffsetPtr, Ctx, U);
507 
508  if (OS) {
509  // The presence of OS signals verbose dumping.
510  DIDumpOptions DumpOptions;
511  DumpOptions.Verbose = true;
512  Prologue.dump(*OS, DumpOptions);
513  }
514 
515  if (PrologueErr)
516  return PrologueErr;
517 
518  const uint32_t EndOffset =
519  DebugLineOffset + Prologue.TotalLength + Prologue.sizeofTotalLength();
520 
521  // See if we should tell the data extractor the address size.
522  if (DebugLineData.getAddressSize() == 0)
523  DebugLineData.setAddressSize(Prologue.getAddressSize());
524  else
525  assert(Prologue.getAddressSize() == 0 ||
526  Prologue.getAddressSize() == DebugLineData.getAddressSize());
527 
528  ParsingState State(this);
529 
530  while (*OffsetPtr < EndOffset) {
531  if (OS)
532  *OS << format("0x%08.08" PRIx32 ": ", *OffsetPtr);
533 
534  uint8_t Opcode = DebugLineData.getU8(OffsetPtr);
535 
536  if (OS)
537  *OS << format("%02.02" PRIx8 " ", Opcode);
538 
539  if (Opcode == 0) {
540  // Extended Opcodes always start with a zero opcode followed by
541  // a uleb128 length so you can skip ones you don't know about
542  uint64_t Len = DebugLineData.getULEB128(OffsetPtr);
543  uint32_t ExtOffset = *OffsetPtr;
544 
545  // Tolerate zero-length; assume length is correct and soldier on.
546  if (Len == 0) {
547  if (OS)
548  *OS << "Badly formed extended line op (length 0)\n";
549  continue;
550  }
551 
552  uint8_t SubOpcode = DebugLineData.getU8(OffsetPtr);
553  if (OS)
554  *OS << LNExtendedString(SubOpcode);
555  switch (SubOpcode) {
556  case DW_LNE_end_sequence:
557  // Set the end_sequence register of the state machine to true and
558  // append a row to the matrix using the current values of the
559  // state-machine registers. Then reset the registers to the initial
560  // values specified above. Every statement program sequence must end
561  // with a DW_LNE_end_sequence instruction which creates a row whose
562  // address is that of the byte after the last target machine instruction
563  // of the sequence.
564  State.Row.EndSequence = true;
565  State.appendRowToMatrix();
566  if (OS) {
567  *OS << "\n";
568  OS->indent(12);
569  State.Row.dump(*OS);
570  }
571  State.resetRowAndSequence();
572  break;
573 
574  case DW_LNE_set_address:
575  // Takes a single relocatable address as an operand. The size of the
576  // operand is the size appropriate to hold an address on the target
577  // machine. Set the address register to the value given by the
578  // relocatable address. All of the other statement program opcodes
579  // that affect the address register add a delta to it. This instruction
580  // stores a relocatable value into it instead.
581  //
582  // Make sure the extractor knows the address size. If not, infer it
583  // from the size of the operand.
584  if (DebugLineData.getAddressSize() == 0)
585  DebugLineData.setAddressSize(Len - 1);
586  else if (DebugLineData.getAddressSize() != Len - 1) {
588  "mismatching address size at offset 0x%8.8" PRIx32
589  " expected 0x%2.2" PRIx8 " found 0x%2.2" PRIx64,
590  ExtOffset, DebugLineData.getAddressSize(),
591  Len - 1);
592  }
593  State.Row.Address.Address = DebugLineData.getRelocatedAddress(
594  OffsetPtr, &State.Row.Address.SectionIndex);
595  if (OS)
596  *OS << format(" (0x%16.16" PRIx64 ")", State.Row.Address.Address);
597  break;
598 
599  case DW_LNE_define_file:
600  // Takes 4 arguments. The first is a null terminated string containing
601  // a source file name. The second is an unsigned LEB128 number
602  // representing the directory index of the directory in which the file
603  // was found. The third is an unsigned LEB128 number representing the
604  // time of last modification of the file. The fourth is an unsigned
605  // LEB128 number representing the length in bytes of the file. The time
606  // and length fields may contain LEB128(0) if the information is not
607  // available.
608  //
609  // The directory index represents an entry in the include_directories
610  // section of the statement program prologue. The index is LEB128(0)
611  // if the file was found in the current directory of the compilation,
612  // LEB128(1) if it was found in the first directory in the
613  // include_directories section, and so on. The directory index is
614  // ignored for file names that represent full path names.
615  //
616  // The files are numbered, starting at 1, in the order in which they
617  // appear; the names in the prologue come before names defined by
618  // the DW_LNE_define_file instruction. These numbers are used in the
619  // the file register of the state machine.
620  {
621  FileNameEntry FileEntry;
622  const char *Name = DebugLineData.getCStr(OffsetPtr);
623  FileEntry.Name =
624  DWARFFormValue::createFromPValue(dwarf::DW_FORM_string, Name);
625  FileEntry.DirIdx = DebugLineData.getULEB128(OffsetPtr);
626  FileEntry.ModTime = DebugLineData.getULEB128(OffsetPtr);
627  FileEntry.Length = DebugLineData.getULEB128(OffsetPtr);
628  Prologue.FileNames.push_back(FileEntry);
629  if (OS)
630  *OS << " (" << Name << ", dir=" << FileEntry.DirIdx << ", mod_time="
631  << format("(0x%16.16" PRIx64 ")", FileEntry.ModTime)
632  << ", length=" << FileEntry.Length << ")";
633  }
634  break;
635 
636  case DW_LNE_set_discriminator:
637  State.Row.Discriminator = DebugLineData.getULEB128(OffsetPtr);
638  if (OS)
639  *OS << " (" << State.Row.Discriminator << ")";
640  break;
641 
642  default:
643  if (OS)
644  *OS << format("Unrecognized extended op 0x%02.02" PRIx8, SubOpcode)
645  << format(" length %" PRIx64, Len);
646  // Len doesn't include the zero opcode byte or the length itself, but
647  // it does include the sub_opcode, so we have to adjust for that.
648  (*OffsetPtr) += Len - 1;
649  break;
650  }
651  // Make sure the stated and parsed lengths are the same.
652  // Otherwise we have an unparseable line-number program.
653  if (*OffsetPtr - ExtOffset != Len)
655  "unexpected line op length at offset 0x%8.8" PRIx32
656  " expected 0x%2.2" PRIx64 " found 0x%2.2" PRIx32,
657  ExtOffset, Len, *OffsetPtr - ExtOffset);
658  } else if (Opcode < Prologue.OpcodeBase) {
659  if (OS)
660  *OS << LNStandardString(Opcode);
661  switch (Opcode) {
662  // Standard Opcodes
663  case DW_LNS_copy:
664  // Takes no arguments. Append a row to the matrix using the
665  // current values of the state-machine registers.
666  if (OS) {
667  *OS << "\n";
668  OS->indent(12);
669  State.Row.dump(*OS);
670  *OS << "\n";
671  }
672  State.appendRowToMatrix();
673  break;
674 
675  case DW_LNS_advance_pc:
676  // Takes a single unsigned LEB128 operand, multiplies it by the
677  // min_inst_length field of the prologue, and adds the
678  // result to the address register of the state machine.
679  {
680  uint64_t AddrOffset =
681  DebugLineData.getULEB128(OffsetPtr) * Prologue.MinInstLength;
682  State.Row.Address.Address += AddrOffset;
683  if (OS)
684  *OS << " (" << AddrOffset << ")";
685  }
686  break;
687 
688  case DW_LNS_advance_line:
689  // Takes a single signed LEB128 operand and adds that value to
690  // the line register of the state machine.
691  State.Row.Line += DebugLineData.getSLEB128(OffsetPtr);
692  if (OS)
693  *OS << " (" << State.Row.Line << ")";
694  break;
695 
696  case DW_LNS_set_file:
697  // Takes a single unsigned LEB128 operand and stores it in the file
698  // register of the state machine.
699  State.Row.File = DebugLineData.getULEB128(OffsetPtr);
700  if (OS)
701  *OS << " (" << State.Row.File << ")";
702  break;
703 
704  case DW_LNS_set_column:
705  // Takes a single unsigned LEB128 operand and stores it in the
706  // column register of the state machine.
707  State.Row.Column = DebugLineData.getULEB128(OffsetPtr);
708  if (OS)
709  *OS << " (" << State.Row.Column << ")";
710  break;
711 
712  case DW_LNS_negate_stmt:
713  // Takes no arguments. Set the is_stmt register of the state
714  // machine to the logical negation of its current value.
715  State.Row.IsStmt = !State.Row.IsStmt;
716  break;
717 
718  case DW_LNS_set_basic_block:
719  // Takes no arguments. Set the basic_block register of the
720  // state machine to true
721  State.Row.BasicBlock = true;
722  break;
723 
724  case DW_LNS_const_add_pc:
725  // Takes no arguments. Add to the address register of the state
726  // machine the address increment value corresponding to special
727  // opcode 255. The motivation for DW_LNS_const_add_pc is this:
728  // when the statement program needs to advance the address by a
729  // small amount, it can use a single special opcode, which occupies
730  // a single byte. When it needs to advance the address by up to
731  // twice the range of the last special opcode, it can use
732  // DW_LNS_const_add_pc followed by a special opcode, for a total
733  // of two bytes. Only if it needs to advance the address by more
734  // than twice that range will it need to use both DW_LNS_advance_pc
735  // and a special opcode, requiring three or more bytes.
736  {
737  uint8_t AdjustOpcode = 255 - Prologue.OpcodeBase;
738  uint64_t AddrOffset =
739  (AdjustOpcode / Prologue.LineRange) * Prologue.MinInstLength;
740  State.Row.Address.Address += AddrOffset;
741  if (OS)
742  *OS
743  << format(" (0x%16.16" PRIx64 ")", AddrOffset);
744  }
745  break;
746 
747  case DW_LNS_fixed_advance_pc:
748  // Takes a single uhalf operand. Add to the address register of
749  // the state machine the value of the (unencoded) operand. This
750  // is the only extended opcode that takes an argument that is not
751  // a variable length number. The motivation for DW_LNS_fixed_advance_pc
752  // is this: existing assemblers cannot emit DW_LNS_advance_pc or
753  // special opcodes because they cannot encode LEB128 numbers or
754  // judge when the computation of a special opcode overflows and
755  // requires the use of DW_LNS_advance_pc. Such assemblers, however,
756  // can use DW_LNS_fixed_advance_pc instead, sacrificing compression.
757  {
758  uint16_t PCOffset = DebugLineData.getRelocatedValue(2, OffsetPtr);
759  State.Row.Address.Address += PCOffset;
760  if (OS)
761  *OS
762  << format(" (0x%4.4" PRIx16 ")", PCOffset);
763  }
764  break;
765 
766  case DW_LNS_set_prologue_end:
767  // Takes no arguments. Set the prologue_end register of the
768  // state machine to true
769  State.Row.PrologueEnd = true;
770  break;
771 
772  case DW_LNS_set_epilogue_begin:
773  // Takes no arguments. Set the basic_block register of the
774  // state machine to true
775  State.Row.EpilogueBegin = true;
776  break;
777 
778  case DW_LNS_set_isa:
779  // Takes a single unsigned LEB128 operand and stores it in the
780  // column register of the state machine.
781  State.Row.Isa = DebugLineData.getULEB128(OffsetPtr);
782  if (OS)
783  *OS << " (" << State.Row.Isa << ")";
784  break;
785 
786  default:
787  // Handle any unknown standard opcodes here. We know the lengths
788  // of such opcodes because they are specified in the prologue
789  // as a multiple of LEB128 operands for each opcode.
790  {
791  assert(Opcode - 1U < Prologue.StandardOpcodeLengths.size());
792  uint8_t OpcodeLength = Prologue.StandardOpcodeLengths[Opcode - 1];
793  for (uint8_t I = 0; I < OpcodeLength; ++I) {
794  uint64_t Value = DebugLineData.getULEB128(OffsetPtr);
795  if (OS)
796  *OS << format("Skipping ULEB128 value: 0x%16.16" PRIx64 ")\n",
797  Value);
798  }
799  }
800  break;
801  }
802  } else {
803  // Special Opcodes
804 
805  // A special opcode value is chosen based on the amount that needs
806  // to be added to the line and address registers. The maximum line
807  // increment for a special opcode is the value of the line_base
808  // field in the header, plus the value of the line_range field,
809  // minus 1 (line base + line range - 1). If the desired line
810  // increment is greater than the maximum line increment, a standard
811  // opcode must be used instead of a special opcode. The "address
812  // advance" is calculated by dividing the desired address increment
813  // by the minimum_instruction_length field from the header. The
814  // special opcode is then calculated using the following formula:
815  //
816  // opcode = (desired line increment - line_base) +
817  // (line_range * address advance) + opcode_base
818  //
819  // If the resulting opcode is greater than 255, a standard opcode
820  // must be used instead.
821  //
822  // To decode a special opcode, subtract the opcode_base from the
823  // opcode itself to give the adjusted opcode. The amount to
824  // increment the address register is the result of the adjusted
825  // opcode divided by the line_range multiplied by the
826  // minimum_instruction_length field from the header. That is:
827  //
828  // address increment = (adjusted opcode / line_range) *
829  // minimum_instruction_length
830  //
831  // The amount to increment the line register is the line_base plus
832  // the result of the adjusted opcode modulo the line_range. That is:
833  //
834  // line increment = line_base + (adjusted opcode % line_range)
835 
836  uint8_t AdjustOpcode = Opcode - Prologue.OpcodeBase;
837  uint64_t AddrOffset =
838  (AdjustOpcode / Prologue.LineRange) * Prologue.MinInstLength;
839  int32_t LineOffset =
840  Prologue.LineBase + (AdjustOpcode % Prologue.LineRange);
841  State.Row.Line += LineOffset;
842  State.Row.Address.Address += AddrOffset;
843 
844  if (OS) {
845  *OS << "address += " << AddrOffset << ", line += " << LineOffset
846  << "\n";
847  OS->indent(12);
848  State.Row.dump(*OS);
849  }
850 
851  State.appendRowToMatrix();
852  }
853  if(OS)
854  *OS << "\n";
855  }
856 
857  if (!State.Sequence.Empty)
858  RecoverableErrorCallback(
860  "last sequence in debug line table is not terminated!"));
861 
862  // Sort all sequences so that address lookup will work faster.
863  if (!Sequences.empty()) {
864  llvm::sort(Sequences, Sequence::orderByHighPC);
865  // Note: actually, instruction address ranges of sequences should not
866  // overlap (in shared objects and executables). If they do, the address
867  // lookup would still work, though, but result would be ambiguous.
868  // We don't report warning in this case. For example,
869  // sometimes .so compiled from multiple object files contains a few
870  // rudimentary sequences for address ranges [0x0, 0xsomething).
871  }
872 
873  return Error::success();
874 }
875 
876 uint32_t DWARFDebugLine::LineTable::findRowInSeq(
877  const DWARFDebugLine::Sequence &Seq,
879  if (!Seq.containsPC(Address))
880  return UnknownRowIndex;
881  assert(Seq.SectionIndex == Address.SectionIndex);
882  // In some cases, e.g. first instruction in a function, the compiler generates
883  // two entries, both with the same address. We want the last one.
884  //
885  // In general we want a non-empty range: the last row whose address is less
886  // than or equal to Address. This can be computed as upper_bound - 1.
888  Row.Address = Address;
889  RowIter FirstRow = Rows.begin() + Seq.FirstRowIndex;
890  RowIter LastRow = Rows.begin() + Seq.LastRowIndex;
891  assert(FirstRow->Address.Address <= Row.Address.Address &&
892  Row.Address.Address < LastRow[-1].Address.Address);
893  RowIter RowPos = std::upper_bound(FirstRow + 1, LastRow - 1, Row,
895  1;
896  assert(Seq.SectionIndex == RowPos->Address.SectionIndex);
897  return RowPos - Rows.begin();
898 }
899 
901  object::SectionedAddress Address) const {
902 
903  // Search for relocatable addresses
904  uint32_t Result = lookupAddressImpl(Address);
905 
906  if (Result != UnknownRowIndex ||
908  return Result;
909 
910  // Search for absolute addresses
912  return lookupAddressImpl(Address);
913 }
914 
915 uint32_t DWARFDebugLine::LineTable::lookupAddressImpl(
916  object::SectionedAddress Address) const {
917  // First, find an instruction sequence containing the given address.
919  Sequence.SectionIndex = Address.SectionIndex;
920  Sequence.HighPC = Address.Address;
921  SequenceIter It = llvm::upper_bound(Sequences, Sequence,
923  if (It == Sequences.end() || It->SectionIndex != Address.SectionIndex)
924  return UnknownRowIndex;
925  return findRowInSeq(*It, Address);
926 }
927 
929  object::SectionedAddress Address, uint64_t Size,
930  std::vector<uint32_t> &Result) const {
931 
932  // Search for relocatable addresses
933  if (lookupAddressRangeImpl(Address, Size, Result))
934  return true;
935 
937  return false;
938 
939  // Search for absolute addresses
941  return lookupAddressRangeImpl(Address, Size, Result);
942 }
943 
944 bool DWARFDebugLine::LineTable::lookupAddressRangeImpl(
945  object::SectionedAddress Address, uint64_t Size,
946  std::vector<uint32_t> &Result) const {
947  if (Sequences.empty())
948  return false;
949  uint64_t EndAddr = Address.Address + Size;
950  // First, find an instruction sequence containing the given address.
952  Sequence.SectionIndex = Address.SectionIndex;
953  Sequence.HighPC = Address.Address;
954  SequenceIter LastSeq = Sequences.end();
956  Sequences, Sequence, DWARFDebugLine::Sequence::orderByHighPC);
957  if (SeqPos == LastSeq || !SeqPos->containsPC(Address))
958  return false;
959 
960  SequenceIter StartPos = SeqPos;
961 
962  // Add the rows from the first sequence to the vector, starting with the
963  // index we just calculated
964 
965  while (SeqPos != LastSeq && SeqPos->LowPC < EndAddr) {
966  const DWARFDebugLine::Sequence &CurSeq = *SeqPos;
967  // For the first sequence, we need to find which row in the sequence is the
968  // first in our range.
969  uint32_t FirstRowIndex = CurSeq.FirstRowIndex;
970  if (SeqPos == StartPos)
971  FirstRowIndex = findRowInSeq(CurSeq, Address);
972 
973  // Figure out the last row in the range.
974  uint32_t LastRowIndex =
975  findRowInSeq(CurSeq, {EndAddr - 1, Address.SectionIndex});
976  if (LastRowIndex == UnknownRowIndex)
977  LastRowIndex = CurSeq.LastRowIndex - 1;
978 
979  assert(FirstRowIndex != UnknownRowIndex);
980  assert(LastRowIndex != UnknownRowIndex);
981 
982  for (uint32_t I = FirstRowIndex; I <= LastRowIndex; ++I) {
983  Result.push_back(I);
984  }
985 
986  ++SeqPos;
987  }
988 
989  return true;
990 }
991 
992 Optional<StringRef> DWARFDebugLine::LineTable::getSourceByIndex(uint64_t FileIndex,
993  FileLineInfoKind Kind) const {
994  if (Kind == FileLineInfoKind::None || !Prologue.hasFileAtIndex(FileIndex))
995  return None;
996  const FileNameEntry &Entry = Prologue.getFileNameEntry(FileIndex);
997  if (Optional<const char *> source = Entry.Source.getAsCString())
998  return StringRef(*source);
999  return None;
1000 }
1001 
1002 static bool isPathAbsoluteOnWindowsOrPosix(const Twine &Path) {
1003  // Debug info can contain paths from any OS, not necessarily
1004  // an OS we're currently running on. Moreover different compilation units can
1005  // be compiled on different operating systems and linked together later.
1008 }
1009 
1011  StringRef CompDir,
1012  FileLineInfoKind Kind,
1013  std::string &Result) const {
1014  if (Kind == FileLineInfoKind::None || !hasFileAtIndex(FileIndex))
1015  return false;
1016  const FileNameEntry &Entry = getFileNameEntry(FileIndex);
1017  StringRef FileName = Entry.Name.getAsCString().getValue();
1018  if (Kind != FileLineInfoKind::AbsoluteFilePath ||
1019  isPathAbsoluteOnWindowsOrPosix(FileName)) {
1020  Result = FileName;
1021  return true;
1022  }
1023 
1024  SmallString<16> FilePath;
1025  StringRef IncludeDir;
1026  // Be defensive about the contents of Entry.
1027  if (getVersion() >= 5) {
1028  if (Entry.DirIdx < IncludeDirectories.size())
1029  IncludeDir = IncludeDirectories[Entry.DirIdx].getAsCString().getValue();
1030  } else {
1031  if (0 < Entry.DirIdx && Entry.DirIdx <= IncludeDirectories.size())
1032  IncludeDir =
1033  IncludeDirectories[Entry.DirIdx - 1].getAsCString().getValue();
1034 
1035  // We may still need to append compilation directory of compile unit.
1036  // We know that FileName is not absolute, the only way to have an
1037  // absolute path at this point would be if IncludeDir is absolute.
1038  if (!CompDir.empty() && !isPathAbsoluteOnWindowsOrPosix(IncludeDir))
1039  sys::path::append(FilePath, CompDir);
1040  }
1041 
1042  // sys::path::append skips empty strings.
1043  sys::path::append(FilePath, IncludeDir, FileName);
1044  Result = FilePath.str();
1045  return true;
1046 }
1047 
1049  object::SectionedAddress Address, const char *CompDir,
1050  FileLineInfoKind Kind, DILineInfo &Result) const {
1051  // Get the index of row we're looking for in the line table.
1052  uint32_t RowIndex = lookupAddress(Address);
1053  if (RowIndex == -1U)
1054  return false;
1055  // Take file number and line/column from the row.
1056  const auto &Row = Rows[RowIndex];
1057  if (!getFileNameByIndex(Row.File, CompDir, Kind, Result.FileName))
1058  return false;
1059  Result.Line = Row.Line;
1060  Result.Column = Row.Column;
1061  Result.Discriminator = Row.Discriminator;
1062  Result.Source = getSourceByIndex(Row.File, Kind);
1063  return true;
1064 }
1065 
1066 // We want to supply the Unit associated with a .debug_line[.dwo] table when
1067 // we dump it, if possible, but still dump the table even if there isn't a Unit.
1068 // Therefore, collect up handles on all the Units that point into the
1069 // line-table section.
1074  for (const auto &CU : CUs)
1075  if (auto CUDIE = CU->getUnitDIE())
1076  if (auto StmtOffset = toSectionOffset(CUDIE.find(DW_AT_stmt_list)))
1077  LineToUnit.insert(std::make_pair(*StmtOffset, &*CU));
1078  for (const auto &TU : TUs)
1079  if (auto TUDIE = TU->getUnitDIE())
1080  if (auto StmtOffset = toSectionOffset(TUDIE.find(DW_AT_stmt_list)))
1081  LineToUnit.insert(std::make_pair(*StmtOffset, &*TU));
1082  return LineToUnit;
1083 }
1084 
1086  const DWARFContext &C,
1087  cu_range CUs, tu_range TUs)
1088  : DebugLineData(Data), Context(C) {
1089  LineToUnit = buildLineToUnitMap(CUs, TUs);
1090  if (!DebugLineData.isValidOffset(Offset))
1091  Done = true;
1092 }
1093 
1095  return TotalLength == 0xffffffff || TotalLength < 0xfffffff0;
1096 }
1097 
1099  function_ref<void(Error)> RecoverableErrorCallback,
1100  function_ref<void(Error)> UnrecoverableErrorCallback, raw_ostream *OS) {
1101  assert(DebugLineData.isValidOffset(Offset) &&
1102  "parsing should have terminated");
1103  DWARFUnit *U = prepareToParse(Offset);
1104  uint32_t OldOffset = Offset;
1105  LineTable LT;
1106  if (Error Err = LT.parse(DebugLineData, &Offset, Context, U,
1107  RecoverableErrorCallback, OS))
1108  UnrecoverableErrorCallback(std::move(Err));
1109  moveToNextTable(OldOffset, LT.Prologue);
1110  return LT;
1111 }
1112 
1114  function_ref<void(Error)> ErrorCallback) {
1115  assert(DebugLineData.isValidOffset(Offset) &&
1116  "parsing should have terminated");
1117  DWARFUnit *U = prepareToParse(Offset);
1118  uint32_t OldOffset = Offset;
1119  LineTable LT;
1120  if (Error Err = LT.Prologue.parse(DebugLineData, &Offset, Context, U))
1121  ErrorCallback(std::move(Err));
1122  moveToNextTable(OldOffset, LT.Prologue);
1123 }
1124 
1125 DWARFUnit *DWARFDebugLine::SectionParser::prepareToParse(uint32_t Offset) {
1126  DWARFUnit *U = nullptr;
1127  auto It = LineToUnit.find(Offset);
1128  if (It != LineToUnit.end())
1129  U = It->second;
1130  DebugLineData.setAddressSize(U ? U->getAddressByteSize() : 0);
1131  return U;
1132 }
1133 
1134 void DWARFDebugLine::SectionParser::moveToNextTable(uint32_t OldOffset,
1135  const Prologue &P) {
1136  // If the length field is not valid, we don't know where the next table is, so
1137  // cannot continue to parse. Mark the parser as done, and leave the Offset
1138  // value as it currently is. This will be the end of the bad length field.
1139  if (!P.totalLengthIsValid()) {
1140  Done = true;
1141  return;
1142  }
1143 
1144  Offset = OldOffset + P.TotalLength + P.sizeofTotalLength();
1145  if (!DebugLineData.isValidOffset(Offset)) {
1146  Done = true;
1147  }
1148 }
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:500
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:424
static bool orderByAddress(const Row &LHS, const Row &RHS)
StringRef LNStandardString(unsigned Standard)
Definition: Dwarf.cpp:413
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:145
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)
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:455
const llvm::DWARFDebugLine::FileNameEntry & getFileNameEntry(uint64_t Index) const
Get DWARF-version aware access to the file name entry at the provided index.
bool lookupAddressRange(object::SectionedAddress Address, uint64_t Size, std::vector< uint32_t > &Result) const
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
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:663
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:283
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
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:167
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.
bool hasFileAtIndex(uint64_t FileIndex) const
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)
static bool orderByHighPC(const Sequence &LHS, const Sequence &RHS)
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
uint64_t getRelocatedValue(uint32_t Size, uint32_t *Off, uint64_t *SectionIndex=nullptr) const
Extracts a value and applies a relocation to the result if one exists for the given offset...
Standard .debug_line state machine structure.
void sort(IteratorTy Start, IteratorTy End)
Definition: STLExtras.h:1122
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:837
bool getFileNameByIndex(uint64_t FileIndex, StringRef CompDir, DILineInfoSpecifier::FileLineInfoKind Kind, std::string &Result) const
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
#define I(x, y, z)
Definition: MD5.cpp:58
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:503
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.
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:245
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
Definition: Error.h:1163
auto upper_bound(R &&Range, T &&Value) -> decltype(adl_begin(Range))
Provide wrappers to std::upper_bound which take ranges instead of having to pass begin/end explicitly...
Definition: STLExtras.h:1303