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