LLDB mainline
SymbolFileDWARF.cpp
Go to the documentation of this file.
1//===-- SymbolFileDWARF.cpp -----------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "SymbolFileDWARF.h"
10
11#include "llvm/DebugInfo/DWARF/DWARFDebugLoc.h"
12#include "llvm/Support/Casting.h"
13#include "llvm/Support/Threading.h"
14
15#include "lldb/Core/Module.h"
19#include "lldb/Core/Progress.h"
20#include "lldb/Core/Section.h"
21#include "lldb/Core/Value.h"
25#include "lldb/Utility/Scalar.h"
27#include "lldb/Utility/Timer.h"
28
31
33#include "lldb/Host/Host.h"
34
37
41#include "lldb/Symbol/Block.h"
50#include "lldb/Symbol/TypeMap.h"
53
55#include "lldb/Target/Target.h"
56
57#include "AppleDWARFIndex.h"
58#include "DWARFASTParser.h"
59#include "DWARFASTParserClang.h"
60#include "DWARFCompileUnit.h"
61#include "DWARFDebugAbbrev.h"
62#include "DWARFDebugAranges.h"
63#include "DWARFDebugInfo.h"
64#include "DWARFDebugMacro.h"
65#include "DWARFDebugRanges.h"
66#include "DWARFDeclContext.h"
67#include "DWARFFormValue.h"
68#include "DWARFTypeUnit.h"
69#include "DWARFUnit.h"
71#include "LogChannelDWARF.h"
72#include "ManualDWARFIndex.h"
74#include "SymbolFileDWARFDwo.h"
75
76#include "llvm/DebugInfo/DWARF/DWARFContext.h"
77#include "llvm/Support/FileSystem.h"
78#include "llvm/Support/FormatVariadic.h"
79
80#include <algorithm>
81#include <map>
82#include <memory>
83#include <optional>
84
85#include <cctype>
86#include <cstring>
87
88//#define ENABLE_DEBUG_PRINTF // COMMENT OUT THIS LINE PRIOR TO CHECKIN
89
90#ifdef ENABLE_DEBUG_PRINTF
91#include <cstdio>
92#define DEBUG_PRINTF(fmt, ...) printf(fmt, __VA_ARGS__)
93#else
94#define DEBUG_PRINTF(fmt, ...)
95#endif
96
97using namespace lldb;
98using namespace lldb_private;
99using namespace lldb_private::dwarf;
100
102
104
105namespace {
106
107#define LLDB_PROPERTIES_symbolfiledwarf
108#include "SymbolFileDWARFProperties.inc"
109
110enum {
111#define LLDB_PROPERTIES_symbolfiledwarf
112#include "SymbolFileDWARFPropertiesEnum.inc"
113};
114
115class PluginProperties : public Properties {
116public:
117 static llvm::StringRef GetSettingName() {
119 }
120
121 PluginProperties() {
122 m_collection_sp = std::make_shared<OptionValueProperties>(GetSettingName());
123 m_collection_sp->Initialize(g_symbolfiledwarf_properties);
124 }
125
126 bool IgnoreFileIndexes() const {
127 return GetPropertyAtIndexAs<bool>(ePropertyIgnoreIndexes, false);
128 }
129};
130
131} // namespace
132
133static PluginProperties &GetGlobalPluginProperties() {
134 static PluginProperties g_settings;
135 return g_settings;
136}
137
138static const llvm::DWARFDebugLine::LineTable *
140 llvm::DWARFDebugLine &line, dw_offset_t line_offset,
141 dw_offset_t unit_offset) {
142 Log *log = GetLog(DWARFLog::DebugInfo);
143
144 llvm::DWARFDataExtractor data = context.getOrLoadLineData().GetAsLLVMDWARF();
145 llvm::DWARFContext &ctx = context.GetAsLLVM();
146 llvm::Expected<const llvm::DWARFDebugLine::LineTable *> line_table =
147 line.getOrParseLineTable(
148 data, line_offset, ctx, nullptr, [&](llvm::Error e) {
150 log, std::move(e),
151 "SymbolFileDWARF::ParseLineTable failed to parse: {0}");
152 });
153
154 if (!line_table) {
155 LLDB_LOG_ERROR(log, line_table.takeError(),
156 "SymbolFileDWARF::ParseLineTable failed to parse: {0}");
157 return nullptr;
158 }
159 return *line_table;
160}
161
163 llvm::DWARFDebugLine::Prologue &prologue,
164 dw_offset_t line_offset,
165 dw_offset_t unit_offset) {
166 Log *log = GetLog(DWARFLog::DebugInfo);
167 bool success = true;
168 llvm::DWARFDataExtractor data = context.getOrLoadLineData().GetAsLLVMDWARF();
169 llvm::DWARFContext &ctx = context.GetAsLLVM();
170 uint64_t offset = line_offset;
171 llvm::Error error = prologue.parse(
172 data, &offset,
173 [&](llvm::Error e) {
174 success = false;
175 LLDB_LOG_ERROR(log, std::move(e),
176 "SymbolFileDWARF::ParseSupportFiles failed to parse "
177 "line table prologue: {0}");
178 },
179 ctx, nullptr);
180 if (error) {
181 LLDB_LOG_ERROR(log, std::move(error),
182 "SymbolFileDWARF::ParseSupportFiles failed to parse line "
183 "table prologue: {0}");
184 return false;
185 }
186 return success;
187}
188
189static std::optional<std::string>
190GetFileByIndex(const llvm::DWARFDebugLine::Prologue &prologue, size_t idx,
191 llvm::StringRef compile_dir, FileSpec::Style style) {
192 // Try to get an absolute path first.
193 std::string abs_path;
194 auto absolute = llvm::DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath;
195 if (prologue.getFileNameByIndex(idx, compile_dir, absolute, abs_path, style))
196 return std::move(abs_path);
197
198 // Otherwise ask for a relative path.
199 std::string rel_path;
200 auto relative = llvm::DILineInfoSpecifier::FileLineInfoKind::RawValue;
201 if (!prologue.getFileNameByIndex(idx, compile_dir, relative, rel_path, style))
202 return {};
203 return std::move(rel_path);
204}
205
206static FileSpecList
208 const llvm::DWARFDebugLine::Prologue &prologue,
209 FileSpec::Style style,
210 llvm::StringRef compile_dir = {}) {
211 FileSpecList support_files;
212 size_t first_file = 0;
213 if (prologue.getVersion() <= 4) {
214 // File index 0 is not valid before DWARF v5. Add a dummy entry to ensure
215 // support file list indices match those we get from the debug info and line
216 // tables.
217 support_files.Append(FileSpec());
218 first_file = 1;
219 }
220
221 const size_t number_of_files = prologue.FileNames.size();
222 for (size_t idx = first_file; idx <= number_of_files; ++idx) {
223 std::string remapped_file;
224 if (auto file_path = GetFileByIndex(prologue, idx, compile_dir, style)) {
225 if (auto remapped = module->RemapSourceFile(llvm::StringRef(*file_path)))
226 remapped_file = *remapped;
227 else
228 remapped_file = std::move(*file_path);
229 }
230
231 // Unconditionally add an entry, so the indices match up.
232 support_files.EmplaceBack(remapped_file, style);
233 }
234
235 return support_files;
236}
237
244}
245
248 debugger, PluginProperties::GetSettingName())) {
249 const bool is_global_setting = true;
251 debugger, GetGlobalPluginProperties().GetValueProperties(),
252 "Properties for the dwarf symbol-file plug-in.", is_global_setting);
253 }
254}
255
260}
261
263 return "DWARF and DWARF3 debug symbol file reader.";
264}
265
267 return new SymbolFileDWARF(std::move(objfile_sp),
268 /*dwo_section_list*/ nullptr);
269}
270
272 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
273 if (SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile())
274 return debug_map_symfile->GetTypeList();
276}
277void SymbolFileDWARF::GetTypes(const DWARFDIE &die, dw_offset_t min_die_offset,
278 dw_offset_t max_die_offset, uint32_t type_mask,
279 TypeSet &type_set) {
280 if (die) {
281 const dw_offset_t die_offset = die.GetOffset();
282
283 if (die_offset >= max_die_offset)
284 return;
285
286 if (die_offset >= min_die_offset) {
287 const dw_tag_t tag = die.Tag();
288
289 bool add_type = false;
290
291 switch (tag) {
292 case DW_TAG_array_type:
293 add_type = (type_mask & eTypeClassArray) != 0;
294 break;
295 case DW_TAG_unspecified_type:
296 case DW_TAG_base_type:
297 add_type = (type_mask & eTypeClassBuiltin) != 0;
298 break;
299 case DW_TAG_class_type:
300 add_type = (type_mask & eTypeClassClass) != 0;
301 break;
302 case DW_TAG_structure_type:
303 add_type = (type_mask & eTypeClassStruct) != 0;
304 break;
305 case DW_TAG_union_type:
306 add_type = (type_mask & eTypeClassUnion) != 0;
307 break;
308 case DW_TAG_enumeration_type:
309 add_type = (type_mask & eTypeClassEnumeration) != 0;
310 break;
311 case DW_TAG_subroutine_type:
312 case DW_TAG_subprogram:
313 case DW_TAG_inlined_subroutine:
314 add_type = (type_mask & eTypeClassFunction) != 0;
315 break;
316 case DW_TAG_pointer_type:
317 add_type = (type_mask & eTypeClassPointer) != 0;
318 break;
319 case DW_TAG_rvalue_reference_type:
320 case DW_TAG_reference_type:
321 add_type = (type_mask & eTypeClassReference) != 0;
322 break;
323 case DW_TAG_typedef:
324 add_type = (type_mask & eTypeClassTypedef) != 0;
325 break;
326 case DW_TAG_ptr_to_member_type:
327 add_type = (type_mask & eTypeClassMemberPointer) != 0;
328 break;
329 default:
330 break;
331 }
332
333 if (add_type) {
334 const bool assert_not_being_parsed = true;
335 Type *type = ResolveTypeUID(die, assert_not_being_parsed);
336 if (type)
337 type_set.insert(type);
338 }
339 }
340
341 for (DWARFDIE child_die : die.children()) {
342 GetTypes(child_die, min_die_offset, max_die_offset, type_mask, type_set);
343 }
344 }
345}
346
348 TypeClass type_mask, TypeList &type_list)
349
350{
351 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
352 TypeSet type_set;
353
354 CompileUnit *comp_unit = nullptr;
355 if (sc_scope)
356 comp_unit = sc_scope->CalculateSymbolContextCompileUnit();
357
358 const auto &get = [&](DWARFUnit *unit) {
359 if (!unit)
360 return;
361 unit = &unit->GetNonSkeletonUnit();
362 GetTypes(unit->DIE(), unit->GetOffset(), unit->GetNextUnitOffset(),
363 type_mask, type_set);
364 };
365 if (comp_unit) {
366 get(GetDWARFCompileUnit(comp_unit));
367 } else {
368 DWARFDebugInfo &info = DebugInfo();
369 const size_t num_cus = info.GetNumUnits();
370 for (size_t cu_idx = 0; cu_idx < num_cus; ++cu_idx)
371 get(info.GetUnitAtIndex(cu_idx));
372 }
373
374 std::set<CompilerType> compiler_type_set;
375 for (Type *type : type_set) {
376 CompilerType compiler_type = type->GetForwardCompilerType();
377 if (compiler_type_set.find(compiler_type) == compiler_type_set.end()) {
378 compiler_type_set.insert(compiler_type);
379 type_list.Insert(type->shared_from_this());
380 }
381 }
382}
383
384// Gets the first parent that is a lexical block, function or inlined
385// subroutine, or compile unit.
388 DWARFDIE die;
389 for (die = child_die.GetParent(); die; die = die.GetParent()) {
390 dw_tag_t tag = die.Tag();
391
392 switch (tag) {
393 case DW_TAG_compile_unit:
394 case DW_TAG_partial_unit:
395 case DW_TAG_subprogram:
396 case DW_TAG_inlined_subroutine:
397 case DW_TAG_lexical_block:
398 return die;
399 default:
400 break;
401 }
402 }
403 return DWARFDIE();
404}
405
407 SectionList *dwo_section_list)
408 : SymbolFileCommon(std::move(objfile_sp)), m_debug_map_module_wp(),
409 m_debug_map_symfile(nullptr),
410 m_context(m_objfile_sp->GetModule()->GetSectionList(), dwo_section_list),
411 m_fetched_external_modules(false),
412 m_supports_DW_AT_APPLE_objc_complete_type(eLazyBoolCalculate) {}
413
415
417 static ConstString g_dwarf_section_name("__DWARF");
418 return g_dwarf_section_name;
419}
420
422 SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile();
423 if (debug_map_symfile)
424 return debug_map_symfile->GetUniqueDWARFASTTypeMap();
425 else
427}
428
429llvm::Expected<lldb::TypeSystemSP>
431 if (SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile())
432 return debug_map_symfile->GetTypeSystemForLanguage(language);
433
434 auto type_system_or_err =
435 m_objfile_sp->GetModule()->GetTypeSystemForLanguage(language);
436 if (type_system_or_err)
437 if (auto ts = *type_system_or_err)
438 ts->SetSymbolFile(this);
439 return type_system_or_err;
440}
441
443 Log *log = GetLog(DWARFLog::DebugInfo);
444
446
447 if (!GetGlobalPluginProperties().IgnoreFileIndexes()) {
448 StreamString module_desc;
449 GetObjectFile()->GetModule()->GetDescription(module_desc.AsRawOstream(),
451 DWARFDataExtractor apple_names, apple_namespaces, apple_types, apple_objc;
456
457 if (apple_names.GetByteSize() > 0 || apple_namespaces.GetByteSize() > 0 ||
458 apple_types.GetByteSize() > 0 || apple_objc.GetByteSize() > 0) {
459 Progress progress(llvm::formatv("Loading Apple DWARF index for {0}",
460 module_desc.GetData()));
462 *GetObjectFile()->GetModule(), apple_names, apple_namespaces,
463 apple_types, apple_objc, m_context.getOrLoadStrData());
464
465 if (m_index)
466 return;
467 }
468
469 DWARFDataExtractor debug_names;
471 if (debug_names.GetByteSize() > 0) {
472 Progress progress(
473 llvm::formatv("Loading DWARF5 index for {0}", module_desc.GetData()));
474 llvm::Expected<std::unique_ptr<DebugNamesDWARFIndex>> index_or =
476 debug_names,
477 m_context.getOrLoadStrData(), *this);
478 if (index_or) {
479 m_index = std::move(*index_or);
480 return;
481 }
482 LLDB_LOG_ERROR(log, index_or.takeError(),
483 "Unable to read .debug_names data: {0}");
484 }
485 }
486
487 m_index =
488 std::make_unique<ManualDWARFIndex>(*GetObjectFile()->GetModule(), *this);
489}
490
493 *m_objfile_sp->GetModule()->GetSectionList());
496}
497
499 const lldb_private::SectionList &section_list) {
500 for (SectionSP section_sp : section_list) {
501 if (section_sp->GetChildren().GetSize() > 0) {
502 InitializeFirstCodeAddressRecursive(section_sp->GetChildren());
503 } else if (section_sp->GetType() == eSectionTypeCode) {
505 std::min(m_first_code_address, section_sp->GetFileAddress());
506 }
507 }
508}
509
510bool SymbolFileDWARF::SupportedVersion(uint16_t version) {
511 return version >= 2 && version <= 5;
512}
513
515 uint32_t abilities = 0;
516 if (m_objfile_sp != nullptr) {
517 const Section *section = nullptr;
518 const SectionList *section_list = m_objfile_sp->GetSectionList();
519 if (section_list == nullptr)
520 return 0;
521
522 uint64_t debug_abbrev_file_size = 0;
523 uint64_t debug_info_file_size = 0;
524 uint64_t debug_line_file_size = 0;
525
526 section = section_list->FindSectionByName(GetDWARFMachOSegmentName()).get();
527
528 if (section)
529 section_list = &section->GetChildren();
530
531 section =
532 section_list->FindSectionByType(eSectionTypeDWARFDebugInfo, true).get();
533 if (section != nullptr) {
534 debug_info_file_size = section->GetFileSize();
535
536 section =
538 .get();
539 if (section)
540 debug_abbrev_file_size = section->GetFileSize();
541
542 DWARFDebugAbbrev *abbrev = DebugAbbrev();
543 if (abbrev) {
544 std::set<dw_form_t> invalid_forms;
545 abbrev->GetUnsupportedForms(invalid_forms);
546 if (!invalid_forms.empty()) {
548 error.Printf("unsupported DW_FORM value%s:",
549 invalid_forms.size() > 1 ? "s" : "");
550 for (auto form : invalid_forms)
551 error.Printf(" %#x", form);
552 m_objfile_sp->GetModule()->ReportWarning(
553 "{0}", error.GetString().str().c_str());
554 return 0;
555 }
556 }
557
558 section =
560 .get();
561 if (section)
562 debug_line_file_size = section->GetFileSize();
563 } else {
564 llvm::StringRef symfile_dir =
565 m_objfile_sp->GetFileSpec().GetDirectory().GetStringRef();
566 if (symfile_dir.contains_insensitive(".dsym")) {
567 if (m_objfile_sp->GetType() == ObjectFile::eTypeDebugInfo) {
568 // We have a dSYM file that didn't have a any debug info. If the
569 // string table has a size of 1, then it was made from an
570 // executable with no debug info, or from an executable that was
571 // stripped.
572 section =
574 .get();
575 if (section && section->GetFileSize() == 1) {
576 m_objfile_sp->GetModule()->ReportWarning(
577 "empty dSYM file detected, dSYM was created with an "
578 "executable with no debug info.");
579 }
580 }
581 }
582 }
583
584 constexpr uint64_t MaxDebugInfoSize = (1ull) << DW_DIE_OFFSET_MAX_BITSIZE;
585 if (debug_info_file_size >= MaxDebugInfoSize) {
586 m_objfile_sp->GetModule()->ReportWarning(
587 "SymbolFileDWARF can't load this DWARF. It's larger then {0:x+16}",
588 MaxDebugInfoSize);
589 return 0;
590 }
591
592 if (debug_abbrev_file_size > 0 && debug_info_file_size > 0)
593 abilities |= CompileUnits | Functions | Blocks | GlobalVariables |
595
596 if (debug_line_file_size > 0)
597 abilities |= LineTables;
598 }
599 return abilities;
600}
601
603 DWARFDataExtractor &data) {
604 ModuleSP module_sp(m_objfile_sp->GetModule());
605 const SectionList *section_list = module_sp->GetSectionList();
606 if (!section_list)
607 return;
608
609 SectionSP section_sp(section_list->FindSectionByType(sect_type, true));
610 if (!section_sp)
611 return;
612
613 data.Clear();
614 m_objfile_sp->ReadSectionData(section_sp.get(), data);
615}
616
618 if (m_abbr)
619 return m_abbr.get();
620
621 const DWARFDataExtractor &debug_abbrev_data = m_context.getOrLoadAbbrevData();
622 if (debug_abbrev_data.GetByteSize() == 0)
623 return nullptr;
624
625 auto abbr = std::make_unique<DWARFDebugAbbrev>();
626 llvm::Error error = abbr->parse(debug_abbrev_data);
627 if (error) {
628 Log *log = GetLog(DWARFLog::DebugInfo);
629 LLDB_LOG_ERROR(log, std::move(error),
630 "Unable to read .debug_abbrev section: {0}");
631 return nullptr;
632 }
633
634 m_abbr = std::move(abbr);
635 return m_abbr.get();
636}
637
639 llvm::call_once(m_info_once_flag, [&] {
640 LLDB_SCOPED_TIMERF("%s this = %p", LLVM_PRETTY_FUNCTION,
641 static_cast<void *>(this));
642 m_info = std::make_unique<DWARFDebugInfo>(*this, m_context);
643 });
644 return *m_info;
645}
646
648 if (!comp_unit)
649 return nullptr;
650
651 // The compile unit ID is the index of the DWARF unit.
652 DWARFUnit *dwarf_cu = DebugInfo().GetUnitAtIndex(comp_unit->GetID());
653 if (dwarf_cu && dwarf_cu->GetUserData() == nullptr)
654 dwarf_cu->SetUserData(comp_unit);
655
656 // It must be DWARFCompileUnit when it created a CompileUnit.
657 return llvm::cast_or_null<DWARFCompileUnit>(dwarf_cu);
658}
659
661 if (!m_ranges) {
662 LLDB_SCOPED_TIMERF("%s this = %p", LLVM_PRETTY_FUNCTION,
663 static_cast<void *>(this));
664
666 m_ranges = std::make_unique<DWARFDebugRanges>();
667
668 if (m_ranges)
669 m_ranges->Extract(m_context);
670 }
671 return m_ranges.get();
672}
673
674/// Make an absolute path out of \p file_spec and remap it using the
675/// module's source remapping dictionary.
676static void MakeAbsoluteAndRemap(FileSpec &file_spec, DWARFUnit &dwarf_cu,
677 const ModuleSP &module_sp) {
678 if (!file_spec)
679 return;
680 // If we have a full path to the compile unit, we don't need to
681 // resolve the file. This can be expensive e.g. when the source
682 // files are NFS mounted.
683 file_spec.MakeAbsolute(dwarf_cu.GetCompilationDirectory());
684
685 if (auto remapped_file = module_sp->RemapSourceFile(file_spec.GetPath()))
686 file_spec.SetFile(*remapped_file, FileSpec::Style::native);
687}
688
689/// Return the DW_AT_(GNU_)dwo_name.
690static const char *GetDWOName(DWARFCompileUnit &dwarf_cu,
691 const DWARFDebugInfoEntry &cu_die) {
692 const char *dwo_name =
693 cu_die.GetAttributeValueAsString(&dwarf_cu, DW_AT_GNU_dwo_name, nullptr);
694 if (!dwo_name)
695 dwo_name =
696 cu_die.GetAttributeValueAsString(&dwarf_cu, DW_AT_dwo_name, nullptr);
697 return dwo_name;
698}
699
701 CompUnitSP cu_sp;
702 CompileUnit *comp_unit = (CompileUnit *)dwarf_cu.GetUserData();
703 if (comp_unit) {
704 // We already parsed this compile unit, had out a shared pointer to it
705 cu_sp = comp_unit->shared_from_this();
706 } else {
707 if (GetDebugMapSymfile()) {
708 // Let the debug map create the compile unit
709 cu_sp = m_debug_map_symfile->GetCompileUnit(this, dwarf_cu);
710 dwarf_cu.SetUserData(cu_sp.get());
711 } else {
712 ModuleSP module_sp(m_objfile_sp->GetModule());
713 if (module_sp) {
714 auto initialize_cu = [&](const FileSpec &file_spec,
715 LanguageType cu_language) {
717 cu_sp = std::make_shared<CompileUnit>(
718 module_sp, &dwarf_cu, file_spec,
719 *GetDWARFUnitIndex(dwarf_cu.GetID()), cu_language,
721
722 dwarf_cu.SetUserData(cu_sp.get());
723
724 SetCompileUnitAtIndex(dwarf_cu.GetID(), cu_sp);
725 };
726
727 auto lazy_initialize_cu = [&]() {
728 // If the version is < 5, we can't do lazy initialization.
729 if (dwarf_cu.GetVersion() < 5)
730 return false;
731
732 // If there is no DWO, there is no reason to initialize
733 // lazily; we will do eager initialization in that case.
734 if (GetDebugMapSymfile())
735 return false;
736 const DWARFBaseDIE cu_die = dwarf_cu.GetUnitDIEOnly();
737 if (!cu_die)
738 return false;
739 if (!GetDWOName(dwarf_cu, *cu_die.GetDIE()))
740 return false;
741
742 // With DWARFv5 we can assume that the first support
743 // file is also the name of the compile unit. This
744 // allows us to avoid loading the non-skeleton unit,
745 // which may be in a separate DWO file.
746 FileSpecList support_files;
747 if (!ParseSupportFiles(dwarf_cu, module_sp, support_files))
748 return false;
749 if (support_files.GetSize() == 0)
750 return false;
751
752 initialize_cu(support_files.GetFileSpecAtIndex(0),
754 cu_sp->SetSupportFiles(std::move(support_files));
755 return true;
756 };
757
758 if (!lazy_initialize_cu()) {
759 // Eagerly initialize compile unit
760 const DWARFBaseDIE cu_die =
762 if (cu_die) {
764 dwarf_cu.GetDWARFLanguageType());
765
766 FileSpec cu_file_spec(cu_die.GetName(), dwarf_cu.GetPathStyle());
767
768 // Path needs to be remapped in this case. In the support files
769 // case ParseSupportFiles takes care of the remapping.
770 MakeAbsoluteAndRemap(cu_file_spec, dwarf_cu, module_sp);
771
772 initialize_cu(cu_file_spec, cu_language);
773 }
774 }
775 }
776 }
777 }
778 return cu_sp;
779}
780
782 if (!m_lldb_cu_to_dwarf_unit.empty())
783 return;
784
785 DWARFDebugInfo &info = DebugInfo();
786 if (!info.ContainsTypeUnits()) {
787 // We can use a 1-to-1 mapping. No need to build a translation table.
788 return;
789 }
790 for (uint32_t i = 0, num = info.GetNumUnits(); i < num; ++i) {
791 if (auto *cu = llvm::dyn_cast<DWARFCompileUnit>(info.GetUnitAtIndex(i))) {
792 cu->SetID(m_lldb_cu_to_dwarf_unit.size());
793 m_lldb_cu_to_dwarf_unit.push_back(i);
794 }
795 }
796}
797
798std::optional<uint32_t> SymbolFileDWARF::GetDWARFUnitIndex(uint32_t cu_idx) {
800 if (m_lldb_cu_to_dwarf_unit.empty())
801 return cu_idx;
802 if (cu_idx >= m_lldb_cu_to_dwarf_unit.size())
803 return std::nullopt;
804 return m_lldb_cu_to_dwarf_unit[cu_idx];
805}
806
811}
812
814 ASSERT_MODULE_LOCK(this);
815 if (std::optional<uint32_t> dwarf_idx = GetDWARFUnitIndex(cu_idx)) {
816 if (auto *dwarf_cu = llvm::cast_or_null<DWARFCompileUnit>(
817 DebugInfo().GetUnitAtIndex(*dwarf_idx)))
818 return ParseCompileUnit(*dwarf_cu);
819 }
820 return {};
821}
822
824 const DWARFDIE &die) {
825 ASSERT_MODULE_LOCK(this);
826 if (!die.IsValid())
827 return nullptr;
828
829 auto type_system_or_err = GetTypeSystemForLanguage(GetLanguage(*die.GetCU()));
830 if (auto err = type_system_or_err.takeError()) {
831 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
832 "Unable to parse function: {0}");
833 return nullptr;
834 }
835 auto ts = *type_system_or_err;
836 if (!ts)
837 return nullptr;
838 DWARFASTParser *dwarf_ast = ts->GetDWARFParser();
839 if (!dwarf_ast)
840 return nullptr;
841
842 DWARFRangeList ranges = die.GetDIE()->GetAttributeAddressRanges(
843 die.GetCU(), /*check_hi_lo_pc=*/true);
844 if (ranges.IsEmpty())
845 return nullptr;
846
847 // Union of all ranges in the function DIE (if the function is
848 // discontiguous)
849 lldb::addr_t lowest_func_addr = ranges.GetMinRangeBase(0);
850 lldb::addr_t highest_func_addr = ranges.GetMaxRangeEnd(0);
851 if (lowest_func_addr == LLDB_INVALID_ADDRESS ||
852 lowest_func_addr >= highest_func_addr ||
853 lowest_func_addr < m_first_code_address)
854 return nullptr;
855
856 ModuleSP module_sp(die.GetModule());
857 AddressRange func_range;
859 lowest_func_addr, module_sp->GetSectionList());
860 if (!func_range.GetBaseAddress().IsValid())
861 return nullptr;
862
863 func_range.SetByteSize(highest_func_addr - lowest_func_addr);
864 if (!FixupAddress(func_range.GetBaseAddress()))
865 return nullptr;
866
867 return dwarf_ast->ParseFunctionFromDWARF(comp_unit, die, func_range);
868}
869
872 ASSERT_MODULE_LOCK(this);
873 if (!die.IsValid()) {
874 return ConstString();
875 }
876
877 auto type_system_or_err = GetTypeSystemForLanguage(GetLanguage(*die.GetCU()));
878 if (auto err = type_system_or_err.takeError()) {
879 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
880 "Unable to construct demangled name for function: {0}");
881 return ConstString();
882 }
883
884 auto ts = *type_system_or_err;
885 if (!ts) {
886 LLDB_LOG(GetLog(LLDBLog::Symbols), "Type system no longer live");
887 return ConstString();
888 }
889 DWARFASTParser *dwarf_ast = ts->GetDWARFParser();
890 if (!dwarf_ast)
891 return ConstString();
892
893 return dwarf_ast->ConstructDemangledNameFromDWARF(die);
894}
895
897 SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile();
898 if (debug_map_symfile)
899 return debug_map_symfile->LinkOSOFileAddress(this, file_addr);
900 return file_addr;
901}
902
904 SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile();
905 if (debug_map_symfile) {
906 return debug_map_symfile->LinkOSOAddress(addr);
907 }
908 // This is a normal DWARF file, no address fixups need to happen
909 return true;
910}
912 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
913 DWARFUnit *dwarf_cu = GetDWARFCompileUnit(&comp_unit);
914 if (dwarf_cu)
915 return GetLanguage(dwarf_cu->GetNonSkeletonUnit());
916 else
918}
919
921 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
922 DWARFUnit *dwarf_cu = GetDWARFCompileUnit(&comp_unit);
923 if (!dwarf_cu)
924 return {};
925 const DWARFBaseDIE cu_die = dwarf_cu->GetNonSkeletonUnit().GetUnitDIEOnly();
926 if (!cu_die)
927 return {};
928 const char *sdk = cu_die.GetAttributeValueAsString(DW_AT_APPLE_sdk, nullptr);
929 if (!sdk)
930 return {};
931 const char *sysroot =
932 cu_die.GetAttributeValueAsString(DW_AT_LLVM_sysroot, "");
933 // Register the sysroot path remapping with the module belonging to
934 // the CU as well as the one belonging to the symbol file. The two
935 // would be different if this is an OSO object and module is the
936 // corresponding debug map, in which case both should be updated.
937 ModuleSP module_sp = comp_unit.GetModule();
938 if (module_sp)
939 module_sp->RegisterXcodeSDK(sdk, sysroot);
940
941 ModuleSP local_module_sp = m_objfile_sp->GetModule();
942 if (local_module_sp && local_module_sp != module_sp)
943 local_module_sp->RegisterXcodeSDK(sdk, sysroot);
944
945 return {sdk};
946}
947
950 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
951 DWARFUnit *dwarf_cu = GetDWARFCompileUnit(&comp_unit);
952 if (!dwarf_cu)
953 return 0;
954
955 size_t functions_added = 0;
956 dwarf_cu = &dwarf_cu->GetNonSkeletonUnit();
957 for (DWARFDebugInfoEntry &entry : dwarf_cu->dies()) {
958 if (entry.Tag() != DW_TAG_subprogram)
959 continue;
960
961 DWARFDIE die(dwarf_cu, &entry);
962 if (comp_unit.FindFunctionByUID(die.GetID()))
963 continue;
964 if (ParseFunction(comp_unit, die))
965 ++functions_added;
966 }
967 // FixupTypes();
968 return functions_added;
969}
970
972 CompileUnit &comp_unit,
973 llvm::DenseSet<lldb_private::SymbolFile *> &visited_symbol_files,
974 llvm::function_ref<bool(Module &)> lambda) {
975 // Only visit each symbol file once.
976 if (!visited_symbol_files.insert(this).second)
977 return false;
978
980 for (auto &p : m_external_type_modules) {
981 ModuleSP module = p.second;
982 if (!module)
983 continue;
984
985 // Invoke the action and potentially early-exit.
986 if (lambda(*module))
987 return true;
988
989 for (std::size_t i = 0; i < module->GetNumCompileUnits(); ++i) {
990 auto cu = module->GetCompileUnitAtIndex(i);
991 bool early_exit = cu->ForEachExternalModule(visited_symbol_files, lambda);
992 if (early_exit)
993 return true;
994 }
995 }
996 return false;
997}
998
1000 FileSpecList &support_files) {
1001 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1002 DWARFUnit *dwarf_cu = GetDWARFCompileUnit(&comp_unit);
1003 if (!dwarf_cu)
1004 return false;
1005
1006 if (!ParseSupportFiles(*dwarf_cu, comp_unit.GetModule(), support_files))
1007 return false;
1008
1009 comp_unit.SetSupportFiles(support_files);
1010 return true;
1011}
1012
1014 const ModuleSP &module,
1015 FileSpecList &support_files) {
1016
1017 dw_offset_t offset = dwarf_cu.GetLineTableOffset();
1018 if (offset == DW_INVALID_OFFSET)
1019 return false;
1020
1022 llvm::DWARFDebugLine::Prologue prologue;
1023 if (!ParseLLVMLineTablePrologue(m_context, prologue, offset,
1024 dwarf_cu.GetOffset()))
1025 return false;
1026
1027 std::string comp_dir = dwarf_cu.GetCompilationDirectory().GetPath();
1028 support_files = ParseSupportFilesFromPrologue(
1029 module, prologue, dwarf_cu.GetPathStyle(), comp_dir);
1030 return true;
1031}
1032
1034 if (auto *dwarf_cu = llvm::dyn_cast<DWARFCompileUnit>(&unit)) {
1035 if (CompileUnit *lldb_cu = GetCompUnitForDWARFCompUnit(*dwarf_cu))
1036 return lldb_cu->GetSupportFiles().GetFileSpecAtIndex(file_idx);
1037 return FileSpec();
1038 }
1039
1040 auto &tu = llvm::cast<DWARFTypeUnit>(unit);
1041 return GetTypeUnitSupportFiles(tu).GetFileSpecAtIndex(file_idx);
1042}
1043
1044const FileSpecList &
1046 static FileSpecList empty_list;
1047
1048 dw_offset_t offset = tu.GetLineTableOffset();
1049 if (offset == DW_INVALID_OFFSET ||
1050 offset == llvm::DenseMapInfo<dw_offset_t>::getEmptyKey() ||
1051 offset == llvm::DenseMapInfo<dw_offset_t>::getTombstoneKey())
1052 return empty_list;
1053
1054 // Many type units can share a line table, so parse the support file list
1055 // once, and cache it based on the offset field.
1056 auto iter_bool = m_type_unit_support_files.try_emplace(offset);
1057 FileSpecList &list = iter_bool.first->second;
1058 if (iter_bool.second) {
1059 uint64_t line_table_offset = offset;
1060 llvm::DWARFDataExtractor data =
1062 llvm::DWARFContext &ctx = m_context.GetAsLLVM();
1063 llvm::DWARFDebugLine::Prologue prologue;
1064 auto report = [](llvm::Error error) {
1065 Log *log = GetLog(DWARFLog::DebugInfo);
1066 LLDB_LOG_ERROR(log, std::move(error),
1067 "SymbolFileDWARF::GetTypeUnitSupportFiles failed to parse "
1068 "the line table prologue: {0}");
1069 };
1071 llvm::Error error = prologue.parse(data, &line_table_offset, report, ctx);
1072 if (error) {
1073 report(std::move(error));
1074 } else {
1075 list = ParseSupportFilesFromPrologue(GetObjectFile()->GetModule(),
1076 prologue, tu.GetPathStyle());
1077 }
1078 }
1079 return list;
1080}
1081
1083 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1084 DWARFUnit *dwarf_cu = GetDWARFCompileUnit(&comp_unit);
1085 if (dwarf_cu)
1086 return dwarf_cu->GetNonSkeletonUnit().GetIsOptimized();
1087 return false;
1088}
1089
1092 std::vector<SourceModule> &imported_modules) {
1093 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1094 assert(sc.comp_unit);
1095 DWARFUnit *dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
1096 if (!dwarf_cu)
1097 return false;
1099 sc.comp_unit->GetLanguage()))
1100 return false;
1102
1103 const DWARFDIE die = dwarf_cu->DIE();
1104 if (!die)
1105 return false;
1106
1107 for (DWARFDIE child_die : die.children()) {
1108 if (child_die.Tag() != DW_TAG_imported_declaration)
1109 continue;
1110
1111 DWARFDIE module_die = child_die.GetReferencedDIE(DW_AT_import);
1112 if (module_die.Tag() != DW_TAG_module)
1113 continue;
1114
1115 if (const char *name =
1116 module_die.GetAttributeValueAsString(DW_AT_name, nullptr)) {
1117 SourceModule module;
1118 module.path.push_back(ConstString(name));
1119
1120 DWARFDIE parent_die = module_die;
1121 while ((parent_die = parent_die.GetParent())) {
1122 if (parent_die.Tag() != DW_TAG_module)
1123 break;
1124 if (const char *name =
1125 parent_die.GetAttributeValueAsString(DW_AT_name, nullptr))
1126 module.path.push_back(ConstString(name));
1127 }
1128 std::reverse(module.path.begin(), module.path.end());
1129 if (const char *include_path = module_die.GetAttributeValueAsString(
1130 DW_AT_LLVM_include_path, nullptr)) {
1131 FileSpec include_spec(include_path, dwarf_cu->GetPathStyle());
1132 MakeAbsoluteAndRemap(include_spec, *dwarf_cu,
1133 m_objfile_sp->GetModule());
1134 module.search_path = ConstString(include_spec.GetPath());
1135 }
1136 if (const char *sysroot = dwarf_cu->DIE().GetAttributeValueAsString(
1137 DW_AT_LLVM_sysroot, nullptr))
1138 module.sysroot = ConstString(sysroot);
1139 imported_modules.push_back(module);
1140 }
1141 }
1142 return true;
1143}
1144
1146 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1147 if (comp_unit.GetLineTable() != nullptr)
1148 return true;
1149
1150 DWARFUnit *dwarf_cu = GetDWARFCompileUnit(&comp_unit);
1151 if (!dwarf_cu)
1152 return false;
1153
1154 dw_offset_t offset = dwarf_cu->GetLineTableOffset();
1155 if (offset == DW_INVALID_OFFSET)
1156 return false;
1157
1159 llvm::DWARFDebugLine line;
1160 const llvm::DWARFDebugLine::LineTable *line_table =
1161 ParseLLVMLineTable(m_context, line, offset, dwarf_cu->GetOffset());
1162
1163 if (!line_table)
1164 return false;
1165
1166 // FIXME: Rather than parsing the whole line table and then copying it over
1167 // into LLDB, we should explore using a callback to populate the line table
1168 // while we parse to reduce memory usage.
1169 std::vector<std::unique_ptr<LineSequence>> sequences;
1170 // The Sequences view contains only valid line sequences. Don't iterate over
1171 // the Rows directly.
1172 for (const llvm::DWARFDebugLine::Sequence &seq : line_table->Sequences) {
1173 // Ignore line sequences that do not start after the first code address.
1174 // All addresses generated in a sequence are incremental so we only need
1175 // to check the first one of the sequence. Check the comment at the
1176 // m_first_code_address declaration for more details on this.
1177 if (seq.LowPC < m_first_code_address)
1178 continue;
1179 std::unique_ptr<LineSequence> sequence =
1181 for (unsigned idx = seq.FirstRowIndex; idx < seq.LastRowIndex; ++idx) {
1182 const llvm::DWARFDebugLine::Row &row = line_table->Rows[idx];
1184 sequence.get(), row.Address.Address, row.Line, row.Column, row.File,
1185 row.IsStmt, row.BasicBlock, row.PrologueEnd, row.EpilogueBegin,
1186 row.EndSequence);
1187 }
1188 sequences.push_back(std::move(sequence));
1189 }
1190
1191 std::unique_ptr<LineTable> line_table_up =
1192 std::make_unique<LineTable>(&comp_unit, std::move(sequences));
1193
1194 if (SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile()) {
1195 // We have an object file that has a line table with addresses that are not
1196 // linked. We need to link the line table and convert the addresses that
1197 // are relative to the .o file into addresses for the main executable.
1198 comp_unit.SetLineTable(
1199 debug_map_symfile->LinkOSOLineTable(this, line_table_up.get()));
1200 } else {
1201 comp_unit.SetLineTable(line_table_up.release());
1202 }
1203
1204 return true;
1205}
1206
1209 auto iter = m_debug_macros_map.find(*offset);
1210 if (iter != m_debug_macros_map.end())
1211 return iter->second;
1212
1214 const DWARFDataExtractor &debug_macro_data = m_context.getOrLoadMacroData();
1215 if (debug_macro_data.GetByteSize() == 0)
1216 return DebugMacrosSP();
1217
1219 m_debug_macros_map[*offset] = debug_macros_sp;
1220
1221 const DWARFDebugMacroHeader &header =
1222 DWARFDebugMacroHeader::ParseHeader(debug_macro_data, offset);
1224 debug_macro_data, m_context.getOrLoadStrData(), header.OffsetIs64Bit(),
1225 offset, this, debug_macros_sp);
1226
1227 return debug_macros_sp;
1228}
1229
1231 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1232
1233 DWARFUnit *dwarf_cu = GetDWARFCompileUnit(&comp_unit);
1234 if (dwarf_cu == nullptr)
1235 return false;
1236
1237 const DWARFBaseDIE dwarf_cu_die = dwarf_cu->GetUnitDIEOnly();
1238 if (!dwarf_cu_die)
1239 return false;
1240
1241 lldb::offset_t sect_offset =
1242 dwarf_cu_die.GetAttributeValueAsUnsigned(DW_AT_macros, DW_INVALID_OFFSET);
1243 if (sect_offset == DW_INVALID_OFFSET)
1244 sect_offset = dwarf_cu_die.GetAttributeValueAsUnsigned(DW_AT_GNU_macros,
1246 if (sect_offset == DW_INVALID_OFFSET)
1247 return false;
1248
1249 comp_unit.SetDebugMacros(ParseDebugMacros(&sect_offset));
1250
1251 return true;
1252}
1253
1255 lldb_private::CompileUnit &comp_unit, Block *parent_block,
1256 const DWARFDIE &orig_die, addr_t subprogram_low_pc, uint32_t depth) {
1257 size_t blocks_added = 0;
1258 DWARFDIE die = orig_die;
1259 while (die) {
1260 dw_tag_t tag = die.Tag();
1261
1262 switch (tag) {
1263 case DW_TAG_inlined_subroutine:
1264 case DW_TAG_subprogram:
1265 case DW_TAG_lexical_block: {
1266 Block *block = nullptr;
1267 if (tag == DW_TAG_subprogram) {
1268 // Skip any DW_TAG_subprogram DIEs that are inside of a normal or
1269 // inlined functions. These will be parsed on their own as separate
1270 // entities.
1271
1272 if (depth > 0)
1273 break;
1274
1275 block = parent_block;
1276 } else {
1277 BlockSP block_sp(new Block(die.GetID()));
1278 parent_block->AddChild(block_sp);
1279 block = block_sp.get();
1280 }
1281 DWARFRangeList ranges;
1282 const char *name = nullptr;
1283 const char *mangled_name = nullptr;
1284
1285 std::optional<int> decl_file;
1286 std::optional<int> decl_line;
1287 std::optional<int> decl_column;
1288 std::optional<int> call_file;
1289 std::optional<int> call_line;
1290 std::optional<int> call_column;
1291 if (die.GetDIENamesAndRanges(name, mangled_name, ranges, decl_file,
1292 decl_line, decl_column, call_file, call_line,
1293 call_column, nullptr)) {
1294 if (tag == DW_TAG_subprogram) {
1295 assert(subprogram_low_pc == LLDB_INVALID_ADDRESS);
1296 subprogram_low_pc = ranges.GetMinRangeBase(0);
1297 } else if (tag == DW_TAG_inlined_subroutine) {
1298 // We get called here for inlined subroutines in two ways. The first
1299 // time is when we are making the Function object for this inlined
1300 // concrete instance. Since we're creating a top level block at
1301 // here, the subprogram_low_pc will be LLDB_INVALID_ADDRESS. So we
1302 // need to adjust the containing address. The second time is when we
1303 // are parsing the blocks inside the function that contains the
1304 // inlined concrete instance. Since these will be blocks inside the
1305 // containing "real" function the offset will be for that function.
1306 if (subprogram_low_pc == LLDB_INVALID_ADDRESS) {
1307 subprogram_low_pc = ranges.GetMinRangeBase(0);
1308 }
1309 }
1310
1311 const size_t num_ranges = ranges.GetSize();
1312 for (size_t i = 0; i < num_ranges; ++i) {
1313 const DWARFRangeList::Entry &range = ranges.GetEntryRef(i);
1314 const addr_t range_base = range.GetRangeBase();
1315 if (range_base >= subprogram_low_pc)
1316 block->AddRange(Block::Range(range_base - subprogram_low_pc,
1317 range.GetByteSize()));
1318 else {
1319 GetObjectFile()->GetModule()->ReportError(
1320 "{0:x8}: adding range [{1:x16}-{2:x16}) which has a base "
1321 "that is less than the function's low PC {3:x16}. Please file "
1322 "a bug and attach the file at the "
1323 "start of this error message",
1324 block->GetID(), range_base, range.GetRangeEnd(),
1325 subprogram_low_pc);
1326 }
1327 }
1328 block->FinalizeRanges();
1329
1330 if (tag != DW_TAG_subprogram &&
1331 (name != nullptr || mangled_name != nullptr)) {
1332 std::unique_ptr<Declaration> decl_up;
1333 if (decl_file || decl_line || decl_column)
1334 decl_up = std::make_unique<Declaration>(
1336 decl_file ? *decl_file : 0),
1337 decl_line ? *decl_line : 0, decl_column ? *decl_column : 0);
1338
1339 std::unique_ptr<Declaration> call_up;
1340 if (call_file || call_line || call_column)
1341 call_up = std::make_unique<Declaration>(
1343 call_file ? *call_file : 0),
1344 call_line ? *call_line : 0, call_column ? *call_column : 0);
1345
1346 block->SetInlinedFunctionInfo(name, mangled_name, decl_up.get(),
1347 call_up.get());
1348 }
1349
1350 ++blocks_added;
1351
1352 if (die.HasChildren()) {
1353 blocks_added +=
1354 ParseBlocksRecursive(comp_unit, block, die.GetFirstChild(),
1355 subprogram_low_pc, depth + 1);
1356 }
1357 }
1358 } break;
1359 default:
1360 break;
1361 }
1362
1363 // Only parse siblings of the block if we are not at depth zero. A depth of
1364 // zero indicates we are currently parsing the top level DW_TAG_subprogram
1365 // DIE
1366
1367 if (depth == 0)
1368 die.Clear();
1369 else
1370 die = die.GetSibling();
1371 }
1372 return blocks_added;
1373}
1374
1376 if (parent_die) {
1377 for (DWARFDIE die : parent_die.children()) {
1378 dw_tag_t tag = die.Tag();
1379 bool check_virtuality = false;
1380 switch (tag) {
1381 case DW_TAG_inheritance:
1382 case DW_TAG_subprogram:
1383 check_virtuality = true;
1384 break;
1385 default:
1386 break;
1387 }
1388 if (check_virtuality) {
1389 if (die.GetAttributeValueAsUnsigned(DW_AT_virtuality, 0) != 0)
1390 return true;
1391 }
1392 }
1393 }
1394 return false;
1395}
1396
1398 auto *type_system = decl_ctx.GetTypeSystem();
1399 if (type_system != nullptr)
1401 decl_ctx);
1402}
1403
1406
1408 // This method can be called without going through the symbol vendor so we
1409 // need to lock the module.
1410 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1411 // Anytime we have a lldb::user_id_t, we must get the DIE by calling
1412 // SymbolFileDWARF::GetDIE(). See comments inside the
1413 // SymbolFileDWARF::GetDIE() for details.
1414 if (DWARFDIE die = GetDIE(type_uid))
1415 return GetDecl(die);
1416 return CompilerDecl();
1417}
1418
1421 // This method can be called without going through the symbol vendor so we
1422 // need to lock the module.
1423 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1424 // Anytime we have a lldb::user_id_t, we must get the DIE by calling
1425 // SymbolFileDWARF::GetDIE(). See comments inside the
1426 // SymbolFileDWARF::GetDIE() for details.
1427 if (DWARFDIE die = GetDIE(type_uid))
1428 return GetDeclContext(die);
1429 return CompilerDeclContext();
1430}
1431
1434 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1435 // Anytime we have a lldb::user_id_t, we must get the DIE by calling
1436 // SymbolFileDWARF::GetDIE(). See comments inside the
1437 // SymbolFileDWARF::GetDIE() for details.
1438 if (DWARFDIE die = GetDIE(type_uid))
1439 return GetContainingDeclContext(die);
1440 return CompilerDeclContext();
1441}
1442
1444 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1445 // Anytime we have a lldb::user_id_t, we must get the DIE by calling
1446 // SymbolFileDWARF::GetDIE(). See comments inside the
1447 // SymbolFileDWARF::GetDIE() for details.
1448 if (DWARFDIE type_die = GetDIE(type_uid))
1449 return type_die.ResolveType();
1450 else
1451 return nullptr;
1452}
1453
1454std::optional<SymbolFile::ArrayInfo> SymbolFileDWARF::GetDynamicArrayInfoForUID(
1455 lldb::user_id_t type_uid, const lldb_private::ExecutionContext *exe_ctx) {
1456 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1457 if (DWARFDIE type_die = GetDIE(type_uid))
1458 return DWARFASTParser::ParseChildArrayInfo(type_die, exe_ctx);
1459 else
1460 return std::nullopt;
1461}
1462
1464 return ResolveType(GetDIE(die_ref), true);
1465}
1466
1468 bool assert_not_being_parsed) {
1469 if (die) {
1470 Log *log = GetLog(DWARFLog::DebugInfo);
1471 if (log)
1472 GetObjectFile()->GetModule()->LogMessage(
1473 log, "SymbolFileDWARF::ResolveTypeUID (die = {0:x16}) {1} '{2}'",
1474 die.GetOffset(), die.GetTagAsCString(), die.GetName());
1475
1476 // We might be coming in in the middle of a type tree (a class within a
1477 // class, an enum within a class), so parse any needed parent DIEs before
1478 // we get to this one...
1479 DWARFDIE decl_ctx_die = GetDeclContextDIEContainingDIE(die);
1480 if (decl_ctx_die) {
1481 if (log) {
1482 switch (decl_ctx_die.Tag()) {
1483 case DW_TAG_structure_type:
1484 case DW_TAG_union_type:
1485 case DW_TAG_class_type: {
1486 // Get the type, which could be a forward declaration
1487 if (log)
1488 GetObjectFile()->GetModule()->LogMessage(
1489 log,
1490 "SymbolFileDWARF::ResolveTypeUID (die = {0:x16}) "
1491 "{1} '{2}' "
1492 "resolve parent forward type for {3:x16})",
1493 die.GetOffset(), die.GetTagAsCString(), die.GetName(),
1494 decl_ctx_die.GetOffset());
1495 } break;
1496
1497 default:
1498 break;
1499 }
1500 }
1501 }
1502 return ResolveType(die);
1503 }
1504 return nullptr;
1505}
1506
1507// This function is used when SymbolFileDWARFDebugMap owns a bunch of
1508// SymbolFileDWARF objects to detect if this DWARF file is the one that can
1509// resolve a compiler_type.
1511 const CompilerType &compiler_type) {
1512 CompilerType compiler_type_no_qualifiers =
1513 ClangUtil::RemoveFastQualifiers(compiler_type);
1514 if (GetForwardDeclClangTypeToDie().count(
1515 compiler_type_no_qualifiers.GetOpaqueQualType())) {
1516 return true;
1517 }
1518 auto type_system = compiler_type.GetTypeSystem();
1519 auto clang_type_system = type_system.dyn_cast_or_null<TypeSystemClang>();
1520 if (!clang_type_system)
1521 return false;
1522 DWARFASTParserClang *ast_parser =
1523 static_cast<DWARFASTParserClang *>(clang_type_system->GetDWARFParser());
1524 return ast_parser->GetClangASTImporter().CanImport(compiler_type);
1525}
1526
1528 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1529 auto clang_type_system =
1531 if (clang_type_system) {
1532 DWARFASTParserClang *ast_parser =
1533 static_cast<DWARFASTParserClang *>(clang_type_system->GetDWARFParser());
1534 if (ast_parser &&
1535 ast_parser->GetClangASTImporter().CanImport(compiler_type))
1536 return ast_parser->GetClangASTImporter().CompleteType(compiler_type);
1537 }
1538
1539 // We have a struct/union/class/enum that needs to be fully resolved.
1540 CompilerType compiler_type_no_qualifiers =
1541 ClangUtil::RemoveFastQualifiers(compiler_type);
1542 auto die_it = GetForwardDeclClangTypeToDie().find(
1543 compiler_type_no_qualifiers.GetOpaqueQualType());
1544 if (die_it == GetForwardDeclClangTypeToDie().end()) {
1545 // We have already resolved this type...
1546 return true;
1547 }
1548
1549 DWARFDIE dwarf_die = GetDIE(die_it->getSecond());
1550 if (dwarf_die) {
1551 // Once we start resolving this type, remove it from the forward
1552 // declaration map in case anyone child members or other types require this
1553 // type to get resolved. The type will get resolved when all of the calls
1554 // to SymbolFileDWARF::ResolveClangOpaqueTypeDefinition are done.
1555 GetForwardDeclClangTypeToDie().erase(die_it);
1556
1557 Type *type = GetDIEToType().lookup(dwarf_die.GetDIE());
1558
1559 Log *log = GetLog(DWARFLog::DebugInfo | DWARFLog::TypeCompletion);
1560 if (log)
1561 GetObjectFile()->GetModule()->LogMessageVerboseBacktrace(
1562 log, "{0:x8}: {1} '{2}' resolving forward declaration...",
1563 dwarf_die.GetID(), dwarf_die.GetTagAsCString(),
1564 type->GetName().AsCString());
1565 assert(compiler_type);
1566 if (DWARFASTParser *dwarf_ast = GetDWARFParser(*dwarf_die.GetCU()))
1567 return dwarf_ast->CompleteTypeFromDWARF(dwarf_die, type, compiler_type);
1568 }
1569 return false;
1570}
1571
1573 bool assert_not_being_parsed,
1574 bool resolve_function_context) {
1575 if (die) {
1576 Type *type = GetTypeForDIE(die, resolve_function_context).get();
1577
1578 if (assert_not_being_parsed) {
1579 if (type != DIE_IS_BEING_PARSED)
1580 return type;
1581
1582 GetObjectFile()->GetModule()->ReportError(
1583 "Parsing a die that is being parsed die: {0:x16}: {1} {2}",
1584 die.GetOffset(), die.GetTagAsCString(), die.GetName());
1585
1586 } else
1587 return type;
1588 }
1589 return nullptr;
1590}
1591
1594 if (dwarf_cu.IsDWOUnit()) {
1595 DWARFCompileUnit *non_dwo_cu =
1596 static_cast<DWARFCompileUnit *>(dwarf_cu.GetUserData());
1597 assert(non_dwo_cu);
1599 *non_dwo_cu);
1600 }
1601 // Check if the symbol vendor already knows about this compile unit?
1602 if (dwarf_cu.GetUserData() == nullptr) {
1603 // The symbol vendor doesn't know about this compile unit, we need to parse
1604 // and add it to the symbol vendor object.
1605 return ParseCompileUnit(dwarf_cu).get();
1606 }
1607 return static_cast<CompileUnit *>(dwarf_cu.GetUserData());
1608}
1609
1611 ConstString class_name, llvm::function_ref<bool(DWARFDIE die)> callback) {
1612 m_index->GetObjCMethods(class_name, callback);
1613}
1614
1616 sc.Clear(false);
1617
1618 if (die && llvm::isa<DWARFCompileUnit>(die.GetCU())) {
1619 // Check if the symbol vendor already knows about this compile unit?
1620 sc.comp_unit =
1621 GetCompUnitForDWARFCompUnit(llvm::cast<DWARFCompileUnit>(*die.GetCU()));
1622
1623 sc.function = sc.comp_unit->FindFunctionByUID(die.GetID()).get();
1624 if (sc.function == nullptr)
1625 sc.function = ParseFunction(*sc.comp_unit, die);
1626
1627 if (sc.function) {
1629 return true;
1630 }
1631 }
1632
1633 return false;
1634}
1635
1638 const auto &pos = m_external_type_modules.find(name);
1639 if (pos == m_external_type_modules.end())
1640 return lldb::ModuleSP();
1641 return pos->second;
1642}
1643
1646 // This method can be called without going through the symbol vendor so we
1647 // need to lock the module.
1648 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1649
1650 SymbolFileDWARF *symbol_file = nullptr;
1651
1652 // Anytime we get a "lldb::user_id_t" from an lldb_private::SymbolFile API we
1653 // must make sure we use the correct DWARF file when resolving things. On
1654 // MacOSX, when using SymbolFileDWARFDebugMap, we will use multiple
1655 // SymbolFileDWARF classes, one for each .o file. We can often end up with
1656 // references to other DWARF objects and we must be ready to receive a
1657 // "lldb::user_id_t" that specifies a DIE from another SymbolFileDWARF
1658 // instance.
1659 std::optional<uint32_t> file_index = die_ref.file_index();
1660 if (file_index) {
1661 if (SymbolFileDWARFDebugMap *debug_map = GetDebugMapSymfile()) {
1662 symbol_file = debug_map->GetSymbolFileByOSOIndex(*file_index); // OSO case
1663 if (symbol_file)
1664 return symbol_file->DebugInfo().GetDIE(die_ref);
1665 return DWARFDIE();
1666 }
1667
1668 if (*file_index == DIERef::k_file_index_mask)
1669 symbol_file = m_dwp_symfile.get(); // DWP case
1670 else
1671 symbol_file = this->DebugInfo()
1672 .GetUnitAtIndex(*die_ref.file_index())
1673 ->GetDwoSymbolFile(); // DWO case
1674 } else if (die_ref.die_offset() == DW_INVALID_OFFSET) {
1675 return DWARFDIE();
1676 }
1677
1678 if (symbol_file)
1679 return symbol_file->GetDIE(die_ref);
1680
1681 return DebugInfo().GetDIE(die_ref);
1682}
1683
1684/// Return the DW_AT_(GNU_)dwo_id.
1685static std::optional<uint64_t> GetDWOId(DWARFCompileUnit &dwarf_cu,
1686 const DWARFDebugInfoEntry &cu_die) {
1687 std::optional<uint64_t> dwo_id =
1688 cu_die.GetAttributeValueAsOptionalUnsigned(&dwarf_cu, DW_AT_GNU_dwo_id);
1689 if (dwo_id)
1690 return dwo_id;
1691 return cu_die.GetAttributeValueAsOptionalUnsigned(&dwarf_cu, DW_AT_dwo_id);
1692}
1693
1694std::optional<uint64_t> SymbolFileDWARF::GetDWOId() {
1695 if (GetNumCompileUnits() == 1) {
1696 if (auto comp_unit = GetCompileUnitAtIndex(0))
1697 if (DWARFCompileUnit *cu = GetDWARFCompileUnit(comp_unit.get()))
1698 if (DWARFDebugInfoEntry *cu_die = cu->DIE().GetDIE())
1699 return ::GetDWOId(*cu, *cu_die);
1700 }
1701 return {};
1702}
1703
1704std::shared_ptr<SymbolFileDWARFDwo>
1706 DWARFUnit &unit, const DWARFDebugInfoEntry &cu_die) {
1707 // If this is a Darwin-style debug map (non-.dSYM) symbol file,
1708 // never attempt to load ELF-style DWO files since the -gmodules
1709 // support uses the same DWO mechanism to specify full debug info
1710 // files for modules. This is handled in
1711 // UpdateExternalModuleListIfNeeded().
1712 if (GetDebugMapSymfile())
1713 return nullptr;
1714
1715 DWARFCompileUnit *dwarf_cu = llvm::dyn_cast<DWARFCompileUnit>(&unit);
1716 // Only compile units can be split into two parts and we should only
1717 // look for a DWO file if there is a valid DWO ID.
1718 if (!dwarf_cu || !dwarf_cu->GetDWOId().has_value())
1719 return nullptr;
1720
1721 const char *dwo_name = GetDWOName(*dwarf_cu, cu_die);
1722 if (!dwo_name) {
1724 "missing DWO name in skeleton DIE {0:x16}", cu_die.GetOffset()));
1725 return nullptr;
1726 }
1727
1728 if (std::shared_ptr<SymbolFileDWARFDwo> dwp_sp = GetDwpSymbolFile())
1729 return dwp_sp;
1730
1731 FileSpec dwo_file(dwo_name);
1732 FileSystem::Instance().Resolve(dwo_file);
1733 bool found = false;
1734
1735 const FileSpecList &debug_file_search_paths =
1737 size_t num_search_paths = debug_file_search_paths.GetSize();
1738
1739 // It's relative, e.g. "foo.dwo", but we just to happen to be right next to
1740 // it. Or it's absolute.
1741 found = FileSystem::Instance().Exists(dwo_file);
1742
1743 if (!found) {
1744 // It could be a relative path that also uses DW_AT_COMP_DIR.
1745 const char *comp_dir =
1746 cu_die.GetAttributeValueAsString(dwarf_cu, DW_AT_comp_dir, nullptr);
1747
1748 if (comp_dir) {
1749 dwo_file.SetFile(comp_dir, FileSpec::Style::native);
1750 if (!dwo_file.IsRelative()) {
1751 FileSystem::Instance().Resolve(dwo_file);
1752 dwo_file.AppendPathComponent(dwo_name);
1753 found = FileSystem::Instance().Exists(dwo_file);
1754 } else {
1755 FileSpecList dwo_paths;
1756
1757 // if DW_AT_comp_dir is relative, it should be relative to the location
1758 // of the executable, not to the location from which the debugger was
1759 // launched.
1760 FileSpec relative_to_binary = dwo_file;
1761 relative_to_binary.PrependPathComponent(
1762 m_objfile_sp->GetFileSpec().GetDirectory().GetStringRef());
1763 FileSystem::Instance().Resolve(relative_to_binary);
1764 relative_to_binary.AppendPathComponent(dwo_name);
1765 dwo_paths.Append(relative_to_binary);
1766
1767 // Or it's relative to one of the user specified debug directories.
1768 for (size_t idx = 0; idx < num_search_paths; ++idx) {
1769 FileSpec dirspec = debug_file_search_paths.GetFileSpecAtIndex(idx);
1770 dirspec.AppendPathComponent(comp_dir);
1771 FileSystem::Instance().Resolve(dirspec);
1772 if (!FileSystem::Instance().IsDirectory(dirspec))
1773 continue;
1774
1775 dirspec.AppendPathComponent(dwo_name);
1776 dwo_paths.Append(dirspec);
1777 }
1778
1779 size_t num_possible = dwo_paths.GetSize();
1780 for (size_t idx = 0; idx < num_possible && !found; ++idx) {
1781 FileSpec dwo_spec = dwo_paths.GetFileSpecAtIndex(idx);
1782 if (FileSystem::Instance().Exists(dwo_spec)) {
1783 dwo_file = dwo_spec;
1784 found = true;
1785 }
1786 }
1787 }
1788 } else {
1789 Log *log = GetLog(LLDBLog::Symbols);
1790 LLDB_LOGF(log,
1791 "unable to locate relative .dwo debug file \"%s\" for "
1792 "skeleton DIE 0x%016" PRIx64 " without valid DW_AT_comp_dir "
1793 "attribute",
1794 dwo_name, cu_die.GetOffset());
1795 }
1796 }
1797
1798 if (!found) {
1799 // Try adding the DW_AT_dwo_name ( e.g. "c/d/main-main.dwo"), and just the
1800 // filename ("main-main.dwo") to binary dir and search paths.
1801 FileSpecList dwo_paths;
1802 FileSpec dwo_name_spec(dwo_name);
1803 llvm::StringRef filename_only = dwo_name_spec.GetFilename();
1804
1805 FileSpec binary_directory(
1806 m_objfile_sp->GetFileSpec().GetDirectory().GetStringRef());
1807 FileSystem::Instance().Resolve(binary_directory);
1808
1809 if (dwo_name_spec.IsRelative()) {
1810 FileSpec dwo_name_binary_directory(binary_directory);
1811 dwo_name_binary_directory.AppendPathComponent(dwo_name);
1812 dwo_paths.Append(dwo_name_binary_directory);
1813 }
1814
1815 FileSpec filename_binary_directory(binary_directory);
1816 filename_binary_directory.AppendPathComponent(filename_only);
1817 dwo_paths.Append(filename_binary_directory);
1818
1819 for (size_t idx = 0; idx < num_search_paths; ++idx) {
1820 FileSpec dirspec = debug_file_search_paths.GetFileSpecAtIndex(idx);
1821 FileSystem::Instance().Resolve(dirspec);
1822 if (!FileSystem::Instance().IsDirectory(dirspec))
1823 continue;
1824
1825 FileSpec dwo_name_dirspec(dirspec);
1826 dwo_name_dirspec.AppendPathComponent(dwo_name);
1827 dwo_paths.Append(dwo_name_dirspec);
1828
1829 FileSpec filename_dirspec(dirspec);
1830 filename_dirspec.AppendPathComponent(filename_only);
1831 dwo_paths.Append(filename_dirspec);
1832 }
1833
1834 size_t num_possible = dwo_paths.GetSize();
1835 for (size_t idx = 0; idx < num_possible && !found; ++idx) {
1836 FileSpec dwo_spec = dwo_paths.GetFileSpecAtIndex(idx);
1837 if (FileSystem::Instance().Exists(dwo_spec)) {
1838 dwo_file = dwo_spec;
1839 found = true;
1840 }
1841 }
1842 }
1843
1844 if (!found) {
1846 "unable to locate .dwo debug file \"{0}\" for skeleton DIE "
1847 "{1:x16}",
1848 dwo_file.GetPath().c_str(), cu_die.GetOffset()));
1849
1850 if (m_dwo_warning_issued.test_and_set(std::memory_order_relaxed) == false) {
1851 GetObjectFile()->GetModule()->ReportWarning(
1852 "unable to locate separate debug file (dwo, dwp). Debugging will be "
1853 "degraded.");
1854 }
1855 return nullptr;
1856 }
1857
1858 const lldb::offset_t file_offset = 0;
1859 DataBufferSP dwo_file_data_sp;
1860 lldb::offset_t dwo_file_data_offset = 0;
1861 ObjectFileSP dwo_obj_file = ObjectFile::FindPlugin(
1862 GetObjectFile()->GetModule(), &dwo_file, file_offset,
1863 FileSystem::Instance().GetByteSize(dwo_file), dwo_file_data_sp,
1864 dwo_file_data_offset);
1865 if (dwo_obj_file == nullptr) {
1867 "unable to load object file for .dwo debug file \"{0}\" for "
1868 "unit DIE {1:x16}",
1869 dwo_name, cu_die.GetOffset()));
1870 return nullptr;
1871 }
1872
1873 return std::make_shared<SymbolFileDWARFDwo>(*this, dwo_obj_file,
1874 dwarf_cu->GetID());
1875}
1876
1879 return;
1881 DWARFDebugInfo &debug_info = DebugInfo();
1882
1883 // Follow DWO skeleton unit breadcrumbs.
1884 const uint32_t num_compile_units = GetNumCompileUnits();
1885 for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx) {
1886 auto *dwarf_cu =
1887 llvm::dyn_cast<DWARFCompileUnit>(debug_info.GetUnitAtIndex(cu_idx));
1888 if (!dwarf_cu)
1889 continue;
1890
1891 const DWARFBaseDIE die = dwarf_cu->GetUnitDIEOnly();
1892 if (!die || die.HasChildren() || !die.GetDIE())
1893 continue;
1894
1895 const char *name = die.GetAttributeValueAsString(DW_AT_name, nullptr);
1896 if (!name)
1897 continue;
1898
1899 ConstString const_name(name);
1900 ModuleSP &module_sp = m_external_type_modules[const_name];
1901 if (module_sp)
1902 continue;
1903
1904 const char *dwo_path = GetDWOName(*dwarf_cu, *die.GetDIE());
1905 if (!dwo_path)
1906 continue;
1907
1908 ModuleSpec dwo_module_spec;
1909 dwo_module_spec.GetFileSpec().SetFile(dwo_path, FileSpec::Style::native);
1910 if (dwo_module_spec.GetFileSpec().IsRelative()) {
1911 const char *comp_dir =
1912 die.GetAttributeValueAsString(DW_AT_comp_dir, nullptr);
1913 if (comp_dir) {
1914 dwo_module_spec.GetFileSpec().SetFile(comp_dir,
1915 FileSpec::Style::native);
1916 FileSystem::Instance().Resolve(dwo_module_spec.GetFileSpec());
1917 dwo_module_spec.GetFileSpec().AppendPathComponent(dwo_path);
1918 }
1919 }
1920 dwo_module_spec.GetArchitecture() =
1921 m_objfile_sp->GetModule()->GetArchitecture();
1922
1923 // When LLDB loads "external" modules it looks at the presence of
1924 // DW_AT_dwo_name. However, when the already created module
1925 // (corresponding to .dwo itself) is being processed, it will see
1926 // the presence of DW_AT_dwo_name (which contains the name of dwo
1927 // file) and will try to call ModuleList::GetSharedModule
1928 // again. In some cases (i.e., for empty files) Clang 4.0
1929 // generates a *.dwo file which has DW_AT_dwo_name, but no
1930 // DW_AT_comp_dir. In this case the method
1931 // ModuleList::GetSharedModule will fail and the warning will be
1932 // printed. However, as one can notice in this case we don't
1933 // actually need to try to load the already loaded module
1934 // (corresponding to .dwo) so we simply skip it.
1935 if (m_objfile_sp->GetFileSpec().GetFileNameExtension() == ".dwo" &&
1936 llvm::StringRef(m_objfile_sp->GetFileSpec().GetPath())
1937 .endswith(dwo_module_spec.GetFileSpec().GetPath())) {
1938 continue;
1939 }
1940
1941 Status error = ModuleList::GetSharedModule(dwo_module_spec, module_sp,
1942 nullptr, nullptr, nullptr);
1943 if (!module_sp) {
1944 GetObjectFile()->GetModule()->ReportWarning(
1945 "{0:x16}: unable to locate module needed for external types: "
1946 "{1}\nerror: {2}\nDebugging will be degraded due to missing "
1947 "types. Rebuilding the project will regenerate the needed "
1948 "module files.",
1949 die.GetOffset(), dwo_module_spec.GetFileSpec().GetPath().c_str(),
1950 error.AsCString("unknown error"));
1951 continue;
1952 }
1953
1954 // Verify the DWO hash.
1955 // FIXME: Technically "0" is a valid hash.
1956 std::optional<uint64_t> dwo_id = ::GetDWOId(*dwarf_cu, *die.GetDIE());
1957 if (!dwo_id)
1958 continue;
1959
1960 auto *dwo_symfile =
1961 llvm::dyn_cast_or_null<SymbolFileDWARF>(module_sp->GetSymbolFile());
1962 if (!dwo_symfile)
1963 continue;
1964 std::optional<uint64_t> dwo_dwo_id = dwo_symfile->GetDWOId();
1965 if (!dwo_dwo_id)
1966 continue;
1967
1968 if (dwo_id != dwo_dwo_id) {
1969 GetObjectFile()->GetModule()->ReportWarning(
1970 "{0:x16}: Module {1} is out-of-date (hash mismatch). Type "
1971 "information "
1972 "from this module may be incomplete or inconsistent with the rest of "
1973 "the program. Rebuilding the project will regenerate the needed "
1974 "module files.",
1975 die.GetOffset(), dwo_module_spec.GetFileSpec().GetPath().c_str());
1976 }
1977 }
1978}
1979
1981 if (!m_global_aranges_up) {
1982 m_global_aranges_up = std::make_unique<GlobalVariableMap>();
1983
1984 ModuleSP module_sp = GetObjectFile()->GetModule();
1985 if (module_sp) {
1986 const size_t num_cus = module_sp->GetNumCompileUnits();
1987 for (size_t i = 0; i < num_cus; ++i) {
1988 CompUnitSP cu_sp = module_sp->GetCompileUnitAtIndex(i);
1989 if (cu_sp) {
1990 VariableListSP globals_sp = cu_sp->GetVariableList(true);
1991 if (globals_sp) {
1992 const size_t num_globals = globals_sp->GetSize();
1993 for (size_t g = 0; g < num_globals; ++g) {
1994 VariableSP var_sp = globals_sp->GetVariableAtIndex(g);
1995 if (var_sp && !var_sp->GetLocationIsConstantValueData()) {
1996 const DWARFExpressionList &location =
1997 var_sp->LocationExpressionList();
1998 Value location_result;
1999 Status error;
2000 ExecutionContext exe_ctx;
2001 if (location.Evaluate(&exe_ctx, nullptr, LLDB_INVALID_ADDRESS,
2002 nullptr, nullptr, location_result,
2003 &error)) {
2004 if (location_result.GetValueType() ==
2005 Value::ValueType::FileAddress) {
2006 lldb::addr_t file_addr =
2007 location_result.GetScalar().ULongLong();
2008 lldb::addr_t byte_size = 1;
2009 if (var_sp->GetType())
2010 byte_size =
2011 var_sp->GetType()->GetByteSize(nullptr).value_or(0);
2013 file_addr, byte_size, var_sp.get()));
2014 }
2015 }
2016 }
2017 }
2018 }
2019 }
2020 }
2021 }
2022 m_global_aranges_up->Sort();
2023 }
2024 return *m_global_aranges_up;
2025}
2026
2028 bool lookup_block,
2029 SymbolContext &sc) {
2030 assert(sc.comp_unit);
2031 DWARFCompileUnit &cu =
2033 DWARFDIE function_die = cu.LookupAddress(file_vm_addr);
2034 DWARFDIE block_die;
2035 if (function_die) {
2036 sc.function = sc.comp_unit->FindFunctionByUID(function_die.GetID()).get();
2037 if (sc.function == nullptr)
2038 sc.function = ParseFunction(*sc.comp_unit, function_die);
2039
2040 if (sc.function && lookup_block)
2041 block_die = function_die.LookupDeepestBlock(file_vm_addr);
2042 }
2043
2044 if (!sc.function || !lookup_block)
2045 return;
2046
2047 Block &block = sc.function->GetBlock(true);
2048 if (block_die)
2049 sc.block = block.FindBlockByID(block_die.GetID());
2050 else
2051 sc.block = block.FindBlockByID(function_die.GetID());
2052}
2053
2054uint32_t SymbolFileDWARF::ResolveSymbolContext(const Address &so_addr,
2055 SymbolContextItem resolve_scope,
2056 SymbolContext &sc) {
2057 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
2058 LLDB_SCOPED_TIMERF("SymbolFileDWARF::"
2059 "ResolveSymbolContext (so_addr = { "
2060 "section = %p, offset = 0x%" PRIx64
2061 " }, resolve_scope = 0x%8.8x)",
2062 static_cast<void *>(so_addr.GetSection().get()),
2063 so_addr.GetOffset(), resolve_scope);
2064 uint32_t resolved = 0;
2065 if (resolve_scope &
2066 (eSymbolContextCompUnit | eSymbolContextFunction | eSymbolContextBlock |
2067 eSymbolContextLineEntry | eSymbolContextVariable)) {
2068 lldb::addr_t file_vm_addr = so_addr.GetFileAddress();
2069
2070 DWARFDebugInfo &debug_info = DebugInfo();
2071 const DWARFDebugAranges &aranges = debug_info.GetCompileUnitAranges();
2072 const dw_offset_t cu_offset = aranges.FindAddress(file_vm_addr);
2073 if (cu_offset == DW_INVALID_OFFSET) {
2074 // Global variables are not in the compile unit address ranges. The only
2075 // way to currently find global variables is to iterate over the
2076 // .debug_pubnames or the __apple_names table and find all items in there
2077 // that point to DW_TAG_variable DIEs and then find the address that
2078 // matches.
2079 if (resolve_scope & eSymbolContextVariable) {
2081 const GlobalVariableMap::Entry *entry =
2082 map.FindEntryThatContains(file_vm_addr);
2083 if (entry && entry->data) {
2084 Variable *variable = entry->data;
2085 SymbolContextScope *scc = variable->GetSymbolContextScope();
2086 if (scc) {
2087 scc->CalculateSymbolContext(&sc);
2088 sc.variable = variable;
2089 }
2090 return sc.GetResolvedMask();
2091 }
2092 }
2093 } else {
2094 uint32_t cu_idx = DW_INVALID_INDEX;
2095 if (auto *dwarf_cu = llvm::dyn_cast_or_null<DWARFCompileUnit>(
2096 debug_info.GetUnitAtOffset(DIERef::Section::DebugInfo, cu_offset,
2097 &cu_idx))) {
2098 sc.comp_unit = GetCompUnitForDWARFCompUnit(*dwarf_cu);
2099 if (sc.comp_unit) {
2100 resolved |= eSymbolContextCompUnit;
2101
2102 bool force_check_line_table = false;
2103 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock)) {
2104 ResolveFunctionAndBlock(file_vm_addr,
2105 resolve_scope & eSymbolContextBlock, sc);
2106 if (sc.function)
2107 resolved |= eSymbolContextFunction;
2108 else {
2109 // We might have had a compile unit that had discontiguous address
2110 // ranges where the gaps are symbols that don't have any debug
2111 // info. Discontiguous compile unit address ranges should only
2112 // happen when there aren't other functions from other compile
2113 // units in these gaps. This helps keep the size of the aranges
2114 // down.
2115 force_check_line_table = true;
2116 }
2117 if (sc.block)
2118 resolved |= eSymbolContextBlock;
2119 }
2120
2121 if ((resolve_scope & eSymbolContextLineEntry) ||
2122 force_check_line_table) {
2123 LineTable *line_table = sc.comp_unit->GetLineTable();
2124 if (line_table != nullptr) {
2125 // And address that makes it into this function should be in terms
2126 // of this debug file if there is no debug map, or it will be an
2127 // address in the .o file which needs to be fixed up to be in
2128 // terms of the debug map executable. Either way, calling
2129 // FixupAddress() will work for us.
2130 Address exe_so_addr(so_addr);
2131 if (FixupAddress(exe_so_addr)) {
2132 if (line_table->FindLineEntryByAddress(exe_so_addr,
2133 sc.line_entry)) {
2134 resolved |= eSymbolContextLineEntry;
2135 }
2136 }
2137 }
2138 }
2139
2140 if (force_check_line_table && !(resolved & eSymbolContextLineEntry)) {
2141 // We might have had a compile unit that had discontiguous address
2142 // ranges where the gaps are symbols that don't have any debug info.
2143 // Discontiguous compile unit address ranges should only happen when
2144 // there aren't other functions from other compile units in these
2145 // gaps. This helps keep the size of the aranges down.
2146 sc.comp_unit = nullptr;
2147 resolved &= ~eSymbolContextCompUnit;
2148 }
2149 } else {
2150 GetObjectFile()->GetModule()->ReportWarning(
2151 "{0:x16}: compile unit {1} failed to create a valid "
2152 "lldb_private::CompileUnit class.",
2153 cu_offset, cu_idx);
2154 }
2155 }
2156 }
2157 }
2158 return resolved;
2159}
2160
2162 const SourceLocationSpec &src_location_spec,
2163 SymbolContextItem resolve_scope, SymbolContextList &sc_list) {
2164 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
2165 const bool check_inlines = src_location_spec.GetCheckInlines();
2166 const uint32_t prev_size = sc_list.GetSize();
2167 if (resolve_scope & eSymbolContextCompUnit) {
2168 for (uint32_t cu_idx = 0, num_cus = GetNumCompileUnits(); cu_idx < num_cus;
2169 ++cu_idx) {
2170 CompileUnit *dc_cu = ParseCompileUnitAtIndex(cu_idx).get();
2171 if (!dc_cu)
2172 continue;
2173
2174 bool file_spec_matches_cu_file_spec = FileSpec::Match(
2175 src_location_spec.GetFileSpec(), dc_cu->GetPrimaryFile());
2176 if (check_inlines || file_spec_matches_cu_file_spec) {
2177 dc_cu->ResolveSymbolContext(src_location_spec, resolve_scope, sc_list);
2178 if (!check_inlines)
2179 break;
2180 }
2181 }
2182 }
2183 return sc_list.GetSize() - prev_size;
2184}
2185
2187 // Get the symbol table for the symbol file prior to taking the module lock
2188 // so that it is available without needing to take the module lock. The DWARF
2189 // indexing might end up needing to relocate items when DWARF sections are
2190 // loaded as they might end up getting the section contents which can call
2191 // ObjectFileELF::RelocateSection() which in turn will ask for the symbol
2192 // table and can cause deadlocks.
2193 GetSymtab();
2194 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
2195 m_index->Preload();
2196}
2197
2198std::recursive_mutex &SymbolFileDWARF::GetModuleMutex() const {
2199 lldb::ModuleSP module_sp(m_debug_map_module_wp.lock());
2200 if (module_sp)
2201 return module_sp->GetMutex();
2202 return GetObjectFile()->GetModule()->GetMutex();
2203}
2204
2206 const lldb_private::CompilerDeclContext &decl_ctx) {
2207 if (!decl_ctx.IsValid()) {
2208 // Invalid namespace decl which means we aren't matching only things in
2209 // this symbol file, so return true to indicate it matches this symbol
2210 // file.
2211 return true;
2212 }
2213
2214 TypeSystem *decl_ctx_type_system = decl_ctx.GetTypeSystem();
2215 auto type_system_or_err = GetTypeSystemForLanguage(
2216 decl_ctx_type_system->GetMinimumLanguage(nullptr));
2217 if (auto err = type_system_or_err.takeError()) {
2218 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
2219 "Unable to match namespace decl using TypeSystem: {0}");
2220 return false;
2221 }
2222
2223 if (decl_ctx_type_system == type_system_or_err->get())
2224 return true; // The type systems match, return true
2225
2226 // The namespace AST was valid, and it does not match...
2227 Log *log = GetLog(DWARFLog::Lookups);
2228
2229 if (log)
2230 GetObjectFile()->GetModule()->LogMessage(
2231 log, "Valid namespace does not match symbol file");
2232
2233 return false;
2234}
2235
2237 ConstString name, const CompilerDeclContext &parent_decl_ctx,
2238 uint32_t max_matches, VariableList &variables) {
2239 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
2240 Log *log = GetLog(DWARFLog::Lookups);
2241
2242 if (log)
2243 GetObjectFile()->GetModule()->LogMessage(
2244 log,
2245 "SymbolFileDWARF::FindGlobalVariables (name=\"{0}\", "
2246 "parent_decl_ctx={1:p}, max_matches={2}, variables)",
2247 name.GetCString(), static_cast<const void *>(&parent_decl_ctx),
2248 max_matches);
2249
2250 if (!DeclContextMatchesThisSymbolFile(parent_decl_ctx))
2251 return;
2252
2253 // Remember how many variables are in the list before we search.
2254 const uint32_t original_size = variables.GetSize();
2255
2256 llvm::StringRef basename;
2257 llvm::StringRef context;
2258 bool name_is_mangled = Mangled::GetManglingScheme(name.GetStringRef()) !=
2260
2262 context, basename))
2263 basename = name.GetStringRef();
2264
2265 // Loop invariant: Variables up to this index have been checked for context
2266 // matches.
2267 uint32_t pruned_idx = original_size;
2268
2269 SymbolContext sc;
2270 m_index->GetGlobalVariables(ConstString(basename), [&](DWARFDIE die) {
2271 if (!sc.module_sp)
2272 sc.module_sp = m_objfile_sp->GetModule();
2273 assert(sc.module_sp);
2274
2275 if (die.Tag() != DW_TAG_variable)
2276 return true;
2277
2278 auto *dwarf_cu = llvm::dyn_cast<DWARFCompileUnit>(die.GetCU());
2279 if (!dwarf_cu)
2280 return true;
2281 sc.comp_unit = GetCompUnitForDWARFCompUnit(*dwarf_cu);
2282
2283 if (parent_decl_ctx) {
2284 if (DWARFASTParser *dwarf_ast = GetDWARFParser(*die.GetCU())) {
2285 CompilerDeclContext actual_parent_decl_ctx =
2286 dwarf_ast->GetDeclContextContainingUIDFromDWARF(die);
2287
2288 /// If the actual namespace is inline (i.e., had a DW_AT_export_symbols)
2289 /// and a child (possibly through other layers of inline namespaces)
2290 /// of the namespace referred to by 'basename', allow the lookup to
2291 /// succeed.
2292 if (!actual_parent_decl_ctx ||
2293 (actual_parent_decl_ctx != parent_decl_ctx &&
2294 !parent_decl_ctx.IsContainedInLookup(actual_parent_decl_ctx)))
2295 return true;
2296 }
2297 }
2298
2299 ParseAndAppendGlobalVariable(sc, die, variables);
2300 while (pruned_idx < variables.GetSize()) {
2301 VariableSP var_sp = variables.GetVariableAtIndex(pruned_idx);
2302 if (name_is_mangled ||
2303 var_sp->GetName().GetStringRef().contains(name.GetStringRef()))
2304 ++pruned_idx;
2305 else
2306 variables.RemoveVariableAtIndex(pruned_idx);
2307 }
2308
2309 return variables.GetSize() - original_size < max_matches;
2310 });
2311
2312 // Return the number of variable that were appended to the list
2313 const uint32_t num_matches = variables.GetSize() - original_size;
2314 if (log && num_matches > 0) {
2315 GetObjectFile()->GetModule()->LogMessage(
2316 log,
2317 "SymbolFileDWARF::FindGlobalVariables (name=\"{0}\", "
2318 "parent_decl_ctx={1:p}, max_matches={2}, variables) => {3}",
2319 name.GetCString(), static_cast<const void *>(&parent_decl_ctx),
2320 max_matches, num_matches);
2321 }
2322}
2323
2325 uint32_t max_matches,
2326 VariableList &variables) {
2327 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
2328 Log *log = GetLog(DWARFLog::Lookups);
2329
2330 if (log) {
2331 GetObjectFile()->GetModule()->LogMessage(
2332 log,
2333 "SymbolFileDWARF::FindGlobalVariables (regex=\"{0}\", "
2334 "max_matches={1}, variables)",
2335 regex.GetText().str().c_str(), max_matches);
2336 }
2337
2338 // Remember how many variables are in the list before we search.
2339 const uint32_t original_size = variables.GetSize();
2340
2341 SymbolContext sc;
2342 m_index->GetGlobalVariables(regex, [&](DWARFDIE die) {
2343 if (!sc.module_sp)
2344 sc.module_sp = m_objfile_sp->GetModule();
2345 assert(sc.module_sp);
2346
2347 DWARFCompileUnit *dwarf_cu = llvm::dyn_cast<DWARFCompileUnit>(die.GetCU());
2348 if (!dwarf_cu)
2349 return true;
2350 sc.comp_unit = GetCompUnitForDWARFCompUnit(*dwarf_cu);
2351
2352 ParseAndAppendGlobalVariable(sc, die, variables);
2353
2354 return variables.GetSize() - original_size < max_matches;
2355 });
2356}
2357
2359 bool include_inlines,
2360 SymbolContextList &sc_list) {
2361 SymbolContext sc;
2362
2363 if (!orig_die)
2364 return false;
2365
2366 // If we were passed a die that is not a function, just return false...
2367 if (!(orig_die.Tag() == DW_TAG_subprogram ||
2368 (include_inlines && orig_die.Tag() == DW_TAG_inlined_subroutine)))
2369 return false;
2370
2371 DWARFDIE die = orig_die;
2372 DWARFDIE inlined_die;
2373 if (die.Tag() == DW_TAG_inlined_subroutine) {
2374 inlined_die = die;
2375
2376 while (true) {
2377 die = die.GetParent();
2378
2379 if (die) {
2380 if (die.Tag() == DW_TAG_subprogram)
2381 break;
2382 } else
2383 break;
2384 }
2385 }
2386 assert(die && die.Tag() == DW_TAG_subprogram);
2387 if (GetFunction(die, sc)) {
2388 Address addr;
2389 // Parse all blocks if needed
2390 if (inlined_die) {
2391 Block &function_block = sc.function->GetBlock(true);
2392 sc.block = function_block.FindBlockByID(inlined_die.GetID());
2393 if (sc.block == nullptr)
2394 sc.block = function_block.FindBlockByID(inlined_die.GetOffset());
2395 if (sc.block == nullptr || !sc.block->GetStartAddress(addr))
2396 addr.Clear();
2397 } else {
2398 sc.block = nullptr;
2400 }
2401
2402 sc_list.Append(sc);
2403 return true;
2404 }
2405
2406 return false;
2407}
2408
2410 const DWARFDIE &die,
2411 bool only_root_namespaces) {
2412 // If we have no parent decl context to match this DIE matches, and if the
2413 // parent decl context isn't valid, we aren't trying to look for any
2414 // particular decl context so any die matches.
2415 if (!decl_ctx.IsValid()) {
2416 // ...But if we are only checking root decl contexts, confirm that the
2417 // 'die' is a top-level context.
2418 if (only_root_namespaces)
2419 return die.GetParent().Tag() == dwarf::DW_TAG_compile_unit;
2420
2421 return true;
2422 }
2423
2424 if (die) {
2425 if (DWARFASTParser *dwarf_ast = GetDWARFParser(*die.GetCU())) {
2426 if (CompilerDeclContext actual_decl_ctx =
2427 dwarf_ast->GetDeclContextContainingUIDFromDWARF(die))
2428 return decl_ctx.IsContainedInLookup(actual_decl_ctx);
2429 }
2430 }
2431 return false;
2432}
2433
2435 const CompilerDeclContext &parent_decl_ctx,
2436 bool include_inlines,
2437 SymbolContextList &sc_list) {
2438 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
2439 ConstString name = lookup_info.GetLookupName();
2440 FunctionNameType name_type_mask = lookup_info.GetNameTypeMask();
2441
2442 // eFunctionNameTypeAuto should be pre-resolved by a call to
2443 // Module::LookupInfo::LookupInfo()
2444 assert((name_type_mask & eFunctionNameTypeAuto) == 0);
2445
2446 Log *log = GetLog(DWARFLog::Lookups);
2447
2448 if (log) {
2449 GetObjectFile()->GetModule()->LogMessage(
2450 log,
2451 "SymbolFileDWARF::FindFunctions (name=\"{0}\", name_type_mask={1:x}, "
2452 "sc_list)",
2453 name.GetCString(), name_type_mask);
2454 }
2455
2456 if (!DeclContextMatchesThisSymbolFile(parent_decl_ctx))
2457 return;
2458
2459 // If name is empty then we won't find anything.
2460 if (name.IsEmpty())
2461 return;
2462
2463 // Remember how many sc_list are in the list before we search in case we are
2464 // appending the results to a variable list.
2465
2466 const uint32_t original_size = sc_list.GetSize();
2467
2468 llvm::DenseSet<const DWARFDebugInfoEntry *> resolved_dies;
2469
2470 m_index->GetFunctions(lookup_info, *this, parent_decl_ctx, [&](DWARFDIE die) {
2471 if (resolved_dies.insert(die.GetDIE()).second)
2472 ResolveFunction(die, include_inlines, sc_list);
2473 return true;
2474 });
2475 // With -gsimple-template-names, a templated type's DW_AT_name will not
2476 // contain the template parameters. Try again stripping '<' and anything
2477 // after, filtering out entries with template parameters that don't match.
2478 {
2479 const llvm::StringRef name_ref = name.GetStringRef();
2480 auto it = name_ref.find('<');
2481 if (it != llvm::StringRef::npos) {
2482 const llvm::StringRef name_no_template_params = name_ref.slice(0, it);
2483
2484 Module::LookupInfo no_tp_lookup_info(lookup_info);
2485 no_tp_lookup_info.SetLookupName(ConstString(name_no_template_params));
2486 m_index->GetFunctions(no_tp_lookup_info, *this, parent_decl_ctx, [&](DWARFDIE die) {
2487 if (resolved_dies.insert(die.GetDIE()).second)
2488 ResolveFunction(die, include_inlines, sc_list);
2489 return true;
2490 });
2491 }
2492 }
2493
2494 // Return the number of variable that were appended to the list
2495 const uint32_t num_matches = sc_list.GetSize() - original_size;
2496
2497 if (log && num_matches > 0) {
2498 GetObjectFile()->GetModule()->LogMessage(
2499 log,
2500 "SymbolFileDWARF::FindFunctions (name=\"{0}\", "
2501 "name_type_mask={1:x}, include_inlines={2:d}, sc_list) => {3}",
2502 name.GetCString(), name_type_mask, include_inlines, num_matches);
2503 }
2504}
2505
2507 bool include_inlines,
2508 SymbolContextList &sc_list) {
2509 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
2510 LLDB_SCOPED_TIMERF("SymbolFileDWARF::FindFunctions (regex = '%s')",
2511 regex.GetText().str().c_str());
2512
2513 Log *log = GetLog(DWARFLog::Lookups);
2514
2515 if (log) {
2516 GetObjectFile()->GetModule()->LogMessage(
2517 log, "SymbolFileDWARF::FindFunctions (regex=\"{0}\", sc_list)",
2518 regex.GetText().str().c_str());
2519 }
2520
2521 llvm::DenseSet<const DWARFDebugInfoEntry *> resolved_dies;
2522 m_index->GetFunctions(regex, [&](DWARFDIE die) {
2523 if (resolved_dies.insert(die.GetDIE()).second)
2524 ResolveFunction(die, include_inlines, sc_list);
2525 return true;
2526 });
2527}
2528
2530 const std::string &scope_qualified_name,
2531 std::vector<ConstString> &mangled_names) {
2532 DWARFDebugInfo &info = DebugInfo();
2533 uint32_t num_comp_units = info.GetNumUnits();
2534 for (uint32_t i = 0; i < num_comp_units; i++) {
2535 DWARFUnit *cu = info.GetUnitAtIndex(i);
2536 if (cu == nullptr)
2537 continue;
2538
2540 if (dwo)
2541 dwo->GetMangledNamesForFunction(scope_qualified_name, mangled_names);
2542 }
2543
2544 for (DIERef die_ref :
2545 m_function_scope_qualified_name_map.lookup(scope_qualified_name)) {
2546 DWARFDIE die = GetDIE(die_ref);
2547 mangled_names.push_back(ConstString(die.GetMangledName()));
2548 }
2549}
2550
2552 ConstString name, const CompilerDeclContext &parent_decl_ctx,
2553 uint32_t max_matches,
2554 llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
2555 TypeMap &types) {
2556 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
2557 // Make sure we haven't already searched this SymbolFile before.
2558 if (!searched_symbol_files.insert(this).second)
2559 return;
2560
2561 Log *log = GetLog(DWARFLog::Lookups);
2562
2563 if (log) {
2564 if (parent_decl_ctx)
2565 GetObjectFile()->GetModule()->LogMessage(
2566 log,
2567 "SymbolFileDWARF::FindTypes (sc, name=\"{0}\", parent_decl_ctx = "
2568 "{1:p} (\"{2}\"), max_matches={3}, type_list)",
2569 name.GetCString(), static_cast<const void *>(&parent_decl_ctx),
2570 parent_decl_ctx.GetName().AsCString("<NULL>"), max_matches);
2571 else
2572 GetObjectFile()->GetModule()->LogMessage(
2573 log,
2574 "SymbolFileDWARF::FindTypes (sc, name=\"{0}\", parent_decl_ctx = "
2575 "NULL, max_matches={1}, type_list)",
2576 name.GetCString(), max_matches);
2577 }
2578
2579 if (!DeclContextMatchesThisSymbolFile(parent_decl_ctx))
2580 return;
2581
2582 // Unlike FindFunctions(), FindTypes() following cannot produce false
2583 // positives.
2584
2585 const llvm::StringRef name_ref = name.GetStringRef();
2586 auto name_bracket_index = name_ref.find('<');
2587 m_index->GetTypes(name, [&](DWARFDIE die) {
2588 if (!DIEInDeclContext(parent_decl_ctx, die))
2589 return true; // The containing decl contexts don't match
2590
2591 Type *matching_type = ResolveType(die, true, true);
2592 if (!matching_type)
2593 return true;
2594
2595 // With -gsimple-template-names, a templated type's DW_AT_name will not
2596 // contain the template parameters. Make sure that if the original query
2597 // didn't contain a '<', we filter out entries with template parameters.
2598 if (name_bracket_index == llvm::StringRef::npos &&
2599 matching_type->IsTemplateType())
2600 return true;
2601
2602 // We found a type pointer, now find the shared pointer form our type
2603 // list
2604 types.InsertUnique(matching_type->shared_from_this());
2605 return types.GetSize() < max_matches;
2606 });
2607
2608 // With -gsimple-template-names, a templated type's DW_AT_name will not
2609 // contain the template parameters. Try again stripping '<' and anything
2610 // after, filtering out entries with template parameters that don't match.
2611 if (types.GetSize() < max_matches) {
2612 if (name_bracket_index != llvm::StringRef::npos) {
2613 const llvm::StringRef name_no_template_params =
2614 name_ref.slice(0, name_bracket_index);
2615 const llvm::StringRef template_params =
2616 name_ref.slice(name_bracket_index, name_ref.size());
2617 m_index->GetTypes(ConstString(name_no_template_params), [&](DWARFDIE die) {
2618 if (!DIEInDeclContext(parent_decl_ctx, die))
2619 return true; // The containing decl contexts don't match
2620
2621 const llvm::StringRef base_name = GetTypeForDIE(die)->GetBaseName().AsCString();
2622 auto it = base_name.find('<');
2623 // If the candidate qualified name doesn't have '<', it doesn't have
2624 // template params to compare.
2625 if (it == llvm::StringRef::npos)
2626 return true;
2627
2628 // Filter out non-matching instantiations by comparing template params.
2629 const llvm::StringRef base_name_template_params =
2630 base_name.slice(it, base_name.size());
2631
2632 if (template_params != base_name_template_params)
2633 return true;
2634
2635 Type *matching_type = ResolveType(die, true, true);
2636 if (!matching_type)
2637 return true;
2638
2639 // We found a type pointer, now find the shared pointer form our type
2640 // list.
2641 types.InsertUnique(matching_type->shared_from_this());
2642 return types.GetSize() < max_matches;
2643 });
2644 }
2645 }
2646
2647 // Next search through the reachable Clang modules. This only applies for
2648 // DWARF objects compiled with -gmodules that haven't been processed by
2649 // dsymutil.
2650 if (types.GetSize() < max_matches) {
2652
2653 for (const auto &pair : m_external_type_modules)
2654 if (ModuleSP external_module_sp = pair.second)
2655 if (SymbolFile *sym_file = external_module_sp->GetSymbolFile())
2656 sym_file->FindTypes(name, parent_decl_ctx, max_matches,
2657 searched_symbol_files, types);
2658 }
2659
2660 if (log && types.GetSize()) {
2661 if (parent_decl_ctx) {
2662 GetObjectFile()->GetModule()->LogMessage(
2663 log,
2664 "SymbolFileDWARF::FindTypes (sc, name=\"{0}\", parent_decl_ctx "
2665 "= {1:p} (\"{2}\"), max_matches={3}, type_list) => {4}",
2666 name.GetCString(), static_cast<const void *>(&parent_decl_ctx),
2667 parent_decl_ctx.GetName().AsCString("<NULL>"), max_matches,
2668 types.GetSize());
2669 } else {
2670 GetObjectFile()->GetModule()->LogMessage(
2671 log,
2672 "SymbolFileDWARF::FindTypes (sc, name=\"{0}\", parent_decl_ctx "
2673 "= NULL, max_matches={1}, type_list) => {2}",
2674 name.GetCString(), max_matches, types.GetSize());
2675 }
2676 }
2677}
2678
2680 llvm::ArrayRef<CompilerContext> pattern, LanguageSet languages,
2681 llvm::DenseSet<SymbolFile *> &searched_symbol_files, TypeMap &types) {
2682 // Make sure we haven't already searched this SymbolFile before.
2683 if (!searched_symbol_files.insert(this).second)
2684 return;
2685
2686 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
2687 if (pattern.empty())
2688 return;
2689
2690 ConstString name = pattern.back().name;
2691
2692 if (!name)
2693 return;
2694
2695 m_index->GetTypes(name, [&](DWARFDIE die) {
2696 if (!languages[GetLanguageFamily(*die.GetCU())])
2697 return true;
2698
2699 llvm::SmallVector<CompilerContext, 4> die_context;
2700 die.GetDeclContext(die_context);
2701 if (!contextMatches(die_context, pattern))
2702 return true;
2703
2704 if (Type *matching_type = ResolveType(die, true, true)) {
2705 // We found a type pointer, now find the shared pointer form our type
2706 // list.
2707 types.InsertUnique(matching_type->shared_from_this());
2708 }
2709 return true;
2710 });
2711
2712 // Next search through the reachable Clang modules. This only applies for
2713 // DWARF objects compiled with -gmodules that haven't been processed by
2714 // dsymutil.
2716
2717 for (const auto &pair : m_external_type_modules)
2718 if (ModuleSP external_module_sp = pair.second)
2719 external_module_sp->FindTypes(pattern, languages, searched_symbol_files,
2720 types);
2721}
2722
2725 const CompilerDeclContext &parent_decl_ctx,
2726 bool only_root_namespaces) {
2727 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
2728 Log *log = GetLog(DWARFLog::Lookups);
2729
2730 if (log) {
2731 GetObjectFile()->GetModule()->LogMessage(
2732 log, "SymbolFileDWARF::FindNamespace (sc, name=\"{0}\")",
2733 name.GetCString());
2734 }
2735
2736 CompilerDeclContext namespace_decl_ctx;
2737
2738 if (!DeclContextMatchesThisSymbolFile(parent_decl_ctx))
2739 return namespace_decl_ctx;
2740
2741 m_index->GetNamespaces(name, [&](DWARFDIE die) {
2742 if (!DIEInDeclContext(parent_decl_ctx, die, only_root_namespaces))
2743 return true; // The containing decl contexts don't match
2744
2745 DWARFASTParser *dwarf_ast = GetDWARFParser(*die.GetCU());
2746 if (!dwarf_ast)
2747 return true;
2748
2749 namespace_decl_ctx = dwarf_ast->GetDeclContextForUIDFromDWARF(die);
2750 return !namespace_decl_ctx.IsValid();
2751 });
2752
2753 if (log && namespace_decl_ctx) {
2754 GetObjectFile()->GetModule()->LogMessage(
2755 log,
2756 "SymbolFileDWARF::FindNamespace (sc, name=\"{0}\") => "
2757 "CompilerDeclContext({1:p}/{2:p}) \"{3}\"",
2758 name.GetCString(),
2759 static_cast<const void *>(namespace_decl_ctx.GetTypeSystem()),
2760 static_cast<const void *>(namespace_decl_ctx.GetOpaqueDeclContext()),
2761 namespace_decl_ctx.GetName().AsCString("<NULL>"));
2762 }
2763
2764 return namespace_decl_ctx;
2765}
2766
2768 bool resolve_function_context) {
2769 TypeSP type_sp;
2770 if (die) {
2771 Type *type_ptr = GetDIEToType().lookup(die.GetDIE());
2772 if (type_ptr == nullptr) {
2773 SymbolContextScope *scope;
2774 if (auto *dwarf_cu = llvm::dyn_cast<DWARFCompileUnit>(die.GetCU()))
2775 scope = GetCompUnitForDWARFCompUnit(*dwarf_cu);
2776 else
2777 scope = GetObjectFile()->GetModule().get();
2778 assert(scope);
2779 SymbolContext sc(scope);
2780 const DWARFDebugInfoEntry *parent_die = die.GetParent().GetDIE();
2781 while (parent_die != nullptr) {
2782 if (parent_die->Tag() == DW_TAG_subprogram)
2783 break;
2784 parent_die = parent_die->GetParent();
2785 }
2786 SymbolContext sc_backup = sc;
2787 if (resolve_function_context && parent_die != nullptr &&
2788 !GetFunction(DWARFDIE(die.GetCU(), parent_die), sc))
2789 sc = sc_backup;
2790
2791 type_sp = ParseType(sc, die, nullptr);
2792 } else if (type_ptr != DIE_IS_BEING_PARSED) {
2793 // Get the original shared pointer for this type
2794 type_sp = type_ptr->shared_from_this();
2795 }
2796 }
2797 return type_sp;
2798}
2799
2802 if (orig_die) {
2803 DWARFDIE die = orig_die;
2804
2805 while (die) {
2806 // If this is the original DIE that we are searching for a declaration
2807 // for, then don't look in the cache as we don't want our own decl
2808 // context to be our decl context...
2809 if (orig_die != die) {
2810 switch (die.Tag()) {
2811 case DW_TAG_compile_unit:
2812 case DW_TAG_partial_unit:
2813 case DW_TAG_namespace:
2814 case DW_TAG_structure_type:
2815 case DW_TAG_union_type:
2816 case DW_TAG_class_type:
2817 case DW_TAG_lexical_block:
2818 case DW_TAG_subprogram:
2819 return die;
2820 case DW_TAG_inlined_subroutine: {
2821 DWARFDIE abs_die = die.GetReferencedDIE(DW_AT_abstract_origin);
2822 if (abs_die) {
2823 return abs_die;
2824 }
2825 break;
2826 }
2827 default:
2828 break;
2829 }
2830 }
2831
2832 DWARFDIE spec_die = die.GetReferencedDIE(DW_AT_specification);
2833 if (spec_die) {
2834 DWARFDIE decl_ctx_die = GetDeclContextDIEContainingDIE(spec_die);
2835 if (decl_ctx_die)
2836 return decl_ctx_die;
2837 }
2838
2839 DWARFDIE abs_die = die.GetReferencedDIE(DW_AT_abstract_origin);
2840 if (abs_die) {
2841 DWARFDIE decl_ctx_die = GetDeclContextDIEContainingDIE(abs_die);
2842 if (decl_ctx_die)
2843 return decl_ctx_die;
2844 }
2845
2846 die = die.GetParent();
2847 }
2848 }
2849 return DWARFDIE();
2850}
2851
2853 Symbol *objc_class_symbol = nullptr;
2854 if (m_objfile_sp) {
2855 Symtab *symtab = m_objfile_sp->GetSymtab();
2856 if (symtab) {
2857 objc_class_symbol = symtab->FindFirstSymbolWithNameAndType(
2858 objc_class_name, eSymbolTypeObjCClass, Symtab::eDebugNo,
2860 }
2861 }
2862 return objc_class_symbol;
2863}
2864
2865// Some compilers don't emit the DW_AT_APPLE_objc_complete_type attribute. If
2866// they don't then we can end up looking through all class types for a complete
2867// type and never find the full definition. We need to know if this attribute
2868// is supported, so we determine this here and cache th result. We also need to
2869// worry about the debug map
2870// DWARF file
2871// if we are doing darwin DWARF in .o file debugging.
2877 else {
2878 DWARFDebugInfo &debug_info = DebugInfo();
2879 const uint32_t num_compile_units = GetNumCompileUnits();
2880 for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx) {
2881 DWARFUnit *dwarf_cu = debug_info.GetUnitAtIndex(cu_idx);
2882 if (dwarf_cu != cu &&
2885 break;
2886 }
2887 }
2888 }
2892 }
2894}
2895
2896// This function can be used when a DIE is found that is a forward declaration
2897// DIE and we want to try and find a type that has the complete definition.
2899 const DWARFDIE &die, ConstString type_name, bool must_be_implementation) {
2900
2901 TypeSP type_sp;
2902
2903 if (!type_name || (must_be_implementation && !GetObjCClassSymbol(type_name)))
2904 return type_sp;
2905
2906 m_index->GetCompleteObjCClass(
2907 type_name, must_be_implementation, [&](DWARFDIE type_die) {
2908 bool try_resolving_type = false;
2909
2910 // Don't try and resolve the DIE we are looking for with the DIE
2911 // itself!
2912 if (type_die != die) {
2913 switch (type_die.Tag()) {
2914 case DW_TAG_class_type:
2915 case DW_TAG_structure_type:
2916 try_resolving_type = true;
2917 break;
2918 default:
2919 break;
2920 }
2921 }
2922 if (!try_resolving_type)
2923 return true;
2924
2925 if (must_be_implementation &&
2927 try_resolving_type = type_die.GetAttributeValueAsUnsigned(
2928 DW_AT_APPLE_objc_complete_type, 0);
2929 if (!try_resolving_type)
2930 return true;
2931
2932 Type *resolved_type = ResolveType(type_die, false, true);
2933 if (!resolved_type || resolved_type == DIE_IS_BEING_PARSED)
2934 return true;
2935
2937 "resolved 0x%8.8" PRIx64 " from %s to 0x%8.8" PRIx64
2938 " (cu 0x%8.8" PRIx64 ")\n",
2939 die.GetID(),
2940 m_objfile_sp->GetFileSpec().GetFilename().AsCString("<Unknown>"),
2941 type_die.GetID(), type_cu->GetID());
2942
2943 if (die)
2944 GetDIEToType()[die.GetDIE()] = resolved_type;
2945 type_sp = resolved_type->shared_from_this();
2946 return false;
2947 });
2948 return type_sp;
2949}
2950
2951// This function helps to ensure that the declaration contexts match for two
2952// different DIEs. Often times debug information will refer to a forward
2953// declaration of a type (the equivalent of "struct my_struct;". There will
2954// often be a declaration of that type elsewhere that has the full definition.
2955// When we go looking for the full type "my_struct", we will find one or more
2956// matches in the accelerator tables and we will then need to make sure the
2957// type was in the same declaration context as the original DIE. This function
2958// can efficiently compare two DIEs and will return true when the declaration
2959// context matches, and false when they don't.
2961 const DWARFDIE &die2) {
2962 if (die1 == die2)
2963 return true;
2964
2965 std::vector<DWARFDIE> decl_ctx_1;
2966 std::vector<DWARFDIE> decl_ctx_2;
2967 // The declaration DIE stack is a stack of the declaration context DIEs all
2968 // the way back to the compile unit. If a type "T" is declared inside a class
2969 // "B", and class "B" is declared inside a class "A" and class "A" is in a
2970 // namespace "lldb", and the namespace is in a compile unit, there will be a
2971 // stack of DIEs:
2972 //
2973 // [0] DW_TAG_class_type for "B"
2974 // [1] DW_TAG_class_type for "A"
2975 // [2] DW_TAG_namespace for "lldb"
2976 // [3] DW_TAG_compile_unit or DW_TAG_partial_unit for the source file.
2977 //
2978 // We grab both contexts and make sure that everything matches all the way
2979 // back to the compiler unit.
2980
2981 // First lets grab the decl contexts for both DIEs
2982 decl_ctx_1 = die1.GetDeclContextDIEs();
2983 decl_ctx_2 = die2.GetDeclContextDIEs();
2984 // Make sure the context arrays have the same size, otherwise we are done
2985 const size_t count1 = decl_ctx_1.size();
2986 const size_t count2 = decl_ctx_2.size();
2987 if (count1 != count2)
2988 return false;
2989
2990 // Make sure the DW_TAG values match all the way back up the compile unit. If
2991 // they don't, then we are done.
2992 DWARFDIE decl_ctx_die1;
2993 DWARFDIE decl_ctx_die2;
2994 size_t i;
2995 for (i = 0; i < count1; i++) {
2996 decl_ctx_die1 = decl_ctx_1[i];
2997 decl_ctx_die2 = decl_ctx_2[i];
2998 if (decl_ctx_die1.Tag() != decl_ctx_die2.Tag())
2999 return false;
3000 }
3001#ifndef NDEBUG
3002
3003 // Make sure the top item in the decl context die array is always
3004 // DW_TAG_compile_unit or DW_TAG_partial_unit. If it isn't then
3005 // something went wrong in the DWARFDIE::GetDeclContextDIEs()
3006 // function.
3007 dw_tag_t cu_tag = decl_ctx_1[count1 - 1].Tag();
3009 assert(cu_tag == DW_TAG_compile_unit || cu_tag == DW_TAG_partial_unit);
3010
3011#endif
3012 // Always skip the compile unit when comparing by only iterating up to "count
3013 // - 1". Here we compare the names as we go.
3014 for (i = 0; i < count1 - 1; i++) {
3015 decl_ctx_die1 = decl_ctx_1[i];
3016 decl_ctx_die2 = decl_ctx_2[i];
3017 const char *name1 = decl_ctx_die1.GetName();
3018 const char *name2 = decl_ctx_die2.GetName();
3019 // If the string was from a DW_FORM_strp, then the pointer will often be
3020 // the same!
3021 if (name1 == name2)
3022 continue;
3023
3024 // Name pointers are not equal, so only compare the strings if both are not
3025 // NULL.
3026 if (name1 && name2) {
3027 // If the strings don't compare, we are done...
3028 if (strcmp(name1, name2) != 0)
3029 return false;
3030 } else {
3031 // One name was NULL while the other wasn't
3032 return false;
3033 }
3034 }
3035 // We made it through all of the checks and the declaration contexts are
3036 // equal.
3037 return true;
3038}
3039
3040TypeSP
3042 TypeSP type_sp;
3043
3044 if (die.GetName()) {
3045 const dw_tag_t tag = die.Tag();
3046
3047 Log *log = GetLog(DWARFLog::TypeCompletion | DWARFLog::Lookups);
3048 if (log) {
3049 GetObjectFile()->GetModule()->LogMessage(
3050 log,
3051 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag={0}, "
3052 "name='{1}')",
3053 DW_TAG_value_to_name(tag), die.GetName());
3054 }
3055
3056 // Get the type system that we are looking to find a type for. We will
3057 // use this to ensure any matches we find are in a language that this
3058 // type system supports
3059 const LanguageType language = GetLanguage(*die.GetCU());
3060 TypeSystemSP type_system = nullptr;
3061 if (language != eLanguageTypeUnknown) {
3062 auto type_system_or_err = GetTypeSystemForLanguage(language);
3063 if (auto err = type_system_or_err.takeError()) {
3064 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
3065 "Cannot get TypeSystem for language {1}: {0}",
3067 } else {
3068 type_system = *type_system_or_err;
3069 }
3070 }
3071
3072 // See comments below about -gsimple-template-names for why we attempt to
3073 // compute missing template parameter names.
3074 ConstString template_params;
3075 if (type_system) {
3076 DWARFASTParser *dwarf_ast = type_system->GetDWARFParser();
3077 if (dwarf_ast)
3078 template_params = dwarf_ast->GetDIEClassTemplateParams(die);
3079 }
3080
3081 m_index->GetTypes(GetDWARFDeclContext(die), [&](DWARFDIE type_die) {
3082 // Make sure type_die's language matches the type system we are
3083 // looking for. We don't want to find a "Foo" type from Java if we
3084 // are looking for a "Foo" type for C, C++, ObjC, or ObjC++.
3085 if (type_system &&
3086 !type_system->SupportsLanguage(GetLanguage(*type_die.GetCU())))
3087 return true;
3088 bool try_resolving_type = false;
3089
3090 // Don't try and resolve the DIE we are looking for with the DIE
3091 // itself!
3092 const dw_tag_t type_tag = type_die.Tag();
3093 // Make sure the tags match
3094 if (type_tag == tag) {
3095 // The tags match, lets try resolving this type
3096 try_resolving_type = true;
3097 } else {
3098 // The tags don't match, but we need to watch our for a forward
3099 // declaration for a struct and ("struct foo") ends up being a
3100 // class ("class foo { ... };") or vice versa.
3101 switch (type_tag) {
3102 case DW_TAG_class_type:
3103 // We had a "class foo", see if we ended up with a "struct foo
3104 // { ... };"
3105 try_resolving_type = (tag == DW_TAG_structure_type);
3106 break;
3107 case DW_TAG_structure_type:
3108 // We had a "struct foo", see if we ended up with a "class foo
3109 // { ... };"
3110 try_resolving_type = (tag == DW_TAG_class_type);
3111 break;
3112 default:
3113 // Tags don't match, don't event try to resolve using this type
3114 // whose name matches....
3115 break;
3116 }
3117 }
3118
3119 if (!try_resolving_type) {
3120 if (log) {
3121 GetObjectFile()->GetModule()->LogMessage(
3122 log,
3123 "SymbolFileDWARF::"
3124 "FindDefinitionTypeForDWARFDeclContext(tag={0}, "
3125 "name='{1}') ignoring die={2:x16} ({3})",
3126 DW_TAG_value_to_name(tag), die.GetName(), type_die.GetOffset(),
3127 type_die.GetName());
3128 }
3129 return true;
3130 }
3131
3132 DWARFDeclContext type_dwarf_decl_ctx = GetDWARFDeclContext(type_die);
3133
3134 if (log) {
3135 GetObjectFile()->GetModule()->LogMessage(
3136 log,
3137 "SymbolFileDWARF::"
3138 "FindDefinitionTypeForDWARFDeclContext(tag={0}, "
3139 "name='{1}') trying die={2:x16} ({3})",
3140 DW_TAG_value_to_name(tag), die.GetName(), type_die.GetOffset(),
3141 type_dwarf_decl_ctx.GetQualifiedName());
3142 }
3143
3144 // Make sure the decl contexts match all the way up
3145 if (GetDWARFDeclContext(die) != type_dwarf_decl_ctx)
3146 return true;
3147
3148 Type *resolved_type = ResolveType(type_die, false);
3149 if (!resolved_type || resolved_type == DIE_IS_BEING_PARSED)
3150 return true;
3151
3152 // With -gsimple-template-names, the DIE name may not contain the template
3153 // parameters. If the declaration has template parameters but doesn't
3154 // contain '<', check that the child template parameters match.
3155 if (template_params) {
3156 llvm::StringRef test_base_name =
3157 GetTypeForDIE(type_die)->GetBaseName().GetStringRef();
3158 auto i = test_base_name.find('<');
3159
3160 // Full name from clang AST doesn't contain '<' so this type_die isn't
3161 // a template parameter, but we're expecting template parameters, so
3162 // bail.
3163 if (i == llvm::StringRef::npos)
3164 return true;
3165
3166 llvm::StringRef test_template_params =
3167 test_base_name.slice(i, test_base_name.size());
3168 // Bail if template parameters don't match.
3169 if (test_template_params != template_params.GetStringRef())
3170 return true;
3171 }
3172
3173 type_sp = resolved_type->shared_from_this();
3174 return false;
3175 });
3176 }
3177 return type_sp;
3178}
3179
3181 bool *type_is_new_ptr) {
3182 if (!die)
3183 return {};
3184
3185 auto type_system_or_err = GetTypeSystemForLanguage(GetLanguage(*die.GetCU()));
3186 if (auto err = type_system_or_err.takeError()) {
3187 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
3188 "Unable to parse type: {0}");
3189 return {};
3190 }
3191 auto ts = *type_system_or_err;
3192 if (!ts)
3193 return {};
3194
3195 DWARFASTParser *dwarf_ast = ts->GetDWARFParser();
3196 if (!dwarf_ast)
3197 return {};
3198
3199 TypeSP type_sp = dwarf_ast->ParseTypeFromDWARF(sc, die, type_is_new_ptr);
3200 if (type_sp) {
3201 if (die.Tag() == DW_TAG_subprogram) {
3202 std::string scope_qualified_name(GetDeclContextForUID(die.GetID())
3204 .AsCString(""));
3205 if (scope_qualified_name.size()) {
3206 m_function_scope_qualified_name_map[scope_qualified_name].insert(
3207 *die.GetDIERef());
3208 }
3209 }
3210 }
3211
3212 return type_sp;
3213}
3214
3216 const DWARFDIE &orig_die,
3217 bool parse_siblings, bool parse_children) {
3218 size_t types_added = 0;
3219 DWARFDIE die = orig_die;
3220
3221 while (die) {
3222 const dw_tag_t tag = die.Tag();
3223 bool type_is_new = false;
3224
3225 Tag dwarf_tag = static_cast<Tag>(tag);
3226
3227 // TODO: Currently ParseTypeFromDWARF(...) which is called by ParseType(...)
3228 // does not handle DW_TAG_subrange_type. It is not clear if this is a bug or
3229 // not.
3230 if (isType(dwarf_tag) && tag != DW_TAG_subrange_type)
3231 ParseType(sc, die, &type_is_new);
3232
3233 if (type_is_new)
3234 ++types_added;
3235
3236 if (parse_children && die.HasChildren()) {
3237 if (die.Tag() == DW_TAG_subprogram) {
3238 SymbolContext child_sc(sc);
3239 child_sc.function = sc.comp_unit->FindFunctionByUID(die.GetID()).get();
3240 types_added += ParseTypes(child_sc, die.GetFirstChild(), true, true);
3241 } else
3242 types_added += ParseTypes(sc, die.GetFirstChild(), true, true);
3243 }
3244
3245 if (parse_siblings)
3246 die = die.GetSibling();
3247 else
3248 die.Clear();
3249 }
3250 return types_added;
3251}
3252
3254 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
3255 CompileUnit *comp_unit = func.GetCompileUnit();
3256 lldbassert(comp_unit);
3257
3258 DWARFUnit *dwarf_cu = GetDWARFCompileUnit(comp_unit);
3259 if (!dwarf_cu)
3260 return 0;
3261
3262 size_t functions_added = 0;
3263 const dw_offset_t function_die_offset = DIERef(func.GetID()).die_offset();
3264 DWARFDIE function_die =
3265 dwarf_cu->GetNonSkeletonUnit().GetDIE(function_die_offset);
3266 if (function_die) {
3267 ParseBlocksRecursive(*comp_unit, &func.GetBlock(false), function_die,
3269 }
3270
3271 return functions_added;
3272}
3273
3275 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
3276 size_t types_added = 0;
3277 DWARFUnit *dwarf_cu = GetDWARFCompileUnit(&comp_unit);
3278 if (dwarf_cu) {
3279 DWARFDIE dwarf_cu_die = dwarf_cu->DIE();
3280 if (dwarf_cu_die && dwarf_cu_die.HasChildren()) {
3281 SymbolContext sc;
3282 sc.comp_unit = &comp_unit;
3283 types_added = ParseTypes(sc, dwarf_cu_die.GetFirstChild(), true, true);
3284 }
3285 }
3286
3287 return types_added;
3288}
3289
3291 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
3292 if (sc.comp_unit != nullptr) {
3293 if (sc.function) {
3294 DWARFDIE function_die = GetDIE(sc.function->GetID());
3295
3296 dw_addr_t func_lo_pc = LLDB_INVALID_ADDRESS;
3297 DWARFRangeList ranges = function_die.GetDIE()->GetAttributeAddressRanges(
3298 function_die.GetCU(), /*check_hi_lo_pc=*/true);
3299 if (!ranges.IsEmpty())
3300 func_lo_pc = ranges.GetMinRangeBase(0);
3301 if (func_lo_pc != LLDB_INVALID_ADDRESS) {
3302 const size_t num_variables =
3303 ParseVariablesInFunctionContext(sc, function_die, func_lo_pc);
3304
3305 // Let all blocks know they have parse all their variables
3306 sc.function->GetBlock(false).SetDidParseVariables(true, true);
3307 return num_variables;
3308 }
3309 } else if (sc.comp_unit) {
3310 DWARFUnit *dwarf_cu = DebugInfo().GetUnitAtIndex(sc.comp_unit->GetID());
3311
3312 if (dwarf_cu == nullptr)
3313 return 0;
3314
3315 uint32_t vars_added = 0;
3316 VariableListSP variables(sc.comp_unit->GetVariableList(false));
3317
3318 if (variables.get() == nullptr) {
3319 variables = std::make_shared<VariableList>();
3320 sc.comp_unit->SetVariableList(variables);
3321
3322 m_index->GetGlobalVariables(*dwarf_cu, [&](DWARFDIE die) {
3323 VariableSP var_sp(ParseVariableDIECached(sc, die));
3324 if (var_sp) {
3325 variables->AddVariableIfUnique(var_sp);
3326 ++vars_added;
3327 }
3328 return true;
3329 });
3330 }
3331 return vars_added;
3332 }
3333 }
3334 return 0;
3335}
3336
3338 const DWARFDIE &die) {
3339 if (!die)
3340 return nullptr;
3341
3342 DIEToVariableSP &die_to_variable = die.GetDWARF()->GetDIEToVariable();
3343
3344 VariableSP var_sp = die_to_variable[die.GetDIE()];
3345 if (var_sp)
3346 return var_sp;
3347
3348 var_sp = ParseVariableDIE(sc, die, LLDB_INVALID_ADDRESS);
3349 if (var_sp) {
3350 die_to_variable[die.GetDIE()] = var_sp;
3351 if (DWARFDIE spec_die = die.GetReferencedDIE(DW_AT_specification))
3352 die_to_variable[spec_die.GetDIE()] = var_sp;
3353 }
3354 return var_sp;
3355}
3356
3357/// Creates a DWARFExpressionList from an DW_AT_location form_value.
3359 ModuleSP module,
3360 const DWARFDIE &die,
3361 const addr_t func_low_pc) {
3362 if (DWARFFormValue::IsBlockForm(form_value.Form())) {
3363 const DWARFDataExtractor &data = die.GetData();
3364
3365 uint32_t block_offset = form_value.BlockData() - data.GetDataStart();
3366 uint32_t block_length = form_value.Unsigned();
3367 return DWARFExpressionList(
3368 module, DataExtractor(data, block_offset, block_length), die.GetCU());
3369 }
3370
3371 DWARFExpressionList location_list(module, DWARFExpression(), die.GetCU());
3372 DataExtractor data = die.GetCU()->GetLocationData();
3373 dw_offset_t offset = form_value.Unsigned();
3374 if (form_value.Form() == DW_FORM_loclistx)
3375 offset = die.GetCU()->GetLoclistOffset(offset).value_or(-1);
3376 if (data.ValidOffset(offset)) {
3377 data = DataExtractor(data, offset, data.GetByteSize() - offset);
3378 const DWARFUnit *dwarf_cu = form_value.GetUnit();
3379 if (DWARFExpression::ParseDWARFLocationList(dwarf_cu, data, &location_list))
3380 location_list.SetFuncFileAddress(func_low_pc);
3381 }
3382
3383 return location_list;
3384}
3385
3386/// Creates a DWARFExpressionList from an DW_AT_const_value. This is either a
3387/// block form, or a string, or a data form. For data forms, this returns an
3388/// empty list, as we cannot initialize it properly without a SymbolFileType.
3391 const DWARFDIE &die) {
3392 const DWARFDataExtractor &debug_info_data = die.GetData();
3393 if (DWARFFormValue::IsBlockForm(form_value.Form())) {
3394 // Retrieve the value as a block expression.
3395 uint32_t block_offset =
3396 form_value.BlockData() - debug_info_data.GetDataStart();
3397 uint32_t block_length = form_value.Unsigned();
3398 return DWARFExpressionList(
3399 module, DataExtractor(debug_info_data, block_offset, block_length),
3400 die.GetCU());
3401 }
3402 if (const char *str = form_value.AsCString())
3403 return DWARFExpressionList(module,
3404 DataExtractor(str, strlen(str) + 1,
3405 die.GetCU()->GetByteOrder(),
3406 die.GetCU()->GetAddressByteSize()),
3407 die.GetCU());
3408 return DWARFExpressionList(module, DWARFExpression(), die.GetCU());
3409}
3410
3411/// Global variables that are not initialized may have their address set to
3412/// zero. Since multiple variables may have this address, we cannot apply the
3413/// OSO relink address approach we normally use.
3414/// However, the executable will have a matching symbol with a good address;
3415/// this function attempts to find the correct address by looking into the
3416/// executable's symbol table. If it succeeds, the expr_list is updated with
3417/// the new address and the executable's symbol is returned.
3419 SymbolFileDWARFDebugMap &debug_map_symfile, llvm::StringRef name,
3420 DWARFExpressionList &expr_list, const DWARFDIE &die) {
3421 ObjectFile *debug_map_objfile = debug_map_symfile.GetObjectFile();
3422 if (!debug_map_objfile)
3423 return nullptr;
3424
3425 Symtab *debug_map_symtab = debug_map_objfile->GetSymtab();
3426 if (!debug_map_symtab)
3427 return nullptr;
3428 Symbol *exe_symbol = debug_map_symtab->FindFirstSymbolWithNameAndType(
3431 if (!exe_symbol || !exe_symbol->ValueIsAddress())
3432 return nullptr;
3433 const addr_t exe_file_addr = exe_symbol->GetAddressRef().GetFileAddress();
3434 if (exe_file_addr == LLDB_INVALID_ADDRESS)
3435 return nullptr;
3436
3437 DWARFExpression *location = expr_list.GetMutableExpressionAtAddress();
3438 if (location->Update_DW_OP_addr(die.GetCU(), exe_file_addr))
3439 return exe_symbol;
3440 return nullptr;
3441}
3442
3444 const DWARFDIE &die,
3445 const lldb::addr_t func_low_pc) {
3446 if (die.GetDWARF() != this)
3447 return die.GetDWARF()->ParseVariableDIE(sc, die, func_low_pc);
3448
3449 if (!die)
3450 return nullptr;
3451
3452 const dw_tag_t tag = die.Tag();
3453 ModuleSP module = GetObjectFile()->GetModule();
3454
3455 if (tag != DW_TAG_variable && tag != DW_TAG_constant &&
3456 (tag != DW_TAG_formal_parameter || !sc.function))
3457 return nullptr;
3458
3459 DWARFAttributes attributes = die.GetAttributes();
3460 const char *name = nullptr;
3461 const char *mangled = nullptr;
3462 Declaration decl;
3463 DWARFFormValue type_die_form;
3464 bool is_external = false;
3465 bool is_artificial = false;
3466 DWARFFormValue const_value_form, location_form;
3467 Variable::RangeList scope_ranges;
3468
3469 for (size_t i = 0; i < attributes.Size(); ++i) {
3470 dw_attr_t attr = attributes.AttributeAtIndex(i);
3471 DWARFFormValue form_value;
3472
3473 if (!attributes.ExtractFormValueAtIndex(i, form_value))
3474 continue;
3475 switch (attr) {
3476 case DW_AT_decl_file:
3477 decl.SetFile(
3478 attributes.CompileUnitAtIndex(i)->GetFile(form_value.Unsigned()));
3479 break;
3480 case DW_AT_decl_line:
3481 decl.SetLine(form_value.Unsigned());
3482 break;
3483 case DW_AT_decl_column:
3484 decl.SetColumn(form_value.Unsigned());
3485 break;
3486 case DW_AT_name:
3487 name = form_value.AsCString();
3488 break;
3489 case DW_AT_linkage_name:
3490 case DW_AT_MIPS_linkage_name:
3491 mangled = form_value.AsCString();
3492 break;
3493 case DW_AT_type:
3494 type_die_form = form_value;
3495 break;
3496 case DW_AT_external:
3497 is_external = form_value.Boolean();
3498 break;
3499 case DW_AT_const_value:
3500 const_value_form = form_value;
3501 break;
3502 case DW_AT_location:
3503 location_form = form_value;
3504 break;
3505 case DW_AT_start_scope:
3506 // TODO: Implement this.
3507 break;
3508 case DW_AT_artificial:
3509 is_artificial = form_value.Boolean();
3510 break;
3511 case DW_AT_declaration:
3512 case DW_AT_description:
3513 case DW_AT_endianity:
3514 case DW_AT_segment:
3515 case DW_AT_specification:
3516 case DW_AT_visibility:
3517 default:
3518 case DW_AT_abstract_origin:
3519 case DW_AT_sibling:
3520 break;
3521 }
3522 }
3523
3524 // Prefer DW_AT_location over DW_AT_const_value. Both can be emitted e.g.
3525 // for static constexpr member variables -- DW_AT_const_value will be
3526 // present in the class declaration and DW_AT_location in the DIE defining
3527 // the member.
3528 bool location_is_const_value_data =
3529 const_value_form.IsValid() && !location_form.IsValid();
3530
3531 DWARFExpressionList location_list = [&] {
3532 if (location_form.IsValid())
3533 return GetExprListFromAtLocation(location_form, module, die, func_low_pc);
3534 if (const_value_form.IsValid())
3535 return GetExprListFromAtConstValue(const_value_form, module, die);
3536 return DWARFExpressionList(module, DWARFExpression(), die.GetCU());
3537 }();
3538
3539 const DWARFDIE parent_context_die = GetDeclContextDIEContainingDIE(die);
3540 const DWARFDIE sc_parent_die = GetParentSymbolContextDIE(die);
3541 const dw_tag_t parent_tag = sc_parent_die.Tag();
3542 bool is_static_member = (parent_tag == DW_TAG_compile_unit ||
3543 parent_tag == DW_TAG_partial_unit) &&
3544 (parent_context_die.Tag() == DW_TAG_class_type ||
3545 parent_context_die.Tag() == DW_TAG_structure_type);
3546
3548 SymbolContextScope *symbol_context_scope = nullptr;
3549
3550 bool has_explicit_mangled = mangled != nullptr;
3551 if (!mangled) {
3552 // LLDB relies on the mangled name (DW_TAG_linkage_name or
3553 // DW_AT_MIPS_linkage_name) to generate fully qualified names
3554 // of global variables with commands like "frame var j". For
3555 // example, if j were an int variable holding a value 4 and
3556 // declared in a namespace B which in turn is contained in a
3557 // namespace A, the command "frame var j" returns
3558 // "(int) A::B::j = 4".
3559 // If the compiler does not emit a linkage name, we should be
3560 // able to generate a fully qualified name from the
3561 // declaration context.
3562 if ((parent_tag == DW_TAG_compile_unit ||
3563 parent_tag == DW_TAG_partial_unit) &&
3565 mangled =
3567 }
3568
3569 if (tag == DW_TAG_formal_parameter)
3571 else {
3572 // DWARF doesn't specify if a DW_TAG_variable is a local, global
3573 // or static variable, so we have to do a little digging:
3574 // 1) DW_AT_linkage_name implies static lifetime (but may be missing)
3575 // 2) An empty DW_AT_location is an (optimized-out) static lifetime var.
3576 // 3) DW_AT_location containing a DW_OP_addr implies static lifetime.
3577 // Clang likes to combine small global variables into the same symbol
3578 // with locations like: DW_OP_addr(0x1000), DW_OP_constu(2), DW_OP_plus
3579 // so we need to look through the whole expression.
3580 bool has_explicit_location = location_form.IsValid();
3581 bool is_static_lifetime =
3582 has_explicit_mangled ||
3583 (has_explicit_location && !location_list.IsValid());
3584 // Check if the location has a DW_OP_addr with any address value...
3585 lldb::addr_t location_DW_OP_addr = LLDB_INVALID_ADDRESS;
3586 if (!location_is_const_value_data) {
3587 bool op_error = false;
3588 const DWARFExpression* location = location_list.GetAlwaysValidExpr();
3589 if (location)
3590 location_DW_OP_addr =
3591 location->GetLocation_DW_OP_addr(location_form.GetUnit(), op_error);
3592 if (op_error) {
3593 StreamString strm;
3594 location->DumpLocation(&strm, eDescriptionLevelFull, nullptr);
3595 GetObjectFile()->GetModule()->ReportError(
3596 "{0:x16}: {1} has an invalid location: {2}", die.GetOffset(),
3597 die.GetTagAsCString(), strm.GetData());
3598 }
3599 if (location_DW_OP_addr != LLDB_INVALID_ADDRESS)
3600 is_static_lifetime = true;
3601 }
3602 SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile();
3603 if (debug_map_symfile)
3604 // Set the module of the expression to the linked module
3605 // instead of the object file so the relocated address can be
3606 // found there.
3607 location_list.SetModule(debug_map_symfile->GetObjectFile()->GetModule());
3608
3609 if (is_static_lifetime) {
3610 if (is_external)
3612 else
3614
3615 if (debug_map_symfile) {
3616 bool linked_oso_file_addr = false;
3617
3618 if (is_external && location_DW_OP_addr == 0) {
3619 if (Symbol *exe_symbol = fixupExternalAddrZeroVariable(
3620 *debug_map_symfile, mangled ? mangled : name, location_list,
3621 die)) {
3622 linked_oso_file_addr = true;
3623 symbol_context_scope = exe_symbol;
3624 }
3625 }
3626
3627 if (!linked_oso_file_addr) {
3628 // The DW_OP_addr is not zero, but it contains a .o file address
3629 // which needs to be linked up correctly.
3630 const lldb::addr_t exe_file_addr =
3631 debug_map_symfile->LinkOSOFileAddress(this, location_DW_OP_addr);
3632 if (exe_file_addr != LLDB_INVALID_ADDRESS) {
3633 // Update the file address for this variable
3634 DWARFExpression *location =
3635 location_list.GetMutableExpressionAtAddress();
3636 location->Update_DW_OP_addr(die.GetCU(), exe_file_addr);
3637 } else {
3638 // Variable didn't make it into the final executable
3639 return nullptr;
3640 }
3641 }
3642 }
3643 } else {
3644 if (location_is_const_value_data &&
3645 die.GetDIE()->IsGlobalOrStaticScopeVariable())
3647 else {
3649 if (debug_map_symfile) {
3650 // We need to check for TLS addresses that we need to fixup
3651 if (location_list.ContainsThreadLocalStorage()) {
3652 location_list.LinkThreadLocalStorage(
3653 debug_map_symfile->GetObjectFile()->GetModule(),
3654 [this, debug_map_symfile](
3655 lldb::addr_t unlinked_file_addr) -> lldb::addr_t {
3656 return debug_map_symfile->LinkOSOFileAddress(
3657 this, unlinked_file_addr);
3658 });
3660 }
3661 }
3662 }
3663 }
3664 }
3665
3666 if (symbol_context_scope == nullptr) {
3667 switch (parent_tag) {
3668 case DW_TAG_subprogram:
3669 case DW_TAG_inlined_subroutine:
3670 case DW_TAG_lexical_block:
3671 if (sc.function) {
3672 symbol_context_scope =
3673 sc.function->GetBlock(true).FindBlockByID(sc_parent_die.GetID());
3674 if (symbol_context_scope == nullptr)
3675 symbol_context_scope = sc.function;
3676 }
3677 break;
3678
3679 default:
3680 symbol_context_scope = sc.comp_unit;
3681 break;
3682 }
3683 }
3684
3685 if (!symbol_context_scope) {
3686 // Not ready to parse this variable yet. It might be a global or static
3687 // variable that is in a function scope and the function in the symbol
3688 // context wasn't filled in yet
3689 return nullptr;
3690 }
3691
3692 auto type_sp = std::make_shared<SymbolFileType>(
3693 *this, type_die_form.Reference().GetID());
3694
3695 bool use_type_size_for_value =
3696 location_is_const_value_data &&
3697 DWARFFormValue::IsDataForm(const_value_form.Form());
3698 if (use_type_size_for_value && type_sp->GetType()) {
3699 DWARFExpression *location = location_list.GetMutableExpressionAtAddress();
3700 location->UpdateValue(const_value_form.Unsigned(),
3701 type_sp->GetType()->GetByteSize(nullptr).value_or(0),
3702 die.GetCU()->GetAddressByteSize());
3703 }
3704
3705 return std::make_shared<Variable>(
3706 die.GetID(), name, mangled, type_sp, scope, symbol_context_scope,
3707 scope_ranges, &decl, location_list, is_external, is_artificial,
3708 location_is_const_value_data, is_static_member);
3709}
3710
3713 const DIERef &func_die_ref, dw_offset_t spec_block_die_offset) {
3714 // Give the concrete function die specified by "func_die_offset", find the
3715 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
3716 // to "spec_block_die_offset"
3717 return FindBlockContainingSpecification(DebugInfo().GetDIE(func_die_ref),
3718 spec_block_die_offset);
3719}
3720
3723 const DWARFDIE &die, dw_offset_t spec_block_die_offset) {
3724 if (die) {
3725 switch (die.Tag()) {
3726 case DW_TAG_subprogram:
3727 case DW_TAG_inlined_subroutine:
3728 case DW_TAG_lexical_block: {
3729 if (die.GetReferencedDIE(DW_AT_specification).GetOffset() ==
3730 spec_block_die_offset)
3731 return die;
3732
3733 if (die.GetReferencedDIE(DW_AT_abstract_origin).GetOffset() ==
3734 spec_block_die_offset)
3735 return die;
3736 } break;
3737 default:
3738 break;
3739 }
3740
3741 // Give the concrete function die specified by "func_die_offset", find the
3742 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
3743 // to "spec_block_die_offset"
3744 for (DWARFDIE child_die : die.children()) {
3745 DWARFDIE result_die =
3746 FindBlockContainingSpecification(child_die, spec_block_die_offset);
3747 if (result_die)
3748 return result_die;
3749 }
3750 }
3751
3752 return DWARFDIE();
3753}
3754
3756 const SymbolContext &sc, const DWARFDIE &die,
3757 VariableList &cc_variable_list) {
3758 if (!die)
3759 return;
3760
3761 dw_tag_t tag = die.Tag();
3762 if (tag != DW_TAG_variable && tag != DW_TAG_constant)
3763 return;
3764
3765 // Check to see if we have already parsed this variable or constant?
3766 VariableSP var_sp = GetDIEToVariable()[die.GetDIE()];
3767 if (var_sp) {
3768 cc_variable_list.AddVariableIfUnique(var_sp);
3769 return;
3770 }
3771
3772 // We haven't parsed the variable yet, lets do that now. Also, let us include
3773 // the variable in the relevant compilation unit's variable list, if it
3774 // exists.
3775 VariableListSP variable_list_sp;
3776 DWARFDIE sc_parent_die = GetParentSymbolContextDIE(die);
3777 dw_tag_t parent_tag = sc_parent_die.Tag();
3778 switch (parent_tag) {
3779 case DW_TAG_compile_unit:
3780 case DW_TAG_partial_unit:
3781 if (sc.comp_unit != nullptr) {
3782 variable_list_sp = sc.comp_unit->GetVariableList(false);
3783 } else {
3784 GetObjectFile()->GetModule()->ReportError(
3785 "parent {0:x8} {1} with no valid compile unit in "
3786 "symbol context for {2:x8} {3}.\n",
3787 sc_parent_die.GetID(), sc_parent_die.GetTagAsCString(), die.GetID(),
3788 die.GetTagAsCString());
3789 return;
3790 }
3791 break;
3792
3793 default:
3794 GetObjectFile()->GetModule()->ReportError(
3795 "didn't find appropriate parent DIE for variable list for {0:x8} "
3796 "{1}.\n",
3797 die.GetID(), die.GetTagAsCString());
3798 return;
3799 }
3800
3801 var_sp = ParseVariableDIECached(sc, die);
3802 if (!var_sp)
3803 return;
3804
3805 cc_variable_list.AddVariableIfUnique(var_sp);
3806 if (variable_list_sp)
3807 variable_list_sp->AddVariableIfUnique(var_sp);
3808}
3809
3812 DIEArray &&variable_dies) {
3813 // DW_TAG_inline_subroutine objects may omit DW_TAG_formal_parameter in
3814 // instances of the function when they are unused (i.e., the parameter's
3815 // location list would be empty). The current DW_TAG_inline_subroutine may
3816 // refer to another DW_TAG_subprogram that might actually have the definitions
3817 // of the parameters and we need to include these so they show up in the
3818 // variables for this function (for example, in a stack trace). Let us try to
3819 // find the abstract subprogram that might contain the parameter definitions
3820 // and merge with the concrete parameters.
3821
3822 // Nothing to merge if the block is not an inlined function.
3823 if (block_die.Tag() != DW_TAG_inlined_subroutine) {
3824 return std::move(variable_dies);
3825 }
3826
3827 // Nothing to merge if the block does not have abstract parameters.
3828 DWARFDIE abs_die = block_die.GetReferencedDIE(DW_AT_abstract_origin);
3829 if (!abs_die || abs_die.Tag() != DW_TAG_subprogram ||
3830 !abs_die.HasChildren()) {
3831 return std::move(variable_dies);
3832 }
3833
3834 // For each abstract parameter, if we have its concrete counterpart, insert
3835 // it. Otherwise, insert the abstract parameter.
3836 DIEArray::iterator concrete_it = variable_dies.begin();
3837 DWARFDIE abstract_child = abs_die.GetFirstChild();
3838 DIEArray merged;
3839 bool did_merge_abstract = false;
3840 for (; abstract_child; abstract_child = abstract_child.GetSibling()) {
3841 if (abstract_child.Tag() == DW_TAG_formal_parameter) {
3842 if (concrete_it == variable_dies.end() ||
3843 GetDIE(*concrete_it).Tag() != DW_TAG_formal_parameter) {
3844 // We arrived at the end of the concrete parameter list, so all
3845 // the remaining abstract parameters must have been omitted.
3846 // Let us insert them to the merged list here.
3847 merged.push_back(*abstract_child.GetDIERef());
3848 did_merge_abstract = true;
3849 continue;
3850 }
3851
3852 DWARFDIE origin_of_concrete =
3853 GetDIE(*concrete_it).GetReferencedDIE(DW_AT_abstract_origin);
3854 if (origin_of_concrete == abstract_child) {
3855 // The current abstract parameter is the origin of the current
3856 // concrete parameter, just push the concrete parameter.
3857 merged.push_back(*concrete_it);
3858 ++concrete_it;
3859 } else {
3860 // Otherwise, the parameter must have been omitted from the concrete
3861 // function, so insert the abstract one.
3862 merged.push_back(*abstract_child.GetDIERef());
3863 did_merge_abstract = true;
3864 }
3865 }
3866 }
3867
3868 // Shortcut if no merging happened.
3869 if (!did_merge_abstract)
3870 return std::move(variable_dies);
3871
3872 // We inserted all the abstract parameters (or their concrete counterparts).
3873 // Let us insert all the remaining concrete variables to the merged list.
3874 // During the insertion, let us check there are no remaining concrete
3875 // formal parameters. If that's the case, then just bailout from the merge -
3876 // the variable list is malformed.
3877 for (; concrete_it != variable_dies.end(); ++concrete_it) {
3878 if (GetDIE(*concrete_it).Tag() == DW_TAG_formal_parameter) {
3879 return std::move(variable_dies);
3880 }
3881 merged.push_back(*concrete_it);
3882 }
3883 return merged;
3884}
3885
3887 const SymbolContext &sc, const DWARFDIE &die,
3888 const lldb::addr_t func_low_pc) {
3889 if (!die || !sc.function)
3890 return 0;
3891
3892 DIEArray dummy_block_variables; // The recursive call should not add anything
3893 // to this vector because |die| should be a
3894 // subprogram, so all variables will be added
3895 // to the subprogram's list.
3896 return ParseVariablesInFunctionContextRecursive(sc, die, func_low_pc,
3897 dummy_block_variables);
3898}
3899
3900// This method parses all the variables in the blocks in the subtree of |die|,
3901// and inserts them to the variable list for all the nested blocks.
3902// The uninserted variables for the current block are accumulated in
3903// |accumulator|.
3905 const lldb_private::SymbolContext &sc, const DWARFDIE &die,
3906 lldb::addr_t func_low_pc, DIEArray &accumulator) {
3907 size_t vars_added = 0;
3908 dw_tag_t tag = die.Tag();
3909
3910 if ((tag == DW_TAG_variable) || (tag == DW_TAG_constant) ||
3911 (tag == DW_TAG_formal_parameter)) {
3912 accumulator.push_back(*die.GetDIERef());
3913 }
3914
3915 switch (tag) {
3916 case DW_TAG_subprogram:
3917 case DW_TAG_inlined_subroutine:
3918 case DW_TAG_lexical_block: {
3919 // If we start a new block, compute a new block variable list and recurse.
3920 Block *block =
3921 sc.function->GetBlock(/*can_create=*/true).FindBlockByID(die.GetID());
3922 if (block == nullptr) {
3923 // This must be a specification or abstract origin with a
3924 // concrete block counterpart in the current function. We need
3925 // to find the concrete block so we can correctly add the
3926 // variable to it.
3927 const DWARFDIE concrete_block_die = FindBlockContainingSpecification(
3928 GetDIE(sc.function->GetID()), die.GetOffset());
3929 if (concrete_block_die)
3930 block = sc.function->GetBlock(/*can_create=*/true)
3931 .FindBlockByID(concrete_block_die.GetID());
3932 }
3933
3934 if (block == nullptr)
3935 return 0;
3936
3937 const bool can_create = false;
3938 VariableListSP block_variable_list_sp =
3939 block->GetBlockVariableList(can_create);
3940 if (block_variable_list_sp.get() == nullptr) {
3941 block_variable_list_sp = std::make_shared<VariableList>();
3942 block->SetVariableList(block_variable_list_sp);
3943 }
3944
3945 DIEArray block_variables;
3946 for (DWARFDIE child = die.GetFirstChild(); child;
3947 child = child.GetSibling()) {
3949 sc, child, func_low_pc, block_variables);
3950 }
3951 block_variables =
3952 MergeBlockAbstractParameters(die, std::move(block_variables));
3953 vars_added += PopulateBlockVariableList(*block_variable_list_sp, sc,
3954 block_variables, func_low_pc);
3955 break;
3956 }
3957
3958 default:
3959 // Recurse to children with the same variable accumulator.
3960 for (DWARFDIE child = die.GetFirstChild(); child;
3961 child = child.GetSibling()) {
3963 sc, child, func_low_pc, accumulator);
3964 }
3965 break;
3966 }
3967
3968 return vars_added;
3969}
3970
3972 VariableList &variable_list, const lldb_private::SymbolContext &sc,
3973 llvm::ArrayRef<DIERef> variable_dies, lldb::addr_t func_low_pc) {
3974 // Parse the variable DIEs and insert them to the list.
3975 for (auto &die : variable_dies) {
3976 if (VariableSP var_sp = ParseVariableDIE(sc, GetDIE(die), func_low_pc)) {
3977 variable_list.AddVariableIfUnique(var_sp);
3978 }
3979 }
3980 return variable_dies.size();
3981}
3982
3983/// Collect call site parameters in a DW_TAG_call_site DIE.
3986 CallSiteParameterArray parameters;
3987 for (DWARFDIE child : call_site_die.children()) {
3988 if (child.Tag() != DW_TAG_call_site_parameter &&
3989 child.Tag() != DW_TAG_GNU_call_site_parameter)
3990 continue;
3991
3992 std::optional<DWARFExpressionList> LocationInCallee;
3993 std::optional<DWARFExpressionList> LocationInCaller;
3994
3995 DWARFAttributes attributes = child.GetAttributes();
3996
3997 // Parse the location at index \p attr_index within this call site parameter
3998 // DIE, or return std::nullopt on failure.
3999 auto parse_simple_location =
4000 [&](int attr_index) -> std::optional<DWARFExpressionList> {
4001 DWARFFormValue form_value;
4002 if (!attributes.ExtractFormValueAtIndex(attr_index, form_value))
4003 return {};
4004 if (!DWARFFormValue::IsBlockForm(form_value.Form()))
4005 return {};
4006 auto data = child.GetData();
4007 uint32_t block_offset = form_value.BlockData() - data.GetDataStart();
4008 uint32_t block_length = form_value.Unsigned();
4009 return DWARFExpressionList(
4010 module, DataExtractor(data, block_offset, block_length),
4011 child.GetCU());
4012 };
4013
4014 for (size_t i = 0; i < attributes.Size(); ++i) {
4015 dw_attr_t attr = attributes.AttributeAtIndex(i);
4016 if (attr == DW_AT_location)
4017 LocationInCallee = parse_simple_location(i);
4018 if (attr == DW_AT_call_value || attr == DW_AT_GNU_call_site_value)
4019 LocationInCaller = parse_simple_location(i);
4020 }
4021
4022 if (LocationInCallee && LocationInCaller) {
4023 CallSiteParameter param = {*LocationInCallee, *LocationInCaller};
4024 parameters.push_back(param);
4025 }
4026 }
4027 return parameters;
4028}
4029
4030/// Collect call graph edges present in a function DIE.
4031std::vector<std::unique_ptr<lldb_private::CallEdge>>
4033 // Check if the function has a supported call site-related attribute.
4034 // TODO: In the future it may be worthwhile to support call_all_source_calls.
4035 bool has_call_edges =
4036 function_die.GetAttributeValueAsUnsigned(DW_AT_call_all_calls, 0) ||
4037 function_die.GetAttributeValueAsUnsigned(DW_AT_GNU_all_call_sites, 0);
4038 if (!has_call_edges)
4039 return {};
4040
4041 Log *log = GetLog(LLDBLog::Step);
4042 LLDB_LOG(log, "CollectCallEdges: Found call site info in {0}",
4043 function_die.GetPubname());
4044
4045 // Scan the DIE for TAG_call_site entries.
4046 // TODO: A recursive scan of all blocks in the subprogram is needed in order
4047 // to be DWARF5-compliant. This may need to be done lazily to be performant.
4048 // For now, assume that all entries are nested directly under the subprogram
4049 // (this is the kind of DWARF LLVM produces) and parse them eagerly.
4050 std::vector<std::unique_ptr<CallEdge>> call_edges;
4051 for (DWARFDIE child : function_die.children()) {
4052 if (child.Tag() != DW_TAG_call_site && child.Tag() != DW_TAG_GNU_call_site)
4053 continue;
4054
4055 std::optional<DWARFDIE> call_origin;
4056 std::optional<DWARFExpressionList> call_target;
4057 addr_t return_pc = LLDB_INVALID_ADDRESS;
4058 addr_t call_inst_pc = LLDB_INVALID_ADDRESS;
4060 bool tail_call = false;
4061
4062 // Second DW_AT_low_pc may come from DW_TAG_subprogram referenced by
4063 // DW_TAG_GNU_call_site's DW_AT_abstract_origin overwriting our 'low_pc'.
4064 // So do not inherit attributes from DW_AT_abstract_origin.
4065 DWARFAttributes attributes = child.GetAttributes(DWARFDIE::Recurse::no);
4066 for (size_t i = 0; i < attributes.Size(); ++i) {
4067 DWARFFormValue form_value;
4068 if (!attributes.ExtractFormValueAtIndex(i, form_value)) {
4069 LLDB_LOG(log, "CollectCallEdges: Could not extract TAG_call_site form");
4070 break;
4071 }
4072
4073 dw_attr_t attr = attributes.AttributeAtIndex(i);
4074
4075 if (attr == DW_AT_call_tail_call || attr == DW_AT_GNU_tail_call)
4076 tail_call = form_value.Boolean();
4077
4078 // Extract DW_AT_call_origin (the call target's DIE).
4079 if (attr == DW_AT_call_origin || attr == DW_AT_abstract_origin) {
4080 call_origin = form_value.Reference();
4081 if (!call_origin->IsValid()) {
4082 LLDB_LOG(log, "CollectCallEdges: Invalid call origin in {0}",
4083 function_die.GetPubname());
4084 break;
4085 }
4086 }
4087
4088 if (attr == DW_AT_low_pc)
4089 low_pc = form_value.Address();
4090
4091 // Extract DW_AT_call_return_pc (the PC the call returns to) if it's
4092 // available. It should only ever be unavailable for tail call edges, in
4093 // which case use LLDB_INVALID_ADDRESS.
4094 if (attr == DW_AT_call_return_pc)
4095 return_pc = form_value.Address();
4096
4097 // Extract DW_AT_call_pc (the PC at the call/branch instruction). It
4098 // should only ever be unavailable for non-tail calls, in which case use
4099 // LLDB_INVALID_ADDRESS.
4100 if (attr == DW_AT_call_pc)
4101 call_inst_pc = form_value.Address();
4102
4103 // Extract DW_AT_call_target (the location of the address of the indirect
4104 // call).
4105 if (attr == DW_AT_call_target || attr == DW_AT_GNU_call_site_target) {
4106 if (!DWARFFormValue::IsBlockForm(form_value.Form())) {
4107 LLDB_LOG(log,
4108 "CollectCallEdges: AT_call_target does not have block form");
4109 break;
4110 }
4111
4112 auto data = child.GetData();
4113 uint32_t block_offset = form_value.BlockData() - data.GetDataStart();
4114 uint32_t block_length = form_value.Unsigned();
4115 call_target = DWARFExpressionList(
4116 module, DataExtractor(data, block_offset, block_length),
4117 child.GetCU());
4118 }
4119 }
4120 if (!call_origin && !call_target) {
4121 LLDB_LOG(log, "CollectCallEdges: call site without any call target");
4122 continue;
4123 }
4124
4125 addr_t caller_address;
4126 CallEdge::AddrType caller_address_type;
4127 if (return_pc != LLDB_INVALID_ADDRESS) {
4128 caller_address = return_pc;
4129 caller_address_type = CallEdge::AddrType::AfterCall;
4130 } else if (low_pc != LLDB_INVALID_ADDRESS) {
4131 caller_address = low_pc;
4132 caller_address_type = CallEdge::AddrType::AfterCall;
4133 } else if (call_inst_pc != LLDB_INVALID_ADDRESS) {
4134 caller_address = call_inst_pc;
4135 caller_address_type = CallEdge::AddrType::Call;
4136 } else {
4137 LLDB_LOG(log, "CollectCallEdges: No caller address");
4138 continue;
4139 }
4140 // Adjust any PC forms. It needs to be fixed up if the main executable
4141 // contains a debug map (i.e. pointers to object files), because we need a
4142 // file address relative to the executable's text section.
4143 caller_address = FixupAddress(caller_address);
4144
4145 // Extract call site parameters.
4146 CallSiteParameterArray parameters =
4147 CollectCallSiteParameters(module, child);
4148
4149 std::unique_ptr<CallEdge> edge;
4150 if (call_origin) {
4151 LLDB_LOG(log,
4152 "CollectCallEdges: Found call origin: {0} (retn-PC: {1:x}) "
4153 "(call-PC: {2:x})",
4154 call_origin->GetPubname(), return_pc, call_inst_pc);
4155 edge = std::make_unique<DirectCallEdge>(
4156 call_origin->GetMangledName(), caller_address_type, caller_address,
4157 tail_call, std::move(parameters));
4158 } else {
4159 if (log) {
4160 StreamString call_target_desc;
4161 call_target->GetDescription(&call_target_desc, eDescriptionLevelBrief,
4162 nullptr);
4163 LLDB_LOG(log, "CollectCallEdges: Found indirect call target: {0}",
4164 call_target_desc.GetString());
4165 }
4166 edge = std::make_unique<IndirectCallEdge>(
4167 *call_target, caller_address_type, caller_address, tail_call,
4168 std::move(parameters));
4169 }
4170
4171 if (log && parameters.size()) {
4172 for (const CallSiteParameter &param : parameters) {
4173 StreamString callee_loc_desc, caller_loc_desc;
4174 param.LocationInCallee.GetDescription(&callee_loc_desc,
4175 eDescriptionLevelBrief, nullptr);
4176 param.LocationInCaller.GetDescription(&caller_loc_desc,
4177 eDescriptionLevelBrief, nullptr);
4178 LLDB_LOG(log, "CollectCallEdges: \tparam: {0} => {1}",
4179 callee_loc_desc.GetString(), caller_loc_desc.GetString());
4180 }
4181 }
4182
4183 call_edges.push_back(std::move(edge));
4184 }
4185 return call_edges;
4186}
4187
4188std::vector<std::unique_ptr<lldb_private::CallEdge>>
4190 // ParseCallEdgesInFunction must be called at the behest of an exclusively
4191 // locked lldb::Function instance. Storage for parsed call edges is owned by
4192 // the lldb::Function instance: locking at the SymbolFile level would be too
4193 // late, because the act of storing results from ParseCallEdgesInFunction
4194 // would be racy.
4195 DWARFDIE func_die = GetDIE(func_id.GetID());
4196 if (func_die.IsValid())
4197 return CollectCallEdges(GetObjectFile()->GetModule(), func_die);
4198 return {};
4199}
4200
4203 m_index->Dump(s);
4204}
4205
4208 if (!ts_or_err)
4209 return;
4210 auto ts = *ts_or_err;
4211 TypeSystemClang *clang = llvm::dyn_cast_or_null<TypeSystemClang>(ts.get());
4212 if (!clang)
4213 return;
4214 clang->Dump(s.AsRawOstream());
4215}
4216
4218 if (m_debug_map_symfile == nullptr) {
4219 lldb::ModuleSP module_sp(m_debug_map_module_wp.lock());
4220 if (module_sp) {
4221 m_debug_map_symfile = llvm::cast<SymbolFileDWARFDebugMap>(
4222 module_sp->GetSymbolFile()->GetBackingSymbolFile());
4223 }
4224 }
4225 return m_debug_map_symfile;
4226}
4227
4228const std::shared_ptr<SymbolFileDWARFDwo> &SymbolFileDWARF::GetDwpSymbolFile() {
4229 llvm::call_once(m_dwp_symfile_once_flag, [this]() {
4230 ModuleSpec module_spec;
4231 module_spec.GetFileSpec() = m_objfile_sp->GetFileSpec();
4232 module_spec.GetSymbolFileSpec() =
4233 FileSpec(m_objfile_sp->GetModule()->GetFileSpec().GetPath() + ".dwp");
4234
4236 FileSpec dwp_filespec =
4237 Symbols::LocateExecutableSymbolFile(module_spec, search_paths);
4238 if (FileSystem::Instance().Exists(dwp_filespec)) {
4239 DataBufferSP dwp_file_data_sp;
4240 lldb::offset_t dwp_file_data_offset = 0;
4241 ObjectFileSP dwp_obj_file = ObjectFile::FindPlugin(
4242 GetObjectFile()->GetModule(), &dwp_filespec, 0,
4243 FileSystem::Instance().GetByteSize(dwp_filespec), dwp_file_data_sp,
4244 dwp_file_data_offset);
4245 if (!dwp_obj_file)
4246 return;
4247 m_dwp_symfile = std::make_shared<SymbolFileDWARFDwo>(
4248 *this, dwp_obj_file, DIERef::k_file_index_mask);
4249 }
4250 });
4251 return m_dwp_symfile;
4252}
4253
4254llvm::Expected<lldb::TypeSystemSP>
4257}
4258
4260 auto type_system_or_err = GetTypeSystem(unit);
4261 if (auto err = type_system_or_err.takeError()) {
4262 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
4263 "Unable to get DWARFASTParser: {0}");
4264 return nullptr;
4265 }
4266 if (auto ts = *type_system_or_err)
4267 return ts->GetDWARFParser();
4268 return nullptr;
4269}
4270
4272 if (DWARFASTParser *dwarf_ast = GetDWARFParser(*die.GetCU()))
4273 return dwarf_ast->GetDeclForUIDFromDWARF(die);
4274 return CompilerDecl();
4275}
4276
4278 if (DWARFASTParser *dwarf_ast = GetDWARFParser(*die.GetCU()))
4279 return dwarf_ast->GetDeclContextForUIDFromDWARF(die);
4280 return CompilerDeclContext();
4281}
4282
4285 if (DWARFASTParser *dwarf_ast = GetDWARFParser(*die.GetCU()))
4286 return dwarf_ast->GetDeclContextContainingUIDFromDWARF(die);
4287 return CompilerDeclContext();
4288}
4289
4291 if (!die.IsValid())
4292 return {};
4293 DWARFDeclContext dwarf_decl_ctx =
4294 die.GetDIE()->GetDWARFDeclContext(die.GetCU());
4295 return dwarf_decl_ctx;
4296}
4297
4299 // Note: user languages between lo_user and hi_user must be handled
4300 // explicitly here.
4301 switch (val) {
4302 case DW_LANG_Mips_Assembler:
4304 default:
4305 return static_cast<LanguageType>(val);
4306 }
4307}
4308
4311}
4312
4314 auto lang = (llvm::dwarf::SourceLanguage)unit.GetDWARFLanguageType();
4315 if (llvm::dwarf::isCPlusPlus(lang))
4316 lang = DW_LANG_C_plus_plus;
4317 return LanguageTypeFromDWARF(lang);
4318}
4319
4321 if (m_index)
4322 return m_index->GetIndexTime();
4323 return {};
4324}
4325
4327 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
4328 CompileUnit *cu = frame.GetSymbolContext(eSymbolContextCompUnit).comp_unit;
4329 if (!cu)
4330 return Status();
4331
4332 DWARFCompileUnit *dwarf_cu = GetDWARFCompileUnit(cu);
4333 if (!dwarf_cu)
4334 return Status();
4335
4336 // Check if we have a skeleton compile unit that had issues trying to load
4337 // its .dwo/.dwp file. First pares the Unit DIE to make sure we see any .dwo
4338 // related errors.
4339 dwarf_cu->ExtractUnitDIEIfNeeded();
4340 const Status &dwo_error = dwarf_cu->GetDwoError();
4341 if (dwo_error.Fail())
4342 return dwo_error;
4343
4344 // Don't return an error for assembly files as they typically don't have
4345 // varaible information.
4346 if (dwarf_cu->GetDWARFLanguageType() == DW_LANG_Mips_Assembler)
4347 return Status();
4348
4349 // Check if this compile unit has any variable DIEs. If it doesn't then there
4350 // is not variable information for the entire compile unit.
4351 if (dwarf_cu->HasAny({DW_TAG_variable, DW_TAG_formal_parameter}))
4352 return Status();
4353
4354 return Status("no variable information is available in debug info for this "
4355 "compile unit");
4356}
4357
4359 std::unordered_map<lldb::CompUnitSP, lldb_private::Args> &args) {
4360
4361 const uint32_t num_compile_units = GetNumCompileUnits();
4362
4363 for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx) {
4364 lldb::CompUnitSP comp_unit = GetCompileUnitAtIndex(cu_idx);
4365 if (!comp_unit)
4366 continue;
4367
4368 DWARFUnit *dwarf_cu = GetDWARFCompileUnit(comp_unit.get());
4369 if (!dwarf_cu)
4370 continue;
4371
4372 const DWARFBaseDIE die = dwarf_cu->GetUnitDIEOnly();
4373 if (!die)
4374 continue;
4375
4376 const char *flags = die.GetAttributeValueAsString(DW_AT_APPLE_flags, NULL);
4377
4378 if (!flags)
4379 continue;
4380 args.insert({comp_unit, Args(flags)});
4381 }
4382}
static llvm::raw_ostream & error(Stream &strm)
std::vector< DIERef > DIEArray
Definition: DIERef.h:133
#define DEBUG_PRINTF(fmt,...)
static PluginProperties & GetGlobalPluginProperties()
#define lldbassert(x)
Definition: LLDBAssert.h:15
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
Definition: Log.h:342
#define LLDB_LOGF(log,...)
Definition: Log.h:349
#define LLDB_LOG_ERROR(log, error,...)
Definition: Log.h:365
#define LLDB_PLUGIN_DEFINE(PluginName)
Definition: PluginManager.h:31
static double elapsed(const StatsTimepoint &start, const StatsTimepoint &end)
Definition: Statistics.cpp:36
static PluginProperties & GetGlobalPluginProperties()
static ConstString GetDWARFMachOSegmentName()
static DWARFExpressionList GetExprListFromAtConstValue(DWARFFormValue form_value, ModuleSP module, const DWARFDIE &die)
Creates a DWARFExpressionList from an DW_AT_const_value.
static CallSiteParameterArray CollectCallSiteParameters(ModuleSP module, DWARFDIE call_site_die)
Collect call site parameters in a DW_TAG_call_site DIE.
static void MakeAbsoluteAndRemap(FileSpec &file_spec, DWARFUnit &dwarf_cu, const ModuleSP &module_sp)
Make an absolute path out of file_spec and remap it using the module's source remapping dictionary.
static bool ParseLLVMLineTablePrologue(lldb_private::DWARFContext &context, llvm::DWARFDebugLine::Prologue &prologue, dw_offset_t line_offset, dw_offset_t unit_offset)
static Symbol * fixupExternalAddrZeroVariable(SymbolFileDWARFDebugMap &debug_map_symfile, llvm::StringRef name, DWARFExpressionList &expr_list, const DWARFDIE &die)
Global variables that are not initialized may have their address set to zero.
static std::optional< uint64_t > GetDWOId(DWARFCompileUnit &dwarf_cu, const DWARFDebugInfoEntry &cu_die)
Return the DW_AT_(GNU_)dwo_id.
static std::optional< std::string > GetFileByIndex(const llvm::DWARFDebugLine::Prologue &prologue, size_t idx, llvm::StringRef compile_dir, FileSpec::Style style)
static FileSpecList ParseSupportFilesFromPrologue(const lldb::ModuleSP &module, const llvm::DWARFDebugLine::Prologue &prologue, FileSpec::Style style, llvm::StringRef compile_dir={})
static const llvm::DWARFDebugLine::LineTable * ParseLLVMLineTable(lldb_private::DWARFContext &context, llvm::DWARFDebugLine &line, dw_offset_t line_offset, dw_offset_t unit_offset)
static DWARFExpressionList GetExprListFromAtLocation(DWARFFormValue form_value, ModuleSP module, const DWARFDIE &die, const addr_t func_low_pc)
Creates a DWARFExpressionList from an DW_AT_location form_value.
static const char * GetDWOName(DWARFCompileUnit &dwarf_cu, const DWARFDebugInfoEntry &cu_die)
Return the DW_AT_(GNU_)dwo_name.
#define DIE_IS_BEING_PARSED
#define ASSERT_MODULE_LOCK(expr)
Definition: SymbolFile.h:38
#define LLDB_SCOPED_TIMER()
Definition: Timer.h:83
#define LLDB_SCOPED_TIMERF(...)
Definition: Timer.h:86
Identifies a DWARF debug info entry within a given Module.
Definition: DIERef.h:28
static constexpr uint64_t k_file_index_mask
Definition: DIERef.h:117
std::optional< uint32_t > file_index() const
Definition: DIERef.h:57
@ DebugInfo
Definition: DIERef.h:30
dw_offset_t die_offset() const
Definition: DIERef.h:65
lldb_private::ClangASTImporter & GetClangASTImporter()
virtual lldb_private::Function * ParseFunctionFromDWARF(lldb_private::CompileUnit &comp_unit, const DWARFDIE &die, const lldb_private::AddressRange &range)=0
virtual lldb_private::ConstString GetDIEClassTemplateParams(const DWARFDIE &die)=0
virtual void EnsureAllDIEsInDeclContextHaveBeenParsed(lldb_private::CompilerDeclContext decl_context)=0
virtual lldb_private::ConstString ConstructDemangledNameFromDWARF(const DWARFDIE &die)=0
virtual lldb::TypeSP ParseTypeFromDWARF(const lldb_private::SymbolContext &sc, const DWARFDIE &die, bool *type_is_new_ptr)=0
virtual lldb_private::CompilerDeclContext GetDeclContextForUIDFromDWARF(const DWARFDIE &die)=0
static std::optional< lldb_private::SymbolFile::ArrayInfo > ParseChildArrayInfo(const DWARFDIE &parent_die, const lldb_private::ExecutionContext *exe_ctx=nullptr)
dw_attr_t AttributeAtIndex(uint32_t i) const
DWARFUnit * CompileUnitAtIndex(uint32_t i) const
bool ExtractFormValueAtIndex(uint32_t i, DWARFFormValue &form_value) const
size_t Size() const
dw_tag_t Tag() const
DWARFAttributes GetAttributes(Recurse recurse=Recurse::yes) const
const char * GetTagAsCString() const
bool HasChildren() const
DWARFDebugInfoEntry * GetDIE() const
Definition: DWARFBaseDIE.h:57
const lldb_private::DWARFDataExtractor & GetData() const
bool IsValid() const
Definition: DWARFBaseDIE.h:46
void Clear()
Definition: DWARFBaseDIE.h:70
const char * GetAttributeValueAsString(const dw_attr_t attr, const char *fail_value) const
DWARFUnit * GetCU() const
Definition: DWARFBaseDIE.h:55
std::optional< DIERef > GetDIERef() const
lldb::ModuleSP GetModule() const
SymbolFileDWARF * GetDWARF() const
bool Supports_DW_AT_APPLE_objc_complete_type() const
const char * GetName() const
uint64_t GetAttributeValueAsUnsigned(const dw_attr_t attr, uint64_t fail_value) const
dw_offset_t GetOffset() const
lldb::user_id_t GetID() const
DWARFDIE LookupAddress(const dw_addr_t address)
DWARFCompileUnit & GetNonSkeletonUnit()
std::vector< DWARFDIE > GetDeclContextDIEs() const
Definition: DWARFDIE.cpp:361
void GetName(lldb_private::Stream &s) const
Definition: DWARFDIE.cpp:217
DWARFDIE GetFirstChild() const
Definition: DWARFDIE.cpp:94
DWARFDIE GetParent() const
Definition: DWARFDIE.cpp:86
void GetDeclContext(llvm::SmallVectorImpl< lldb_private::CompilerContext > &context) const
Return this DIE's decl context as it is needed to look up types in Clang's -gmodules debug info forma...
Definition: DWARFDIE.cpp:375
const char * GetMangledName() const
Definition: DWARFDIE.cpp:198
DWARFDIE GetDIE(dw_offset_t die_offset) const
Definition: DWARFDIE.cpp:118
llvm::iterator_range< child_iterator > children() const
The range of all the children of this DIE.
Definition: DWARFDIE.cpp:453
DWARFDIE LookupDeepestBlock(lldb::addr_t file_addr) const
Definition: DWARFDIE.cpp:139
DWARFDIE GetReferencedDIE(const dw_attr_t attr) const
Definition: DWARFDIE.cpp:110
bool GetDIENamesAndRanges(const char *&name, const char *&mangled, DWARFRangeList &ranges, std::optional< int > &decl_file, std::optional< int > &decl_line, std::optional< int > &decl_column, std::optional< int > &call_file, std::optional< int > &call_line, std::optional< int > &call_column, lldb_private::DWARFExpressionList *frame_base) const
Definition: DWARFDIE.cpp:439
const char * GetPubname() const
Definition: DWARFDIE.cpp:205
DWARFDIE GetSibling() const
Definition: DWARFDIE.cpp:102
void GetUnsupportedForms(std::set< dw_form_t > &invalid_forms) const
dw_offset_t FindAddress(dw_addr_t address) const
DWARFDebugInfoEntry objects assume that they are living in one big vector and do pointer arithmetic o...
std::optional< uint64_t > GetAttributeValueAsOptionalUnsigned(const DWARFUnit *cu, const dw_attr_t attr, bool check_specification_or_abstract_origin=false) const
dw_offset_t GetOffset() const
const char * GetAttributeValueAsString(const DWARFUnit *cu, const dw_attr_t attr, const char *fail_value, bool check_specification_or_abstract_origin=false) const
DWARFDebugInfoEntry * GetParent()
DWARFUnit * GetUnitAtOffset(DIERef::Section section, dw_offset_t cu_offset, uint32_t *idx_ptr=nullptr)
const DWARFDebugAranges & GetCompileUnitAranges()
DWARFDIE GetDIE(const DIERef &die_ref)
DWARFUnit * GetUnitAtIndex(size_t idx)
static void ReadMacroEntries(const lldb_private::DWARFDataExtractor &debug_macro_data, const lldb_private::DWARFDataExtractor &debug_str_data, const bool offset_is_64_bit, lldb::offset_t *sect_offset, SymbolFileDWARF *sym_file_dwarf, lldb_private::DebugMacrosSP &debug_macros_sp)
bool OffsetIs64Bit() const
static DWARFDebugMacroHeader ParseHeader(const lldb_private::DWARFDataExtractor &debug_macro_data, lldb::offset_t *offset)
const char * GetQualifiedName() const
lldb_private::ConstString GetQualifiedNameAsConstString() const
DWARFDIE Reference() const
bool IsValid() const
dw_form_t Form() const
const char * AsCString() const
uint64_t Unsigned() const
static bool IsDataForm(const dw_form_t form)
const uint8_t * BlockData() const
dw_addr_t Address() const
const DWARFUnit * GetUnit() const
static bool IsBlockForm(const dw_form_t form)
bool Boolean() const
SymbolFileDWARFDwo * GetDwoSymbolFile()
Definition: DWARFUnit.cpp:851
std::optional< uint64_t > GetLoclistOffset(uint32_t Index)
Definition: DWARFUnit.h:245
void * GetUserData() const
Definition: DWARFUnit.cpp:678
lldb_private::FileSpec::Style GetPathStyle()
Definition: DWARFUnit.cpp:772
SymbolFileDWARF & GetSymbolFileDWARF() const
Definition: DWARFUnit.h:200
bool GetIsOptimized()
Definition: DWARFUnit.cpp:758
void ExtractUnitDIEIfNeeded()
Definition: DWARFUnit.cpp:71
void SetDwoError(const lldb_private::Status &error)
Set the fission .dwo file specific error for this compile unit.
Definition: DWARFUnit.h:289
dw_offset_t GetLineTableOffset()
Definition: DWARFUnit.cpp:446
bool IsDWOUnit()
Definition: DWARFUnit.h:95
bool Supports_DW_AT_APPLE_objc_complete_type()
Definition: DWARFUnit.cpp:682
DWARFBaseDIE GetUnitDIEOnly()
Definition: DWARFUnit.h:178
uint16_t GetVersion() const
Definition: DWARFUnit.h:155
const lldb_private::Status & GetDwoError() const
Get the fission .dwo file specific error for this compile unit.
Definition: DWARFUnit.h:281
void SetUserData(void *d)
Definition: DWARFUnit.cpp:680
lldb_private::DWARFDataExtractor GetLocationData() const
Definition: DWARFUnit.cpp:524
uint8_t GetAddressByteSize() const
Definition: DWARFUnit.h:158
uint64_t GetDWARFLanguageType()
Definition: DWARFUnit.cpp:746
DWARFDIE DIE()
Definition: DWARFUnit.h:180
DWARFUnit & GetNonSkeletonUnit()
Definition: DWARFUnit.cpp:663
DWARFDIE GetDIE(dw_offset_t die_offset)
Definition: DWARFUnit.cpp:642
die_iterator_range dies()
Definition: DWARFUnit.h:217
lldb::ByteOrder GetByteOrder() const
Definition: DWARFUnit.cpp:624
const lldb_private::FileSpec & GetCompilationDirectory()
Definition: DWARFUnit.cpp:778
std::optional< uint64_t > GetDWOId()
Definition: DWARFUnit.cpp:367
bool HasAny(llvm::ArrayRef< dw_tag_t > tags)
Returns true if any DIEs in the unit match any DW_TAG values in tags.
Definition: DWARFUnit.cpp:1083
lldb_private::FileSpec GetFile(size_t file_idx)
Definition: DWARFUnit.cpp:790
dw_offset_t GetOffset() const
Definition: DWARFUnit.h:134
lldb::CompUnitSP GetCompileUnit(SymbolFileDWARF *oso_dwarf, DWARFCompileUnit &dwarf_cu)
Returns the compile unit associated with the dwarf compile unit.
bool Supports_DW_AT_APPLE_objc_complete_type(SymbolFileDWARF *skip_dwarf_oso)
UniqueDWARFASTTypeMap & GetUniqueDWARFASTTypeMap()
lldb::addr_t LinkOSOFileAddress(SymbolFileDWARF *oso_symfile, lldb::addr_t oso_file_addr)
Convert a .o file "file address" to an executable "file address".
bool LinkOSOAddress(lldb_private::Address &addr)
Convert addr from a .o file address, to an executable address.
lldb_private::CompilerDeclContext GetDeclContextContainingUID(lldb::user_id_t uid) override
static lldb_private::CompilerDeclContext GetContainingDeclContext(const DWARFDIE &die)
virtual lldb::TypeSP FindCompleteObjCDefinitionTypeForDIE(const DWARFDIE &die, lldb_private::ConstString type_name, bool must_be_implementation)
static bool SupportedVersion(uint16_t version)
std::optional< uint32_t > GetDWARFUnitIndex(uint32_t cu_idx)
virtual DIEToVariableSP & GetDIEToVariable()
llvm::DenseMap< const DWARFDebugInfoEntry *, lldb::VariableSP > DIEToVariableSP
lldb_private::CompileUnit * GetCompUnitForDWARFCompUnit(DWARFCompileUnit &dwarf_cu)
DWARFDebugRanges * GetDebugRanges()
void BuildCuTranslationTable()
size_t ParseVariablesForContext(const lldb_private::SymbolContext &sc) override
DWARFDIE FindBlockContainingSpecification(const DIERef &func_die_ref, dw_offset_t spec_block_die_offset)
void Dump(lldb_private::Stream &s) override
size_t ParseVariablesInFunctionContext(const lldb_private::SymbolContext &sc, const DWARFDIE &die, const lldb::addr_t func_low_pc)
bool HasForwardDeclForClangType(const lldb_private::CompilerType &compiler_type)
void UpdateExternalModuleListIfNeeded()
DebugMacrosMap m_debug_macros_map
static DWARFASTParser * GetDWARFParser(DWARFUnit &unit)
bool Supports_DW_AT_APPLE_objc_complete_type(DWARFUnit *cu)
static lldb::LanguageType GetLanguageFamily(DWARFUnit &unit)
Same as GetLanguage() but reports all C++ versions as C++ (no version).
const lldb_private::FileSpecList & GetTypeUnitSupportFiles(DWARFTypeUnit &tu)
bool ResolveFunction(const DWARFDIE &die, bool include_inlines, lldb_private::SymbolContextList &sc_list)
static char ID
LLVM RTTI support.
size_t ParseVariablesInFunctionContextRecursive(const lldb_private::SymbolContext &sc, const DWARFDIE &die, lldb::addr_t func_low_pc, DIEArray &accumulator)
lldb_private::CompilerDeclContext FindNamespace(lldb_private::ConstString name, const lldb_private::CompilerDeclContext &parent_decl_ctx, bool only_root_namespaces) override
Finds a namespace of name name and whose parent context is parent_decl_ctx.
static bool DIEInDeclContext(const lldb_private::CompilerDeclContext &parent_decl_ctx, const DWARFDIE &die, bool only_root_namespaces=false)
DWARFDebugAbbrev * DebugAbbrev()
lldb_private::Type * ResolveType(const DWARFDIE &die, bool assert_not_being_parsed=true, bool resolve_function_context=false)
ExternalTypeModuleMap m_external_type_modules
std::unique_ptr< DWARFDebugAbbrev > m_abbr
size_t PopulateBlockVariableList(lldb_private::VariableList &variable_list, const lldb_private::SymbolContext &sc, llvm::ArrayRef< DIERef > variable_dies, lldb::addr_t func_low_pc)
lldb_private::Function * ParseFunction(lldb_private::CompileUnit &comp_unit, const DWARFDIE &die)
lldb::ModuleSP GetExternalModule(lldb_private::ConstString name)
void InitializeFirstCodeAddressRecursive(const lldb_private::SectionList &section_list)
const std::shared_ptr< SymbolFileDWARFDwo > & GetDwpSymbolFile()
friend class DWARFDIE
size_t ParseFunctions(lldb_private::CompileUnit &comp_unit) override
std::recursive_mutex & GetModuleMutex() const override
Symbols file subclasses should override this to return the Module that owns the TypeSystem that this ...
virtual DWARFCompileUnit * GetDWARFCompileUnit(lldb_private::CompileUnit *comp_unit)
std::optional< ArrayInfo > GetDynamicArrayInfoForUID(lldb::user_id_t type_uid, const lldb_private::ExecutionContext *exe_ctx) override
If type_uid points to an array type, return its characteristics.
lldb_private::RangeDataVector< lldb::addr_t, lldb::addr_t, lldb_private::Variable * > GlobalVariableMap
uint32_t ResolveSymbolContext(const lldb_private::Address &so_addr, lldb::SymbolContextItem resolve_scope, lldb_private::SymbolContext &sc) override
bool CompleteType(lldb_private::CompilerType &compiler_type) override
GlobalVariableMap & GetGlobalAranges()
lldb::TypeSP GetTypeForDIE(const DWARFDIE &die, bool resolve_function_context=false)
NameToOffsetMap m_function_scope_qualified_name_map
bool ParseImportedModules(const lldb_private::SymbolContext &sc, std::vector< lldb_private::SourceModule > &imported_modules) override
size_t ParseBlocksRecursive(lldb_private::Function &func) override
lldb::LanguageType ParseLanguage(lldb_private::CompileUnit &comp_unit) override
lldb_private::ConstString ConstructFunctionDemangledName(const DWARFDIE &die)
std::unique_ptr< GlobalVariableMap > m_global_aranges_up
bool ForEachExternalModule(lldb_private::CompileUnit &, llvm::DenseSet< lldb_private::SymbolFile * > &, llvm::function_ref< bool(lldb_private::Module &)>) override
lldb_private::FileSpec GetFile(DWARFUnit &unit, size_t file_idx)
size_t ParseTypes(lldb_private::CompileUnit &comp_unit) override
virtual DWARFDIE GetDIE(const DIERef &die_ref)
SymbolFileDWARF(lldb::ObjectFileSP objfile_sp, lldb_private::SectionList *dwo_section_list)
static void Initialize()
void InitializeFirstCodeAddress()
bool DeclContextMatchesThisSymbolFile(const lldb_private::CompilerDeclContext &decl_ctx)
lldb::TypeSP ParseType(const lldb_private::SymbolContext &sc, const DWARFDIE &die, bool *type_is_new)
static lldb_private::CompilerDecl GetDecl(const DWARFDIE &die)
static void DebuggerInitialize(lldb_private::Debugger &debugger)
virtual void LoadSectionData(lldb::SectionType sect_type, lldb_private::DWARFDataExtractor &data)
void FindTypes(lldb_private::ConstString name, const lldb_private::CompilerDeclContext &parent_decl_ctx, uint32_t max_matches, llvm::DenseSet< lldb_private::SymbolFile * > &searched_symbol_files, lldb_private::TypeMap &types) override
uint32_t CalculateNumCompileUnits() override
static llvm::StringRef GetPluginNameStatic()
llvm::DenseMap< dw_offset_t, lldb_private::FileSpecList > m_type_unit_support_files
lldb_private::Type * ResolveTypeUID(lldb::user_id_t type_uid) override
static lldb::LanguageType GetLanguage(DWARFUnit &unit)
bool ClassOrStructIsVirtual(const DWARFDIE &die)
std::shared_ptr< SymbolFileDWARFDwo > m_dwp_symfile
std::unique_ptr< DWARFDebugRanges > m_ranges
void FindGlobalVariables(lldb_private::ConstString name, const lldb_private::CompilerDeclContext &parent_decl_ctx, uint32_t max_matches, lldb_private::VariableList &variables) override
bool GetFunction(const DWARFDIE &die, lldb_private::SymbolContext &sc)
static lldb_private::SymbolFile * CreateInstance(lldb::ObjectFileSP objfile_sp)
lldb_private::XcodeSDK ParseXcodeSDK(lldb_private::CompileUnit &comp_unit) override
Return the Xcode SDK comp_unit was compiled against.
lldb_private::StatsDuration m_parse_time
std::optional< uint64_t > GetDWOId()
If this is a DWARF object with a single CU, return its DW_AT_dwo_id.
uint32_t CalculateAbilities() override
SymbolFileDWARFDebugMap * GetDebugMapSymfile()
std::shared_ptr< SymbolFileDWARFDwo > GetDwoSymbolFileForCompileUnit(DWARFUnit &dwarf_cu, const DWARFDebugInfoEntry &cu_die)
bool m_fetched_external_modules
lldb::addr_t m_first_code_address
DWARF does not provide a good way for traditional (concatenating) linkers to invalidate debug info de...
static DWARFDeclContext GetDWARFDeclContext(const DWARFDIE &die)
~SymbolFileDWARF() override
lldb_private::StatsDuration::Duration GetDebugInfoIndexTime() override
Return the time it took to index the debug information in the object file.
lldb_private::DWARFContext m_context
DWARFDebugInfo & DebugInfo()
lldb_private::Status CalculateFrameVariableError(lldb_private::StackFrame &frame) override
Subclasses will override this function to for GetFrameVariableError().
virtual lldb::TypeSP FindDefinitionTypeForDWARFDeclContext(const DWARFDIE &die)
static llvm::StringRef GetPluginDescriptionStatic()
std::vector< std::unique_ptr< lldb_private::CallEdge > > CollectCallEdges(lldb::ModuleSP module, DWARFDIE function_die)
Parse call site entries (DW_TAG_call_site), including any nested call site parameters (DW_TAG_call_si...
DIEArray MergeBlockAbstractParameters(const DWARFDIE &block_die, DIEArray &&variable_dies)
DWARFDIE GetDeclContextDIEContainingDIE(const DWARFDIE &die)
void ResolveFunctionAndBlock(lldb::addr_t file_vm_addr, bool lookup_block, lldb_private::SymbolContext &sc)
Resolve functions and (possibly) blocks for the given file address and a compile unit.
llvm::once_flag m_info_once_flag
void InitializeObject() override
Initialize the SymbolFile object.
static llvm::Expected< lldb::TypeSystemSP > GetTypeSystem(DWARFUnit &unit)
std::vector< uint32_t > m_lldb_cu_to_dwarf_unit
lldb_private::Symbol * GetObjCClassSymbol(lldb_private::ConstString objc_class_name)
void GetMangledNamesForFunction(const std::string &scope_qualified_name, std::vector< lldb_private::ConstString > &mangled_names) override
std::atomic_flag m_dwo_warning_issued
void PreloadSymbols() override
lldb::VariableSP ParseVariableDIE(const lldb_private::SymbolContext &sc, const DWARFDIE &die, const lldb::addr_t func_low_pc)
lldb_private::TypeList & GetTypeList() override
std::unique_ptr< lldb_private::DWARFIndex > m_index
std::vector< std::unique_ptr< lldb_private::CallEdge > > ParseCallEdgesInFunction(lldb_private::UserID func_id) override
llvm::once_flag m_dwp_symfile_once_flag
lldb::CompUnitSP ParseCompileUnit(DWARFCompileUnit &dwarf_cu)
lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) override
llvm::SetVector< lldb_private::Type * > TypeSet
static lldb::LanguageType LanguageTypeFromDWARF(uint64_t val)
void DumpClangAST(lldb_private::Stream &s) override
bool ParseSupportFiles(lldb_private::CompileUnit &comp_unit, lldb_private::FileSpecList &support_files) override
static DWARFDIE GetParentSymbolContextDIE(const DWARFDIE &die)
lldb::addr_t FixupAddress(lldb::addr_t file_addr)
If this symbol file is linked to by a debug map (see SymbolFileDWARFDebugMap), and file_addr is a fil...
static void Terminate()
llvm::Expected< lldb::TypeSystemSP > GetTypeSystemForLanguage(lldb::LanguageType language) override
lldb_private::CompilerDecl GetDeclForUID(lldb::user_id_t uid) override
std::unique_ptr< DWARFDebugInfo > m_info
virtual void GetObjCMethods(lldb_private::ConstString class_name, llvm::function_ref< bool(DWARFDIE die)> callback)
virtual DIEToTypePtr & GetDIEToType()
void GetTypes(lldb_private::SymbolContextScope *sc_scope, lldb::TypeClass type_mask, lldb_private::TypeList &type_list) override
lldb_private::CompilerDeclContext GetDeclContextForUID(lldb::user_id_t uid) override
void ParseAndAppendGlobalVariable(const lldb_private::SymbolContext &sc, const DWARFDIE &die, lldb_private::VariableList &cc_variable_list)
virtual ClangTypeToDIE & GetForwardDeclClangTypeToDie()
lldb::ModuleWP m_debug_map_module_wp
lldb::VariableSP ParseVariableDIECached(const lldb_private::SymbolContext &sc, const DWARFDIE &die)
SymbolFileDWARFDebugMap * m_debug_map_symfile
bool ParseLineTable(lldb_private::CompileUnit &comp_unit) override
UniqueDWARFASTTypeMap m_unique_ast_type_map
void ParseDeclsForContext(lldb_private::CompilerDeclContext decl_ctx) override
bool DIEDeclContextsMatch(const DWARFDIE &die1, const DWARFDIE &die2)
bool ParseDebugMacros(lldb_private::CompileUnit &comp_unit) override
lldb_private::LazyBool m_supports_DW_AT_APPLE_objc_complete_type
static lldb_private::CompilerDeclContext GetDeclContext(const DWARFDIE &die)
bool ParseIsOptimized(lldb_private::CompileUnit &comp_unit) override
virtual UniqueDWARFASTTypeMap & GetUniqueDWARFASTTypeMap()
void FindFunctions(const lldb_private::Module::LookupInfo &lookup_info, const lldb_private::CompilerDeclContext &parent_decl_ctx, bool include_inlines, lldb_private::SymbolContextList &sc_list) override
A section + offset based address range class.
Definition: AddressRange.h:25
Address & GetBaseAddress()
Get accessor for the base address of the range.
Definition: AddressRange.h:209
void SetByteSize(lldb::addr_t byte_size)
Set accessor for the byte size of this range.
Definition: AddressRange.h:237
A section + offset based address class.
Definition: Address.h:59
bool ResolveAddressUsingFileSections(lldb::addr_t addr, const SectionList *sections)
Resolve a file virtual address using a section list.
Definition: Address.cpp:248
lldb::SectionSP GetSection() const
Get const accessor for the section.
Definition: Address.h:429
void Clear()
Clear the object's state.
Definition: Address.h:178
lldb::addr_t GetFileAddress() const
Get the file address.
Definition: Address.cpp:291
lldb::addr_t GetOffset() const
Get the section relative offset value.
Definition: Address.h:319
bool IsValid() const
Check if the object state is valid.
Definition: Address.h:345
static std::unique_ptr< AppleDWARFIndex > Create(Module &module, DWARFDataExtractor apple_names, DWARFDataExtractor apple_namespaces, DWARFDataExtractor apple_types, DWARFDataExtractor apple_objc, DWARFDataExtractor debug_str)
A command line argument class.
Definition: Args.h:33
A class that describes a single lexical block.
Definition: Block.h:41
lldb::VariableListSP GetBlockVariableList(bool can_create)
Get the variable list for this block only.
Definition: Block.cpp:399
Block * FindBlockByID(lldb::user_id_t block_id)
Definition: Block.cpp:112
void SetVariableList(lldb::VariableListSP &variable_list_sp)
Set accessor for the variable list.
Definition: Block.h:331
bool GetStartAddress(Address &addr)
Definition: Block.cpp:317
void SetDidParseVariables(bool b, bool set_children)
Definition: Block.cpp:496
void AddRange(const Range &range)
Add a new offset range to this block.
Definition: Block.cpp:335
void FinalizeRanges()
Definition: Block.cpp:330
void AddChild(const lldb::BlockSP &child_block_sp)
Add a child to this object.
Definition: Block.cpp:385
void SetInlinedFunctionInfo(const char *name, const char *mangled, const Declaration *decl_ptr, const Declaration *call_decl_ptr)
Set accessor for any inlined function information.
Definition: Block.cpp:392
static bool ExtractContextAndIdentifier(const char *name, llvm::StringRef &context, llvm::StringRef &identifier)
bool CanImport(const CompilerType &type)
Returns true iff the given type was copied from another TypeSystemClang and the original type in this...
bool CompleteType(const CompilerType &compiler_type)
static bool LanguageSupportsClangModules(lldb::LanguageType language)
Query whether Clang supports modules for a particular language.
A class that describes a compilation unit.
Definition: CompileUnit.h:41
void SetVariableList(lldb::VariableListSP &variable_list_sp)
Set accessor for the variable list.
lldb::VariableListSP GetVariableList(bool can_create)
Get the variable list for a compile unit.
void SetDebugMacros(const DebugMacrosSP &debug_macros)
void SetSupportFiles(const FileSpecList &support_files)
const FileSpec & GetPrimaryFile() const
Return the primary source file associated with this compile unit.
Definition: CompileUnit.h:227
void ResolveSymbolContext(const SourceLocationSpec &src_location_spec, lldb::SymbolContextItem resolve_scope, SymbolContextList &sc_list)
Resolve symbol contexts by file and line.
void SetLineTable(LineTable *line_table)
Set the line table for the compile unit.
lldb::FunctionSP FindFunctionByUID(lldb::user_id_t uid)
Finds a function by user ID.
const FileSpecList & GetSupportFiles()
Get the compile unit's support file list.
lldb::LanguageType GetLanguage()
LineTable * GetLineTable()
Get the line table for the compile unit.
Represents a generic declaration context in a program.
bool IsContainedInLookup(CompilerDeclContext other) const
Check if the given other decl context is contained in the lookup of this decl context (for example be...
Represents a generic declaration such as a function declaration.
Definition: CompilerDecl.h:28
std::shared_ptr< TypeSystemType > dyn_cast_or_null()
Return a shared_ptr<TypeSystemType> if dyn_cast succeeds.
Definition: CompilerType.h:68
Generic representation of a type in a programming language.
Definition: CompilerType.h:36
TypeSystemSPWrapper GetTypeSystem() const
Accessors.
lldb::opaque_compiler_type_t GetOpaqueQualType() const
Definition: CompilerType.h:234
A uniqued constant string class.
Definition: ConstString.h:40
const char * AsCString(const char *value_if_empty=nullptr) const
Get the string value as a C string.
Definition: ConstString.h:182
bool IsEmpty() const
Test for empty string.
Definition: ConstString.h:293
llvm::StringRef GetStringRef() const
Get the string value as a llvm::StringRef.
Definition: ConstString.h:191
const char * GetCString() const
Get the string value as a C string.
Definition: ConstString.h:205
const DWARFDataExtractor & getOrLoadLineData()
const DWARFDataExtractor & getOrLoadStrData()
llvm::DWARFContext & GetAsLLVM()
const DWARFDataExtractor & getOrLoadRangesData()
const DWARFDataExtractor & getOrLoadAbbrevData()
const DWARFDataExtractor & getOrLoadMacroData()
llvm::DWARFDataExtractor GetAsLLVMDWARF() const
"lldb/Expression/DWARFExpressionList.h" Encapsulates a range map from file address range to a single ...
bool Evaluate(ExecutionContext *exe_ctx, RegisterContext *reg_ctx, lldb::addr_t func_load_addr, const Value *initial_value_ptr, const Value *object_address_ptr, Value &result, Status *error_ptr) const
const DWARFExpression * GetAlwaysValidExpr() const
void SetModule(const lldb::ModuleSP &module)
bool IsValid() const
Return true if the location expression contains data.
void SetFuncFileAddress(lldb::addr_t func_file_addr)
bool LinkThreadLocalStorage(lldb::ModuleSP new_module_sp, std::function< lldb::addr_t(lldb::addr_t file_addr)> const &link_address_callback)
DWARFExpression * GetMutableExpressionAtAddress(lldb::addr_t func_load_addr=LLDB_INVALID_ADDRESS, lldb::addr_t load_addr=0)
"lldb/Expression/DWARFExpression.h" Encapsulates a DWARF location expression and interprets it.
lldb::addr_t GetLocation_DW_OP_addr(const DWARFUnit *dwarf_cu, bool &error) const
Return the address specified by the first DW_OP_{addr, addrx, GNU_addr_index} in the operation stream...
void DumpLocation(Stream *s, lldb::DescriptionLevel level, ABI *abi) const
Definition: