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#include "clang/Basic/ABI.h"
11#include "llvm/ADT/STLExtras.h"
12#include "llvm/ADT/StringExtras.h"
13#include "llvm/ADT/StringRef.h"
14#include "llvm/DebugInfo/DWARF/DWARFAddressRange.h"
15#include "llvm/DebugInfo/DWARF/DWARFDebugLoc.h"
16#include "llvm/Support/Casting.h"
17#include "llvm/Support/Error.h"
18#include "llvm/Support/ErrorExtras.h"
19#include "llvm/Support/FileUtilities.h"
20#include "llvm/Support/FormatAdapters.h"
21#include "llvm/Support/Threading.h"
22
23#include "lldb/Core/Module.h"
27#include "lldb/Core/Progress.h"
28#include "lldb/Core/Section.h"
29#include "lldb/Core/Value.h"
34#include "lldb/Utility/Scalar.h"
37#include "lldb/Utility/Timer.h"
38
41
42#include "lldb/Host/Config.h"
44#include "lldb/Host/Host.h"
45
48
53#include "lldb/Symbol/Block.h"
61#include "lldb/Symbol/TypeMap.h"
64
66#include "lldb/Target/Target.h"
67
68#include "AppleDWARFIndex.h"
69#include "DWARFASTParser.h"
70#include "DWARFASTParserClang.h"
71#include "DWARFCompileUnit.h"
72#include "DWARFDebugAranges.h"
73#include "DWARFDebugInfo.h"
74#include "DWARFDebugMacro.h"
75#include "DWARFDeclContext.h"
76#include "DWARFFormValue.h"
77#include "DWARFTypeUnit.h"
78#include "DWARFUnit.h"
80#include "LogChannelDWARF.h"
81#include "ManualDWARFIndex.h"
83#include "SymbolFileDWARFDwo.h"
85
86#include "llvm/DebugInfo/DWARF/DWARFContext.h"
87#include "llvm/DebugInfo/DWARF/DWARFDebugAbbrev.h"
88#include "llvm/Demangle/Demangle.h"
89#include "llvm/Support/FileSystem.h"
90#include "llvm/Support/FormatVariadic.h"
91
92#include <algorithm>
93#include <map>
94#include <memory>
95#include <optional>
96
97#include <cctype>
98#include <cstring>
99
100//#define ENABLE_DEBUG_PRINTF // COMMENT OUT THIS LINE PRIOR TO CHECKIN
101
102#ifdef ENABLE_DEBUG_PRINTF
103#include <cstdio>
104#define DEBUG_PRINTF(fmt, ...) printf(fmt, __VA_ARGS__)
105#else
106#define DEBUG_PRINTF(fmt, ...)
107#endif
108
109using namespace lldb;
110using namespace lldb_private;
111using namespace lldb_private::plugin::dwarf;
112using namespace llvm::dwarf;
113
115
117
118namespace {
119
120#define LLDB_PROPERTIES_symbolfiledwarf
121#include "SymbolFileDWARFProperties.inc"
122
123enum {
124#define LLDB_PROPERTIES_symbolfiledwarf
125#include "SymbolFileDWARFPropertiesEnum.inc"
126};
127
128class PluginProperties : public Properties {
129public:
130 static llvm::StringRef GetSettingName() {
132 }
133
134 PluginProperties() {
135 m_collection_sp = std::make_shared<OptionValueProperties>(GetSettingName());
136 m_collection_sp->Initialize(g_symbolfiledwarf_properties_def);
137 }
138
139 bool IgnoreFileIndexes() const {
140 return GetPropertyAtIndexAs<bool>(ePropertyIgnoreIndexes, false);
141 }
142};
143
144} // namespace
145
146bool IsStructOrClassTag(llvm::dwarf::Tag Tag) {
147 return Tag == llvm::dwarf::Tag::DW_TAG_class_type ||
148 Tag == llvm::dwarf::Tag::DW_TAG_structure_type;
149}
150
151static PluginProperties &GetGlobalPluginProperties() {
152 static PluginProperties g_settings;
153 return g_settings;
154}
155
156static const llvm::DWARFDebugLine::LineTable *
157ParseLLVMLineTable(DWARFContext &context, llvm::DWARFDebugLine &line,
158 dw_offset_t line_offset, dw_offset_t unit_offset) {
160
161 llvm::DWARFDataExtractor data = context.getOrLoadLineData().GetAsLLVMDWARF();
162 llvm::DWARFContext &ctx = context.GetAsLLVM();
163 llvm::Expected<const llvm::DWARFDebugLine::LineTable *> line_table =
164 line.getOrParseLineTable(
165 data, line_offset, ctx, nullptr, [&](llvm::Error e) {
167 log, std::move(e),
168 "SymbolFileDWARF::ParseLineTable failed to parse: {0}");
169 });
170
171 if (!line_table) {
172 LLDB_LOG_ERROR(log, line_table.takeError(),
173 "SymbolFileDWARF::ParseLineTable failed to parse: {0}");
174 return nullptr;
175 }
176 return *line_table;
177}
178
180 llvm::DWARFDebugLine::Prologue &prologue,
181 dw_offset_t line_offset,
182 dw_offset_t unit_offset) {
184 bool success = true;
185 llvm::DWARFDataExtractor data = context.getOrLoadLineData().GetAsLLVMDWARF();
186 llvm::DWARFContext &ctx = context.GetAsLLVM();
187 uint64_t offset = line_offset;
188 llvm::Error error = prologue.parse(
189 data, &offset,
190 [&](llvm::Error e) {
191 success = false;
192 LLDB_LOG_ERROR(log, std::move(e),
193 "SymbolFileDWARF::ParseSupportFiles failed to parse "
194 "line table prologue: {0}");
195 },
196 ctx, nullptr);
197 if (error) {
198 LLDB_LOG_ERROR(log, std::move(error),
199 "SymbolFileDWARF::ParseSupportFiles failed to parse line "
200 "table prologue: {0}");
201 return false;
202 }
203 return success;
204}
205
206static std::optional<std::string>
207GetFileByIndex(const llvm::DWARFDebugLine::Prologue &prologue, size_t idx,
208 llvm::StringRef compile_dir, FileSpec::Style style) {
209 // Try to get an absolute path first.
210 std::string abs_path;
211 auto absolute = llvm::DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath;
212 if (prologue.getFileNameByIndex(idx, compile_dir, absolute, abs_path, style))
213 return std::move(abs_path);
214
215 // Otherwise ask for a relative path.
216 std::string rel_path;
217 auto relative = llvm::DILineInfoSpecifier::FileLineInfoKind::RawValue;
218 if (!prologue.getFileNameByIndex(idx, compile_dir, relative, rel_path, style))
219 return {};
220 return std::move(rel_path);
221}
222
224 SupportFileList &support_files, const lldb::ModuleSP &module,
225 const llvm::DWARFDebugLine::Prologue &prologue, FileSpec::Style style,
226 llvm::StringRef compile_dir = {}) {
227 // Handle the case where there are no files first to avoid having to special
228 // case this later.
229 if (prologue.FileNames.empty())
230 return;
231
232 // Before DWARF v5, the line table indexes were one based.
233 const bool is_one_based = prologue.getVersion() < 5;
234 const size_t file_names = prologue.FileNames.size();
235 const size_t first_file_idx = is_one_based ? 1 : 0;
236 const size_t last_file_idx = is_one_based ? file_names : file_names - 1;
237
238 // Add a dummy entry to ensure the support file list indices match those we
239 // get from the debug info and line tables.
240 if (is_one_based)
241 support_files.Append(FileSpec());
242
243 for (size_t idx = first_file_idx; idx <= last_file_idx; ++idx) {
244 std::string remapped_file;
245 if (auto file_path = GetFileByIndex(prologue, idx, compile_dir, style)) {
246 auto entry = prologue.getFileNameEntry(idx);
247 auto source = entry.Source.getAsCString();
248 if (!source)
249 consumeError(source.takeError());
250 else {
251 llvm::StringRef source_ref(*source);
252 if (!source_ref.empty()) {
253 /// Wrap a path for an in-DWARF source file. Lazily write it
254 /// to disk when Materialize() is called.
255 struct LazyDWARFSourceFile : public SupportFile {
256 LazyDWARFSourceFile(const FileSpec &fs, llvm::StringRef source,
257 FileSpec::Style style)
258 : SupportFile(fs), source(source), style(style) {}
259 FileSpec tmp_file;
260 /// The file contents buffer.
261 llvm::StringRef source;
262 /// Deletes the temporary file at the end.
263 std::unique_ptr<llvm::FileRemover> remover;
264 FileSpec::Style style;
265
266 /// Write the file contents to a temporary file.
267 const FileSpec &Materialize() override {
268 if (tmp_file)
269 return tmp_file;
270 llvm::SmallString<0> name;
271 int fd;
272 auto orig_name = m_file_spec.GetFilename();
273 auto ec = llvm::sys::fs::createTemporaryFile(
274 "", llvm::sys::path::filename(orig_name, style), fd, name);
275 if (ec || fd <= 0) {
276 LLDB_LOG(GetLog(DWARFLog::DebugInfo),
277 "Could not create temporary file");
278 return tmp_file;
279 }
280 remover = std::make_unique<llvm::FileRemover>(name);
282 size_t num_bytes = source.size();
283 file.Write(source.data(), num_bytes);
284 tmp_file.SetPath(name);
285 return tmp_file;
286 }
287 };
288 support_files.Append(std::make_unique<LazyDWARFSourceFile>(
289 FileSpec(*file_path), *source, style));
290 continue;
291 }
292 }
293 if (auto remapped = module->RemapSourceFile(llvm::StringRef(*file_path)))
294 remapped_file = *remapped;
295 else
296 remapped_file = std::move(*file_path);
297 }
298
299 Checksum checksum;
300 if (prologue.ContentTypes.HasMD5) {
301 const llvm::DWARFDebugLine::FileNameEntry &file_name_entry =
302 prologue.getFileNameEntry(idx);
303 checksum = file_name_entry.Checksum;
304 }
305
306 // Unconditionally add an entry, so the indices match up.
307 support_files.EmplaceBack(FileSpec(remapped_file, style), checksum);
308 }
309}
310
318
321 debugger, PluginProperties::GetSettingName())) {
322 const bool is_global_setting = true;
324 debugger, GetGlobalPluginProperties().GetValueProperties(),
325 "Properties for the dwarf symbol-file plug-in.", is_global_setting);
326 }
327}
328
334
336 return "DWARF and DWARF3 debug symbol file reader.";
337}
338
340 return LLDB_DWO_DIAGNOSTIC_SUFFIX;
341}
342
344 if (objfile_sp->GetArchitecture().GetTriple().isWasm())
345 return new SymbolFileWasm(std::move(objfile_sp),
346 /*dwo_section_list*/ nullptr);
347 return new SymbolFileDWARF(std::move(objfile_sp),
348 /*dwo_section_list*/ nullptr);
349}
350
352 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
353 if (SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile())
354 return debug_map_symfile->GetTypeList();
356}
357void SymbolFileDWARF::GetTypes(const DWARFDIE &die, dw_offset_t min_die_offset,
358 dw_offset_t max_die_offset, uint32_t type_mask,
359 TypeSet &type_set) {
360 if (die) {
361 const dw_offset_t die_offset = die.GetOffset();
362
363 if (die_offset >= max_die_offset)
364 return;
365
366 if (die_offset >= min_die_offset) {
367 const dw_tag_t tag = die.Tag();
368
369 bool add_type = false;
370
371 switch (tag) {
372 case DW_TAG_array_type:
373 add_type = (type_mask & eTypeClassArray) != 0;
374 break;
375 case DW_TAG_unspecified_type:
376 case DW_TAG_base_type:
377 add_type = (type_mask & eTypeClassBuiltin) != 0;
378 break;
379 case DW_TAG_class_type:
380 add_type = (type_mask & eTypeClassClass) != 0;
381 break;
382 case DW_TAG_structure_type:
383 add_type = (type_mask & eTypeClassStruct) != 0;
384 break;
385 case DW_TAG_union_type:
386 add_type = (type_mask & eTypeClassUnion) != 0;
387 break;
388 case DW_TAG_enumeration_type:
389 add_type = (type_mask & eTypeClassEnumeration) != 0;
390 break;
391 case DW_TAG_subroutine_type:
392 case DW_TAG_subprogram:
393 case DW_TAG_inlined_subroutine:
394 add_type = (type_mask & eTypeClassFunction) != 0;
395 break;
396 case DW_TAG_pointer_type:
397 add_type = (type_mask & eTypeClassPointer) != 0;
398 break;
399 case DW_TAG_rvalue_reference_type:
400 case DW_TAG_reference_type:
401 add_type = (type_mask & eTypeClassReference) != 0;
402 break;
403 case DW_TAG_typedef:
404 add_type = (type_mask & eTypeClassTypedef) != 0;
405 break;
406 case DW_TAG_ptr_to_member_type:
407 add_type = (type_mask & eTypeClassMemberPointer) != 0;
408 break;
409 default:
410 break;
411 }
412
413 if (add_type) {
414 const bool assert_not_being_parsed = true;
415 Type *type = ResolveTypeUID(die, assert_not_being_parsed);
416 if (type)
417 type_set.insert(type);
418 }
419 }
420
421 for (DWARFDIE child_die : die.children()) {
422 GetTypes(child_die, min_die_offset, max_die_offset, type_mask, type_set);
423 }
424 }
425}
426
428 TypeClass type_mask, TypeList &type_list)
429
430{
431 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
432 TypeSet type_set;
433
434 CompileUnit *comp_unit = nullptr;
435 if (sc_scope)
436 comp_unit = sc_scope->CalculateSymbolContextCompileUnit();
437
438 const auto &get = [&](DWARFUnit *unit) {
439 if (!unit)
440 return;
441 unit = &unit->GetNonSkeletonUnit();
442 GetTypes(unit->DIE(), unit->GetOffset(), unit->GetNextUnitOffset(),
443 type_mask, type_set);
444 };
445 if (comp_unit) {
446 get(GetDWARFCompileUnit(comp_unit));
447 } else {
448 DWARFDebugInfo &info = DebugInfo();
449 const size_t num_cus = info.GetNumUnits();
450 for (size_t cu_idx = 0; cu_idx < num_cus; ++cu_idx)
451 get(info.GetUnitAtIndex(cu_idx));
452 }
453
454 std::set<CompilerType> compiler_type_set;
455 for (Type *type : type_set) {
456 CompilerType compiler_type = type->GetForwardCompilerType();
457 if (compiler_type_set.find(compiler_type) == compiler_type_set.end()) {
458 compiler_type_set.insert(compiler_type);
459 type_list.Insert(type->shared_from_this());
460 }
461 }
462}
463
464// Gets the first parent that is a lexical block, function or inlined
465// subroutine, or compile unit.
468 DWARFDIE die;
469 for (die = child_die.GetParent(); die; die = die.GetParent()) {
470 dw_tag_t tag = die.Tag();
471
472 switch (tag) {
473 case DW_TAG_compile_unit:
474 case DW_TAG_partial_unit:
475 case DW_TAG_subprogram:
476 case DW_TAG_inlined_subroutine:
477 case DW_TAG_lexical_block:
478 return die;
479 default:
480 break;
481 }
482 }
483 return DWARFDIE();
484}
485
487 SectionList *dwo_section_list)
488 : SymbolFileCommon(std::move(objfile_sp)), m_debug_map_module_wp(),
489 m_debug_map_symfile(nullptr),
490 m_context(m_objfile_sp->GetModule()->GetSectionList(), dwo_section_list),
492
494
496 static ConstString g_dwarf_section_name("__DWARF");
497 return g_dwarf_section_name;
498}
499
500llvm::DenseMap<const DWARFDebugInfoEntry *, Type *> &
502 if (SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile())
503 return debug_map_symfile->GetDIEToType();
504 return m_die_to_type;
505}
506
507llvm::DenseMap<lldb::opaque_compiler_type_t, DIERef> &
509 if (SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile())
510 return debug_map_symfile->GetForwardDeclCompilerTypeToDIE();
512}
513
515 SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile();
516 if (debug_map_symfile)
517 return debug_map_symfile->GetUniqueDWARFASTTypeMap();
518 else
520}
521
522llvm::Expected<lldb::TypeSystemSP>
524 if (SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile())
525 return debug_map_symfile->GetTypeSystemForLanguage(language);
526
528}
529
532
534
535 if (!GetGlobalPluginProperties().IgnoreFileIndexes()) {
536 StreamString module_desc;
537 GetObjectFile()->GetModule()->GetDescription(module_desc.AsRawOstream(),
539 DWARFDataExtractor apple_names, apple_namespaces, apple_types, apple_objc;
544
545 if (apple_names.GetByteSize() > 0 || apple_namespaces.GetByteSize() > 0 ||
546 apple_types.GetByteSize() > 0 || apple_objc.GetByteSize() > 0) {
548 *GetObjectFile()->GetModule(), apple_names, apple_namespaces,
549 apple_types, apple_objc, m_context.getOrLoadStrData());
550
551 if (m_index)
552 return;
553 }
554
555 DWARFDataExtractor debug_names;
557 if (debug_names.GetByteSize() > 0) {
558 Progress progress("Loading DWARF5 index", module_desc.GetData());
559 llvm::Expected<std::unique_ptr<DebugNamesDWARFIndex>> index_or =
561 debug_names,
562 m_context.getOrLoadStrData(), *this);
563 if (index_or) {
564 m_index = std::move(*index_or);
565 return;
566 }
567 LLDB_LOG_ERROR(log, index_or.takeError(),
568 "Unable to read .debug_names data: {0}");
569 }
570 }
571
572 m_index =
573 std::make_unique<ManualDWARFIndex>(*GetObjectFile()->GetModule(), *this);
574}
575
582
584 const lldb_private::SectionList &section_list) {
585 for (SectionSP section_sp : section_list) {
586 if (section_sp->GetChildren().GetSize() > 0) {
587 InitializeFirstCodeAddressRecursive(section_sp->GetChildren());
588 } else if (section_sp->GetType() == eSectionTypeCode) {
590 std::min(m_first_code_address, section_sp->GetFileAddress());
591 }
592 }
593}
594
595bool SymbolFileDWARF::SupportedVersion(uint16_t version) {
596 return version >= 2 && version <= 5;
597}
598
599static std::set<dw_form_t>
600GetUnsupportedForms(llvm::DWARFDebugAbbrev *debug_abbrev) {
601 if (!debug_abbrev)
602 return {};
603
604 std::set<dw_form_t> unsupported_forms;
605 for (const auto &[_, decl_set] : *debug_abbrev)
606 for (const auto &decl : decl_set)
607 for (const auto &attr : decl.attributes())
608 if (!DWARFFormValue::FormIsSupported(attr.Form))
609 unsupported_forms.insert(attr.Form);
610
611 return unsupported_forms;
612}
613
615 uint32_t abilities = 0;
616 if (m_objfile_sp != nullptr) {
617 const Section *section = nullptr;
618 const SectionList *section_list = m_objfile_sp->GetSectionList();
619 if (section_list == nullptr)
620 return 0;
621
622 uint64_t debug_abbrev_file_size = 0;
623 uint64_t debug_info_file_size = 0;
624 uint64_t debug_line_file_size = 0;
625
626 section = section_list->FindSectionByName(GetDWARFMachOSegmentName()).get();
627
628 if (section)
629 section_list = &section->GetChildren();
630
631 section =
632 section_list->FindSectionByType(eSectionTypeDWARFDebugInfo, true).get();
633 if (section != nullptr) {
634 debug_info_file_size = section->GetFileSize();
635
636 section =
638 .get();
639 if (section)
640 debug_abbrev_file_size = section->GetFileSize();
641
642 llvm::DWARFDebugAbbrev *abbrev = DebugAbbrev();
643 std::set<dw_form_t> unsupported_forms = GetUnsupportedForms(abbrev);
644 if (!unsupported_forms.empty()) {
646 error.Printf("unsupported DW_FORM value%s:",
647 unsupported_forms.size() > 1 ? "s" : "");
648 for (auto form : unsupported_forms)
649 error.Printf(" %#x", form);
650 m_objfile_sp->GetModule()->ReportWarning("{0}", error.GetString());
651 return 0;
652 }
653
654 section =
656 .get();
657 if (section)
658 debug_line_file_size = section->GetFileSize();
659 } else {
660 llvm::StringRef symfile_dir = m_objfile_sp->GetFileSpec().GetDirectory();
661 if (symfile_dir.contains_insensitive(".dsym")) {
662 if (m_objfile_sp->GetType() == ObjectFile::eTypeDebugInfo) {
663 // We have a dSYM file that didn't have a any debug info. If the
664 // string table has a size of 1, then it was made from an
665 // executable with no debug info, or from an executable that was
666 // stripped.
667 section =
669 .get();
670 if (section && section->GetFileSize() == 1) {
671 m_objfile_sp->GetModule()->ReportWarning(
672 "empty dSYM file detected, dSYM was created with an "
673 "executable with no debug info");
674 }
675 }
676 }
677 }
678
679 constexpr uint64_t MaxDebugInfoSize = (1ull) << DW_DIE_OFFSET_MAX_BITSIZE;
680 if (debug_info_file_size >= MaxDebugInfoSize) {
681 m_objfile_sp->GetModule()->ReportWarning(
682 "SymbolFileDWARF can't load this DWARF. It's larger then {0:x+16}",
683 MaxDebugInfoSize);
684 return 0;
685 }
686
687 if (debug_abbrev_file_size > 0 && debug_info_file_size > 0)
688 abilities |= CompileUnits | Functions | Blocks | GlobalVariables |
690
691 if (debug_line_file_size > 0)
692 abilities |= LineTables;
693 }
694 return abilities;
695}
696
698 DWARFDataExtractor &data) {
699 ModuleSP module_sp(m_objfile_sp->GetModule());
700 const SectionList *section_list = module_sp->GetSectionList();
701 if (!section_list)
702 return;
703
704 SectionSP section_sp(section_list->FindSectionByType(sect_type, true));
705 if (!section_sp)
706 return;
707
708 data.Clear();
709 m_objfile_sp->ReadSectionData(section_sp.get(), data);
710}
711
712llvm::DWARFDebugAbbrev *SymbolFileDWARF::DebugAbbrev() {
713 if (m_abbr)
714 return m_abbr.get();
715
716 const DWARFDataExtractor &debug_abbrev_data = m_context.getOrLoadAbbrevData();
717 if (debug_abbrev_data.GetByteSize() == 0)
718 return nullptr;
719
721 auto abbr =
722 std::make_unique<llvm::DWARFDebugAbbrev>(debug_abbrev_data.GetAsLLVM());
723 llvm::Error error = abbr->parse();
724 if (error) {
726 LLDB_LOG_ERROR(log, std::move(error),
727 "Unable to read .debug_abbrev section: {0}");
728 return nullptr;
729 }
730
731 m_abbr = std::move(abbr);
732 return m_abbr.get();
733}
734
736 llvm::call_once(m_info_once_flag, [&] {
738
739 m_info = std::make_unique<DWARFDebugInfo>(*this, m_context);
740 });
741 return *m_info;
742}
743
745 if (!comp_unit)
746 return nullptr;
747
748 // The compile unit ID is the index of the DWARF unit.
749 DWARFUnit *dwarf_cu = DebugInfo().GetUnitAtIndex(comp_unit->GetID());
750 if (dwarf_cu && dwarf_cu->GetLLDBCompUnit() == nullptr)
751 dwarf_cu->SetLLDBCompUnit(comp_unit);
752
753 // It must be DWARFCompileUnit when it created a CompileUnit.
754 return llvm::cast_or_null<DWARFCompileUnit>(dwarf_cu);
755}
756
757/// Make an absolute path out of \p file_spec and remap it using the
758/// module's source remapping dictionary.
759static void MakeAbsoluteAndRemap(FileSpec &file_spec, DWARFUnit &dwarf_cu,
760 const ModuleSP &module_sp) {
761 if (!file_spec)
762 return;
763 // If we have a full path to the compile unit, we don't need to
764 // resolve the file. This can be expensive e.g. when the source
765 // files are NFS mounted.
766 file_spec.MakeAbsolute(dwarf_cu.GetCompilationDirectory());
767
768 if (auto remapped_file = module_sp->RemapSourceFile(file_spec.GetPath()))
769 file_spec.SetFile(*remapped_file, FileSpec::Style::native);
770}
771
772/// Return the DW_AT_(GNU_)dwo_name.
773static const char *GetDWOName(DWARFCompileUnit &dwarf_cu,
774 const DWARFDebugInfoEntry &cu_die) {
775 const char *dwo_name =
776 cu_die.GetAttributeValueAsString(&dwarf_cu, DW_AT_GNU_dwo_name, nullptr);
777 if (!dwo_name)
778 dwo_name =
779 cu_die.GetAttributeValueAsString(&dwarf_cu, DW_AT_dwo_name, nullptr);
780 return dwo_name;
781}
782
784 CompUnitSP cu_sp;
785 CompileUnit *comp_unit = dwarf_cu.GetLLDBCompUnit();
786 if (comp_unit) {
787 // We already parsed this compile unit, had out a shared pointer to it
788 cu_sp = comp_unit->shared_from_this();
789 } else {
790 if (GetDebugMapSymfile()) {
791 // Let the debug map create the compile unit
792 cu_sp = m_debug_map_symfile->GetCompileUnit(this, dwarf_cu);
793 dwarf_cu.SetLLDBCompUnit(cu_sp.get());
794 } else {
795 ModuleSP module_sp(m_objfile_sp->GetModule());
796 if (module_sp) {
797 auto initialize_cu = [&](SupportFileNSP support_file_nsp,
798 LanguageType cu_language,
799 SupportFileList &&support_files = {}) {
801 cu_sp = std::make_shared<CompileUnit>(
802 module_sp, &dwarf_cu, support_file_nsp,
803 *GetDWARFUnitIndex(dwarf_cu.GetID()), cu_language,
804 eLazyBoolCalculate, std::move(support_files));
805
806 dwarf_cu.SetLLDBCompUnit(cu_sp.get());
807
808 SetCompileUnitAtIndex(dwarf_cu.GetID(), cu_sp);
809 };
810
811 auto lazy_initialize_cu = [&]() {
812 // If the version is < 5, we can't do lazy initialization.
813 if (dwarf_cu.GetVersion() < 5)
814 return false;
815
816 // If there is no DWO, there is no reason to initialize
817 // lazily; we will do eager initialization in that case.
818 if (GetDebugMapSymfile())
819 return false;
820 const DWARFBaseDIE cu_die = dwarf_cu.GetUnitDIEOnly();
821 if (!cu_die)
822 return false;
823 if (!GetDWOName(dwarf_cu, *cu_die.GetDIE()))
824 return false;
825
826 // With DWARFv5 we can assume that the first support
827 // file is also the name of the compile unit. This
828 // allows us to avoid loading the non-skeleton unit,
829 // which may be in a separate DWO file.
830 SupportFileList support_files;
831 if (!ParseSupportFiles(dwarf_cu, module_sp, support_files))
832 return false;
833 if (support_files.GetSize() == 0)
834 return false;
835 initialize_cu(support_files.GetSupportFileAtIndex(0),
836 eLanguageTypeUnknown, std::move(support_files));
837 return true;
838 };
839
840 if (!lazy_initialize_cu()) {
841 // Eagerly initialize compile unit
842 const DWARFBaseDIE cu_die =
844 if (cu_die) {
846 dwarf_cu.GetDWARFLanguageType());
847
848 FileSpec cu_file_spec(cu_die.GetName(), dwarf_cu.GetPathStyle());
849
850 // Path needs to be remapped in this case. In the support files
851 // case ParseSupportFiles takes care of the remapping.
852 MakeAbsoluteAndRemap(cu_file_spec, dwarf_cu, module_sp);
853
854 initialize_cu(std::make_shared<SupportFile>(cu_file_spec),
855 cu_language);
856 }
857 }
858 }
859 }
860 }
861 return cu_sp;
862}
863
865 if (!m_lldb_cu_to_dwarf_unit.empty())
866 return;
867
868 DWARFDebugInfo &info = DebugInfo();
869 if (!info.ContainsTypeUnits()) {
870 // We can use a 1-to-1 mapping. No need to build a translation table.
871 return;
872 }
873 for (uint32_t i = 0, num = info.GetNumUnits(); i < num; ++i) {
874 if (auto *cu = llvm::dyn_cast<DWARFCompileUnit>(info.GetUnitAtIndex(i))) {
875 cu->SetID(m_lldb_cu_to_dwarf_unit.size());
876 m_lldb_cu_to_dwarf_unit.push_back(i);
877 }
878 }
879}
880
881std::optional<uint32_t> SymbolFileDWARF::GetDWARFUnitIndex(uint32_t cu_idx) {
883 if (m_lldb_cu_to_dwarf_unit.empty())
884 return cu_idx;
885 if (cu_idx >= m_lldb_cu_to_dwarf_unit.size())
886 return std::nullopt;
887 return m_lldb_cu_to_dwarf_unit[cu_idx];
888}
889
895
897 ASSERT_MODULE_LOCK(this);
898 if (std::optional<uint32_t> dwarf_idx = GetDWARFUnitIndex(cu_idx)) {
899 if (auto *dwarf_cu = llvm::cast_or_null<DWARFCompileUnit>(
900 DebugInfo().GetUnitAtIndex(*dwarf_idx)))
901 return ParseCompileUnit(*dwarf_cu);
902 }
903 return {};
904}
905
907 const DWARFDIE &die) {
908 ASSERT_MODULE_LOCK(this);
910 if (!die.IsValid())
911 return nullptr;
912
913 auto type_system_or_err = GetTypeSystemForLanguage(GetLanguage(*die.GetCU()));
914 if (auto err = type_system_or_err.takeError()) {
915 LLDB_LOG_ERROR(log, std::move(err), "Unable to parse function: {0}");
916 return nullptr;
917 }
918 auto ts = *type_system_or_err;
919 if (!ts)
920 return nullptr;
921 DWARFASTParser *dwarf_ast = ts->GetDWARFParser();
922 if (!dwarf_ast)
923 return nullptr;
924
925 AddressRanges ranges;
926 ModuleSP module_sp(die.GetModule());
927 if (llvm::Expected<llvm::DWARFAddressRangesVector> die_ranges =
928 die.GetDIE()->GetAttributeAddressRanges(die.GetCU(),
929 /*check_hi_lo_pc=*/true)) {
930 for (const auto &range : *die_ranges) {
931 if (range.valid() && range.LowPC < m_first_code_address)
932 continue;
933 // Require the low PC to resolve to a section. This rejects addresses that
934 // don't correspond to any real code, such as the "(dead code)" tombstone
935 // a linker leaves on the DW_AT_low_pc of an eliminated function.
936 if (Address base_addr(range.LowPC, module_sp->GetSectionList());
937 base_addr.IsSectionOffset() && FixupAddress(base_addr))
938 ranges.emplace_back(std::move(base_addr), range.HighPC - range.LowPC);
939 }
940 } else {
941 LLDB_LOG_ERRORV(log, die_ranges.takeError(), "DIE({1:x}): {0}",
942 die.GetID());
943 }
944 if (ranges.empty())
945 return nullptr;
946
947 return dwarf_ast->ParseFunctionFromDWARF(comp_unit, die, std::move(ranges));
948}
949
952 ASSERT_MODULE_LOCK(this);
953 if (!die.IsValid()) {
954 return ConstString();
955 }
956
957 auto type_system_or_err = GetTypeSystemForLanguage(GetLanguage(*die.GetCU()));
958 if (auto err = type_system_or_err.takeError()) {
959 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
960 "Unable to construct demangled name for function: {0}");
961 return ConstString();
962 }
963
964 auto ts = *type_system_or_err;
965 if (!ts) {
966 LLDB_LOG(GetLog(LLDBLog::Symbols), "Type system no longer live");
967 return ConstString();
968 }
969 DWARFASTParser *dwarf_ast = ts->GetDWARFParser();
970 if (!dwarf_ast)
971 return ConstString();
972
973 return dwarf_ast->ConstructDemangledNameFromDWARF(die);
974}
975
977 SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile();
978 if (debug_map_symfile)
979 return debug_map_symfile->LinkOSOFileAddress(this, file_addr);
980 return file_addr;
981}
982
984 SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile();
985 if (debug_map_symfile) {
986 return debug_map_symfile->LinkOSOAddress(addr);
987 }
988 // This is a normal DWARF file, no address fixups need to happen
989 return true;
990}
992 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
993 DWARFUnit *dwarf_cu = GetDWARFCompileUnit(&comp_unit);
994 if (dwarf_cu)
995 return GetLanguage(dwarf_cu->GetNonSkeletonUnit());
996 else
998}
999
1001 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1002 DWARFUnit *dwarf_cu = GetDWARFCompileUnit(&comp_unit);
1003 if (!dwarf_cu)
1004 return {};
1005 const DWARFBaseDIE cu_die = dwarf_cu->GetNonSkeletonUnit().GetUnitDIEOnly();
1006 if (!cu_die)
1007 return {};
1008 const char *sdk = cu_die.GetAttributeValueAsString(DW_AT_APPLE_sdk, nullptr);
1009 if (!sdk)
1010 return {};
1011 llvm::StringRef sysroot =
1012 cu_die.GetAttributeValueAsString(DW_AT_LLVM_sysroot, "");
1013
1014 // RegisterXcodeSDK calls into xcrun which is not aware of CLT, which is
1015 // expensive.
1016 if (!sysroot.starts_with("/Library/Developer/CommandLineTools/SDKs")) {
1017 // Register the sysroot path remapping with the module belonging to
1018 // the CU as well as the one belonging to the symbol file. The two
1019 // would be different if this is an OSO object and module is the
1020 // corresponding debug map, in which case both should be updated.
1021 ModuleSP module_sp = comp_unit.GetModule();
1022 if (module_sp)
1023 module_sp->RegisterXcodeSDK(sdk, sysroot);
1024
1025 ModuleSP local_module_sp = m_objfile_sp->GetModule();
1026 if (local_module_sp && local_module_sp != module_sp)
1027 local_module_sp->RegisterXcodeSDK(sdk, sysroot);
1028 }
1029
1030 return {sdk, FileSpec(sysroot)};
1031}
1032
1035 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1036 DWARFUnit *dwarf_cu = GetDWARFCompileUnit(&comp_unit);
1037 if (!dwarf_cu)
1038 return 0;
1039
1040 size_t functions_added = 0;
1041 dwarf_cu = &dwarf_cu->GetNonSkeletonUnit();
1042 for (DWARFDebugInfoEntry &entry : dwarf_cu->dies()) {
1043 if (entry.Tag() != DW_TAG_subprogram)
1044 continue;
1045
1046 DWARFDIE die(dwarf_cu, &entry);
1047 if (comp_unit.FindFunctionByUID(die.GetID()))
1048 continue;
1049 if (ParseFunction(comp_unit, die))
1050 ++functions_added;
1051 }
1052 // FixupTypes();
1053 return functions_added;
1054}
1055
1057 CompileUnit &comp_unit,
1058 llvm::DenseSet<lldb_private::SymbolFile *> &visited_symbol_files,
1059 llvm::function_ref<bool(Module &)> lambda) {
1060 // Only visit each symbol file once.
1061 if (!visited_symbol_files.insert(this).second)
1062 return false;
1063
1065 for (auto &p : m_external_type_modules) {
1066 ModuleSP module = p.second;
1067 if (!module)
1068 continue;
1069
1070 // Invoke the action and potentially early-exit.
1071 if (lambda(*module))
1072 return true;
1073
1074 for (std::size_t i = 0; i < module->GetNumCompileUnits(); ++i) {
1075 auto cu = module->GetCompileUnitAtIndex(i);
1076 bool early_exit = cu->ForEachExternalModule(visited_symbol_files, lambda);
1077 if (early_exit)
1078 return true;
1079 }
1080 }
1081 return false;
1082}
1083
1085 SupportFileList &support_files) {
1086 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1087 DWARFUnit *dwarf_cu = GetDWARFCompileUnit(&comp_unit);
1088 if (!dwarf_cu)
1089 return false;
1090
1091 if (!ParseSupportFiles(*dwarf_cu, comp_unit.GetModule(), support_files))
1092 return false;
1093
1094 return true;
1095}
1096
1098 const ModuleSP &module,
1099 SupportFileList &support_files) {
1100
1101 dw_offset_t offset = dwarf_cu.GetLineTableOffset();
1102 if (offset == DW_INVALID_OFFSET)
1103 return false;
1104
1106 llvm::DWARFDebugLine::Prologue prologue;
1107 if (!ParseLLVMLineTablePrologue(m_context, prologue, offset,
1108 dwarf_cu.GetOffset()))
1109 return false;
1110
1111 std::string comp_dir = dwarf_cu.GetCompilationDirectory().GetPath();
1112 ParseSupportFilesFromPrologue(support_files, module, prologue,
1113 dwarf_cu.GetPathStyle(), comp_dir);
1114 return true;
1115}
1116
1118 if (auto *dwarf_cu = llvm::dyn_cast<DWARFCompileUnit>(&unit)) {
1119 if (CompileUnit *lldb_cu = GetCompUnitForDWARFCompUnit(*dwarf_cu))
1120 return lldb_cu->GetSupportFiles().GetFileSpecAtIndex(file_idx);
1121 return FileSpec();
1122 }
1123
1124 auto &tu = llvm::cast<DWARFTypeUnit>(unit);
1125 if (const SupportFileList *support_files = GetTypeUnitSupportFiles(tu))
1126 return support_files->GetFileSpecAtIndex(file_idx);
1127 return {};
1128}
1129
1130const SupportFileList *
1132 static SupportFileList empty_list;
1133
1134 dw_offset_t offset = tu.GetLineTableOffset();
1135 if (offset == DW_INVALID_OFFSET)
1136 return nullptr;
1137
1138 // Many type units can share a line table, so parse the support file list
1139 // once, and cache it based on the offset field.
1140 auto iter_bool = m_type_unit_support_files.try_emplace(offset);
1141 std::unique_ptr<SupportFileList> &list = iter_bool.first->second;
1142 if (iter_bool.second) {
1143 list = std::make_unique<SupportFileList>();
1144 uint64_t line_table_offset = offset;
1145 llvm::DWARFDataExtractor data =
1146 m_context.getOrLoadLineData().GetAsLLVMDWARF();
1147 llvm::DWARFContext &ctx = m_context.GetAsLLVM();
1148 llvm::DWARFDebugLine::Prologue prologue;
1149 auto report = [](llvm::Error error) {
1151 LLDB_LOG_ERROR(log, std::move(error),
1152 "SymbolFileDWARF::GetTypeUnitSupportFiles failed to parse "
1153 "the line table prologue: {0}");
1154 };
1156 llvm::Error error = prologue.parse(data, &line_table_offset, report, ctx);
1157 if (error)
1158 report(std::move(error));
1159 else
1160 ParseSupportFilesFromPrologue(*list, GetObjectFile()->GetModule(),
1161 prologue, tu.GetPathStyle());
1162 }
1163 return list.get();
1164}
1165
1167 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1168 DWARFUnit *dwarf_cu = GetDWARFCompileUnit(&comp_unit);
1169 if (dwarf_cu)
1170 return dwarf_cu->GetNonSkeletonUnit().GetIsOptimized();
1171 return false;
1172}
1173
1176 std::vector<SourceModule> &imported_modules) {
1177 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1178 assert(sc.comp_unit);
1179 DWARFUnit *dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
1180 if (!dwarf_cu)
1181 return false;
1183 sc.comp_unit->GetLanguage()))
1184 return false;
1186
1187 const DWARFDIE die = dwarf_cu->DIE();
1188 if (!die)
1189 return false;
1190
1191 for (DWARFDIE child_die : die.children()) {
1192 if (child_die.Tag() != DW_TAG_imported_declaration)
1193 continue;
1194
1195 DWARFDIE module_die = child_die.GetReferencedDIE(DW_AT_import);
1196 if (module_die.Tag() != DW_TAG_module)
1197 continue;
1198
1199 if (const char *name =
1200 module_die.GetAttributeValueAsString(DW_AT_name, nullptr)) {
1201 SourceModule module;
1202 module.path.push_back(ConstString(name));
1203
1204 const char *include_path = module_die.GetAttributeValueAsString(
1205 DW_AT_LLVM_include_path, nullptr);
1206 DWARFDIE parent_die = module_die;
1207 while ((parent_die = parent_die.GetParent())) {
1208 if (parent_die.Tag() != DW_TAG_module)
1209 break;
1210 if (const char *name =
1211 parent_die.GetAttributeValueAsString(DW_AT_name, nullptr))
1212 module.path.push_back(ConstString(name));
1213
1214 // Inferred submodule declarations may not have a
1215 // DW_AT_LLVM_include_path. Pick the parent (aka umbrella) module's
1216 // include path instead.
1217 if (!include_path)
1218 include_path = parent_die.GetAttributeValueAsString(
1219 DW_AT_LLVM_include_path, nullptr);
1220 }
1221 std::reverse(module.path.begin(), module.path.end());
1222 if (include_path) {
1223 FileSpec include_spec(include_path, dwarf_cu->GetPathStyle());
1224 MakeAbsoluteAndRemap(include_spec, *dwarf_cu,
1225 m_objfile_sp->GetModule());
1226 module.search_path = ConstString(include_spec.GetPath());
1227 }
1228 if (const char *sysroot = dwarf_cu->DIE().GetAttributeValueAsString(
1229 DW_AT_LLVM_sysroot, nullptr))
1230 module.sysroot = ConstString(sysroot);
1231 imported_modules.push_back(module);
1232 }
1233 }
1234 return true;
1235}
1236
1238 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1239 if (comp_unit.GetLineTable() != nullptr)
1240 return true;
1241
1242 DWARFUnit *dwarf_cu = GetDWARFCompileUnit(&comp_unit);
1243 if (!dwarf_cu)
1244 return false;
1245
1246 dw_offset_t offset = dwarf_cu->GetLineTableOffset();
1247 if (offset == DW_INVALID_OFFSET)
1248 return false;
1249
1251 llvm::DWARFDebugLine line;
1252 const llvm::DWARFDebugLine::LineTable *line_table =
1253 ParseLLVMLineTable(m_context, line, offset, dwarf_cu->GetOffset());
1254
1255 if (!line_table)
1256 return false;
1257
1258 // FIXME: Rather than parsing the whole line table and then copying it over
1259 // into LLDB, we should explore using a callback to populate the line table
1260 // while we parse to reduce memory usage.
1261 std::vector<LineTable::Sequence> sequences;
1262 // The Sequences view contains only valid line sequences. Don't iterate over
1263 // the Rows directly.
1264 for (const llvm::DWARFDebugLine::Sequence &seq : line_table->Sequences) {
1265 // Ignore line sequences that do not start after the first code address.
1266 // All addresses generated in a sequence are incremental so we only need
1267 // to check the first one of the sequence. Check the comment at the
1268 // m_first_code_address declaration for more details on this.
1269 if (seq.LowPC < m_first_code_address)
1270 continue;
1271 LineTable::Sequence sequence;
1272 for (unsigned idx = seq.FirstRowIndex; idx < seq.LastRowIndex; ++idx) {
1273 const llvm::DWARFDebugLine::Row &row = line_table->Rows[idx];
1275 sequence, row.Address.Address, row.Line, row.Column, row.File,
1276 row.IsStmt, row.BasicBlock, row.PrologueEnd, row.EpilogueBegin,
1277 row.EndSequence);
1278 }
1279 sequences.push_back(std::move(sequence));
1280 }
1281
1282 std::unique_ptr<LineTable> line_table_up =
1283 std::make_unique<LineTable>(&comp_unit, std::move(sequences));
1284
1285 if (SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile()) {
1286 // We have an object file that has a line table with addresses that are not
1287 // linked. We need to link the line table and convert the addresses that
1288 // are relative to the .o file into addresses for the main executable.
1289 comp_unit.SetLineTable(
1290 debug_map_symfile->LinkOSOLineTable(this, line_table_up.get()));
1291 } else {
1292 comp_unit.SetLineTable(line_table_up.release());
1293 }
1294
1295 return true;
1296}
1297
1300 auto iter = m_debug_macros_map.find(*offset);
1301 if (iter != m_debug_macros_map.end())
1302 return iter->second;
1303
1305 const DWARFDataExtractor &debug_macro_data = m_context.getOrLoadMacroData();
1306 if (debug_macro_data.GetByteSize() == 0)
1307 return DebugMacrosSP();
1308
1310 m_debug_macros_map[*offset] = debug_macros_sp;
1311
1312 const DWARFDebugMacroHeader &header =
1313 DWARFDebugMacroHeader::ParseHeader(debug_macro_data, offset);
1315 debug_macro_data, m_context.getOrLoadStrData(), header.OffsetIs64Bit(),
1316 offset, this, debug_macros_sp);
1317
1318 return debug_macros_sp;
1319}
1320
1322 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1323
1324 DWARFUnit *dwarf_cu = GetDWARFCompileUnit(&comp_unit);
1325 if (dwarf_cu == nullptr)
1326 return false;
1327
1328 const DWARFBaseDIE dwarf_cu_die = dwarf_cu->GetUnitDIEOnly();
1329 if (!dwarf_cu_die)
1330 return false;
1331
1332 lldb::offset_t sect_offset =
1333 dwarf_cu_die.GetAttributeValueAsUnsigned(DW_AT_macros, DW_INVALID_OFFSET);
1334 if (sect_offset == DW_INVALID_OFFSET)
1335 sect_offset = dwarf_cu_die.GetAttributeValueAsUnsigned(DW_AT_GNU_macros,
1337 if (sect_offset == DW_INVALID_OFFSET)
1338 return false;
1339
1340 comp_unit.SetDebugMacros(ParseDebugMacros(&sect_offset));
1341
1342 return true;
1343}
1344
1346 Block *parent_block, DWARFDIE die,
1347 addr_t function_file_addr) {
1348 size_t blocks_added = 0;
1349 for (; die; die = die.GetSibling()) {
1350 dw_tag_t tag = die.Tag();
1351
1352 if (tag != DW_TAG_inlined_subroutine && tag != DW_TAG_lexical_block)
1353 continue;
1354
1355 Block *block = parent_block->CreateChild(die.GetID()).get();
1356 llvm::DWARFAddressRangesVector ranges;
1357 const char *name = nullptr;
1358 const char *mangled_name = nullptr;
1359
1360 std::optional<int> decl_file;
1361 std::optional<int> decl_line;
1362 std::optional<int> decl_column;
1363 std::optional<int> call_file;
1364 std::optional<int> call_line;
1365 std::optional<int> call_column;
1366 if (die.GetDIENamesAndRanges(name, mangled_name, ranges, decl_file,
1367 decl_line, decl_column, call_file, call_line,
1368 call_column, nullptr)) {
1369 for (const llvm::DWARFAddressRange &range : ranges) {
1370 if (range.valid() && range.LowPC >= m_first_code_address)
1371 block->AddRange(Block::Range(range.LowPC - function_file_addr,
1372 range.HighPC - range.LowPC));
1373 }
1374 block->FinalizeRanges();
1375
1376 if (tag != DW_TAG_subprogram &&
1377 (name != nullptr || mangled_name != nullptr)) {
1378 std::unique_ptr<Declaration> decl_up;
1379 if (decl_file || decl_line || decl_column)
1380 decl_up = std::make_unique<Declaration>(
1382 decl_file.value_or(0)),
1383 decl_line.value_or(0), decl_column.value_or(0));
1384
1385 std::unique_ptr<Declaration> call_up;
1386 if (call_file || call_line || call_column)
1387 call_up = std::make_unique<Declaration>(
1389 call_file.value_or(0)),
1390 call_line.value_or(0), call_column.value_or(0));
1391
1392 block->SetInlinedFunctionInfo(name, mangled_name, decl_up.get(),
1393 call_up.get());
1394 }
1395
1396 ++blocks_added;
1397
1398 if (die.HasChildren()) {
1399 blocks_added += ParseBlocksRecursive(
1400 comp_unit, block, die.GetFirstChild(), function_file_addr);
1401 }
1402 }
1403 }
1404 return blocks_added;
1405}
1406
1408 if (parent_die) {
1409 for (DWARFDIE die : parent_die.children()) {
1410 dw_tag_t tag = die.Tag();
1411 bool check_virtuality = false;
1412 switch (tag) {
1413 case DW_TAG_inheritance:
1414 case DW_TAG_subprogram:
1415 check_virtuality = true;
1416 break;
1417 default:
1418 break;
1419 }
1420 if (check_virtuality) {
1421 if (die.GetAttributeValueAsUnsigned(DW_AT_virtuality, 0) != 0)
1422 return true;
1423 }
1424 }
1425 }
1426 return false;
1427}
1428
1430 auto *type_system = decl_ctx.GetTypeSystem();
1431 if (type_system != nullptr)
1433 decl_ctx);
1434}
1435
1438
1440 // This method can be called without going through the symbol vendor so we
1441 // need to lock the module.
1442 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1443 // Anytime we have a lldb::user_id_t, we must get the DIE by calling
1444 // SymbolFileDWARF::GetDIE(). See comments inside the
1445 // SymbolFileDWARF::GetDIE() for details.
1446 if (DWARFDIE die = GetDIE(type_uid))
1447 return GetDecl(die);
1448 return CompilerDecl();
1449}
1450
1453 // This method can be called without going through the symbol vendor so we
1454 // need to lock the module.
1455 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1456 // Anytime we have a lldb::user_id_t, we must get the DIE by calling
1457 // SymbolFileDWARF::GetDIE(). See comments inside the
1458 // SymbolFileDWARF::GetDIE() for details.
1459 if (DWARFDIE die = GetDIE(type_uid))
1460 return GetDeclContext(die);
1461 return CompilerDeclContext();
1462}
1463
1466 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1467 // Anytime we have a lldb::user_id_t, we must get the DIE by calling
1468 // SymbolFileDWARF::GetDIE(). See comments inside the
1469 // SymbolFileDWARF::GetDIE() for details.
1470 if (DWARFDIE die = GetDIE(type_uid))
1471 return GetContainingDeclContext(die);
1472 return CompilerDeclContext();
1473}
1474
1475std::vector<CompilerContext>
1477 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1478 // Anytime we have a lldb::user_id_t, we must get the DIE by calling
1479 // SymbolFileDWARF::GetDIE(). See comments inside the
1480 // SymbolFileDWARF::GetDIE() for details.
1481 if (DWARFDIE die = GetDIE(type_uid))
1482 return die.GetDeclContext();
1483 return {};
1484}
1485
1487 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1488 // Anytime we have a lldb::user_id_t, we must get the DIE by calling
1489 // SymbolFileDWARF::GetDIE(). See comments inside the
1490 // SymbolFileDWARF::GetDIE() for details.
1491 if (DWARFDIE type_die = GetDIE(type_uid))
1492 return type_die.ResolveType();
1493 else
1494 return nullptr;
1495}
1496
1497std::optional<SymbolFile::ArrayInfo> SymbolFileDWARF::GetDynamicArrayInfoForUID(
1498 lldb::user_id_t type_uid, const lldb_private::ExecutionContext *exe_ctx) {
1499 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1500 if (DWARFDIE type_die = GetDIE(type_uid))
1501 return DWARFASTParser::ParseChildArrayInfo(type_die, exe_ctx);
1502 else
1503 return std::nullopt;
1504}
1505
1507 return ResolveType(GetDIE(die_ref), true);
1508}
1509
1511 bool assert_not_being_parsed) {
1512 if (die) {
1514 if (log)
1515 GetObjectFile()->GetModule()->LogMessage(
1516 log,
1517 "SymbolFileDWARF::ResolveTypeUID (die = {0:x16}) {1} ({2}) '{3}'",
1518 die.GetOffset(), DW_TAG_value_to_name(die.Tag()), die.Tag(),
1519 die.GetName());
1520
1521 // We might be coming in in the middle of a type tree (a class within a
1522 // class, an enum within a class), so parse any needed parent DIEs before
1523 // we get to this one...
1524 DWARFDIE decl_ctx_die = GetDeclContextDIEContainingDIE(die);
1525 if (decl_ctx_die) {
1526 if (log) {
1527 switch (decl_ctx_die.Tag()) {
1528 case DW_TAG_structure_type:
1529 case DW_TAG_union_type:
1530 case DW_TAG_class_type: {
1531 // Get the type, which could be a forward declaration
1532 if (log)
1533 GetObjectFile()->GetModule()->LogMessage(
1534 log,
1535 "SymbolFileDWARF::ResolveTypeUID (die = {0:x16}) {1} ({2}) "
1536 "'{3}' resolve parent forward type for {4:x16})",
1537 die.GetOffset(), DW_TAG_value_to_name(die.Tag()), die.Tag(),
1538 die.GetName(), decl_ctx_die.GetOffset());
1539 } break;
1540
1541 default:
1542 break;
1543 }
1544 }
1545 }
1546 return ResolveType(die);
1547 }
1548 return nullptr;
1549}
1550
1551// This function is used when SymbolFileDWARFDebugMap owns a bunch of
1552// SymbolFileDWARF objects to detect if this DWARF file is the one that can
1553// resolve a compiler_type.
1555 const CompilerType &compiler_type) {
1556 CompilerType compiler_type_no_qualifiers =
1557 ClangUtil::RemoveFastQualifiers(compiler_type);
1559 compiler_type_no_qualifiers.GetOpaqueQualType())) {
1560 return true;
1561 }
1562 auto clang_type_system = compiler_type.GetTypeSystem<TypeSystemClang>();
1563 if (!clang_type_system)
1564 return false;
1565 auto *ast_parser =
1566 llvm::cast<DWARFASTParserClang>(clang_type_system->GetDWARFParser());
1567 return ast_parser->GetClangASTImporter().CanImport(compiler_type);
1568}
1569
1571 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1572 auto clang_type_system = compiler_type.GetTypeSystem<TypeSystemClang>();
1573 if (clang_type_system) {
1574 auto *ast_parser =
1575 llvm::cast<DWARFASTParserClang>(clang_type_system->GetDWARFParser());
1576 if (ast_parser &&
1577 ast_parser->GetClangASTImporter().CanImport(compiler_type))
1578 return ast_parser->GetClangASTImporter().CompleteType(compiler_type);
1579 }
1580
1581 // We have a struct/union/class/enum that needs to be fully resolved.
1582 CompilerType compiler_type_no_qualifiers =
1583 ClangUtil::RemoveFastQualifiers(compiler_type);
1584 auto die_it = GetForwardDeclCompilerTypeToDIE().find(
1585 compiler_type_no_qualifiers.GetOpaqueQualType());
1586 if (die_it == GetForwardDeclCompilerTypeToDIE().end()) {
1587 // We have already resolved this type...
1588 return true;
1589 }
1590
1591 DWARFDIE decl_die = GetDIE(die_it->getSecond());
1592 // Once we start resolving this type, remove it from the forward
1593 // declaration map in case anyone's child members or other types require this
1594 // type to get resolved.
1595 GetForwardDeclCompilerTypeToDIE().erase(die_it);
1596 DWARFDIE def_die = FindDefinitionDIE(decl_die);
1597 if (!def_die) {
1598 SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile();
1599 if (debug_map_symfile) {
1600 // We weren't able to find a full declaration in this DWARF, see
1601 // if we have a declaration anywhere else...
1602 def_die = debug_map_symfile->FindDefinitionDIE(decl_die);
1603 }
1604 }
1605 if (!def_die) {
1606 // If we don't have definition DIE, CompleteTypeFromDWARF will forcefully
1607 // complete this type.
1608 def_die = decl_die;
1609 }
1610
1611 DWARFASTParser *dwarf_ast = GetDWARFParser(*def_die.GetCU());
1612 if (!dwarf_ast)
1613 return false;
1614 Type *type = GetDIEToType().lookup(decl_die.GetDIE());
1615 assert(type);
1616
1617 if (decl_die != def_die) {
1618 GetDIEToType()[def_die.GetDIE()] = type;
1619 auto *ast_parser = llvm::cast<DWARFASTParserClang>(dwarf_ast);
1620 ast_parser->MapDeclDIEToDefDIE(decl_die, def_die);
1621 }
1622
1624 if (log)
1625 GetObjectFile()->GetModule()->LogMessageVerboseBacktrace(
1626 log, "{0:x8}: {1} ({2}) '{3}' resolving forward declaration...",
1627 def_die.GetID(), DW_TAG_value_to_name(def_die.Tag()), def_die.Tag(),
1628 type->GetName().GetStringRef());
1629 assert(compiler_type);
1630 return dwarf_ast->CompleteTypeFromDWARF(def_die, type, compiler_type);
1631}
1632
1634 bool assert_not_being_parsed,
1635 bool resolve_function_context) {
1636 if (die) {
1637 Type *type = GetTypeForDIE(die, resolve_function_context).get();
1638
1639 if (assert_not_being_parsed) {
1640 if (type != DIE_IS_BEING_PARSED)
1641 return type;
1642
1643 GetObjectFile()->GetModule()->ReportError(
1644 "Parsing a die that is being parsed die: {0:x16}: {1} ({2}) {3}",
1645 die.GetOffset(), DW_TAG_value_to_name(die.Tag()), die.Tag(),
1646 die.GetName());
1647
1648 } else
1649 return type;
1650 }
1651 return nullptr;
1652}
1653
1656
1657 if (dwarf_cu.IsDWOUnit()) {
1658 DWARFCompileUnit *non_dwo_cu = dwarf_cu.GetSkeletonUnit();
1659 assert(non_dwo_cu);
1661 *non_dwo_cu);
1662 }
1663 // Check if the symbol vendor already knows about this compile unit?
1664 CompileUnit *lldb_cu = dwarf_cu.GetLLDBCompUnit();
1665 if (lldb_cu)
1666 return lldb_cu;
1667 // The symbol vendor doesn't know about this compile unit, we need to parse
1668 // and add it to the symbol vendor object.
1669 return ParseCompileUnit(dwarf_cu).get();
1670}
1671
1673 ConstString class_name,
1674 llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
1675 m_index->GetObjCMethods(class_name, callback);
1676}
1677
1679 sc.Clear(false);
1680
1681 if (die && llvm::isa<DWARFCompileUnit>(die.GetCU())) {
1682 // Check if the symbol vendor already knows about this compile unit?
1683 sc.comp_unit =
1684 GetCompUnitForDWARFCompUnit(llvm::cast<DWARFCompileUnit>(*die.GetCU()));
1685
1686 sc.function = sc.comp_unit->FindFunctionByUID(die.GetID()).get();
1687 if (sc.function == nullptr)
1688 sc.function = ParseFunction(*sc.comp_unit, die);
1689
1690 if (sc.function) {
1692 return true;
1693 }
1694 }
1695
1696 return false;
1697}
1698
1701 const auto &pos = m_external_type_modules.find(name);
1702 if (pos == m_external_type_modules.end())
1703 return lldb::ModuleSP();
1704 return pos->second;
1705}
1706
1708 // Anytime we get a "lldb::user_id_t" from an lldb_private::SymbolFile API we
1709 // must make sure we use the correct DWARF file when resolving things. On
1710 // MacOSX, when using SymbolFileDWARFDebugMap, we will use multiple
1711 // SymbolFileDWARF classes, one for each .o file. We can often end up with
1712 // references to other DWARF objects and we must be ready to receive a
1713 // "lldb::user_id_t" that specifies a DIE from another SymbolFileDWARF
1714 // instance.
1715
1716 std::optional<uint32_t> file_index = die_ref.file_index();
1717
1718 // If the file index matches, then we have the right SymbolFileDWARF already.
1719 // This will work for both .dwo file and DWARF in .o files for mac. Also if
1720 // both the file indexes are invalid, then we have a match.
1721 if (GetFileIndex() == file_index)
1722 return this;
1723
1724 if (file_index) {
1725 // We have a SymbolFileDWARFDebugMap, so let it find the right file
1727 return debug_map->GetSymbolFileByOSOIndex(*file_index);
1728
1729 // Handle the .dwp file case correctly
1730 if (*file_index == DIERef::k_file_index_mask)
1731 return GetDwpSymbolFile().get(); // DWP case
1732
1733 // Handle the .dwo file case correctly
1734 return DebugInfo().GetUnitAtIndex(*die_ref.file_index())
1735 ->GetDwoSymbolFile(); // DWO case
1736 }
1737 return this;
1738}
1739
1742 if (die_ref.die_offset() == DW_INVALID_OFFSET)
1743 return DWARFDIE();
1744
1745 // This method can be called without going through the symbol vendor so we
1746 // need to lock the module.
1747 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1748 SymbolFileDWARF *symbol_file = GetDIERefSymbolFile(die_ref);
1749 if (symbol_file)
1750 return symbol_file->DebugInfo().GetDIE(die_ref.section(),
1751 die_ref.die_offset());
1752 return DWARFDIE();
1753}
1754
1755/// Return the DW_AT_(GNU_)dwo_id.
1756static std::optional<uint64_t> GetDWOId(DWARFCompileUnit &dwarf_cu,
1757 const DWARFDebugInfoEntry &cu_die) {
1758 std::optional<uint64_t> dwo_id =
1759 cu_die.GetAttributeValueAsOptionalUnsigned(&dwarf_cu, DW_AT_GNU_dwo_id);
1760 if (dwo_id)
1761 return dwo_id;
1762 return cu_die.GetAttributeValueAsOptionalUnsigned(&dwarf_cu, DW_AT_dwo_id);
1763}
1764
1765std::optional<uint64_t> SymbolFileDWARF::GetDWOId() {
1766 if (GetNumCompileUnits() == 1) {
1767 if (auto comp_unit = GetCompileUnitAtIndex(0))
1768 if (DWARFCompileUnit *cu = GetDWARFCompileUnit(comp_unit.get()))
1769 if (DWARFDebugInfoEntry *cu_die = cu->DIE().GetDIE())
1770 return ::GetDWOId(*cu, *cu_die);
1771 }
1772 return {};
1773}
1774
1778
1779std::shared_ptr<SymbolFileDWARFDwo>
1781 DWARFUnit &unit, const DWARFDebugInfoEntry &cu_die) {
1782 // If this is a Darwin-style debug map (non-.dSYM) symbol file,
1783 // never attempt to load ELF-style DWO files since the -gmodules
1784 // support uses the same DWO mechanism to specify full debug info
1785 // files for modules. This is handled in
1786 // UpdateExternalModuleListIfNeeded().
1787 if (GetDebugMapSymfile())
1788 return nullptr;
1789
1790 DWARFCompileUnit *dwarf_cu = llvm::dyn_cast<DWARFCompileUnit>(&unit);
1791 // Only compile units can be split into two parts and we should only
1792 // look for a DWO file if there is a valid DWO ID.
1793 if (!dwarf_cu || !dwarf_cu->GetDWOId().has_value())
1794 return nullptr;
1795
1796 const char *dwo_name = GetDWOName(*dwarf_cu, cu_die);
1797 if (!dwo_name) {
1799 "missing DWO name in skeleton DIE {0:x16}", cu_die.GetOffset()));
1800 return nullptr;
1801 }
1802
1803 if (std::shared_ptr<SymbolFileDWARFDwo> dwp_sp = GetDwpSymbolFile())
1804 return dwp_sp;
1805
1806 FileSpec dwo_file(dwo_name);
1807 FileSystem::Instance().Resolve(dwo_file);
1808 bool found = false;
1809
1810 const FileSpecList &debug_file_search_paths =
1812 size_t num_search_paths = debug_file_search_paths.GetSize();
1813
1814 // It's relative, e.g. "foo.dwo", but we just to happen to be right next to
1815 // it. Or it's absolute.
1816 found = FileSystem::Instance().Exists(dwo_file);
1817
1818 const char *comp_dir =
1819 cu_die.GetAttributeValueAsString(dwarf_cu, DW_AT_comp_dir, nullptr);
1820 if (!found) {
1821 // It could be a relative path that also uses DW_AT_COMP_DIR.
1822 if (comp_dir) {
1823 dwo_file.SetFile(comp_dir, FileSpec::Style::native);
1824 if (!dwo_file.IsRelative()) {
1825 FileSystem::Instance().Resolve(dwo_file);
1826 dwo_file.AppendPathComponent(dwo_name);
1827 found = FileSystem::Instance().Exists(dwo_file);
1828 } else {
1829 FileSpecList dwo_paths;
1830
1831 // if DW_AT_comp_dir is relative, it should be relative to the location
1832 // of the executable, not to the location from which the debugger was
1833 // launched.
1834 FileSpec relative_to_binary = dwo_file;
1835 relative_to_binary.PrependPathComponent(
1836 m_objfile_sp->GetFileSpec().GetDirectory());
1837 FileSystem::Instance().Resolve(relative_to_binary);
1838 relative_to_binary.AppendPathComponent(dwo_name);
1839 dwo_paths.Append(relative_to_binary);
1840
1841 // Or it's relative to one of the user specified debug directories.
1842 for (size_t idx = 0; idx < num_search_paths; ++idx) {
1843 FileSpec dirspec = debug_file_search_paths.GetFileSpecAtIndex(idx);
1844 dirspec.AppendPathComponent(comp_dir);
1845 FileSystem::Instance().Resolve(dirspec);
1846 if (!FileSystem::Instance().IsDirectory(dirspec))
1847 continue;
1848
1849 dirspec.AppendPathComponent(dwo_name);
1850 dwo_paths.Append(dirspec);
1851 }
1852
1853 size_t num_possible = dwo_paths.GetSize();
1854 for (size_t idx = 0; idx < num_possible && !found; ++idx) {
1855 FileSpec dwo_spec = dwo_paths.GetFileSpecAtIndex(idx);
1856 if (FileSystem::Instance().Exists(dwo_spec)) {
1857 dwo_file = dwo_spec;
1858 found = true;
1859 }
1860 }
1861 }
1862 } else {
1863 Log *log = GetLog(LLDBLog::Symbols);
1864 LLDB_LOGF(log,
1865 "unable to locate relative .dwo debug file \"%s\" for "
1866 "skeleton DIE 0x%016" PRIx64 " without valid DW_AT_comp_dir "
1867 "attribute",
1868 dwo_name, cu_die.GetOffset());
1869 }
1870 }
1871
1872 if (!found) {
1873 // Try adding the DW_AT_dwo_name ( e.g. "c/d/main-main.dwo"), and just the
1874 // filename ("main-main.dwo") to binary dir and search paths.
1875 FileSpecList dwo_paths;
1876 FileSpec dwo_name_spec(dwo_name);
1877 llvm::StringRef filename_only = dwo_name_spec.GetFilename();
1878
1879 FileSpec binary_directory(m_objfile_sp->GetFileSpec().GetDirectory());
1880 FileSystem::Instance().Resolve(binary_directory);
1881
1882 if (dwo_name_spec.IsRelative()) {
1883 FileSpec dwo_name_binary_directory(binary_directory);
1884 dwo_name_binary_directory.AppendPathComponent(dwo_name);
1885 dwo_paths.Append(dwo_name_binary_directory);
1886 }
1887
1888 FileSpec filename_binary_directory(binary_directory);
1889 filename_binary_directory.AppendPathComponent(filename_only);
1890 dwo_paths.Append(filename_binary_directory);
1891
1892 for (size_t idx = 0; idx < num_search_paths; ++idx) {
1893 FileSpec dirspec = debug_file_search_paths.GetFileSpecAtIndex(idx);
1894 FileSystem::Instance().Resolve(dirspec);
1895 if (!FileSystem::Instance().IsDirectory(dirspec))
1896 continue;
1897
1898 FileSpec dwo_name_dirspec(dirspec);
1899 dwo_name_dirspec.AppendPathComponent(dwo_name);
1900 dwo_paths.Append(dwo_name_dirspec);
1901
1902 FileSpec filename_dirspec(dirspec);
1903 filename_dirspec.AppendPathComponent(filename_only);
1904 dwo_paths.Append(filename_dirspec);
1905 }
1906
1907 size_t num_possible = dwo_paths.GetSize();
1908 for (size_t idx = 0; idx < num_possible && !found; ++idx) {
1909 FileSpec dwo_spec = dwo_paths.GetFileSpecAtIndex(idx);
1910 if (FileSystem::Instance().Exists(dwo_spec)) {
1911 dwo_file = dwo_spec;
1912 found = true;
1913 }
1914 }
1915 }
1916
1917 if (!found) {
1918 FileSpec error_dwo_path(dwo_name);
1919 FileSystem::Instance().Resolve(error_dwo_path);
1920 if (error_dwo_path.IsRelative() && comp_dir != nullptr) {
1921 error_dwo_path.PrependPathComponent(comp_dir);
1922 FileSystem::Instance().Resolve(error_dwo_path);
1923 }
1925 "unable to locate .dwo debug file \"{0}\" for skeleton DIE "
1926 "{1:x16}. {2}",
1927 error_dwo_path.GetPath().c_str(), cu_die.GetOffset(),
1929
1930 if (m_dwo_warning_issued.test_and_set(std::memory_order_relaxed) == false) {
1931 GetObjectFile()->GetModule()->ReportWarning(
1932 "unable to locate separate debug file (dwo, dwp). {0}",
1934 }
1935 return nullptr;
1936 }
1937
1938 const lldb::offset_t file_offset = 0;
1939 DataExtractorSP dwo_file_extractor_sp;
1940 lldb::offset_t dwo_file_data_offset = 0;
1941 ObjectFileSP dwo_obj_file = ObjectFile::FindPlugin(
1942 GetObjectFile()->GetModule(), &dwo_file, file_offset,
1943 FileSystem::Instance().GetByteSize(dwo_file), dwo_file_extractor_sp,
1944 dwo_file_data_offset);
1945 if (dwo_obj_file == nullptr) {
1947 "unable to load object file for .dwo debug file \"{0}\" for "
1948 "unit DIE {1:x16}",
1949 dwo_name, cu_die.GetOffset()));
1950 return nullptr;
1951 }
1952
1953 return std::make_shared<SymbolFileDWARFDwo>(*this, dwo_obj_file,
1954 dwarf_cu->GetID());
1955}
1956
1959 return;
1961 DWARFDebugInfo &debug_info = DebugInfo();
1962
1963 // Follow DWO skeleton unit breadcrumbs.
1964 const uint32_t num_compile_units = GetNumCompileUnits();
1965 for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx) {
1966 auto *dwarf_cu =
1967 llvm::dyn_cast<DWARFCompileUnit>(debug_info.GetUnitAtIndex(cu_idx));
1968 if (!dwarf_cu)
1969 continue;
1970
1971 const DWARFBaseDIE die = dwarf_cu->GetUnitDIEOnly();
1972 if (!die || die.HasChildren() || !die.GetDIE())
1973 continue;
1974
1975 const char *name = die.GetAttributeValueAsString(DW_AT_name, nullptr);
1976 if (!name)
1977 continue;
1978
1979 ConstString const_name(name);
1980 ModuleSP &module_sp = m_external_type_modules[const_name];
1981 if (module_sp)
1982 continue;
1983
1984 const char *dwo_path = GetDWOName(*dwarf_cu, *die.GetDIE());
1985 if (!dwo_path)
1986 continue;
1987
1988 ModuleSpec dwo_module_spec;
1989 dwo_module_spec.GetFileSpec().SetFile(dwo_path, FileSpec::Style::native);
1990 if (dwo_module_spec.GetFileSpec().IsRelative()) {
1991 const char *comp_dir =
1992 die.GetAttributeValueAsString(DW_AT_comp_dir, nullptr);
1993 if (comp_dir) {
1994 dwo_module_spec.GetFileSpec().SetFile(comp_dir,
1995 FileSpec::Style::native);
1996 FileSystem::Instance().Resolve(dwo_module_spec.GetFileSpec());
1997 dwo_module_spec.GetFileSpec().AppendPathComponent(dwo_path);
1998 }
1999 }
2000 dwo_module_spec.GetArchitecture() =
2001 m_objfile_sp->GetModule()->GetArchitecture();
2002
2003 // When LLDB loads "external" modules it looks at the presence of
2004 // DW_AT_dwo_name. However, when the already created module
2005 // (corresponding to .dwo itself) is being processed, it will see
2006 // the presence of DW_AT_dwo_name (which contains the name of dwo
2007 // file) and will try to call ModuleList::GetSharedModule
2008 // again. In some cases (i.e., for empty files) Clang 4.0
2009 // generates a *.dwo file which has DW_AT_dwo_name, but no
2010 // DW_AT_comp_dir. In this case the method
2011 // ModuleList::GetSharedModule will fail and the warning will be
2012 // printed. However, as one can notice in this case we don't
2013 // actually need to try to load the already loaded module
2014 // (corresponding to .dwo) so we simply skip it.
2015 if (m_objfile_sp->GetFileSpec().GetFileNameExtension() == ".dwo" &&
2016 llvm::StringRef(m_objfile_sp->GetFileSpec().GetPath())
2017 .ends_with(dwo_module_spec.GetFileSpec().GetPath())) {
2018 continue;
2019 }
2020
2021 Status error = ModuleList::GetSharedModule(dwo_module_spec, module_sp,
2022 nullptr, nullptr);
2023 if (!module_sp) {
2024 // ReportWarning also rate-limits based on the warning string,
2025 // but in a -gmodules build, each object file has a similar DAG
2026 // of module dependencies that would all be listed here.
2027 GetObjectFile()->GetModule()->ReportWarning(
2028 "{0}", error.AsCString("unknown error"));
2029 GetObjectFile()->GetModule()->ReportWarning(
2030 "unable to locate module needed for external types.\n"
2031 "Debugging will be degraded due to missing types. Rebuilding the "
2032 "project will regenerate the needed module files");
2033 continue;
2034 }
2035
2036 // Verify the DWO hash.
2037 // FIXME: Technically "0" is a valid hash.
2038 std::optional<uint64_t> dwo_id = ::GetDWOId(*dwarf_cu, *die.GetDIE());
2039 if (!dwo_id)
2040 continue;
2041
2042 auto *dwo_symfile =
2043 llvm::dyn_cast_or_null<SymbolFileDWARF>(module_sp->GetSymbolFile());
2044 if (!dwo_symfile)
2045 continue;
2046 std::optional<uint64_t> dwo_dwo_id = dwo_symfile->GetDWOId();
2047 if (!dwo_dwo_id)
2048 continue;
2049
2050 if (dwo_id != dwo_dwo_id) {
2051 GetObjectFile()->GetModule()->ReportWarning(
2052 "module {0} is out-of-date (hash mismatch).\n"
2053 "Type information from this module may be incomplete or inconsistent "
2054 "with the rest of the program. Rebuilding the project will "
2055 "regenerate the needed module files",
2056 dwo_module_spec.GetFileSpec().GetPath());
2057 }
2058 }
2059}
2060
2062 if (!m_global_aranges_up) {
2063 m_global_aranges_up = std::make_unique<GlobalVariableMap>();
2064
2065 ModuleSP module_sp = GetObjectFile()->GetModule();
2066 if (module_sp) {
2067 const size_t num_cus = module_sp->GetNumCompileUnits();
2068 for (size_t i = 0; i < num_cus; ++i) {
2069 CompUnitSP cu_sp = module_sp->GetCompileUnitAtIndex(i);
2070 if (cu_sp) {
2071 VariableListSP globals_sp = cu_sp->GetVariableList(true);
2072 if (globals_sp) {
2073 const size_t num_globals = globals_sp->GetSize();
2074 for (size_t g = 0; g < num_globals; ++g) {
2075 VariableSP var_sp = globals_sp->GetVariableAtIndex(g);
2076 if (var_sp && !var_sp->GetLocationIsConstantValueData()) {
2077 const DWARFExpressionList &location =
2078 var_sp->LocationExpressionList();
2079 ExecutionContext exe_ctx;
2080 llvm::Expected<Value> location_result = location.Evaluate(
2081 &exe_ctx, nullptr, LLDB_INVALID_ADDRESS, nullptr, nullptr);
2082 if (location_result) {
2083 if (location_result->GetValueType() ==
2085 lldb::addr_t file_addr =
2086 location_result->GetScalar().ULongLong();
2087 lldb::addr_t byte_size = 1;
2088 if (var_sp->GetType())
2089 byte_size = llvm::expectedToOptional(
2090 var_sp->GetType()->GetByteSize(nullptr))
2091 .value_or(0);
2093 file_addr, byte_size, var_sp.get()));
2094 }
2095 } else {
2097 location_result.takeError(),
2098 "location expression failed to execute: {0}");
2099 }
2100 }
2101 }
2102 }
2103 }
2104 }
2105 }
2106 m_global_aranges_up->Sort();
2107 }
2108 return *m_global_aranges_up;
2109}
2110
2112 bool lookup_block,
2113 SymbolContext &sc) {
2114 assert(sc.comp_unit);
2115 DWARFCompileUnit &cu =
2117 DWARFDIE function_die = cu.LookupAddress(file_vm_addr);
2118 DWARFDIE block_die;
2119 if (function_die) {
2120 sc.function = sc.comp_unit->FindFunctionByUID(function_die.GetID()).get();
2121 if (sc.function == nullptr)
2122 sc.function = ParseFunction(*sc.comp_unit, function_die);
2123
2124 if (sc.function && lookup_block)
2125 block_die = function_die.LookupDeepestBlock(file_vm_addr);
2126 }
2127
2128 if (!sc.function || !lookup_block)
2129 return;
2130
2131 Block &block = sc.function->GetBlock(true);
2132 if (block_die)
2133 sc.block = block.FindBlockByID(block_die.GetID());
2134 else
2135 sc.block = block.FindBlockByID(function_die.GetID());
2136}
2137
2138uint32_t SymbolFileDWARF::ResolveSymbolContext(const Address &so_addr,
2139 SymbolContextItem resolve_scope,
2140 SymbolContext &sc) {
2141 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
2142 LLDB_SCOPED_TIMERF("SymbolFileDWARF::"
2143 "ResolveSymbolContext (so_addr = { "
2144 "section = %p, offset = 0x%" PRIx64
2145 " }, resolve_scope = 0x%8.8x)",
2146 static_cast<void *>(so_addr.GetSection().get()),
2147 so_addr.GetOffset(), resolve_scope);
2148 uint32_t resolved = 0;
2149 if (resolve_scope &
2150 (eSymbolContextCompUnit | eSymbolContextFunction | eSymbolContextBlock |
2151 eSymbolContextLineEntry | eSymbolContextVariable)) {
2152 lldb::addr_t file_vm_addr = so_addr.GetFileAddress();
2153
2154 DWARFDebugInfo &debug_info = DebugInfo();
2155 const DWARFDebugAranges &aranges = debug_info.GetCompileUnitAranges();
2156 const dw_offset_t cu_offset = aranges.FindAddress(file_vm_addr);
2157 if (cu_offset == DW_INVALID_OFFSET) {
2158 // Global variables are not in the compile unit address ranges. The only
2159 // way to currently find global variables is to iterate over the
2160 // .debug_pubnames or the __apple_names table and find all items in there
2161 // that point to DW_TAG_variable DIEs and then find the address that
2162 // matches.
2163 if (resolve_scope & eSymbolContextVariable) {
2165 const GlobalVariableMap::Entry *entry =
2166 map.FindEntryThatContains(file_vm_addr);
2167 if (entry && entry->data) {
2168 Variable *variable = entry->data;
2169 SymbolContextScope *scc = variable->GetSymbolContextScope();
2170 if (scc) {
2171 scc->CalculateSymbolContext(&sc);
2172 sc.variable = variable;
2173 }
2174 return sc.GetResolvedMask();
2175 }
2176 }
2177 } else {
2178 uint32_t cu_idx = DW_INVALID_INDEX;
2179 if (auto *dwarf_cu = llvm::dyn_cast_or_null<DWARFCompileUnit>(
2180 debug_info.GetUnitAtOffset(DIERef::Section::DebugInfo, cu_offset,
2181 &cu_idx))) {
2182 sc.comp_unit = GetCompUnitForDWARFCompUnit(*dwarf_cu);
2183 if (sc.comp_unit) {
2184 resolved |= eSymbolContextCompUnit;
2185
2186 bool force_check_line_table = false;
2187 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock)) {
2188 ResolveFunctionAndBlock(file_vm_addr,
2189 resolve_scope & eSymbolContextBlock, sc);
2190 if (sc.function)
2191 resolved |= eSymbolContextFunction;
2192 else {
2193 // We might have had a compile unit that had discontiguous address
2194 // ranges where the gaps are symbols that don't have any debug
2195 // info. Discontiguous compile unit address ranges should only
2196 // happen when there aren't other functions from other compile
2197 // units in these gaps. This helps keep the size of the aranges
2198 // down.
2199 force_check_line_table = true;
2200 }
2201 if (sc.block)
2202 resolved |= eSymbolContextBlock;
2203 }
2204
2205 if ((resolve_scope & eSymbolContextLineEntry) ||
2206 force_check_line_table) {
2207 LineTable *line_table = sc.comp_unit->GetLineTable();
2208 if (line_table != nullptr) {
2209 // And address that makes it into this function should be in terms
2210 // of this debug file if there is no debug map, or it will be an
2211 // address in the .o file which needs to be fixed up to be in
2212 // terms of the debug map executable. Either way, calling
2213 // FixupAddress() will work for us.
2214 Address exe_so_addr(so_addr);
2215 if (FixupAddress(exe_so_addr)) {
2216 if (line_table->FindLineEntryByAddress(exe_so_addr,
2217 sc.line_entry)) {
2218 resolved |= eSymbolContextLineEntry;
2219 }
2220 }
2221 }
2222 }
2223
2224 if (force_check_line_table && !(resolved & eSymbolContextLineEntry)) {
2225 // We might have had a compile unit that had discontiguous address
2226 // ranges where the gaps are symbols that don't have any debug info.
2227 // Discontiguous compile unit address ranges should only happen when
2228 // there aren't other functions from other compile units in these
2229 // gaps. This helps keep the size of the aranges down.
2230 sc.comp_unit = nullptr;
2231 resolved &= ~eSymbolContextCompUnit;
2232 }
2233 } else {
2234 GetObjectFile()->GetModule()->ReportWarning(
2235 "{0:x16}: compile unit {1} failed to create a valid "
2236 "lldb_private::CompileUnit class",
2237 cu_offset, cu_idx);
2238 }
2239 }
2240 }
2241 }
2242 return resolved;
2243}
2244
2246 const SourceLocationSpec &src_location_spec,
2247 SymbolContextItem resolve_scope, SymbolContextList &sc_list) {
2248 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
2249 const bool check_inlines = src_location_spec.GetCheckInlines();
2250 const uint32_t prev_size = sc_list.GetSize();
2251 if (resolve_scope & eSymbolContextCompUnit) {
2252 for (uint32_t cu_idx = 0, num_cus = GetNumCompileUnits(); cu_idx < num_cus;
2253 ++cu_idx) {
2254 CompileUnit *dc_cu = ParseCompileUnitAtIndex(cu_idx).get();
2255 if (!dc_cu)
2256 continue;
2257
2258 bool file_spec_matches_cu_file_spec = FileSpec::Match(
2259 src_location_spec.GetFileSpec(), dc_cu->GetPrimaryFile());
2260 if (check_inlines || file_spec_matches_cu_file_spec) {
2261 dc_cu->ResolveSymbolContext(src_location_spec, resolve_scope, sc_list);
2262 if (!check_inlines)
2263 break;
2264 }
2265 }
2266 }
2267 return sc_list.GetSize() - prev_size;
2268}
2269
2271 // Get the symbol table for the symbol file prior to taking the module lock
2272 // so that it is available without needing to take the module lock. The DWARF
2273 // indexing might end up needing to relocate items when DWARF sections are
2274 // loaded as they might end up getting the section contents which can call
2275 // ObjectFileELF::RelocateSection() which in turn will ask for the symbol
2276 // table and can cause deadlocks.
2277 GetSymtab();
2278 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
2279 m_index->Preload();
2280}
2281
2282std::recursive_mutex &SymbolFileDWARF::GetModuleMutex() const {
2283 lldb::ModuleSP module_sp(m_debug_map_module_wp.lock());
2284 if (module_sp)
2285 return module_sp->GetMutex();
2286 return GetObjectFile()->GetModule()->GetMutex();
2287}
2288
2290 const lldb_private::CompilerDeclContext &decl_ctx) {
2291 if (!decl_ctx.IsValid()) {
2292 // Invalid namespace decl which means we aren't matching only things in
2293 // this symbol file, so return true to indicate it matches this symbol
2294 // file.
2295 return true;
2296 }
2297
2298 TypeSystem *decl_ctx_type_system = decl_ctx.GetTypeSystem();
2299 auto type_system_or_err = GetTypeSystemForLanguage(
2300 decl_ctx_type_system->GetMinimumLanguage(nullptr));
2301 if (auto err = type_system_or_err.takeError()) {
2302 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
2303 "Unable to match namespace decl using TypeSystem: {0}");
2304 return false;
2305 }
2306
2307 if (decl_ctx_type_system == type_system_or_err->get())
2308 return true; // The type systems match, return true
2309
2310 // The namespace AST was valid, and it does not match...
2312
2313 if (log)
2314 GetObjectFile()->GetModule()->LogMessage(
2315 log, "Valid namespace does not match symbol file");
2316
2317 return false;
2318}
2319
2321 ConstString name, const CompilerDeclContext &parent_decl_ctx,
2322 uint32_t max_matches, VariableList &variables) {
2323 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
2325
2326 if (log)
2327 GetObjectFile()->GetModule()->LogMessage(
2328 log,
2329 "SymbolFileDWARF::FindGlobalVariables (name=\"{0}\", "
2330 "parent_decl_ctx={1:p}, max_matches={2}, variables)",
2331 name.GetCString(), static_cast<const void *>(&parent_decl_ctx),
2332 max_matches);
2333
2334 if (!DeclContextMatchesThisSymbolFile(parent_decl_ctx))
2335 return;
2336
2337 // Remember how many variables are in the list before we search.
2338 const uint32_t original_size = variables.GetSize();
2339
2340 llvm::StringRef basename;
2341 llvm::StringRef context;
2342 bool name_is_mangled = Mangled::GetManglingScheme(name.GetStringRef()) !=
2344
2345 // Technically not a mangled name, but a support variable emitted by clang.
2346 // Regardless, we need an exact lookup
2347 //
2348 // FIXME: Replace this with a constant shared between Clang and LLDB
2349 if (name == "__clang_vtable")
2350 name_is_mangled = true;
2351
2353 context, basename))
2354 basename = name.GetStringRef();
2355
2356 // Loop invariant: Variables up to this index have been checked for context
2357 // matches.
2358 uint32_t pruned_idx = original_size;
2359
2360 SymbolContext sc;
2361 m_index->GetGlobalVariables(ConstString(basename), [&](DWARFDIE die) {
2362 if (!sc.module_sp)
2363 sc.module_sp = m_objfile_sp->GetModule();
2364 assert(sc.module_sp);
2365
2366 if (die.Tag() != DW_TAG_variable && die.Tag() != DW_TAG_member)
2368
2369 auto *dwarf_cu = llvm::dyn_cast<DWARFCompileUnit>(die.GetCU());
2370 if (!dwarf_cu)
2372 sc.comp_unit = GetCompUnitForDWARFCompUnit(*dwarf_cu);
2373
2374 if (parent_decl_ctx) {
2375 if (DWARFASTParser *dwarf_ast = GetDWARFParser(*die.GetCU())) {
2376 CompilerDeclContext actual_parent_decl_ctx =
2377 dwarf_ast->GetDeclContextContainingUIDFromDWARF(die);
2378
2379 /// If the actual namespace is inline (i.e., had a DW_AT_export_symbols)
2380 /// and a child (possibly through other layers of inline namespaces)
2381 /// of the namespace referred to by 'basename', allow the lookup to
2382 /// succeed.
2383 if (!actual_parent_decl_ctx ||
2384 (actual_parent_decl_ctx != parent_decl_ctx &&
2385 !parent_decl_ctx.IsContainedInLookup(actual_parent_decl_ctx)))
2387 }
2388 }
2389
2390 ParseAndAppendGlobalVariable(sc, die, variables);
2391 while (pruned_idx < variables.GetSize()) {
2392 VariableSP var_sp = variables.GetVariableAtIndex(pruned_idx);
2393 if (name_is_mangled ||
2394 var_sp->GetName().GetStringRef().contains(name.GetStringRef()))
2395 ++pruned_idx;
2396 else
2397 variables.RemoveVariableAtIndex(pruned_idx);
2398 }
2399
2400 if (variables.GetSize() - original_size < max_matches)
2402
2403 return IterationAction::Stop;
2404 });
2405
2406 // Return the number of variable that were appended to the list
2407 const uint32_t num_matches = variables.GetSize() - original_size;
2408 if (log && num_matches > 0) {
2409 GetObjectFile()->GetModule()->LogMessage(
2410 log,
2411 "SymbolFileDWARF::FindGlobalVariables (name=\"{0}\", "
2412 "parent_decl_ctx={1:p}, max_matches={2}, variables) => {3}",
2413 name.GetCString(), static_cast<const void *>(&parent_decl_ctx),
2414 max_matches, num_matches);
2415 }
2416}
2417
2419 uint32_t max_matches,
2420 VariableList &variables) {
2421 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
2423
2424 if (log) {
2425 GetObjectFile()->GetModule()->LogMessage(
2426 log,
2427 "SymbolFileDWARF::FindGlobalVariables (regex=\"{0}\", "
2428 "max_matches={1}, variables)",
2429 regex.GetText().str().c_str(), max_matches);
2430 }
2431
2432 // Remember how many variables are in the list before we search.
2433 const uint32_t original_size = variables.GetSize();
2434
2435 SymbolContext sc;
2436 m_index->GetGlobalVariables(regex, [&](DWARFDIE die) {
2437 if (!sc.module_sp)
2438 sc.module_sp = m_objfile_sp->GetModule();
2439 assert(sc.module_sp);
2440
2441 DWARFCompileUnit *dwarf_cu = llvm::dyn_cast<DWARFCompileUnit>(die.GetCU());
2442 if (!dwarf_cu)
2444 sc.comp_unit = GetCompUnitForDWARFCompUnit(*dwarf_cu);
2445
2446 ParseAndAppendGlobalVariable(sc, die, variables);
2447
2448 if (variables.GetSize() - original_size < max_matches)
2450
2451 return IterationAction::Stop;
2452 });
2453}
2454
2456 bool include_inlines,
2457 SymbolContextList &sc_list) {
2458 SymbolContext sc;
2459
2460 if (!orig_die)
2461 return false;
2462
2463 // If we were passed a die that is not a function, just return false...
2464 if (!(orig_die.Tag() == DW_TAG_subprogram ||
2465 (include_inlines && orig_die.Tag() == DW_TAG_inlined_subroutine)))
2466 return false;
2467
2468 DWARFDIE die = orig_die;
2469 DWARFDIE inlined_die;
2470 if (die.Tag() == DW_TAG_inlined_subroutine) {
2471 inlined_die = die;
2472
2473 while (true) {
2474 die = die.GetParent();
2475
2476 if (die) {
2477 if (die.Tag() == DW_TAG_subprogram)
2478 break;
2479 } else
2480 break;
2481 }
2482 }
2483 assert(die && die.Tag() == DW_TAG_subprogram);
2484 if (GetFunction(die, sc)) {
2485 // Parse all blocks if needed
2486 if (inlined_die) {
2487 Block &function_block = sc.function->GetBlock(true);
2488 sc.block = function_block.FindBlockByID(inlined_die.GetID());
2489 if (sc.block == nullptr)
2490 sc.block = function_block.FindBlockByID(inlined_die.GetOffset());
2491 }
2492
2493 sc_list.AppendIfUnique(sc, /*merge_symbol_into_function=*/true);
2494 return true;
2495 }
2496
2497 return false;
2498}
2499
2500static llvm::StringRef ClangToItaniumCtorKind(clang::CXXCtorType kind) {
2501 switch (kind) {
2502 case clang::CXXCtorType::Ctor_Complete:
2503 return "C1";
2504 case clang::CXXCtorType::Ctor_Base:
2505 return "C2";
2506 case clang::CXXCtorType::Ctor_Unified:
2507 return "C4";
2508 case clang::CXXCtorType::Ctor_CopyingClosure:
2509 case clang::CXXCtorType::Ctor_DefaultClosure:
2510 case clang::CXXCtorType::Ctor_Comdat:
2511 llvm_unreachable("Unexpected constructor kind.");
2512 }
2513 llvm_unreachable("Fully covered switch above");
2514}
2515
2516static llvm::StringRef ClangToItaniumDtorKind(clang::CXXDtorType kind) {
2517 switch (kind) {
2518 case clang::CXXDtorType::Dtor_Deleting:
2519 return "D0";
2520 case clang::CXXDtorType::Dtor_Complete:
2521 return "D1";
2522 case clang::CXXDtorType::Dtor_Base:
2523 return "D2";
2524 case clang::CXXDtorType::Dtor_Unified:
2525 return "D4";
2526 case clang::CXXDtorType::Dtor_Comdat:
2527 case clang::CXXDtorType::Dtor_VectorDeleting:
2528 llvm_unreachable("Unexpected destructor kind.");
2529 }
2530 llvm_unreachable("Fully covered switch above");
2531}
2532
2533static llvm::StringRef
2534GetItaniumCtorDtorVariant(llvm::StringRef discriminator) {
2535 const bool is_ctor = discriminator.consume_front("C");
2536 if (!is_ctor && !discriminator.consume_front("D"))
2537 return {};
2538
2539 uint64_t structor_kind;
2540 if (!llvm::to_integer(discriminator, structor_kind))
2541 return {};
2542
2543 if (is_ctor) {
2544 if (structor_kind > clang::CXXCtorType::Ctor_Unified)
2545 return {};
2546
2548 static_cast<clang::CXXCtorType>(structor_kind));
2549 }
2550
2551 if (structor_kind > clang::CXXDtorType::Dtor_Unified)
2552 return {};
2553
2554 return ClangToItaniumDtorKind(static_cast<clang::CXXDtorType>(structor_kind));
2555}
2556
2557llvm::Expected<DWARFDIE>
2559 const DWARFDIE &declaration) {
2560 auto do_lookup = [this](llvm::StringRef lookup_name) -> DWARFDIE {
2561 DWARFDIE found;
2562 auto lookup_infos = Module::LookupInfo::MakeLookupInfos(
2563 ConstString(lookup_name), lldb::eFunctionNameTypeFull,
2565
2566 m_index->GetFunctions(lookup_infos, *this, {}, [&](DWARFDIE entry) {
2567 if (entry.GetAttributeValueAsUnsigned(llvm::dwarf::DW_AT_declaration, 0))
2569
2570 found = entry;
2571 return IterationAction::Stop;
2572 });
2573
2574 return found;
2575 };
2576
2577 DWARFDIE definition = do_lookup(label.lookup_name);
2578 if (definition.IsValid())
2579 return definition;
2580
2581 // This is not a structor lookup. Nothing else to be done here.
2582 if (label.discriminator.empty())
2583 return llvm::createStringError(
2584 "no definition DIE found in this SymbolFile");
2585
2586 // We're doing a structor lookup. Maybe we didn't find the structor variant
2587 // because the complete object structor was aliased to the base object
2588 // structor. Try finding the alias instead.
2589 //
2590 // TODO: there are other reasons for why a subprogram definition might be
2591 // missing. Ideally DWARF would tell us more details about which structor
2592 // variant a DIE corresponds to and whether it's an alias.
2593 auto subst_or_err =
2595 label.lookup_name);
2596 if (!subst_or_err)
2597 return subst_or_err.takeError();
2598
2599 definition = do_lookup(*subst_or_err);
2600
2601 if (!definition.IsValid())
2602 return llvm::createStringError(
2603 "failed to find definition DIE for structor alias in fallback lookup");
2604
2605 return definition;
2606}
2607
2608llvm::Expected<SymbolContext>
2610 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
2611
2612 if (!label.discriminator.empty()) {
2613 llvm::StringRef from = label.discriminator[0] == 'C' ? "C4" : "D4";
2614
2615 llvm::StringRef variant = GetItaniumCtorDtorVariant(label.discriminator);
2616 if (variant.empty())
2617 return llvm::createStringError(
2618 "failed to get Itanium variant for discriminator");
2619
2620 if (from == variant)
2621 return llvm::createStringError(
2622 "tried substituting unified structor variant into label");
2623
2624 // If we failed to substitute unified mangled name, don't try to do a lookup
2625 // using the unified name because there may be multiple definitions for it
2626 // in the index, and we wouldn't know which one to choose.
2628 label.lookup_name, from, variant);
2629 if (!subst_or_err)
2630 return llvm::joinErrors(
2631 llvm::createStringErrorV(
2632 "failed to substitute {0} for {1} in mangled name {2}:", from,
2633 variant, label.lookup_name),
2634 subst_or_err.takeError());
2635
2636 if (!*subst_or_err)
2637 return llvm::createStringErrorV(
2638 "got invalid substituted mangled named (substituted "
2639 "{0} for {1} in mangled name {2})",
2640 from, variant, label.lookup_name);
2641
2642 label.lookup_name = subst_or_err->GetStringRef();
2643 }
2644
2645 DWARFDIE die = GetDIE(label.symbol_id);
2646 if (!die.IsValid())
2647 return llvm::createStringErrorV("invalid DIE ID in {0}", label);
2648
2649 // Label was created using a declaration DIE. Need to fetch the definition
2650 // to resolve the function call.
2651 if (die.GetAttributeValueAsUnsigned(llvm::dwarf::DW_AT_declaration, 0)) {
2652 auto die_or_err = FindFunctionDefinition(label, die);
2653 if (!die_or_err)
2654 return llvm::joinErrors(
2655 llvm::createStringError("failed to find definition DIE:"),
2656 die_or_err.takeError());
2657
2658 die = std::move(*die_or_err);
2659 }
2660
2661 SymbolContextList sc_list;
2662 if (!ResolveFunction(die, /*include_inlines=*/false, sc_list))
2663 return llvm::createStringError("failed to resolve function");
2664
2665 if (sc_list.IsEmpty())
2666 return llvm::createStringError("failed to find function");
2667
2668 assert(sc_list.GetSize() == 1);
2669
2670 return sc_list[0];
2671}
2672
2674 const DWARFDIE &die,
2675 bool only_root_namespaces) {
2676 // If we have no parent decl context to match this DIE matches, and if the
2677 // parent decl context isn't valid, we aren't trying to look for any
2678 // particular decl context so any die matches.
2679 if (!decl_ctx.IsValid()) {
2680 // ...But if we are only checking root decl contexts, confirm that the
2681 // 'die' is a top-level context.
2682 if (only_root_namespaces)
2683 return die.GetParent().Tag() == llvm::dwarf::DW_TAG_compile_unit;
2684
2685 return true;
2686 }
2687
2688 if (die) {
2689 if (DWARFASTParser *dwarf_ast = GetDWARFParser(*die.GetCU())) {
2690 if (CompilerDeclContext actual_decl_ctx =
2691 dwarf_ast->GetDeclContextContainingUIDFromDWARF(die))
2692 return decl_ctx.IsContainedInLookup(actual_decl_ctx);
2693 }
2694 }
2695 return false;
2696}
2697
2699 const CompilerDeclContext &parent_decl_ctx,
2700 bool include_inlines,
2701 SymbolContextList &sc_list) {
2702 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
2703 ConstString name = lookup_info.GetLookupName();
2704 FunctionNameType name_type_mask = lookup_info.GetNameTypeMask();
2705
2706 // eFunctionNameTypeAuto should be pre-resolved by a call to
2707 // Module::LookupInfo::LookupInfo()
2708 assert((name_type_mask & eFunctionNameTypeAuto) == 0);
2709
2711
2712 if (log) {
2713 GetObjectFile()->GetModule()->LogMessage(
2714 log,
2715 "SymbolFileDWARF::FindFunctions (name=\"{0}\", name_type_mask={1:x}, "
2716 "sc_list)",
2717 name.GetCString(), name_type_mask);
2718 }
2719
2720 if (!DeclContextMatchesThisSymbolFile(parent_decl_ctx))
2721 return;
2722
2723 // If name is empty then we won't find anything.
2724 if (name.IsEmpty())
2725 return;
2726
2727 // Remember how many sc_list are in the list before we search in case we are
2728 // appending the results to a variable list.
2729
2730 const uint32_t original_size = sc_list.GetSize();
2731
2732 llvm::DenseSet<const DWARFDebugInfoEntry *> resolved_dies;
2733
2734 m_index->GetFunctions(lookup_info, *this, parent_decl_ctx, [&](DWARFDIE die) {
2735 if (resolved_dies.insert(die.GetDIE()).second)
2736 ResolveFunction(die, include_inlines, sc_list);
2738 });
2739 // With -gsimple-template-names, a templated type's DW_AT_name will not
2740 // contain the template parameters. Try again stripping '<' and anything
2741 // after, filtering out entries with template parameters that don't match.
2742 {
2743 const llvm::StringRef name_ref = name.GetStringRef();
2744 auto it = name_ref.find('<');
2745 if (it != llvm::StringRef::npos) {
2746 const llvm::StringRef name_no_template_params = name_ref.slice(0, it);
2747
2748 Module::LookupInfo no_tp_lookup_info(
2749 lookup_info, ConstString(name_no_template_params));
2750 m_index->GetFunctions(no_tp_lookup_info, *this, parent_decl_ctx,
2751 [&](DWARFDIE die) {
2752 if (resolved_dies.insert(die.GetDIE()).second)
2753 ResolveFunction(die, include_inlines, sc_list);
2755 });
2756 }
2757 }
2758
2759 // Return the number of variable that were appended to the list
2760 const uint32_t num_matches = sc_list.GetSize() - original_size;
2761
2762 if (log && num_matches > 0) {
2763 GetObjectFile()->GetModule()->LogMessage(
2764 log,
2765 "SymbolFileDWARF::FindFunctions (name=\"{0}\", "
2766 "name_type_mask={1:x}, include_inlines={2:d}, sc_list) => {3}",
2767 name.GetCString(), name_type_mask, include_inlines, num_matches);
2768 }
2769}
2770
2772 bool include_inlines,
2773 SymbolContextList &sc_list) {
2774 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
2775 LLDB_SCOPED_TIMERF("SymbolFileDWARF::FindFunctions (regex = '%s')",
2776 regex.GetText().str().c_str());
2777
2779
2780 if (log) {
2781 GetObjectFile()->GetModule()->LogMessage(
2782 log, "SymbolFileDWARF::FindFunctions (regex=\"{0}\", sc_list)",
2783 regex.GetText().str().c_str());
2784 }
2785
2786 llvm::DenseSet<const DWARFDebugInfoEntry *> resolved_dies;
2787 m_index->GetFunctions(regex, [&](DWARFDIE die) {
2788 if (resolved_dies.insert(die.GetDIE()).second)
2789 ResolveFunction(die, include_inlines, sc_list);
2791 });
2792}
2793
2795 const std::string &scope_qualified_name,
2796 std::vector<ConstString> &mangled_names) {
2797 DWARFDebugInfo &info = DebugInfo();
2798 uint32_t num_comp_units = info.GetNumUnits();
2799 for (uint32_t i = 0; i < num_comp_units; i++) {
2800 DWARFUnit *cu = info.GetUnitAtIndex(i);
2801 if (cu == nullptr)
2802 continue;
2803
2805 if (dwo)
2806 dwo->GetMangledNamesForFunction(scope_qualified_name, mangled_names);
2807 }
2808
2809 for (DIERef die_ref :
2810 m_function_scope_qualified_name_map.lookup(scope_qualified_name)) {
2811 DWARFDIE die = GetDIE(die_ref);
2812 mangled_names.push_back(ConstString(die.GetMangledName()));
2813 }
2814}
2815
2816/// Split a name up into a basename and template parameters.
2817static bool SplitTemplateParams(llvm::StringRef fullname,
2818 llvm::StringRef &basename,
2819 llvm::StringRef &template_params) {
2820 auto it = fullname.find('<');
2821 if (it == llvm::StringRef::npos) {
2822 basename = fullname;
2823 template_params = llvm::StringRef();
2824 return false;
2825 }
2826 basename = fullname.slice(0, it);
2827 template_params = fullname.slice(it, fullname.size());
2828 return true;
2829}
2830
2832 // We need to find any names in the context that have template parameters
2833 // and strip them so the context can be matched when -gsimple-template-names
2834 // is being used. Returns true if any of the context items were updated.
2835 bool any_context_updated = false;
2836 for (auto &context : match.GetContextRef()) {
2837 llvm::StringRef basename, params;
2838 if (SplitTemplateParams(context.name.GetStringRef(), basename, params)) {
2839 context.name = ConstString(basename);
2840 any_context_updated = true;
2841 }
2842 }
2843 return any_context_updated;
2844}
2845
2846uint64_t SymbolFileDWARF::GetDebugInfoSize(bool load_all_debug_info) {
2847 DWARFDebugInfo &info = DebugInfo();
2848 uint32_t num_comp_units = info.GetNumUnits();
2849
2850 uint64_t debug_info_size = SymbolFileCommon::GetDebugInfoSize();
2851 // In dwp scenario, debug info == skeleton debug info + dwp debug info.
2852 if (std::shared_ptr<SymbolFileDWARFDwo> dwp_sp = GetDwpSymbolFile())
2853 return debug_info_size + dwp_sp->GetDebugInfoSize();
2854
2855 // In dwo scenario, debug info == skeleton debug info + all dwo debug info.
2856 for (uint32_t i = 0; i < num_comp_units; i++) {
2857 DWARFUnit *cu = info.GetUnitAtIndex(i);
2858 if (cu == nullptr)
2859 continue;
2860
2861 SymbolFileDWARFDwo *dwo = cu->GetDwoSymbolFile(load_all_debug_info);
2862 if (dwo)
2863 debug_info_size += dwo->GetDebugInfoSize();
2864 }
2865 return debug_info_size;
2866}
2867
2869
2870 // Make sure we haven't already searched this SymbolFile before.
2871 if (results.AlreadySearched(this))
2872 return;
2873
2874 auto type_basename = query.GetTypeBasename();
2875
2877 if (log) {
2878 GetObjectFile()->GetModule()->LogMessage(
2879 log, "SymbolFileDWARF::FindTypes(type_basename=\"{0}\")",
2880 type_basename);
2881 }
2882
2883 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
2884
2885 TypeQuery query_full(query);
2886 bool have_index_match = false;
2887 m_index->GetTypesWithQuery(query_full, [&](DWARFDIE die) {
2888 if (Type *matching_type = ResolveType(die, true, true)) {
2889 if (!query.GetSearchByMangledName() && matching_type->IsTemplateType()) {
2890 // We have to watch out for case where we lookup a type by basename and
2891 // it matches a template with simple template names. Like looking up
2892 // "Foo" and if we have simple template names then we will match
2893 // "Foo<int>" and "Foo<double>" because all the DWARF has is "Foo" in
2894 // the accelerator tables. The main case we see this in is when the
2895 // expression parser is trying to parse "Foo<int>" and it will first do
2896 // a lookup on just "Foo". We verify the type basename matches before
2897 // inserting the type in the results.
2898 auto CompilerTypeBasename =
2899 matching_type->GetForwardCompilerType().GetTypeName(true);
2900 if (CompilerTypeBasename != query.GetTypeBasename())
2902 }
2903 have_index_match = true;
2904 results.InsertUnique(matching_type->shared_from_this());
2905 }
2906 if (!results.Done(query))
2908
2909 return IterationAction::Stop;
2910 });
2911
2912 if (results.Done(query)) {
2913 if (log) {
2914 GetObjectFile()->GetModule()->LogMessage(
2915 log, "SymbolFileDWARF::FindTypes(type_basename=\"{0}\") => {1}",
2916 type_basename, results.GetTypeMap().GetSize());
2917 }
2918 return;
2919 }
2920
2921 // With -gsimple-template-names, a templated type's DW_AT_name will not
2922 // contain the template parameters. Try again stripping '<' and anything
2923 // after, filtering out entries with template parameters that don't match.
2924 if (!have_index_match && !query.GetSearchByMangledName()) {
2925 // Create a type matcher with a compiler context that is tuned for
2926 // -gsimple-template-names. We will use this for the index lookup and the
2927 // context matching, but will use the original "match" to insert matches
2928 // into if things match. The "match_simple" has a compiler context with
2929 // all template parameters removed to allow the names and context to match.
2930 // The UpdateCompilerContextForSimpleTemplateNames(...) will return true if
2931 // it trims any context items down by removing template parameter names.
2932 TypeQuery query_simple(query);
2934 auto type_basename_simple = query_simple.GetTypeBasename();
2935 // Copy our match's context and update the basename we are looking for
2936 // so we can use this only to compare the context correctly.
2937 m_index->GetTypesWithQuery(query_simple, [&](DWARFDIE die) {
2938 std::vector<CompilerContext> qualified_context =
2939 query.GetModuleSearch()
2940 ? die.GetDeclContext(/*derive_template_names=*/true)
2941 : die.GetTypeLookupContext(/*derive_template_names=*/true);
2942 if (query.ContextMatches(qualified_context))
2943 if (Type *matching_type = ResolveType(die, true, true))
2944 results.InsertUnique(matching_type->shared_from_this());
2945 if (!results.Done(query))
2947
2948 return IterationAction::Stop;
2949 });
2950 if (results.Done(query)) {
2951 if (log) {
2952 GetObjectFile()->GetModule()->LogMessage(
2953 log,
2954 "SymbolFileDWARF::FindTypes(type_basename=\"{0}\") => {1} "
2955 "(simplified as \"{2}\")",
2956 type_basename, results.GetTypeMap().GetSize(),
2957 type_basename_simple);
2958 }
2959 return;
2960 }
2961 }
2962 }
2963
2964 // Next search through the reachable Clang modules. This only applies for
2965 // DWARF objects compiled with -gmodules that haven't been processed by
2966 // dsymutil.
2968
2969 for (const auto &pair : m_external_type_modules) {
2970 if (ModuleSP external_module_sp = pair.second) {
2971 external_module_sp->FindTypes(query, results);
2972 if (results.Done(query)) {
2973 // We don't log the results here as they are already logged in the
2974 // nested FindTypes call
2975 return;
2976 }
2977 }
2978 }
2979}
2980
2983 const CompilerDeclContext &parent_decl_ctx,
2984 bool only_root_namespaces) {
2985 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
2987
2988 if (log) {
2989 GetObjectFile()->GetModule()->LogMessage(
2990 log, "SymbolFileDWARF::FindNamespace (sc, name=\"{0}\")",
2991 name.GetCString());
2992 }
2993
2994 CompilerDeclContext namespace_decl_ctx;
2995
2996 if (!DeclContextMatchesThisSymbolFile(parent_decl_ctx))
2997 return namespace_decl_ctx;
2998
2999 m_index->GetNamespacesWithParents(name, parent_decl_ctx, [&](DWARFDIE die) {
3000 if (!DIEInDeclContext(parent_decl_ctx, die, only_root_namespaces))
3002
3003 DWARFASTParser *dwarf_ast = GetDWARFParser(*die.GetCU());
3004 if (!dwarf_ast)
3006
3007 namespace_decl_ctx = dwarf_ast->GetDeclContextForUIDFromDWARF(die);
3008 if (namespace_decl_ctx.IsValid())
3009 return IterationAction::Stop;
3010
3012 });
3013
3014 if (log && namespace_decl_ctx) {
3015 GetObjectFile()->GetModule()->LogMessage(
3016 log,
3017 "SymbolFileDWARF::FindNamespace (sc, name=\"{0}\") => "
3018 "CompilerDeclContext({1:p}/{2:p}) \"{3}\"",
3019 name.GetCString(),
3020 static_cast<const void *>(namespace_decl_ctx.GetTypeSystem()),
3021 static_cast<const void *>(namespace_decl_ctx.GetOpaqueDeclContext()),
3022 namespace_decl_ctx.GetName().AsCString("<NULL>"));
3023 }
3024
3025 return namespace_decl_ctx;
3026}
3027
3029 bool resolve_function_context) {
3030 TypeSP type_sp;
3031 if (die) {
3032 Type *type_ptr = GetDIEToType().lookup(die.GetDIE());
3033 if (type_ptr == nullptr) {
3034 SymbolContextScope *scope;
3035 if (auto *dwarf_cu = llvm::dyn_cast<DWARFCompileUnit>(die.GetCU()))
3036 scope = GetCompUnitForDWARFCompUnit(*dwarf_cu);
3037 else
3038 scope = GetObjectFile()->GetModule().get();
3039 assert(scope);
3040 SymbolContext sc(scope);
3041 const DWARFDebugInfoEntry *parent_die = die.GetParent().GetDIE();
3042 while (parent_die != nullptr) {
3043 if (parent_die->Tag() == DW_TAG_subprogram)
3044 break;
3045 parent_die = parent_die->GetParent();
3046 }
3047 SymbolContext sc_backup = sc;
3048 if (resolve_function_context && parent_die != nullptr &&
3049 !GetFunction(DWARFDIE(die.GetCU(), parent_die), sc))
3050 sc = sc_backup;
3051
3052 type_sp = ParseType(sc, die, nullptr);
3053 } else if (type_ptr != DIE_IS_BEING_PARSED) {
3054 // Get the original shared pointer for this type
3055 type_sp = type_ptr->shared_from_this();
3056 }
3057 }
3058 return type_sp;
3059}
3060
3063 if (orig_die) {
3064 DWARFDIE die = orig_die;
3065
3066 while (die) {
3067 // If this is the original DIE that we are searching for a declaration
3068 // for, then don't look in the cache as we don't want our own decl
3069 // context to be our decl context...
3070 if (orig_die != die) {
3071 switch (die.Tag()) {
3072 case DW_TAG_compile_unit:
3073 case DW_TAG_partial_unit:
3074 case DW_TAG_namespace:
3075 case DW_TAG_structure_type:
3076 case DW_TAG_union_type:
3077 case DW_TAG_class_type:
3078 case DW_TAG_lexical_block:
3079 case DW_TAG_subprogram:
3080 return die;
3081 case DW_TAG_inlined_subroutine: {
3082 DWARFDIE abs_die = die.GetReferencedDIE(DW_AT_abstract_origin);
3083 if (abs_die) {
3084 return abs_die;
3085 }
3086 break;
3087 }
3088 default:
3089 break;
3090 }
3091 }
3092
3093 DWARFDIE spec_die = die.GetReferencedDIE(DW_AT_specification);
3094 if (spec_die) {
3095 DWARFDIE decl_ctx_die = GetDeclContextDIEContainingDIE(spec_die);
3096 if (decl_ctx_die)
3097 return decl_ctx_die;
3098 }
3099
3100 DWARFDIE abs_die = die.GetReferencedDIE(DW_AT_abstract_origin);
3101 if (abs_die) {
3102 DWARFDIE decl_ctx_die = GetDeclContextDIEContainingDIE(abs_die);
3103 if (decl_ctx_die)
3104 return decl_ctx_die;
3105 }
3106
3107 die = die.GetParent();
3108 }
3109 }
3110 return DWARFDIE();
3111}
3112
3114 Symbol *objc_class_symbol = nullptr;
3115 if (m_objfile_sp) {
3116 Symtab *symtab = m_objfile_sp->GetSymtab();
3117 if (symtab) {
3118 objc_class_symbol = symtab->FindFirstSymbolWithNameAndType(
3119 objc_class_name, eSymbolTypeObjCClass, Symtab::eDebugNo,
3121 }
3122 }
3123 return objc_class_symbol;
3124}
3125
3126// This function can be used when a DIE is found that is a forward declaration
3127// DIE and we want to try and find a type that has the complete definition.
3129 const DWARFDIE &die, ConstString type_name, bool must_be_implementation) {
3130
3131 TypeSP type_sp;
3132
3133 if (!type_name || (must_be_implementation && !GetObjCClassSymbol(type_name)))
3134 return type_sp;
3135
3136 m_index->GetCompleteObjCClass(
3137 type_name, must_be_implementation, [&](DWARFDIE type_die) {
3138 // Don't try and resolve the DIE we are looking for with the DIE
3139 // itself!
3140 if (type_die == die || !IsStructOrClassTag(type_die.Tag()))
3142
3143 if (must_be_implementation) {
3144 const bool try_resolving_type = type_die.GetAttributeValueAsUnsigned(
3145 DW_AT_APPLE_objc_complete_type, 0);
3146 if (!try_resolving_type)
3148 }
3149
3150 Type *resolved_type = ResolveType(type_die, false, true);
3151 if (!resolved_type || resolved_type == DIE_IS_BEING_PARSED)
3153
3155 "resolved 0x%8.8" PRIx64 " from %s to 0x%8.8" PRIx64
3156 " (cu 0x%8.8" PRIx64 ")\n",
3157 die.GetID(),
3158 m_objfile_sp->GetFileSpec().GetFilename().AsCString("<Unknown>"),
3159 type_die.GetID(), type_cu->GetID());
3160
3161 if (die)
3162 GetDIEToType()[die.GetDIE()] = resolved_type;
3163 type_sp = resolved_type->shared_from_this();
3164 return IterationAction::Stop;
3165 });
3166 return type_sp;
3167}
3168
3171 const char *name = die.GetName();
3172 if (!name)
3173 return {};
3174 if (!die.GetAttributeValueAsUnsigned(DW_AT_declaration, 0))
3175 return die;
3176
3177 Progress progress(llvm::formatv("Searching definition DIE in {0}: '{1}'",
3178 GetObjectFile()->GetFileSpec().GetFilename(),
3179 name));
3180
3181 const dw_tag_t tag = die.Tag();
3182
3184 if (log) {
3185 GetObjectFile()->GetModule()->LogMessage(
3186 log,
3187 "SymbolFileDWARF::FindDefinitionDIE(tag={0} "
3188 "({1}), name='{2}')",
3189 DW_TAG_value_to_name(tag), tag, name);
3190 }
3191
3192 // Get the type system that we are looking to find a type for. We will
3193 // use this to ensure any matches we find are in a language that this
3194 // type system supports
3195 const LanguageType language = GetLanguage(*die.GetCU());
3196 TypeSystemSP type_system = nullptr;
3197 if (language != eLanguageTypeUnknown) {
3198 auto type_system_or_err = GetTypeSystemForLanguage(language);
3199 if (auto err = type_system_or_err.takeError()) {
3200 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
3201 "Cannot get TypeSystem for language {1}: {0}",
3203 } else {
3204 type_system = *type_system_or_err;
3205 }
3206 }
3207
3208 // See comments below about -gsimple-template-names for why we attempt to
3209 // compute missing template parameter names.
3210 std::vector<std::string> template_params;
3211 DWARFDeclContext die_dwarf_decl_ctx;
3212 DWARFASTParser *dwarf_ast =
3213 type_system ? type_system->GetDWARFParser() : nullptr;
3214 for (DWARFDIE ctx_die = die; ctx_die && !isUnitType(ctx_die.Tag());
3215 ctx_die = ctx_die.GetParentDeclContextDIE()) {
3216 die_dwarf_decl_ctx.AppendDeclContext(ctx_die.Tag(), ctx_die.GetName());
3217 template_params.push_back(
3218 (ctx_die.IsStructUnionOrClass() && dwarf_ast)
3219 ? dwarf_ast->GetDIEClassTemplateParams(ctx_die)
3220 : "");
3221 }
3222 const bool any_template_params = llvm::any_of(
3223 template_params, [](llvm::StringRef p) { return !p.empty(); });
3224
3225 auto die_matches = [&](DWARFDIE type_die) {
3226 // Resolve the type if both have the same tag or {class, struct} tags.
3227 const bool tag_matches =
3228 type_die.Tag() == tag ||
3229 (IsStructOrClassTag(type_die.Tag()) && IsStructOrClassTag(tag));
3230 if (!tag_matches)
3231 return false;
3232 if (any_template_params) {
3233 size_t pos = 0;
3234 for (DWARFDIE ctx_die = type_die; ctx_die && !isUnitType(ctx_die.Tag()) &&
3235 pos < template_params.size();
3236 ctx_die = ctx_die.GetParentDeclContextDIE(), ++pos) {
3237 if (template_params[pos].empty())
3238 continue;
3239 if (template_params[pos] !=
3240 dwarf_ast->GetDIEClassTemplateParams(ctx_die))
3241 return false;
3242 }
3243 if (pos != template_params.size())
3244 return false;
3245 }
3246 return true;
3247 };
3248 DWARFDIE result;
3249 m_index->GetFullyQualifiedType(die_dwarf_decl_ctx, [&](DWARFDIE type_die) {
3250 // Make sure type_die's language matches the type system we are
3251 // looking for. We don't want to find a "Foo" type from Java if we
3252 // are looking for a "Foo" type for C, C++, ObjC, or ObjC++.
3253 if (type_system &&
3254 !type_system->SupportsLanguage(GetLanguage(*type_die.GetCU())))
3256
3257 if (!die_matches(type_die)) {
3258 if (log) {
3259 GetObjectFile()->GetModule()->LogMessage(
3260 log,
3261 "SymbolFileDWARF::FindDefinitionDIE(tag={0} ({1}), "
3262 "name='{2}') ignoring die={3:x16} ({4})",
3263 DW_TAG_value_to_name(tag), tag, name, type_die.GetOffset(),
3264 type_die.GetName());
3265 }
3267 }
3268
3269 if (log) {
3270 DWARFDeclContext type_dwarf_decl_ctx = type_die.GetDWARFDeclContext();
3271 GetObjectFile()->GetModule()->LogMessage(
3272 log,
3273 "SymbolFileDWARF::FindDefinitionTypeDIE(tag={0} ({1}), name='{2}') "
3274 "trying die={3:x16} ({4})",
3275 DW_TAG_value_to_name(tag), tag, name, type_die.GetOffset(),
3276 type_dwarf_decl_ctx.GetQualifiedName());
3277 }
3278
3279 result = type_die;
3280 return IterationAction::Stop;
3281 });
3282 return result;
3283}
3284
3286 bool *type_is_new_ptr) {
3287 if (!die)
3288 return {};
3289
3290 auto type_system_or_err = GetTypeSystemForLanguage(GetLanguage(*die.GetCU()));
3291 if (auto err = type_system_or_err.takeError()) {
3292 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
3293 "Unable to parse type: {0}");
3294 return {};
3295 }
3296 auto ts = *type_system_or_err;
3297 if (!ts)
3298 return {};
3299
3300 DWARFASTParser *dwarf_ast = ts->GetDWARFParser();
3301 if (!dwarf_ast)
3302 return {};
3303
3304 TypeSP type_sp = dwarf_ast->ParseTypeFromDWARF(sc, die, type_is_new_ptr);
3305 if (type_sp) {
3306 if (die.Tag() == DW_TAG_subprogram) {
3307 std::string scope_qualified_name(GetDeclContextForUID(die.GetID())
3309 .AsCString(""));
3310 if (scope_qualified_name.size()) {
3311 m_function_scope_qualified_name_map[scope_qualified_name].insert(
3312 *die.GetDIERef());
3313 }
3314 }
3315 }
3316
3317 return type_sp;
3318}
3319
3321 const DWARFDIE &orig_die,
3322 bool parse_siblings, bool parse_children) {
3323 size_t types_added = 0;
3324 DWARFDIE die = orig_die;
3325
3326 while (die) {
3327 const dw_tag_t tag = die.Tag();
3328 bool type_is_new = false;
3329
3330 Tag dwarf_tag = static_cast<Tag>(tag);
3331
3332 // TODO: Currently ParseTypeFromDWARF(...) which is called by ParseType(...)
3333 // does not handle DW_TAG_subrange_type. It is not clear if this is a bug or
3334 // not.
3335 if (isType(dwarf_tag) && tag != DW_TAG_subrange_type)
3336 ParseType(sc, die, &type_is_new);
3337
3338 if (type_is_new)
3339 ++types_added;
3340
3341 if (parse_children && die.HasChildren()) {
3342 if (die.Tag() == DW_TAG_subprogram) {
3343 SymbolContext child_sc(sc);
3344 child_sc.function = sc.comp_unit->FindFunctionByUID(die.GetID()).get();
3345 types_added += ParseTypes(child_sc, die.GetFirstChild(), true, true);
3346 } else
3347 types_added += ParseTypes(sc, die.GetFirstChild(), true, true);
3348 }
3349
3350 if (parse_siblings)
3351 die = die.GetSibling();
3352 else
3353 die.Clear();
3354 }
3355 return types_added;
3356}
3357
3359 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
3360 CompileUnit *comp_unit = func.GetCompileUnit();
3361 lldbassert(comp_unit);
3362
3363 DWARFUnit *dwarf_cu = GetDWARFCompileUnit(comp_unit);
3364 if (!dwarf_cu)
3365 return 0;
3366
3367 size_t functions_added = 0;
3368 const dw_offset_t function_die_offset = DIERef(func.GetID()).die_offset();
3369 DWARFDIE function_die =
3370 dwarf_cu->GetNonSkeletonUnit().GetDIE(function_die_offset);
3371 if (function_die) {
3372 // We can't use the file address from the Function object as (in the OSO
3373 // case) it will already be remapped to the main module.
3374 if (llvm::Expected<llvm::DWARFAddressRangesVector> ranges =
3375 function_die.GetDIE()->GetAttributeAddressRanges(
3376 function_die.GetCU(),
3377 /*check_hi_lo_pc=*/true)) {
3378 if (ranges->empty())
3379 return 0;
3380 dw_addr_t function_file_addr = ranges->begin()->LowPC;
3381 if (function_file_addr != LLDB_INVALID_ADDRESS)
3382 ParseBlocksRecursive(*comp_unit, &func.GetBlock(false),
3383 function_die.GetFirstChild(), function_file_addr);
3384 } else {
3385 LLDB_LOG_ERRORV(GetLog(DWARFLog::DebugInfo), ranges.takeError(),
3386 "{1:x}: {0}", dwarf_cu->GetOffset());
3387 }
3388 }
3389
3390 return functions_added;
3391}
3392
3394 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
3395 size_t types_added = 0;
3396 DWARFUnit *dwarf_cu = GetDWARFCompileUnit(&comp_unit);
3397 if (dwarf_cu) {
3398 DWARFDIE dwarf_cu_die = dwarf_cu->DIE();
3399 if (dwarf_cu_die && dwarf_cu_die.HasChildren()) {
3400 SymbolContext sc;
3401 sc.comp_unit = &comp_unit;
3402 types_added = ParseTypes(sc, dwarf_cu_die.GetFirstChild(), true, true);
3403 }
3404 }
3405
3406 return types_added;
3407}
3408
3410 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
3411 if (sc.comp_unit != nullptr) {
3412 if (sc.function) {
3413 DWARFDIE function_die = GetDIE(sc.function->GetID());
3414
3415 dw_addr_t func_lo_pc = LLDB_INVALID_ADDRESS;
3416 if (llvm::Expected<llvm::DWARFAddressRangesVector> ranges =
3417 function_die.GetDIE()->GetAttributeAddressRanges(
3418 function_die.GetCU(), /*check_hi_lo_pc=*/true)) {
3419 if (!ranges->empty())
3420 func_lo_pc = ranges->begin()->LowPC;
3421 } else {
3422 LLDB_LOG_ERRORV(GetLog(DWARFLog::DebugInfo), ranges.takeError(),
3423 "DIE({1:x}): {0}", function_die.GetID());
3424 }
3425 if (func_lo_pc != LLDB_INVALID_ADDRESS) {
3426 const size_t num_variables =
3427 ParseVariablesInFunctionContext(sc, function_die, func_lo_pc);
3428
3429 // Let all blocks know they have parse all their variables
3430 sc.function->GetBlock(false).SetDidParseVariables(true, true);
3431 return num_variables;
3432 }
3433 } else if (sc.comp_unit) {
3434 DWARFUnit *dwarf_cu = DebugInfo().GetUnitAtIndex(sc.comp_unit->GetID());
3435
3436 if (dwarf_cu == nullptr)
3437 return 0;
3438
3439 uint32_t vars_added = 0;
3440 VariableListSP variables(sc.comp_unit->GetVariableList(false));
3441
3442 if (variables.get() == nullptr) {
3443 variables = std::make_shared<VariableList>();
3444 sc.comp_unit->SetVariableList(variables);
3445
3446 m_index->GetGlobalVariables(*dwarf_cu, [&](DWARFDIE die) {
3447 VariableSP var_sp(ParseVariableDIECached(sc, die));
3448 if (var_sp) {
3449 variables->AddVariableIfUnique(var_sp);
3450 ++vars_added;
3451 }
3453 });
3454 }
3455 return vars_added;
3456 }
3457 }
3458 return 0;
3459}
3460
3462 const DWARFDIE &die) {
3463 if (!die)
3464 return nullptr;
3465
3466 DIEToVariableSP &die_to_variable = die.GetDWARF()->GetDIEToVariable();
3467
3468 VariableSP var_sp = die_to_variable[die.GetDIE()];
3469 if (var_sp)
3470 return var_sp;
3471
3472 var_sp = ParseVariableDIE(sc, die, LLDB_INVALID_ADDRESS);
3473 if (var_sp) {
3474 die_to_variable[die.GetDIE()] = var_sp;
3475 if (DWARFDIE spec_die = die.GetReferencedDIE(DW_AT_specification))
3476 die_to_variable[spec_die.GetDIE()] = var_sp;
3477 }
3478 return var_sp;
3479}
3480
3481/// Walks transparent type wrappers following DW_AT_type and returns
3482/// the first DW_AT_byte_size encountered along the chain.
3483static std::optional<uint64_t> GetByteSizeFromTypeDIE(DWARFDIE die,
3484 unsigned max_depth = 64) {
3485 // Bound the walk to guard against malformed/cyclic DWARF.
3486 if (!die || !max_depth)
3487 return std::nullopt;
3488
3489 if (std::optional<uint64_t> byte_size =
3490 die.GetAttributeValueAsOptionalUnsigned(DW_AT_byte_size))
3491 return byte_size;
3492
3493 switch (die.Tag()) {
3494 case DW_TAG_const_type:
3495 case DW_TAG_volatile_type:
3496 case DW_TAG_restrict_type:
3497 case DW_TAG_atomic_type:
3498 case DW_TAG_typedef:
3499 if (DWARFDIE next = die.GetAttributeValueAsReferenceDIE(DW_AT_type))
3500 return GetByteSizeFromTypeDIE(next, max_depth - 1);
3501 break;
3502 default:
3503 break;
3504 }
3505 return std::nullopt;
3506}
3507
3508/// Creates a DWARFExpressionList from an DW_AT_location form_value.
3510 ModuleSP module,
3511 const DWARFDIE &die,
3512 const addr_t func_low_pc) {
3513 if (DWARFFormValue::IsBlockForm(form_value.Form())) {
3514 const DWARFDataExtractor &data = die.GetData();
3515
3516 uint64_t block_offset = form_value.BlockData() - data.GetDataStart();
3517 uint64_t block_length = form_value.Unsigned();
3518 return DWARFExpressionList(
3519 module, DataExtractor(data, block_offset, block_length), die.GetCU());
3520 }
3521
3522 DWARFExpressionList location_list(module, DWARFExpression(), die.GetCU());
3523 DataExtractor data = die.GetCU()->GetLocationData();
3524 dw_offset_t offset = form_value.Unsigned();
3525 if (form_value.Form() == DW_FORM_loclistx)
3526 offset = die.GetCU()->GetLoclistOffset(offset).value_or(-1);
3527 if (data.ValidOffset(offset)) {
3528 data = DataExtractor(data, offset, data.GetByteSize() - offset);
3529 const DWARFUnit *dwarf_cu = form_value.GetUnit();
3530 if (dwarf_cu->ParseDWARFLocationList(data, location_list))
3531 location_list.SetFuncFileAddress(func_low_pc);
3532 }
3533
3534 return location_list;
3535}
3536
3537/// Creates a DWARFExpressionList from an DW_AT_const_value. This is either a
3538/// block form, or a string, or a data form. For data forms, this returns an
3539/// empty list, as we cannot initialize it properly without a SymbolFileType.
3540static DWARFExpressionList
3542 const DWARFDIE &die) {
3543 const DWARFDataExtractor &debug_info_data = die.GetData();
3544 if (DWARFFormValue::IsBlockForm(form_value.Form())) {
3545 // Retrieve the value as a block expression.
3546 uint64_t block_offset =
3547 form_value.BlockData() - debug_info_data.GetDataStart();
3548 uint64_t block_length = form_value.Unsigned();
3549 return DWARFExpressionList(
3550 module, DataExtractor(debug_info_data, block_offset, block_length),
3551 die.GetCU());
3552 }
3553 if (const char *str = form_value.AsCString())
3554 return DWARFExpressionList(module,
3555 DataExtractor(str, strlen(str) + 1,
3556 die.GetCU()->GetByteOrder(),
3557 die.GetCU()->GetAddressByteSize()),
3558 die.GetCU());
3559 return DWARFExpressionList(module, DWARFExpression(), die.GetCU());
3560}
3561
3562/// Global variables that are not initialized may have their address set to
3563/// zero. Since multiple variables may have this address, we cannot apply the
3564/// OSO relink address approach we normally use.
3565/// However, the executable will have a matching symbol with a good address;
3566/// this function attempts to find the correct address by looking into the
3567/// executable's symbol table. If it succeeds, the expr_list is updated with
3568/// the new address and the executable's symbol is returned.
3570 SymbolFileDWARFDebugMap &debug_map_symfile, llvm::StringRef name,
3571 DWARFExpressionList &expr_list, const DWARFDIE &die) {
3572 ObjectFile *debug_map_objfile = debug_map_symfile.GetObjectFile();
3573 if (!debug_map_objfile)
3574 return nullptr;
3575
3576 Symtab *debug_map_symtab = debug_map_objfile->GetSymtab();
3577 if (!debug_map_symtab)
3578 return nullptr;
3579 Symbol *exe_symbol = debug_map_symtab->FindFirstSymbolWithNameAndType(
3582 if (!exe_symbol || !exe_symbol->ValueIsAddress())
3583 return nullptr;
3584 const addr_t exe_file_addr = exe_symbol->GetAddressRef().GetFileAddress();
3585 if (exe_file_addr == LLDB_INVALID_ADDRESS)
3586 return nullptr;
3587
3588 DWARFExpression *location = expr_list.GetMutableExpressionAtAddress();
3589 if (location->Update_DW_OP_addr(die.GetCU(), exe_file_addr))
3590 return exe_symbol;
3591 return nullptr;
3592}
3593
3595 const DWARFDIE &die,
3596 const lldb::addr_t func_low_pc) {
3597 if (die.GetDWARF() != this)
3598 return die.GetDWARF()->ParseVariableDIE(sc, die, func_low_pc);
3599
3600 if (!die)
3601 return nullptr;
3602
3603 const dw_tag_t tag = die.Tag();
3604 ModuleSP module = GetObjectFile()->GetModule();
3605
3606 if (tag != DW_TAG_variable && tag != DW_TAG_constant &&
3607 tag != DW_TAG_member && (tag != DW_TAG_formal_parameter || !sc.function))
3608 return nullptr;
3609
3610 DWARFAttributes attributes = die.GetAttributes();
3611 const char *name = nullptr;
3612 const char *mangled = nullptr;
3613 Declaration decl;
3614 DWARFFormValue type_die_form;
3615 bool is_external = false;
3616 bool is_artificial = false;
3617 std::optional<uint64_t> tag_offset = std::nullopt;
3618 DWARFFormValue const_value_form, location_form;
3619 Variable::RangeList scope_ranges;
3620
3621 for (size_t i = 0; i < attributes.Size(); ++i) {
3622 dw_attr_t attr = attributes.AttributeAtIndex(i);
3623 DWARFFormValue form_value;
3624
3625 if (!attributes.ExtractFormValueAtIndex(i, form_value))
3626 continue;
3627 switch (attr) {
3628 case DW_AT_LLVM_tag_offset:
3629 tag_offset = form_value.Unsigned();
3630 break;
3631 case DW_AT_decl_file:
3632 decl.SetFile(
3633 attributes.CompileUnitAtIndex(i)->GetFile(form_value.Unsigned()));
3634 break;
3635 case DW_AT_decl_line:
3636 decl.SetLine(form_value.Unsigned());
3637 break;
3638 case DW_AT_decl_column:
3639 decl.SetColumn(form_value.Unsigned());
3640 break;
3641 case DW_AT_name:
3642 name = form_value.AsCString();
3643 break;
3644 case DW_AT_linkage_name:
3645 case DW_AT_MIPS_linkage_name:
3646 mangled = form_value.AsCString();
3647 break;
3648 case DW_AT_type:
3649 // DW_AT_type on declaration may be less accurate than
3650 // that of definition, so don't overwrite it.
3651 if (!type_die_form.IsValid())
3652 type_die_form = form_value;
3653 break;
3654 case DW_AT_external:
3655 is_external = form_value.Boolean();
3656 break;
3657 case DW_AT_const_value:
3658 const_value_form = form_value;
3659 break;
3660 case DW_AT_location:
3661 location_form = form_value;
3662 break;
3663 case DW_AT_start_scope:
3664 // TODO: Implement this.
3665 break;
3666 case DW_AT_artificial:
3667 is_artificial = form_value.Boolean();
3668 break;
3669 case DW_AT_declaration:
3670 case DW_AT_description:
3671 case DW_AT_endianity:
3672 case DW_AT_segment:
3673 case DW_AT_specification:
3674 case DW_AT_visibility:
3675 default:
3676 case DW_AT_abstract_origin:
3677 case DW_AT_sibling:
3678 break;
3679 }
3680 }
3681
3682 // Prefer DW_AT_location over DW_AT_const_value. Both can be emitted e.g.
3683 // for static constexpr member variables -- DW_AT_const_value and
3684 // DW_AT_location will both be present in the DIE defining the member.
3685 bool location_is_const_value_data =
3686 const_value_form.IsValid() && !location_form.IsValid();
3687
3688 DWARFExpressionList location_list = [&] {
3689 if (location_form.IsValid())
3690 return GetExprListFromAtLocation(location_form, module, die, func_low_pc);
3691 if (const_value_form.IsValid())
3692 return GetExprListFromAtConstValue(const_value_form, module, die);
3693 return DWARFExpressionList(module, DWARFExpression(), die.GetCU());
3694 }();
3695
3696 const DWARFDIE parent_context_die = GetDeclContextDIEContainingDIE(die);
3697 const DWARFDIE sc_parent_die = GetParentSymbolContextDIE(die);
3698 const dw_tag_t parent_tag = sc_parent_die.Tag();
3699 bool is_static_member = (parent_tag == DW_TAG_compile_unit ||
3700 parent_tag == DW_TAG_partial_unit) &&
3701 (parent_context_die.Tag() == DW_TAG_class_type ||
3702 parent_context_die.Tag() == DW_TAG_structure_type);
3703
3705 SymbolContextScope *symbol_context_scope = nullptr;
3706
3707 bool has_explicit_mangled = mangled != nullptr;
3708 if (!mangled) {
3709 // LLDB relies on the mangled name (DW_TAG_linkage_name or
3710 // DW_AT_MIPS_linkage_name) to generate fully qualified names
3711 // of global variables with commands like "frame var j". For
3712 // example, if j were an int variable holding a value 4 and
3713 // declared in a namespace B which in turn is contained in a
3714 // namespace A, the command "frame var j" returns
3715 // "(int) A::B::j = 4".
3716 // If the compiler does not emit a linkage name, we should be
3717 // able to generate a fully qualified name from the
3718 // declaration context.
3719 if ((parent_tag == DW_TAG_compile_unit ||
3720 parent_tag == DW_TAG_partial_unit) &&
3722 mangled = die.GetDWARFDeclContext()
3724 .GetCString();
3725 }
3726
3727 if (tag == DW_TAG_formal_parameter)
3729 else {
3730 // DWARF doesn't specify if a DW_TAG_variable is a local, global
3731 // or static variable, so we have to do a little digging:
3732 // 1) DW_AT_linkage_name implies static lifetime (but may be missing)
3733 // 2) An empty DW_AT_location is an (optimized-out) static lifetime var.
3734 // 3) DW_AT_location containing a DW_OP_addr implies static lifetime.
3735 // Clang likes to combine small global variables into the same symbol
3736 // with locations like: DW_OP_addr(0x1000), DW_OP_constu(2), DW_OP_plus
3737 // so we need to look through the whole expression.
3738 bool has_explicit_location = location_form.IsValid();
3739 bool is_static_lifetime =
3740 has_explicit_mangled ||
3741 (has_explicit_location && !location_list.IsValid());
3742 // Check if the location has a DW_OP_addr with any address value...
3743 lldb::addr_t location_DW_OP_addr = LLDB_INVALID_ADDRESS;
3744 if (!location_is_const_value_data) {
3745 if (const DWARFExpression *location =
3746 location_list.GetAlwaysValidExpr()) {
3747 if (auto maybe_location_DW_OP_addr =
3748 location->GetLocation_DW_OP_addr(location_form.GetUnit())) {
3749 location_DW_OP_addr = *maybe_location_DW_OP_addr;
3750 } else {
3751 StreamString strm;
3752 location->DumpLocation(&strm, eDescriptionLevelFull, nullptr);
3753 GetObjectFile()->GetModule()->ReportError(
3754 "{0:x16}: {1} ({2}) has an invalid location: {3}: {4}",
3755 die.GetOffset(), DW_TAG_value_to_name(die.Tag()), die.Tag(),
3756 llvm::fmt_consume(maybe_location_DW_OP_addr.takeError()),
3757 strm.GetData());
3758 }
3759 }
3760 if (location_DW_OP_addr != LLDB_INVALID_ADDRESS)
3761 is_static_lifetime = true;
3762 }
3763 SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile();
3764 if (debug_map_symfile)
3765 // Set the module of the expression to the linked module
3766 // instead of the object file so the relocated address can be
3767 // found there.
3768 location_list.SetModule(debug_map_symfile->GetObjectFile()->GetModule());
3769
3770 if (is_static_lifetime) {
3771 if (is_external)
3773 else
3775
3776 if (debug_map_symfile) {
3777 bool linked_oso_file_addr = false;
3778
3779 if (is_external && location_DW_OP_addr == 0) {
3780 if (Symbol *exe_symbol = fixupExternalAddrZeroVariable(
3781 *debug_map_symfile, mangled ? mangled : name, location_list,
3782 die)) {
3783 linked_oso_file_addr = true;
3784 symbol_context_scope = exe_symbol;
3785 }
3786 }
3787
3788 if (!linked_oso_file_addr) {
3789 // The DW_OP_addr is not zero, but it contains a .o file address
3790 // which needs to be linked up correctly.
3791 const lldb::addr_t exe_file_addr =
3792 debug_map_symfile->LinkOSOFileAddress(this, location_DW_OP_addr);
3793 if (exe_file_addr != LLDB_INVALID_ADDRESS) {
3794 // Update the file address for this variable
3795 DWARFExpression *location =
3796 location_list.GetMutableExpressionAtAddress();
3797 location->Update_DW_OP_addr(die.GetCU(), exe_file_addr);
3798 } else {
3799 // Variable didn't make it into the final executable
3800 return nullptr;
3801 }
3802 }
3803 }
3804 } else {
3805 if (location_is_const_value_data &&
3806 die.GetDIE()->IsGlobalOrStaticScopeVariable())
3808 else {
3810 if (debug_map_symfile) {
3811 // We need to check for TLS addresses that we need to fixup
3812 if (location_list.ContainsThreadLocalStorage()) {
3813 location_list.LinkThreadLocalStorage(
3814 debug_map_symfile->GetObjectFile()->GetModule(),
3815 [this, debug_map_symfile](
3816 lldb::addr_t unlinked_file_addr) -> lldb::addr_t {
3817 return debug_map_symfile->LinkOSOFileAddress(
3818 this, unlinked_file_addr);
3819 });
3821 }
3822 }
3823 }
3824 }
3825 }
3826
3827 if (symbol_context_scope == nullptr) {
3828 switch (parent_tag) {
3829 case DW_TAG_subprogram:
3830 case DW_TAG_inlined_subroutine:
3831 case DW_TAG_lexical_block:
3832 if (sc.function) {
3833 symbol_context_scope =
3834 sc.function->GetBlock(true).FindBlockByID(sc_parent_die.GetID());
3835 if (symbol_context_scope == nullptr)
3836 symbol_context_scope = sc.function;
3837 }
3838 break;
3839
3840 default:
3841 symbol_context_scope = sc.comp_unit;
3842 break;
3843 }
3844 }
3845
3846 if (!symbol_context_scope) {
3847 // Not ready to parse this variable yet. It might be a global or static
3848 // variable that is in a function scope and the function in the symbol
3849 // context wasn't filled in yet
3850 return nullptr;
3851 }
3852
3853 auto type_sp = std::make_shared<SymbolFileType>(
3854 *this, type_die_form.Reference().GetID());
3855
3856 bool use_type_size_for_value =
3857 location_is_const_value_data &&
3858 DWARFFormValue::IsDataForm(const_value_form.Form());
3859 if (use_type_size_for_value) {
3860 std::optional<uint64_t> byte_size;
3861 if (Type *t = type_sp->GetType())
3862 byte_size = llvm::expectedToOptional(t->GetByteSize(nullptr));
3863
3864 // Some TypeSystems (such as Swift) cannot determine a type's byte
3865 // size without an execution context (e.g. types whose layout
3866 // depends on runtime metadata). In those cases the debug info
3867 // might still carry the static size of the value's box, which is
3868 // enough if the value is a constant.
3869 if (!byte_size)
3870 byte_size = GetByteSizeFromTypeDIE(type_die_form.Reference());
3871
3872 if (byte_size) {
3873 DWARFExpression *location = location_list.GetMutableExpressionAtAddress();
3874 location->UpdateValue(const_value_form.Unsigned(), *byte_size,
3875 die.GetCU()->GetAddressByteSize());
3876 }
3877 }
3878
3879 return std::make_shared<Variable>(
3880 die.GetID(), name, mangled, type_sp, scope, symbol_context_scope,
3881 scope_ranges, &decl, location_list, is_external, is_artificial,
3882 location_is_const_value_data, is_static_member, tag_offset);
3883}
3884
3887 const DIERef &func_die_ref, dw_offset_t spec_block_die_offset) {
3888 // Give the concrete function die specified by "func_die_offset", find the
3889 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
3890 // to "spec_block_die_offset"
3891 return FindBlockContainingSpecification(GetDIE(func_die_ref),
3892 spec_block_die_offset);
3893}
3894
3897 const DWARFDIE &die, dw_offset_t spec_block_die_offset) {
3898 if (die) {
3899 switch (die.Tag()) {
3900 case DW_TAG_subprogram:
3901 case DW_TAG_inlined_subroutine:
3902 case DW_TAG_lexical_block: {
3903 if (die.GetReferencedDIE(DW_AT_specification).GetOffset() ==
3904 spec_block_die_offset)
3905 return die;
3906
3907 if (die.GetReferencedDIE(DW_AT_abstract_origin).GetOffset() ==
3908 spec_block_die_offset)
3909 return die;
3910 } break;
3911 default:
3912 break;
3913 }
3914
3915 // Give the concrete function die specified by "func_die_offset", find the
3916 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
3917 // to "spec_block_die_offset"
3918 for (DWARFDIE child_die : die.children()) {
3919 DWARFDIE result_die =
3920 FindBlockContainingSpecification(child_die, spec_block_die_offset);
3921 if (result_die)
3922 return result_die;
3923 }
3924 }
3925
3926 return DWARFDIE();
3927}
3928
3930 const SymbolContext &sc, const DWARFDIE &die,
3931 VariableList &cc_variable_list) {
3932 if (!die)
3933 return;
3934
3935 dw_tag_t tag = die.Tag();
3936 if (tag != DW_TAG_variable && tag != DW_TAG_constant && tag != DW_TAG_member)
3937 return;
3938
3939 // Check to see if we have already parsed this variable or constant?
3940 VariableSP var_sp = GetDIEToVariable()[die.GetDIE()];
3941 if (var_sp) {
3942 cc_variable_list.AddVariableIfUnique(var_sp);
3943 return;
3944 }
3945
3946 // We haven't parsed the variable yet, lets do that now. Also, let us include
3947 // the variable in the relevant compilation unit's variable list, if it
3948 // exists.
3949 VariableListSP variable_list_sp;
3950 DWARFDIE sc_parent_die = GetParentSymbolContextDIE(die);
3951 dw_tag_t parent_tag = sc_parent_die.Tag();
3952 switch (parent_tag) {
3953 case DW_TAG_compile_unit:
3954 case DW_TAG_partial_unit:
3955 if (sc.comp_unit != nullptr) {
3956 variable_list_sp = sc.comp_unit->GetVariableList(false);
3957 } else {
3958 GetObjectFile()->GetModule()->ReportError(
3959 "parent {0:x8} {1} ({2}) with no valid compile unit in "
3960 "symbol context for {3:x8} {4} ({5}).\n",
3961 sc_parent_die.GetID(), DW_TAG_value_to_name(sc_parent_die.Tag()),
3962 sc_parent_die.Tag(), die.GetID(), DW_TAG_value_to_name(die.Tag()),
3963 die.Tag());
3964 return;
3965 }
3966 break;
3967
3968 default:
3970 "{0} '{1}' ({2:x8}) is not a global variable - ignoring", tag,
3971 die.GetName(), die.GetID());
3972 return;
3973 }
3974
3975 var_sp = ParseVariableDIECached(sc, die);
3976 if (!var_sp)
3977 return;
3978
3979 cc_variable_list.AddVariableIfUnique(var_sp);
3980 if (variable_list_sp)
3981 variable_list_sp->AddVariableIfUnique(var_sp);
3982}
3983
3986 DIEArray &&variable_dies) {
3987 // DW_TAG_inline_subroutine objects may omit DW_TAG_formal_parameter in
3988 // instances of the function when they are unused (i.e., the parameter's
3989 // location list would be empty). The current DW_TAG_inline_subroutine may
3990 // refer to another DW_TAG_subprogram that might actually have the definitions
3991 // of the parameters and we need to include these so they show up in the
3992 // variables for this function (for example, in a stack trace). Let us try to
3993 // find the abstract subprogram that might contain the parameter definitions
3994 // and merge with the concrete parameters.
3995
3996 // Nothing to merge if the block is not an inlined function.
3997 if (block_die.Tag() != DW_TAG_inlined_subroutine) {
3998 return std::move(variable_dies);
3999 }
4000
4001 // Nothing to merge if the block does not have abstract parameters.
4002 DWARFDIE abs_die = block_die.GetReferencedDIE(DW_AT_abstract_origin);
4003 if (!abs_die || abs_die.Tag() != DW_TAG_subprogram ||
4004 !abs_die.HasChildren()) {
4005 return std::move(variable_dies);
4006 }
4007
4008 // For each abstract parameter, if we have its concrete counterpart, insert
4009 // it. Otherwise, insert the abstract parameter.
4010 DIEArray::iterator concrete_it = variable_dies.begin();
4011 DWARFDIE abstract_child = abs_die.GetFirstChild();
4012 DIEArray merged;
4013 bool did_merge_abstract = false;
4014 for (; abstract_child; abstract_child = abstract_child.GetSibling()) {
4015 if (abstract_child.Tag() == DW_TAG_formal_parameter) {
4016 if (concrete_it == variable_dies.end() ||
4017 GetDIE(*concrete_it).Tag() != DW_TAG_formal_parameter) {
4018 // We arrived at the end of the concrete parameter list, so all
4019 // the remaining abstract parameters must have been omitted.
4020 // Let us insert them to the merged list here.
4021 merged.push_back(*abstract_child.GetDIERef());
4022 did_merge_abstract = true;
4023 continue;
4024 }
4025
4026 DWARFDIE origin_of_concrete =
4027 GetDIE(*concrete_it).GetReferencedDIE(DW_AT_abstract_origin);
4028 if (origin_of_concrete == abstract_child) {
4029 // The current abstract parameter is the origin of the current
4030 // concrete parameter, just push the concrete parameter.
4031 merged.push_back(*concrete_it);
4032 ++concrete_it;
4033 } else {
4034 // Otherwise, the parameter must have been omitted from the concrete
4035 // function, so insert the abstract one.
4036 merged.push_back(*abstract_child.GetDIERef());
4037 did_merge_abstract = true;
4038 }
4039 }
4040 }
4041
4042 // Shortcut if no merging happened.
4043 if (!did_merge_abstract)
4044 return std::move(variable_dies);
4045
4046 // We inserted all the abstract parameters (or their concrete counterparts).
4047 // Let us insert all the remaining concrete variables to the merged list.
4048 // During the insertion, let us check there are no remaining concrete
4049 // formal parameters. If that's the case, then just bailout from the merge -
4050 // the variable list is malformed.
4051 for (; concrete_it != variable_dies.end(); ++concrete_it) {
4052 if (GetDIE(*concrete_it).Tag() == DW_TAG_formal_parameter) {
4053 return std::move(variable_dies);
4054 }
4055 merged.push_back(*concrete_it);
4056 }
4057 return merged;
4058}
4059
4061 const SymbolContext &sc, const DWARFDIE &die,
4062 const lldb::addr_t func_low_pc) {
4063 if (!die || !sc.function)
4064 return 0;
4065
4066 DIEArray dummy_block_variables; // The recursive call should not add anything
4067 // to this vector because |die| should be a
4068 // subprogram, so all variables will be added
4069 // to the subprogram's list.
4070 return ParseVariablesInFunctionContextRecursive(sc, die, func_low_pc,
4071 dummy_block_variables);
4072}
4073
4074// This method parses all the variables in the blocks in the subtree of |die|,
4075// and inserts them to the variable list for all the nested blocks.
4076// The uninserted variables for the current block are accumulated in
4077// |accumulator|.
4079 const lldb_private::SymbolContext &sc, const DWARFDIE &die,
4080 lldb::addr_t func_low_pc, DIEArray &accumulator) {
4081 size_t vars_added = 0;
4082 dw_tag_t tag = die.Tag();
4083
4084 if ((tag == DW_TAG_variable) || (tag == DW_TAG_constant) ||
4085 (tag == DW_TAG_formal_parameter)) {
4086 accumulator.push_back(*die.GetDIERef());
4087 }
4088
4089 switch (tag) {
4090 case DW_TAG_subprogram:
4091 case DW_TAG_inlined_subroutine:
4092 case DW_TAG_lexical_block: {
4093 // If we start a new block, compute a new block variable list and recurse.
4094 Block *block =
4095 sc.function->GetBlock(/*can_create=*/true).FindBlockByID(die.GetID());
4096 if (block == nullptr) {
4097 // This must be a specification or abstract origin with a
4098 // concrete block counterpart in the current function. We need
4099 // to find the concrete block so we can correctly add the
4100 // variable to it.
4101 const DWARFDIE concrete_block_die = FindBlockContainingSpecification(
4102 GetDIE(sc.function->GetID()), die.GetOffset());
4103 if (concrete_block_die)
4104 block = sc.function->GetBlock(/*can_create=*/true)
4105 .FindBlockByID(concrete_block_die.GetID());
4106 }
4107
4108 if (block == nullptr)
4109 return 0;
4110
4111 const bool can_create = false;
4112 VariableListSP block_variable_list_sp =
4113 block->GetBlockVariableList(can_create);
4114 if (block_variable_list_sp.get() == nullptr) {
4115 block_variable_list_sp = std::make_shared<VariableList>();
4116 block->SetVariableList(block_variable_list_sp);
4117 }
4118
4119 DIEArray block_variables;
4120 for (DWARFDIE child = die.GetFirstChild(); child;
4121 child = child.GetSibling()) {
4123 sc, child, func_low_pc, block_variables);
4124 }
4125 block_variables =
4126 MergeBlockAbstractParameters(die, std::move(block_variables));
4127 vars_added += PopulateBlockVariableList(*block_variable_list_sp, sc,
4128 block_variables, func_low_pc);
4129 break;
4130 }
4131
4132 default:
4133 // Recurse to children with the same variable accumulator.
4134 for (DWARFDIE child = die.GetFirstChild(); child;
4135 child = child.GetSibling()) {
4137 sc, child, func_low_pc, accumulator);
4138 }
4139 break;
4140 }
4141
4142 return vars_added;
4143}
4144
4146 VariableList &variable_list, const lldb_private::SymbolContext &sc,
4147 llvm::ArrayRef<DIERef> variable_dies, lldb::addr_t func_low_pc) {
4148 // Parse the variable DIEs and insert them to the list.
4149 for (auto &die : variable_dies) {
4150 if (VariableSP var_sp = ParseVariableDIE(sc, GetDIE(die), func_low_pc)) {
4151 variable_list.AddVariableIfUnique(var_sp);
4152 }
4153 }
4154 return variable_dies.size();
4155}
4156
4157/// Collect call site parameters in a DW_TAG_call_site DIE.
4160 CallSiteParameterArray parameters;
4161 for (DWARFDIE child : call_site_die.children()) {
4162 if (child.Tag() != DW_TAG_call_site_parameter &&
4163 child.Tag() != DW_TAG_GNU_call_site_parameter)
4164 continue;
4165
4166 std::optional<DWARFExpressionList> LocationInCallee;
4167 std::optional<DWARFExpressionList> LocationInCaller;
4168
4169 DWARFAttributes attributes = child.GetAttributes();
4170
4171 // Parse the location at index \p attr_index within this call site parameter
4172 // DIE, or return std::nullopt on failure.
4173 auto parse_simple_location =
4174 [&](int attr_index) -> std::optional<DWARFExpressionList> {
4175 DWARFFormValue form_value;
4176 if (!attributes.ExtractFormValueAtIndex(attr_index, form_value))
4177 return {};
4178 if (!DWARFFormValue::IsBlockForm(form_value.Form()))
4179 return {};
4180 auto data = child.GetData();
4181 uint64_t block_offset = form_value.BlockData() - data.GetDataStart();
4182 uint64_t block_length = form_value.Unsigned();
4183 return DWARFExpressionList(
4184 module, DataExtractor(data, block_offset, block_length),
4185 child.GetCU());
4186 };
4187
4188 for (size_t i = 0; i < attributes.Size(); ++i) {
4189 dw_attr_t attr = attributes.AttributeAtIndex(i);
4190 if (attr == DW_AT_location)
4191 LocationInCallee = parse_simple_location(i);
4192 if (attr == DW_AT_call_value || attr == DW_AT_GNU_call_site_value)
4193 LocationInCaller = parse_simple_location(i);
4194 }
4195
4196 if (LocationInCallee && LocationInCaller) {
4197 CallSiteParameter param = {*LocationInCallee, *LocationInCaller};
4198 parameters.push_back(param);
4199 }
4200 }
4201 return parameters;
4202}
4203
4204/// Collect call graph edges present in a function DIE.
4205std::vector<std::unique_ptr<lldb_private::CallEdge>>
4207 // Check if the function has a supported call site-related attribute.
4208 // TODO: In the future it may be worthwhile to support call_all_source_calls.
4209 bool has_call_edges =
4210 function_die.GetAttributeValueAsUnsigned(DW_AT_call_all_calls, 0) ||
4211 function_die.GetAttributeValueAsUnsigned(DW_AT_GNU_all_call_sites, 0);
4212 if (!has_call_edges)
4213 return {};
4214
4215 Log *log = GetLog(LLDBLog::Step);
4216 LLDB_LOG(log, "CollectCallEdges: Found call site info in {0}",
4217 function_die.GetPubname());
4218
4219 // Scan the DIE for TAG_call_site entries.
4220 // TODO: A recursive scan of all blocks in the subprogram is needed in order
4221 // to be DWARF5-compliant. This may need to be done lazily to be performant.
4222 // For now, assume that all entries are nested directly under the subprogram
4223 // (this is the kind of DWARF LLVM produces) and parse them eagerly.
4224 std::vector<std::unique_ptr<CallEdge>> call_edges;
4225 for (DWARFDIE child : function_die.children()) {
4226 if (child.Tag() != DW_TAG_call_site && child.Tag() != DW_TAG_GNU_call_site)
4227 continue;
4228
4229 std::optional<DWARFDIE> call_origin;
4230 std::optional<DWARFExpressionList> call_target;
4231 addr_t return_pc = LLDB_INVALID_ADDRESS;
4232 addr_t call_inst_pc = LLDB_INVALID_ADDRESS;
4234 bool tail_call = false;
4235
4236 // Second DW_AT_low_pc may come from DW_TAG_subprogram referenced by
4237 // DW_TAG_GNU_call_site's DW_AT_abstract_origin overwriting our 'low_pc'.
4238 // So do not inherit attributes from DW_AT_abstract_origin.
4239 DWARFAttributes attributes = child.GetAttributes(DWARFDIE::Recurse::no);
4240 for (size_t i = 0; i < attributes.Size(); ++i) {
4241 DWARFFormValue form_value;
4242 if (!attributes.ExtractFormValueAtIndex(i, form_value)) {
4243 LLDB_LOG(log, "CollectCallEdges: Could not extract TAG_call_site form");
4244 break;
4245 }
4246
4247 dw_attr_t attr = attributes.AttributeAtIndex(i);
4248
4249 if (attr == DW_AT_call_tail_call || attr == DW_AT_GNU_tail_call)
4250 tail_call = form_value.Boolean();
4251
4252 // Extract DW_AT_call_origin (the call target's DIE).
4253 if (attr == DW_AT_call_origin || attr == DW_AT_abstract_origin) {
4254 call_origin = form_value.Reference();
4255 if (!call_origin->IsValid()) {
4256 LLDB_LOG(log, "CollectCallEdges: Invalid call origin in {0}",
4257 function_die.GetPubname());
4258 break;
4259 }
4260 }
4261
4262 if (attr == DW_AT_low_pc)
4263 low_pc = form_value.Address();
4264
4265 // Extract DW_AT_call_return_pc (the PC the call returns to) if it's
4266 // available. It should only ever be unavailable for tail call edges, in
4267 // which case use LLDB_INVALID_ADDRESS.
4268 if (attr == DW_AT_call_return_pc)
4269 return_pc = form_value.Address();
4270
4271 // Extract DW_AT_call_pc (the PC at the call/branch instruction). It
4272 // should only ever be unavailable for non-tail calls, in which case use
4273 // LLDB_INVALID_ADDRESS.
4274 if (attr == DW_AT_call_pc)
4275 call_inst_pc = form_value.Address();
4276
4277 // Extract DW_AT_call_target (the location of the address of the indirect
4278 // call).
4279 if (attr == DW_AT_call_target || attr == DW_AT_GNU_call_site_target) {
4280 if (!DWARFFormValue::IsBlockForm(form_value.Form())) {
4281 LLDB_LOG(log,
4282 "CollectCallEdges: AT_call_target does not have block form");
4283 break;
4284 }
4285
4286 auto data = child.GetData();
4287 uint64_t block_offset = form_value.BlockData() - data.GetDataStart();
4288 uint64_t block_length = form_value.Unsigned();
4289 call_target = DWARFExpressionList(
4290 module, DataExtractor(data, block_offset, block_length),
4291 child.GetCU());
4292 }
4293 }
4294 if (!call_origin && !call_target) {
4295 LLDB_LOG(log, "CollectCallEdges: call site without any call target");
4296 continue;
4297 }
4298
4299 addr_t caller_address;
4300 CallEdge::AddrType caller_address_type;
4301 if (return_pc != LLDB_INVALID_ADDRESS) {
4302 caller_address = return_pc;
4303 caller_address_type = CallEdge::AddrType::AfterCall;
4304 } else if (low_pc != LLDB_INVALID_ADDRESS) {
4305 caller_address = low_pc;
4306 caller_address_type = CallEdge::AddrType::AfterCall;
4307 } else if (call_inst_pc != LLDB_INVALID_ADDRESS) {
4308 caller_address = call_inst_pc;
4309 caller_address_type = CallEdge::AddrType::Call;
4310 } else {
4311 LLDB_LOG(log, "CollectCallEdges: No caller address");
4312 continue;
4313 }
4314 // Adjust any PC forms. It needs to be fixed up if the main executable
4315 // contains a debug map (i.e. pointers to object files), because we need a
4316 // file address relative to the executable's text section.
4317 caller_address = FixupAddress(caller_address);
4318
4319 // Extract call site parameters.
4320 CallSiteParameterArray parameters =
4321 CollectCallSiteParameters(module, child);
4322
4323 std::unique_ptr<CallEdge> edge;
4324 if (call_origin) {
4325 LLDB_LOG(log,
4326 "CollectCallEdges: Found call origin: {0} (retn-PC: {1:x}) "
4327 "(call-PC: {2:x})",
4328 call_origin->GetPubname(), return_pc, call_inst_pc);
4329 edge = std::make_unique<DirectCallEdge>(
4330 call_origin->GetMangledName(), caller_address_type, caller_address,
4331 tail_call, std::move(parameters));
4332 } else {
4333 if (log) {
4334 StreamString call_target_desc;
4335 call_target->GetDescription(&call_target_desc, eDescriptionLevelBrief,
4336 nullptr);
4337 LLDB_LOG(log, "CollectCallEdges: Found indirect call target: {0}",
4338 call_target_desc.GetString());
4339 }
4340 edge = std::make_unique<IndirectCallEdge>(
4341 *call_target, caller_address_type, caller_address, tail_call,
4342 std::move(parameters));
4343 }
4344
4345 if (log && parameters.size()) {
4346 for (const CallSiteParameter &param : parameters) {
4347 StreamString callee_loc_desc, caller_loc_desc;
4348 param.LocationInCallee.GetDescription(&callee_loc_desc,
4349 eDescriptionLevelBrief, nullptr);
4350 param.LocationInCaller.GetDescription(&caller_loc_desc,
4351 eDescriptionLevelBrief, nullptr);
4352 LLDB_LOG(log, "CollectCallEdges: \tparam: {0} => {1}",
4353 callee_loc_desc.GetString(), caller_loc_desc.GetString());
4354 }
4355 }
4356
4357 call_edges.push_back(std::move(edge));
4358 }
4359 return call_edges;
4360}
4361
4362std::vector<std::unique_ptr<lldb_private::CallEdge>>
4364 // ParseCallEdgesInFunction must be called at the behest of an exclusively
4365 // locked lldb::Function instance. Storage for parsed call edges is owned by
4366 // the lldb::Function instance: locking at the SymbolFile level would be too
4367 // late, because the act of storing results from ParseCallEdgesInFunction
4368 // would be racy.
4369 DWARFDIE func_die = GetDIE(func_id.GetID());
4370 if (func_die.IsValid())
4371 return CollectCallEdges(GetObjectFile()->GetModule(), func_die);
4372 return {};
4373}
4374
4379
4380void SymbolFileDWARF::DumpClangAST(Stream &s, llvm::StringRef filter,
4381 bool show_color) {
4383 if (!ts_or_err)
4384 return;
4385 auto ts = *ts_or_err;
4386 TypeSystemClang *clang = llvm::dyn_cast_or_null<TypeSystemClang>(ts.get());
4387 if (!clang)
4388 return;
4389 clang->Dump(s.AsRawOstream(), filter, show_color);
4390}
4391
4393 DWARFDebugInfo &info = DebugInfo();
4394 const size_t num_cus = info.GetNumUnits();
4396 // Check if a .dwp file exists, returning it if it does.
4397 if (const auto &dwp_sp = GetDwpSymbolFile()) {
4398 if (ObjectFile *dwp_obj = dwp_sp->GetObjectFile()) {
4399 spec_list.Append(ModuleSpec(dwp_obj->GetFileSpec()));
4400 // Only one .dwp file is expected, so return early.
4401 return spec_list;
4402 }
4403 }
4404
4405 for (uint32_t cu_idx = 0; cu_idx < num_cus; ++cu_idx) {
4406 DWARFUnit *unit = info.GetUnitAtIndex(cu_idx);
4407 DWARFCompileUnit *dwarf_cu = llvm::dyn_cast<DWARFCompileUnit>(unit);
4408 if (dwarf_cu == nullptr || !dwarf_cu->GetDWOId().has_value())
4409 continue;
4410
4411 const DWARFBaseDIE die = dwarf_cu->GetUnitDIEOnly();
4412 if (!die)
4413 continue;
4414
4415 const char *dwo_name = GetDWOName(*dwarf_cu, *die.GetDIE());
4416 if (!dwo_name)
4417 continue;
4418
4419 lldb_private::FileSpec dwo_file(dwo_name);
4420 if (!dwo_file.IsAbsolute()) {
4421 const char *comp_dir = die.GetDIE()->GetAttributeValueAsString(
4422 dwarf_cu, DW_AT_comp_dir, nullptr);
4423 if (comp_dir)
4424 dwo_file.PrependPathComponent(comp_dir);
4425 }
4426 spec_list.Append(ModuleSpec(dwo_file));
4427 }
4428 return spec_list;
4429}
4430
4432 bool errors_only,
4433 bool load_all_debug_info) {
4434 StructuredData::Array separate_debug_info_files;
4435 DWARFDebugInfo &info = DebugInfo();
4436 const size_t num_cus = info.GetNumUnits();
4437 for (size_t cu_idx = 0; cu_idx < num_cus; cu_idx++) {
4438 DWARFUnit *unit = info.GetUnitAtIndex(cu_idx);
4439 DWARFCompileUnit *dwarf_cu = llvm::dyn_cast<DWARFCompileUnit>(unit);
4440 if (dwarf_cu == nullptr)
4441 continue;
4442
4443 // Check if this is a DWO unit by checking if it has a DWO ID.
4444 // NOTE: it seems that `DWARFUnit::IsDWOUnit` is always false?
4445 if (!dwarf_cu->GetDWOId().has_value())
4446 continue;
4447
4449 std::make_shared<StructuredData::Dictionary>();
4450 const uint64_t dwo_id = dwarf_cu->GetDWOId().value();
4451 dwo_data->AddIntegerItem("dwo_id", dwo_id);
4452
4453 if (const DWARFBaseDIE die = dwarf_cu->GetUnitDIEOnly()) {
4454 const char *dwo_name = GetDWOName(*dwarf_cu, *die.GetDIE());
4455 if (dwo_name) {
4456 dwo_data->AddStringItem("dwo_name", dwo_name);
4457 } else {
4458 dwo_data->AddStringItem("error", "missing dwo name");
4459 }
4460
4461 const char *comp_dir = die.GetDIE()->GetAttributeValueAsString(
4462 dwarf_cu, DW_AT_comp_dir, nullptr);
4463 if (comp_dir) {
4464 dwo_data->AddStringItem("comp_dir", comp_dir);
4465 }
4466 } else {
4467 dwo_data->AddStringItem(
4468 "error",
4469 llvm::formatv("unable to get unit DIE for DWARFUnit at {0:x}",
4470 dwarf_cu->GetOffset())
4471 .str());
4472 }
4473
4474 // If we have a DWO symbol file, that means we were able to successfully
4475 // load it.
4476 SymbolFile *dwo_symfile = dwarf_cu->GetDwoSymbolFile(load_all_debug_info);
4477 if (dwo_symfile) {
4478 dwo_data->AddStringItem(
4479 "resolved_dwo_path",
4480 dwo_symfile->GetObjectFile()->GetFileSpec().GetPath());
4481 } else {
4482 dwo_data->AddStringItem("error",
4483 dwarf_cu->GetDwoError().AsCString("unknown"));
4484 }
4485 dwo_data->AddBooleanItem("loaded", dwo_symfile != nullptr);
4486 if (!errors_only || dwo_data->HasKey("error"))
4487 separate_debug_info_files.AddItem(dwo_data);
4488 }
4489
4490 d.AddStringItem("type", "dwo");
4491 d.AddStringItem("symfile", GetMainObjectFile()->GetFileSpec().GetPath());
4492 d.AddItem("separate-debug-info-files",
4493 std::make_shared<StructuredData::Array>(
4494 std::move(separate_debug_info_files)));
4495 return true;
4496}
4497
4499 if (m_debug_map_symfile == nullptr) {
4500 lldb::ModuleSP module_sp(m_debug_map_module_wp.lock());
4501 if (module_sp) {
4502 m_debug_map_symfile = llvm::cast<SymbolFileDWARFDebugMap>(
4503 module_sp->GetSymbolFile()->GetBackingSymbolFile());
4504 }
4505 }
4506 return m_debug_map_symfile;
4507}
4508
4509const std::shared_ptr<SymbolFileDWARFDwo> &SymbolFileDWARF::GetDwpSymbolFile() {
4510 llvm::call_once(m_dwp_symfile_once_flag, [this]() {
4511 if (m_objfile_sp->GetArchitecture().GetTriple().isAppleMachO())
4512 return;
4513
4514 // Create a list of files to try and append .dwp to.
4515 FileSpecList symfiles;
4516 // Append the module's object file path.
4517 const FileSpec module_fspec = m_objfile_sp->GetModule()->GetFileSpec();
4518 symfiles.Append(module_fspec);
4519 // Append the object file for this SymbolFile only if it is different from
4520 // the module's file path. Our main module could be "a.out", our symbol file
4521 // could be "a.debug" and our ".dwp" file might be "a.debug.dwp" instead of
4522 // "a.out.dwp".
4523 const FileSpec symfile_fspec(m_objfile_sp->GetFileSpec());
4524 if (symfile_fspec != module_fspec) {
4525 symfiles.Append(symfile_fspec);
4526 } else {
4527 // If we don't have a separate debug info file, then try stripping the
4528 // extension. The main module could be "a.debug" and the .dwp file could
4529 // be "a.dwp" instead of "a.debug.dwp".
4530 llvm::StringRef filename_no_ext =
4531 module_fspec.GetFileNameStrippingExtension();
4532 if (filename_no_ext != module_fspec.GetFilename()) {
4533 FileSpec module_spec_no_ext(module_fspec);
4534 module_spec_no_ext.SetFilename(filename_no_ext);
4535 symfiles.Append(module_spec_no_ext);
4536 }
4537 }
4540 ModuleSpec module_spec;
4541 module_spec.GetFileSpec() = m_objfile_sp->GetFileSpec();
4542 FileSpec dwp_filespec;
4543 for (const auto &symfile : symfiles.files()) {
4544 module_spec.GetSymbolFileSpec() =
4545 FileSpec(symfile.GetPath() + ".dwp", symfile.GetPathStyle());
4546 LLDB_LOG(log, "Searching for DWP using: \"{0}\"",
4547 module_spec.GetSymbolFileSpec());
4549 module_spec, search_paths,
4550 m_objfile_sp->GetModule()->GetSymbolLocatorStatistics());
4551 if (FileSystem::Instance().Exists(dwp_filespec)) {
4552 break;
4553 }
4554 }
4555 if (!FileSystem::Instance().Exists(dwp_filespec)) {
4556 LLDB_LOG(log, "No DWP file found locally");
4557 // Fill in the UUID for the module we're trying to match for, so we can
4558 // find the correct DWP file, as the Debuginfod plugin uses *only* this
4559 // data to correctly match the DWP file with the binary.
4560 module_spec.GetUUID() = m_objfile_sp->GetUUID();
4562 module_spec, search_paths,
4563 m_objfile_sp->GetModule()->GetSymbolLocatorStatistics());
4564 }
4565 if (FileSystem::Instance().Exists(dwp_filespec)) {
4566 LLDB_LOG(log, "Found DWP file: \"{0}\"", dwp_filespec);
4567 DataExtractorSP dwp_file_extractor_sp;
4568 lldb::offset_t dwp_file_data_offset = 0;
4569 ObjectFileSP dwp_obj_file = ObjectFile::FindPlugin(
4570 GetObjectFile()->GetModule(), &dwp_filespec, 0,
4571 FileSystem::Instance().GetByteSize(dwp_filespec),
4572 dwp_file_extractor_sp, dwp_file_data_offset);
4573 if (dwp_obj_file) {
4574 m_dwp_symfile = std::make_shared<SymbolFileDWARFDwo>(
4575 *this, dwp_obj_file, DIERef::k_file_index_mask);
4576 }
4577 }
4578 if (!m_dwp_symfile) {
4579 LLDB_LOG(log, "Unable to locate for DWP file for: \"{0}\"",
4580 m_objfile_sp->GetModule()->GetFileSpec());
4581 }
4582 });
4583 return m_dwp_symfile;
4584}
4585
4586llvm::Expected<lldb::TypeSystemSP>
4590
4592 auto type_system_or_err = GetTypeSystem(unit);
4593 if (auto err = type_system_or_err.takeError()) {
4594 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
4595 "Unable to get DWARFASTParser: {0}");
4596 return nullptr;
4597 }
4598 if (auto ts = *type_system_or_err)
4599 return ts->GetDWARFParser();
4600 return nullptr;
4601}
4602
4604 if (DWARFASTParser *dwarf_ast = GetDWARFParser(*die.GetCU()))
4605 return dwarf_ast->GetDeclForUIDFromDWARF(die);
4606 return CompilerDecl();
4607}
4608
4610 if (DWARFASTParser *dwarf_ast = GetDWARFParser(*die.GetCU()))
4611 return dwarf_ast->GetDeclContextForUIDFromDWARF(die);
4612 return CompilerDeclContext();
4613}
4614
4617 if (DWARFASTParser *dwarf_ast = GetDWARFParser(*die.GetCU()))
4618 return dwarf_ast->GetDeclContextContainingUIDFromDWARF(die);
4619 return CompilerDeclContext();
4620}
4621
4624 return static_cast<LanguageType>(val);
4625
4626 // Note: user languages between lo_user and hi_user must be handled
4627 // explicitly here.
4628 switch (val) {
4629 case DW_LANG_Mips_Assembler:
4631 default:
4632 return eLanguageTypeUnknown;
4633 }
4634}
4635
4639
4641 auto lang = (llvm::dwarf::SourceLanguage)unit.GetDWARFLanguageType();
4642 if (llvm::dwarf::isCPlusPlus(lang))
4643 lang = DW_LANG_C_plus_plus;
4644 return LanguageTypeFromDWARF(lang);
4645}
4646
4648 if (m_index)
4649 return m_index->GetIndexTime();
4650 return {};
4651}
4652
4654 m_parse_time.reset();
4655 if (m_index)
4656 return m_index->ResetStatistics();
4657}
4658
4660 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
4661 CompileUnit *cu = frame.GetSymbolContext(eSymbolContextCompUnit).comp_unit;
4662 if (!cu)
4663 return Status();
4664
4665 DWARFCompileUnit *dwarf_cu = GetDWARFCompileUnit(cu);
4666 if (!dwarf_cu)
4667 return Status();
4668
4669 // Check if we have a skeleton compile unit that had issues trying to load
4670 // its .dwo/.dwp file. First pares the Unit DIE to make sure we see any .dwo
4671 // related errors.
4672 dwarf_cu->ExtractUnitDIEIfNeeded();
4673 const Status &dwo_error = dwarf_cu->GetDwoError();
4674 if (dwo_error.Fail())
4675 return dwo_error.Clone();
4676
4677 // Don't return an error for assembly files as they typically don't have
4678 // varaible information.
4679 if (dwarf_cu->GetDWARFLanguageType() == DW_LANG_Mips_Assembler)
4680 return Status();
4681
4682 // Check if this compile unit has any variable DIEs. If it doesn't then there
4683 // is not variable information for the entire compile unit.
4684 if (dwarf_cu->HasAny({DW_TAG_variable, DW_TAG_formal_parameter}))
4685 return Status();
4686
4688 "no variable information is available in debug info for this "
4689 "compile unit");
4690}
4691
4693 std::unordered_map<lldb::CompUnitSP, lldb_private::Args> &args) {
4694
4695 const uint32_t num_compile_units = GetNumCompileUnits();
4696
4697 for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx) {
4698 lldb::CompUnitSP comp_unit = GetCompileUnitAtIndex(cu_idx);
4699 if (!comp_unit)
4700 continue;
4701
4702 DWARFUnit *dwarf_cu = GetDWARFCompileUnit(comp_unit.get());
4703 if (!dwarf_cu)
4704 continue;
4705
4706 const DWARFBaseDIE die = dwarf_cu->GetUnitDIEOnly();
4707 if (!die)
4708 continue;
4709
4710 const char *flags = die.GetAttributeValueAsString(DW_AT_APPLE_flags, NULL);
4711
4712 if (!flags)
4713 continue;
4714 args.insert({comp_unit, Args(flags)});
4715 }
4716}
4717
4719 DWOStats stats;
4720
4721 DWARFDebugInfo &info = DebugInfo();
4722 const size_t num_cus = info.GetNumUnits();
4723 for (size_t cu_idx = 0; cu_idx < num_cus; cu_idx++) {
4724 DWARFUnit *dwarf_cu = info.GetUnitAtIndex(cu_idx);
4725 if (dwarf_cu == nullptr)
4726 continue;
4727
4728 // Check if this is a DWO unit by checking if it has a DWO ID.
4729 if (!dwarf_cu->GetDWOId().has_value())
4730 continue;
4731
4732 stats.dwo_file_count++;
4733
4734 // If we have a DWO symbol file, that means we were able to successfully
4735 // load it.
4736 SymbolFile *dwo_symfile =
4737 dwarf_cu->GetDwoSymbolFile(/*load_all_debug_info=*/false);
4738 if (dwo_symfile) {
4739 stats.loaded_dwo_file_count++;
4740 }
4741
4742 // Check if this unit has a DWO load error, false by default.
4743 const Status &dwo_error = dwarf_cu->GetDwoError();
4744 if (dwo_error.Fail())
4745 stats.dwo_error_count++;
4746 }
4747
4748 return stats;
4749}
4750
4752 DWARFDIE die = GetDIE(uid);
4753
4754 if (die.Tag() != DW_TAG_variable)
4755 return nullptr;
4756
4758}
static llvm::raw_ostream & error(Stream &strm)
#define DEBUG_PRINTF(fmt,...)
static PluginProperties & GetGlobalPluginProperties()
#define lldbassert(x)
Definition LLDBAssert.h:16
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
Definition Log.h:375
#define LLDB_LOG_ERRORV(log, error,...)
Definition Log.h:421
#define LLDB_LOGF(log,...)
Definition Log.h:389
#define LLDB_LOG_ERROR(log, error,...)
Definition Log.h:405
#define LLDB_PLUGIN_DEFINE(PluginName)
static double elapsed(const StatsTimepoint &start, const StatsTimepoint &end)
static PluginProperties & GetGlobalPluginProperties()
static bool UpdateCompilerContextForSimpleTemplateNames(TypeQuery &match)
static ConstString GetDWARFMachOSegmentName()
static DWARFExpressionList GetExprListFromAtConstValue(DWARFFormValue form_value, ModuleSP module, const DWARFDIE &die)
Creates a DWARFExpressionList from an DW_AT_const_value.
static llvm::StringRef ClangToItaniumCtorKind(clang::CXXCtorType kind)
static void ParseSupportFilesFromPrologue(SupportFileList &support_files, const lldb::ModuleSP &module, const llvm::DWARFDebugLine::Prologue &prologue, FileSpec::Style style, llvm::StringRef compile_dir={})
static std::optional< uint64_t > GetByteSizeFromTypeDIE(DWARFDIE die, unsigned max_depth=64)
Walks transparent type wrappers following DW_AT_type and returns the first DW_AT_byte_size encountere...
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 llvm::StringRef GetItaniumCtorDtorVariant(llvm::StringRef discriminator)
static const llvm::DWARFDebugLine::LineTable * ParseLLVMLineTable(DWARFContext &context, llvm::DWARFDebugLine &line, dw_offset_t line_offset, dw_offset_t unit_offset)
bool IsStructOrClassTag(llvm::dwarf::Tag Tag)
static bool SplitTemplateParams(llvm::StringRef fullname, llvm::StringRef &basename, llvm::StringRef &template_params)
Split a name up into a basename and template parameters.
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::set< dw_form_t > GetUnsupportedForms(llvm::DWARFDebugAbbrev *debug_abbrev)
static std::optional< std::string > GetFileByIndex(const llvm::DWARFDebugLine::Prologue &prologue, size_t idx, llvm::StringRef compile_dir, FileSpec::Style style)
static llvm::StringRef ClangToItaniumDtorKind(clang::CXXDtorType kind)
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 bool ParseLLVMLineTablePrologue(DWARFContext &context, llvm::DWARFDebugLine::Prologue &prologue, dw_offset_t line_offset, dw_offset_t unit_offset)
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:40
#define LLDB_SCOPED_TIMER()
Definition Timer.h:83
#define LLDB_SCOPED_TIMERF(...)
Definition Timer.h:86
A section + offset based address class.
Definition Address.h:62
lldb::SectionSP GetSection() const
Get const accessor for the section.
Definition Address.h:426
lldb::addr_t GetFileAddress() const
Get the file address.
Definition Address.cpp:283
lldb::addr_t GetOffset() const
Get the section relative offset value.
Definition Address.h:329
bool IsSectionOffset() const
Check if an address is section offset.
Definition Address.h:342
A command line argument class.
Definition Args.h:33
A class that describes a single lexical block.
Definition Block.h:41
RangeList::Entry Range
Definition Block.h:44
lldb::VariableListSP GetBlockVariableList(bool can_create)
Get the variable list for this block only.
Definition Block.cpp:382
lldb::BlockSP CreateChild(lldb::user_id_t uid)
Creates a block with the specified UID uid.
Definition Block.cpp:370
Block * FindBlockByID(lldb::user_id_t block_id)
Definition Block.cpp:113
void SetVariableList(lldb::VariableListSP &variable_list_sp)
Set accessor for the variable list.
Definition Block.h:310
void SetDidParseVariables(bool b, bool set_children)
Definition Block.cpp:479
void AddRange(const Range &range)
Add a new offset range to this block.
Definition Block.cpp:331
void FinalizeRanges()
Definition Block.cpp:326
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:375
static bool ExtractContextAndIdentifier(llvm::StringRef name, llvm::StringRef &context, llvm::StringRef &identifier)
static llvm::Expected< ConstString > SubstituteStructor_ItaniumMangle(llvm::StringRef mangled_name, llvm::StringRef subst_from, llvm::StringRef subst_to)
Substitutes Itanium structor encoding substrings given by subst_from in mangled_name with subst_to.
static llvm::Expected< ConstString > SubstituteStructorAliases_ItaniumMangle(llvm::StringRef mangled_name)
Tries replacing Itanium structor encoding substrings in mangled_name with potential aliases....
Checksum(llvm::MD5::MD5Result md5=g_sentinel)
Definition Checksum.cpp:15
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:43
void SetVariableList(lldb::VariableListSP &variable_list_sp)
Set accessor for the variable list.
const SupportFileList & GetSupportFiles()
Get the compile unit's support file list.
lldb::VariableListSP GetVariableList(bool can_create)
Get the variable list for a compile unit.
void SetDebugMacros(const DebugMacrosSP &debug_macros)
const FileSpec & GetPrimaryFile() const
Return the primary source spec associated with this compile unit.
void ResolveSymbolContext(const SourceLocationSpec &src_location_spec, lldb::SymbolContextItem resolve_scope, SymbolContextList &sc_list, RealpathPrefixes *realpath_prefixes=nullptr)
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.
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.
Generic representation of a type in a programming language.
TypeSystemSPWrapper GetTypeSystem() const
Accessors.
lldb::opaque_compiler_type_t GetOpaqueQualType() const
A uniqued constant string class.
Definition ConstString.h:40
bool IsEmpty() const
Test for empty string.
llvm::StringRef GetStringRef() const
Get the string value as a llvm::StringRef.
const char * GetCString() const
Get the string value as a C string.
const char * AsCString(const char *value_if_empty) const
Get the string value as a C string.
llvm::DWARFDataExtractor GetAsLLVMDWARF() const
"lldb/Expression/DWARFExpressionList.h" Encapsulates a range map from file address range to a single ...
llvm::Expected< Value > Evaluate(ExecutionContext *exe_ctx, RegisterContext *reg_ctx, lldb::addr_t func_load_addr, const Value *initial_value_ptr, const Value *object_address_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.
void UpdateValue(uint64_t const_value, lldb::offset_t const_value_byte_size, uint8_t addr_byte_size)
bool Update_DW_OP_addr(const Delegate *dwarf_cu, lldb::addr_t file_addr)
An data extractor class.
void Clear()
Clears the object state.
virtual uint64_t GetByteSize() const
Get the number of bytes contained in this object.
llvm::DataExtractor GetAsLLVM() const
const uint8_t * GetDataStart() const
Get the data start pointer.
bool ValidOffset(lldb::offset_t offset) const
Test the validity of offset.
A class to manage flag bits.
Definition Debugger.h:100
A class that describes the declaration location of a lldb object.
Definition Declaration.h:24
void SetLine(uint32_t line)
Set accessor for the declaration line number.
void SetColumn(uint16_t column)
Set accessor for the declaration column number.
void SetFile(const FileSpec &file_spec)
Set accessor for the declaration file specification.
A class that measures elapsed time in an exception safe way.
Definition Statistics.h:76
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
A file collection class.
llvm::iterator_range< const_iterator > files() const
const FileSpec & GetFileSpecAtIndex(size_t idx) const
Get file at index.
void Append(const FileSpec &file)
Append a FileSpec object to the list.
size_t GetSize() const
Get the number of files in the file list.
A file utility class.
Definition FileSpec.h:56
void SetFile(llvm::StringRef path, Style style)
Change the file specified with a new path.
Definition FileSpec.cpp:174
void AppendPathComponent(llvm::StringRef component)
Definition FileSpec.cpp:454
static bool Match(const FileSpec &pattern, const FileSpec &file)
Match FileSpec pattern against FileSpec file.
Definition FileSpec.cpp:317
bool IsRelative() const
Returns true if the filespec represents a relative path.
Definition FileSpec.cpp:514
llvm::StringRef GetFileNameStrippingExtension() const
Return the filename without the extension part.
Definition FileSpec.cpp:414
void SetFilename(llvm::StringRef filename)
Filename string set accessor.
Definition FileSpec.cpp:363
void MakeAbsolute(const FileSpec &dir)
Make the FileSpec absolute by treating it relative to dir.
Definition FileSpec.cpp:537
void SetPath(llvm::StringRef p)
Temporary helper for FileSystem change.
Definition FileSpec.h:286
llvm::StringRef GetFilename() const
Filename string const get accessor.
Definition FileSpec.h:248
bool IsAbsolute() const
Returns true if the filespec represents an absolute path.
Definition FileSpec.cpp:518
void PrependPathComponent(llvm::StringRef component)
Definition FileSpec.cpp:440
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
Definition FileSpec.cpp:380
llvm::sys::path::Style Style
Definition FileSpec.h:58
bool Exists(const FileSpec &file_spec) const
Returns whether the given file exists.
static FileSystem & Instance()
void Resolve(llvm::SmallVectorImpl< char > &path, bool force_make_absolute=false)
Resolve path to make it canonical.
A class that describes a function.
Definition Function.h:377
lldb::ModuleSP CalculateSymbolContextModule() override
Definition Function.cpp:476
CompileUnit * GetCompileUnit()
Get accessor for the compile unit that owns this function.
Definition Function.cpp:418
Block & GetBlock(bool can_create)
Get accessor for the block list.
Definition Function.cpp:403
static const char * GetNameForLanguageType(lldb::LanguageType language)
Returns the internal LLDB name for the specified language.
Definition Language.cpp:305
static bool LanguageIsCPlusPlus(lldb::LanguageType language)
Definition Language.cpp:342
static void AppendLineEntryToSequence(Sequence &sequence, lldb::addr_t file_addr, uint32_t line, uint16_t column, uint16_t file_idx, bool is_start_of_statement, bool is_start_of_basic_block, bool is_prologue_end, bool is_epilogue_begin, bool is_terminal_entry)
Definition LineTable.cpp:59
bool FindLineEntryByAddress(const Address &so_addr, LineEntry &line_entry, uint32_t *index_ptr=nullptr)
Find a line entry that contains the section offset address so_addr.
static Mangled::ManglingScheme GetManglingScheme(llvm::StringRef name)
Try to identify the mangling scheme used.
Definition Mangled.cpp:43
lldb::ModuleSP GetModule() const
Get const accessor for the module pointer.
static Status GetSharedModule(const ModuleSpec &module_spec, lldb::ModuleSP &module_sp, llvm::SmallVectorImpl< lldb::ModuleSP > *old_modules, bool *did_create_ptr, bool invoke_locate_callback=true, bool invoke_symbol_locators=true)
void Append(const ModuleSpec &spec)
Definition ModuleSpec.h:371
FileSpec & GetFileSpec()
Definition ModuleSpec.h:57
ArchSpec & GetArchitecture()
Definition ModuleSpec.h:93
FileSpec & GetSymbolFileSpec()
Definition ModuleSpec.h:81
A class that encapsulates name lookup information.
Definition Module.h:935
lldb::FunctionNameType GetNameTypeMask() const
Definition Module.h:976
ConstString GetLookupName() const
Definition Module.h:974
static std::vector< LookupInfo > MakeLookupInfos(ConstString name, lldb::FunctionNameType name_type_mask, lldb::LanguageType lang_type, ConstString lookup_name_override={})
Creates a vector of lookup infos for function name resolution.
Definition Module.cpp:683
A class that describes an executable image and its associated object and symbol files.
Definition Module.h:91
A plug-in interface definition class for object file parsers.
Definition ObjectFile.h:46
static lldb::ObjectFileSP FindPlugin(const lldb::ModuleSP &module_sp, const FileSpec *file_spec, lldb::offset_t file_offset, lldb::offset_t file_size, lldb::DataExtractorSP extractor_sp, lldb::offset_t &data_offset)
Find a ObjectFile plug-in that can parse file_spec.
Symtab * GetSymtab(bool can_create=true)
Gets the symbol table for the currently selected architecture (and object for archives).
@ eTypeDebugInfo
An object file that contains only debug information.
Definition ObjectFile.h:57
virtual FileSpec & GetFileSpec()
Get accessor to the object file specification.
Definition ObjectFile.h:280
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description, ABICreateInstance create_callback)
static FileSpec LocateExecutableSymbolFile(const ModuleSpec &module_spec, const FileSpecList &default_search_paths, StatisticsMap &map)
static bool CreateSettingForSymbolFilePlugin(Debugger &debugger, const lldb::OptionValuePropertiesSP &properties_sp, llvm::StringRef description, bool is_global_property)
static lldb::OptionValuePropertiesSP GetSettingForSymbolFilePlugin(Debugger &debugger, llvm::StringRef setting_name)
static bool UnregisterPlugin(ABICreateInstance create_callback)
A Progress indicator helper class.
Definition Progress.h:60
RangeData< lldb::addr_t, lldb::addr_t, Variable * > Entry
Definition RangeMap.h:462
llvm::StringRef GetText() const
Access the regular expression text.
lldb::SectionSP FindSectionByName(llvm::StringRef section_name) const
Definition Section.cpp:562
lldb::SectionSP FindSectionByType(lldb::SectionType sect_type, bool check_children, size_t start_idx=0) const
Definition Section.cpp:602
SectionList & GetChildren()
Definition Section.h:167
lldb::offset_t GetFileSize() const
Definition Section.h:187
This base class provides an interface to stack frames.
Definition StackFrame.h:44
virtual const SymbolContext & GetSymbolContext(lldb::SymbolContextItem resolve_scope)
Provide a SymbolContext for this StackFrame's current pc value.
std::chrono::duration< double > Duration
Definition Statistics.h:37
An error handling class.
Definition Status.h:118
Status Clone() const
Don't call this function in new code.
Definition Status.h:174
static Status FromErrorString(const char *str)
Definition Status.h:141
bool Fail() const
Test for error condition.
Definition Status.cpp:293
const char * AsCString(const char *default_error_str="unknown error") const
Get the error string associated with the current error.
Definition Status.cpp:194
static Status static Status FromErrorStringWithFormatv(const char *format, Args &&...args)
Definition Status.h:151
const char * GetData() const
llvm::StringRef GetString() const
A stream class that can stream formatted output to a file.
Definition Stream.h:28
llvm::raw_ostream & AsRawOstream()
Returns a raw_ostream that forwards the data to this Stream object.
Definition Stream.h:405
void AddItem(const ObjectSP &item)
void AddStringItem(llvm::StringRef key, llvm::StringRef value)
void AddItem(llvm::StringRef key, ObjectSP value_sp)
std::shared_ptr< Dictionary > DictionarySP
A list of support files for a CompileUnit.
const FileSpec & GetFileSpecAtIndex(size_t idx) const
void Append(const FileSpec &file)
SupportFileNSP GetSupportFileAtIndex(size_t idx) const
void EmplaceBack(Args &&...args)
Wraps a FileSpec and an optional Checksum.
Definition SupportFile.h:22
virtual const FileSpec & Materialize()
Materialize the file to disk and return the path to that temporary file.
Definition SupportFile.h:73
Defines a list of symbol context objects.
uint32_t GetSize() const
Get accessor for a symbol context list size.
bool AppendIfUnique(const SymbolContext &sc, bool merge_symbol_into_function)
"lldb/Symbol/SymbolContextScope.h" Inherit from this if your object is part of a symbol context and c...
virtual CompileUnit * CalculateSymbolContextCompileUnit()
virtual void CalculateSymbolContext(SymbolContext *sc)=0
Reconstruct the object's symbol context into sc.
Defines a symbol context baton that can be handed other debug core functions.
Function * function
The Function for a given query.
Block * block
The Block for a given query.
lldb::ModuleSP module_sp
The Module for a given query.
CompileUnit * comp_unit
The CompileUnit for a given query.
void Clear(bool clear_target)
Clear the object's state.
Variable * variable
The global variable matching the given query.
LineEntry line_entry
The LineEntry for a given query.
lldb::CompUnitSP GetCompileUnitAtIndex(uint32_t idx) override
ObjectFile * GetObjectFile() override
Definition SymbolFile.h:588
virtual TypeList & GetTypeList()
Definition SymbolFile.h:661
lldb::ObjectFileSP m_objfile_sp
Definition SymbolFile.h:664
ObjectFile * GetMainObjectFile() override
void SetCompileUnitAtIndex(uint32_t idx, const lldb::CompUnitSP &cu_sp)
SymbolFileCommon(lldb::ObjectFileSP objfile_sp)
Definition SymbolFile.h:573
Symtab * GetSymtab(bool can_create=true) override
llvm::Expected< lldb::TypeSystemSP > GetTypeSystemForLanguage(lldb::LanguageType language) override
uint32_t GetNumCompileUnits() override
void Dump(Stream &s) override
uint64_t GetDebugInfoSize(bool load_all_debug_info=false) override
Metrics gathering functions.
std::unordered_map< lldb::CompUnitSP, Args > GetCompileOptions()
Returns a map of compilation unit to the compile option arguments associated with that compilation un...
Definition SymbolFile.h:532
virtual ObjectFile * GetObjectFile()=0
bool ValueIsAddress() const
Definition Symbol.cpp:191
Address & GetAddressRef()
Definition Symbol.h:78
Symbol * FindFirstSymbolWithNameAndType(ConstString name, lldb::SymbolType symbol_type, Debug symbol_debug_type, Visibility symbol_visibility)
Definition Symtab.cpp:860
static FileSpecList GetDefaultDebugFileSearchPaths()
Definition Target.cpp:2905
void Insert(const lldb::TypeSP &type)
Definition TypeList.cpp:27
uint32_t GetSize() const
Definition TypeMap.cpp:51
A class that contains all state required for type lookups.
Definition Type.h:104
bool GetModuleSearch() const
The m_context can be used in two ways: normal types searching with the context containing a stanadard...
Definition Type.h:294
std::vector< lldb_private::CompilerContext > & GetContextRef()
Access the internal compiler context array.
Definition Type.h:322
ConstString GetTypeBasename() const
Get the type basename to use when searching the type indexes in each SymbolFile object.
Definition Type.cpp:114
bool ContextMatches(llvm::ArrayRef< lldb_private::CompilerContext > context) const
Check of a CompilerContext array from matching type from a symbol file matches the m_context.
Definition Type.cpp:130
bool GetSearchByMangledName() const
Returns true if the type query is supposed to treat the name to be searched as a mangled name.
Definition Type.h:308
This class tracks the state and results of a TypeQuery.
Definition Type.h:344
bool InsertUnique(const lldb::TypeSP &type_sp)
When types that match a TypeQuery are found, this API is used to insert the matching types.
Definition Type.cpp:195
TypeMap & GetTypeMap()
Definition Type.h:386
bool Done(const TypeQuery &query) const
Check if the type matching has found all of the matches that it needs.
Definition Type.cpp:201
bool AlreadySearched(lldb_private::SymbolFile *sym_file)
Check if a SymbolFile object has already been searched by this type match object.
Definition Type.cpp:191
A TypeSystem implementation based on Clang.
Interface for representing a type system.
Definition TypeSystem.h:72
virtual lldb::LanguageType GetMinimumLanguage(lldb::opaque_compiler_type_t type)=0
virtual plugin::dwarf::DWARFASTParser * GetDWARFParser()
Definition TypeSystem.h:91
ConstString GetName()
Definition Type.cpp:442
@ FileAddress
A file address value.
Definition Value.h:48
bool AddVariableIfUnique(const lldb::VariableSP &var_sp)
lldb::VariableSP GetVariableAtIndex(size_t idx) const
lldb::VariableSP RemoveVariableAtIndex(size_t idx)
SymbolContextScope * GetSymbolContextScope() const
Definition Variable.h:52
RangeVector< lldb::addr_t, lldb::addr_t > RangeList
Definition Variable.h:27
An abstraction for Xcode-style SDKs that works like ArchSpec.
Definition XcodeSDK.h:25
static std::unique_ptr< AppleDWARFIndex > Create(Module &module, DWARFDataExtractor apple_names, DWARFDataExtractor apple_namespaces, DWARFDataExtractor apple_types, DWARFDataExtractor apple_objc, DWARFDataExtractor debug_str)
Identifies a DWARF debug info entry within a given Module.
Definition DIERef.h:31
std::optional< uint32_t > file_index() const
Definition DIERef.h:60
static constexpr uint64_t k_file_index_mask
Definition DIERef.h:120
dw_offset_t die_offset() const
Definition DIERef.h:68
virtual void EnsureAllDIEsInDeclContextHaveBeenParsed(CompilerDeclContext decl_context)=0
virtual bool CompleteTypeFromDWARF(const DWARFDIE &die, Type *type, const CompilerType &compiler_type)=0
virtual std::string GetDIEClassTemplateParams(DWARFDIE die)=0
virtual Function * ParseFunctionFromDWARF(CompileUnit &comp_unit, const DWARFDIE &die, AddressRanges ranges)=0
virtual ConstString ConstructDemangledNameFromDWARF(const DWARFDIE &die)=0
virtual lldb::TypeSP ParseTypeFromDWARF(const SymbolContext &sc, const DWARFDIE &die, bool *type_is_new_ptr)=0
static std::optional< SymbolFile::ArrayInfo > ParseChildArrayInfo(const DWARFDIE &parent_die, const ExecutionContext *exe_ctx=nullptr)
virtual CompilerDeclContext GetDeclContextForUIDFromDWARF(const DWARFDIE &die)=0
DWARFUnit * CompileUnitAtIndex(uint32_t i) const
dw_attr_t AttributeAtIndex(uint32_t i) const
bool ExtractFormValueAtIndex(uint32_t i, DWARFFormValue &form_value) const
DWARFAttributes GetAttributes(Recurse recurse=Recurse::yes) const
std::optional< uint64_t > GetAttributeValueAsOptionalUnsigned(const dw_attr_t attr) const
const DWARFDataExtractor & GetData() const
const char * GetAttributeValueAsString(const dw_attr_t attr, const char *fail_value) const
std::optional< DIERef > GetDIERef() const
DWARFDebugInfoEntry * GetDIE() const
uint64_t GetAttributeValueAsUnsigned(const dw_attr_t attr, uint64_t fail_value) const
DWARFDIE LookupAddress(const dw_addr_t address)
const DWARFDataExtractor & getOrLoadLineData()
const char * GetMangledName(bool substitute_name_allowed=true) const
Definition DWARFDIE.cpp:212
bool GetDIENamesAndRanges(const char *&name, const char *&mangled, llvm::DWARFAddressRangesVector &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, DWARFExpressionList *frame_base) const
Definition DWARFDIE.cpp:584
DWARFDIE GetDIE(dw_offset_t die_offset) const
Definition DWARFDIE.cpp:126
llvm::iterator_range< child_iterator > children() const
The range of all the children of this DIE.
Definition DWARFDIE.cpp:601
std::vector< CompilerContext > GetDeclContext(bool derive_template_names=false) const
Return this DIE's decl context as it is needed to look up types in Clang modules.
Definition DWARFDIE.cpp:456
DWARFDIE LookupDeepestBlock(lldb::addr_t file_addr) const
Definition DWARFDIE.cpp:147
DWARFDIE GetAttributeValueAsReferenceDIE(const dw_attr_t attr) const
Definition DWARFDIE.cpp:134
DWARFDeclContext GetDWARFDeclContext() const
Definition DWARFDIE.cpp:526
DWARFDIE GetReferencedDIE(const dw_attr_t attr) const
Definition DWARFDIE.cpp:118
std::vector< CompilerContext > GetTypeLookupContext(bool derive_template_names=false) const
Get a context to a type so it can be looked up.
Definition DWARFDIE.cpp:503
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_elaborating_dies=false) const
const char * GetAttributeValueAsString(const DWARFUnit *cu, const dw_attr_t attr, const char *fail_value, bool check_elaborating_dies=false) const
DWARFUnit * GetSkeletonUnit(DWARFUnit *dwo_unit)
DWARFUnit * GetUnitAtOffset(DIERef::Section section, dw_offset_t cu_offset, uint32_t *idx_ptr=nullptr)
const DWARFDebugAranges & GetCompileUnitAranges()
DWARFDIE GetDIE(DIERef::Section section, dw_offset_t die_offset)
static void ReadMacroEntries(const DWARFDataExtractor &debug_macro_data, const DWARFDataExtractor &debug_str_data, const bool offset_is_64_bit, lldb::offset_t *sect_offset, SymbolFileDWARF *sym_file_dwarf, DebugMacrosSP &debug_macros_sp)
static DWARFDebugMacroHeader ParseHeader(const DWARFDataExtractor &debug_macro_data, lldb::offset_t *offset)
void AppendDeclContext(dw_tag_t tag, const char *name)
static bool IsDataForm(const dw_form_t form)
static bool IsBlockForm(const dw_form_t form)
SymbolFileDWARF & GetSymbolFileDWARF() const
Definition DWARFUnit.h:201
DWARFCompileUnit * GetSkeletonUnit()
Get the skeleton compile unit for a DWO file.
const Status & GetDwoError() const
Get the fission .dwo file specific error for this compile unit.
Definition DWARFUnit.h:285
void SetLLDBCompUnit(lldb_private::CompileUnit *cu)
Definition DWARFUnit.h:185
lldb_private::CompileUnit * GetLLDBCompUnit() const
Definition DWARFUnit.h:183
uint8_t GetAddressByteSize() const override
Definition DWARFUnit.h:127
DWARFDataExtractor GetLocationData() const
std::optional< uint64_t > GetLoclistOffset(uint32_t Index)
Definition DWARFUnit.h:250
bool ParseDWARFLocationList(const DataExtractor &data, DWARFExpressionList &loc_list) const
void SetDwoError(Status &&error)
Set the fission .dwo file specific error for this compile unit.
Definition DWARFUnit.h:293
DWARFDIE GetDIE(dw_offset_t die_offset)
lldb::ByteOrder GetByteOrder() const
SymbolFileDWARFDwo * GetDwoSymbolFile(bool load_all_debug_info=true)
uint16_t GetVersion() const override
Definition DWARFUnit.h:121
std::optional< uint64_t > GetDWOId()
Get the DWO ID from the DWARFUnitHeader for DWARF5, or from the unit DIE's DW_AT_dwo_id or DW_AT_GNU_...
bool HasAny(llvm::ArrayRef< dw_tag_t > tags)
Returns true if any DIEs in the unit match any DW_TAG values in tags.
FileSpec GetFile(size_t file_idx)
static llvm::Expected< std::unique_ptr< DebugNamesDWARFIndex > > Create(Module &module, DWARFDataExtractor debug_names, DWARFDataExtractor debug_str, SymbolFileDWARF &dwarf)
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(Address &addr)
Convert addr from a .o file address, to an executable address.
uint64_t GetDebugInfoSize(bool load_all_debug_info=false) override
Metrics gathering functions.
CompilerDeclContext GetDeclContextContainingUID(lldb::user_id_t uid) override
static CompilerDeclContext GetContainingDeclContext(const DWARFDIE &die)
static bool SupportedVersion(uint16_t version)
std::optional< uint32_t > GetDWARFUnitIndex(uint32_t cu_idx)
CompileUnit * GetCompUnitForDWARFCompUnit(DWARFCompileUnit &dwarf_cu)
lldb::ModuleSP GetExternalModule(ConstString name)
void FindGlobalVariables(ConstString name, const CompilerDeclContext &parent_decl_ctx, uint32_t max_matches, VariableList &variables) override
virtual DWARFDIE FindDefinitionDIE(const DWARFDIE &die)
DWARFDIE FindBlockContainingSpecification(const DIERef &func_die_ref, dw_offset_t spec_block_die_offset)
lldb::VariableSP ParseVariableDIE(const SymbolContext &sc, const DWARFDIE &die, const lldb::addr_t func_low_pc)
static DWARFASTParser * GetDWARFParser(DWARFUnit &unit)
static lldb::LanguageType GetLanguageFamily(DWARFUnit &unit)
Same as GetLanguage() but reports all C++ versions as C++ (no version).
bool ForEachExternalModule(CompileUnit &, llvm::DenseSet< SymbolFile * > &, llvm::function_ref< bool(Module &)>) override
std::unique_ptr< DWARFDebugInfo > m_info
bool DeclContextMatchesThisSymbolFile(const CompilerDeclContext &decl_ctx)
void GetMangledNamesForFunction(const std::string &scope_qualified_name, std::vector< ConstString > &mangled_names) override
size_t PopulateBlockVariableList(VariableList &variable_list, const SymbolContext &sc, llvm::ArrayRef< DIERef > variable_dies, lldb::addr_t func_low_pc)
Type * ResolveType(const DWARFDIE &die, bool assert_not_being_parsed=true, bool resolve_function_context=false)
DWOStats GetDwoStats() override
Gets statistics about dwo files associated with this symbol file.
virtual llvm::DenseMap< lldb::opaque_compiler_type_t, DIERef > & GetForwardDeclCompilerTypeToDIE()
llvm::DenseMap< const DWARFDebugInfoEntry *, lldb::VariableSP > DIEToVariableSP
size_t ParseVariablesInFunctionContextRecursive(const SymbolContext &sc, const DWARFDIE &die, lldb::addr_t func_low_pc, DIEArray &accumulator)
virtual lldb::TypeSP FindCompleteObjCDefinitionTypeForDIE(const DWARFDIE &die, ConstString type_name, bool must_be_implementation)
const std::shared_ptr< SymbolFileDWARFDwo > & GetDwpSymbolFile()
std::recursive_mutex & GetModuleMutex() const override
Symbols file subclasses should override this to return the Module that owns the TypeSystem that this ...
bool GetSeparateDebugInfo(StructuredData::Dictionary &d, bool errors_only, bool load_all_debug_info=false) override
List separate dwo files.
llvm::Expected< DWARFDIE > FindFunctionDefinition(const FunctionCallLabel &label, const DWARFDIE &declaration)
Find the definition DIE for the specified label in this SymbolFile.
virtual llvm::DenseMap< const DWARFDebugInfoEntry *, Type * > & GetDIEToType()
virtual DWARFCompileUnit * GetDWARFCompileUnit(CompileUnit *comp_unit)
Function * ParseFunction(CompileUnit &comp_unit, const DWARFDIE &die)
lldb::TypeSP GetTypeForDIE(const DWARFDIE &die, bool resolve_function_context=false)
llvm::Expected< SymbolContext > ResolveFunctionCallLabel(FunctionCallLabel &label) override
Resolves the function corresponding to the specified LLDB function call label.
lldb::addr_t m_first_code_address
DWARF does not provide a good way for traditional (concatenating) linkers to invalidate debug info de...
ConstString ConstructFunctionDemangledName(const DWARFDIE &die)
DWARFUnit * GetSkeletonUnit(DWARFUnit *dwo_unit)
Given a DWO DWARFUnit, find the corresponding skeleton DWARFUnit in the main symbol file.
FileSpec GetFile(DWARFUnit &unit, size_t file_idx)
std::shared_ptr< SymbolFileDWARFDwo > m_dwp_symfile
void DumpClangAST(Stream &s, llvm::StringRef filter, bool show_colors) override
void InitializeFirstCodeAddressRecursive(const SectionList &section_list)
std::unique_ptr< llvm::DWARFDebugAbbrev > m_abbr
llvm::DenseMap< lldb::opaque_compiler_type_t, DIERef > m_forward_decl_compiler_type_to_die
std::vector< CompilerContext > GetCompilerContextForUID(lldb::user_id_t uid) override
virtual DWARFDIE GetDIE(const DIERef &die_ref)
std::unique_ptr< GlobalVariableMap > m_global_aranges_up
uint64_t GetDebugInfoSize(bool load_all_debug_info=false) override
Metrics gathering functions.
void FindTypes(const lldb_private::TypeQuery &match, lldb_private::TypeResults &results) override
Find types using a type-matching object that contains all search parameters.
static CompilerDecl GetDecl(const DWARFDIE &die)
void ResolveFunctionAndBlock(lldb::addr_t file_vm_addr, bool lookup_block, SymbolContext &sc)
Resolve functions and (possibly) blocks for the given file address and a compile unit.
void ResetStatistics() override
Reset the statistics for the symbol file.
size_t ParseVariablesForContext(const SymbolContext &sc) override
std::optional< ArrayInfo > GetDynamicArrayInfoForUID(lldb::user_id_t type_uid, const ExecutionContext *exe_ctx) override
If type_uid points to an array type, return its characteristics.
size_t ParseBlocksRecursive(Function &func) override
Type * ResolveTypeUID(lldb::user_id_t type_uid) override
static lldb::LanguageType GetLanguage(DWARFUnit &unit)
llvm::DenseMap< dw_offset_t, std::unique_ptr< SupportFileList > > m_type_unit_support_files
size_t ParseFunctions(CompileUnit &comp_unit) override
bool ParseDebugMacros(CompileUnit &comp_unit) override
static SymbolFile * CreateInstance(lldb::ObjectFileSP objfile_sp)
bool ParseSupportFiles(CompileUnit &comp_unit, SupportFileList &support_files) override
XcodeSDK ParseXcodeSDK(CompileUnit &comp_unit) override
Return the Xcode SDK comp_unit was compiled against.
bool ParseImportedModules(const SymbolContext &sc, std::vector< SourceModule > &imported_modules) override
std::optional< uint64_t > GetDWOId()
If this is a DWARF object with a single CU, return its DW_AT_dwo_id.
void GetTypes(SymbolContextScope *sc_scope, lldb::TypeClass type_mask, TypeList &type_list) override
void ParseDeclsForContext(CompilerDeclContext decl_ctx) override
size_t ParseTypes(CompileUnit &comp_unit) override
std::shared_ptr< SymbolFileDWARFDwo > GetDwoSymbolFileForCompileUnit(DWARFUnit &dwarf_cu, const DWARFDebugInfoEntry &cu_die)
SymbolFileDWARF(lldb::ObjectFileSP objfile_sp, SectionList *dwo_section_list)
lldb::VariableSP ParseVariableDIECached(const SymbolContext &sc, const DWARFDIE &die)
lldb_private::ModuleSpecList GetSeparateDebugInfoFiles() override
Return a map of separate debug info files that are loaded.
StatsDuration::Duration GetDebugInfoIndexTime() override
Return the time it took to index the debug information in the object file.
bool CompleteType(CompilerType &compiler_type) override
bool ParseLineTable(CompileUnit &comp_unit) override
lldb::TypeSP GetTypeEnclosingVariableUID(lldb::user_id_t uid) override
Get the semantically innermost non-function type that encloses the provided variable.
bool ResolveFunction(const DWARFDIE &die, bool include_inlines, SymbolContextList &sc_list)
bool ParseIsOptimized(CompileUnit &comp_unit) override
std::vector< std::unique_ptr< 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 InitializeObject() override
Initialize the SymbolFile object.
void ParseAndAppendGlobalVariable(const SymbolContext &sc, const DWARFDIE &die, VariableList &cc_variable_list)
static llvm::Expected< lldb::TypeSystemSP > GetTypeSystem(DWARFUnit &unit)
void FindFunctions(const Module::LookupInfo &lookup_info, const CompilerDeclContext &parent_decl_ctx, bool include_inlines, SymbolContextList &sc_list) override
static bool DIEInDeclContext(const CompilerDeclContext &parent_decl_ctx, const DWARFDIE &die, bool only_root_namespaces=false)
uint32_t ResolveSymbolContext(const Address &so_addr, lldb::SymbolContextItem resolve_scope, SymbolContext &sc) override
bool HasForwardDeclForCompilerType(const CompilerType &compiler_type)
lldb::CompUnitSP ParseCompileUnit(DWARFCompileUnit &dwarf_cu)
CompilerDeclContext FindNamespace(ConstString name, const CompilerDeclContext &parent_decl_ctx, bool only_root_namespaces) override
Finds a namespace of name name and whose parent context is parent_decl_ctx.
lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) override
static lldb::LanguageType LanguageTypeFromDWARF(uint64_t val)
lldb::TypeSP ParseType(const SymbolContext &sc, const DWARFDIE &die, bool *type_is_new)
static DWARFDIE GetParentSymbolContextDIE(const DWARFDIE &die)
std::vector< std::unique_ptr< CallEdge > > ParseCallEdgesInFunction(UserID func_id) override
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...
virtual void GetObjCMethods(ConstString class_name, llvm::function_ref< IterationAction(DWARFDIE die)> callback)
llvm::Expected< lldb::TypeSystemSP > GetTypeSystemForLanguage(lldb::LanguageType language) override
CompilerDecl GetDeclForUID(lldb::user_id_t uid) override
virtual SymbolFileDWARF * GetDIERefSymbolFile(const DIERef &die_ref)
Given a DIERef, find the correct SymbolFileDWARF.
lldb::LanguageType ParseLanguage(CompileUnit &comp_unit) override
CompilerDeclContext GetDeclContextForUID(lldb::user_id_t uid) override
static void DebuggerInitialize(Debugger &debugger)
RangeDataVector< lldb::addr_t, lldb::addr_t, Variable * > GlobalVariableMap
size_t ParseVariablesInFunctionContext(const SymbolContext &sc, const DWARFDIE &die, const lldb::addr_t func_low_pc)
llvm::DenseMap< const DWARFDebugInfoEntry *, Type * > m_die_to_type
bool GetFunction(const DWARFDIE &die, SymbolContext &sc)
const SupportFileList * GetTypeUnitSupportFiles(DWARFTypeUnit &tu)
std::optional< uint64_t > GetFileIndex() const
Symbol * GetObjCClassSymbol(ConstString objc_class_name)
static CompilerDeclContext GetDeclContext(const DWARFDIE &die)
virtual UniqueDWARFASTTypeMap & GetUniqueDWARFASTTypeMap()
virtual void LoadSectionData(lldb::SectionType sect_type, DWARFDataExtractor &data)
Status CalculateFrameVariableError(StackFrame &frame) override
Subclasses will override this function to for GetFrameVariableError().
uint64_t dw_offset_t
Definition dwarf.h:24
#define DW_INVALID_OFFSET
Definition dwarf.h:29
llvm::dwarf::Tag dw_tag_t
Definition dwarf.h:19
#define DW_DIE_OFFSET_MAX_BITSIZE
Definition dwarf.h:28
llvm::dwarf::Attribute dw_attr_t
Definition dwarf.h:17
uint64_t dw_addr_t
Definition dwarf.h:20
#define DW_INVALID_INDEX
Definition dwarf.h:30
#define LLDB_INVALID_ADDRESS
llvm::StringRef DW_TAG_value_to_name(dw_tag_t tag)
std::vector< DIERef > DIEArray
Definition DIERef.h:136
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition Log.h:338
NonNullSharedPtr< lldb_private::SupportFile > SupportFileNSP
Definition SupportFile.h:80
NativeFilePosix NativeFile
Definition File.h:29
std::shared_ptr< DebugMacros > DebugMacrosSP
Definition DebugMacros.h:22
llvm::SmallVector< CallSiteParameter, 0 > CallSiteParameterArray
A vector of CallSiteParameter.
Definition Function.h:247
IterationAction
Useful for callbacks whose return type indicates whether to continue iteration or short-circuit.
std::shared_ptr< lldb_private::TypeSystem > TypeSystemSP
@ eDescriptionLevelBrief
@ eDescriptionLevelFull
uint64_t offset_t
Definition lldb-types.h:86
std::shared_ptr< lldb_private::ObjectFile > ObjectFileSP
LanguageType
Programming language type.
@ eLanguageTypeMipsAssembler
Mips_Assembler.
@ eLanguageTypeUnknown
Unknown or invalid language value.
@ eLanguageTypeC_plus_plus
ISO C++:1998.
@ eLanguageTypeLastStandardLanguage
std::shared_ptr< lldb_private::Type > TypeSP
@ eSymbolTypeObjCClass
std::shared_ptr< lldb_private::VariableList > VariableListSP
std::shared_ptr< lldb_private::Variable > VariableSP
@ eValueTypeVariableGlobal
globals variable
@ eValueTypeVariableLocal
function local variables
@ eValueTypeVariableArgument
function argument variables
@ eValueTypeVariableStatic
static variable
@ eValueTypeVariableThreadLocal
thread local storage variable
uint64_t user_id_t
Definition lldb-types.h:83
std::shared_ptr< lldb_private::Section > SectionSP
uint64_t addr_t
Definition lldb-types.h:80
@ eSectionTypeDWARFAppleNamespaces
@ eSectionTypeDWARFDebugNames
DWARF v5 .debug_names.
@ eSectionTypeDWARFAppleTypes
@ eSectionTypeDWARFDebugInfo
@ eSectionTypeDWARFDebugLine
@ eSectionTypeDWARFDebugStr
@ eSectionTypeDWARFAppleNames
@ eSectionTypeDWARFAppleObjC
@ eSectionTypeDWARFDebugAbbrev
std::shared_ptr< lldb_private::DataExtractor > DataExtractorSP
std::shared_ptr< lldb_private::Module > ModuleSP
std::shared_ptr< lldb_private::CompileUnit > CompUnitSP
Represent the locations of a parameter at a call site, both in the caller and in the callee.
Definition Function.h:241
static CompilerType RemoveFastQualifiers(const CompilerType &ct)
Definition ClangUtil.cpp:51
Holds statistics about DWO (Debug With Object) files.
Definition Statistics.h:124
uint32_t loaded_dwo_file_count
Definition Statistics.h:125
Holds parsed information about a function call label that LLDB attaches as an AsmLabel to function AS...
Definition Expression.h:110
lldb::user_id_t symbol_id
Unique identifier of the function symbol on which to perform the function call.
Definition Expression.h:122
llvm::StringRef discriminator
Arbitrary string which language plugins can interpret for their own needs.
Definition Expression.h:113
llvm::StringRef lookup_name
Name to use when searching for the function symbol in module_id.
Definition Expression.h:131
Information needed to import a source-language module.
std::vector< ConstString > path
Something like "Module.Submodule".
A mix in class that contains a generic user ID.
Definition UserID.h:31
lldb::user_id_t GetID() const
Get accessor for the user ID.
Definition UserID.h:47