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