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