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