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