LLDB  mainline
DWARFUnit.cpp
Go to the documentation of this file.
1 //===-- DWARFUnit.cpp -----------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "DWARFUnit.h"
10 
11 #include "lldb/Core/Module.h"
12 #include "lldb/Symbol/ObjectFile.h"
15 #include "lldb/Utility/Timer.h"
16 #include "llvm/DebugInfo/DWARF/DWARFDebugLoc.h"
17 #include "llvm/Object/Error.h"
18 
19 #include "DWARFCompileUnit.h"
20 #include "DWARFDebugAranges.h"
21 #include "DWARFDebugInfo.h"
22 #include "DWARFTypeUnit.h"
23 #include "LogChannelDWARF.h"
24 #include "SymbolFileDWARFDwo.h"
25 
26 using namespace lldb;
27 using namespace lldb_private;
28 using namespace lldb_private::dwarf;
29 
30 extern int g_verbose;
31 
33  const DWARFUnitHeader &header,
34  const DWARFAbbreviationDeclarationSet &abbrevs,
35  DIERef::Section section, bool is_dwo)
36  : UserID(uid), m_dwarf(dwarf), m_header(header), m_abbrevs(&abbrevs),
37  m_cancel_scopes(false), m_section(section), m_is_dwo(is_dwo),
39 
40 DWARFUnit::~DWARFUnit() = default;
41 
42 // Parses first DIE of a compile unit, excluding DWO.
44  {
45  llvm::sys::ScopedReader lock(m_first_die_mutex);
46  if (m_first_die)
47  return; // Already parsed
48  }
49  llvm::sys::ScopedWriter lock(m_first_die_mutex);
50  if (m_first_die)
51  return; // Already parsed
52 
54  LLDB_SCOPED_TIMERF("%8.8x: DWARFUnit::ExtractUnitDIENoDwoIfNeeded()",
55  GetOffset());
56 
57  // Set the offset to that of the first DIE and calculate the start of the
58  // next compilation unit header.
60 
61  // We are in our compile unit, parse starting at the offset we were told to
62  // parse
63  const DWARFDataExtractor &data = GetData();
64  if (offset < GetNextUnitOffset() &&
65  m_first_die.Extract(data, this, &offset)) {
67  return;
68  }
69 }
70 
71 // Parses first DIE of a compile unit including DWO.
74 
76  return;
77 
79 
80  std::shared_ptr<SymbolFileDWARFDwo> dwo_symbol_file =
82  if (!dwo_symbol_file)
83  return;
84 
85  DWARFUnit *dwo_cu = dwo_symbol_file->GetDWOCompileUnitForHash(m_dwo_id);
86 
87  if (!dwo_cu)
88  return; // Can't fetch the compile unit from the dwo file.
89  dwo_cu->SetUserData(this);
90 
91  DWARFBaseDIE dwo_cu_die = dwo_cu->GetUnitDIEOnly();
92  if (!dwo_cu_die.IsValid())
93  return; // Can't fetch the compile unit DIE from the dwo file.
94 
95  // Here for DWO CU we want to use the address base set in the skeleton unit
96  // (DW_AT_addr_base) if it is available and use the DW_AT_GNU_addr_base
97  // otherwise. We do that because pre-DWARF v5 could use the DW_AT_GNU_*
98  // attributes which were applicable to the DWO units. The corresponding
99  // DW_AT_* attributes standardized in DWARF v5 are also applicable to the
100  // main unit in contrast.
101  if (m_addr_base)
102  dwo_cu->SetAddrBase(*m_addr_base);
103  else if (m_gnu_addr_base)
104  dwo_cu->SetAddrBase(*m_gnu_addr_base);
105 
106  if (GetVersion() <= 4 && m_gnu_ranges_base)
108  else if (dwo_symbol_file->GetDWARFContext()
109  .getOrLoadRngListsData()
110  .GetByteSize() > 0)
111  dwo_cu->SetRangesBase(llvm::DWARFListTableHeader::getHeaderSize(DWARF32));
112 
113  if (GetVersion() >= 5 &&
114  dwo_symbol_file->GetDWARFContext().getOrLoadLocListsData().GetByteSize() >
115  0)
116  dwo_cu->SetLoclistsBase(llvm::DWARFListTableHeader::getHeaderSize(DWARF32));
117 
118  dwo_cu->SetBaseAddress(GetBaseAddress());
119 
120  m_dwo = std::shared_ptr<DWARFUnit>(std::move(dwo_symbol_file), dwo_cu);
121 }
122 
123 // Parses a compile unit and indexes its DIEs if it hasn't already been done.
124 // It will leave this compile unit extracted forever.
126  m_cancel_scopes = true;
127 
128  {
129  llvm::sys::ScopedReader lock(m_die_array_mutex);
130  if (!m_die_array.empty())
131  return; // Already parsed
132  }
133  llvm::sys::ScopedWriter lock(m_die_array_mutex);
134  if (!m_die_array.empty())
135  return; // Already parsed
136 
138 }
139 
140 // Parses a compile unit and indexes its DIEs if it hasn't already been done.
141 // It will clear this compile unit after returned instance gets out of scope,
142 // no other ScopedExtractDIEs instance is running for this compile unit
143 // and no ExtractDIEsIfNeeded() has been executed during this ScopedExtractDIEs
144 // lifetime.
146  ScopedExtractDIEs scoped(*this);
147 
148  {
149  llvm::sys::ScopedReader lock(m_die_array_mutex);
150  if (!m_die_array.empty())
151  return scoped; // Already parsed
152  }
153  llvm::sys::ScopedWriter lock(m_die_array_mutex);
154  if (!m_die_array.empty())
155  return scoped; // Already parsed
156 
157  // Otherwise m_die_array would be already populated.
159 
161  scoped.m_clear_dies = true;
162  return scoped;
163 }
164 
166  m_cu->m_die_array_scoped_mutex.lock_shared();
167 }
168 
170  if (!m_cu)
171  return;
172  m_cu->m_die_array_scoped_mutex.unlock_shared();
173  if (!m_clear_dies || m_cu->m_cancel_scopes)
174  return;
175  // Be sure no other ScopedExtractDIEs is running anymore.
176  llvm::sys::ScopedWriter lock_scoped(m_cu->m_die_array_scoped_mutex);
177  llvm::sys::ScopedWriter lock(m_cu->m_die_array_mutex);
178  if (m_cu->m_cancel_scopes)
179  return;
180  m_cu->ClearDIEsRWLocked();
181 }
182 
184  : m_cu(rhs.m_cu), m_clear_dies(rhs.m_clear_dies) {
185  rhs.m_cu = nullptr;
186 }
187 
190  m_cu = rhs.m_cu;
191  rhs.m_cu = nullptr;
192  m_clear_dies = rhs.m_clear_dies;
193  return *this;
194 }
195 
196 // Parses a compile unit and indexes its DIEs, m_die_array_mutex must be
197 // held R/W and m_die_array must be empty.
199  llvm::sys::ScopedWriter first_die_lock(m_first_die_mutex);
200 
202  LLDB_SCOPED_TIMERF("%8.8x: DWARFUnit::ExtractDIEsIfNeeded()", GetOffset());
203 
204  // Set the offset to that of the first DIE and calculate the start of the
205  // next compilation unit header.
207  lldb::offset_t next_cu_offset = GetNextUnitOffset();
208 
210 
211  uint32_t depth = 0;
212  // We are in our compile unit, parse starting at the offset we were told to
213  // parse
214  const DWARFDataExtractor &data = GetData();
215  std::vector<uint32_t> die_index_stack;
216  die_index_stack.reserve(32);
217  die_index_stack.push_back(0);
218  bool prev_die_had_children = false;
219  while (offset < next_cu_offset && die.Extract(data, this, &offset)) {
220  const bool null_die = die.IsNULL();
221  if (depth == 0) {
222  assert(m_die_array.empty() && "Compile unit DIE already added");
223 
224  // The average bytes per DIE entry has been seen to be around 14-20 so
225  // lets pre-reserve half of that since we are now stripping the NULL
226  // tags.
227 
228  // Only reserve the memory if we are adding children of the main
229  // compile unit DIE. The compile unit DIE is always the first entry, so
230  // if our size is 1, then we are adding the first compile unit child
231  // DIE and should reserve the memory.
232  m_die_array.reserve(GetDebugInfoSize() / 24);
233  m_die_array.push_back(die);
234 
235  if (!m_first_die)
236  AddUnitDIE(m_die_array.front());
237 
238  // With -fsplit-dwarf-inlining, clang will emit non-empty skeleton compile
239  // units. We are not able to access these DIE *and* the dwo file
240  // simultaneously. We also don't need to do that as the dwo file will
241  // contain a superset of information. So, we don't even attempt to parse
242  // any remaining DIEs.
243  if (m_dwo) {
244  m_die_array.front().SetHasChildren(false);
245  break;
246  }
247 
248  } else {
249  if (null_die) {
250  if (prev_die_had_children) {
251  // This will only happen if a DIE says is has children but all it
252  // contains is a NULL tag. Since we are removing the NULL DIEs from
253  // the list (saves up to 25% in C++ code), we need a way to let the
254  // DIE know that it actually doesn't have children.
255  if (!m_die_array.empty())
256  m_die_array.back().SetHasChildren(false);
257  }
258  } else {
259  die.SetParentIndex(m_die_array.size() - die_index_stack[depth - 1]);
260 
261  if (die_index_stack.back())
262  m_die_array[die_index_stack.back()].SetSiblingIndex(
263  m_die_array.size() - die_index_stack.back());
264 
265  // Only push the DIE if it isn't a NULL DIE
266  m_die_array.push_back(die);
267  }
268  }
269 
270  if (null_die) {
271  // NULL DIE.
272  if (!die_index_stack.empty())
273  die_index_stack.pop_back();
274 
275  if (depth > 0)
276  --depth;
277  prev_die_had_children = false;
278  } else {
279  die_index_stack.back() = m_die_array.size() - 1;
280  // Normal DIE
281  const bool die_has_children = die.HasChildren();
282  if (die_has_children) {
283  die_index_stack.push_back(0);
284  ++depth;
285  }
286  prev_die_had_children = die_has_children;
287  }
288 
289  if (depth == 0)
290  break; // We are done with this compile unit!
291  }
292 
293  if (!m_die_array.empty()) {
294  // The last die cannot have children (if it did, it wouldn't be the last one).
295  // This only makes a difference for malformed dwarf that does not have a
296  // terminating null die.
297  m_die_array.back().SetHasChildren(false);
298 
299  if (m_first_die) {
300  // Only needed for the assertion.
301  m_first_die.SetHasChildren(m_die_array.front().HasChildren());
302  lldbassert(m_first_die == m_die_array.front());
303  }
304  m_first_die = m_die_array.front();
305  }
306 
307  m_die_array.shrink_to_fit();
308 
309  if (m_dwo)
310  m_dwo->ExtractDIEsIfNeeded();
311 }
312 
313 // This is used when a split dwarf is enabled.
314 // A skeleton compilation unit may contain the DW_AT_str_offsets_base attribute
315 // that points to the first string offset of the CU contribution to the
316 // .debug_str_offsets. At the same time, the corresponding split debug unit also
317 // may use DW_FORM_strx* forms pointing to its own .debug_str_offsets.dwo and
318 // for that case, we should find the offset (skip the section header).
320  lldb::offset_t baseOffset = 0;
321 
322  if (const llvm::DWARFUnitIndex::Entry *entry = m_header.GetIndexEntry()) {
323  if (const auto *contribution =
324  entry->getContribution(llvm::DW_SECT_STR_OFFSETS))
325  baseOffset = contribution->Offset;
326  else
327  return;
328  }
329 
330  if (GetVersion() >= 5) {
331  const DWARFDataExtractor &strOffsets =
333  uint64_t length = strOffsets.GetU32(&baseOffset);
334  if (length == 0xffffffff)
335  length = strOffsets.GetU64(&baseOffset);
336 
337  // Check version.
338  if (strOffsets.GetU16(&baseOffset) < 5)
339  return;
340 
341  // Skip padding.
342  baseOffset += 2;
343  }
344 
345  SetStrOffsetsBase(baseOffset);
346 }
347 
350  return m_dwo_id;
351 }
352 
353 // m_die_array_mutex must be already held as read/write.
355  DWARFAttributes attributes;
356  size_t num_attributes = cu_die.GetAttributes(this, attributes);
357 
358  // Extract DW_AT_addr_base first, as other attributes may need it.
359  for (size_t i = 0; i < num_attributes; ++i) {
360  if (attributes.AttributeAtIndex(i) != DW_AT_addr_base)
361  continue;
362  DWARFFormValue form_value;
363  if (attributes.ExtractFormValueAtIndex(i, form_value)) {
364  SetAddrBase(form_value.Unsigned());
365  break;
366  }
367  }
368 
369  for (size_t i = 0; i < num_attributes; ++i) {
370  dw_attr_t attr = attributes.AttributeAtIndex(i);
371  DWARFFormValue form_value;
372  if (!attributes.ExtractFormValueAtIndex(i, form_value))
373  continue;
374  switch (attr) {
375  case DW_AT_loclists_base:
376  SetLoclistsBase(form_value.Unsigned());
377  break;
378  case DW_AT_rnglists_base:
379  SetRangesBase(form_value.Unsigned());
380  break;
381  case DW_AT_str_offsets_base:
382  SetStrOffsetsBase(form_value.Unsigned());
383  break;
384  case DW_AT_low_pc:
385  SetBaseAddress(form_value.Address());
386  break;
387  case DW_AT_entry_pc:
388  // If the value was already set by DW_AT_low_pc, don't update it.
390  SetBaseAddress(form_value.Address());
391  break;
392  case DW_AT_stmt_list:
393  m_line_table_offset = form_value.Unsigned();
394  break;
395  case DW_AT_GNU_addr_base:
396  m_gnu_addr_base = form_value.Unsigned();
397  break;
398  case DW_AT_GNU_ranges_base:
399  m_gnu_ranges_base = form_value.Unsigned();
400  break;
401  case DW_AT_GNU_dwo_id:
402  m_dwo_id = form_value.Unsigned();
403  break;
404  }
405  }
406 
407  if (m_is_dwo) {
410  return;
411  }
412 }
413 
416 }
417 
419  return m_abbrevs;
420 }
421 
424 }
425 
428  return m_line_table_offset;
429 }
430 
431 void DWARFUnit::SetAddrBase(dw_addr_t addr_base) { m_addr_base = addr_base; }
432 
433 // Parse the rangelist table header, including the optional array of offsets
434 // following it (DWARF v5 and later).
435 template <typename ListTableType>
436 static llvm::Expected<ListTableType>
437 ParseListTableHeader(const llvm::DWARFDataExtractor &data, uint64_t offset,
438  DwarfFormat format) {
439  // We are expected to be called with Offset 0 or pointing just past the table
440  // header. Correct Offset in the latter case so that it points to the start
441  // of the header.
442  if (offset == 0) {
443  // This means DW_AT_rnglists_base is missing and therefore DW_FORM_rnglistx
444  // cannot be handled. Returning a default-constructed ListTableType allows
445  // DW_FORM_sec_offset to be supported.
446  return ListTableType();
447  }
448 
449  uint64_t HeaderSize = llvm::DWARFListTableHeader::getHeaderSize(format);
450  if (offset < HeaderSize)
451  return llvm::createStringError(std::errc::invalid_argument,
452  "did not detect a valid"
453  " list table with base = 0x%" PRIx64 "\n",
454  offset);
455  offset -= HeaderSize;
456  ListTableType Table;
457  if (llvm::Error E = Table.extractHeaderAndOffsets(data, &offset))
458  return std::move(E);
459  return Table;
460 }
461 
463  uint64_t offset = 0;
464  if (const llvm::DWARFUnitIndex::Entry *entry = m_header.GetIndexEntry()) {
465  const auto *contribution = entry->getContribution(llvm::DW_SECT_LOCLISTS);
466  if (!contribution) {
467  GetSymbolFileDWARF().GetObjectFile()->GetModule()->ReportError(
468  "Failed to find location list contribution for CU with DWO Id "
469  "0x%" PRIx64,
470  this->GetDWOId());
471  return;
472  }
473  offset += contribution->Offset;
474  }
475  m_loclists_base = loclists_base;
476 
477  uint64_t header_size = llvm::DWARFListTableHeader::getHeaderSize(DWARF32);
478  if (loclists_base < header_size)
479  return;
480 
481  m_loclist_table_header.emplace(".debug_loclists", "locations");
482  offset += loclists_base - header_size;
483  if (llvm::Error E = m_loclist_table_header->extract(
485  &offset)) {
486  GetSymbolFileDWARF().GetObjectFile()->GetModule()->ReportError(
487  "Failed to extract location list table at offset 0x%" PRIx64
488  " (location list base: 0x%" PRIx64 "): %s",
489  offset, loclists_base, toString(std::move(E)).c_str());
490  }
491 }
492 
493 std::unique_ptr<llvm::DWARFLocationTable>
495  llvm::DWARFDataExtractor llvm_data(
496  data.GetData(), data.GetByteOrder() == lldb::eByteOrderLittle,
497  data.GetAddressByteSize());
498 
499  if (m_is_dwo || GetVersion() >= 5)
500  return std::make_unique<llvm::DWARFDebugLoclists>(llvm_data, GetVersion());
501  return std::make_unique<llvm::DWARFDebugLoc>(llvm_data);
502 }
503 
506  const DWARFDataExtractor &data =
507  GetVersion() >= 5 ? Ctx.getOrLoadLocListsData() : Ctx.getOrLoadLocData();
508  if (const llvm::DWARFUnitIndex::Entry *entry = m_header.GetIndexEntry()) {
509  if (const auto *contribution = entry->getContribution(
510  GetVersion() >= 5 ? llvm::DW_SECT_LOCLISTS : llvm::DW_SECT_EXT_LOC))
511  return DWARFDataExtractor(data, contribution->Offset,
512  contribution->Length);
513  return DWARFDataExtractor();
514  }
515  return data;
516 }
517 
520  const DWARFDataExtractor &data = Ctx.getOrLoadRngListsData();
521  if (const llvm::DWARFUnitIndex::Entry *entry = m_header.GetIndexEntry()) {
522  if (const auto *contribution =
523  entry->getContribution(llvm::DW_SECT_RNGLISTS))
524  return DWARFDataExtractor(data, contribution->Offset,
525  contribution->Length);
526  GetSymbolFileDWARF().GetObjectFile()->GetModule()->ReportError(
527  "Failed to find range list contribution for CU with signature "
528  "0x%" PRIx64,
529  entry->getSignature());
530 
531  return DWARFDataExtractor();
532  }
533  return data;
534 }
535 
538 
539  m_ranges_base = ranges_base;
540 }
541 
542 const llvm::Optional<llvm::DWARFDebugRnglistTable> &
544  if (GetVersion() >= 5 && !m_rnglist_table_done) {
545  m_rnglist_table_done = true;
546  if (auto table_or_error =
547  ParseListTableHeader<llvm::DWARFDebugRnglistTable>(
548  GetRnglistData().GetAsLLVM(), m_ranges_base, DWARF32))
549  m_rnglist_table = std::move(table_or_error.get());
550  else
551  GetSymbolFileDWARF().GetObjectFile()->GetModule()->ReportError(
552  "Failed to extract range list table at offset 0x%" PRIx64 ": %s",
553  m_ranges_base, toString(table_or_error.takeError()).c_str());
554  }
555  return m_rnglist_table;
556 }
557 
558 // This function is called only for DW_FORM_rnglistx.
559 llvm::Expected<uint64_t> DWARFUnit::GetRnglistOffset(uint32_t Index) {
560  if (!GetRnglistTable())
561  return llvm::createStringError(std::errc::invalid_argument,
562  "missing or invalid range list table");
563  if (!m_ranges_base)
564  return llvm::createStringError(std::errc::invalid_argument,
565  "DW_FORM_rnglistx cannot be used without "
566  "DW_AT_rnglists_base for CU at 0x%8.8x",
567  GetOffset());
568  if (llvm::Optional<uint64_t> off = GetRnglistTable()->getOffsetEntry(
569  GetRnglistData().GetAsLLVM(), Index))
570  return *off + m_ranges_base;
571  return llvm::createStringError(
572  std::errc::invalid_argument,
573  "invalid range list table index %u; OffsetEntryCount is %u, "
574  "DW_AT_rnglists_base is %" PRIu64,
575  Index, GetRnglistTable()->getOffsetEntryCount(), m_ranges_base);
576 }
577 
579  m_str_offsets_base = str_offsets_base;
580 }
581 
582 // It may be called only with m_die_array_mutex held R/W.
584  m_die_array.clear();
585  m_die_array.shrink_to_fit();
586 
587  if (m_dwo)
588  m_dwo->ClearDIEsRWLocked();
589 }
590 
592  return m_dwarf.GetObjectFile()->GetByteOrder();
593 }
594 
595 void DWARFUnit::SetBaseAddress(dw_addr_t base_addr) { m_base_addr = base_addr; }
596 
597 // Compare function DWARFDebugAranges::Range structures
598 static bool CompareDIEOffset(const DWARFDebugInfoEntry &die,
599  const dw_offset_t die_offset) {
600  return die.GetOffset() < die_offset;
601 }
602 
603 // GetDIE()
604 //
605 // Get the DIE (Debug Information Entry) with the specified offset by first
606 // checking if the DIE is contained within this compile unit and grabbing the
607 // DIE from this compile unit. Otherwise we grab the DIE from the DWARF file.
608 DWARFDIE
610  if (die_offset == DW_INVALID_OFFSET)
611  return DWARFDIE(); // Not found
612 
613  if (!ContainsDIEOffset(die_offset)) {
614  GetSymbolFileDWARF().GetObjectFile()->GetModule()->ReportError(
615  "GetDIE for DIE 0x%" PRIx32 " is outside of its CU 0x%" PRIx32,
616  die_offset, GetOffset());
617  return DWARFDIE(); // Not found
618  }
619 
623  lower_bound(m_die_array.cbegin(), end, die_offset, CompareDIEOffset);
624 
625  if (pos != end && die_offset == (*pos).GetOffset())
626  return DWARFDIE(this, &(*pos));
627  return DWARFDIE(); // Not found
628 }
629 
632  if (m_dwo)
633  return *m_dwo;
634  return *this;
635 }
636 
638  if (cu)
639  return cu->GetAddressByteSize();
641 }
642 
643 uint8_t DWARFUnit::GetDefaultAddressSize() { return 4; }
644 
645 void *DWARFUnit::GetUserData() const { return m_user_data; }
646 
647 void DWARFUnit::SetUserData(void *d) { m_user_data = d; }
648 
650  return GetProducer() != eProducerLLVMGCC;
651 }
652 
654  // llvm-gcc makes completely invalid decl file attributes and won't ever be
655  // fixed, so we need to know to ignore these.
656  return GetProducer() == eProducerLLVMGCC;
657 }
658 
660  if (GetProducer() == eProducerClang)
661  return GetProducerVersion() >= llvm::VersionTuple(425, 0, 13);
662  // Assume all other compilers didn't have incorrect ObjC bitfield info.
663  return true;
664 }
665 
668  const DWARFDebugInfoEntry *die = GetUnitDIEPtrOnly();
669  if (!die)
670  return;
671 
672  llvm::StringRef producer(
673  die->GetAttributeValueAsString(this, DW_AT_producer, nullptr));
674  if (producer.empty())
675  return;
676 
677  static const RegularExpression g_swiftlang_version_regex(
678  llvm::StringRef(R"(swiftlang-([0-9]+\.[0-9]+\.[0-9]+(\.[0-9]+)?))"));
679  static const RegularExpression g_clang_version_regex(
680  llvm::StringRef(R"(clang-([0-9]+\.[0-9]+\.[0-9]+(\.[0-9]+)?))"));
681  static const RegularExpression g_llvm_gcc_regex(
682  llvm::StringRef(R"(4\.[012]\.[01] )"
683  R"(\(Based on Apple Inc\. build [0-9]+\) )"
684  R"(\(LLVM build [\.0-9]+\)$)"));
685 
686  llvm::SmallVector<llvm::StringRef, 3> matches;
687  if (g_swiftlang_version_regex.Execute(producer, &matches)) {
688  m_producer_version.tryParse(matches[1]);
690  } else if (producer.contains("clang")) {
691  if (g_clang_version_regex.Execute(producer, &matches))
692  m_producer_version.tryParse(matches[1]);
694  } else if (producer.contains("GNU")) {
696  } else if (g_llvm_gcc_regex.Execute(producer)) {
698  }
699 }
700 
704  return m_producer;
705 }
706 
707 llvm::VersionTuple DWARFUnit::GetProducerVersion() {
708  if (m_producer_version.empty())
710  return m_producer_version;
711 }
712 
714  if (m_language_type)
715  return *m_language_type;
716 
717  const DWARFDebugInfoEntry *die = GetUnitDIEPtrOnly();
718  if (!die)
719  m_language_type = 0;
720  else
721  m_language_type = die->GetAttributeValueAsUnsigned(this, DW_AT_language, 0);
722  return *m_language_type;
723 }
724 
727  const DWARFDebugInfoEntry *die = GetUnitDIEPtrOnly();
728  if (die) {
730  if (die->GetAttributeValueAsUnsigned(this, DW_AT_APPLE_optimized, 0) ==
731  1) {
733  }
734  }
735  }
736  return m_is_optimized == eLazyBoolYes;
737 }
738 
740  if (!m_comp_dir)
742  return m_comp_dir->GetPathStyle();
743 }
744 
746  if (!m_comp_dir)
748  return *m_comp_dir;
749 }
750 
752  if (!m_file_spec)
754  return *m_file_spec;
755 }
756 
757 FileSpec DWARFUnit::GetFile(size_t file_idx) {
758  return m_dwarf.GetFile(*this, file_idx);
759 }
760 
761 // DWARF2/3 suggests the form hostname:pathname for compilation directory.
762 // Remove the host part if present.
763 static llvm::StringRef
764 removeHostnameFromPathname(llvm::StringRef path_from_dwarf) {
765  if (!path_from_dwarf.contains(':'))
766  return path_from_dwarf;
767  llvm::StringRef host, path;
768  std::tie(host, path) = path_from_dwarf.split(':');
769 
770  if (host.contains('/'))
771  return path_from_dwarf;
772 
773  // check whether we have a windows path, and so the first character is a
774  // drive-letter not a hostname.
775  if (host.size() == 1 && llvm::isAlpha(host[0]) &&
776  (path.startswith("\\") || path.startswith("/")))
777  return path_from_dwarf;
778 
779  return path;
780 }
781 
783  m_comp_dir = FileSpec();
784  const DWARFDebugInfoEntry *die = GetUnitDIEPtrOnly();
785  if (!die)
786  return;
787 
788  llvm::StringRef comp_dir = removeHostnameFromPathname(
789  die->GetAttributeValueAsString(this, DW_AT_comp_dir, nullptr));
790  if (!comp_dir.empty()) {
791  FileSpec::Style comp_dir_style =
792  FileSpec::GuessPathStyle(comp_dir).value_or(FileSpec::Style::native);
793  m_comp_dir = FileSpec(comp_dir, comp_dir_style);
794  } else {
795  // Try to detect the style based on the DW_AT_name attribute, but just store
796  // the detected style in the m_comp_dir field.
797  const char *name =
798  die->GetAttributeValueAsString(this, DW_AT_name, nullptr);
800  "", FileSpec::GuessPathStyle(name).value_or(FileSpec::Style::native));
801  }
802 }
803 
805  m_file_spec = FileSpec();
806  const DWARFDebugInfoEntry *die = GetUnitDIEPtrOnly();
807  if (!die)
808  return;
809 
810  m_file_spec =
811  FileSpec(die->GetAttributeValueAsString(this, DW_AT_name, nullptr),
812  GetPathStyle());
813 
814  if (m_file_spec->IsRelative())
815  m_file_spec->MakeAbsolute(GetCompilationDirectory());
816 }
817 
820  if (m_dwo)
821  return &llvm::cast<SymbolFileDWARFDwo>(m_dwo->GetSymbolFileDWARF());
822  return nullptr;
823 }
824 
826  if (m_func_aranges_up == nullptr) {
827  m_func_aranges_up = std::make_unique<DWARFDebugAranges>();
828  const DWARFDebugInfoEntry *die = DIEPtr();
829  if (die)
831 
832  if (m_dwo) {
833  const DWARFDebugInfoEntry *dwo_die = m_dwo->DIEPtr();
834  if (dwo_die)
835  dwo_die->BuildFunctionAddressRangeTable(m_dwo.get(),
836  m_func_aranges_up.get());
837  }
838 
839  const bool minimize = false;
840  m_func_aranges_up->Sort(minimize);
841  }
842  return *m_func_aranges_up;
843 }
844 
845 llvm::Expected<DWARFUnitHeader>
847  DIERef::Section section,
849  lldb::offset_t *offset_ptr) {
850  DWARFUnitHeader header;
851  header.m_offset = *offset_ptr;
852  header.m_length = data.GetDWARFInitialLength(offset_ptr);
853  header.m_version = data.GetU16(offset_ptr);
854  if (header.m_version == 5) {
855  header.m_unit_type = data.GetU8(offset_ptr);
856  header.m_addr_size = data.GetU8(offset_ptr);
857  header.m_abbr_offset = data.GetDWARFOffset(offset_ptr);
858  if (header.m_unit_type == llvm::dwarf::DW_UT_skeleton ||
859  header.m_unit_type == llvm::dwarf::DW_UT_split_compile)
860  header.m_dwo_id = data.GetU64(offset_ptr);
861  } else {
862  header.m_abbr_offset = data.GetDWARFOffset(offset_ptr);
863  header.m_addr_size = data.GetU8(offset_ptr);
864  header.m_unit_type =
865  section == DIERef::Section::DebugTypes ? DW_UT_type : DW_UT_compile;
866  }
867 
868  if (header.IsTypeUnit()) {
869  header.m_type_hash = data.GetU64(offset_ptr);
870  header.m_type_offset = data.GetDWARFOffset(offset_ptr);
871  }
872 
873  if (context.isDwo()) {
874  const llvm::DWARFUnitIndex *Index;
875  if (header.IsTypeUnit()) {
876  Index = &context.GetAsLLVM().getTUIndex();
877  if (*Index)
878  header.m_index_entry = Index->getFromHash(header.m_type_hash);
879  } else {
880  Index = &context.GetAsLLVM().getCUIndex();
881  if (*Index && header.m_version >= 5)
882  header.m_index_entry = Index->getFromHash(header.m_dwo_id);
883  }
884  if (!header.m_index_entry)
885  header.m_index_entry = Index->getFromOffset(header.m_offset);
886  }
887 
888  if (header.m_index_entry) {
889  if (header.m_abbr_offset) {
890  return llvm::createStringError(
891  llvm::inconvertibleErrorCode(),
892  "Package unit with a non-zero abbreviation offset");
893  }
894  auto *unit_contrib = header.m_index_entry->getContribution();
895  if (!unit_contrib || unit_contrib->Length != header.m_length + 4) {
896  return llvm::createStringError(llvm::inconvertibleErrorCode(),
897  "Inconsistent DWARF package unit index");
898  }
899  auto *abbr_entry =
900  header.m_index_entry->getContribution(llvm::DW_SECT_ABBREV);
901  if (!abbr_entry) {
902  return llvm::createStringError(
903  llvm::inconvertibleErrorCode(),
904  "DWARF package index missing abbreviation column");
905  }
906  header.m_abbr_offset = abbr_entry->Offset;
907  }
908 
909  bool length_OK = data.ValidOffset(header.GetNextUnitOffset() - 1);
910  bool version_OK = SymbolFileDWARF::SupportedVersion(header.m_version);
911  bool addr_size_OK = (header.m_addr_size == 4) || (header.m_addr_size == 8);
912  bool type_offset_OK =
913  !header.IsTypeUnit() || (header.m_type_offset <= header.GetLength());
914 
915  if (!length_OK)
916  return llvm::make_error<llvm::object::GenericBinaryError>(
917  "Invalid unit length");
918  if (!version_OK)
919  return llvm::make_error<llvm::object::GenericBinaryError>(
920  "Unsupported unit version");
921  if (!addr_size_OK)
922  return llvm::make_error<llvm::object::GenericBinaryError>(
923  "Invalid unit address size");
924  if (!type_offset_OK)
925  return llvm::make_error<llvm::object::GenericBinaryError>(
926  "Type offset out of range");
927 
928  return header;
929 }
930 
931 llvm::Expected<DWARFUnitSP>
933  const DWARFDataExtractor &debug_info,
934  DIERef::Section section, lldb::offset_t *offset_ptr) {
935  assert(debug_info.ValidOffset(*offset_ptr));
936 
937  auto expected_header = DWARFUnitHeader::extract(
938  debug_info, section, dwarf.GetDWARFContext(), offset_ptr);
939  if (!expected_header)
940  return expected_header.takeError();
941 
942  const DWARFDebugAbbrev *abbr = dwarf.DebugAbbrev();
943  if (!abbr)
944  return llvm::make_error<llvm::object::GenericBinaryError>(
945  "No debug_abbrev data");
946 
947  bool abbr_offset_OK =
948  dwarf.GetDWARFContext().getOrLoadAbbrevData().ValidOffset(
949  expected_header->GetAbbrOffset());
950  if (!abbr_offset_OK)
951  return llvm::make_error<llvm::object::GenericBinaryError>(
952  "Abbreviation offset for unit is not valid");
953 
954  const DWARFAbbreviationDeclarationSet *abbrevs =
955  abbr->GetAbbreviationDeclarationSet(expected_header->GetAbbrOffset());
956  if (!abbrevs)
957  return llvm::make_error<llvm::object::GenericBinaryError>(
958  "No abbrev exists at the specified offset.");
959 
960  bool is_dwo = dwarf.GetDWARFContext().isDwo();
961  if (expected_header->IsTypeUnit())
962  return DWARFUnitSP(new DWARFTypeUnit(dwarf, uid, *expected_header, *abbrevs,
963  section, is_dwo));
964  return DWARFUnitSP(new DWARFCompileUnit(dwarf, uid, *expected_header,
965  *abbrevs, section, is_dwo));
966 }
967 
969  return m_section == DIERef::Section::DebugTypes
972 }
973 
975  switch (m_header.GetUnitType()) {
976  case llvm::dwarf::DW_UT_compile:
977  case llvm::dwarf::DW_UT_partial:
978  return GetVersion() < 5 ? 11 : 12;
979  case llvm::dwarf::DW_UT_skeleton:
980  case llvm::dwarf::DW_UT_split_compile:
981  return 20;
982  case llvm::dwarf::DW_UT_type:
983  case llvm::dwarf::DW_UT_split_type:
984  return GetVersion() < 5 ? 23 : 24;
985  }
986  llvm_unreachable("invalid UnitType.");
987 }
988 
989 llvm::Optional<uint64_t>
991  offset_t offset = GetStrOffsetsBase() + index * 4;
993 }
994 
995 llvm::Expected<DWARFRangeList>
997  if (GetVersion() <= 4) {
998  const DWARFDebugRanges *debug_ranges = m_dwarf.GetDebugRanges();
999  if (!debug_ranges)
1000  return llvm::make_error<llvm::object::GenericBinaryError>(
1001  "No debug_ranges section");
1002  DWARFRangeList ranges;
1003  debug_ranges->FindRanges(this, offset, ranges);
1004  return ranges;
1005  }
1006 
1007  if (!GetRnglistTable())
1008  return llvm::createStringError(std::errc::invalid_argument,
1009  "missing or invalid range list table");
1010 
1011  llvm::DWARFDataExtractor data = GetRnglistData().GetAsLLVM();
1012 
1013  // As DW_AT_rnglists_base may be missing we need to call setAddressSize.
1014  data.setAddressSize(m_header.GetAddressByteSize());
1015  auto range_list_or_error = GetRnglistTable()->findList(data, offset);
1016  if (!range_list_or_error)
1017  return range_list_or_error.takeError();
1018 
1019  llvm::Expected<llvm::DWARFAddressRangesVector> llvm_ranges =
1020  range_list_or_error->getAbsoluteRanges(
1021  llvm::object::SectionedAddress{GetBaseAddress()},
1022  GetAddressByteSize(), [&](uint32_t index) {
1023  uint32_t index_size = GetAddressByteSize();
1024  dw_offset_t addr_base = GetAddrBase();
1025  lldb::offset_t offset = addr_base + index * index_size;
1026  return llvm::object::SectionedAddress{
1028  &offset, index_size)};
1029  });
1030  if (!llvm_ranges)
1031  return llvm_ranges.takeError();
1032 
1033  DWARFRangeList ranges;
1034  for (const llvm::DWARFAddressRange &llvm_range : *llvm_ranges) {
1035  ranges.Append(DWARFRangeList::Entry(llvm_range.LowPC,
1036  llvm_range.HighPC - llvm_range.LowPC));
1037  }
1038  return ranges;
1039 }
1040 
1041 llvm::Expected<DWARFRangeList>
1043  llvm::Expected<uint64_t> maybe_offset = GetRnglistOffset(index);
1044  if (!maybe_offset)
1045  return maybe_offset.takeError();
1046  return FindRnglistFromOffset(*maybe_offset);
1047 }
lldb_private::toString
const char * toString(AppleArm64ExceptionClass EC)
Definition: AppleArm64ExceptionClass.h:38
DWARFUnit::GetRnglistData
lldb_private::DWARFDataExtractor GetRnglistData() const
Definition: DWARFUnit.cpp:518
DWARFUnit::m_producer_version
llvm::VersionTuple m_producer_version
Definition: DWARFUnit.h:313
DWARFUnit::GetRnglistOffset
llvm::Expected< uint64_t > GetRnglistOffset(uint32_t Index)
Return a rangelist's offset based on an index.
Definition: DWARFUnit.cpp:559
DWARFUnit::SetUserData
void SetUserData(void *d)
Definition: DWARFUnit.cpp:647
LLDB_SCOPED_TIMERF
#define LLDB_SCOPED_TIMERF(...)
Definition: Timer.h:86
DWARFCompileUnit.h
DWARFDebugInfoEntry::GetOffset
dw_offset_t GetOffset() const
Definition: DWARFDebugInfoEntry.h:118
lldb_private::RegularExpression
Definition: RegularExpression.h:18
DWARFUnit::GetData
const lldb_private::DWARFDataExtractor & GetData() const
Get the data that contains the DIE information for this unit.
Definition: DWARFUnit.cpp:968
lldb_private::DWARFContext::getOrLoadStrOffsetsData
const DWARFDataExtractor & getOrLoadStrOffsetsData()
Definition: DWARFContext.cpp:115
SymbolFileDWARF::GetFile
lldb_private::FileSpec GetFile(DWARFUnit &unit, size_t file_idx)
Definition: SymbolFileDWARF.cpp:1002
DWARFUnit::m_addr_base
llvm::Optional< dw_addr_t > m_addr_base
Value of DW_AT_addr_base.
Definition: DWARFUnit.h:318
CompareDIEOffset
static bool CompareDIEOffset(const DWARFDebugInfoEntry &die, const dw_offset_t die_offset)
Definition: DWARFUnit.cpp:598
eProducerClang
@ eProducerClang
Definition: DWARFUnit.h:30
DWARFUnit::GetRnglistTable
const llvm::Optional< llvm::DWARFDebugRnglistTable > & GetRnglistTable()
Definition: DWARFUnit.cpp:543
DWARFDebugAranges
Definition: DWARFDebugAranges.h:16
lldb_private::DataExtractor::ValidOffset
bool ValidOffset(lldb::offset_t offset) const
Test the validity of offset.
Definition: DataExtractor.h:956
DWARFUnit::DWARFUnit
DWARFUnit(SymbolFileDWARF &dwarf, lldb::user_id_t uid, const DWARFUnitHeader &header, const DWARFAbbreviationDeclarationSet &abbrevs, DIERef::Section section, bool is_dwo)
Definition: DWARFUnit.cpp:32
DWARFUnit::GetProducer
DWARFProducer GetProducer()
Definition: DWARFUnit.cpp:701
DWARFUnit::ScopedExtractDIEs::m_clear_dies
bool m_clear_dies
Definition: DWARFUnit.h:104
SymbolFileDWARF::GetDWARFContext
lldb_private::DWARFContext & GetDWARFContext()
Definition: SymbolFileDWARF.h:294
DWARFUnit::GetDWOId
uint64_t GetDWOId()
Definition: DWARFUnit.cpp:348
lldb_private::UserID
Definition: UserID.h:31
DWARFTypeUnit
Definition: DWARFTypeUnit.h:15
DWARFFormValue::Address
dw_addr_t Address() const
Definition: DWARFFormValue.cpp:484
DWARFUnitHeader::m_type_hash
uint64_t m_type_hash
Definition: DWARFUnit.h:51
lldb_private::eLazyBoolYes
@ eLazyBoolYes
Definition: lldb-private-enumerations.h:115
DWARFUnit::m_loclists_base
dw_addr_t m_loclists_base
Value of DW_AT_loclists_base.
Definition: DWARFUnit.h:319
lldb_private::ElapsedTime
A class that measures elapsed time in an exception safe way.
Definition: Statistics.h:66
DWARFUnit::GetDwoSymbolFile
SymbolFileDWARFDwo * GetDwoSymbolFile()
Definition: DWARFUnit.cpp:818
DWARFUnit::m_header
DWARFUnitHeader m_header
Definition: DWARFUnit.h:292
Module.h
DWARFUnit::m_ranges_base
dw_addr_t m_ranges_base
Value of DW_AT_rnglists_base.
Definition: DWARFUnit.h:320
DWARFProducer
DWARFProducer
Definition: DWARFUnit.h:28
DWARFUnit::ExtractDIEsRWLocked
void ExtractDIEsRWLocked()
Definition: DWARFUnit.cpp:198
DWARFDebugInfoEntry::HasChildren
bool HasChildren() const
Definition: DWARFDebugInfoEntry.h:120
DWARFDebugRanges::FindRanges
bool FindRanges(const DWARFUnit *cu, dw_offset_t debug_ranges_offset, DWARFRangeList &range_list) const
Definition: DWARFDebugRanges.cpp:111
DWARFUnitHeader::m_version
uint16_t m_version
Definition: DWARFUnit.h:43
lldb_private::DWARFContext::getOrLoadAddrData
const DWARFDataExtractor & getOrLoadAddrData()
Definition: DWARFContext.cpp:63
SymbolFileDWARF
Definition: SymbolFileDWARF.h:59
DWARFUnit::m_comp_dir
llvm::Optional< lldb_private::FileSpec > m_comp_dir
Definition: DWARFUnit.h:316
DWARFUnit::m_rnglist_table_done
bool m_rnglist_table_done
Definition: DWARFUnit.h:330
lldb::offset_t
uint64_t offset_t
Definition: lldb-types.h:87
DWARFUnit::ComputeCompDirAndGuessPathStyle
void ComputeCompDirAndGuessPathStyle()
Definition: DWARFUnit.cpp:782
SymbolFileDWARF::GetDebugRanges
DWARFDebugRanges * GetDebugRanges()
Definition: SymbolFileDWARF.cpp:657
DWARFUnit::m_dwarf
SymbolFileDWARF & m_dwarf
Definition: DWARFUnit.h:290
DWARFUnit::GetDebugInfoSize
size_t GetDebugInfoSize() const
Definition: DWARFUnit.cpp:414
DWARFUnit::ClearDIEsRWLocked
void ClearDIEsRWLocked()
Definition: DWARFUnit.cpp:583
lldb_private::DWARFDataExtractor
Definition: DWARFDataExtractor.h:18
DWARFUnit::extract
static llvm::Expected< DWARFUnitSP > extract(SymbolFileDWARF &dwarf2Data, lldb::user_id_t uid, const lldb_private::DWARFDataExtractor &debug_info, DIERef::Section section, lldb::offset_t *offset_ptr)
Definition: DWARFUnit.cpp:932
DWARFUnit::m_is_optimized
lldb_private::LazyBool m_is_optimized
Definition: DWARFUnit.h:315
DWARFUnit::m_base_addr
dw_addr_t m_base_addr
Definition: DWARFUnit.h:311
DWARFUnitHeader::m_index_entry
const llvm::DWARFUnitIndex::Entry * m_index_entry
Definition: DWARFUnit.h:46
DWARFUnit::GetStrOffsetsBase
dw_addr_t GetStrOffsetsBase() const
Definition: DWARFUnit.h:162
DWARFDebugInfoEntry
DWARFDebugInfoEntry objects assume that they are living in one big vector and do pointer arithmetic o...
Definition: DWARFDebugInfoEntry.h:31
DW_INVALID_OFFSET
#define DW_INVALID_OFFSET
Definition: dwarf.h:37
DWARFUnitHeader::m_offset
dw_offset_t m_offset
Definition: DWARFUnit.h:41
DWARFUnit::FindRnglistFromOffset
llvm::Expected< DWARFRangeList > FindRnglistFromOffset(dw_offset_t offset)
Return a list of address ranges resulting from a (possibly encoded) range list starting at a given of...
Definition: DWARFUnit.cpp:996
lldb_private::DataExtractor::GetU64
uint64_t GetU64(lldb::offset_t *offset_ptr) const
Extract a uint64_t value from *offset_ptr.
Definition: DataExtractor.cpp:474
DWARFUnit::m_first_die
DWARFDebugInfoEntry m_first_die
Definition: DWARFUnit.h:306
DWARFUnit::SetLoclistsBase
void SetLoclistsBase(dw_addr_t loclists_base)
Definition: DWARFUnit.cpp:462
lldb_private::DWARFContext
Definition: DWARFContext.h:20
DWARFAttributes
Definition: DWARFAttribute.h:44
lldb_private::RangeVector::Append
void Append(const Entry &entry)
Definition: RangeMap.h:174
DWARFUnit::GetUnitDIEPtrOnly
const DWARFDebugInfoEntry * GetUnitDIEPtrOnly()
Definition: DWARFUnit.h:270
DWARFAbbreviationDeclarationSet::GetOffset
dw_offset_t GetOffset() const
Definition: DWARFDebugAbbrev.h:35
DWARFDIE
Definition: DWARFDIE.h:16
DWARFUnit::m_dwo
std::shared_ptr< DWARFUnit > m_dwo
Definition: DWARFUnit.h:291
DWARFUnit::GetDWARFLanguageType
uint64_t GetDWARFLanguageType()
Definition: DWARFUnit.cpp:713
lldb_private::FileSpec
Definition: FileSpec.h:56
SymbolFileDWARFDwo.h
DWARFCompileUnit
Definition: DWARFCompileUnit.h:15
eProducerSwift
@ eProducerSwift
Definition: DWARFUnit.h:33
elapsed
static double elapsed(const StatsTimepoint &start, const StatsTimepoint &end)
Definition: Statistics.cpp:36
DWARFUnit::GetAddressByteSize
uint8_t GetAddressByteSize() const
Definition: DWARFUnit.h:157
lldb_private::DWARFContext::GetAsLLVM
llvm::DWARFContext & GetAsLLVM()
Definition: DWARFContext.cpp:126
DWARFUnit::ScopedExtractDIEs
Definition: DWARFUnit.h:101
DWARFUnit::AddUnitDIE
void AddUnitDIE(const DWARFDebugInfoEntry &cu_die)
Definition: DWARFUnit.cpp:354
DWARFUnit
Definition: DWARFUnit.h:83
DWARFUnit::m_abbrevs
const DWARFAbbreviationDeclarationSet * m_abbrevs
Definition: DWARFUnit.h:293
LLDBAssert.h
SymbolFileDWARF::GetDebugInfoParseTimeRef
lldb_private::StatsDuration & GetDebugInfoParseTimeRef()
Definition: SymbolFileDWARF.h:327
DWARFUnit::GetCompilationDirectory
const lldb_private::FileSpec & GetCompilationDirectory()
Definition: DWARFUnit.cpp:745
DWARFUnit::GetLocationTable
std::unique_ptr< llvm::DWARFLocationTable > GetLocationTable(const lldb_private::DataExtractor &data) const
Return the location table for parsing the given location list data.
Definition: DWARFUnit.cpp:494
DWARFUnit::m_cancel_scopes
std::atomic< bool > m_cancel_scopes
Definition: DWARFUnit.h:302
lldb_private::DataExtractor::GetAddressByteSize
uint32_t GetAddressByteSize() const
Get the current address size.
Definition: DataExtractor.h:264
DWARFUnit::ExtractUnitDIENoDwoIfNeeded
void ExtractUnitDIENoDwoIfNeeded()
Definition: DWARFUnit.cpp:43
dwarf
Definition: ABISysV_arc.cpp:61
DWARFUnit::GetNextUnitOffset
dw_offset_t GetNextUnitOffset() const
Definition: DWARFUnit.h:149
lldb_private::DataExtractor
Definition: DataExtractor.h:48
SymbolFileDWARF::GetDwoSymbolFileForCompileUnit
std::shared_ptr< SymbolFileDWARFDwo > GetDwoSymbolFileForCompileUnit(DWARFUnit &dwarf_cu, const DWARFDebugInfoEntry &cu_die)
Definition: SymbolFileDWARF.cpp:1705
lldb_private::DWARFContext::isDwo
bool isDwo()
Definition: DWARFContext.h:77
DWARFUnit::ScopedExtractDIEs::ScopedExtractDIEs
ScopedExtractDIEs(DWARFUnit &cu)
Definition: DWARFUnit.cpp:165
DWARFUnit::ParseProducerInfo
void ParseProducerInfo()
Definition: DWARFUnit.cpp:666
DWARFUnit::GetAddrBase
dw_addr_t GetAddrBase() const
Definition: DWARFUnit.h:158
DWARFUnitSP
std::shared_ptr< DWARFUnit > DWARFUnitSP
Definition: DWARFUnit.h:24
DWARFUnitHeader::GetNextUnitOffset
uint32_t GetNextUnitOffset() const
Definition: DWARFUnit.h:75
DWARFUnit::~DWARFUnit
virtual ~DWARFUnit()
DWARFUnit::GetPathStyle
lldb_private::FileSpec::Style GetPathStyle()
Definition: DWARFUnit.cpp:739
DWARFUnit::GetAbbrevOffset
dw_offset_t GetAbbrevOffset() const
Definition: DWARFUnit.cpp:422
StreamString.h
DWARFDebugInfoEntry::SetHasChildren
void SetHasChildren(bool b)
Definition: DWARFDebugInfoEntry.h:122
DWARFUnitHeader::m_addr_size
uint8_t m_addr_size
Definition: DWARFUnit.h:49
DWARFUnit::ScopedExtractDIEs::m_cu
DWARFUnit * m_cu
Definition: DWARFUnit.h:102
DWARFUnit::GetStringOffsetSectionItem
llvm::Optional< uint64_t > GetStringOffsetSectionItem(uint32_t index) const
Definition: DWARFUnit.cpp:990
DWARFUnit::ScopedExtractDIEs::~ScopedExtractDIEs
~ScopedExtractDIEs()
Definition: DWARFUnit.cpp:169
DWARFUnit::GetFirstDIEOffset
dw_offset_t GetFirstDIEOffset() const
Definition: DWARFUnit.h:146
lldb_private::DataExtractor::GetByteOrder
lldb::ByteOrder GetByteOrder() const
Get the current byte order value.
Definition: DataExtractor.h:594
DWARFUnit::m_func_aranges_up
std::unique_ptr< DWARFDebugAranges > m_func_aranges_up
Definition: DWARFUnit.h:310
removeHostnameFromPathname
static llvm::StringRef removeHostnameFromPathname(llvm::StringRef path_from_dwarf)
Definition: DWARFUnit.cpp:764
lldb_private::ObjectFile::GetByteOrder
virtual lldb::ByteOrder GetByteOrder() const =0
Gets whether endian swapping should occur when extracting data from this object file.
DWARFUnit::SetStrOffsetsBase
void SetStrOffsetsBase(dw_offset_t str_offsets_base)
Definition: DWARFUnit.cpp:578
lldb_private::DataExtractor::GetU8
uint8_t GetU8(lldb::offset_t *offset_ptr) const
Extract a uint8_t value from *offset_ptr.
Definition: DataExtractor.cpp:316
DWARFUnit::m_str_offsets_base
dw_offset_t m_str_offsets_base
Definition: DWARFUnit.h:327
DWARFUnit::m_dwo_id
uint64_t m_dwo_id
Value of DW_AT_GNU_dwo_id (v4) or dwo_id from CU header (v5).
Definition: DWARFUnit.h:337
DWARFUnitHeader::GetUnitType
uint8_t GetUnitType() const
Definition: DWARFUnit.h:64
Timer.h
lldb_private::DWARFDataExtractor::GetDWARFInitialLength
uint64_t GetDWARFInitialLength(lldb::offset_t *offset_ptr) const
Definition: DWARFDataExtractor.cpp:15
DWARFDebugAranges.h
ParseListTableHeader
static llvm::Expected< ListTableType > ParseListTableHeader(const llvm::DWARFDataExtractor &data, uint64_t offset, DwarfFormat format)
Definition: DWARFUnit.cpp:437
DWARFUnit::Supports_unnamed_objc_bitfields
bool Supports_unnamed_objc_bitfields()
Definition: DWARFUnit.cpp:659
DWARFFormValue
Definition: DWARFFormValue.h:20
DWARFUnit::m_die_array_scoped_mutex
llvm::sys::RWMutex m_die_array_scoped_mutex
Definition: DWARFUnit.h:299
lldb_private::DWARFContext::getOrLoadDebugInfoData
const DWARFDataExtractor & getOrLoadDebugInfoData()
Definition: DWARFContext.cpp:68
DWARFUnitHeader::IsTypeUnit
bool IsTypeUnit() const
Definition: DWARFUnit.h:71
DWARFUnitHeader
Base class describing the header of any kind of "unit." Some information is specific to certain unit ...
Definition: DWARFUnit.h:40
lldb_private::Range
Definition: Process.h:61
SymbolFileDWARF::SupportedVersion
static bool SupportedVersion(uint16_t version)
Definition: SymbolFileDWARF.cpp:515
DWARFUnit::DIEPtr
const DWARFDebugInfoEntry * DIEPtr()
Definition: DWARFUnit.h:279
LogChannelDWARF.h
DWARFDebugInfoEntry::const_iterator
collection::const_iterator const_iterator
Definition: DWARFDebugInfoEntry.h:35
DWARFUnit::GetHeaderByteSize
uint32_t GetHeaderByteSize() const
Get the size in bytes of the unit header.
Definition: DWARFUnit.cpp:974
DWARFDebugRanges
Definition: DWARFDebugRanges.h:20
DWARFDebugInfoEntry::Extract
bool Extract(const lldb_private::DWARFDataExtractor &data, const DWARFUnit *cu, lldb::offset_t *offset_ptr)
Definition: DWARFDebugInfoEntry.cpp:39
DWARFDebugInfoEntry::BuildFunctionAddressRangeTable
void BuildFunctionAddressRangeTable(DWARFUnit *cu, DWARFDebugAranges *debug_aranges) const
This function is builds a table very similar to the standard .debug_aranges table,...
Definition: DWARFDebugInfoEntry.cpp:693
DWARFUnitHeader::m_type_offset
uint32_t m_type_offset
Definition: DWARFUnit.h:52
DWARFDebugInfo.h
DWARFUnit.h
DWARFUnit::GetByteOrder
lldb::ByteOrder GetByteOrder() const
Definition: DWARFUnit.cpp:591
DWARFUnit::ScopedExtractDIEs::operator=
const ScopedExtractDIEs & operator=(const ScopedExtractDIEs &)=delete
DWARFAttributes::ExtractFormValueAtIndex
bool ExtractFormValueAtIndex(uint32_t i, DWARFFormValue &form_value) const
Definition: DWARFAttribute.cpp:38
lldb_private::RangeVector
Definition: RangeMap.h:131
DWARFDebugInfoEntry::GetAttributeValueAsString
const char * GetAttributeValueAsString(const DWARFUnit *cu, const dw_attr_t attr, const char *fail_value, bool check_specification_or_abstract_origin=false) const
Definition: DWARFDebugInfoEntry.cpp:525
DWARFFormValue::Unsigned
uint64_t Unsigned() const
Definition: DWARFFormValue.h:64
DWARFUnit::GetBaseAddress
dw_addr_t GetBaseAddress() const
Definition: DWARFUnit.h:159
DWARFUnit::GetLineTableOffset
dw_offset_t GetLineTableOffset()
Definition: DWARFUnit.cpp:426
eProducerLLVMGCC
@ eProducerLLVMGCC
Definition: DWARFUnit.h:32
ObjectFile.h
eProducerGCC
@ eProducerGCC
Definition: DWARFUnit.h:31
DWARFUnit::GetOffset
dw_offset_t GetOffset() const
Definition: DWARFUnit.h:133
DWARFDebugAbbrev
Definition: DWARFDebugAbbrev.h:64
DWARFUnit::GetFunctionAranges
const DWARFDebugAranges & GetFunctionAranges()
Definition: DWARFUnit.cpp:825
lldb_private::DWARFDataExtractor::GetDWARFOffset
dw_offset_t GetDWARFOffset(lldb::offset_t *offset_ptr) const
Definition: DWARFDataExtractor.cpp:20
lldb_private::FileSpec::Style
llvm::sys::path::Style Style
Definition: FileSpec.h:58
DWARFUnit::m_producer
DWARFProducer m_producer
Definition: DWARFUnit.h:312
DWARFUnit::m_is_dwo
bool m_is_dwo
Definition: DWARFUnit.h:334
lldbassert
#define lldbassert(x)
Definition: LLDBAssert.h:15
DWARFUnit::ExtractDIEsScoped
ScopedExtractDIEs ExtractDIEsScoped()
Definition: DWARFUnit.cpp:145
eProducerInvalid
@ eProducerInvalid
Definition: DWARFUnit.h:29
DWARFUnit::m_rnglist_table
llvm::Optional< llvm::DWARFDebugRnglistTable > m_rnglist_table
Definition: DWARFUnit.h:329
DWARFAbbreviationDeclarationSet
Definition: DWARFDebugAbbrev.h:27
DWARFUnit::SetRangesBase
void SetRangesBase(dw_addr_t ranges_base)
Definition: DWARFUnit.cpp:536
DWARFUnitHeader::m_unit_type
uint8_t m_unit_type
Definition: DWARFUnit.h:48
DWARFUnit::DW_AT_decl_file_attributes_are_invalid
bool DW_AT_decl_file_attributes_are_invalid()
Definition: DWARFUnit.cpp:653
DWARFUnit::GetLength
uint32_t GetLength() const
Definition: DWARFUnit.h:153
DWARFUnitHeader::GetAddressByteSize
uint16_t GetAddressByteSize() const
Definition: DWARFUnit.h:61
DWARFUnit::m_section
const DIERef::Section m_section
Definition: DWARFUnit.h:333
uint32_t
lldb_private::eLazyBoolNo
@ eLazyBoolNo
Definition: lldb-private-enumerations.h:115
DWARFUnit::GetUnitDIEOnly
DWARFBaseDIE GetUnitDIEOnly()
Definition: DWARFUnit.h:175
DWARFUnit::SetBaseAddress
void SetBaseAddress(dw_addr_t base_addr)
Definition: DWARFUnit.cpp:595
DWARFUnit::GetVersion
uint16_t GetVersion() const
Definition: DWARFUnit.h:154
DWARFUnit::ExtractDIEsIfNeeded
void ExtractDIEsIfNeeded()
Definition: DWARFUnit.cpp:125
DWARFUnit::m_language_type
llvm::Optional< uint64_t > m_language_type
Definition: DWARFUnit.h:314
lldb_private::DWARFContext::getOrLoadRngListsData
const DWARFDataExtractor & getOrLoadRngListsData()
Definition: DWARFContext.cpp:104
lldb_private::DataExtractor::GetMaxU64
uint64_t GetMaxU64(lldb::offset_t *offset_ptr, size_t byte_size) const
Extract an unsigned integer of size byte_size from *offset_ptr.
Definition: DataExtractor.cpp:524
DWARFUnit::m_has_parsed_non_skeleton_unit
bool m_has_parsed_non_skeleton_unit
Definition: DWARFUnit.h:335
DWARFUnit::m_gnu_addr_base
llvm::Optional< uint64_t > m_gnu_addr_base
Definition: DWARFUnit.h:321
DWARFUnitHeader::m_abbr_offset
dw_offset_t m_abbr_offset
Definition: DWARFUnit.h:44
g_verbose
int g_verbose
DWARFUnit::m_line_table_offset
dw_offset_t m_line_table_offset
Value of DW_AT_stmt_list.
Definition: DWARFUnit.h:325
DWARFUnit::m_user_data
void * m_user_data
Definition: DWARFUnit.h:294
SymbolFileDWARFDwo
Definition: SymbolFileDWARFDwo.h:14
DWARFUnit::GetNonSkeletonUnit
DWARFUnit & GetNonSkeletonUnit()
Definition: DWARFUnit.cpp:630
DWARFUnit::Supports_DW_AT_APPLE_objc_complete_type
bool Supports_DW_AT_APPLE_objc_complete_type()
Definition: DWARFUnit.cpp:649
DWARFUnitHeader::m_length
dw_offset_t m_length
Definition: DWARFUnit.h:42
lldb_private::ModuleChild::GetModule
lldb::ModuleSP GetModule() const
Get const accessor for the module pointer.
Definition: ModuleChild.cpp:24
DWARFUnitHeader::GetIndexEntry
const llvm::DWARFUnitIndex::Entry * GetIndexEntry() const
Definition: DWARFUnit.h:65
DWARFUnit::GetLengthByteSize
size_t GetLengthByteSize() const
Get the size in bytes of the length field in the header.
Definition: DWARFUnit.h:140
lldb_private::DWARFDataExtractor::GetAsLLVM
llvm::DWARFDataExtractor GetAsLLVM() const
Definition: DWARFDataExtractor.cpp:24
uint16_t
lldb_private::DataExtractor::GetU32
uint32_t GetU32(lldb::offset_t *offset_ptr) const
Extract a uint32_t value from *offset_ptr.
Definition: DataExtractor.cpp:425
DWARFUnit::m_first_die_mutex
llvm::sys::RWMutex m_first_die_mutex
Definition: DWARFUnit.h:307
DWARFDebugInfoEntry::SetParentIndex
void SetParentIndex(uint32_t idx)
Definition: DWARFDebugInfoEntry.h:157
DWARFUnit::GetLocationData
lldb_private::DWARFDataExtractor GetLocationData() const
Definition: DWARFUnit.cpp:504
LLDB_INVALID_ADDRESS
#define LLDB_INVALID_ADDRESS
Definition: lldb-defines.h:74
eProducerOther
@ eProducerOther
Definition: DWARFUnit.h:34
DWARFAttributes::AttributeAtIndex
dw_attr_t AttributeAtIndex(uint32_t i) const
Definition: DWARFAttribute.h:55
DWARFUnit::ComputeAbsolutePath
void ComputeAbsolutePath()
Definition: DWARFUnit.cpp:804
DWARFUnit::ExtractUnitDIEIfNeeded
void ExtractUnitDIEIfNeeded()
Definition: DWARFUnit.cpp:72
DWARFTypeUnit.h
DWARFUnit::GetUserData
void * GetUserData() const
Definition: DWARFUnit.cpp:645
lldb_private::SymbolFileCommon::GetObjectFile
ObjectFile * GetObjectFile() override
Definition: SymbolFile.h:403
lldb::user_id_t
uint64_t user_id_t
Definition: lldb-types.h:84
DWARFUnit::m_die_array
DWARFDebugInfoEntry::collection m_die_array
Definition: DWARFUnit.h:296
DWARFUnit::GetProducerVersion
llvm::VersionTuple GetProducerVersion()
Definition: DWARFUnit.cpp:707
DWARFUnit::m_gnu_ranges_base
llvm::Optional< uint64_t > m_gnu_ranges_base
Definition: DWARFUnit.h:322
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::DataExtractor::GetU16
uint16_t GetU16(lldb::offset_t *offset_ptr) const
Extract a uint16_t value from *offset_ptr.
Definition: DataExtractor.cpp:347
lldb_private::eLazyBoolCalculate
@ eLazyBoolCalculate
Definition: lldb-private-enumerations.h:115
DWARFUnitHeader::extract
static llvm::Expected< DWARFUnitHeader > extract(const lldb_private::DWARFDataExtractor &data, DIERef::Section section, lldb_private::DWARFContext &dwarf_context, lldb::offset_t *offset_ptr)
Definition: DWARFUnit.cpp:846
Error
llvm::Error Error
Definition: UdtRecordCompleter.cpp:30
DWARFDebugAbbrev::GetAbbreviationDeclarationSet
const DWARFAbbreviationDeclarationSet * GetAbbreviationDeclarationSet(dw_offset_t cu_abbr_offset) const
Definition: DWARFDebugAbbrev.cpp:123
lldb_private::DWARFContext::getOrLoadLocData
const DWARFDataExtractor & getOrLoadLocData()
Definition: DWARFContext.cpp:83
lldb_private::RegularExpression::Execute
bool Execute(llvm::StringRef string, llvm::SmallVectorImpl< llvm::StringRef > *matches=nullptr) const
Execute a regular expression match using the compiled regular expression that is already in this obje...
Definition: RegularExpression.cpp:23
DWARFUnit::SetAddrBase
void SetAddrBase(dw_addr_t addr_base)
Definition: DWARFUnit.cpp:431
Entry
FormatEntity::Entry Entry
Definition: FormatEntity.cpp:82
lldb_private::DataExtractor::GetData
const void * GetData(lldb::offset_t *offset_ptr, lldb::offset_t length) const
Extract length bytes from *offset_ptr.
Definition: DataExtractor.h:337
lldb_private::DWARFContext::getOrLoadDebugTypesData
const DWARFDataExtractor & getOrLoadDebugTypesData()
Definition: DWARFContext.cpp:121
DWARFDebugInfoEntry::GetAttributes
size_t GetAttributes(DWARFUnit *cu, DWARFAttributes &attrs, Recurse recurse=Recurse::yes) const
Definition: DWARFDebugInfoEntry.h:51
DWARFUnit::ContainsDIEOffset
bool ContainsDIEOffset(dw_offset_t die_offset) const
Definition: DWARFUnit.h:142
DWARFUnit::GetDefaultAddressSize
static uint8_t GetDefaultAddressSize()
Definition: DWARFUnit.cpp:643
DWARFUnit::GetSymbolFileDWARF
SymbolFileDWARF & GetSymbolFileDWARF() const
Definition: DWARFUnit.h:197
DWARFUnit::m_die_array_mutex
llvm::sys::RWMutex m_die_array_mutex
Definition: DWARFUnit.h:297
DWARFDebugInfoEntry::IsNULL
bool IsNULL() const
Definition: DWARFDebugInfoEntry.h:116
DWARFUnit::GetAbbreviations
const DWARFAbbreviationDeclarationSet * GetAbbreviations() const
Definition: DWARFUnit.cpp:418
DWARFUnit::FindRnglistFromIndex
llvm::Expected< DWARFRangeList > FindRnglistFromIndex(uint32_t index)
Return a list of address ranges retrieved from an encoded range list whose offset is found via a tabl...
Definition: DWARFUnit.cpp:1042
dw_addr_t
uint64_t dw_addr_t
Definition: dwarf.h:29
DWARFUnit::GetIsOptimized
bool GetIsOptimized()
Definition: DWARFUnit.cpp:725
GetDWOId
static uint64_t GetDWOId(DWARFCompileUnit &dwarf_cu, const DWARFDebugInfoEntry &cu_die)
Return the DW_AT_(GNU_)dwo_id.
Definition: SymbolFileDWARF.cpp:1684
DWARFUnit::SetDwoStrOffsetsBase
void SetDwoStrOffsetsBase()
Definition: DWARFUnit.cpp:319
lldb::eByteOrderLittle
@ eByteOrderLittle
Definition: lldb-enumerations.h:142
DWARFDebugInfoEntry::GetAttributeValueAsUnsigned
uint64_t GetAttributeValueAsUnsigned(const DWARFUnit *cu, const dw_attr_t attr, uint64_t fail_value, bool check_specification_or_abstract_origin=false) const
Definition: DWARFDebugInfoEntry.cpp:538
lldb
Definition: SBAddress.h:15
DWARFUnit::m_loclist_table_header
llvm::Optional< llvm::DWARFListTableHeader > m_loclist_table_header
Definition: DWARFUnit.h:331
DWARFUnitHeader::m_dwo_id
uint64_t m_dwo_id
Definition: DWARFUnit.h:54
lldb_private::dwarf
Definition: dwarf.h:19
DIERef::Section
Section
Definition: DIERef.h:28
DWARFUnit::GetFile
lldb_private::FileSpec GetFile(size_t file_idx)
Definition: DWARFUnit.cpp:757
lldb::ByteOrder
ByteOrder
Byte ordering definitions.
Definition: lldb-enumerations.h:138
DWARFBaseDIE
Definition: DWARFBaseDIE.h:25
DWARFUnit::GetAbsolutePath
const lldb_private::FileSpec & GetAbsolutePath()
Definition: DWARFUnit.cpp:751
lldb_private::DWARFContext::getOrLoadLocListsData
const DWARFDataExtractor & getOrLoadLocListsData()
Definition: DWARFContext.cpp:88
DWARFBaseDIE::IsValid
bool IsValid() const
Definition: DWARFBaseDIE.h:45
DWARFUnitHeader::GetLength
dw_offset_t GetLength() const
Definition: DWARFUnit.h:62
DWARFUnit::m_file_spec
llvm::Optional< lldb_private::FileSpec > m_file_spec
Definition: DWARFUnit.h:317
DWARFUnit::GetDIE
DWARFDIE GetDIE(dw_offset_t die_offset)
Definition: DWARFUnit.cpp:609