1 //===-- SymbolFileDWARF.cpp -----------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "SymbolFileDWARF.h"
11 #include "llvm/ADT/Optional.h"
12 #include "llvm/Support/Casting.h"
13 #include "llvm/Support/Threading.h"
15 #include "lldb/Core/Module.h"
16 #include "lldb/Core/ModuleList.h"
17 #include "lldb/Core/ModuleSpec.h"
18 #include "lldb/Core/PluginManager.h"
19 #include "lldb/Core/Section.h"
20 #include "lldb/Core/StreamFile.h"
21 #include "lldb/Core/Value.h"
22 #include "lldb/Utility/ArchSpec.h"
23 #include "lldb/Utility/RegularExpression.h"
24 #include "lldb/Utility/Scalar.h"
25 #include "lldb/Utility/StreamString.h"
26 #include "lldb/Utility/Timer.h"
28 #include "Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.h"
29 #include "Plugins/Language/CPlusPlus/CPlusPlusLanguage.h"
31 #include "lldb/Host/FileSystem.h"
32 #include "lldb/Host/Host.h"
34 #include "lldb/Interpreter/OptionValueFileSpecList.h"
35 #include "lldb/Interpreter/OptionValueProperties.h"
37 #include "Plugins/ExpressionParser/Clang/ClangUtil.h"
38 #include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
39 #include "lldb/Symbol/Block.h"
40 #include "lldb/Symbol/CompileUnit.h"
41 #include "lldb/Symbol/CompilerDecl.h"
42 #include "lldb/Symbol/CompilerDeclContext.h"
43 #include "lldb/Symbol/DebugMacros.h"
44 #include "lldb/Symbol/LineTable.h"
45 #include "lldb/Symbol/LocateSymbolFile.h"
46 #include "lldb/Symbol/ObjectFile.h"
47 #include "lldb/Symbol/SymbolFile.h"
48 #include "lldb/Symbol/TypeMap.h"
49 #include "lldb/Symbol/TypeSystem.h"
50 #include "lldb/Symbol/VariableList.h"
52 #include "lldb/Target/Language.h"
53 #include "lldb/Target/Target.h"
55 #include "AppleDWARFIndex.h"
56 #include "DWARFASTParser.h"
57 #include "DWARFASTParserClang.h"
58 #include "DWARFCompileUnit.h"
59 #include "DWARFDebugAbbrev.h"
60 #include "DWARFDebugAranges.h"
61 #include "DWARFDebugInfo.h"
62 #include "DWARFDebugMacro.h"
63 #include "DWARFDebugRanges.h"
64 #include "DWARFDeclContext.h"
65 #include "DWARFFormValue.h"
66 #include "DWARFTypeUnit.h"
67 #include "DWARFUnit.h"
68 #include "DebugNamesDWARFIndex.h"
69 #include "LogChannelDWARF.h"
70 #include "ManualDWARFIndex.h"
71 #include "SymbolFileDWARFDebugMap.h"
72 #include "SymbolFileDWARFDwo.h"
74 #include "llvm/DebugInfo/DWARF/DWARFContext.h"
75 #include "llvm/Support/FileSystem.h"
84 //#define ENABLE_DEBUG_PRINTF // COMMENT OUT THIS LINE PRIOR TO CHECKIN
86 #ifdef ENABLE_DEBUG_PRINTF
88 #define DEBUG_PRINTF(fmt, ...) printf(fmt, __VA_ARGS__)
90 #define DEBUG_PRINTF(fmt, ...)
94 using namespace lldb_private;
96 LLDB_PLUGIN_DEFINE(SymbolFileDWARF)
98 char SymbolFileDWARF::ID;
100 // static inline bool
101 // child_requires_parent_class_union_or_struct_to_be_completed (dw_tag_t tag)
107 // case DW_TAG_subprogram:
108 // case DW_TAG_inlined_subroutine:
109 // case DW_TAG_class_type:
110 // case DW_TAG_structure_type:
111 // case DW_TAG_union_type:
120 #define LLDB_PROPERTIES_symbolfiledwarf
121 #include "SymbolFileDWARFProperties.inc"
124 #define LLDB_PROPERTIES_symbolfiledwarf
125 #include "SymbolFileDWARFPropertiesEnum.inc"
128 class PluginProperties : public Properties {
130 static ConstString GetSettingName() {
131 return SymbolFileDWARF::GetPluginNameStatic();
135 m_collection_sp = std::make_shared<OptionValueProperties>(GetSettingName());
136 m_collection_sp->Initialize(g_symbolfiledwarf_properties);
139 bool IgnoreFileIndexes() const {
140 return m_collection_sp->GetPropertyAtIndexAsBoolean(
141 nullptr, ePropertyIgnoreIndexes, false);
145 typedef std::shared_ptr<PluginProperties> SymbolFileDWARFPropertiesSP;
147 static const SymbolFileDWARFPropertiesSP &GetGlobalPluginProperties() {
148 static const auto g_settings_sp(std::make_shared<PluginProperties>());
149 return g_settings_sp;
154 static const llvm::DWARFDebugLine::LineTable *
155 ParseLLVMLineTable(lldb_private::DWARFContext &context,
156 llvm::DWARFDebugLine &line, dw_offset_t line_offset,
157 dw_offset_t unit_offset) {
158 Log *log = LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO);
160 llvm::DWARFDataExtractor data = context.getOrLoadLineData().GetAsLLVM();
161 llvm::DWARFContext &ctx = context.GetAsLLVM();
162 llvm::Expected<const llvm::DWARFDebugLine::LineTable *> line_table =
163 line.getOrParseLineTable(
164 data, line_offset, ctx, nullptr, [&](llvm::Error e) {
167 "SymbolFileDWARF::ParseLineTable failed to parse: {0}");
171 LLDB_LOG_ERROR(log, line_table.takeError(),
172 "SymbolFileDWARF::ParseLineTable failed to parse: {0}");
178 static bool ParseLLVMLineTablePrologue(lldb_private::DWARFContext &context,
179 llvm::DWARFDebugLine::Prologue &prologue,
180 dw_offset_t line_offset,
181 dw_offset_t unit_offset) {
182 Log *log = LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO);
184 llvm::DWARFDataExtractor data = context.getOrLoadLineData().GetAsLLVM();
185 llvm::DWARFContext &ctx = context.GetAsLLVM();
186 uint64_t offset = line_offset;
187 llvm::Error error = prologue.parse(
191 LLDB_LOG_ERROR(log, std::move(e),
192 "SymbolFileDWARF::ParseSupportFiles failed to parse "
193 "line table prologue: {0}");
197 LLDB_LOG_ERROR(log, std::move(error),
198 "SymbolFileDWARF::ParseSupportFiles failed to parse line "
199 "table prologue: {0}");
205 static llvm::Optional<std::string>
206 GetFileByIndex(const llvm::DWARFDebugLine::Prologue &prologue, size_t idx,
207 llvm::StringRef compile_dir, FileSpec::Style style) {
208 // Try to get an absolute path first.
209 std::string abs_path;
210 auto absolute = llvm::DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath;
211 if (prologue.getFileNameByIndex(idx, compile_dir, absolute, abs_path, style))
212 return std::move(abs_path);
214 // Otherwise ask for a relative path.
215 std::string rel_path;
216 auto relative = llvm::DILineInfoSpecifier::FileLineInfoKind::RawValue;
217 if (!prologue.getFileNameByIndex(idx, compile_dir, relative, rel_path, style))
219 return std::move(rel_path);
223 ParseSupportFilesFromPrologue(const lldb::ModuleSP &module,
224 const llvm::DWARFDebugLine::Prologue &prologue,
225 FileSpec::Style style,
226 llvm::StringRef compile_dir = {}) {
227 FileSpecList support_files;
228 size_t first_file = 0;
229 if (prologue.getVersion() <= 4) {
230 // File index 0 is not valid before DWARF v5. Add a dummy entry to ensure
231 // support file list indices match those we get from the debug info and line
233 support_files.Append(FileSpec());
237 const size_t number_of_files = prologue.FileNames.size();
238 for (size_t idx = first_file; idx <= number_of_files; ++idx) {
239 std::string remapped_file;
240 if (auto file_path = GetFileByIndex(prologue, idx, compile_dir, style))
241 if (!module->RemapSourceFile(llvm::StringRef(*file_path), remapped_file))
242 remapped_file = std::move(*file_path);
244 // Unconditionally add an entry, so the indices match up.
245 support_files.EmplaceBack(remapped_file, style);
248 return support_files;
251 void SymbolFileDWARF::Initialize() {
252 LogChannelDWARF::Initialize();
253 PluginManager::RegisterPlugin(GetPluginNameStatic(),
254 GetPluginDescriptionStatic(), CreateInstance,
256 SymbolFileDWARFDebugMap::Initialize();
259 void SymbolFileDWARF::DebuggerInitialize(Debugger &debugger) {
260 if (!PluginManager::GetSettingForSymbolFilePlugin(
261 debugger, PluginProperties::GetSettingName())) {
262 const bool is_global_setting = true;
263 PluginManager::CreateSettingForSymbolFilePlugin(
264 debugger, GetGlobalPluginProperties()->GetValueProperties(),
265 ConstString("Properties for the dwarf symbol-file plug-in."),
270 void SymbolFileDWARF::Terminate() {
271 SymbolFileDWARFDebugMap::Terminate();
272 PluginManager::UnregisterPlugin(CreateInstance);
273 LogChannelDWARF::Terminate();
276 lldb_private::ConstString SymbolFileDWARF::GetPluginNameStatic() {
277 static ConstString g_name("dwarf");
281 const char *SymbolFileDWARF::GetPluginDescriptionStatic() {
282 return "DWARF and DWARF3 debug symbol file reader.";
285 SymbolFile *SymbolFileDWARF::CreateInstance(ObjectFileSP objfile_sp) {
286 return new SymbolFileDWARF(std::move(objfile_sp),
287 /*dwo_section_list*/ nullptr);
290 TypeList &SymbolFileDWARF::GetTypeList() {
291 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
292 if (SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile())
293 return debug_map_symfile->GetTypeList();
294 return SymbolFile::GetTypeList();
296 void SymbolFileDWARF::GetTypes(const DWARFDIE &die, dw_offset_t min_die_offset,
297 dw_offset_t max_die_offset, uint32_t type_mask,
300 const dw_offset_t die_offset = die.GetOffset();
302 if (die_offset >= max_die_offset)
305 if (die_offset >= min_die_offset) {
306 const dw_tag_t tag = die.Tag();
308 bool add_type = false;
311 case DW_TAG_array_type:
312 add_type = (type_mask & eTypeClassArray) != 0;
314 case DW_TAG_unspecified_type:
315 case DW_TAG_base_type:
316 add_type = (type_mask & eTypeClassBuiltin) != 0;
318 case DW_TAG_class_type:
319 add_type = (type_mask & eTypeClassClass) != 0;
321 case DW_TAG_structure_type:
322 add_type = (type_mask & eTypeClassStruct) != 0;
324 case DW_TAG_union_type:
325 add_type = (type_mask & eTypeClassUnion) != 0;
327 case DW_TAG_enumeration_type:
328 add_type = (type_mask & eTypeClassEnumeration) != 0;
330 case DW_TAG_subroutine_type:
331 case DW_TAG_subprogram:
332 case DW_TAG_inlined_subroutine:
333 add_type = (type_mask & eTypeClassFunction) != 0;
335 case DW_TAG_pointer_type:
336 add_type = (type_mask & eTypeClassPointer) != 0;
338 case DW_TAG_rvalue_reference_type:
339 case DW_TAG_reference_type:
340 add_type = (type_mask & eTypeClassReference) != 0;
343 add_type = (type_mask & eTypeClassTypedef) != 0;
345 case DW_TAG_ptr_to_member_type:
346 add_type = (type_mask & eTypeClassMemberPointer) != 0;
353 const bool assert_not_being_parsed = true;
354 Type *type = ResolveTypeUID(die, assert_not_being_parsed);
356 type_set.insert(type);
360 for (DWARFDIE child_die = die.GetFirstChild(); child_die.IsValid();
361 child_die = child_die.GetSibling()) {
362 GetTypes(child_die, min_die_offset, max_die_offset, type_mask, type_set);
367 void SymbolFileDWARF::GetTypes(SymbolContextScope *sc_scope,
368 TypeClass type_mask, TypeList &type_list)
371 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
374 CompileUnit *comp_unit = nullptr;
375 DWARFUnit *dwarf_cu = nullptr;
377 comp_unit = sc_scope->CalculateSymbolContextCompileUnit();
380 dwarf_cu = GetDWARFCompileUnit(comp_unit);
383 GetTypes(dwarf_cu->DIE(), dwarf_cu->GetOffset(),
384 dwarf_cu->GetNextUnitOffset(), type_mask, type_set);
386 DWARFDebugInfo &info = DebugInfo();
387 const size_t num_cus = info.GetNumUnits();
388 for (size_t cu_idx = 0; cu_idx < num_cus; ++cu_idx) {
389 dwarf_cu = info.GetUnitAtIndex(cu_idx);
391 GetTypes(dwarf_cu->DIE(), 0, UINT32_MAX, type_mask, type_set);
395 std::set<CompilerType> compiler_type_set;
396 for (Type *type : type_set) {
397 CompilerType compiler_type = type->GetForwardCompilerType();
398 if (compiler_type_set.find(compiler_type) == compiler_type_set.end()) {
399 compiler_type_set.insert(compiler_type);
400 type_list.Insert(type->shared_from_this());
405 // Gets the first parent that is a lexical block, function or inlined
406 // subroutine, or compile unit.
408 SymbolFileDWARF::GetParentSymbolContextDIE(const DWARFDIE &child_die) {
410 for (die = child_die.GetParent(); die; die = die.GetParent()) {
411 dw_tag_t tag = die.Tag();
414 case DW_TAG_compile_unit:
415 case DW_TAG_partial_unit:
416 case DW_TAG_subprogram:
417 case DW_TAG_inlined_subroutine:
418 case DW_TAG_lexical_block:
427 SymbolFileDWARF::SymbolFileDWARF(ObjectFileSP objfile_sp,
428 SectionList *dwo_section_list)
429 : SymbolFile(std::move(objfile_sp)),
430 UserID(0x7fffffff00000000), // Used by SymbolFileDWARFDebugMap to
431 // when this class parses .o files to
432 // contain the .o file index/ID
433 m_debug_map_module_wp(), m_debug_map_symfile(nullptr),
434 m_context(m_objfile_sp->GetModule()->GetSectionList(), dwo_section_list),
435 m_fetched_external_modules(false),
436 m_supports_DW_AT_APPLE_objc_complete_type(eLazyBoolCalculate) {}
438 SymbolFileDWARF::~SymbolFileDWARF() {}
440 static ConstString GetDWARFMachOSegmentName() {
441 static ConstString g_dwarf_section_name("__DWARF");
442 return g_dwarf_section_name;
445 UniqueDWARFASTTypeMap &SymbolFileDWARF::GetUniqueDWARFASTTypeMap() {
446 SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile();
447 if (debug_map_symfile)
448 return debug_map_symfile->GetUniqueDWARFASTTypeMap();
450 return m_unique_ast_type_map;
453 llvm::Expected<TypeSystem &>
454 SymbolFileDWARF::GetTypeSystemForLanguage(LanguageType language) {
455 if (SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile())
456 return debug_map_symfile->GetTypeSystemForLanguage(language);
458 auto type_system_or_err =
459 m_objfile_sp->GetModule()->GetTypeSystemForLanguage(language);
460 if (type_system_or_err) {
461 type_system_or_err->SetSymbolFile(this);
463 return type_system_or_err;
466 void SymbolFileDWARF::InitializeObject() {
467 Log *log = LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO);
469 if (!GetGlobalPluginProperties()->IgnoreFileIndexes()) {
470 DWARFDataExtractor apple_names, apple_namespaces, apple_types, apple_objc;
471 LoadSectionData(eSectionTypeDWARFAppleNames, apple_names);
472 LoadSectionData(eSectionTypeDWARFAppleNamespaces, apple_namespaces);
473 LoadSectionData(eSectionTypeDWARFAppleTypes, apple_types);
474 LoadSectionData(eSectionTypeDWARFAppleObjC, apple_objc);
476 m_index = AppleDWARFIndex::Create(
477 *GetObjectFile()->GetModule(), apple_names, apple_namespaces,
478 apple_types, apple_objc, m_context.getOrLoadStrData());
483 DWARFDataExtractor debug_names;
484 LoadSectionData(eSectionTypeDWARFDebugNames, debug_names);
485 if (debug_names.GetByteSize() > 0) {
486 llvm::Expected<std::unique_ptr<DebugNamesDWARFIndex>> index_or =
487 DebugNamesDWARFIndex::Create(*GetObjectFile()->GetModule(),
489 m_context.getOrLoadStrData(), *this);
491 m_index = std::move(*index_or);
494 LLDB_LOG_ERROR(log, index_or.takeError(),
495 "Unable to read .debug_names data: {0}");
500 std::make_unique<ManualDWARFIndex>(*GetObjectFile()->GetModule(), *this);
503 bool SymbolFileDWARF::SupportedVersion(uint16_t version) {
504 return version >= 2 && version <= 5;
507 uint32_t SymbolFileDWARF::CalculateAbilities() {
508 uint32_t abilities = 0;
509 if (m_objfile_sp != nullptr) {
510 const Section *section = nullptr;
511 const SectionList *section_list = m_objfile_sp->GetSectionList();
512 if (section_list == nullptr)
515 uint64_t debug_abbrev_file_size = 0;
516 uint64_t debug_info_file_size = 0;
517 uint64_t debug_line_file_size = 0;
519 section = section_list->FindSectionByName(GetDWARFMachOSegmentName()).get();
522 section_list = §ion->GetChildren();
525 section_list->FindSectionByType(eSectionTypeDWARFDebugInfo, true).get();
526 if (section != nullptr) {
527 debug_info_file_size = section->GetFileSize();
530 section_list->FindSectionByType(eSectionTypeDWARFDebugAbbrev, true)
533 debug_abbrev_file_size = section->GetFileSize();
535 DWARFDebugAbbrev *abbrev = DebugAbbrev();
537 std::set<dw_form_t> invalid_forms;
538 abbrev->GetUnsupportedForms(invalid_forms);
539 if (!invalid_forms.empty()) {
541 error.Printf("unsupported DW_FORM value%s:",
542 invalid_forms.size() > 1 ? "s" : "");
543 for (auto form : invalid_forms)
544 error.Printf(" %#x", form);
545 m_objfile_sp->GetModule()->ReportWarning(
546 "%s", error.GetString().str().c_str());
552 section_list->FindSectionByType(eSectionTypeDWARFDebugLine, true)
555 debug_line_file_size = section->GetFileSize();
557 const char *symfile_dir_cstr =
558 m_objfile_sp->GetFileSpec().GetDirectory().GetCString();
559 if (symfile_dir_cstr) {
560 if (strcasestr(symfile_dir_cstr, ".dsym")) {
561 if (m_objfile_sp->GetType() == ObjectFile::eTypeDebugInfo) {
562 // We have a dSYM file that didn't have a any debug info. If the
563 // string table has a size of 1, then it was made from an
564 // executable with no debug info, or from an executable that was
567 section_list->FindSectionByType(eSectionTypeDWARFDebugStr, true)
569 if (section && section->GetFileSize() == 1) {
570 m_objfile_sp->GetModule()->ReportWarning(
571 "empty dSYM file detected, dSYM was created with an "
572 "executable with no debug info.");
579 if (debug_abbrev_file_size > 0 && debug_info_file_size > 0)
580 abilities |= CompileUnits | Functions | Blocks | GlobalVariables |
581 LocalVariables | VariableTypes;
583 if (debug_line_file_size > 0)
584 abilities |= LineTables;
589 void SymbolFileDWARF::LoadSectionData(lldb::SectionType sect_type,
590 DWARFDataExtractor &data) {
591 ModuleSP module_sp(m_objfile_sp->GetModule());
592 const SectionList *section_list = module_sp->GetSectionList();
596 SectionSP section_sp(section_list->FindSectionByType(sect_type, true));
601 m_objfile_sp->ReadSectionData(section_sp.get(), data);
604 DWARFDebugAbbrev *SymbolFileDWARF::DebugAbbrev() {
608 const DWARFDataExtractor &debug_abbrev_data = m_context.getOrLoadAbbrevData();
609 if (debug_abbrev_data.GetByteSize() == 0)
612 auto abbr = std::make_unique<DWARFDebugAbbrev>();
613 llvm::Error error = abbr->parse(debug_abbrev_data);
615 Log *log = LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO);
616 LLDB_LOG_ERROR(log, std::move(error),
617 "Unable to read .debug_abbrev section: {0}");
621 m_abbr = std::move(abbr);
625 DWARFDebugInfo &SymbolFileDWARF::DebugInfo() {
626 llvm::call_once(m_info_once_flag, [&] {
627 static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
628 Timer scoped_timer(func_cat, "%s this = %p", LLVM_PRETTY_FUNCTION,
629 static_cast<void *>(this));
630 m_info = std::make_unique<DWARFDebugInfo>(*this, m_context);
636 SymbolFileDWARF::GetDWARFCompileUnit(lldb_private::CompileUnit *comp_unit) {
640 // The compile unit ID is the index of the DWARF unit.
641 DWARFUnit *dwarf_cu = DebugInfo().GetUnitAtIndex(comp_unit->GetID());
642 if (dwarf_cu && dwarf_cu->GetUserData() == nullptr)
643 dwarf_cu->SetUserData(comp_unit);
647 DWARFDebugRanges *SymbolFileDWARF::GetDebugRanges() {
649 static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
650 Timer scoped_timer(func_cat, "%s this = %p", LLVM_PRETTY_FUNCTION,
651 static_cast<void *>(this));
653 if (m_context.getOrLoadRangesData().GetByteSize() > 0)
654 m_ranges = std::make_unique<DWARFDebugRanges>();
657 m_ranges->Extract(m_context);
659 return m_ranges.get();
662 /// Make an absolute path out of \p file_spec and remap it using the
663 /// module's source remapping dictionary.
664 static void MakeAbsoluteAndRemap(FileSpec &file_spec, DWARFUnit &dwarf_cu,
665 const ModuleSP &module_sp) {
668 // If we have a full path to the compile unit, we don't need to
669 // resolve the file. This can be expensive e.g. when the source
670 // files are NFS mounted.
671 file_spec.MakeAbsolute(dwarf_cu.GetCompilationDirectory());
673 std::string remapped_file;
674 if (module_sp->RemapSourceFile(file_spec.GetPath(), remapped_file))
675 file_spec.SetFile(remapped_file, FileSpec::Style::native);
678 lldb::CompUnitSP SymbolFileDWARF::ParseCompileUnit(DWARFCompileUnit &dwarf_cu) {
680 CompileUnit *comp_unit = (CompileUnit *)dwarf_cu.GetUserData();
682 // We already parsed this compile unit, had out a shared pointer to it
683 cu_sp = comp_unit->shared_from_this();
685 if (dwarf_cu.GetOffset() == 0 && GetDebugMapSymfile()) {
686 // Let the debug map create the compile unit
687 cu_sp = m_debug_map_symfile->GetCompileUnit(this);
688 dwarf_cu.SetUserData(cu_sp.get());
690 ModuleSP module_sp(m_objfile_sp->GetModule());
692 const DWARFBaseDIE cu_die =
693 dwarf_cu.GetNonSkeletonUnit().GetUnitDIEOnly();
695 FileSpec cu_file_spec(cu_die.GetName(), dwarf_cu.GetPathStyle());
696 MakeAbsoluteAndRemap(cu_file_spec, dwarf_cu, module_sp);
698 LanguageType cu_language = SymbolFileDWARF::LanguageTypeFromDWARF(
699 cu_die.GetAttributeValueAsUnsigned(DW_AT_language, 0));
701 bool is_optimized = dwarf_cu.GetNonSkeletonUnit().GetIsOptimized();
702 BuildCuTranslationTable();
703 cu_sp = std::make_shared<CompileUnit>(
704 module_sp, &dwarf_cu, cu_file_spec,
705 *GetDWARFUnitIndex(dwarf_cu.GetID()), cu_language,
706 is_optimized ? eLazyBoolYes : eLazyBoolNo);
708 dwarf_cu.SetUserData(cu_sp.get());
710 SetCompileUnitAtIndex(dwarf_cu.GetID(), cu_sp);
718 void SymbolFileDWARF::BuildCuTranslationTable() {
719 if (!m_lldb_cu_to_dwarf_unit.empty())
722 DWARFDebugInfo &info = DebugInfo();
723 if (!info.ContainsTypeUnits()) {
724 // We can use a 1-to-1 mapping. No need to build a translation table.
727 for (uint32_t i = 0, num = info.GetNumUnits(); i < num; ++i) {
728 if (auto *cu = llvm::dyn_cast<DWARFCompileUnit>(info.GetUnitAtIndex(i))) {
729 cu->SetID(m_lldb_cu_to_dwarf_unit.size());
730 m_lldb_cu_to_dwarf_unit.push_back(i);
735 llvm::Optional<uint32_t> SymbolFileDWARF::GetDWARFUnitIndex(uint32_t cu_idx) {
736 BuildCuTranslationTable();
737 if (m_lldb_cu_to_dwarf_unit.empty())
739 if (cu_idx >= m_lldb_cu_to_dwarf_unit.size())
741 return m_lldb_cu_to_dwarf_unit[cu_idx];
744 uint32_t SymbolFileDWARF::CalculateNumCompileUnits() {
745 BuildCuTranslationTable();
746 return m_lldb_cu_to_dwarf_unit.empty() ? DebugInfo().GetNumUnits()
747 : m_lldb_cu_to_dwarf_unit.size();
750 CompUnitSP SymbolFileDWARF::ParseCompileUnitAtIndex(uint32_t cu_idx) {
751 ASSERT_MODULE_LOCK(this);
752 if (llvm::Optional<uint32_t> dwarf_idx = GetDWARFUnitIndex(cu_idx)) {
753 if (auto *dwarf_cu = llvm::cast_or_null<DWARFCompileUnit>(
754 DebugInfo().GetUnitAtIndex(*dwarf_idx)))
755 return ParseCompileUnit(*dwarf_cu);
760 Function *SymbolFileDWARF::ParseFunction(CompileUnit &comp_unit,
761 const DWARFDIE &die) {
762 ASSERT_MODULE_LOCK(this);
766 auto type_system_or_err = GetTypeSystemForLanguage(GetLanguage(*die.GetCU()));
767 if (auto err = type_system_or_err.takeError()) {
768 LLDB_LOG_ERROR(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_SYMBOLS),
769 std::move(err), "Unable to parse function");
772 DWARFASTParser *dwarf_ast = type_system_or_err->GetDWARFParser();
776 return dwarf_ast->ParseFunctionFromDWARF(comp_unit, die);
779 lldb::addr_t SymbolFileDWARF::FixupAddress(lldb::addr_t file_addr) {
780 SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile();
781 if (debug_map_symfile)
782 return debug_map_symfile->LinkOSOFileAddress(this, file_addr);
786 bool SymbolFileDWARF::FixupAddress(Address &addr) {
787 SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile();
788 if (debug_map_symfile) {
789 return debug_map_symfile->LinkOSOAddress(addr);
791 // This is a normal DWARF file, no address fixups need to happen
794 lldb::LanguageType SymbolFileDWARF::ParseLanguage(CompileUnit &comp_unit) {
795 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
796 DWARFUnit *dwarf_cu = GetDWARFCompileUnit(&comp_unit);
798 return GetLanguage(*dwarf_cu);
800 return eLanguageTypeUnknown;
803 XcodeSDK SymbolFileDWARF::ParseXcodeSDK(CompileUnit &comp_unit) {
804 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
805 DWARFUnit *dwarf_cu = GetDWARFCompileUnit(&comp_unit);
808 const DWARFBaseDIE cu_die = dwarf_cu->GetNonSkeletonUnit().GetUnitDIEOnly();
811 const char *sdk = cu_die.GetAttributeValueAsString(DW_AT_APPLE_sdk, nullptr);
814 const char *sysroot =
815 cu_die.GetAttributeValueAsString(DW_AT_LLVM_sysroot, "");
816 // Register the sysroot path remapping with the module belonging to
817 // the CU as well as the one belonging to the symbol file. The two
818 // would be different if this is an OSO object and module is the
819 // corresponding debug map, in which case both should be updated.
820 ModuleSP module_sp = comp_unit.GetModule();
822 module_sp->RegisterXcodeSDK(sdk, sysroot);
824 ModuleSP local_module_sp = m_objfile_sp->GetModule();
825 if (local_module_sp && local_module_sp != module_sp)
826 local_module_sp->RegisterXcodeSDK(sdk, sysroot);
831 size_t SymbolFileDWARF::ParseFunctions(CompileUnit &comp_unit) {
832 static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
833 Timer scoped_timer(func_cat, "SymbolFileDWARF::ParseFunctions");
834 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
835 DWARFUnit *dwarf_cu = GetDWARFCompileUnit(&comp_unit);
839 size_t functions_added = 0;
840 dwarf_cu = &dwarf_cu->GetNonSkeletonUnit();
841 for (DWARFDebugInfoEntry &entry : dwarf_cu->dies()) {
842 if (entry.Tag() != DW_TAG_subprogram)
845 DWARFDIE die(dwarf_cu, &entry);
846 if (comp_unit.FindFunctionByUID(die.GetID()))
848 if (ParseFunction(comp_unit, die))
852 return functions_added;
855 bool SymbolFileDWARF::ForEachExternalModule(
856 CompileUnit &comp_unit,
857 llvm::DenseSet<lldb_private::SymbolFile *> &visited_symbol_files,
858 llvm::function_ref<bool(Module &)> lambda) {
859 // Only visit each symbol file once.
860 if (!visited_symbol_files.insert(this).second)
863 UpdateExternalModuleListIfNeeded();
864 for (auto &p : m_external_type_modules) {
865 ModuleSP module = p.second;
869 // Invoke the action and potentially early-exit.
873 for (std::size_t i = 0; i < module->GetNumCompileUnits(); ++i) {
874 auto cu = module->GetCompileUnitAtIndex(i);
875 bool early_exit = cu->ForEachExternalModule(visited_symbol_files, lambda);
883 bool SymbolFileDWARF::ParseSupportFiles(CompileUnit &comp_unit,
884 FileSpecList &support_files) {
885 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
886 DWARFUnit *dwarf_cu = GetDWARFCompileUnit(&comp_unit);
890 dw_offset_t offset = dwarf_cu->GetLineTableOffset();
891 if (offset == DW_INVALID_OFFSET)
894 llvm::DWARFDebugLine::Prologue prologue;
895 if (!ParseLLVMLineTablePrologue(m_context, prologue, offset,
896 dwarf_cu->GetOffset()))
899 comp_unit.SetSupportFiles(ParseSupportFilesFromPrologue(
900 comp_unit.GetModule(), prologue, dwarf_cu->GetPathStyle(),
901 dwarf_cu->GetCompilationDirectory().GetCString()));
906 FileSpec SymbolFileDWARF::GetFile(DWARFUnit &unit, size_t file_idx) {
907 if (auto *dwarf_cu = llvm::dyn_cast<DWARFCompileUnit>(&unit)) {
908 if (CompileUnit *lldb_cu = GetCompUnitForDWARFCompUnit(*dwarf_cu))
909 return lldb_cu->GetSupportFiles().GetFileSpecAtIndex(file_idx);
913 auto &tu = llvm::cast<DWARFTypeUnit>(unit);
914 return GetTypeUnitSupportFiles(tu).GetFileSpecAtIndex(file_idx);
918 SymbolFileDWARF::GetTypeUnitSupportFiles(DWARFTypeUnit &tu) {
919 static FileSpecList empty_list;
921 dw_offset_t offset = tu.GetLineTableOffset();
922 if (offset == DW_INVALID_OFFSET ||
923 offset == llvm::DenseMapInfo<dw_offset_t>::getEmptyKey() ||
924 offset == llvm::DenseMapInfo<dw_offset_t>::getTombstoneKey())
927 // Many type units can share a line table, so parse the support file list
928 // once, and cache it based on the offset field.
929 auto iter_bool = m_type_unit_support_files.try_emplace(offset);
930 FileSpecList &list = iter_bool.first->second;
931 if (iter_bool.second) {
932 uint64_t line_table_offset = offset;
933 llvm::DWARFDataExtractor data = m_context.getOrLoadLineData().GetAsLLVM();
934 llvm::DWARFContext &ctx = m_context.GetAsLLVM();
935 llvm::DWARFDebugLine::Prologue prologue;
936 auto report = [](llvm::Error error) {
937 Log *log = LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO);
938 LLDB_LOG_ERROR(log, std::move(error),
939 "SymbolFileDWARF::GetTypeUnitSupportFiles failed to parse "
940 "the line table prologue");
942 llvm::Error error = prologue.parse(data, &line_table_offset, report, ctx);
944 report(std::move(error));
946 list = ParseSupportFilesFromPrologue(GetObjectFile()->GetModule(),
947 prologue, tu.GetPathStyle());
953 bool SymbolFileDWARF::ParseIsOptimized(CompileUnit &comp_unit) {
954 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
955 DWARFUnit *dwarf_cu = GetDWARFCompileUnit(&comp_unit);
957 return dwarf_cu->GetIsOptimized();
961 bool SymbolFileDWARF::ParseImportedModules(
962 const lldb_private::SymbolContext &sc,
963 std::vector<SourceModule> &imported_modules) {
964 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
965 assert(sc.comp_unit);
966 DWARFUnit *dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
969 if (!ClangModulesDeclVendor::LanguageSupportsClangModules(
970 sc.comp_unit->GetLanguage()))
972 UpdateExternalModuleListIfNeeded();
974 const DWARFDIE die = dwarf_cu->DIE();
978 for (DWARFDIE child_die = die.GetFirstChild(); child_die;
979 child_die = child_die.GetSibling()) {
980 if (child_die.Tag() != DW_TAG_imported_declaration)
983 DWARFDIE module_die = child_die.GetReferencedDIE(DW_AT_import);
984 if (module_die.Tag() != DW_TAG_module)
987 if (const char *name =
988 module_die.GetAttributeValueAsString(DW_AT_name, nullptr)) {
990 module.path.push_back(ConstString(name));
992 DWARFDIE parent_die = module_die;
993 while ((parent_die = parent_die.GetParent())) {
994 if (parent_die.Tag() != DW_TAG_module)
996 if (const char *name =
997 parent_die.GetAttributeValueAsString(DW_AT_name, nullptr))
998 module.path.push_back(ConstString(name));
1000 std::reverse(module.path.begin(), module.path.end());
1001 if (const char *include_path = module_die.GetAttributeValueAsString(
1002 DW_AT_LLVM_include_path, nullptr)) {
1003 FileSpec include_spec(include_path, dwarf_cu->GetPathStyle());
1004 MakeAbsoluteAndRemap(include_spec, *dwarf_cu, m_objfile_sp->GetModule());
1005 module.search_path = ConstString(include_spec.GetPath());
1007 if (const char *sysroot = dwarf_cu->DIE().GetAttributeValueAsString(
1008 DW_AT_LLVM_sysroot, nullptr))
1009 module.sysroot = ConstString(sysroot);
1010 imported_modules.push_back(module);
1016 bool SymbolFileDWARF::ParseLineTable(CompileUnit &comp_unit) {
1017 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1018 if (comp_unit.GetLineTable() != nullptr)
1021 DWARFUnit *dwarf_cu = GetDWARFCompileUnit(&comp_unit);
1025 dw_offset_t offset = dwarf_cu->GetLineTableOffset();
1026 if (offset == DW_INVALID_OFFSET)
1029 llvm::DWARFDebugLine line;
1030 const llvm::DWARFDebugLine::LineTable *line_table =
1031 ParseLLVMLineTable(m_context, line, offset, dwarf_cu->GetOffset());
1036 // FIXME: Rather than parsing the whole line table and then copying it over
1037 // into LLDB, we should explore using a callback to populate the line table
1038 // while we parse to reduce memory usage.
1039 std::vector<std::unique_ptr<LineSequence>> sequences;
1040 // The Sequences view contains only valid line sequences. Don't iterate over
1041 // the Rows directly.
1042 for (const llvm::DWARFDebugLine::Sequence &seq : line_table->Sequences) {
1043 std::unique_ptr<LineSequence> sequence =
1044 LineTable::CreateLineSequenceContainer();
1045 for (unsigned idx = seq.FirstRowIndex; idx < seq.LastRowIndex; ++idx) {
1046 const llvm::DWARFDebugLine::Row &row = line_table->Rows[idx];
1047 LineTable::AppendLineEntryToSequence(
1048 sequence.get(), row.Address.Address, row.Line, row.Column, row.File,
1049 row.IsStmt, row.BasicBlock, row.PrologueEnd, row.EpilogueBegin,
1052 sequences.push_back(std::move(sequence));
1055 std::unique_ptr<LineTable> line_table_up =
1056 std::make_unique<LineTable>(&comp_unit, std::move(sequences));
1058 if (SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile()) {
1059 // We have an object file that has a line table with addresses that are not
1060 // linked. We need to link the line table and convert the addresses that
1061 // are relative to the .o file into addresses for the main executable.
1062 comp_unit.SetLineTable(
1063 debug_map_symfile->LinkOSOLineTable(this, line_table_up.get()));
1065 comp_unit.SetLineTable(line_table_up.release());
1071 lldb_private::DebugMacrosSP
1072 SymbolFileDWARF::ParseDebugMacros(lldb::offset_t *offset) {
1073 auto iter = m_debug_macros_map.find(*offset);
1074 if (iter != m_debug_macros_map.end())
1075 return iter->second;
1077 const DWARFDataExtractor &debug_macro_data = m_context.getOrLoadMacroData();
1078 if (debug_macro_data.GetByteSize() == 0)
1079 return DebugMacrosSP();
1081 lldb_private::DebugMacrosSP debug_macros_sp(new lldb_private::DebugMacros());
1082 m_debug_macros_map[*offset] = debug_macros_sp;
1084 const DWARFDebugMacroHeader &header =
1085 DWARFDebugMacroHeader::ParseHeader(debug_macro_data, offset);
1086 DWARFDebugMacroEntry::ReadMacroEntries(
1087 debug_macro_data, m_context.getOrLoadStrData(), header.OffsetIs64Bit(),
1088 offset, this, debug_macros_sp);
1090 return debug_macros_sp;
1093 bool SymbolFileDWARF::ParseDebugMacros(CompileUnit &comp_unit) {
1094 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1096 DWARFUnit *dwarf_cu = GetDWARFCompileUnit(&comp_unit);
1097 if (dwarf_cu == nullptr)
1100 const DWARFBaseDIE dwarf_cu_die = dwarf_cu->GetUnitDIEOnly();
1104 lldb::offset_t sect_offset =
1105 dwarf_cu_die.GetAttributeValueAsUnsigned(DW_AT_macros, DW_INVALID_OFFSET);
1106 if (sect_offset == DW_INVALID_OFFSET)
1107 sect_offset = dwarf_cu_die.GetAttributeValueAsUnsigned(DW_AT_GNU_macros,
1109 if (sect_offset == DW_INVALID_OFFSET)
1112 comp_unit.SetDebugMacros(ParseDebugMacros(§_offset));
1117 size_t SymbolFileDWARF::ParseBlocksRecursive(
1118 lldb_private::CompileUnit &comp_unit, Block *parent_block,
1119 const DWARFDIE &orig_die, addr_t subprogram_low_pc, uint32_t depth) {
1120 size_t blocks_added = 0;
1121 DWARFDIE die = orig_die;
1123 dw_tag_t tag = die.Tag();
1126 case DW_TAG_inlined_subroutine:
1127 case DW_TAG_subprogram:
1128 case DW_TAG_lexical_block: {
1129 Block *block = nullptr;
1130 if (tag == DW_TAG_subprogram) {
1131 // Skip any DW_TAG_subprogram DIEs that are inside of a normal or
1132 // inlined functions. These will be parsed on their own as separate
1138 block = parent_block;
1140 BlockSP block_sp(new Block(die.GetID()));
1141 parent_block->AddChild(block_sp);
1142 block = block_sp.get();
1144 DWARFRangeList ranges;
1145 const char *name = nullptr;
1146 const char *mangled_name = nullptr;
1150 int decl_column = 0;
1153 int call_column = 0;
1154 if (die.GetDIENamesAndRanges(name, mangled_name, ranges, decl_file,
1155 decl_line, decl_column, call_file, call_line,
1156 call_column, nullptr)) {
1157 if (tag == DW_TAG_subprogram) {
1158 assert(subprogram_low_pc == LLDB_INVALID_ADDRESS);
1159 subprogram_low_pc = ranges.GetMinRangeBase(0);
1160 } else if (tag == DW_TAG_inlined_subroutine) {
1161 // We get called here for inlined subroutines in two ways. The first
1162 // time is when we are making the Function object for this inlined
1163 // concrete instance. Since we're creating a top level block at
1164 // here, the subprogram_low_pc will be LLDB_INVALID_ADDRESS. So we
1165 // need to adjust the containing address. The second time is when we
1166 // are parsing the blocks inside the function that contains the
1167 // inlined concrete instance. Since these will be blocks inside the
1168 // containing "real" function the offset will be for that function.
1169 if (subprogram_low_pc == LLDB_INVALID_ADDRESS) {
1170 subprogram_low_pc = ranges.GetMinRangeBase(0);
1174 const size_t num_ranges = ranges.GetSize();
1175 for (size_t i = 0; i < num_ranges; ++i) {
1176 const DWARFRangeList::Entry &range = ranges.GetEntryRef(i);
1177 const addr_t range_base = range.GetRangeBase();
1178 if (range_base >= subprogram_low_pc)
1179 block->AddRange(Block::Range(range_base - subprogram_low_pc,
1180 range.GetByteSize()));
1182 GetObjectFile()->GetModule()->ReportError(
1183 "0x%8.8" PRIx64 ": adding range [0x%" PRIx64 "-0x%" PRIx64
1184 ") which has a base that is less than the function's low PC "
1185 "0x%" PRIx64 ". Please file a bug and attach the file at the "
1186 "start of this error message",
1187 block->GetID(), range_base, range.GetRangeEnd(),
1191 block->FinalizeRanges();
1193 if (tag != DW_TAG_subprogram &&
1194 (name != nullptr || mangled_name != nullptr)) {
1195 std::unique_ptr<Declaration> decl_up;
1196 if (decl_file != 0 || decl_line != 0 || decl_column != 0)
1197 decl_up = std::make_unique<Declaration>(
1198 comp_unit.GetSupportFiles().GetFileSpecAtIndex(decl_file),
1199 decl_line, decl_column);
1201 std::unique_ptr<Declaration> call_up;
1202 if (call_file != 0 || call_line != 0 || call_column != 0)
1203 call_up = std::make_unique<Declaration>(
1204 comp_unit.GetSupportFiles().GetFileSpecAtIndex(call_file),
1205 call_line, call_column);
1207 block->SetInlinedFunctionInfo(name, mangled_name, decl_up.get(),
1213 if (die.HasChildren()) {
1215 ParseBlocksRecursive(comp_unit, block, die.GetFirstChild(),
1216 subprogram_low_pc, depth + 1);
1224 // Only parse siblings of the block if we are not at depth zero. A depth of
1225 // zero indicates we are currently parsing the top level DW_TAG_subprogram
1231 die = die.GetSibling();
1233 return blocks_added;
1236 bool SymbolFileDWARF::ClassOrStructIsVirtual(const DWARFDIE &parent_die) {
1238 for (DWARFDIE die = parent_die.GetFirstChild(); die;
1239 die = die.GetSibling()) {
1240 dw_tag_t tag = die.Tag();
1241 bool check_virtuality = false;
1243 case DW_TAG_inheritance:
1244 case DW_TAG_subprogram:
1245 check_virtuality = true;
1250 if (check_virtuality) {
1251 if (die.GetAttributeValueAsUnsigned(DW_AT_virtuality, 0) != 0)
1259 void SymbolFileDWARF::ParseDeclsForContext(CompilerDeclContext decl_ctx) {
1260 auto *type_system = decl_ctx.GetTypeSystem();
1261 if (type_system != nullptr)
1262 type_system->GetDWARFParser()->EnsureAllDIEsInDeclContextHaveBeenParsed(
1266 user_id_t SymbolFileDWARF::GetUID(DIERef ref) {
1267 if (GetDebugMapSymfile())
1268 return GetID() | ref.die_offset();
1270 return user_id_t(GetDwoNum().getValueOr(0x7fffffff)) << 32 |
1272 (lldb::user_id_t(ref.section() == DIERef::Section::DebugTypes) << 63);
1275 llvm::Optional<SymbolFileDWARF::DecodedUID>
1276 SymbolFileDWARF::DecodeUID(lldb::user_id_t uid) {
1277 // This method can be called without going through the symbol vendor so we
1278 // need to lock the module.
1279 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1280 // Anytime we get a "lldb::user_id_t" from an lldb_private::SymbolFile API we
1281 // must make sure we use the correct DWARF file when resolving things. On
1282 // MacOSX, when using SymbolFileDWARFDebugMap, we will use multiple
1283 // SymbolFileDWARF classes, one for each .o file. We can often end up with
1284 // references to other DWARF objects and we must be ready to receive a
1285 // "lldb::user_id_t" that specifies a DIE from another SymbolFileDWARF
1287 if (SymbolFileDWARFDebugMap *debug_map = GetDebugMapSymfile()) {
1288 SymbolFileDWARF *dwarf = debug_map->GetSymbolFileByOSOIndex(
1289 debug_map->GetOSOIndexFromUserID(uid));
1291 *dwarf, {llvm::None, DIERef::Section::DebugInfo, dw_offset_t(uid)}};
1293 dw_offset_t die_offset = uid;
1294 if (die_offset == DW_INVALID_OFFSET)
1297 DIERef::Section section =
1298 uid >> 63 ? DIERef::Section::DebugTypes : DIERef::Section::DebugInfo;
1300 llvm::Optional<uint32_t> dwo_num = uid >> 32 & 0x7fffffff;
1301 if (*dwo_num == 0x7fffffff)
1302 dwo_num = llvm::None;
1304 return DecodedUID{*this, {dwo_num, section, die_offset}};
1308 SymbolFileDWARF::GetDIE(lldb::user_id_t uid) {
1309 // This method can be called without going through the symbol vendor so we
1310 // need to lock the module.
1311 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1313 llvm::Optional<DecodedUID> decoded = DecodeUID(uid);
1316 return decoded->dwarf.GetDIE(decoded->ref);
1321 CompilerDecl SymbolFileDWARF::GetDeclForUID(lldb::user_id_t type_uid) {
1322 // This method can be called without going through the symbol vendor so we
1323 // need to lock the module.
1324 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1325 // Anytime we have a lldb::user_id_t, we must get the DIE by calling
1326 // SymbolFileDWARF::GetDIE(). See comments inside the
1327 // SymbolFileDWARF::GetDIE() for details.
1328 if (DWARFDIE die = GetDIE(type_uid))
1329 return GetDecl(die);
1330 return CompilerDecl();
1334 SymbolFileDWARF::GetDeclContextForUID(lldb::user_id_t type_uid) {
1335 // This method can be called without going through the symbol vendor so we
1336 // need to lock the module.
1337 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1338 // Anytime we have a lldb::user_id_t, we must get the DIE by calling
1339 // SymbolFileDWARF::GetDIE(). See comments inside the
1340 // SymbolFileDWARF::GetDIE() for details.
1341 if (DWARFDIE die = GetDIE(type_uid))
1342 return GetDeclContext(die);
1343 return CompilerDeclContext();
1347 SymbolFileDWARF::GetDeclContextContainingUID(lldb::user_id_t type_uid) {
1348 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1349 // Anytime we have a lldb::user_id_t, we must get the DIE by calling
1350 // SymbolFileDWARF::GetDIE(). See comments inside the
1351 // SymbolFileDWARF::GetDIE() for details.
1352 if (DWARFDIE die = GetDIE(type_uid))
1353 return GetContainingDeclContext(die);
1354 return CompilerDeclContext();
1357 Type *SymbolFileDWARF::ResolveTypeUID(lldb::user_id_t type_uid) {
1358 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1359 // Anytime we have a lldb::user_id_t, we must get the DIE by calling
1360 // SymbolFileDWARF::GetDIE(). See comments inside the
1361 // SymbolFileDWARF::GetDIE() for details.
1362 if (DWARFDIE type_die = GetDIE(type_uid))
1363 return type_die.ResolveType();
1368 llvm::Optional<SymbolFile::ArrayInfo>
1369 SymbolFileDWARF::GetDynamicArrayInfoForUID(
1370 lldb::user_id_t type_uid, const lldb_private::ExecutionContext *exe_ctx) {
1371 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1372 if (DWARFDIE type_die = GetDIE(type_uid))
1373 return DWARFASTParser::ParseChildArrayInfo(type_die, exe_ctx);
1378 Type *SymbolFileDWARF::ResolveTypeUID(const DIERef &die_ref) {
1379 return ResolveType(GetDIE(die_ref), true);
1382 Type *SymbolFileDWARF::ResolveTypeUID(const DWARFDIE &die,
1383 bool assert_not_being_parsed) {
1385 Log *log(LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
1387 GetObjectFile()->GetModule()->LogMessage(
1388 log, "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s'",
1389 die.GetOffset(), die.GetTagAsCString(), die.GetName());
1391 // We might be coming in in the middle of a type tree (a class within a
1392 // class, an enum within a class), so parse any needed parent DIEs before
1393 // we get to this one...
1394 DWARFDIE decl_ctx_die = GetDeclContextDIEContainingDIE(die);
1397 switch (decl_ctx_die.Tag()) {
1398 case DW_TAG_structure_type:
1399 case DW_TAG_union_type:
1400 case DW_TAG_class_type: {
1401 // Get the type, which could be a forward declaration
1403 GetObjectFile()->GetModule()->LogMessage(
1405 "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' "
1406 "resolve parent forward type for 0x%8.8x",
1407 die.GetOffset(), die.GetTagAsCString(), die.GetName(),
1408 decl_ctx_die.GetOffset());
1416 return ResolveType(die);
1421 // This function is used when SymbolFileDWARFDebugMap owns a bunch of
1422 // SymbolFileDWARF objects to detect if this DWARF file is the one that can
1423 // resolve a compiler_type.
1424 bool SymbolFileDWARF::HasForwardDeclForClangType(
1425 const CompilerType &compiler_type) {
1426 CompilerType compiler_type_no_qualifiers =
1427 ClangUtil::RemoveFastQualifiers(compiler_type);
1428 if (GetForwardDeclClangTypeToDie().count(
1429 compiler_type_no_qualifiers.GetOpaqueQualType())) {
1432 TypeSystem *type_system = compiler_type.GetTypeSystem();
1434 TypeSystemClang *clang_type_system =
1435 llvm::dyn_cast_or_null<TypeSystemClang>(type_system);
1436 if (!clang_type_system)
1438 DWARFASTParserClang *ast_parser =
1439 static_cast<DWARFASTParserClang *>(clang_type_system->GetDWARFParser());
1440 return ast_parser->GetClangASTImporter().CanImport(compiler_type);
1443 bool SymbolFileDWARF::CompleteType(CompilerType &compiler_type) {
1444 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1446 TypeSystemClang *clang_type_system =
1447 llvm::dyn_cast_or_null<TypeSystemClang>(compiler_type.GetTypeSystem());
1448 if (clang_type_system) {
1449 DWARFASTParserClang *ast_parser =
1450 static_cast<DWARFASTParserClang *>(clang_type_system->GetDWARFParser());
1452 ast_parser->GetClangASTImporter().CanImport(compiler_type))
1453 return ast_parser->GetClangASTImporter().CompleteType(compiler_type);
1456 // We have a struct/union/class/enum that needs to be fully resolved.
1457 CompilerType compiler_type_no_qualifiers =
1458 ClangUtil::RemoveFastQualifiers(compiler_type);
1459 auto die_it = GetForwardDeclClangTypeToDie().find(
1460 compiler_type_no_qualifiers.GetOpaqueQualType());
1461 if (die_it == GetForwardDeclClangTypeToDie().end()) {
1462 // We have already resolved this type...
1466 DWARFDIE dwarf_die = GetDIE(die_it->getSecond());
1468 // Once we start resolving this type, remove it from the forward
1469 // declaration map in case anyone child members or other types require this
1470 // type to get resolved. The type will get resolved when all of the calls
1471 // to SymbolFileDWARF::ResolveClangOpaqueTypeDefinition are done.
1472 GetForwardDeclClangTypeToDie().erase(die_it);
1474 Type *type = GetDIEToType().lookup(dwarf_die.GetDIE());
1476 Log *log(LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO |
1477 DWARF_LOG_TYPE_COMPLETION));
1479 GetObjectFile()->GetModule()->LogMessageVerboseBacktrace(
1480 log, "0x%8.8" PRIx64 ": %s '%s' resolving forward declaration...",
1481 dwarf_die.GetID(), dwarf_die.GetTagAsCString(),
1482 type->GetName().AsCString());
1483 assert(compiler_type);
1484 if (DWARFASTParser *dwarf_ast = GetDWARFParser(*dwarf_die.GetCU()))
1485 return dwarf_ast->CompleteTypeFromDWARF(dwarf_die, type, compiler_type);
1490 Type *SymbolFileDWARF::ResolveType(const DWARFDIE &die,
1491 bool assert_not_being_parsed,
1492 bool resolve_function_context) {
1494 Type *type = GetTypeForDIE(die, resolve_function_context).get();
1496 if (assert_not_being_parsed) {
1497 if (type != DIE_IS_BEING_PARSED)
1500 GetObjectFile()->GetModule()->ReportError(
1501 "Parsing a die that is being parsed die: 0x%8.8x: %s %s",
1502 die.GetOffset(), die.GetTagAsCString(), die.GetName());
1511 SymbolFileDWARF::GetCompUnitForDWARFCompUnit(DWARFCompileUnit &dwarf_cu) {
1512 if (dwarf_cu.IsDWOUnit()) {
1513 DWARFCompileUnit *non_dwo_cu =
1514 static_cast<DWARFCompileUnit *>(dwarf_cu.GetUserData());
1516 return non_dwo_cu->GetSymbolFileDWARF().GetCompUnitForDWARFCompUnit(
1519 // Check if the symbol vendor already knows about this compile unit?
1520 if (dwarf_cu.GetUserData() == nullptr) {
1521 // The symbol vendor doesn't know about this compile unit, we need to parse
1522 // and add it to the symbol vendor object.
1523 return ParseCompileUnit(dwarf_cu).get();
1525 return static_cast<CompileUnit *>(dwarf_cu.GetUserData());
1528 void SymbolFileDWARF::GetObjCMethods(
1529 ConstString class_name, llvm::function_ref<bool(DWARFDIE die)> callback) {
1530 m_index->GetObjCMethods(class_name, callback);
1533 bool SymbolFileDWARF::GetFunction(const DWARFDIE &die, SymbolContext &sc) {
1536 if (die && llvm::isa<DWARFCompileUnit>(die.GetCU())) {
1537 // Check if the symbol vendor already knows about this compile unit?
1539 GetCompUnitForDWARFCompUnit(llvm::cast<DWARFCompileUnit>(*die.GetCU()));
1541 sc.function = sc.comp_unit->FindFunctionByUID(die.GetID()).get();
1542 if (sc.function == nullptr)
1543 sc.function = ParseFunction(*sc.comp_unit, die);
1546 sc.module_sp = sc.function->CalculateSymbolContextModule();
1554 lldb::ModuleSP SymbolFileDWARF::GetExternalModule(ConstString name) {
1555 UpdateExternalModuleListIfNeeded();
1556 const auto &pos = m_external_type_modules.find(name);
1557 if (pos != m_external_type_modules.end())
1560 return lldb::ModuleSP();
1564 SymbolFileDWARF::GetDIE(const DIERef &die_ref) {
1565 if (die_ref.dwo_num()) {
1566 SymbolFileDWARF *dwarf = *die_ref.dwo_num() == 0x3fffffff
1567 ? m_dwp_symfile.get()
1569 .GetUnitAtIndex(*die_ref.dwo_num())
1570 ->GetDwoSymbolFile();
1571 return dwarf->DebugInfo().GetDIE(die_ref);
1574 return DebugInfo().GetDIE(die_ref);
1577 /// Return the DW_AT_(GNU_)dwo_name.
1578 static const char *GetDWOName(DWARFCompileUnit &dwarf_cu,
1579 const DWARFDebugInfoEntry &cu_die) {
1580 const char *dwo_name =
1581 cu_die.GetAttributeValueAsString(&dwarf_cu, DW_AT_GNU_dwo_name, nullptr);
1584 cu_die.GetAttributeValueAsString(&dwarf_cu, DW_AT_dwo_name, nullptr);
1588 /// Return the DW_AT_(GNU_)dwo_id.
1589 /// FIXME: Technically 0 is a valid hash.
1590 static uint64_t GetDWOId(DWARFCompileUnit &dwarf_cu,
1591 const DWARFDebugInfoEntry &cu_die) {
1593 cu_die.GetAttributeValueAsUnsigned(&dwarf_cu, DW_AT_GNU_dwo_id, 0);
1595 dwo_id = cu_die.GetAttributeValueAsUnsigned(&dwarf_cu, DW_AT_dwo_id, 0);
1599 llvm::Optional<uint64_t> SymbolFileDWARF::GetDWOId() {
1600 if (GetNumCompileUnits() == 1) {
1601 if (auto comp_unit = GetCompileUnitAtIndex(0))
1602 if (DWARFCompileUnit *cu = llvm::dyn_cast_or_null<DWARFCompileUnit>(
1603 GetDWARFCompileUnit(comp_unit.get())))
1604 if (DWARFDebugInfoEntry *cu_die = cu->DIE().GetDIE())
1605 if (uint64_t dwo_id = ::GetDWOId(*cu, *cu_die))
1611 std::shared_ptr<SymbolFileDWARFDwo>
1612 SymbolFileDWARF::GetDwoSymbolFileForCompileUnit(
1613 DWARFUnit &unit, const DWARFDebugInfoEntry &cu_die) {
1614 // If this is a Darwin-style debug map (non-.dSYM) symbol file,
1615 // never attempt to load ELF-style DWO files since the -gmodules
1616 // support uses the same DWO machanism to specify full debug info
1617 // files for modules. This is handled in
1618 // UpdateExternalModuleListIfNeeded().
1619 if (GetDebugMapSymfile())
1622 DWARFCompileUnit *dwarf_cu = llvm::dyn_cast<DWARFCompileUnit>(&unit);
1623 // Only compile units can be split into two parts.
1627 const char *dwo_name = GetDWOName(*dwarf_cu, cu_die);
1631 if (std::shared_ptr<SymbolFileDWARFDwo> dwp_sp = GetDwpSymbolFile())
1634 FileSpec dwo_file(dwo_name);
1635 FileSystem::Instance().Resolve(dwo_file);
1636 if (dwo_file.IsRelative()) {
1637 const char *comp_dir =
1638 cu_die.GetAttributeValueAsString(dwarf_cu, DW_AT_comp_dir, nullptr);
1642 dwo_file.SetFile(comp_dir, FileSpec::Style::native);
1643 FileSystem::Instance().Resolve(dwo_file);
1644 dwo_file.AppendPathComponent(dwo_name);
1647 if (!FileSystem::Instance().Exists(dwo_file))
1650 const lldb::offset_t file_offset = 0;
1651 DataBufferSP dwo_file_data_sp;
1652 lldb::offset_t dwo_file_data_offset = 0;
1653 ObjectFileSP dwo_obj_file = ObjectFile::FindPlugin(
1654 GetObjectFile()->GetModule(), &dwo_file, file_offset,
1655 FileSystem::Instance().GetByteSize(dwo_file), dwo_file_data_sp,
1656 dwo_file_data_offset);
1657 if (dwo_obj_file == nullptr)
1660 return std::make_shared<SymbolFileDWARFDwo>(*this, dwo_obj_file,
1664 void SymbolFileDWARF::UpdateExternalModuleListIfNeeded() {
1665 if (m_fetched_external_modules)
1667 m_fetched_external_modules = true;
1668 DWARFDebugInfo &debug_info = DebugInfo();
1670 // Follow DWO skeleton unit breadcrumbs.
1671 const uint32_t num_compile_units = GetNumCompileUnits();
1672 for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx) {
1674 llvm::dyn_cast<DWARFCompileUnit>(debug_info.GetUnitAtIndex(cu_idx));
1678 const DWARFBaseDIE die = dwarf_cu->GetUnitDIEOnly();
1679 if (!die || die.HasChildren() || !die.GetDIE())
1682 const char *name = die.GetAttributeValueAsString(DW_AT_name, nullptr);
1686 ConstString const_name(name);
1687 ModuleSP &module_sp = m_external_type_modules[const_name];
1691 const char *dwo_path = GetDWOName(*dwarf_cu, *die.GetDIE());
1695 ModuleSpec dwo_module_spec;
1696 dwo_module_spec.GetFileSpec().SetFile(dwo_path, FileSpec::Style::native);
1697 if (dwo_module_spec.GetFileSpec().IsRelative()) {
1698 const char *comp_dir =
1699 die.GetAttributeValueAsString(DW_AT_comp_dir, nullptr);
1701 dwo_module_spec.GetFileSpec().SetFile(comp_dir,
1702 FileSpec::Style::native);
1703 FileSystem::Instance().Resolve(dwo_module_spec.GetFileSpec());
1704 dwo_module_spec.GetFileSpec().AppendPathComponent(dwo_path);
1707 dwo_module_spec.GetArchitecture() =
1708 m_objfile_sp->GetModule()->GetArchitecture();
1710 // When LLDB loads "external" modules it looks at the presence of
1711 // DW_AT_dwo_name. However, when the already created module
1712 // (corresponding to .dwo itself) is being processed, it will see
1713 // the presence of DW_AT_dwo_name (which contains the name of dwo
1714 // file) and will try to call ModuleList::GetSharedModule
1715 // again. In some cases (i.e., for empty files) Clang 4.0
1716 // generates a *.dwo file which has DW_AT_dwo_name, but no
1717 // DW_AT_comp_dir. In this case the method
1718 // ModuleList::GetSharedModule will fail and the warning will be
1719 // printed. However, as one can notice in this case we don't
1720 // actually need to try to load the already loaded module
1721 // (corresponding to .dwo) so we simply skip it.
1722 if (m_objfile_sp->GetFileSpec().GetFileNameExtension() == ".dwo" &&
1723 llvm::StringRef(m_objfile_sp->GetFileSpec().GetPath())
1724 .endswith(dwo_module_spec.GetFileSpec().GetPath())) {
1728 Status error = ModuleList::GetSharedModule(dwo_module_spec, module_sp,
1729 nullptr, nullptr, nullptr);
1731 GetObjectFile()->GetModule()->ReportWarning(
1732 "0x%8.8x: unable to locate module needed for external types: "
1733 "%s\nerror: %s\nDebugging will be degraded due to missing "
1734 "types. Rebuilding the project will regenerate the needed "
1736 die.GetOffset(), dwo_module_spec.GetFileSpec().GetPath().c_str(),
1737 error.AsCString("unknown error"));
1741 // Verify the DWO hash.
1742 // FIXME: Technically "0" is a valid hash.
1743 uint64_t dwo_id = ::GetDWOId(*dwarf_cu, *die.GetDIE());
1748 llvm::dyn_cast_or_null<SymbolFileDWARF>(module_sp->GetSymbolFile());
1751 llvm::Optional<uint64_t> dwo_dwo_id = dwo_symfile->GetDWOId();
1755 if (dwo_id != dwo_dwo_id) {
1756 GetObjectFile()->GetModule()->ReportWarning(
1757 "0x%8.8x: Module %s is out-of-date (hash mismatch). Type information "
1758 "from this module may be incomplete or inconsistent with the rest of "
1759 "the program. Rebuilding the project will regenerate the needed "
1761 die.GetOffset(), dwo_module_spec.GetFileSpec().GetPath().c_str());
1766 SymbolFileDWARF::GlobalVariableMap &SymbolFileDWARF::GetGlobalAranges() {
1767 if (!m_global_aranges_up) {
1768 m_global_aranges_up = std::make_unique<GlobalVariableMap>();
1770 ModuleSP module_sp = GetObjectFile()->GetModule();
1772 const size_t num_cus = module_sp->GetNumCompileUnits();
1773 for (size_t i = 0; i < num_cus; ++i) {
1774 CompUnitSP cu_sp = module_sp->GetCompileUnitAtIndex(i);
1776 VariableListSP globals_sp = cu_sp->GetVariableList(true);
1778 const size_t num_globals = globals_sp->GetSize();
1779 for (size_t g = 0; g < num_globals; ++g) {
1780 VariableSP var_sp = globals_sp->GetVariableAtIndex(g);
1781 if (var_sp && !var_sp->GetLocationIsConstantValueData()) {
1782 const DWARFExpression &location = var_sp->LocationExpression();
1783 Value location_result;
1785 if (location.Evaluate(nullptr, LLDB_INVALID_ADDRESS, nullptr,
1786 nullptr, location_result, &error)) {
1787 if (location_result.GetValueType() ==
1788 Value::eValueTypeFileAddress) {
1789 lldb::addr_t file_addr =
1790 location_result.GetScalar().ULongLong();
1791 lldb::addr_t byte_size = 1;
1792 if (var_sp->GetType())
1794 var_sp->GetType()->GetByteSize().getValueOr(0);
1795 m_global_aranges_up->Append(GlobalVariableMap::Entry(
1796 file_addr, byte_size, var_sp.get()));
1805 m_global_aranges_up->Sort();
1807 return *m_global_aranges_up;
1810 void SymbolFileDWARF::ResolveFunctionAndBlock(lldb::addr_t file_vm_addr,
1812 SymbolContext &sc) {
1813 assert(sc.comp_unit);
1814 DWARFUnit &cu = GetDWARFCompileUnit(sc.comp_unit)->GetNonSkeletonUnit();
1815 DWARFDIE function_die = cu.LookupAddress(file_vm_addr);
1818 sc.function = sc.comp_unit->FindFunctionByUID(function_die.GetID()).get();
1819 if (sc.function == nullptr)
1820 sc.function = ParseFunction(*sc.comp_unit, function_die);
1822 if (sc.function && lookup_block)
1823 block_die = function_die.LookupDeepestBlock(file_vm_addr);
1826 if (!sc.function || ! lookup_block)
1829 Block &block = sc.function->GetBlock(true);
1831 sc.block = block.FindBlockByID(block_die.GetID());
1833 sc.block = block.FindBlockByID(function_die.GetID());
1836 uint32_t SymbolFileDWARF::ResolveSymbolContext(const Address &so_addr,
1837 SymbolContextItem resolve_scope,
1838 SymbolContext &sc) {
1839 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1840 static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
1841 Timer scoped_timer(func_cat,
1843 "ResolveSymbolContext (so_addr = { "
1844 "section = %p, offset = 0x%" PRIx64
1845 " }, resolve_scope = 0x%8.8x)",
1846 static_cast<void *>(so_addr.GetSection().get()),
1847 so_addr.GetOffset(), resolve_scope);
1848 uint32_t resolved = 0;
1850 (eSymbolContextCompUnit | eSymbolContextFunction | eSymbolContextBlock |
1851 eSymbolContextLineEntry | eSymbolContextVariable)) {
1852 lldb::addr_t file_vm_addr = so_addr.GetFileAddress();
1854 DWARFDebugInfo &debug_info = DebugInfo();
1855 llvm::Expected<DWARFDebugAranges &> aranges =
1856 debug_info.GetCompileUnitAranges();
1858 Log *log = LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO);
1859 LLDB_LOG_ERROR(log, aranges.takeError(),
1860 "SymbolFileDWARF::ResolveSymbolContext failed to get cu "
1865 const dw_offset_t cu_offset = aranges->FindAddress(file_vm_addr);
1866 if (cu_offset == DW_INVALID_OFFSET) {
1867 // Global variables are not in the compile unit address ranges. The only
1868 // way to currently find global variables is to iterate over the
1869 // .debug_pubnames or the __apple_names table and find all items in there
1870 // that point to DW_TAG_variable DIEs and then find the address that
1872 if (resolve_scope & eSymbolContextVariable) {
1873 GlobalVariableMap &map = GetGlobalAranges();
1874 const GlobalVariableMap::Entry *entry =
1875 map.FindEntryThatContains(file_vm_addr);
1876 if (entry && entry->data) {
1877 Variable *variable = entry->data;
1878 SymbolContextScope *scc = variable->GetSymbolContextScope();
1880 scc->CalculateSymbolContext(&sc);
1881 sc.variable = variable;
1883 return sc.GetResolvedMask();
1887 uint32_t cu_idx = DW_INVALID_INDEX;
1888 if (auto *dwarf_cu = llvm::dyn_cast_or_null<DWARFCompileUnit>(
1889 debug_info.GetUnitAtOffset(DIERef::Section::DebugInfo, cu_offset,
1891 sc.comp_unit = GetCompUnitForDWARFCompUnit(*dwarf_cu);
1893 resolved |= eSymbolContextCompUnit;
1895 bool force_check_line_table = false;
1896 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock)) {
1897 ResolveFunctionAndBlock(file_vm_addr,
1898 resolve_scope & eSymbolContextBlock, sc);
1900 resolved |= eSymbolContextFunction;
1902 // We might have had a compile unit that had discontiguous address
1903 // ranges where the gaps are symbols that don't have any debug
1904 // info. Discontiguous compile unit address ranges should only
1905 // happen when there aren't other functions from other compile
1906 // units in these gaps. This helps keep the size of the aranges
1908 force_check_line_table = true;
1911 resolved |= eSymbolContextBlock;
1914 if ((resolve_scope & eSymbolContextLineEntry) ||
1915 force_check_line_table) {
1916 LineTable *line_table = sc.comp_unit->GetLineTable();
1917 if (line_table != nullptr) {
1918 // And address that makes it into this function should be in terms
1919 // of this debug file if there is no debug map, or it will be an
1920 // address in the .o file which needs to be fixed up to be in
1921 // terms of the debug map executable. Either way, calling
1922 // FixupAddress() will work for us.
1923 Address exe_so_addr(so_addr);
1924 if (FixupAddress(exe_so_addr)) {
1925 if (line_table->FindLineEntryByAddress(exe_so_addr,
1927 resolved |= eSymbolContextLineEntry;
1933 if (force_check_line_table && !(resolved & eSymbolContextLineEntry)) {
1934 // We might have had a compile unit that had discontiguous address
1935 // ranges where the gaps are symbols that don't have any debug info.
1936 // Discontiguous compile unit address ranges should only happen when
1937 // there aren't other functions from other compile units in these
1938 // gaps. This helps keep the size of the aranges down.
1939 sc.comp_unit = nullptr;
1940 resolved &= ~eSymbolContextCompUnit;
1943 GetObjectFile()->GetModule()->ReportWarning(
1944 "0x%8.8x: compile unit %u failed to create a valid "
1945 "lldb_private::CompileUnit class.",
1954 uint32_t SymbolFileDWARF::ResolveSymbolContext(const FileSpec &file_spec,
1957 SymbolContextItem resolve_scope,
1958 SymbolContextList &sc_list) {
1959 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1960 const uint32_t prev_size = sc_list.GetSize();
1961 if (resolve_scope & eSymbolContextCompUnit) {
1962 for (uint32_t cu_idx = 0, num_cus = GetNumCompileUnits(); cu_idx < num_cus;
1964 CompileUnit *dc_cu = ParseCompileUnitAtIndex(cu_idx).get();
1968 bool file_spec_matches_cu_file_spec =
1969 FileSpec::Match(file_spec, dc_cu->GetPrimaryFile());
1970 if (check_inlines || file_spec_matches_cu_file_spec) {
1971 SymbolContext sc(m_objfile_sp->GetModule());
1972 sc.comp_unit = dc_cu;
1973 uint32_t file_idx = UINT32_MAX;
1975 // If we are looking for inline functions only and we don't find it
1976 // in the support files, we are done.
1977 if (check_inlines) {
1979 sc.comp_unit->GetSupportFiles().FindFileIndex(1, file_spec, true);
1980 if (file_idx == UINT32_MAX)
1985 LineTable *line_table = sc.comp_unit->GetLineTable();
1987 if (line_table != nullptr && line != 0) {
1988 // We will have already looked up the file index if we are
1989 // searching for inline entries.
1991 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex(
1992 1, file_spec, true);
1994 if (file_idx != UINT32_MAX) {
1995 uint32_t found_line;
1996 uint32_t line_idx = line_table->FindLineEntryIndexByFileIndex(
1997 0, file_idx, line, false, &sc.line_entry);
1998 found_line = sc.line_entry.line;
2000 while (line_idx != UINT32_MAX) {
2001 sc.function = nullptr;
2004 (eSymbolContextFunction | eSymbolContextBlock)) {
2005 const lldb::addr_t file_vm_addr =
2006 sc.line_entry.range.GetBaseAddress().GetFileAddress();
2007 if (file_vm_addr != LLDB_INVALID_ADDRESS) {
2008 ResolveFunctionAndBlock(
2009 file_vm_addr, resolve_scope & eSymbolContextBlock, sc);
2014 line_idx = line_table->FindLineEntryIndexByFileIndex(
2015 line_idx + 1, file_idx, found_line, true, &sc.line_entry);
2018 } else if (file_spec_matches_cu_file_spec && !check_inlines) {
2019 // only append the context if we aren't looking for inline call
2020 // sites by file and line and if the file spec matches that of
2024 } else if (file_spec_matches_cu_file_spec && !check_inlines) {
2025 // only append the context if we aren't looking for inline call
2026 // sites by file and line and if the file spec matches that of
2036 return sc_list.GetSize() - prev_size;
2039 void SymbolFileDWARF::PreloadSymbols() {
2040 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
2044 std::recursive_mutex &SymbolFileDWARF::GetModuleMutex() const {
2045 lldb::ModuleSP module_sp(m_debug_map_module_wp.lock());
2047 return module_sp->GetMutex();
2048 return GetObjectFile()->GetModule()->GetMutex();
2051 bool SymbolFileDWARF::DeclContextMatchesThisSymbolFile(
2052 const lldb_private::CompilerDeclContext &decl_ctx) {
2053 if (!decl_ctx.IsValid()) {
2054 // Invalid namespace decl which means we aren't matching only things in
2055 // this symbol file, so return true to indicate it matches this symbol
2060 TypeSystem *decl_ctx_type_system = decl_ctx.GetTypeSystem();
2061 auto type_system_or_err = GetTypeSystemForLanguage(
2062 decl_ctx_type_system->GetMinimumLanguage(nullptr));
2063 if (auto err = type_system_or_err.takeError()) {
2064 LLDB_LOG_ERROR(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_SYMBOLS),
2066 "Unable to match namespace decl using TypeSystem");
2070 if (decl_ctx_type_system == &type_system_or_err.get())
2071 return true; // The type systems match, return true
2073 // The namespace AST was valid, and it does not match...
2074 Log *log(LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
2077 GetObjectFile()->GetModule()->LogMessage(
2078 log, "Valid namespace does not match symbol file");
2083 void SymbolFileDWARF::FindGlobalVariables(
2084 ConstString name, const CompilerDeclContext &parent_decl_ctx,
2085 uint32_t max_matches, VariableList &variables) {
2086 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
2087 Log *log(LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
2090 GetObjectFile()->GetModule()->LogMessage(
2092 "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", "
2093 "parent_decl_ctx=%p, max_matches=%u, variables)",
2094 name.GetCString(), static_cast<const void *>(&parent_decl_ctx),
2097 if (!DeclContextMatchesThisSymbolFile(parent_decl_ctx))
2100 // Remember how many variables are in the list before we search.
2101 const uint32_t original_size = variables.GetSize();
2103 llvm::StringRef basename;
2104 llvm::StringRef context;
2105 bool name_is_mangled = (bool)Mangled(name);
2107 if (!CPlusPlusLanguage::ExtractContextAndIdentifier(name.GetCString(),
2109 basename = name.GetStringRef();
2111 // Loop invariant: Variables up to this index have been checked for context
2113 uint32_t pruned_idx = original_size;
2116 m_index->GetGlobalVariables(ConstString(basename), [&](DWARFDIE die) {
2118 sc.module_sp = m_objfile_sp->GetModule();
2119 assert(sc.module_sp);
2121 if (die.Tag() != DW_TAG_variable)
2124 auto *dwarf_cu = llvm::dyn_cast<DWARFCompileUnit>(die.GetCU());
2127 sc.comp_unit = GetCompUnitForDWARFCompUnit(*dwarf_cu);
2129 if (parent_decl_ctx) {
2130 if (DWARFASTParser *dwarf_ast = GetDWARFParser(*die.GetCU())) {
2131 CompilerDeclContext actual_parent_decl_ctx =
2132 dwarf_ast->GetDeclContextContainingUIDFromDWARF(die);
2133 if (!actual_parent_decl_ctx ||
2134 actual_parent_decl_ctx != parent_decl_ctx)
2139 ParseVariables(sc, die, LLDB_INVALID_ADDRESS, false, false, &variables);
2140 while (pruned_idx < variables.GetSize()) {
2141 VariableSP var_sp = variables.GetVariableAtIndex(pruned_idx);
2142 if (name_is_mangled ||
2143 var_sp->GetName().GetStringRef().contains(name.GetStringRef()))
2146 variables.RemoveVariableAtIndex(pruned_idx);
2149 return variables.GetSize() - original_size < max_matches;
2152 // Return the number of variable that were appended to the list
2153 const uint32_t num_matches = variables.GetSize() - original_size;
2154 if (log && num_matches > 0) {
2155 GetObjectFile()->GetModule()->LogMessage(
2157 "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", "
2158 "parent_decl_ctx=%p, max_matches=%u, variables) => %u",
2159 name.GetCString(), static_cast<const void *>(&parent_decl_ctx),
2160 max_matches, num_matches);
2164 void SymbolFileDWARF::FindGlobalVariables(const RegularExpression ®ex,
2165 uint32_t max_matches,
2166 VariableList &variables) {
2167 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
2168 Log *log(LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
2171 GetObjectFile()->GetModule()->LogMessage(
2173 "SymbolFileDWARF::FindGlobalVariables (regex=\"%s\", "
2174 "max_matches=%u, variables)",
2175 regex.GetText().str().c_str(), max_matches);
2178 // Remember how many variables are in the list before we search.
2179 const uint32_t original_size = variables.GetSize();
2182 m_index->GetGlobalVariables(regex, [&](DWARFDIE die) {
2184 sc.module_sp = m_objfile_sp->GetModule();
2185 assert(sc.module_sp);
2187 DWARFCompileUnit *dwarf_cu = llvm::dyn_cast<DWARFCompileUnit>(die.GetCU());
2190 sc.comp_unit = GetCompUnitForDWARFCompUnit(*dwarf_cu);
2192 ParseVariables(sc, die, LLDB_INVALID_ADDRESS, false, false, &variables);
2194 return variables.GetSize() - original_size < max_matches;
2198 bool SymbolFileDWARF::ResolveFunction(const DWARFDIE &orig_die,
2199 bool include_inlines,
2200 SymbolContextList &sc_list) {
2206 // If we were passed a die that is not a function, just return false...
2207 if (!(orig_die.Tag() == DW_TAG_subprogram ||
2208 (include_inlines && orig_die.Tag() == DW_TAG_inlined_subroutine)))
2211 DWARFDIE die = orig_die;
2212 DWARFDIE inlined_die;
2213 if (die.Tag() == DW_TAG_inlined_subroutine) {
2217 die = die.GetParent();
2220 if (die.Tag() == DW_TAG_subprogram)
2226 assert(die && die.Tag() == DW_TAG_subprogram);
2227 if (GetFunction(die, sc)) {
2229 // Parse all blocks if needed
2231 Block &function_block = sc.function->GetBlock(true);
2232 sc.block = function_block.FindBlockByID(inlined_die.GetID());
2233 if (sc.block == nullptr)
2234 sc.block = function_block.FindBlockByID(inlined_die.GetOffset());
2235 if (sc.block == nullptr || !sc.block->GetStartAddress(addr))
2239 addr = sc.function->GetAddressRange().GetBaseAddress();
2243 if (auto section_sp = addr.GetSection()) {
2244 if (section_sp->GetPermissions() & ePermissionsExecutable) {
2254 bool SymbolFileDWARF::DIEInDeclContext(const CompilerDeclContext &decl_ctx,
2255 const DWARFDIE &die) {
2256 // If we have no parent decl context to match this DIE matches, and if the
2257 // parent decl context isn't valid, we aren't trying to look for any
2258 // particular decl context so any die matches.
2259 if (!decl_ctx.IsValid())
2263 if (DWARFASTParser *dwarf_ast = GetDWARFParser(*die.GetCU())) {
2264 if (CompilerDeclContext actual_decl_ctx =
2265 dwarf_ast->GetDeclContextContainingUIDFromDWARF(die))
2266 return decl_ctx.IsContainedInLookup(actual_decl_ctx);
2272 void SymbolFileDWARF::FindFunctions(ConstString name,
2273 const CompilerDeclContext &parent_decl_ctx,
2274 FunctionNameType name_type_mask,
2275 bool include_inlines,
2276 SymbolContextList &sc_list) {
2277 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
2278 static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
2279 Timer scoped_timer(func_cat, "SymbolFileDWARF::FindFunctions (name = '%s')",
2282 // eFunctionNameTypeAuto should be pre-resolved by a call to
2283 // Module::LookupInfo::LookupInfo()
2284 assert((name_type_mask & eFunctionNameTypeAuto) == 0);
2286 Log *log(LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
2289 GetObjectFile()->GetModule()->LogMessage(
2291 "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, sc_list)",
2292 name.GetCString(), name_type_mask);
2295 if (!DeclContextMatchesThisSymbolFile(parent_decl_ctx))
2298 // If name is empty then we won't find anything.
2302 // Remember how many sc_list are in the list before we search in case we are
2303 // appending the results to a variable list.
2305 const uint32_t original_size = sc_list.GetSize();
2307 llvm::DenseSet<const DWARFDebugInfoEntry *> resolved_dies;
2309 m_index->GetFunctions(name, *this, parent_decl_ctx, name_type_mask,
2311 if (resolved_dies.insert(die.GetDIE()).second)
2312 ResolveFunction(die, include_inlines, sc_list);
2316 // Return the number of variable that were appended to the list
2317 const uint32_t num_matches = sc_list.GetSize() - original_size;
2319 if (log && num_matches > 0) {
2320 GetObjectFile()->GetModule()->LogMessage(
2322 "SymbolFileDWARF::FindFunctions (name=\"%s\", "
2323 "name_type_mask=0x%x, include_inlines=%d, sc_list) => %u",
2324 name.GetCString(), name_type_mask, include_inlines,
2329 void SymbolFileDWARF::FindFunctions(const RegularExpression ®ex,
2330 bool include_inlines,
2331 SymbolContextList &sc_list) {
2332 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
2333 static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
2334 Timer scoped_timer(func_cat, "SymbolFileDWARF::FindFunctions (regex = '%s')",
2335 regex.GetText().str().c_str());
2337 Log *log(LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
2340 GetObjectFile()->GetModule()->LogMessage(
2341 log, "SymbolFileDWARF::FindFunctions (regex=\"%s\", sc_list)",
2342 regex.GetText().str().c_str());
2345 llvm::DenseSet<const DWARFDebugInfoEntry *> resolved_dies;
2346 m_index->GetFunctions(regex, [&](DWARFDIE die) {
2347 if (resolved_dies.insert(die.GetDIE()).second)
2348 ResolveFunction(die, include_inlines, sc_list);
2353 void SymbolFileDWARF::GetMangledNamesForFunction(
2354 const std::string &scope_qualified_name,
2355 std::vector<ConstString> &mangled_names) {
2356 DWARFDebugInfo &info = DebugInfo();
2357 uint32_t num_comp_units = info.GetNumUnits();
2358 for (uint32_t i = 0; i < num_comp_units; i++) {
2359 DWARFUnit *cu = info.GetUnitAtIndex(i);
2363 SymbolFileDWARFDwo *dwo = cu->GetDwoSymbolFile();
2365 dwo->GetMangledNamesForFunction(scope_qualified_name, mangled_names);
2368 for (DIERef die_ref :
2369 m_function_scope_qualified_name_map.lookup(scope_qualified_name)) {
2370 DWARFDIE die = GetDIE(die_ref);
2371 mangled_names.push_back(ConstString(die.GetMangledName()));
2375 void SymbolFileDWARF::FindTypes(
2376 ConstString name, const CompilerDeclContext &parent_decl_ctx,
2377 uint32_t max_matches,
2378 llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
2380 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
2381 // Make sure we haven't already searched this SymbolFile before.
2382 if (!searched_symbol_files.insert(this).second)
2385 Log *log(LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
2388 if (parent_decl_ctx)
2389 GetObjectFile()->GetModule()->LogMessage(
2391 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", parent_decl_ctx = "
2392 "%p (\"%s\"), max_matches=%u, type_list)",
2393 name.GetCString(), static_cast<const void *>(&parent_decl_ctx),
2394 parent_decl_ctx.GetName().AsCString("<NULL>"), max_matches);
2396 GetObjectFile()->GetModule()->LogMessage(
2398 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", parent_decl_ctx = "
2399 "NULL, max_matches=%u, type_list)",
2400 name.GetCString(), max_matches);
2403 if (!DeclContextMatchesThisSymbolFile(parent_decl_ctx))
2406 m_index->GetTypes(name, [&](DWARFDIE die) {
2407 if (!DIEInDeclContext(parent_decl_ctx, die))
2408 return true; // The containing decl contexts don't match
2410 Type *matching_type = ResolveType(die, true, true);
2414 // We found a type pointer, now find the shared pointer form our type
2416 types.InsertUnique(matching_type->shared_from_this());
2417 return types.GetSize() < max_matches;
2420 // Next search through the reachable Clang modules. This only applies for
2421 // DWARF objects compiled with -gmodules that haven't been processed by
2423 if (types.GetSize() < max_matches) {
2424 UpdateExternalModuleListIfNeeded();
2426 for (const auto &pair : m_external_type_modules)
2427 if (ModuleSP external_module_sp = pair.second)
2428 if (SymbolFile *sym_file = external_module_sp->GetSymbolFile())
2429 sym_file->FindTypes(name, parent_decl_ctx, max_matches,
2430 searched_symbol_files, types);
2433 if (log && types.GetSize()) {
2434 if (parent_decl_ctx) {
2435 GetObjectFile()->GetModule()->LogMessage(
2437 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", parent_decl_ctx "
2438 "= %p (\"%s\"), max_matches=%u, type_list) => %u",
2439 name.GetCString(), static_cast<const void *>(&parent_decl_ctx),
2440 parent_decl_ctx.GetName().AsCString("<NULL>"), max_matches,
2443 GetObjectFile()->GetModule()->LogMessage(
2445 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", parent_decl_ctx "
2446 "= NULL, max_matches=%u, type_list) => %u",
2447 name.GetCString(), max_matches, types.GetSize());
2452 void SymbolFileDWARF::FindTypes(
2453 llvm::ArrayRef<CompilerContext> pattern, LanguageSet languages,
2454 llvm::DenseSet<SymbolFile *> &searched_symbol_files, TypeMap &types) {
2455 // Make sure we haven't already searched this SymbolFile before.
2456 if (!searched_symbol_files.insert(this).second)
2459 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
2460 if (pattern.empty())
2463 ConstString name = pattern.back().name;
2468 m_index->GetTypes(name, [&](DWARFDIE die) {
2469 if (!languages[GetLanguage(*die.GetCU())])
2472 llvm::SmallVector<CompilerContext, 4> die_context;
2473 die.GetDeclContext(die_context);
2474 if (!contextMatches(die_context, pattern))
2477 if (Type *matching_type = ResolveType(die, true, true)) {
2478 // We found a type pointer, now find the shared pointer form our type
2480 types.InsertUnique(matching_type->shared_from_this());
2485 // Next search through the reachable Clang modules. This only applies for
2486 // DWARF objects compiled with -gmodules that haven't been processed by
2488 UpdateExternalModuleListIfNeeded();
2490 for (const auto &pair : m_external_type_modules)
2491 if (ModuleSP external_module_sp = pair.second)
2492 external_module_sp->FindTypes(pattern, languages, searched_symbol_files,
2497 SymbolFileDWARF::FindNamespace(ConstString name,
2498 const CompilerDeclContext &parent_decl_ctx) {
2499 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
2500 Log *log(LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
2503 GetObjectFile()->GetModule()->LogMessage(
2504 log, "SymbolFileDWARF::FindNamespace (sc, name=\"%s\")",
2508 CompilerDeclContext namespace_decl_ctx;
2510 if (!DeclContextMatchesThisSymbolFile(parent_decl_ctx))
2511 return namespace_decl_ctx;
2513 m_index->GetNamespaces(name, [&](DWARFDIE die) {
2514 if (!DIEInDeclContext(parent_decl_ctx, die))
2515 return true; // The containing decl contexts don't match
2517 DWARFASTParser *dwarf_ast = GetDWARFParser(*die.GetCU());
2521 namespace_decl_ctx = dwarf_ast->GetDeclContextForUIDFromDWARF(die);
2522 return !namespace_decl_ctx.IsValid();
2525 if (log && namespace_decl_ctx) {
2526 GetObjectFile()->GetModule()->LogMessage(
2528 "SymbolFileDWARF::FindNamespace (sc, name=\"%s\") => "
2529 "CompilerDeclContext(%p/%p) \"%s\"",
2531 static_cast<const void *>(namespace_decl_ctx.GetTypeSystem()),
2532 static_cast<const void *>(namespace_decl_ctx.GetOpaqueDeclContext()),
2533 namespace_decl_ctx.GetName().AsCString("<NULL>"));
2536 return namespace_decl_ctx;
2539 TypeSP SymbolFileDWARF::GetTypeForDIE(const DWARFDIE &die,
2540 bool resolve_function_context) {
2543 Type *type_ptr = GetDIEToType().lookup(die.GetDIE());
2544 if (type_ptr == nullptr) {
2545 SymbolContextScope *scope;
2546 if (auto *dwarf_cu = llvm::dyn_cast<DWARFCompileUnit>(die.GetCU()))
2547 scope = GetCompUnitForDWARFCompUnit(*dwarf_cu);
2549 scope = GetObjectFile()->GetModule().get();
2551 SymbolContext sc(scope);
2552 const DWARFDebugInfoEntry *parent_die = die.GetParent().GetDIE();
2553 while (parent_die != nullptr) {
2554 if (parent_die->Tag() == DW_TAG_subprogram)
2556 parent_die = parent_die->GetParent();
2558 SymbolContext sc_backup = sc;
2559 if (resolve_function_context && parent_die != nullptr &&
2560 !GetFunction(DWARFDIE(die.GetCU(), parent_die), sc))
2563 type_sp = ParseType(sc, die, nullptr);
2564 } else if (type_ptr != DIE_IS_BEING_PARSED) {
2565 // Grab the existing type from the master types lists
2566 type_sp = type_ptr->shared_from_this();
2573 SymbolFileDWARF::GetDeclContextDIEContainingDIE(const DWARFDIE &orig_die) {
2575 DWARFDIE die = orig_die;
2578 // If this is the original DIE that we are searching for a declaration
2579 // for, then don't look in the cache as we don't want our own decl
2580 // context to be our decl context...
2581 if (orig_die != die) {
2582 switch (die.Tag()) {
2583 case DW_TAG_compile_unit:
2584 case DW_TAG_partial_unit:
2585 case DW_TAG_namespace:
2586 case DW_TAG_structure_type:
2587 case DW_TAG_union_type:
2588 case DW_TAG_class_type:
2589 case DW_TAG_lexical_block:
2590 case DW_TAG_subprogram:
2592 case DW_TAG_inlined_subroutine: {
2593 DWARFDIE abs_die = die.GetReferencedDIE(DW_AT_abstract_origin);
2604 DWARFDIE spec_die = die.GetReferencedDIE(DW_AT_specification);
2606 DWARFDIE decl_ctx_die = GetDeclContextDIEContainingDIE(spec_die);
2608 return decl_ctx_die;
2611 DWARFDIE abs_die = die.GetReferencedDIE(DW_AT_abstract_origin);
2613 DWARFDIE decl_ctx_die = GetDeclContextDIEContainingDIE(abs_die);
2615 return decl_ctx_die;
2618 die = die.GetParent();
2624 Symbol *SymbolFileDWARF::GetObjCClassSymbol(ConstString objc_class_name) {
2625 Symbol *objc_class_symbol = nullptr;
2627 Symtab *symtab = m_objfile_sp->GetSymtab();
2629 objc_class_symbol = symtab->FindFirstSymbolWithNameAndType(
2630 objc_class_name, eSymbolTypeObjCClass, Symtab::eDebugNo,
2631 Symtab::eVisibilityAny);
2634 return objc_class_symbol;
2637 // Some compilers don't emit the DW_AT_APPLE_objc_complete_type attribute. If
2638 // they don't then we can end up looking through all class types for a complete
2639 // type and never find the full definition. We need to know if this attribute
2640 // is supported, so we determine this here and cache th result. We also need to
2641 // worry about the debug map
2643 // if we are doing darwin DWARF in .o file debugging.
2644 bool SymbolFileDWARF::Supports_DW_AT_APPLE_objc_complete_type(DWARFUnit *cu) {
2645 if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolCalculate) {
2646 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolNo;
2647 if (cu && cu->Supports_DW_AT_APPLE_objc_complete_type())
2648 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes;
2650 DWARFDebugInfo &debug_info = DebugInfo();
2651 const uint32_t num_compile_units = GetNumCompileUnits();
2652 for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx) {
2653 DWARFUnit *dwarf_cu = debug_info.GetUnitAtIndex(cu_idx);
2654 if (dwarf_cu != cu &&
2655 dwarf_cu->Supports_DW_AT_APPLE_objc_complete_type()) {
2656 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes;
2661 if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolNo &&
2662 GetDebugMapSymfile())
2663 return m_debug_map_symfile->Supports_DW_AT_APPLE_objc_complete_type(this);
2665 return m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolYes;
2668 // This function can be used when a DIE is found that is a forward declaration
2669 // DIE and we want to try and find a type that has the complete definition.
2670 TypeSP SymbolFileDWARF::FindCompleteObjCDefinitionTypeForDIE(
2671 const DWARFDIE &die, ConstString type_name, bool must_be_implementation) {
2675 if (!type_name || (must_be_implementation && !GetObjCClassSymbol(type_name)))
2678 m_index->GetCompleteObjCClass(
2679 type_name, must_be_implementation, [&](DWARFDIE type_die) {
2680 bool try_resolving_type = false;
2682 // Don't try and resolve the DIE we are looking for with the DIE
2684 if (type_die != die) {
2685 switch (type_die.Tag()) {
2686 case DW_TAG_class_type:
2687 case DW_TAG_structure_type:
2688 try_resolving_type = true;
2694 if (!try_resolving_type)
2697 if (must_be_implementation &&
2698 type_die.Supports_DW_AT_APPLE_objc_complete_type())
2699 try_resolving_type = type_die.GetAttributeValueAsUnsigned(
2700 DW_AT_APPLE_objc_complete_type, 0);
2701 if (!try_resolving_type)
2704 Type *resolved_type = ResolveType(type_die, false, true);
2705 if (!resolved_type || resolved_type == DIE_IS_BEING_PARSED)
2709 "resolved 0x%8.8" PRIx64 " from %s to 0x%8.8" PRIx64
2710 " (cu 0x%8.8" PRIx64 ")\n",
2712 m_objfile_sp->GetFileSpec().GetFilename().AsCString("<Unknown>"),
2713 type_die.GetID(), type_cu->GetID());
2716 GetDIEToType()[die.GetDIE()] = resolved_type;
2717 type_sp = resolved_type->shared_from_this();
2723 // This function helps to ensure that the declaration contexts match for two
2724 // different DIEs. Often times debug information will refer to a forward
2725 // declaration of a type (the equivalent of "struct my_struct;". There will
2726 // often be a declaration of that type elsewhere that has the full definition.
2727 // When we go looking for the full type "my_struct", we will find one or more
2728 // matches in the accelerator tables and we will then need to make sure the
2729 // type was in the same declaration context as the original DIE. This function
2730 // can efficiently compare two DIEs and will return true when the declaration
2731 // context matches, and false when they don't.
2732 bool SymbolFileDWARF::DIEDeclContextsMatch(const DWARFDIE &die1,
2733 const DWARFDIE &die2) {
2737 std::vector<DWARFDIE> decl_ctx_1;
2738 std::vector<DWARFDIE> decl_ctx_2;
2739 // The declaration DIE stack is a stack of the declaration context DIEs all
2740 // the way back to the compile unit. If a type "T" is declared inside a class
2741 // "B", and class "B" is declared inside a class "A" and class "A" is in a
2742 // namespace "lldb", and the namespace is in a compile unit, there will be a
2745 // [0] DW_TAG_class_type for "B"
2746 // [1] DW_TAG_class_type for "A"
2747 // [2] DW_TAG_namespace for "lldb"
2748 // [3] DW_TAG_compile_unit or DW_TAG_partial_unit for the source file.
2750 // We grab both contexts and make sure that everything matches all the way
2751 // back to the compiler unit.
2753 // First lets grab the decl contexts for both DIEs
2754 decl_ctx_1 = die1.GetDeclContextDIEs();
2755 decl_ctx_2 = die2.GetDeclContextDIEs();
2756 // Make sure the context arrays have the same size, otherwise we are done
2757 const size_t count1 = decl_ctx_1.size();
2758 const size_t count2 = decl_ctx_2.size();
2759 if (count1 != count2)
2762 // Make sure the DW_TAG values match all the way back up the compile unit. If
2763 // they don't, then we are done.
2764 DWARFDIE decl_ctx_die1;
2765 DWARFDIE decl_ctx_die2;
2767 for (i = 0; i < count1; i++) {
2768 decl_ctx_die1 = decl_ctx_1[i];
2769 decl_ctx_die2 = decl_ctx_2[i];
2770 if (decl_ctx_die1.Tag() != decl_ctx_die2.Tag())
2775 // Make sure the top item in the decl context die array is always
2776 // DW_TAG_compile_unit or DW_TAG_partial_unit. If it isn't then
2777 // something went wrong in the DWARFDIE::GetDeclContextDIEs()
2779 dw_tag_t cu_tag = decl_ctx_1[count1 - 1].Tag();
2780 UNUSED_IF_ASSERT_DISABLED(cu_tag);
2781 assert(cu_tag == DW_TAG_compile_unit || cu_tag == DW_TAG_partial_unit);
2784 // Always skip the compile unit when comparing by only iterating up to "count
2785 // - 1". Here we compare the names as we go.
2786 for (i = 0; i < count1 - 1; i++) {
2787 decl_ctx_die1 = decl_ctx_1[i];
2788 decl_ctx_die2 = decl_ctx_2[i];
2789 const char *name1 = decl_ctx_die1.GetName();
2790 const char *name2 = decl_ctx_die2.GetName();
2791 // If the string was from a DW_FORM_strp, then the pointer will often be
2796 // Name pointers are not equal, so only compare the strings if both are not
2798 if (name1 && name2) {
2799 // If the strings don't compare, we are done...
2800 if (strcmp(name1, name2) != 0)
2803 // One name was NULL while the other wasn't
2807 // We made it through all of the checks and the declaration contexts are
2812 TypeSP SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(
2813 const DWARFDeclContext &dwarf_decl_ctx) {
2816 const uint32_t dwarf_decl_ctx_count = dwarf_decl_ctx.GetSize();
2817 if (dwarf_decl_ctx_count > 0) {
2818 const ConstString type_name(dwarf_decl_ctx[0].name);
2819 const dw_tag_t tag = dwarf_decl_ctx[0].tag;
2822 Log *log(LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION |
2823 DWARF_LOG_LOOKUPS));
2825 GetObjectFile()->GetModule()->LogMessage(
2827 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%"
2828 "s, qualified-name='%s')",
2829 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
2830 dwarf_decl_ctx.GetQualifiedName());
2833 // Get the type system that we are looking to find a type for. We will
2834 // use this to ensure any matches we find are in a language that this
2835 // type system supports
2836 const LanguageType language = dwarf_decl_ctx.GetLanguage();
2837 TypeSystem *type_system = nullptr;
2838 if (language != eLanguageTypeUnknown) {
2839 auto type_system_or_err = GetTypeSystemForLanguage(language);
2840 if (auto err = type_system_or_err.takeError()) {
2842 lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_SYMBOLS),
2843 std::move(err), "Cannot get TypeSystem for language {}",
2844 Language::GetNameForLanguageType(language));
2846 type_system = &type_system_or_err.get();
2850 m_index->GetTypes(dwarf_decl_ctx, [&](DWARFDIE type_die) {
2851 // Make sure type_die's langauge matches the type system we are
2852 // looking for. We don't want to find a "Foo" type from Java if we
2853 // are looking for a "Foo" type for C, C++, ObjC, or ObjC++.
2855 !type_system->SupportsLanguage(GetLanguage(*type_die.GetCU())))
2857 bool try_resolving_type = false;
2859 // Don't try and resolve the DIE we are looking for with the DIE
2861 const dw_tag_t type_tag = type_die.Tag();
2862 // Make sure the tags match
2863 if (type_tag == tag) {
2864 // The tags match, lets try resolving this type
2865 try_resolving_type = true;
2867 // The tags don't match, but we need to watch our for a forward
2868 // declaration for a struct and ("struct foo") ends up being a
2869 // class ("class foo { ... };") or vice versa.
2871 case DW_TAG_class_type:
2872 // We had a "class foo", see if we ended up with a "struct foo
2874 try_resolving_type = (tag == DW_TAG_structure_type);
2876 case DW_TAG_structure_type:
2877 // We had a "struct foo", see if we ended up with a "class foo
2879 try_resolving_type = (tag == DW_TAG_class_type);
2882 // Tags don't match, don't event try to resolve using this type
2883 // whose name matches....
2888 if (!try_resolving_type) {
2890 std::string qualified_name;
2891 type_die.GetQualifiedName(qualified_name);
2892 GetObjectFile()->GetModule()->LogMessage(
2895 "FindDefinitionTypeForDWARFDeclContext(tag=%s, "
2896 "qualified-name='%s') ignoring die=0x%8.8x (%s)",
2897 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
2898 dwarf_decl_ctx.GetQualifiedName(), type_die.GetOffset(),
2899 qualified_name.c_str());
2904 DWARFDeclContext type_dwarf_decl_ctx = GetDWARFDeclContext(type_die);
2907 GetObjectFile()->GetModule()->LogMessage(
2910 "FindDefinitionTypeForDWARFDeclContext(tag=%s, "
2911 "qualified-name='%s') trying die=0x%8.8x (%s)",
2912 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
2913 dwarf_decl_ctx.GetQualifiedName(), type_die.GetOffset(),
2914 type_dwarf_decl_ctx.GetQualifiedName());
2917 // Make sure the decl contexts match all the way up
2918 if (dwarf_decl_ctx != type_dwarf_decl_ctx)
2921 Type *resolved_type = ResolveType(type_die, false);
2922 if (!resolved_type || resolved_type == DIE_IS_BEING_PARSED)
2925 type_sp = resolved_type->shared_from_this();
2933 TypeSP SymbolFileDWARF::ParseType(const SymbolContext &sc, const DWARFDIE &die,
2934 bool *type_is_new_ptr) {
2938 auto type_system_or_err = GetTypeSystemForLanguage(GetLanguage(*die.GetCU()));
2939 if (auto err = type_system_or_err.takeError()) {
2940 LLDB_LOG_ERROR(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_SYMBOLS),
2941 std::move(err), "Unable to parse type");
2945 DWARFASTParser *dwarf_ast = type_system_or_err->GetDWARFParser();
2949 TypeSP type_sp = dwarf_ast->ParseTypeFromDWARF(sc, die, type_is_new_ptr);
2951 GetTypeList().Insert(type_sp);
2953 if (die.Tag() == DW_TAG_subprogram) {
2954 std::string scope_qualified_name(GetDeclContextForUID(die.GetID())
2955 .GetScopeQualifiedName()
2957 if (scope_qualified_name.size()) {
2958 m_function_scope_qualified_name_map[scope_qualified_name].insert(
2967 size_t SymbolFileDWARF::ParseTypes(const SymbolContext &sc,
2968 const DWARFDIE &orig_die,
2969 bool parse_siblings, bool parse_children) {
2970 size_t types_added = 0;
2971 DWARFDIE die = orig_die;
2974 const dw_tag_t tag = die.Tag();
2975 bool type_is_new = false;
2977 Tag dwarf_tag = static_cast<Tag>(tag);
2979 // TODO: Currently ParseTypeFromDWARF(...) which is called by ParseType(...)
2980 // does not handle DW_TAG_subrange_type. It is not clear if this is a bug or
2982 if (isType(dwarf_tag) && tag != DW_TAG_subrange_type)
2983 ParseType(sc, die, &type_is_new);
2988 if (parse_children && die.HasChildren()) {
2989 if (die.Tag() == DW_TAG_subprogram) {
2990 SymbolContext child_sc(sc);
2991 child_sc.function = sc.comp_unit->FindFunctionByUID(die.GetID()).get();
2992 types_added += ParseTypes(child_sc, die.GetFirstChild(), true, true);
2994 types_added += ParseTypes(sc, die.GetFirstChild(), true, true);
2998 die = die.GetSibling();
3005 size_t SymbolFileDWARF::ParseBlocksRecursive(Function &func) {
3006 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
3007 CompileUnit *comp_unit = func.GetCompileUnit();
3008 lldbassert(comp_unit);
3010 DWARFUnit *dwarf_cu = GetDWARFCompileUnit(comp_unit);
3014 size_t functions_added = 0;
3015 const dw_offset_t function_die_offset = func.GetID();
3016 DWARFDIE function_die =
3017 dwarf_cu->GetNonSkeletonUnit().GetDIE(function_die_offset);
3019 ParseBlocksRecursive(*comp_unit, &func.GetBlock(false), function_die,
3020 LLDB_INVALID_ADDRESS, 0);
3023 return functions_added;
3026 size_t SymbolFileDWARF::ParseTypes(CompileUnit &comp_unit) {
3027 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
3028 size_t types_added = 0;
3029 DWARFUnit *dwarf_cu = GetDWARFCompileUnit(&comp_unit);
3031 DWARFDIE dwarf_cu_die = dwarf_cu->DIE();
3032 if (dwarf_cu_die && dwarf_cu_die.HasChildren()) {
3034 sc.comp_unit = &comp_unit;
3035 types_added = ParseTypes(sc, dwarf_cu_die.GetFirstChild(), true, true);
3042 size_t SymbolFileDWARF::ParseVariablesForContext(const SymbolContext &sc) {
3043 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
3044 if (sc.comp_unit != nullptr) {
3046 DWARFDIE function_die = GetDIE(sc.function->GetID());
3048 const dw_addr_t func_lo_pc = function_die.GetAttributeValueAsAddress(
3049 DW_AT_low_pc, LLDB_INVALID_ADDRESS);
3050 if (func_lo_pc != LLDB_INVALID_ADDRESS) {
3051 const size_t num_variables = ParseVariables(
3052 sc, function_die.GetFirstChild(), func_lo_pc, true, true);
3054 // Let all blocks know they have parse all their variables
3055 sc.function->GetBlock(false).SetDidParseVariables(true, true);
3056 return num_variables;
3058 } else if (sc.comp_unit) {
3059 DWARFUnit *dwarf_cu = DebugInfo().GetUnitAtIndex(sc.comp_unit->GetID());
3061 if (dwarf_cu == nullptr)
3064 uint32_t vars_added = 0;
3065 VariableListSP variables(sc.comp_unit->GetVariableList(false));
3067 if (variables.get() == nullptr) {
3068 variables = std::make_shared<VariableList>();
3069 sc.comp_unit->SetVariableList(variables);
3071 m_index->GetGlobalVariables(
3072 dwarf_cu->GetNonSkeletonUnit(), [&](DWARFDIE die) {
3074 ParseVariableDIE(sc, die, LLDB_INVALID_ADDRESS));
3076 variables->AddVariableIfUnique(var_sp);
3088 VariableSP SymbolFileDWARF::ParseVariableDIE(const SymbolContext &sc,
3089 const DWARFDIE &die,
3090 const lldb::addr_t func_low_pc) {
3091 if (die.GetDWARF() != this)
3092 return die.GetDWARF()->ParseVariableDIE(sc, die, func_low_pc);
3098 var_sp = GetDIEToVariable()[die.GetDIE()];
3100 return var_sp; // Already been parsed!
3102 const dw_tag_t tag = die.Tag();
3103 ModuleSP module = GetObjectFile()->GetModule();
3105 if ((tag == DW_TAG_variable) || (tag == DW_TAG_constant) ||
3106 (tag == DW_TAG_formal_parameter && sc.function)) {
3107 DWARFAttributes attributes;
3108 const size_t num_attributes = die.GetAttributes(attributes);
3110 if (num_attributes > 0) {
3111 const char *name = nullptr;
3112 const char *mangled = nullptr;
3115 DWARFFormValue type_die_form;
3116 DWARFExpression location;
3117 bool is_external = false;
3118 bool is_artificial = false;
3119 bool location_is_const_value_data = false;
3120 bool has_explicit_location = false;
3121 DWARFFormValue const_value;
3122 Variable::RangeList scope_ranges;
3123 // AccessType accessibility = eAccessNone;
3125 for (i = 0; i < num_attributes; ++i) {
3126 dw_attr_t attr = attributes.AttributeAtIndex(i);
3127 DWARFFormValue form_value;
3129 if (attributes.ExtractFormValueAtIndex(i, form_value)) {
3131 case DW_AT_decl_file:
3132 decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(
3133 form_value.Unsigned()));
3135 case DW_AT_decl_line:
3136 decl.SetLine(form_value.Unsigned());
3138 case DW_AT_decl_column:
3139 decl.SetColumn(form_value.Unsigned());
3142 name = form_value.AsCString();
3144 case DW_AT_linkage_name:
3145 case DW_AT_MIPS_linkage_name:
3146 mangled = form_value.AsCString();
3149 type_die_form = form_value;
3151 case DW_AT_external:
3152 is_external = form_value.Boolean();
3154 case DW_AT_const_value:
3155 // If we have already found a DW_AT_location attribute, ignore this
3157 if (!has_explicit_location) {
3158 location_is_const_value_data = true;
3159 // The constant value will be either a block, a data value or a
3161 auto debug_info_data = die.GetData();
3162 if (DWARFFormValue::IsBlockForm(form_value.Form())) {
3163 // Retrieve the value as a block expression.
3164 uint32_t block_offset =
3165 form_value.BlockData() - debug_info_data.GetDataStart();
3166 uint32_t block_length = form_value.Unsigned();
3167 location = DWARFExpression(
3169 DataExtractor(debug_info_data, block_offset, block_length),
3171 } else if (DWARFFormValue::IsDataForm(form_value.Form())) {
3172 // Retrieve the value as a data expression.
3173 uint32_t data_offset = attributes.DIEOffsetAtIndex(i);
3174 if (auto data_length = form_value.GetFixedSize())
3175 location = DWARFExpression(
3177 DataExtractor(debug_info_data, data_offset, *data_length),
3180 const uint8_t *data_pointer = form_value.BlockData();
3182 form_value.Unsigned();
3183 } else if (DWARFFormValue::IsDataForm(form_value.Form())) {
3184 // we need to get the byte size of the type later after we
3185 // create the variable
3186 const_value = form_value;
3190 // Retrieve the value as a string expression.
3191 if (form_value.Form() == DW_FORM_strp) {
3192 uint32_t data_offset = attributes.DIEOffsetAtIndex(i);
3193 if (auto data_length = form_value.GetFixedSize())
3194 location = DWARFExpression(module,
3195 DataExtractor(debug_info_data,
3200 const char *str = form_value.AsCString();
3201 uint32_t string_offset =
3202 str - (const char *)debug_info_data.GetDataStart();
3203 uint32_t string_length = strlen(str) + 1;
3204 location = DWARFExpression(module,
3205 DataExtractor(debug_info_data,
3213 case DW_AT_location: {
3214 location_is_const_value_data = false;
3215 has_explicit_location = true;
3216 if (DWARFFormValue::IsBlockForm(form_value.Form())) {
3217 auto data = die.GetData();
3219 uint32_t block_offset =
3220 form_value.BlockData() - data.GetDataStart();
3221 uint32_t block_length = form_value.Unsigned();
3222 location = DWARFExpression(
3223 module, DataExtractor(data, block_offset, block_length),
3226 DataExtractor data = die.GetCU()->GetLocationData();
3227 dw_offset_t offset = form_value.Unsigned();
3228 if (form_value.Form() == DW_FORM_loclistx)
3229 offset = die.GetCU()->GetLoclistOffset(offset).getValueOr(-1);
3230 if (data.ValidOffset(offset)) {
3231 data = DataExtractor(data, offset, data.GetByteSize() - offset);
3232 location = DWARFExpression(module, data, die.GetCU());
3233 assert(func_low_pc != LLDB_INVALID_ADDRESS);
3234 location.SetLocationListAddresses(
3235 attributes.CompileUnitAtIndex(i)->GetBaseAddress(),
3240 case DW_AT_specification:
3241 spec_die = form_value.Reference();
3243 case DW_AT_start_scope:
3244 // TODO: Implement this.
3246 case DW_AT_artificial:
3247 is_artificial = form_value.Boolean();
3249 case DW_AT_accessibility:
3250 break; // accessibility =
3251 // DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
3252 case DW_AT_declaration:
3253 case DW_AT_description:
3254 case DW_AT_endianity:
3256 case DW_AT_visibility:
3258 case DW_AT_abstract_origin:
3265 const DWARFDIE parent_context_die = GetDeclContextDIEContainingDIE(die);
3266 const dw_tag_t parent_tag = die.GetParent().Tag();
3267 bool is_static_member =
3268 (parent_tag == DW_TAG_compile_unit ||
3269 parent_tag == DW_TAG_partial_unit) &&
3270 (parent_context_die.Tag() == DW_TAG_class_type ||
3271 parent_context_die.Tag() == DW_TAG_structure_type);
3273 ValueType scope = eValueTypeInvalid;
3275 const DWARFDIE sc_parent_die = GetParentSymbolContextDIE(die);
3276 SymbolContextScope *symbol_context_scope = nullptr;
3278 bool has_explicit_mangled = mangled != nullptr;
3280 // LLDB relies on the mangled name (DW_TAG_linkage_name or
3281 // DW_AT_MIPS_linkage_name) to generate fully qualified names
3282 // of global variables with commands like "frame var j". For
3283 // example, if j were an int variable holding a value 4 and
3284 // declared in a namespace B which in turn is contained in a
3285 // namespace A, the command "frame var j" returns
3286 // "(int) A::B::j = 4".
3287 // If the compiler does not emit a linkage name, we should be
3288 // able to generate a fully qualified name from the
3289 // declaration context.
3290 if ((parent_tag == DW_TAG_compile_unit ||
3291 parent_tag == DW_TAG_partial_unit) &&
3292 Language::LanguageIsCPlusPlus(GetLanguage(*die.GetCU())))
3293 mangled = GetDWARFDeclContext(die)
3294 .GetQualifiedNameAsConstString()
3298 if (tag == DW_TAG_formal_parameter)
3299 scope = eValueTypeVariableArgument;
3301 // DWARF doesn't specify if a DW_TAG_variable is a local, global
3302 // or static variable, so we have to do a little digging:
3303 // 1) DW_AT_linkage_name implies static lifetime (but may be missing)
3304 // 2) An empty DW_AT_location is an (optimized-out) static lifetime var.
3305 // 3) DW_AT_location containing a DW_OP_addr implies static lifetime.
3306 // Clang likes to combine small global variables into the same symbol
3307 // with locations like: DW_OP_addr(0x1000), DW_OP_constu(2), DW_OP_plus
3308 // so we need to look through the whole expression.
3309 bool is_static_lifetime =
3310 has_explicit_mangled ||
3311 (has_explicit_location && !location.IsValid());
3312 // Check if the location has a DW_OP_addr with any address value...
3313 lldb::addr_t location_DW_OP_addr = LLDB_INVALID_ADDRESS;
3314 if (!location_is_const_value_data) {
3315 bool op_error = false;
3316 location_DW_OP_addr = location.GetLocation_DW_OP_addr(0, op_error);
3319 location.DumpLocationForAddress(&strm, eDescriptionLevelFull, 0, 0,
3321 GetObjectFile()->GetModule()->ReportError(
3322 "0x%8.8x: %s has an invalid location: %s", die.GetOffset(),
3323 die.GetTagAsCString(), strm.GetData());
3325 if (location_DW_OP_addr != LLDB_INVALID_ADDRESS)
3326 is_static_lifetime = true;
3328 SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile();
3329 if (debug_map_symfile)
3330 // Set the module of the expression to the linked module
3331 // instead of the oject file so the relocated address can be
3333 location.SetModule(debug_map_symfile->GetObjectFile()->GetModule());
3335 if (is_static_lifetime) {
3337 scope = eValueTypeVariableGlobal;
3339 scope = eValueTypeVariableStatic;
3341 if (debug_map_symfile) {
3342 // When leaving the DWARF in the .o files on darwin, when we have a
3343 // global variable that wasn't initialized, the .o file might not
3344 // have allocated a virtual address for the global variable. In
3345 // this case it will have created a symbol for the global variable
3346 // that is undefined/data and external and the value will be the
3347 // byte size of the variable. When we do the address map in
3348 // SymbolFileDWARFDebugMap we rely on having an address, we need to
3349 // do some magic here so we can get the correct address for our
3350 // global variable. The address for all of these entries will be
3351 // zero, and there will be an undefined symbol in this object file,
3352 // and the executable will have a matching symbol with a good
3353 // address. So here we dig up the correct address and replace it in
3354 // the location for the variable, and set the variable's symbol
3355 // context scope to be that of the main executable so the file
3356 // address will resolve correctly.
3357 bool linked_oso_file_addr = false;
3358 if (is_external && location_DW_OP_addr == 0) {
3359 // we have a possible uninitialized extern global
3360 ConstString const_name(mangled ? mangled : name);
3361 ObjectFile *debug_map_objfile =
3362 debug_map_symfile->GetObjectFile();
3363 if (debug_map_objfile) {
3364 Symtab *debug_map_symtab = debug_map_objfile->GetSymtab();
3365 if (debug_map_symtab) {
3366 Symbol *exe_symbol =
3367 debug_map_symtab->FindFirstSymbolWithNameAndType(
3368 const_name, eSymbolTypeData, Symtab::eDebugYes,
3369 Symtab::eVisibilityExtern);
3371 if (exe_symbol->ValueIsAddress()) {
3372 const addr_t exe_file_addr =
3373 exe_symbol->GetAddressRef().GetFileAddress();
3374 if (exe_file_addr != LLDB_INVALID_ADDRESS) {
3375 if (location.Update_DW_OP_addr(exe_file_addr)) {
3376 linked_oso_file_addr = true;
3377 symbol_context_scope = exe_symbol;
3386 if (!linked_oso_file_addr) {
3387 // The DW_OP_addr is not zero, but it contains a .o file address
3388 // which needs to be linked up correctly.
3389 const lldb::addr_t exe_file_addr =
3390 debug_map_symfile->LinkOSOFileAddress(this,
3391 location_DW_OP_addr);
3392 if (exe_file_addr != LLDB_INVALID_ADDRESS) {
3393 // Update the file address for this variable
3394 location.Update_DW_OP_addr(exe_file_addr);
3396 // Variable didn't make it into the final executable
3402 if (location_is_const_value_data &&
3403 die.GetDIE()->IsGlobalOrStaticScopeVariable())
3404 scope = eValueTypeVariableStatic;
3406 scope = eValueTypeVariableLocal;
3407 if (debug_map_symfile) {
3408 // We need to check for TLS addresses that we need to fixup
3409 if (location.ContainsThreadLocalStorage()) {
3410 location.LinkThreadLocalStorage(
3411 debug_map_symfile->GetObjectFile()->GetModule(),
3412 [this, debug_map_symfile](
3413 lldb::addr_t unlinked_file_addr) -> lldb::addr_t {
3414 return debug_map_symfile->LinkOSOFileAddress(
3415 this, unlinked_file_addr);
3417 scope = eValueTypeVariableThreadLocal;
3424 if (symbol_context_scope == nullptr) {
3425 switch (parent_tag) {
3426 case DW_TAG_subprogram:
3427 case DW_TAG_inlined_subroutine:
3428 case DW_TAG_lexical_block:
3430 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(
3431 sc_parent_die.GetID());
3432 if (symbol_context_scope == nullptr)
3433 symbol_context_scope = sc.function;
3438 symbol_context_scope = sc.comp_unit;
3443 if (symbol_context_scope) {
3444 SymbolFileTypeSP type_sp(
3445 new SymbolFileType(*this, GetUID(type_die_form.Reference())));
3447 if (const_value.Form() && type_sp && type_sp->GetType())
3448 location.UpdateValue(const_value.Unsigned(),
3449 type_sp->GetType()->GetByteSize().getValueOr(0),
3450 die.GetCU()->GetAddressByteSize());
3452 var_sp = std::make_shared<Variable>(
3453 die.GetID(), name, mangled, type_sp, scope, symbol_context_scope,
3454 scope_ranges, &decl, location, is_external, is_artificial,
3457 var_sp->SetLocationIsConstantValueData(location_is_const_value_data);
3459 // Not ready to parse this variable yet. It might be a global or static
3460 // variable that is in a function scope and the function in the symbol
3461 // context wasn't filled in yet
3465 // Cache var_sp even if NULL (the variable was just a specification or was
3466 // missing vital information to be able to be displayed in the debugger
3467 // (missing location due to optimization, etc)) so we don't re-parse this
3468 // DIE over and over later...
3469 GetDIEToVariable()[die.GetDIE()] = var_sp;
3471 GetDIEToVariable()[spec_die.GetDIE()] = var_sp;
3477 SymbolFileDWARF::FindBlockContainingSpecification(
3478 const DIERef &func_die_ref, dw_offset_t spec_block_die_offset) {
3479 // Give the concrete function die specified by "func_die_offset", find the
3480 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
3481 // to "spec_block_die_offset"
3482 return FindBlockContainingSpecification(DebugInfo().GetDIE(func_die_ref),
3483 spec_block_die_offset);
3487 SymbolFileDWARF::FindBlockContainingSpecification(
3488 const DWARFDIE &die, dw_offset_t spec_block_die_offset) {
3490 switch (die.Tag()) {
3491 case DW_TAG_subprogram:
3492 case DW_TAG_inlined_subroutine:
3493 case DW_TAG_lexical_block: {
3494 if (die.GetReferencedDIE(DW_AT_specification).GetOffset() ==
3495 spec_block_die_offset)
3498 if (die.GetReferencedDIE(DW_AT_abstract_origin).GetOffset() ==
3499 spec_block_die_offset)
3506 // Give the concrete function die specified by "func_die_offset", find the
3507 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
3508 // to "spec_block_die_offset"
3509 for (DWARFDIE child_die = die.GetFirstChild(); child_die;
3510 child_die = child_die.GetSibling()) {
3511 DWARFDIE result_die =
3512 FindBlockContainingSpecification(child_die, spec_block_die_offset);
3521 size_t SymbolFileDWARF::ParseVariables(const SymbolContext &sc,
3522 const DWARFDIE &orig_die,
3523 const lldb::addr_t func_low_pc,
3524 bool parse_siblings, bool parse_children,
3525 VariableList *cc_variable_list) {
3529 VariableListSP variable_list_sp;
3531 size_t vars_added = 0;
3532 DWARFDIE die = orig_die;
3534 dw_tag_t tag = die.Tag();
3536 // Check to see if we have already parsed this variable or constant?
3537 VariableSP var_sp = GetDIEToVariable()[die.GetDIE()];
3539 if (cc_variable_list)
3540 cc_variable_list->AddVariableIfUnique(var_sp);
3542 // We haven't already parsed it, lets do that now.
3543 if ((tag == DW_TAG_variable) || (tag == DW_TAG_constant) ||
3544 (tag == DW_TAG_formal_parameter && sc.function)) {
3545 if (variable_list_sp.get() == nullptr) {
3546 DWARFDIE sc_parent_die = GetParentSymbolContextDIE(orig_die);
3547 dw_tag_t parent_tag = sc_parent_die.Tag();
3548 switch (parent_tag) {
3549 case DW_TAG_compile_unit:
3550 case DW_TAG_partial_unit:
3551 if (sc.comp_unit != nullptr) {
3552 variable_list_sp = sc.comp_unit->GetVariableList(false);
3553 if (variable_list_sp.get() == nullptr) {
3554 variable_list_sp = std::make_shared<VariableList>();
3557 GetObjectFile()->GetModule()->ReportError(
3558 "parent 0x%8.8" PRIx64 " %s with no valid compile unit in "
3559 "symbol context for 0x%8.8" PRIx64 " %s.\n",
3560 sc_parent_die.GetID(), sc_parent_die.GetTagAsCString(),
3561 orig_die.GetID(), orig_die.GetTagAsCString());
3565 case DW_TAG_subprogram:
3566 case DW_TAG_inlined_subroutine:
3567 case DW_TAG_lexical_block:
3568 if (sc.function != nullptr) {
3569 // Check to see if we already have parsed the variables for the
3572 Block *block = sc.function->GetBlock(true).FindBlockByID(
3573 sc_parent_die.GetID());
3574 if (block == nullptr) {
3575 // This must be a specification or abstract origin with a
3576 // concrete block counterpart in the current function. We need
3577 // to find the concrete block so we can correctly add the
3579 const DWARFDIE concrete_block_die =
3580 FindBlockContainingSpecification(
3581 GetDIE(sc.function->GetID()),
3582 sc_parent_die.GetOffset());
3583 if (concrete_block_die)
3584 block = sc.function->GetBlock(true).FindBlockByID(
3585 concrete_block_die.GetID());
3588 if (block != nullptr) {
3589 const bool can_create = false;
3590 variable_list_sp = block->GetBlockVariableList(can_create);
3591 if (variable_list_sp.get() == nullptr) {
3592 variable_list_sp = std::make_shared<VariableList>();
3593 block->SetVariableList(variable_list_sp);
3600 GetObjectFile()->GetModule()->ReportError(
3601 "didn't find appropriate parent DIE for variable list for "
3602 "0x%8.8" PRIx64 " %s.\n",
3603 orig_die.GetID(), orig_die.GetTagAsCString());
3608 if (variable_list_sp) {
3609 VariableSP var_sp(ParseVariableDIE(sc, die, func_low_pc));
3611 variable_list_sp->AddVariableIfUnique(var_sp);
3612 if (cc_variable_list)
3613 cc_variable_list->AddVariableIfUnique(var_sp);
3620 bool skip_children = (sc.function == nullptr && tag == DW_TAG_subprogram);
3622 if (!skip_children && parse_children && die.HasChildren()) {
3623 vars_added += ParseVariables(sc, die.GetFirstChild(), func_low_pc, true,
3624 true, cc_variable_list);
3628 die = die.GetSibling();
3635 /// Collect call site parameters in a DW_TAG_call_site DIE.
3636 static CallSiteParameterArray
3637 CollectCallSiteParameters(ModuleSP module, DWARFDIE call_site_die) {
3638 CallSiteParameterArray parameters;
3639 for (DWARFDIE child = call_site_die.GetFirstChild(); child.IsValid();
3640 child = child.GetSibling()) {
3641 if (child.Tag() != DW_TAG_call_site_parameter &&
3642 child.Tag() != DW_TAG_GNU_call_site_parameter)
3645 llvm::Optional<DWARFExpression> LocationInCallee;
3646 llvm::Optional<DWARFExpression> LocationInCaller;
3648 DWARFAttributes attributes;
3649 const size_t num_attributes = child.GetAttributes(attributes);
3651 // Parse the location at index \p attr_index within this call site parameter
3652 // DIE, or return None on failure.
3653 auto parse_simple_location =
3654 [&](int attr_index) -> llvm::Optional<DWARFExpression> {
3655 DWARFFormValue form_value;
3656 if (!attributes.ExtractFormValueAtIndex(attr_index, form_value))
3658 if (!DWARFFormValue::IsBlockForm(form_value.Form()))
3660 auto data = child.GetData();
3661 uint32_t block_offset = form_value.BlockData() - data.GetDataStart();
3662 uint32_t block_length = form_value.Unsigned();
3663 return DWARFExpression(module,
3664 DataExtractor(data, block_offset, block_length),
3668 for (size_t i = 0; i < num_attributes; ++i) {
3669 dw_attr_t attr = attributes.AttributeAtIndex(i);
3670 if (attr == DW_AT_location)
3671 LocationInCallee = parse_simple_location(i);
3672 if (attr == DW_AT_call_value || attr == DW_AT_GNU_call_site_value)
3673 LocationInCaller = parse_simple_location(i);
3676 if (LocationInCallee && LocationInCaller) {
3677 CallSiteParameter param = {*LocationInCallee, *LocationInCaller};
3678 parameters.push_back(param);
3684 /// Collect call graph edges present in a function DIE.
3685 std::vector<std::unique_ptr<lldb_private::CallEdge>>
3686 SymbolFileDWARF::CollectCallEdges(ModuleSP module, DWARFDIE function_die) {
3687 // Check if the function has a supported call site-related attribute.
3688 // TODO: In the future it may be worthwhile to support call_all_source_calls.
3689 bool has_call_edges =
3690 function_die.GetAttributeValueAsUnsigned(DW_AT_call_all_calls, 0) ||
3691 function_die.GetAttributeValueAsUnsigned(DW_AT_GNU_all_call_sites, 0);
3692 if (!has_call_edges)
3695 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP));
3696 LLDB_LOG(log, "CollectCallEdges: Found call site info in {0}",
3697 function_die.GetPubname());
3699 // Scan the DIE for TAG_call_site entries.
3700 // TODO: A recursive scan of all blocks in the subprogram is needed in order
3701 // to be DWARF5-compliant. This may need to be done lazily to be performant.
3702 // For now, assume that all entries are nested directly under the subprogram
3703 // (this is the kind of DWARF LLVM produces) and parse them eagerly.
3704 std::vector<std::unique_ptr<CallEdge>> call_edges;
3705 for (DWARFDIE child = function_die.GetFirstChild(); child.IsValid();
3706 child = child.GetSibling()) {
3707 if (child.Tag() != DW_TAG_call_site && child.Tag() != DW_TAG_GNU_call_site)
3710 llvm::Optional<DWARFDIE> call_origin;
3711 llvm::Optional<DWARFExpression> call_target;
3712 addr_t return_pc = LLDB_INVALID_ADDRESS;
3713 addr_t call_inst_pc = LLDB_INVALID_ADDRESS;
3714 addr_t low_pc = LLDB_INVALID_ADDRESS;
3715 bool tail_call = false;
3717 // Second DW_AT_low_pc may come from DW_TAG_subprogram referenced by
3718 // DW_TAG_GNU_call_site's DW_AT_abstract_origin overwriting our 'low_pc'.
3719 // So do not inherit attributes from DW_AT_abstract_origin.
3720 DWARFAttributes attributes;
3721 const size_t num_attributes =
3722 child.GetAttributes(attributes, DWARFDIE::Recurse::no);
3723 for (size_t i = 0; i < num_attributes; ++i) {
3724 DWARFFormValue form_value;
3725 if (!attributes.ExtractFormValueAtIndex(i, form_value)) {
3726 LLDB_LOG(log, "CollectCallEdges: Could not extract TAG_call_site form");
3730 dw_attr_t attr = attributes.AttributeAtIndex(i);
3732 if (attr == DW_AT_call_tail_call || attr == DW_AT_GNU_tail_call)
3733 tail_call = form_value.Boolean();
3735 // Extract DW_AT_call_origin (the call target's DIE).
3736 if (attr == DW_AT_call_origin || attr == DW_AT_abstract_origin) {
3737 call_origin = form_value.Reference();
3738 if (!call_origin->IsValid()) {
3739 LLDB_LOG(log, "CollectCallEdges: Invalid call origin in {0}",
3740 function_die.GetPubname());
3745 if (attr == DW_AT_low_pc)
3746 low_pc = form_value.Address();
3748 // Extract DW_AT_call_return_pc (the PC the call returns to) if it's
3749 // available. It should only ever be unavailable for tail call edges, in
3750 // which case use LLDB_INVALID_ADDRESS.
3751 if (attr == DW_AT_call_return_pc)
3752 return_pc = form_value.Address();
3754 // Extract DW_AT_call_pc (the PC at the call/branch instruction). It
3755 // should only ever be unavailable for non-tail calls, in which case use
3756 // LLDB_INVALID_ADDRESS.
3757 if (attr == DW_AT_call_pc)
3758 call_inst_pc = form_value.Address();
3760 // Extract DW_AT_call_target (the location of the address of the indirect
3762 if (attr == DW_AT_call_target || attr == DW_AT_GNU_call_site_target) {
3763 if (!DWARFFormValue::IsBlockForm(form_value.Form())) {
3765 "CollectCallEdges: AT_call_target does not have block form");
3769 auto data = child.GetData();
3770 uint32_t block_offset = form_value.BlockData() - data.GetDataStart();
3771 uint32_t block_length = form_value.Unsigned();
3772 call_target = DWARFExpression(
3773 module, DataExtractor(data, block_offset, block_length),
3777 if (!call_origin && !call_target) {
3778 LLDB_LOG(log, "CollectCallEdges: call site without any call target");
3782 addr_t caller_address;
3783 CallEdge::AddrType caller_address_type;
3784 if (return_pc != LLDB_INVALID_ADDRESS) {
3785 caller_address = return_pc;
3786 caller_address_type = CallEdge::AddrType::AfterCall;
3787 } else if (low_pc != LLDB_INVALID_ADDRESS) {
3788 caller_address = low_pc;
3789 caller_address_type = CallEdge::AddrType::AfterCall;
3790 } else if (call_inst_pc != LLDB_INVALID_ADDRESS) {
3791 caller_address = call_inst_pc;
3792 caller_address_type = CallEdge::AddrType::Call;
3794 LLDB_LOG(log, "CollectCallEdges: No caller address");
3797 // Adjust any PC forms. It needs to be fixed up if the main executable
3798 // contains a debug map (i.e. pointers to object files), because we need a
3799 // file address relative to the executable's text section.
3800 caller_address = FixupAddress(caller_address);
3802 // Extract call site parameters.
3803 CallSiteParameterArray parameters =
3804 CollectCallSiteParameters(module, child);
3806 std::unique_ptr<CallEdge> edge;
3809 "CollectCallEdges: Found call origin: {0} (retn-PC: {1:x}) "
3811 call_origin->GetPubname(), return_pc, call_inst_pc);
3812 edge = std::make_unique<DirectCallEdge>(
3813 call_origin->GetMangledName(), caller_address_type, caller_address,
3814 tail_call, std::move(parameters));
3817 StreamString call_target_desc;
3818 call_target->GetDescription(&call_target_desc, eDescriptionLevelBrief,
3819 LLDB_INVALID_ADDRESS, nullptr);
3820 LLDB_LOG(log, "CollectCallEdges: Found indirect call target: {0}",
3821 call_target_desc.GetString());
3823 edge = std::make_unique<IndirectCallEdge>(
3824 *call_target, caller_address_type, caller_address, tail_call,
3825 std::move(parameters));
3828 if (log && parameters.size()) {
3829 for (const CallSiteParameter ¶m : parameters) {
3830 StreamString callee_loc_desc, caller_loc_desc;
3831 param.LocationInCallee.GetDescription(&callee_loc_desc,
3832 eDescriptionLevelBrief,
3833 LLDB_INVALID_ADDRESS, nullptr);
3834 param.LocationInCaller.GetDescription(&caller_loc_desc,
3835 eDescriptionLevelBrief,
3836 LLDB_INVALID_ADDRESS, nullptr);
3837 LLDB_LOG(log, "CollectCallEdges: \tparam: {0} => {1}",
3838 callee_loc_desc.GetString(), caller_loc_desc.GetString());
3842 call_edges.push_back(std::move(edge));
3847 std::vector<std::unique_ptr<lldb_private::CallEdge>>
3848 SymbolFileDWARF::ParseCallEdgesInFunction(UserID func_id) {
3849 // ParseCallEdgesInFunction must be called at the behest of an exclusively
3850 // locked lldb::Function instance. Storage for parsed call edges is owned by
3851 // the lldb::Function instance: locking at the SymbolFile level would be too
3852 // late, because the act of storing results from ParseCallEdgesInFunction
3854 DWARFDIE func_die = GetDIE(func_id.GetID());
3855 if (func_die.IsValid())
3856 return CollectCallEdges(GetObjectFile()->GetModule(), func_die);
3860 // PluginInterface protocol
3861 ConstString SymbolFileDWARF::GetPluginName() { return GetPluginNameStatic(); }
3863 uint32_t SymbolFileDWARF::GetPluginVersion() { return 1; }
3865 void SymbolFileDWARF::Dump(lldb_private::Stream &s) {
3866 SymbolFile::Dump(s);
3870 void SymbolFileDWARF::DumpClangAST(Stream &s) {
3871 auto ts_or_err = GetTypeSystemForLanguage(eLanguageTypeC_plus_plus);
3874 TypeSystemClang *clang =
3875 llvm::dyn_cast_or_null<TypeSystemClang>(&ts_or_err.get());
3881 SymbolFileDWARFDebugMap *SymbolFileDWARF::GetDebugMapSymfile() {
3882 if (m_debug_map_symfile == nullptr && !m_debug_map_module_wp.expired()) {
3883 lldb::ModuleSP module_sp(m_debug_map_module_wp.lock());
3885 m_debug_map_symfile =
3886 static_cast<SymbolFileDWARFDebugMap *>(module_sp->GetSymbolFile());
3889 return m_debug_map_symfile;
3892 const std::shared_ptr<SymbolFileDWARFDwo> &SymbolFileDWARF::GetDwpSymbolFile() {
3893 llvm::call_once(m_dwp_symfile_once_flag, [this]() {
3894 ModuleSpec module_spec;
3895 module_spec.GetFileSpec() = m_objfile_sp->GetFileSpec();
3896 module_spec.GetSymbolFileSpec() =
3897 FileSpec(m_objfile_sp->GetModule()->GetFileSpec().GetPath() + ".dwp");
3899 FileSpecList search_paths = Target::GetDefaultDebugFileSearchPaths();
3900 FileSpec dwp_filespec =
3901 Symbols::LocateExecutableSymbolFile(module_spec, search_paths);
3902 if (FileSystem::Instance().Exists(dwp_filespec)) {
3903 DataBufferSP dwp_file_data_sp;
3904 lldb::offset_t dwp_file_data_offset = 0;
3905 ObjectFileSP dwp_obj_file = ObjectFile::FindPlugin(
3906 GetObjectFile()->GetModule(), &dwp_filespec, 0,
3907 FileSystem::Instance().GetByteSize(dwp_filespec), dwp_file_data_sp,
3908 dwp_file_data_offset);
3912 std::make_shared<SymbolFileDWARFDwo>(*this, dwp_obj_file, 0x3fffffff);
3915 return m_dwp_symfile;
3918 llvm::Expected<TypeSystem &> SymbolFileDWARF::GetTypeSystem(DWARFUnit &unit) {
3919 return unit.GetSymbolFileDWARF().GetTypeSystemForLanguage(GetLanguage(unit));
3922 DWARFASTParser *SymbolFileDWARF::GetDWARFParser(DWARFUnit &unit) {
3923 auto type_system_or_err = GetTypeSystem(unit);
3924 if (auto err = type_system_or_err.takeError()) {
3925 LLDB_LOG_ERROR(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_SYMBOLS),
3926 std::move(err), "Unable to get DWARFASTParser");
3929 return type_system_or_err->GetDWARFParser();
3932 CompilerDecl SymbolFileDWARF::GetDecl(const DWARFDIE &die) {
3933 if (DWARFASTParser *dwarf_ast = GetDWARFParser(*die.GetCU()))
3934 return dwarf_ast->GetDeclForUIDFromDWARF(die);
3935 return CompilerDecl();
3938 CompilerDeclContext SymbolFileDWARF::GetDeclContext(const DWARFDIE &die) {
3939 if (DWARFASTParser *dwarf_ast = GetDWARFParser(*die.GetCU()))
3940 return dwarf_ast->GetDeclContextForUIDFromDWARF(die);
3941 return CompilerDeclContext();
3945 SymbolFileDWARF::GetContainingDeclContext(const DWARFDIE &die) {
3946 if (DWARFASTParser *dwarf_ast = GetDWARFParser(*die.GetCU()))
3947 return dwarf_ast->GetDeclContextContainingUIDFromDWARF(die);
3948 return CompilerDeclContext();
3951 DWARFDeclContext SymbolFileDWARF::GetDWARFDeclContext(const DWARFDIE &die) {
3954 DWARFDeclContext dwarf_decl_ctx =
3955 die.GetDIE()->GetDWARFDeclContext(die.GetCU());
3956 dwarf_decl_ctx.SetLanguage(GetLanguage(*die.GetCU()));
3957 return dwarf_decl_ctx;
3960 LanguageType SymbolFileDWARF::LanguageTypeFromDWARF(uint64_t val) {
3961 // Note: user languages between lo_user and hi_user must be handled
3964 case DW_LANG_Mips_Assembler:
3965 return eLanguageTypeMipsAssembler;
3966 case DW_LANG_GOOGLE_RenderScript:
3967 return eLanguageTypeExtRenderScript;
3969 return static_cast<LanguageType>(val);
3973 LanguageType SymbolFileDWARF::GetLanguage(DWARFUnit &unit) {
3974 return LanguageTypeFromDWARF(unit.GetDWARFLanguageType());