1 //===-- DWARFUnit.cpp -------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "DWARFUnit.h"
12 #include "lldb/Core/Module.h"
13 #include "lldb/Host/StringConvert.h"
14 #include "lldb/Symbol/CompileUnit.h"
15 #include "lldb/Symbol/LineTable.h"
16 #include "lldb/Symbol/ObjectFile.h"
17 #include "lldb/Utility/LLDBAssert.h"
18 #include "lldb/Utility/StreamString.h"
19 #include "lldb/Utility/Timer.h"
21 #include "DWARFDIECollection.h"
22 #include "DWARFDebugAranges.h"
23 #include "DWARFDebugInfo.h"
24 #include "LogChannelDWARF.h"
25 #include "SymbolFileDWARFDebugMap.h"
26 #include "SymbolFileDWARFDwo.h"
29 using namespace lldb_private;
34 DWARFUnit::DWARFUnit(SymbolFileDWARF *dwarf)
35 : m_dwarf(dwarf), m_cancel_scopes(false) {}
37 DWARFUnit::~DWARFUnit() {}
39 //----------------------------------------------------------------------
40 // Parses first DIE of a compile unit.
41 //----------------------------------------------------------------------
42 void DWARFUnit::ExtractUnitDIEIfNeeded() {
44 llvm::sys::ScopedReader lock(m_first_die_mutex);
46 return; // Already parsed
48 llvm::sys::ScopedWriter lock(m_first_die_mutex);
50 return; // Already parsed
52 static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
54 func_cat, "%8.8x: DWARFUnit::ExtractUnitDIEIfNeeded()", m_offset);
56 // Set the offset to that of the first DIE and calculate the start of the
57 // next compilation unit header.
58 lldb::offset_t offset = GetFirstDIEOffset();
60 // We are in our compile unit, parse starting at the offset we were told to
62 const DWARFDataExtractor &data = GetData();
63 DWARFFormValue::FixedFormSizes fixed_form_sizes =
64 DWARFFormValue::GetFixedFormSizesForAddressSize(GetAddressByteSize(),
66 if (offset < GetNextCompileUnitOffset() &&
67 m_first_die.FastExtract(data, this, fixed_form_sizes, &offset)) {
68 AddUnitDIE(m_first_die);
72 ExtractDIEsEndCheck(offset);
75 //----------------------------------------------------------------------
76 // Parses a compile unit and indexes its DIEs if it hasn't already been done.
77 // It will leave this compile unit extracted forever.
78 //----------------------------------------------------------------------
79 void DWARFUnit::ExtractDIEsIfNeeded() {
80 m_cancel_scopes = true;
83 llvm::sys::ScopedReader lock(m_die_array_mutex);
84 if (!m_die_array.empty())
85 return; // Already parsed
87 llvm::sys::ScopedWriter lock(m_die_array_mutex);
88 if (!m_die_array.empty())
89 return; // Already parsed
91 ExtractDIEsRWLocked();
94 //----------------------------------------------------------------------
95 // Parses a compile unit and indexes its DIEs if it hasn't already been done.
96 // It will clear this compile unit after returned instance gets out of scope,
97 // no other ScopedExtractDIEs instance is running for this compile unit
98 // and no ExtractDIEsIfNeeded() has been executed during this ScopedExtractDIEs
100 //----------------------------------------------------------------------
101 DWARFUnit::ScopedExtractDIEs DWARFUnit::ExtractDIEsScoped() {
102 ScopedExtractDIEs scoped(this);
105 llvm::sys::ScopedReader lock(m_die_array_mutex);
106 if (!m_die_array.empty())
107 return scoped; // Already parsed
109 llvm::sys::ScopedWriter lock(m_die_array_mutex);
110 if (!m_die_array.empty())
111 return scoped; // Already parsed
113 // Otherwise m_die_array would be already populated.
114 lldbassert(!m_cancel_scopes);
116 ExtractDIEsRWLocked();
117 scoped.m_clear_dies = true;
121 DWARFUnit::ScopedExtractDIEs::ScopedExtractDIEs(DWARFUnit *cu) : m_cu(cu) {
123 m_cu->m_die_array_scoped_mutex.lock_shared();
126 DWARFUnit::ScopedExtractDIEs::~ScopedExtractDIEs() {
129 m_cu->m_die_array_scoped_mutex.unlock_shared();
130 if (!m_clear_dies || m_cu->m_cancel_scopes)
132 // Be sure no other ScopedExtractDIEs is running anymore.
133 llvm::sys::ScopedWriter lock_scoped(m_cu->m_die_array_scoped_mutex);
134 llvm::sys::ScopedWriter lock(m_cu->m_die_array_mutex);
135 if (m_cu->m_cancel_scopes)
137 m_cu->ClearDIEsRWLocked();
140 DWARFUnit::ScopedExtractDIEs::ScopedExtractDIEs(ScopedExtractDIEs &&rhs)
141 : m_cu(rhs.m_cu), m_clear_dies(rhs.m_clear_dies) {
145 DWARFUnit::ScopedExtractDIEs &DWARFUnit::ScopedExtractDIEs::operator=(
146 DWARFUnit::ScopedExtractDIEs &&rhs) {
149 m_clear_dies = rhs.m_clear_dies;
153 //----------------------------------------------------------------------
154 // Parses a compile unit and indexes its DIEs, m_die_array_mutex must be
155 // held R/W and m_die_array must be empty.
156 //----------------------------------------------------------------------
157 void DWARFUnit::ExtractDIEsRWLocked() {
158 llvm::sys::ScopedWriter first_die_lock(m_first_die_mutex);
160 static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
162 func_cat, "%8.8x: DWARFUnit::ExtractDIEsIfNeeded()", m_offset);
164 // Set the offset to that of the first DIE and calculate the start of the
165 // next compilation unit header.
166 lldb::offset_t offset = GetFirstDIEOffset();
167 lldb::offset_t next_cu_offset = GetNextCompileUnitOffset();
169 DWARFDebugInfoEntry die;
170 // Keep a flat array of the DIE for binary lookup by DIE offset
172 LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO | DWARF_LOG_LOOKUPS));
174 m_dwarf->GetObjectFile()->GetModule()->LogMessageVerboseBacktrace(
176 "DWARFUnit::ExtractDIEsIfNeeded () for compile unit at "
177 ".debug_info[0x%8.8x]",
182 // We are in our compile unit, parse starting at the offset we were told to
184 const DWARFDataExtractor &data = GetData();
185 std::vector<uint32_t> die_index_stack;
186 die_index_stack.reserve(32);
187 die_index_stack.push_back(0);
188 bool prev_die_had_children = false;
189 DWARFFormValue::FixedFormSizes fixed_form_sizes =
190 DWARFFormValue::GetFixedFormSizesForAddressSize(GetAddressByteSize(),
192 while (offset < next_cu_offset &&
193 die.FastExtract(data, this, fixed_form_sizes, &offset)) {
195 // log->Printf("0x%8.8x: %*.*s%s%s",
197 // depth * 2, depth * 2, "",
198 // DW_TAG_value_to_name (die.Tag()),
199 // die.HasChildren() ? " *" : "");
201 const bool null_die = die.IsNULL();
203 assert(m_die_array.empty() && "Compile unit DIE already added");
205 // The average bytes per DIE entry has been seen to be around 14-20 so
206 // lets pre-reserve half of that since we are now stripping the NULL
209 // Only reserve the memory if we are adding children of the main
210 // compile unit DIE. The compile unit DIE is always the first entry, so
211 // if our size is 1, then we are adding the first compile unit child
212 // DIE and should reserve the memory.
213 m_die_array.reserve(GetDebugInfoSize() / 24);
214 m_die_array.push_back(die);
217 AddUnitDIE(m_die_array.front());
220 if (prev_die_had_children) {
221 // This will only happen if a DIE says is has children but all it
222 // contains is a NULL tag. Since we are removing the NULL DIEs from
223 // the list (saves up to 25% in C++ code), we need a way to let the
224 // DIE know that it actually doesn't have children.
225 if (!m_die_array.empty())
226 m_die_array.back().SetEmptyChildren(true);
229 die.SetParentIndex(m_die_array.size() - die_index_stack[depth - 1]);
231 if (die_index_stack.back())
232 m_die_array[die_index_stack.back()].SetSiblingIndex(
233 m_die_array.size() - die_index_stack.back());
235 // Only push the DIE if it isn't a NULL DIE
236 m_die_array.push_back(die);
242 if (!die_index_stack.empty())
243 die_index_stack.pop_back();
248 break; // We are done with this compile unit!
250 prev_die_had_children = false;
252 die_index_stack.back() = m_die_array.size() - 1;
254 const bool die_has_children = die.HasChildren();
255 if (die_has_children) {
256 die_index_stack.push_back(0);
259 prev_die_had_children = die_has_children;
263 if (!m_die_array.empty()) {
265 // Only needed for the assertion.
266 m_first_die.SetEmptyChildren(m_die_array.front().GetEmptyChildren());
267 lldbassert(m_first_die == m_die_array.front());
269 m_first_die = m_die_array.front();
272 m_die_array.shrink_to_fit();
274 ExtractDIEsEndCheck(offset);
276 if (m_dwo_symbol_file) {
277 DWARFUnit *dwo_cu = m_dwo_symbol_file->GetCompileUnit();
278 dwo_cu->ExtractDIEsIfNeeded();
282 //--------------------------------------------------------------------------
283 // Final checks for both ExtractUnitDIEIfNeeded() and ExtractDIEsIfNeeded().
284 //--------------------------------------------------------------------------
285 void DWARFUnit::ExtractDIEsEndCheck(lldb::offset_t offset) const {
286 // Give a little bit of info if we encounter corrupt DWARF (our offset should
287 // always terminate at or before the start of the next compilation unit
289 if (offset > GetNextCompileUnitOffset()) {
290 m_dwarf->GetObjectFile()->GetModule()->ReportWarning(
291 "DWARF compile unit extends beyond its bounds cu 0x%8.8x at "
292 "0x%8.8" PRIx64 "\n",
293 GetOffset(), offset);
296 Log *log(LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
297 if (log && log->GetVerbose()) {
300 if (m_die_array.empty())
301 strm.Printf("error: no DIE for compile unit");
303 m_die_array[0].Dump(m_dwarf, this, strm, UINT32_MAX);
304 log->PutString(strm.GetString());
308 // m_die_array_mutex must be already held as read/write.
309 void DWARFUnit::AddUnitDIE(const DWARFDebugInfoEntry &cu_die) {
310 uint64_t base_addr = cu_die.GetAttributeValueAsAddress(
311 m_dwarf, this, DW_AT_low_pc, LLDB_INVALID_ADDRESS);
312 if (base_addr == LLDB_INVALID_ADDRESS)
313 base_addr = cu_die.GetAttributeValueAsAddress(
314 m_dwarf, this, DW_AT_entry_pc, 0);
315 SetBaseAddress(base_addr);
317 std::unique_ptr<SymbolFileDWARFDwo> dwo_symbol_file =
318 m_dwarf->GetDwoSymbolFileForCompileUnit(*this, cu_die);
319 if (!dwo_symbol_file)
322 DWARFUnit *dwo_cu = dwo_symbol_file->GetCompileUnit();
324 return; // Can't fetch the compile unit from the dwo file.
326 DWARFBaseDIE dwo_cu_die = dwo_cu->GetUnitDIEOnly();
327 if (!dwo_cu_die.IsValid())
328 return; // Can't fetch the compile unit DIE from the dwo file.
330 uint64_t main_dwo_id =
331 cu_die.GetAttributeValueAsUnsigned(m_dwarf, this, DW_AT_GNU_dwo_id, 0);
332 uint64_t sub_dwo_id =
333 dwo_cu_die.GetAttributeValueAsUnsigned(DW_AT_GNU_dwo_id, 0);
334 if (main_dwo_id != sub_dwo_id)
335 return; // The 2 dwo ID isn't match. Don't use the dwo file as it belongs to
336 // a differectn compilation.
338 m_dwo_symbol_file = std::move(dwo_symbol_file);
340 dw_addr_t addr_base =
341 cu_die.GetAttributeValueAsUnsigned(m_dwarf, this, DW_AT_GNU_addr_base, 0);
342 dw_addr_t ranges_base = cu_die.GetAttributeValueAsUnsigned(
343 m_dwarf, this, DW_AT_GNU_ranges_base, 0);
344 dwo_cu->SetAddrBase(addr_base, ranges_base, m_offset);
347 DWARFDIE DWARFUnit::LookupAddress(const dw_addr_t address) {
349 const DWARFDebugAranges &func_aranges = GetFunctionAranges();
351 // Re-check the aranges auto pointer contents in case it was created above
352 if (!func_aranges.IsEmpty())
353 return GetDIE(func_aranges.FindAddress(address));
358 size_t DWARFUnit::AppendDIEsWithTag(const dw_tag_t tag,
359 DWARFDIECollection &dies,
360 uint32_t depth) const {
361 size_t old_size = dies.Size();
363 llvm::sys::ScopedReader lock(m_die_array_mutex);
364 DWARFDebugInfoEntry::const_iterator pos;
365 DWARFDebugInfoEntry::const_iterator end = m_die_array.end();
366 for (pos = m_die_array.begin(); pos != end; ++pos) {
367 if (pos->Tag() == tag)
368 dies.Append(DWARFDIE(this, &(*pos)));
372 // Return the number of DIEs added to the collection
373 return dies.Size() - old_size;
377 lldb::user_id_t DWARFUnit::GetID() const {
378 dw_offset_t local_id =
379 m_base_obj_offset != DW_INVALID_OFFSET ? m_base_obj_offset : m_offset;
381 return DIERef(local_id, local_id).GetUID(m_dwarf);
386 dw_offset_t DWARFUnit::GetNextCompileUnitOffset() const {
387 return m_offset + GetLengthByteSize() + GetLength();
390 size_t DWARFUnit::GetDebugInfoSize() const {
391 return GetLengthByteSize() + GetLength() - GetHeaderByteSize();
394 const DWARFAbbreviationDeclarationSet *DWARFUnit::GetAbbreviations() const {
398 dw_offset_t DWARFUnit::GetAbbrevOffset() const {
399 return m_abbrevs ? m_abbrevs->GetOffset() : DW_INVALID_OFFSET;
402 void DWARFUnit::SetAddrBase(dw_addr_t addr_base,
403 dw_addr_t ranges_base,
404 dw_offset_t base_obj_offset) {
405 m_addr_base = addr_base;
406 m_ranges_base = ranges_base;
407 m_base_obj_offset = base_obj_offset;
410 // It may be called only with m_die_array_mutex held R/W.
411 void DWARFUnit::ClearDIEsRWLocked() {
413 m_die_array.shrink_to_fit();
415 if (m_dwo_symbol_file)
416 m_dwo_symbol_file->GetCompileUnit()->ClearDIEsRWLocked();
419 void DWARFUnit::BuildAddressRangeTable(SymbolFileDWARF *dwarf,
420 DWARFDebugAranges *debug_aranges) {
421 // This function is usually called if there in no .debug_aranges section in
422 // order to produce a compile unit level set of address ranges that is
425 size_t num_debug_aranges = debug_aranges->GetNumRanges();
427 // First get the compile unit DIE only and check if it has a DW_AT_ranges
428 const DWARFDebugInfoEntry *die = GetUnitDIEPtrOnly();
430 const dw_offset_t cu_offset = GetOffset();
432 DWARFRangeList ranges;
433 const size_t num_ranges =
434 die->GetAttributeAddressRanges(dwarf, this, ranges, false);
435 if (num_ranges > 0) {
436 // This compile unit has DW_AT_ranges, assume this is correct if it is
437 // present since clang no longer makes .debug_aranges by default and it
438 // emits DW_AT_ranges for DW_TAG_compile_units. GCC also does this with
439 // recent GCC builds.
440 for (size_t i = 0; i < num_ranges; ++i) {
441 const DWARFRangeList::Entry &range = ranges.GetEntryRef(i);
442 debug_aranges->AppendRange(cu_offset, range.GetRangeBase(),
443 range.GetRangeEnd());
446 return; // We got all of our ranges from the DW_AT_ranges attribute
449 // We don't have a DW_AT_ranges attribute, so we need to parse the DWARF
451 // If the DIEs weren't parsed, then we don't want all dies for all compile
452 // units to stay loaded when they weren't needed. So we can end up parsing
453 // the DWARF and then throwing them all away to keep memory usage down.
454 ScopedExtractDIEs clear_dies(ExtractDIEsScoped());
458 die->BuildAddressRangeTable(dwarf, this, debug_aranges);
460 if (debug_aranges->GetNumRanges() == num_debug_aranges) {
461 // We got nothing from the functions, maybe we have a line tables only
462 // situation. Check the line tables and build the arange table from this.
464 sc.comp_unit = dwarf->GetCompUnitForDWARFCompUnit(this);
466 SymbolFileDWARFDebugMap *debug_map_sym_file =
467 m_dwarf->GetDebugMapSymfile();
468 if (debug_map_sym_file == NULL) {
469 LineTable *line_table = sc.comp_unit->GetLineTable();
472 LineTable::FileAddressRanges file_ranges;
473 const bool append = true;
474 const size_t num_ranges =
475 line_table->GetContiguousFileAddressRanges(file_ranges, append);
476 for (uint32_t idx = 0; idx < num_ranges; ++idx) {
477 const LineTable::FileAddressRanges::Entry &range =
478 file_ranges.GetEntryRef(idx);
479 debug_aranges->AppendRange(cu_offset, range.GetRangeBase(),
480 range.GetRangeEnd());
484 debug_map_sym_file->AddOSOARanges(dwarf, debug_aranges);
488 if (debug_aranges->GetNumRanges() == num_debug_aranges) {
489 // We got nothing from the functions, maybe we have a line tables only
490 // situation. Check the line tables and build the arange table from this.
492 sc.comp_unit = dwarf->GetCompUnitForDWARFCompUnit(this);
494 LineTable *line_table = sc.comp_unit->GetLineTable();
497 LineTable::FileAddressRanges file_ranges;
498 const bool append = true;
499 const size_t num_ranges =
500 line_table->GetContiguousFileAddressRanges(file_ranges, append);
501 for (uint32_t idx = 0; idx < num_ranges; ++idx) {
502 const LineTable::FileAddressRanges::Entry &range =
503 file_ranges.GetEntryRef(idx);
504 debug_aranges->AppendRange(GetOffset(), range.GetRangeBase(),
505 range.GetRangeEnd());
512 lldb::ByteOrder DWARFUnit::GetByteOrder() const {
513 return m_dwarf->GetObjectFile()->GetByteOrder();
516 TypeSystem *DWARFUnit::GetTypeSystem() {
518 return m_dwarf->GetTypeSystemForLanguage(GetLanguageType());
523 DWARFFormValue::FixedFormSizes DWARFUnit::GetFixedFormSizes() {
524 return DWARFFormValue::GetFixedFormSizesForAddressSize(GetAddressByteSize(),
528 void DWARFUnit::SetBaseAddress(dw_addr_t base_addr) { m_base_addr = base_addr; }
530 //----------------------------------------------------------------------
531 // Compare function DWARFDebugAranges::Range structures
532 //----------------------------------------------------------------------
533 static bool CompareDIEOffset(const DWARFDebugInfoEntry &die,
534 const dw_offset_t die_offset) {
535 return die.GetOffset() < die_offset;
538 //----------------------------------------------------------------------
541 // Get the DIE (Debug Information Entry) with the specified offset by first
542 // checking if the DIE is contained within this compile unit and grabbing the
543 // DIE from this compile unit. Otherwise we grab the DIE from the DWARF file.
544 //----------------------------------------------------------------------
546 DWARFUnit::GetDIE(dw_offset_t die_offset) {
547 if (die_offset != DW_INVALID_OFFSET) {
548 if (GetDwoSymbolFile())
549 return GetDwoSymbolFile()->GetCompileUnit()->GetDIE(die_offset);
551 if (ContainsDIEOffset(die_offset)) {
552 ExtractDIEsIfNeeded();
553 DWARFDebugInfoEntry::const_iterator end = m_die_array.cend();
554 DWARFDebugInfoEntry::const_iterator pos =
555 lower_bound(m_die_array.cbegin(), end, die_offset, CompareDIEOffset);
557 if (die_offset == (*pos).GetOffset())
558 return DWARFDIE(this, &(*pos));
561 // Don't specify the compile unit offset as we don't know it because the
563 // a different compile unit in the same symbol file.
564 return m_dwarf->DebugInfo()->GetDIEForDIEOffset(die_offset);
567 return DWARFDIE(); // Not found
570 uint8_t DWARFUnit::GetAddressByteSize(const DWARFUnit *cu) {
572 return cu->GetAddressByteSize();
573 return DWARFUnit::GetDefaultAddressSize();
576 bool DWARFUnit::IsDWARF64(const DWARFUnit *cu) {
578 return cu->IsDWARF64();
582 uint8_t DWARFUnit::GetDefaultAddressSize() { return 4; }
584 void *DWARFUnit::GetUserData() const { return m_user_data; }
586 void DWARFUnit::SetUserData(void *d) {
588 if (m_dwo_symbol_file)
589 m_dwo_symbol_file->GetCompileUnit()->SetUserData(d);
592 bool DWARFUnit::Supports_DW_AT_APPLE_objc_complete_type() {
593 if (GetProducer() == eProducerLLVMGCC)
598 bool DWARFUnit::DW_AT_decl_file_attributes_are_invalid() {
599 // llvm-gcc makes completely invalid decl file attributes and won't ever be
600 // fixed, so we need to know to ignore these.
601 return GetProducer() == eProducerLLVMGCC;
604 bool DWARFUnit::Supports_unnamed_objc_bitfields() {
605 if (GetProducer() == eProducerClang) {
606 const uint32_t major_version = GetProducerVersionMajor();
607 if (major_version > 425 ||
608 (major_version == 425 && GetProducerVersionUpdate() >= 13))
613 return true; // Assume all other compilers didn't have incorrect ObjC bitfield
617 SymbolFileDWARF *DWARFUnit::GetSymbolFileDWARF() const { return m_dwarf; }
619 void DWARFUnit::ParseProducerInfo() {
620 m_producer_version_major = UINT32_MAX;
621 m_producer_version_minor = UINT32_MAX;
622 m_producer_version_update = UINT32_MAX;
624 const DWARFDebugInfoEntry *die = GetUnitDIEPtrOnly();
627 const char *producer_cstr =
628 die->GetAttributeValueAsString(m_dwarf, this, DW_AT_producer, NULL);
630 RegularExpression llvm_gcc_regex(
631 llvm::StringRef("^4\\.[012]\\.[01] \\(Based on Apple "
632 "Inc\\. build [0-9]+\\) \\(LLVM build "
634 if (llvm_gcc_regex.Execute(llvm::StringRef(producer_cstr))) {
635 m_producer = eProducerLLVMGCC;
636 } else if (strstr(producer_cstr, "clang")) {
637 static RegularExpression g_clang_version_regex(
638 llvm::StringRef("clang-([0-9]+)\\.([0-9]+)\\.([0-9]+)"));
639 RegularExpression::Match regex_match(3);
640 if (g_clang_version_regex.Execute(llvm::StringRef(producer_cstr),
643 if (regex_match.GetMatchAtIndex(producer_cstr, 1, str))
644 m_producer_version_major =
645 StringConvert::ToUInt32(str.c_str(), UINT32_MAX, 10);
646 if (regex_match.GetMatchAtIndex(producer_cstr, 2, str))
647 m_producer_version_minor =
648 StringConvert::ToUInt32(str.c_str(), UINT32_MAX, 10);
649 if (regex_match.GetMatchAtIndex(producer_cstr, 3, str))
650 m_producer_version_update =
651 StringConvert::ToUInt32(str.c_str(), UINT32_MAX, 10);
653 m_producer = eProducerClang;
654 } else if (strstr(producer_cstr, "GNU"))
655 m_producer = eProducerGCC;
658 if (m_producer == eProducerInvalid)
659 m_producer = eProcucerOther;
662 DWARFProducer DWARFUnit::GetProducer() {
663 if (m_producer == eProducerInvalid)
668 uint32_t DWARFUnit::GetProducerVersionMajor() {
669 if (m_producer_version_major == 0)
671 return m_producer_version_major;
674 uint32_t DWARFUnit::GetProducerVersionMinor() {
675 if (m_producer_version_minor == 0)
677 return m_producer_version_minor;
680 uint32_t DWARFUnit::GetProducerVersionUpdate() {
681 if (m_producer_version_update == 0)
683 return m_producer_version_update;
685 LanguageType DWARFUnit::LanguageTypeFromDWARF(uint64_t val) {
686 // Note: user languages between lo_user and hi_user must be handled
689 case DW_LANG_Mips_Assembler:
690 return eLanguageTypeMipsAssembler;
691 case DW_LANG_GOOGLE_RenderScript:
692 return eLanguageTypeExtRenderScript;
694 return static_cast<LanguageType>(val);
698 LanguageType DWARFUnit::GetLanguageType() {
699 if (m_language_type != eLanguageTypeUnknown)
700 return m_language_type;
702 const DWARFDebugInfoEntry *die = GetUnitDIEPtrOnly();
704 m_language_type = LanguageTypeFromDWARF(
705 die->GetAttributeValueAsUnsigned(m_dwarf, this, DW_AT_language, 0));
706 return m_language_type;
709 bool DWARFUnit::GetIsOptimized() {
710 if (m_is_optimized == eLazyBoolCalculate) {
711 const DWARFDebugInfoEntry *die = GetUnitDIEPtrOnly();
713 m_is_optimized = eLazyBoolNo;
714 if (die->GetAttributeValueAsUnsigned(m_dwarf, this, DW_AT_APPLE_optimized,
716 m_is_optimized = eLazyBoolYes;
720 return m_is_optimized == eLazyBoolYes;
723 SymbolFileDWARFDwo *DWARFUnit::GetDwoSymbolFile() const {
724 return m_dwo_symbol_file.get();
727 dw_offset_t DWARFUnit::GetBaseObjOffset() const { return m_base_obj_offset; }
729 const DWARFDebugAranges &DWARFUnit::GetFunctionAranges() {
730 if (m_func_aranges_ap.get() == NULL) {
731 m_func_aranges_ap.reset(new DWARFDebugAranges());
732 Log *log(LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_ARANGES));
735 m_dwarf->GetObjectFile()->GetModule()->LogMessage(
737 "DWARFUnit::GetFunctionAranges() for compile unit at "
738 ".debug_info[0x%8.8x]",
741 const DWARFDebugInfoEntry *die = DIEPtr();
743 die->BuildFunctionAddressRangeTable(m_dwarf, this,
744 m_func_aranges_ap.get());
746 if (m_dwo_symbol_file) {
747 DWARFUnit *dwo_cu = m_dwo_symbol_file->GetCompileUnit();
748 const DWARFDebugInfoEntry *dwo_die = dwo_cu->DIEPtr();
750 dwo_die->BuildFunctionAddressRangeTable(m_dwo_symbol_file.get(), dwo_cu,
751 m_func_aranges_ap.get());
754 const bool minimize = false;
755 m_func_aranges_ap->Sort(minimize);
757 return *m_func_aranges_ap.get();