LLDB mainline
SymbolFileDWARFDebugMap.cpp
Go to the documentation of this file.
1//===-- SymbolFileDWARFDebugMap.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
10#include "DWARFCompileUnit.h"
11#include "DWARFDebugAranges.h"
12#include "DWARFDebugInfo.h"
13
14#include "lldb/Core/Module.h"
17#include "lldb/Core/Progress.h"
18#include "lldb/Core/Section.h"
24#include "lldb/Utility/Timer.h"
25
26//#define DEBUG_OSO_DMAP // DO NOT CHECKIN WITH THIS NOT COMMENTED OUT
27
32#include "lldb/Symbol/TypeMap.h"
34#include "llvm/ADT/STLExtras.h"
35#include "llvm/ADT/StringRef.h"
36#include "llvm/Support/ErrorExtras.h"
37#include "llvm/Support/ScopedPrinter.h"
38
40
41#include "LogChannelDWARF.h"
42#include "SymbolFileDWARF.h"
44
45#include <memory>
46#include <optional>
47
48using namespace lldb;
49using namespace lldb_private;
50using namespace lldb_private::plugin::dwarf;
51
53
54// Subclass lldb_private::Module so we can intercept the
55// "Module::GetObjectFile()" (so we can fixup the object file sections) and
56// also for "Module::GetSymbolFile()" (so we can fixup the symbol file id.
57
60 SymbolFileDWARFDebugMap *exe_symfile) {
62 return file_range_map;
63
65
66 Module *oso_module = exe_symfile->GetModuleByCompUnitInfo(this);
67 if (!oso_module)
68 return file_range_map;
69
70 ObjectFile *oso_objfile = oso_module->GetObjectFile();
71 if (!oso_objfile)
72 return file_range_map;
73
76 log,
77 "%p: SymbolFileDWARFDebugMap::CompileUnitInfo::GetFileRangeMap ('%s')",
78 static_cast<void *>(this),
79 oso_module->GetSpecificationDescription().c_str());
80
81 std::vector<SymbolFileDWARFDebugMap::CompileUnitInfo *> cu_infos;
82 if (exe_symfile->GetCompUnitInfosForModule(oso_module, cu_infos)) {
83 for (auto comp_unit_info : cu_infos) {
84 Symtab *exe_symtab = exe_symfile->GetObjectFile()->GetSymtab();
85 ModuleSP oso_module_sp(oso_objfile->GetModule());
86 Symtab *oso_symtab = oso_objfile->GetSymtab();
87
88 /// const uint32_t fun_resolve_flags = SymbolContext::Module |
89 /// eSymbolContextCompUnit | eSymbolContextFunction;
90 // SectionList *oso_sections = oso_objfile->Sections();
91 // Now we need to make sections that map from zero based object file
92 // addresses to where things ended up in the main executable.
93
94 assert(comp_unit_info->first_symbol_index != UINT32_MAX);
95 // End index is one past the last valid symbol index
96 const uint32_t oso_end_idx = comp_unit_info->last_symbol_index + 1;
97 for (uint32_t idx = comp_unit_info->first_symbol_index +
98 2; // Skip the N_SO and N_OSO
99 idx < oso_end_idx; ++idx) {
100 const Symbol *exe_symbol = exe_symtab->SymbolAtIndex(idx);
101 if (exe_symbol) {
102 if (!exe_symbol->IsDebug())
103 continue;
104
105 switch (exe_symbol->GetType()) {
106 default:
107 break;
108
109 case eSymbolTypeCode: {
110 // For each N_FUN, or function that we run into in the debug map we
111 // make a new section that we add to the sections found in the .o
112 // file. This new section has the file address set to what the
113 // addresses are in the .o file, and the load address is adjusted
114 // to match where it ended up in the final executable! We do this
115 // before we parse any dwarf info so that when it goes get parsed
116 // all section/offset addresses that get registered will resolve
117 // correctly to the new addresses in the main executable.
118
119 // First we find the original symbol in the .o file's symbol table
120 const Symbol *oso_fun_symbol =
124 if (oso_fun_symbol) {
125 // Add the inverse OSO file address to debug map entry mapping
126 exe_symfile->AddOSOFileRange(
127 this, exe_symbol->GetAddressRef().GetFileAddress(),
128 exe_symbol->GetByteSize(),
129 oso_fun_symbol->GetAddressRef().GetFileAddress(),
130 oso_fun_symbol->GetByteSize());
131 }
132 } break;
133
134 case eSymbolTypeData: {
135 // For each N_GSYM we remap the address for the global by making a
136 // new section that we add to the sections found in the .o file.
137 // This new section has the file address set to what the addresses
138 // are in the .o file, and the load address is adjusted to match
139 // where it ended up in the final executable! We do this before we
140 // parse any dwarf info so that when it goes get parsed all
141 // section/offset addresses that get registered will resolve
142 // correctly to the new addresses in the main executable. We
143 // initially set the section size to be 1 byte, but will need to
144 // fix up these addresses further after all globals have been
145 // parsed to span the gaps, or we can find the global variable
146 // sizes from the DWARF info as we are parsing.
147
148 // Next we find the non-stab entry that corresponds to the N_GSYM
149 // in the .o file
150 const Symbol *oso_gsym_symbol =
154 if (exe_symbol && oso_gsym_symbol && exe_symbol->ValueIsAddress() &&
155 oso_gsym_symbol->ValueIsAddress()) {
156 // Add the inverse OSO file address to debug map entry mapping
157 exe_symfile->AddOSOFileRange(
158 this, exe_symbol->GetAddressRef().GetFileAddress(),
159 exe_symbol->GetByteSize(),
160 oso_gsym_symbol->GetAddressRef().GetFileAddress(),
161 oso_gsym_symbol->GetByteSize());
162 }
163 } break;
164 }
165 }
166 }
167
168 exe_symfile->FinalizeOSOFileRanges(this);
169 // We don't need the symbols anymore for the .o files
170 oso_objfile->ClearSymtab();
171 }
172 }
173 return file_range_map;
174}
175
176namespace lldb_private::plugin {
177namespace dwarf {
178class DebugMapModule : public Module {
179public:
180 DebugMapModule(const ModuleSP &exe_module_sp, uint32_t cu_idx,
181 const FileSpec &file_spec, const ArchSpec &arch,
182 std::string object_name, off_t object_offset,
183 const llvm::sys::TimePoint<> object_mod_time)
184 : Module(file_spec, arch, std::move(object_name), object_offset,
185 object_mod_time),
186 m_exe_module_wp(exe_module_sp), m_cu_idx(cu_idx) {}
187
188 ~DebugMapModule() override = default;
189
190 SymbolFile *
191 GetSymbolFile(bool can_create = true,
192 lldb_private::Stream *feedback_strm = nullptr) override {
193 // Scope for locker
194 if (m_symfile_up.get() || !can_create)
195 return m_symfile_up ? m_symfile_up->GetSymbolFile() : nullptr;
196
197 ModuleSP exe_module_sp(m_exe_module_wp.lock());
198 if (exe_module_sp) {
199 // Now get the object file outside of a locking scope
200 ObjectFile *oso_objfile = GetObjectFile();
201 if (oso_objfile) {
202 std::lock_guard<std::recursive_mutex> guard(m_mutex);
203 if (SymbolFile *symfile =
204 Module::GetSymbolFile(can_create, feedback_strm)) {
205 // Set a pointer to this class to set our OSO DWARF file know that
206 // the DWARF is being used along with a debug map and that it will
207 // have the remapped sections that we do below.
208 SymbolFileDWARF *oso_symfile =
210
211 if (!oso_symfile)
212 return nullptr;
213
214 ObjectFile *exe_objfile = exe_module_sp->GetObjectFile();
215 SymbolFile *exe_symfile = exe_module_sp->GetSymbolFile();
216
217 if (exe_objfile && exe_symfile) {
218 oso_symfile->SetDebugMapModule(exe_module_sp);
219 // Set the ID of the symbol file DWARF to the index of the OSO
220 // shifted left by 32 bits to provide a unique prefix for any
221 // UserID's that get created in the symbol file.
222 oso_symfile->SetFileIndex((uint64_t)m_cu_idx);
223 }
224 return symfile;
225 }
226 }
227 }
228 return nullptr;
229 }
230
231protected:
233 const uint32_t m_cu_idx;
234};
235} // namespace dwarf
236} // namespace lldb_private::plugin
237
242
246
248 return "DWARF and DWARF3 debug symbol file reader (debug map).";
249}
250
252 return new SymbolFileDWARFDebugMap(std::move(objfile_sp));
253}
254
258
260
262
265 return;
266
268
269 // If the object file has been stripped, there is no sense in looking further
270 // as all of the debug symbols for the debug map will not be available
271 if (m_objfile_sp->IsStripped())
272 return;
273
274 // Also make sure the file type is some sort of executable. Core files, debug
275 // info files (dSYM), object files (.o files), and stub libraries all can
276 switch (m_objfile_sp->GetType()) {
284 return;
285
289 break;
290 }
291
292 // In order to get the abilities of this plug-in, we look at the list of
293 // N_OSO entries (object files) from the symbol table and make sure that
294 // these files exist and also contain valid DWARF. If we get any of that then
295 // we return the abilities of the first N_OSO's DWARF.
296
297 Symtab *symtab = m_objfile_sp->GetSymtab();
298 if (!symtab)
299 return;
300
302
303 std::vector<uint32_t> oso_indexes;
304 // When a mach-o symbol is encoded, the n_type field is encoded in bits
305 // 23:16, and the n_desc field is encoded in bits 15:0.
306 //
307 // To find all N_OSO entries that are part of the DWARF + debug map we find
308 // only object file symbols with the flags value as follows: bits 23:16 ==
309 // 0x66 (N_OSO) bits 15: 0 == 0x0001 (specifies this is a debug map object
310 // file)
311 const uint32_t k_oso_symbol_flags_value = 0x660001u;
312
313 const uint32_t oso_index_count =
315 eSymbolTypeObjectFile, k_oso_symbol_flags_value, oso_indexes);
316
317 if (oso_index_count == 0)
318 return;
319
324
327
328 for (uint32_t sym_idx :
329 llvm::concat<uint32_t>(m_func_indexes, m_glob_indexes)) {
330 const Symbol *symbol = symtab->SymbolAtIndex(sym_idx);
331 lldb::addr_t file_addr = symbol->GetAddressRef().GetFileAddress();
332 lldb::addr_t byte_size = symbol->GetByteSize();
333 DebugMap::Entry debug_map_entry(file_addr, byte_size,
335 m_debug_map.Append(debug_map_entry);
336 }
337 m_debug_map.Sort();
338
339 m_compile_unit_infos.resize(oso_index_count);
340
341 for (uint32_t i = 0; i < oso_index_count; ++i) {
342 const uint32_t so_idx = oso_indexes[i] - 1;
343 const uint32_t oso_idx = oso_indexes[i];
344 const Symbol *so_symbol = symtab->SymbolAtIndex(so_idx);
345 const Symbol *oso_symbol = symtab->SymbolAtIndex(oso_idx);
346 if (so_symbol && oso_symbol &&
347 so_symbol->GetType() == eSymbolTypeSourceFile &&
348 oso_symbol->GetType() == eSymbolTypeObjectFile) {
349 m_compile_unit_infos[i].so_file.SetFile(
350 so_symbol->GetName().GetStringRef(), FileSpec::Style::native);
351 m_compile_unit_infos[i].oso_path = oso_symbol->GetName();
352 m_compile_unit_infos[i].oso_mod_time =
353 llvm::sys::toTimePoint(oso_symbol->GetIntegerValue(0));
354 uint32_t sibling_idx = so_symbol->GetSiblingIndex();
355 // The sibling index can't be less that or equal to the current index
356 // "i"
357 if (sibling_idx <= i || sibling_idx == UINT32_MAX) {
358 m_objfile_sp->GetModule()->ReportInternalError(
359 "N_SO in symbol with UID {0} has invalid sibling in debug map",
360 so_symbol->GetID());
361 } else {
362 const Symbol *last_symbol = symtab->SymbolAtIndex(sibling_idx - 1);
363 m_compile_unit_infos[i].first_symbol_index = so_idx;
364 m_compile_unit_infos[i].last_symbol_index = sibling_idx - 1;
365 m_compile_unit_infos[i].first_symbol_id = so_symbol->GetID();
366 m_compile_unit_infos[i].last_symbol_id = last_symbol->GetID();
367
368 LLDB_LOGF(log, "Initialized OSO 0x%8.8x: file=%s", i,
369 oso_symbol->GetName().GetCString());
370 }
371 } else {
372 if (oso_symbol == nullptr)
373 m_objfile_sp->GetModule()->ReportInternalError(
374 "N_OSO symbol[{0}] can't be found", oso_idx);
375 else if (so_symbol == nullptr)
376 m_objfile_sp->GetModule()->ReportInternalError(
377 "N_SO not found for N_OSO symbol[{0}]", oso_idx);
378 else if (so_symbol->GetType() != eSymbolTypeSourceFile)
379 m_objfile_sp->GetModule()->ReportInternalError(
380 "N_SO has incorrect symbol type ({0}) for N_OSO symbol[{1}]",
381 so_symbol->GetType(), oso_idx);
382 else if (oso_symbol->GetType() != eSymbolTypeSourceFile)
383 m_objfile_sp->GetModule()->ReportInternalError(
384 "N_OSO has incorrect symbol type ({0}) for N_OSO symbol[{1}]",
385 oso_symbol->GetType(), oso_idx);
386 }
387 }
388}
389
391 const uint32_t cu_count = GetNumCompileUnits();
392 if (oso_idx < cu_count)
394 return nullptr;
395}
396
398 CompileUnitInfo *comp_unit_info) {
399 if (!comp_unit_info->oso_sp) {
400 auto pos = m_oso_map.find(
401 {comp_unit_info->oso_path, comp_unit_info->oso_mod_time});
402 if (pos != m_oso_map.end()) {
403 comp_unit_info->oso_sp = pos->second;
404 } else {
405 ObjectFile *obj_file = GetObjectFile();
406 comp_unit_info->oso_sp = std::make_shared<OSOInfo>();
407 m_oso_map[{comp_unit_info->oso_path, comp_unit_info->oso_mod_time}] =
408 comp_unit_info->oso_sp;
409 const char *oso_path = comp_unit_info->oso_path.GetCString();
410 FileSpec oso_file(oso_path);
411 llvm::StringRef oso_object;
412 if (FileSystem::Instance().Exists(oso_file)) {
413 // The modification time returned by the FS can have a higher precision
414 // than the one from the CU.
415 auto oso_mod_time = std::chrono::time_point_cast<std::chrono::seconds>(
416 FileSystem::Instance().GetModificationTime(oso_file));
417 // A timestamp of 0 means that the linker was in deterministic mode. In
418 // that case, we should skip the check against the filesystem last
419 // modification timestamp, since it will never match.
420 if (comp_unit_info->oso_mod_time != llvm::sys::TimePoint<>() &&
421 oso_mod_time != comp_unit_info->oso_mod_time) {
423 "debug map object file \"%s\" changed (actual: 0x%8.8x, debug "
424 "map: 0x%8.8x) since this executable was linked, debug info "
425 "will not be loaded",
426 oso_file.GetPath().c_str(),
427 (uint32_t)llvm::sys::toTimeT(oso_mod_time),
428 (uint32_t)llvm::sys::toTimeT(comp_unit_info->oso_mod_time));
429 obj_file->GetModule()->ReportError(
430 "{0}", comp_unit_info->oso_load_error.AsCString());
431 return nullptr;
432 }
433
434 } else {
435 const bool must_exist = true;
436
437 if (!ObjectFile::SplitArchivePathWithObject(oso_path, oso_file,
438 oso_object, must_exist)) {
440 "debug map object file \"%s\" containing debug info does not "
441 "exist, debug info will not be loaded",
442 comp_unit_info->oso_path.GetCString());
443 ReportMissingOSOs(*comp_unit_info);
444 return nullptr;
445 }
446 }
447 // Always create a new module for .o files. Why? Because we use the debug
448 // map, to add new sections to each .o file and even though a .o file
449 // might not have changed, the sections that get added to the .o file can
450 // change.
451 ArchSpec oso_arch;
452 // Only adopt the architecture from the module (not the vendor or OS)
453 // since .o files for "i386-apple-ios" will historically show up as "i386
454 // -apple-macosx" due to the lack of a LC_VERSION_MIN_MACOSX or
455 // LC_VERSION_MIN_IPHONEOS load command...
456 oso_arch.SetTriple(m_objfile_sp->GetModule()
457 ->GetArchitecture()
458 .GetTriple()
459 .getArchName()
460 .str()
461 .c_str());
462 comp_unit_info->oso_sp->module_sp = std::make_shared<DebugMapModule>(
463 obj_file->GetModule(), GetCompUnitInfoIndex(comp_unit_info), oso_file,
464 oso_arch, oso_object.str(), 0,
465 !oso_object.empty() ? comp_unit_info->oso_mod_time
466 : llvm::sys::TimePoint<>());
467
468 if (!oso_object.empty() &&
469 !comp_unit_info->oso_sp->module_sp->GetObjectFile() &&
470 FileSystem::Instance().Exists(oso_file)) {
471 // If we are loading a .o file from a .a file the "oso_object" will
472 // have a valid value name and if the .a file exists, either the .o
473 // file didn't exist in the .a file or the mod time didn't match.
475 "\"{0}\" object from the \"{1}\" archive: "
476 "either the .o file doesn't exist in the archive or the "
477 "modification time (0x{2:x-8}) of the .o file doesn't match",
478 oso_object, oso_file.GetPath(),
479 (uint32_t)llvm::sys::toTimeT(comp_unit_info->oso_mod_time));
480 }
481 }
482 }
483 if (comp_unit_info->oso_sp)
484 return comp_unit_info->oso_sp->module_sp.get();
485 return nullptr;
486}
487
488static bool OSOExists(llvm::StringRef oso_path) {
489 FileSpec oso_file(oso_path);
490 llvm::StringRef oso_object;
491 return FileSystem::Instance().Exists(oso_file) ||
492 ObjectFile::SplitArchivePathWithObject(oso_path, oso_file, oso_object,
493 /*must_exist=*/true);
494}
495
497 const CompileUnitInfo &missing_info) {
498 // Users have no control over shared cache images, so the error is not
499 // actionable.
500 if (m_objfile_sp->IsSharedCacheBinary())
501 return;
502
504 return;
506
507 size_t num_missing =
508 llvm::count_if(m_compile_unit_infos, [](const CompileUnitInfo &info) {
509 return !OSOExists(info.oso_path.GetStringRef());
510 });
511 ModuleSP module_sp = m_objfile_sp->GetModule();
512 if (num_missing <= 1) {
513 module_sp->ReportError("{0}", missing_info.oso_load_error.AsCString());
514 return;
515 }
516 module_sp->ReportError(
517 "{0} of {1} debug map object files do not exist: debug info cannot be "
518 "loaded for them. Run \"image dump separate-debug-info --errors-only\" "
519 "to list them",
520 num_missing, m_compile_unit_infos.size());
521}
522
524 FileSpec &file_spec) {
525 if (oso_idx < m_compile_unit_infos.size()) {
526 if (m_compile_unit_infos[oso_idx].so_file) {
527 file_spec = m_compile_unit_infos[oso_idx].so_file;
528 return true;
529 }
530 }
531 return false;
532}
533
535 Module *oso_module = GetModuleByOSOIndex(oso_idx);
536 if (oso_module)
537 return oso_module->GetObjectFile();
538 return nullptr;
539}
540
545
548 CompileUnitInfo *comp_unit_info = GetCompUnitInfo(comp_unit);
549 if (comp_unit_info)
550 return GetSymbolFileByCompUnitInfo(comp_unit_info);
551 return nullptr;
552}
553
555 CompileUnitInfo *comp_unit_info) {
556 Module *oso_module = GetModuleByCompUnitInfo(comp_unit_info);
557 if (oso_module)
558 return oso_module->GetObjectFile();
559 return nullptr;
560}
561
563 const CompileUnitInfo *comp_unit_info) {
564 if (!m_compile_unit_infos.empty()) {
565 const CompileUnitInfo *first_comp_unit_info = &m_compile_unit_infos.front();
566 const CompileUnitInfo *last_comp_unit_info = &m_compile_unit_infos.back();
567 if (first_comp_unit_info <= comp_unit_info &&
568 comp_unit_info <= last_comp_unit_info)
569 return comp_unit_info - first_comp_unit_info;
570 }
571 return UINT32_MAX;
572}
573
576 unsigned size = m_compile_unit_infos.size();
577 if (oso_idx < size)
579 return nullptr;
580}
581
584 if (sym_file &&
586 return static_cast<SymbolFileDWARF *>(sym_file);
587 return nullptr;
588}
589
591 CompileUnitInfo *comp_unit_info) {
592 if (Module *oso_module = GetModuleByCompUnitInfo(comp_unit_info))
593 return GetSymbolFileAsSymbolFileDWARF(oso_module->GetSymbolFile());
594 return nullptr;
595}
596
598 // In order to get the abilities of this plug-in, we look at the list of
599 // N_OSO entries (object files) from the symbol table and make sure that
600 // these files exist and also contain valid DWARF. If we get any of that then
601 // we return the abilities of the first N_OSO's DWARF.
602
603 const uint32_t oso_index_count = GetNumCompileUnits();
604 if (oso_index_count > 0) {
605 InitOSO();
606 if (!m_compile_unit_infos.empty()) {
611 }
612 }
613 return 0;
614}
615
620
622 CompUnitSP comp_unit_sp;
623 const uint32_t cu_count = GetNumCompileUnits();
624
625 if (cu_idx < cu_count) {
626 auto &cu_info = m_compile_unit_infos[cu_idx];
627 Module *oso_module = GetModuleByCompUnitInfo(&cu_info);
628 if (oso_module) {
629 FileSpec so_file_spec;
630 if (GetFileSpecForSO(cu_idx, so_file_spec)) {
631 // Apply the module's source path remappings so that compile units
632 // created from N_SO stabs (which may contain paths rewritten by
633 // -fdebug-prefix-map at build time) report their real on-disk paths.
634 // This mirrors what MakeAbsoluteAndRemap does for the dSYM case.
635 if (ModuleSP module_sp = m_objfile_sp->GetModule())
636 if (auto remapped =
637 module_sp->RemapSourceFile(so_file_spec.GetPath()))
638 so_file_spec.SetFile(*remapped, FileSpec::Style::native);
639
640 // User zero as the ID to match the compile unit at offset zero in each
641 // .o file.
642 lldb::user_id_t cu_id = 0;
643 cu_info.compile_units_sps.push_back(std::make_shared<CompileUnit>(
644 m_objfile_sp->GetModule(), nullptr,
645 std::make_shared<SupportFile>(so_file_spec), cu_id,
647 cu_info.id_to_index_map.insert({0, 0});
648 SetCompileUnitAtIndex(cu_idx, cu_info.compile_units_sps[0]);
649 // If there's a symbol file also register all the extra compile units.
650 if (SymbolFileDWARF *oso_symfile =
651 GetSymbolFileByCompUnitInfo(&cu_info)) {
652 auto num_dwarf_units = oso_symfile->DebugInfo().GetNumUnits();
653 for (size_t i = 0; i < num_dwarf_units; ++i) {
654 auto *dwarf_unit = oso_symfile->DebugInfo().GetUnitAtIndex(i);
655 if (auto *dwarf_cu = llvm::dyn_cast<DWARFCompileUnit>(dwarf_unit)) {
656 // The "main" one was already registered.
657 if (dwarf_cu->GetID() == 0)
658 continue;
659 cu_info.compile_units_sps.push_back(std::make_shared<CompileUnit>(
660 m_objfile_sp->GetModule(), nullptr,
661 std::make_shared<SupportFile>(so_file_spec),
662 dwarf_cu->GetID(), eLanguageTypeUnknown, eLazyBoolCalculate));
663 cu_info.id_to_index_map.insert(
664 {dwarf_cu->GetID(), cu_info.compile_units_sps.size() - 1});
665 }
666 }
667 }
668 }
669 }
670 if (!cu_info.compile_units_sps.empty())
671 comp_unit_sp = cu_info.compile_units_sps[0];
672 }
673
674 return comp_unit_sp;
675}
676
681
684 const uint32_t cu_count = GetNumCompileUnits();
685 for (uint32_t i = 0; i < cu_count; ++i) {
686 auto &id_to_index_map = m_compile_unit_infos[i].id_to_index_map;
687
688 auto it = id_to_index_map.find(comp_unit.GetID());
689 if (it != id_to_index_map.end() &&
690 &comp_unit ==
691 m_compile_unit_infos[i].compile_units_sps[it->getSecond()].get())
692 return &m_compile_unit_infos[i];
693 }
694 return nullptr;
695}
696
698 const lldb_private::Module *module,
699 std::vector<CompileUnitInfo *> &cu_infos) {
700 const uint32_t cu_count = GetNumCompileUnits();
701 for (uint32_t i = 0; i < cu_count; ++i) {
703 cu_infos.push_back(&m_compile_unit_infos[i]);
704 }
705 return cu_infos.size();
706}
707
710 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
711 SymbolFileDWARF *oso_dwarf = GetSymbolFile(comp_unit);
712 if (oso_dwarf)
713 return oso_dwarf->ParseLanguage(comp_unit);
715}
716
719 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
720 SymbolFileDWARF *oso_dwarf = GetSymbolFile(comp_unit);
721 if (oso_dwarf)
722 return oso_dwarf->ParseXcodeSDK(comp_unit);
723 return {};
724}
725
726llvm::SmallSet<lldb::LanguageType, 4>
728 lldb_private::CompileUnit &comp_unit) {
729 llvm::SmallSet<lldb::LanguageType, 4> langs;
730 auto *info = GetCompUnitInfo(comp_unit);
731 for (auto &comp_unit : info->compile_units_sps) {
732 langs.insert(comp_unit->GetLanguage());
733 }
734 return langs;
735}
736
738 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
739 SymbolFileDWARF *oso_dwarf = GetSymbolFile(comp_unit);
740 if (oso_dwarf)
741 return oso_dwarf->ParseFunctions(comp_unit);
742 return 0;
743}
744
746 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
747 SymbolFileDWARF *oso_dwarf = GetSymbolFile(comp_unit);
748 if (oso_dwarf)
749 return oso_dwarf->ParseLineTable(comp_unit);
750 return false;
751}
752
754 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
755 SymbolFileDWARF *oso_dwarf = GetSymbolFile(comp_unit);
756 if (oso_dwarf)
757 return oso_dwarf->ParseDebugMacros(comp_unit);
758 return false;
759}
760
762 std::string description,
763 std::function<IterationAction(SymbolFileDWARF &)> closure) {
764 const size_t num_oso_idxs = m_compile_unit_infos.size();
765 Progress progress(std::move(description), "", num_oso_idxs,
766 /*debugger=*/nullptr,
768 for (uint32_t oso_idx = 0; oso_idx < num_oso_idxs; ++oso_idx) {
769 if (SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex(oso_idx)) {
770 progress.Increment(oso_idx, oso_dwarf->GetObjectName());
771 if (closure(*oso_dwarf) == IterationAction::Stop)
772 return;
773 }
774 }
775}
776
778 CompileUnit &comp_unit,
779 llvm::DenseSet<lldb_private::SymbolFile *> &visited_symbol_files,
780 llvm::function_ref<bool(Module &)> f) {
781 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
782 SymbolFileDWARF *oso_dwarf = GetSymbolFile(comp_unit);
783 if (oso_dwarf)
784 return oso_dwarf->ForEachExternalModule(comp_unit, visited_symbol_files, f);
785 return false;
786}
787
789 CompileUnit &comp_unit, SupportFileList &support_files) {
790 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
791 SymbolFileDWARF *oso_dwarf = GetSymbolFile(comp_unit);
792 if (oso_dwarf)
793 return oso_dwarf->ParseSupportFiles(comp_unit, support_files);
794 return false;
795}
796
798 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
799 SymbolFileDWARF *oso_dwarf = GetSymbolFile(comp_unit);
800 if (oso_dwarf)
801 return oso_dwarf->ParseIsOptimized(comp_unit);
802 return false;
803}
804
806 const SymbolContext &sc, std::vector<SourceModule> &imported_modules) {
807 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
808 SymbolFileDWARF *oso_dwarf = GetSymbolFile(sc);
809 if (oso_dwarf)
810 return oso_dwarf->ParseImportedModules(sc, imported_modules);
811 return false;
812}
813
815 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
816 CompileUnit *comp_unit = func.GetCompileUnit();
817 if (!comp_unit)
818 return 0;
819
820 SymbolFileDWARF *oso_dwarf = GetSymbolFile(*comp_unit);
821 if (oso_dwarf)
822 return oso_dwarf->ParseBlocksRecursive(func);
823 return 0;
824}
825
827 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
828 SymbolFileDWARF *oso_dwarf = GetSymbolFile(comp_unit);
829 if (oso_dwarf)
830 return oso_dwarf->ParseTypes(comp_unit);
831 return 0;
832}
833
834size_t
836 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
837 SymbolFileDWARF *oso_dwarf = GetSymbolFile(sc);
838 if (oso_dwarf)
839 return oso_dwarf->ParseVariablesForContext(sc);
840 return 0;
841}
842
844 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
845 const uint64_t oso_idx = GetOSOIndexFromUserID(type_uid);
846 SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex(oso_idx);
847 if (oso_dwarf)
848 return oso_dwarf->ResolveTypeUID(type_uid);
849 return nullptr;
850}
851
852std::optional<SymbolFile::ArrayInfo>
854 lldb::user_id_t type_uid, const lldb_private::ExecutionContext *exe_ctx) {
855 const uint64_t oso_idx = GetOSOIndexFromUserID(type_uid);
856 SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex(oso_idx);
857 if (oso_dwarf)
858 return oso_dwarf->GetDynamicArrayInfoForUID(type_uid, exe_ctx);
859 return std::nullopt;
860}
861
863 bool success = false;
864 if (compiler_type) {
865 ForEachSymbolFile("Completing type", [&](SymbolFileDWARF &oso_dwarf) {
866 if (oso_dwarf.HasForwardDeclForCompilerType(compiler_type)) {
867 oso_dwarf.CompleteType(compiler_type);
868 success = true;
870 }
872 });
873 }
874 return success;
875}
876
877uint32_t
879 SymbolContextItem resolve_scope,
880 SymbolContext &sc) {
881 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
882 uint32_t resolved_flags = 0;
883 Symtab *symtab = m_objfile_sp->GetSymtab();
884 if (symtab) {
885 const addr_t exe_file_addr = exe_so_addr.GetFileAddress();
886
887 const DebugMap::Entry *debug_map_entry =
888 m_debug_map.FindEntryThatContains(exe_file_addr);
889 if (debug_map_entry) {
890
891 sc.symbol =
892 symtab->SymbolAtIndex(debug_map_entry->data.GetExeSymbolIndex());
893
894 if (sc.symbol != nullptr) {
895 resolved_flags |= eSymbolContextSymbol;
896
897 uint32_t oso_idx = 0;
898 CompileUnitInfo *comp_unit_info =
900 if (comp_unit_info) {
901 comp_unit_info->GetFileRangeMap(this);
902 Module *oso_module = GetModuleByCompUnitInfo(comp_unit_info);
903 if (oso_module) {
904 lldb::addr_t oso_file_addr =
905 exe_file_addr - debug_map_entry->GetRangeBase() +
906 debug_map_entry->data.GetOSOFileAddress();
907 Address oso_so_addr;
908 if (oso_module->ResolveFileAddress(oso_file_addr, oso_so_addr)) {
909 if (SymbolFile *sym_file = oso_module->GetSymbolFile()) {
910 resolved_flags |= sym_file->ResolveSymbolContext(
911 oso_so_addr, resolve_scope, sc);
912 } else {
913 ObjectFile *obj_file = GetObjectFile();
915 "Failed to get symfile for OSO: {0} in module: {1}",
916 oso_module->GetFileSpec(),
917 obj_file ? obj_file->GetFileSpec()
918 : FileSpec("unknown"));
919 }
920 }
921 }
922 }
923 }
924 }
925 }
926 return resolved_flags;
927}
928
930 const SourceLocationSpec &src_location_spec,
931 SymbolContextItem resolve_scope, SymbolContextList &sc_list) {
932 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
933 const uint32_t initial = sc_list.GetSize();
934 const uint32_t cu_count = GetNumCompileUnits();
935
936 for (uint32_t i = 0; i < cu_count; ++i) {
937 // If we are checking for inlines, then we need to look through all compile
938 // units no matter if "file_spec" matches.
939 bool resolve = src_location_spec.GetCheckInlines();
940
941 if (!resolve) {
942 FileSpec so_file_spec;
943 if (GetFileSpecForSO(i, so_file_spec))
944 resolve =
945 FileSpec::Match(src_location_spec.GetFileSpec(), so_file_spec);
946 }
947 if (resolve) {
949 if (oso_dwarf)
950 oso_dwarf->ResolveSymbolContext(src_location_spec, resolve_scope,
951 sc_list);
952 }
953 }
954 return sc_list.GetSize() - initial;
955}
956
958 ConstString name, const CompilerDeclContext &parent_decl_ctx,
959 const std::vector<uint32_t>
960 &indexes, // Indexes into the symbol table that match "name"
961 uint32_t max_matches, VariableList &variables) {
962 const size_t match_count = indexes.size();
963 for (size_t i = 0; i < match_count; ++i) {
964 uint32_t oso_idx;
965 CompileUnitInfo *comp_unit_info =
966 GetCompileUnitInfoForSymbolWithIndex(indexes[i], &oso_idx);
967 if (comp_unit_info) {
968 SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex(oso_idx);
969 if (oso_dwarf) {
970 oso_dwarf->FindGlobalVariables(name, parent_decl_ctx, max_matches,
971 variables);
972 if (variables.GetSize() > max_matches)
973 break;
974 }
975 }
976 }
977}
978
980 ConstString name, const CompilerDeclContext &parent_decl_ctx,
981 uint32_t max_matches, VariableList &variables) {
982 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
983 uint32_t total_matches = 0;
984
986 "Looking up global variables", [&](SymbolFileDWARF &oso_dwarf) {
987 const uint32_t old_size = variables.GetSize();
988 oso_dwarf.FindGlobalVariables(name, parent_decl_ctx, max_matches,
989 variables);
990 const uint32_t oso_matches = variables.GetSize() - old_size;
991 if (oso_matches > 0) {
992 total_matches += oso_matches;
993
994 // If we are getting all matches, keep going.
995 if (max_matches == UINT32_MAX)
997
998 // If we have found enough matches, lets get out
999 if (max_matches >= total_matches)
1000 return IterationAction::Stop;
1001
1002 // Update the max matches for any subsequent calls to find globals in
1003 // any other object files with DWARF
1004 max_matches -= oso_matches;
1005 }
1006
1008 });
1009}
1010
1012 const RegularExpression &regex, uint32_t max_matches,
1013 VariableList &variables) {
1014 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1015 uint32_t total_matches = 0;
1017 "Looking up global variables", [&](SymbolFileDWARF &oso_dwarf) {
1018 const uint32_t old_size = variables.GetSize();
1019 oso_dwarf.FindGlobalVariables(regex, max_matches, variables);
1020
1021 const uint32_t oso_matches = variables.GetSize() - old_size;
1022 if (oso_matches > 0) {
1023 total_matches += oso_matches;
1024
1025 // If we are getting all matches, keep going.
1026 if (max_matches == UINT32_MAX)
1028
1029 // If we have found enough matches, lets get out
1030 if (max_matches >= total_matches)
1031 return IterationAction::Stop;
1032
1033 // Update the max matches for any subsequent calls to find globals in
1034 // any other object files with DWARF
1035 max_matches -= oso_matches;
1036 }
1037
1039 });
1040}
1041
1043 uint32_t *symbol_idx_ptr, const CompileUnitInfo *comp_unit_info) {
1044 const uint32_t symbol_idx = *symbol_idx_ptr;
1045
1046 if (symbol_idx < comp_unit_info->first_symbol_index)
1047 return -1;
1048
1049 if (symbol_idx <= comp_unit_info->last_symbol_index)
1050 return 0;
1051
1052 return 1;
1053}
1054
1056 user_id_t *symbol_idx_ptr, const CompileUnitInfo *comp_unit_info) {
1057 const user_id_t symbol_id = *symbol_idx_ptr;
1058
1059 if (symbol_id < comp_unit_info->first_symbol_id)
1060 return -1;
1061
1062 if (symbol_id <= comp_unit_info->last_symbol_id)
1063 return 0;
1064
1065 return 1;
1066}
1067
1070 uint32_t symbol_idx, uint32_t *oso_idx_ptr) {
1071 const uint32_t oso_index_count = m_compile_unit_infos.size();
1072 CompileUnitInfo *comp_unit_info = nullptr;
1073 if (oso_index_count) {
1074 comp_unit_info = (CompileUnitInfo *)bsearch(
1075 &symbol_idx, &m_compile_unit_infos[0], m_compile_unit_infos.size(),
1076 sizeof(CompileUnitInfo),
1078 }
1079
1080 if (oso_idx_ptr) {
1081 if (comp_unit_info != nullptr)
1082 *oso_idx_ptr = comp_unit_info - &m_compile_unit_infos[0];
1083 else
1084 *oso_idx_ptr = UINT32_MAX;
1085 }
1086 return comp_unit_info;
1087}
1088
1091 user_id_t symbol_id, uint32_t *oso_idx_ptr) {
1092 const uint32_t oso_index_count = m_compile_unit_infos.size();
1093 CompileUnitInfo *comp_unit_info = nullptr;
1094 if (oso_index_count) {
1095 comp_unit_info = (CompileUnitInfo *)::bsearch(
1096 &symbol_id, &m_compile_unit_infos[0], m_compile_unit_infos.size(),
1097 sizeof(CompileUnitInfo),
1099 }
1100
1101 if (oso_idx_ptr) {
1102 if (comp_unit_info != nullptr)
1103 *oso_idx_ptr = comp_unit_info - &m_compile_unit_infos[0];
1104 else
1105 *oso_idx_ptr = UINT32_MAX;
1106 }
1107 return comp_unit_info;
1108}
1109
1111 SymbolContextList &sc_list,
1112 uint32_t start_idx) {
1113 // We found functions in .o files. Not all functions in the .o files will
1114 // have made it into the final output file. The ones that did make it into
1115 // the final output file will have a section whose module matches the module
1116 // from the ObjectFile for this SymbolFile. When the modules don't match,
1117 // then we have something that was in a .o file, but doesn't map to anything
1118 // in the final executable.
1119 uint32_t i = start_idx;
1120 while (i < sc_list.GetSize()) {
1121 SymbolContext sc;
1122 sc_list.GetContextAtIndex(i, sc);
1123 if (sc.function) {
1124 const SectionSP section_sp = sc.function->GetAddress().GetSection();
1125 if (section_sp->GetModule() != module_sp) {
1126 sc_list.RemoveContextAtIndex(i);
1127 continue;
1128 }
1129 }
1130 ++i;
1131 }
1132}
1133
1135 const Module::LookupInfo &lookup_info,
1136 const CompilerDeclContext &parent_decl_ctx, bool include_inlines,
1137 SymbolContextList &sc_list) {
1138 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1139 LLDB_SCOPED_TIMERF("SymbolFileDWARFDebugMap::FindFunctions (name = %s)",
1140 lookup_info.GetLookupName().GetCString());
1141
1142 ForEachSymbolFile("Looking up functions", [&](SymbolFileDWARF &oso_dwarf) {
1143 uint32_t sc_idx = sc_list.GetSize();
1144 oso_dwarf.FindFunctions(lookup_info, parent_decl_ctx, include_inlines,
1145 sc_list);
1146 if (!sc_list.IsEmpty()) {
1148 sc_idx);
1149 }
1151 });
1152}
1153
1155 bool include_inlines,
1156 SymbolContextList &sc_list) {
1157 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1158 LLDB_SCOPED_TIMERF("SymbolFileDWARFDebugMap::FindFunctions (regex = '%s')",
1159 regex.GetText().str().c_str());
1160
1161 ForEachSymbolFile("Looking up functions", [&](SymbolFileDWARF &oso_dwarf) {
1162 uint32_t sc_idx = sc_list.GetSize();
1163
1164 oso_dwarf.FindFunctions(regex, include_inlines, sc_list);
1165 if (!sc_list.IsEmpty()) {
1167 sc_idx);
1168 }
1170 });
1171}
1172
1174 lldb::TypeClass type_mask,
1175 TypeList &type_list) {
1176 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1177 LLDB_SCOPED_TIMERF("SymbolFileDWARFDebugMap::GetTypes (type_mask = 0x%8.8x)",
1178 type_mask);
1179
1180 SymbolFileDWARF *oso_dwarf = nullptr;
1181 if (sc_scope) {
1182 SymbolContext sc;
1183 sc_scope->CalculateSymbolContext(&sc);
1184
1185 CompileUnitInfo *cu_info = GetCompUnitInfo(sc);
1186 if (cu_info) {
1187 oso_dwarf = GetSymbolFileByCompUnitInfo(cu_info);
1188 if (oso_dwarf)
1189 oso_dwarf->GetTypes(sc_scope, type_mask, type_list);
1190 }
1191 } else {
1192 ForEachSymbolFile("Looking up types", [&](SymbolFileDWARF &oso_dwarf) {
1193 oso_dwarf.GetTypes(sc_scope, type_mask, type_list);
1195 });
1196 }
1197}
1198
1199std::vector<std::unique_ptr<lldb_private::CallEdge>>
1201 lldb_private::UserID func_id) {
1202 uint32_t oso_idx = GetOSOIndexFromUserID(func_id.GetID());
1203 SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex(oso_idx);
1204 if (oso_dwarf)
1205 return oso_dwarf->ParseCallEdgesInFunction(func_id);
1206 return {};
1207}
1208
1210 DWARFDIE result;
1212 "Looking up type definition", [&](SymbolFileDWARF &oso_dwarf) {
1213 result = oso_dwarf.FindDefinitionDIE(die);
1215 });
1216 return result;
1217}
1218
1220 const DWARFDIE &die, ConstString type_name, bool must_be_implementation) {
1221 // If we have a debug map, we will have an Objective-C symbol whose name is
1222 // the type name and whose type is eSymbolTypeObjCClass. If we can find that
1223 // symbol and find its containing parent, we can locate the .o file that will
1224 // contain the implementation definition since it will be scoped inside the
1225 // N_SO and we can then locate the SymbolFileDWARF that corresponds to that
1226 // N_SO.
1227 SymbolFileDWARF *oso_dwarf = nullptr;
1228 TypeSP type_sp;
1229 ObjectFile *module_objfile = m_objfile_sp->GetModule()->GetObjectFile();
1230 if (module_objfile) {
1231 Symtab *symtab = module_objfile->GetSymtab();
1232 if (symtab) {
1233 Symbol *objc_class_symbol = symtab->FindFirstSymbolWithNameAndType(
1236 if (objc_class_symbol) {
1237 // Get the N_SO symbol that contains the objective C class symbol as
1238 // this should be the .o file that contains the real definition...
1239 const Symbol *source_file_symbol = symtab->GetParent(objc_class_symbol);
1240
1241 if (source_file_symbol &&
1242 source_file_symbol->GetType() == eSymbolTypeSourceFile) {
1243 const uint32_t source_file_symbol_idx =
1244 symtab->GetIndexForSymbol(source_file_symbol);
1245 if (source_file_symbol_idx != UINT32_MAX) {
1246 CompileUnitInfo *compile_unit_info =
1247 GetCompileUnitInfoForSymbolWithIndex(source_file_symbol_idx,
1248 nullptr);
1249 if (compile_unit_info) {
1250 oso_dwarf = GetSymbolFileByCompUnitInfo(compile_unit_info);
1251 if (oso_dwarf) {
1253 die, type_name, must_be_implementation));
1254 if (type_sp) {
1255 return type_sp;
1256 }
1257 }
1258 }
1259 }
1260 }
1261 }
1262 }
1263 }
1264
1265 // Only search all .o files for the definition if we don't need the
1266 // implementation because otherwise, with a valid debug map we should have
1267 // the ObjC class symbol and the code above should have found it.
1268 if (!must_be_implementation) {
1269 TypeSP type_sp;
1270
1272 "Looking up Objective-C definition", [&](SymbolFileDWARF &oso_dwarf) {
1273 type_sp = oso_dwarf.FindCompleteObjCDefinitionTypeForDIE(
1274 die, type_name, must_be_implementation);
1276 });
1277
1278 return type_sp;
1279 }
1280 return TypeSP();
1281}
1282
1284 TypeResults &results) {
1285 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1286 ForEachSymbolFile("Looking up type", [&](SymbolFileDWARF &oso_dwarf) {
1287 oso_dwarf.FindTypes(query, results);
1288 return results.Done(query) ? IterationAction::Stop
1290 });
1291}
1292
1294 lldb_private::ConstString name, const CompilerDeclContext &parent_decl_ctx,
1295 bool only_root_namespaces) {
1296 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1297 CompilerDeclContext matching_namespace;
1298
1299 ForEachSymbolFile("Looking up namespace", [&](SymbolFileDWARF &oso_dwarf) {
1300 matching_namespace =
1301 oso_dwarf.FindNamespace(name, parent_decl_ctx, only_root_namespaces);
1302
1303 return matching_namespace ? IterationAction::Stop
1305 });
1306
1307 return matching_namespace;
1308}
1309
1310void SymbolFileDWARFDebugMap::DumpClangAST(Stream &s, llvm::StringRef filter,
1311 bool show_color) {
1312 ForEachSymbolFile("Dumping clang AST", [&](SymbolFileDWARF &oso_dwarf) {
1313 oso_dwarf.DumpClangAST(s, filter, show_color);
1314 // The underlying assumption is that DumpClangAST(...) will obtain the
1315 // AST from the underlying TypeSystem and therefore we only need to do
1316 // this once and can stop after the first iteration hence we return true.
1317 return IterationAction::Stop;
1318 });
1319}
1320
1323 const uint32_t cu_count = GetNumCompileUnits();
1325 for (uint32_t cu_idx = 0; cu_idx < cu_count; ++cu_idx) {
1326 const auto &info = m_compile_unit_infos[cu_idx];
1327 if (info.so_file.GetPath().empty())
1328 continue;
1329
1330 ModuleSpec spec;
1331 FileSpec oso_file;
1332 llvm::StringRef oso_object;
1333 if (ObjectFile::SplitArchivePathWithObject(info.oso_path.GetStringRef(),
1334 oso_file, oso_object,
1335 /*must_exist=*/false)) {
1336 spec.GetFileSpec() = oso_file;
1337 spec.SetObjectName(oso_object.str());
1338 } else {
1339 spec.GetFileSpec() = FileSpec(info.oso_path.GetStringRef());
1340 }
1341
1342 spec.GetObjectModificationTime() = info.oso_mod_time;
1343 spec_list.Append(spec);
1344 }
1345 return spec_list;
1346}
1347
1349 lldb_private::StructuredData::Dictionary &d, bool errors_only,
1350 bool load_all_debug_info) {
1351 StructuredData::Array separate_debug_info_files;
1352 const uint32_t cu_count = GetNumCompileUnits();
1353 for (uint32_t cu_idx = 0; cu_idx < cu_count; ++cu_idx) {
1354 const auto &info = m_compile_unit_infos[cu_idx];
1356 std::make_shared<StructuredData::Dictionary>();
1357 oso_data->AddStringItem("so_file", info.so_file.GetPath());
1358 oso_data->AddStringItem("oso_path", info.oso_path);
1359 oso_data->AddIntegerItem("oso_mod_time",
1360 (uint32_t)llvm::sys::toTimeT(info.oso_mod_time));
1361
1362 bool loaded_successfully = false;
1363 if (GetModuleByOSOIndex(cu_idx)) {
1364 // If we have a valid pointer to the module, we successfully
1365 // loaded the oso if there are no load errors.
1366 if (!info.oso_load_error.Fail()) {
1367 loaded_successfully = true;
1368 }
1369 }
1370 if (!loaded_successfully) {
1371 oso_data->AddStringItem("error", info.oso_load_error.AsCString());
1372 }
1373 oso_data->AddBooleanItem("loaded", loaded_successfully);
1374 if (!errors_only || oso_data->HasKey("error"))
1375 separate_debug_info_files.AddItem(oso_data);
1376 }
1377
1378 d.AddStringItem("type", "oso");
1379 d.AddStringItem("symfile", GetMainObjectFile()->GetFileSpec().GetPath());
1380 d.AddItem("separate-debug-info-files",
1381 std::make_shared<StructuredData::Array>(
1382 std::move(separate_debug_info_files)));
1383 return true;
1384}
1385
1388 DWARFCompileUnit &dwarf_cu) {
1389 if (oso_dwarf) {
1390 const uint32_t cu_count = GetNumCompileUnits();
1391 for (uint32_t cu_idx = 0; cu_idx < cu_count; ++cu_idx) {
1392 SymbolFileDWARF *oso_symfile =
1394 if (oso_symfile == oso_dwarf) {
1395 if (m_compile_unit_infos[cu_idx].compile_units_sps.empty())
1397
1398 auto &id_to_index_map = m_compile_unit_infos[cu_idx].id_to_index_map;
1399 auto it = id_to_index_map.find(dwarf_cu.GetID());
1400 if (it != id_to_index_map.end())
1401 return m_compile_unit_infos[cu_idx]
1402 .compile_units_sps[it->getSecond()];
1403 }
1404 }
1405 }
1406 llvm_unreachable("this shouldn't happen");
1407}
1408
1411 if (oso_dwarf) {
1412 const uint32_t cu_count = GetNumCompileUnits();
1413 for (uint32_t cu_idx = 0; cu_idx < cu_count; ++cu_idx) {
1414 SymbolFileDWARF *oso_symfile =
1416 if (oso_symfile == oso_dwarf) {
1417 return &m_compile_unit_infos[cu_idx];
1418 }
1419 }
1420 }
1421 return nullptr;
1422}
1423
1425 const CompUnitSP &cu_sp) {
1426 if (oso_dwarf) {
1427 const uint32_t cu_count = GetNumCompileUnits();
1428 for (uint32_t cu_idx = 0; cu_idx < cu_count; ++cu_idx) {
1429 SymbolFileDWARF *oso_symfile =
1431 if (oso_symfile == oso_dwarf) {
1432 if (!m_compile_unit_infos[cu_idx].compile_units_sps.empty()) {
1433 assert(m_compile_unit_infos[cu_idx].compile_units_sps[0].get() ==
1434 cu_sp.get());
1435 } else {
1436 assert(cu_sp->GetID() == 0 &&
1437 "Setting first compile unit but with id different than 0!");
1438 auto &compile_units_sps =
1439 m_compile_unit_infos[cu_idx].compile_units_sps;
1440 compile_units_sps.push_back(cu_sp);
1441 m_compile_unit_infos[cu_idx].id_to_index_map.insert(
1442 {cu_sp->GetID(), compile_units_sps.size() - 1});
1443
1444 SetCompileUnitAtIndex(cu_idx, cu_sp);
1445 }
1446 }
1447 }
1448 }
1449}
1450
1453 const uint64_t oso_idx = GetOSOIndexFromUserID(type_uid);
1454 if (SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex(oso_idx))
1455 return oso_dwarf->GetDeclContextForUID(type_uid);
1456 return {};
1457}
1458
1461 const uint64_t oso_idx = GetOSOIndexFromUserID(type_uid);
1462 if (SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex(oso_idx))
1463 return oso_dwarf->GetDeclContextContainingUID(type_uid);
1464 return {};
1465}
1466
1467std::vector<CompilerContext>
1469 const uint64_t oso_idx = GetOSOIndexFromUserID(type_uid);
1470 if (SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex(oso_idx))
1471 return oso_dwarf->GetCompilerContextForUID(type_uid);
1472 return {};
1473}
1474
1477 ForEachSymbolFile("Parsing declarations", [&](SymbolFileDWARF &oso_dwarf) {
1478 oso_dwarf.ParseDeclsForContext(decl_ctx);
1480 });
1481}
1482
1484 lldb::addr_t exe_file_addr,
1485 lldb::addr_t exe_byte_size,
1486 lldb::addr_t oso_file_addr,
1487 lldb::addr_t oso_byte_size) {
1488 const uint32_t debug_map_idx =
1489 m_debug_map.FindEntryIndexThatContains(exe_file_addr);
1490 if (debug_map_idx != UINT32_MAX) {
1491 DebugMap::Entry *debug_map_entry =
1492 m_debug_map.FindEntryThatContains(exe_file_addr);
1493 debug_map_entry->data.SetOSOFileAddress(oso_file_addr);
1494 addr_t range_size = std::min<addr_t>(exe_byte_size, oso_byte_size);
1495 if (range_size == 0) {
1496 range_size = std::max<addr_t>(exe_byte_size, oso_byte_size);
1497 if (range_size == 0)
1498 range_size = 1;
1499 }
1500 cu_info->file_range_map.Append(
1501 FileRangeMap::Entry(oso_file_addr, range_size, exe_file_addr));
1502 return true;
1503 }
1504 return false;
1505}
1506
1508 cu_info->file_range_map.Sort();
1509#if defined(DEBUG_OSO_DMAP)
1510 const FileRangeMap &oso_file_range_map = cu_info->GetFileRangeMap(this);
1511 const size_t n = oso_file_range_map.GetSize();
1512 printf("SymbolFileDWARFDebugMap::FinalizeOSOFileRanges (cu_info = %p) %s\n",
1513 cu_info, cu_info->oso_sp->module_sp->GetFileSpec().GetPath().c_str());
1514 for (size_t i = 0; i < n; ++i) {
1515 const FileRangeMap::Entry &entry = oso_file_range_map.GetEntryRef(i);
1516 printf("oso [0x%16.16" PRIx64 " - 0x%16.16" PRIx64
1517 ") ==> exe [0x%16.16" PRIx64 " - 0x%16.16" PRIx64 ")\n",
1518 entry.GetRangeBase(), entry.GetRangeEnd(), entry.data,
1519 entry.data + entry.GetByteSize());
1520 }
1521#endif
1522}
1523
1526 lldb::addr_t oso_file_addr) {
1527 CompileUnitInfo *cu_info = GetCompileUnitInfo(oso_symfile);
1528 if (cu_info) {
1529 const FileRangeMap::Entry *oso_range_entry =
1530 cu_info->GetFileRangeMap(this).FindEntryThatContains(oso_file_addr);
1531 if (oso_range_entry) {
1532 const DebugMap::Entry *debug_map_entry =
1533 m_debug_map.FindEntryThatContains(oso_range_entry->data);
1534 if (debug_map_entry) {
1535 const lldb::addr_t offset =
1536 oso_file_addr - oso_range_entry->GetRangeBase();
1537 const lldb::addr_t exe_file_addr =
1538 debug_map_entry->GetRangeBase() + offset;
1539 return exe_file_addr;
1540 }
1541 }
1542 }
1543 return LLDB_INVALID_ADDRESS;
1544}
1545
1547 // Make sure this address hasn't been fixed already
1548 Module *exe_module = GetObjectFile()->GetModule().get();
1549 Module *addr_module = addr.GetModule().get();
1550 if (addr_module == exe_module)
1551 return true; // Address is already in terms of the main executable module
1552
1555 if (cu_info) {
1556 const lldb::addr_t oso_file_addr = addr.GetFileAddress();
1557 const FileRangeMap::Entry *oso_range_entry =
1558 cu_info->GetFileRangeMap(this).FindEntryThatContains(oso_file_addr);
1559 if (oso_range_entry) {
1560 const DebugMap::Entry *debug_map_entry =
1561 m_debug_map.FindEntryThatContains(oso_range_entry->data);
1562 if (debug_map_entry) {
1563 const lldb::addr_t offset =
1564 oso_file_addr - oso_range_entry->GetRangeBase();
1565 const lldb::addr_t exe_file_addr =
1566 debug_map_entry->GetRangeBase() + offset;
1567 return exe_module->ResolveFileAddress(exe_file_addr, addr);
1568 }
1569 }
1570 }
1571 return true;
1572}
1573
1575 LineTable *line_table) {
1576 CompileUnitInfo *cu_info = GetCompileUnitInfo(oso_dwarf);
1577 if (cu_info)
1578 return line_table->LinkLineTable(cu_info->GetFileRangeMap(this));
1579 return nullptr;
1580}
1581
1582size_t
1584 DWARFDebugAranges *debug_aranges) {
1585 size_t num_line_entries_added = 0;
1586 if (debug_aranges && dwarf2Data) {
1587 CompileUnitInfo *compile_unit_info = GetCompileUnitInfo(dwarf2Data);
1588 if (compile_unit_info) {
1589 const FileRangeMap &file_range_map =
1590 compile_unit_info->GetFileRangeMap(this);
1591 for (size_t idx = 0; idx < file_range_map.GetSize(); idx++) {
1592 const FileRangeMap::Entry *entry = file_range_map.GetEntryAtIndex(idx);
1593 if (entry) {
1594 debug_aranges->AppendRange(*dwarf2Data->GetFileIndex(),
1595 entry->GetRangeBase(),
1596 entry->GetRangeEnd());
1597 num_line_entries_added++;
1598 }
1599 }
1600 }
1601 }
1602 return num_line_entries_added;
1603}
1604
1606 ModuleList oso_modules;
1607 ForEachSymbolFile("Parsing modules", [&](SymbolFileDWARF &oso_dwarf) {
1608 ObjectFile *oso_objfile = oso_dwarf.GetObjectFile();
1609 if (oso_objfile) {
1610 ModuleSP module_sp = oso_objfile->GetModule();
1611 if (module_sp)
1612 oso_modules.Append(module_sp);
1613 }
1615 });
1616 return oso_modules;
1617}
1618
1620 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1621
1622 // We need to make sure that our PC value from the frame matches the module
1623 // for this object file since we will lookup the PC file address in the debug
1624 // map below.
1625 Address pc_addr = frame.GetFrameCodeAddress();
1626 if (pc_addr.GetModule() == m_objfile_sp->GetModule()) {
1627 Symtab *symtab = m_objfile_sp->GetSymtab();
1628 if (symtab) {
1629 const DebugMap::Entry *debug_map_entry =
1630 m_debug_map.FindEntryThatContains(pc_addr.GetFileAddress());
1631 if (debug_map_entry) {
1632 const Symbol *symbol =
1633 symtab->SymbolAtIndex(debug_map_entry->data.GetExeSymbolIndex());
1634 if (symbol) {
1635 uint32_t oso_idx = 0;
1636 CompileUnitInfo *comp_unit_info =
1637 GetCompileUnitInfoForSymbolWithID(symbol->GetID(), &oso_idx);
1638 if (comp_unit_info) {
1639 Module *oso_module = GetModuleByCompUnitInfo(comp_unit_info);
1640 if (oso_module) {
1641 // Check the .o file's DWARF in case it has an error to display.
1642 SymbolFile *oso_sym_file = oso_module->GetSymbolFile();
1643 if (oso_sym_file)
1644 return oso_sym_file->GetFrameVariableError(frame);
1645 }
1646 // If we don't have a valid OSO module here, then something went
1647 // wrong as we have a symbol for the address in the debug map, but
1648 // we weren't able to open the .o file. Display an appropriate
1649 // error
1650 if (comp_unit_info->oso_load_error.Fail())
1651 return comp_unit_info->oso_load_error.Clone();
1652 else
1654 "unable to load debug map object file \"%s\" "
1655 "exist, debug info will not be loaded",
1656 comp_unit_info->oso_path.GetCString());
1657 }
1658 }
1659 }
1660 }
1661 }
1662 return Status();
1663}
1664
1666 std::unordered_map<lldb::CompUnitSP, lldb_private::Args> &args) {
1667
1668 ForEachSymbolFile("Parsing compile options", [&](SymbolFileDWARF &oso_dwarf) {
1669 oso_dwarf.GetCompileOptions(args);
1671 });
1672}
1673
1676 lldb::TypeSP type;
1677 ForEachSymbolFile("Looking up enclosing type for variable",
1678 [&](SymbolFileDWARF &oso_dwarf) {
1679 type = oso_dwarf.GetTypeEnclosingVariableUID(uid);
1680 return type ? IterationAction::Stop
1682 });
1683 return type;
1684}
1685
1686llvm::Expected<SymbolContext>
1688 const uint64_t oso_idx = GetOSOIndexFromUserID(label.symbol_id);
1689 SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex(oso_idx);
1690 if (!oso_dwarf)
1691 return llvm::createStringErrorV(
1692 "couldn't find symbol file for {0} in debug-map.", label);
1693
1694 return oso_dwarf->ResolveFunctionCallLabel(label);
1695}
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
Definition Log.h:375
#define LLDB_LOGF(log,...)
Definition Log.h:389
static void RemoveFunctionsWithModuleNotEqualTo(const ModuleSP &module_sp, SymbolContextList &sc_list, uint32_t start_idx)
static bool OSOExists(llvm::StringRef oso_path)
#define LLDB_SCOPED_TIMERF(...)
Definition Timer.h:91
A section + offset based address class.
Definition Address.h:62
lldb::SectionSP GetSection() const
Get const accessor for the section.
Definition Address.h:426
lldb::ModuleSP GetModule() const
Get accessor for the module for this address.
Definition Address.cpp:275
lldb::addr_t GetFileAddress() const
Get the file address.
Definition Address.cpp:283
An architecture specification class.
Definition ArchSpec.h:32
bool SetTriple(const llvm::Triple &triple)
Architecture triple setter.
Definition ArchSpec.cpp:768
A class that describes a compilation unit.
Definition CompileUnit.h:43
lldb::LanguageType GetLanguage()
Represents a generic declaration context in a program.
Generic representation of a type in a programming language.
A uniqued constant string class.
Definition ConstString.h:40
llvm::StringRef GetStringRef() const
Get the string value as a llvm::StringRef.
const char * GetCString() const
Get the string value as a C string.
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
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
static bool Match(const FileSpec &pattern, const FileSpec &file)
Match FileSpec pattern against FileSpec file.
Definition FileSpec.cpp:317
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
Definition FileSpec.cpp:380
bool Exists(const FileSpec &file_spec) const
Returns whether the given file exists.
static FileSystem & Instance()
A class that describes a function.
Definition Function.h:386
const Address & GetAddress() const
Return the address of the function (its entry point).
Definition Function.h:439
CompileUnit * GetCompileUnit()
Get accessor for the compile unit that owns this function.
Definition Function.cpp:416
A line table class.
Definition LineTable.h:25
LineTable * LinkLineTable(const FileRangeMap &file_range_map)
ConstString GetName(NamePreference preference=ePreferDemangled) const
Best name get accessor.
Definition Mangled.cpp:297
lldb::ModuleSP GetModule() const
Get const accessor for the module pointer.
A collection class for Module objects.
Definition ModuleList.h:127
void Append(const lldb::ModuleSP &module_sp, bool notify=true)
Append a module to the module list.
void Append(const ModuleSpec &spec)
Definition ModuleSpec.h:371
FileSpec & GetFileSpec()
Definition ModuleSpec.h:57
llvm::sys::TimePoint & GetObjectModificationTime()
Definition ModuleSpec.h:130
void SetObjectName(std::string name)
Definition ModuleSpec.h:107
A class that encapsulates name lookup information.
Definition Module.h:957
ConstString GetLookupName() const
Definition Module.h:997
A class that describes an executable image and its associated object and symbol files.
Definition Module.h:92
virtual ObjectFile * GetObjectFile()
Get the object file representation for the current architecture.
Definition Module.cpp:1208
virtual SymbolFile * GetSymbolFile(bool can_create=true, Stream *feedback_strm=nullptr)
Get the module's symbol file.
Definition Module.cpp:994
Module(const FileSpec &file_spec, const ArchSpec &arch, std::string object_name=std::string(), lldb::offset_t object_offset=0, const llvm::sys::TimePoint<> &object_mod_time=llvm::sys::TimePoint<>())
Construct with file specification and architecture.
Definition Module.cpp:232
std::recursive_mutex m_mutex
A mutex to keep this object happy in multi-threaded environments.
Definition Module.h:1098
bool ResolveFileAddress(lldb::addr_t vm_addr, Address &so_addr)
Definition Module.cpp:425
lldb::SymbolVendorUP m_symfile_up
A pointer to the symbol vendor for this module.
Definition Module.h:1138
friend class ObjectFile
Definition Module.h:1197
std::string GetSpecificationDescription() const
Get the module path and object name.
Definition Module.cpp:1045
const FileSpec & GetFileSpec() const
Get const accessor for the module file specification.
Definition Module.h:448
friend class SymbolFile
Definition Module.h:1198
A plug-in interface definition class for object file parsers.
Definition ObjectFile.h:46
static bool SplitArchivePathWithObject(llvm::StringRef path_with_object, lldb_private::FileSpec &archive_file, llvm::StringRef &archive_object, bool must_exist)
Split a path into a file path with object name.
Symtab * GetSymtab(bool can_create=true)
Gets the symbol table for the currently selected architecture (and object for archives).
@ eTypeExecutable
A normal executable.
Definition ObjectFile.h:55
@ eTypeDebugInfo
An object file that contains only debug information.
Definition ObjectFile.h:57
@ eTypeStubLibrary
A library that can be linked against but not used for execution.
Definition ObjectFile.h:65
@ eTypeObjectFile
An intermediate object file.
Definition ObjectFile.h:61
@ eTypeDynamicLinker
The platform's dynamic linker executable.
Definition ObjectFile.h:59
@ eTypeCoreFile
A core file that has a checkpoint of a program's execution state.
Definition ObjectFile.h:53
@ eTypeSharedLibrary
A shared library that can be used during execution.
Definition ObjectFile.h:63
@ eTypeJIT
JIT code that has symbols, sections and possibly debug info.
Definition ObjectFile.h:67
virtual void ClearSymtab()
Frees the symbol table.
virtual FileSpec & GetFileSpec()
Get accessor to the object file specification.
Definition ObjectFile.h:284
virtual llvm::StringRef GetPluginName()=0
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description, ABICreateInstance create_callback)
static bool UnregisterPlugin(ABICreateInstance create_callback)
A Progress indicator helper class.
Definition Progress.h:60
void Increment(uint64_t amount=1, std::optional< std::string > updated_detail={})
Increment the progress and send a notification to the installed callback.
Definition Progress.cpp:63
static constexpr std::chrono::milliseconds kDefaultHighFrequencyReportTime
The default report time for high frequency progress reports.
Definition Progress.h:119
Entry & GetEntryRef(size_t i)
Definition RangeMap.h:558
const Entry * GetEntryAtIndex(size_t i) const
Definition RangeMap.h:548
RangeData< lldb::addr_t, lldb::addr_t, OSOEntry > Entry
Definition RangeMap.h:462
void Append(const Entry &entry)
Definition RangeMap.h:474
Entry * FindEntryThatContains(B addr)
Definition RangeMap.h:583
llvm::StringRef GetText() const
Access the regular expression text.
This base class provides an interface to stack frames.
Definition StackFrame.h:44
virtual const Address & GetFrameCodeAddress()
Get an Address for the current pc value in this StackFrame.
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 FromErrorStringWithFormat(const char *format,...) __attribute__((format(printf
Definition Status.cpp:106
bool Fail() const
Test for error condition.
Definition Status.cpp:293
const char * AsCString(const char *default_error_str="unknown error") const
Get the error string associated with the current error.
Definition Status.cpp:194
static Status static Status FromErrorStringWithFormatv(const char *format, Args &&...args)
Definition Status.h:151
A stream class that can stream formatted output to a file.
Definition Stream.h:28
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.
Defines a list of symbol context objects.
bool GetContextAtIndex(size_t idx, SymbolContext &sc) const
Get accessor for a symbol context at index idx.
uint32_t GetSize() const
Get accessor for a symbol context list size.
"lldb/Symbol/SymbolContextScope.h" Inherit from this if your object is part of a symbol context and c...
virtual void CalculateSymbolContext(SymbolContext *sc)=0
Reconstruct the object's symbol context into sc.
Defines a symbol context baton that can be handed other debug core functions.
Function * function
The Function for a given query.
CompileUnit * comp_unit
The CompileUnit for a given query.
Symbol * symbol
The Symbol for a given query.
ObjectFile * GetObjectFile() override
Definition SymbolFile.h:601
lldb::ObjectFileSP m_objfile_sp
Definition SymbolFile.h:677
ObjectFile * GetMainObjectFile() override
void SetCompileUnitAtIndex(uint32_t idx, const lldb::CompUnitSP &cu_sp)
SymbolFileCommon(lldb::ObjectFileSP objfile_sp)
Definition SymbolFile.h:586
uint32_t GetNumCompileUnits() override
Provides public interface for all SymbolFiles.
Definition SymbolFile.h:51
virtual std::recursive_mutex & GetModuleMutex() const
Symbols file subclasses should override this to return the Module that owns the TypeSystem that this ...
Status GetFrameVariableError(StackFrame &frame)
Get an error that describes why variables might be missing for a given symbol context.
Definition SymbolFile.h:287
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:545
uint32_t GetSiblingIndex() const
Definition Symbol.cpp:242
uint64_t GetIntegerValue(uint64_t fail_value=0) const
Definition Symbol.h:129
uint32_t GetID() const
Definition Symbol.h:152
bool ValueIsAddress() const
Definition Symbol.cpp:192
bool IsDebug() const
Definition Symbol.h:221
Mangled & GetMangled()
Definition Symbol.h:162
Address & GetAddressRef()
Definition Symbol.h:78
lldb::addr_t GetByteSize() const
Definition Symbol.cpp:470
ConstString GetName() const
Definition Symbol.cpp:615
lldb::SymbolType GetType() const
Definition Symbol.h:197
Symbol * SymbolAtIndex(size_t idx)
Definition Symtab.cpp:226
Symbol * FindFirstSymbolWithNameAndType(ConstString name, lldb::SymbolType symbol_type, Debug symbol_debug_type, Visibility symbol_visibility)
Definition Symtab.cpp:842
void SortSymbolIndexesByValue(std::vector< uint32_t > &indexes, bool remove_duplicates) const
Definition Symtab.cpp:604
uint32_t AppendSymbolIndexesWithType(lldb::SymbolType symbol_type, std::vector< uint32_t > &indexes, uint32_t start_idx=0, uint32_t end_index=UINT32_MAX) const
Definition Symtab.cpp:478
uint32_t GetIndexForSymbol(const Symbol *symbol) const
Definition Symtab.cpp:539
uint32_t AppendSymbolIndexesWithTypeAndFlagsValue(lldb::SymbolType symbol_type, uint32_t flags_value, std::vector< uint32_t > &indexes, uint32_t start_idx=0, uint32_t end_index=UINT32_MAX) const
Definition Symtab.cpp:496
const Symbol * GetParent(Symbol *symbol) const
Get the parent symbol for the given symbol.
Definition Symtab.cpp:1129
A class that contains all state required for type lookups.
This class tracks the state and results of a TypeQuery.
bool Done(const TypeQuery &query) const
Check if the type matching has found all of the matches that it needs.
An abstraction which groups an XcodeSDK with the sysroot it was used from.
Definition XcodeSDK.h:101
void AppendRange(dw_offset_t cu_offset, dw_addr_t low_pc, dw_addr_t high_pc)
SymbolFile * GetSymbolFile(bool can_create=true, lldb_private::Stream *feedback_strm=nullptr) override
Get the module's symbol file.
DebugMapModule(const ModuleSP &exe_module_sp, uint32_t cu_idx, const FileSpec &file_spec, const ArchSpec &arch, std::string object_name, off_t object_offset, const llvm::sys::TimePoint<> object_mod_time)
void ForEachSymbolFile(std::string description, std::function< IterationAction(SymbolFileDWARF &)> closure)
If closure returns IterationAction::Continue, iteration continues.
static SymbolFileDWARF * GetSymbolFileAsSymbolFileDWARF(SymbolFile *sym_file)
lldb_private::ModuleSpecList GetSeparateDebugInfoFiles() override
Return a map of separate debug info files that are loaded.
RangeDataVector< lldb::addr_t, lldb::addr_t, lldb::addr_t > FileRangeMap
Status CalculateFrameVariableError(StackFrame &frame) override
Subclasses will override this function to for GetFrameVariableError().
CompileUnitInfo * GetCompUnitInfo(const SymbolContext &sc)
std::map< std::pair< ConstString, llvm::sys::TimePoint<> >, OSOInfoSP > m_oso_map
CompilerDeclContext GetDeclContextContainingUID(lldb::user_id_t uid) override
void DumpClangAST(Stream &s, llvm::StringRef filter, bool show_color) override
void ParseDeclsForContext(CompilerDeclContext decl_ctx) override
bool GetSeparateDebugInfo(StructuredData::Dictionary &d, bool errors_only, bool load_all_debug_info=false) override
List separate oso files.
void FindGlobalVariables(ConstString name, const CompilerDeclContext &parent_decl_ctx, uint32_t max_matches, VariableList &variables) override
XcodeSDKAndSysroot ParseXcodeSDK(CompileUnit &comp_unit) override
Return the Xcode SDK comp_unit was compiled against.
SymbolFileDWARF * GetSymbolFileByCompUnitInfo(CompileUnitInfo *comp_unit_info)
lldb::CompUnitSP GetCompileUnit(SymbolFileDWARF *oso_dwarf, DWARFCompileUnit &dwarf_cu)
Returns the compile unit associated with the dwarf compile unit.
bool ForEachExternalModule(CompileUnit &, llvm::DenseSet< SymbolFile * > &, llvm::function_ref< bool(Module &)>) override
uint32_t ResolveSymbolContext(const Address &so_addr, lldb::SymbolContextItem resolve_scope, SymbolContext &sc) override
lldb::TypeSP FindCompleteObjCDefinitionTypeForDIE(const DWARFDIE &die, ConstString type_name, bool must_be_implementation)
CompileUnitInfo * GetCompileUnitInfoForSymbolWithIndex(uint32_t symbol_idx, uint32_t *oso_idx_ptr)
bool CompleteType(CompilerType &compiler_type) override
ModuleList GetDebugInfoModules() override
Get the additional modules that this symbol file uses to parse debug info.
lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) override
This function actually returns the first compile unit the object file at the given index contains.
std::vector< CompilerContext > GetCompilerContextForUID(lldb::user_id_t uid) override
lldb::addr_t LinkOSOFileAddress(SymbolFileDWARF *oso_symfile, lldb::addr_t oso_file_addr)
Convert a .o file "file address" to an executable "file address".
SymbolFileDWARF * GetSymbolFile(const SymbolContext &sc)
void PrivateFindGlobalVariables(ConstString name, const CompilerDeclContext &parent_decl_ctx, const std::vector< uint32_t > &name_symbol_indexes, uint32_t max_matches, VariableList &variables)
void FindTypes(const lldb_private::TypeQuery &match, lldb_private::TypeResults &results) override
Find types using a type-matching object that contains all search parameters.
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.
CompileUnitInfo * GetCompileUnitInfo(SymbolFileDWARF *oso_dwarf)
bool GetFileSpecForSO(uint32_t oso_idx, FileSpec &file_spec)
ObjectFile * GetObjectFileByCompUnitInfo(CompileUnitInfo *comp_unit_info)
static SymbolFile * CreateInstance(lldb::ObjectFileSP objfile_sp)
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.
std::vector< std::unique_ptr< CallEdge > > ParseCallEdgesInFunction(UserID func_id) override
lldb::LanguageType ParseLanguage(CompileUnit &comp_unit) override
void ReportMissingOSOs(const CompileUnitInfo &missing_info)
Report missing object files once per module, not once per object file, to avoid flooding the console.
size_t ParseVariablesForContext(const SymbolContext &sc) override
llvm::SmallSet< lldb::LanguageType, 4 > ParseAllLanguages(CompileUnit &comp_unit) override
This function exists because SymbolFileDWARFDebugMap may extra compile units which aren't exposed as ...
uint32_t GetCompUnitInfoIndex(const CompileUnitInfo *comp_unit_info)
Module * GetModuleByCompUnitInfo(CompileUnitInfo *comp_unit_info)
size_t AddOSOARanges(SymbolFileDWARF *dwarf2Data, DWARFDebugAranges *debug_aranges)
void FindFunctions(const Module::LookupInfo &lookup_info, const CompilerDeclContext &parent_decl_ctx, bool include_inlines, SymbolContextList &sc_list) override
void GetTypes(SymbolContextScope *sc_scope, lldb::TypeClass type_mask, TypeList &type_list) override
llvm::Expected< SymbolContext > ResolveFunctionCallLabel(FunctionCallLabel &label) override
Resolves the function corresponding to the specified LLDB function call label.
bool AddOSOFileRange(CompileUnitInfo *cu_info, lldb::addr_t exe_file_addr, lldb::addr_t exe_byte_size, lldb::addr_t oso_file_addr, lldb::addr_t oso_byte_size)
bool ParseSupportFiles(CompileUnit &comp_unit, SupportFileList &support_files) override
void SetCompileUnit(SymbolFileDWARF *oso_dwarf, const lldb::CompUnitSP &cu_sp)
Type * ResolveTypeUID(lldb::user_id_t type_uid) override
static int SymbolContainsSymbolWithID(lldb::user_id_t *symbol_idx_ptr, const CompileUnitInfo *comp_unit_info)
static int SymbolContainsSymbolWithIndex(uint32_t *symbol_idx_ptr, const CompileUnitInfo *comp_unit_info)
uint32_t CalculateNumCompileUnits() override
This function actually returns the number of object files, which may be less than the actual number o...
bool ParseImportedModules(const SymbolContext &sc, std::vector< SourceModule > &imported_modules) override
lldb::TypeSP GetTypeEnclosingVariableUID(lldb::user_id_t uid) override
Get the semantically innermost non-function type that encloses the provided variable.
size_t GetCompUnitInfosForModule(const Module *oso_module, std::vector< CompileUnitInfo * > &cu_infos)
bool LinkOSOAddress(Address &addr)
Convert addr from a .o file address, to an executable address.
void InitializeObject() override
Initialize the SymbolFile object.
CompilerDeclContext GetDeclContextForUID(lldb::user_id_t uid) override
CompileUnitInfo * GetCompileUnitInfoForSymbolWithID(lldb::user_id_t symbol_id, uint32_t *oso_idx_ptr)
LineTable * LinkOSOLineTable(SymbolFileDWARF *oso_symfile, LineTable *line_table)
Given a line table full of lines with "file addresses" that are for a .o file represented by oso_symf...
CompilerDeclContext GetDeclContextContainingUID(lldb::user_id_t uid) override
void FindGlobalVariables(ConstString name, const CompilerDeclContext &parent_decl_ctx, uint32_t max_matches, VariableList &variables) override
virtual DWARFDIE FindDefinitionDIE(const DWARFDIE &die)
bool ForEachExternalModule(CompileUnit &, llvm::DenseSet< SymbolFile * > &, llvm::function_ref< bool(Module &)>) override
virtual lldb::TypeSP FindCompleteObjCDefinitionTypeForDIE(const DWARFDIE &die, ConstString type_name, bool must_be_implementation)
llvm::Expected< SymbolContext > ResolveFunctionCallLabel(FunctionCallLabel &label) override
Resolves the function corresponding to the specified LLDB function call label.
void SetDebugMapModule(const lldb::ModuleSP &module_sp)
void DumpClangAST(Stream &s, llvm::StringRef filter, bool show_colors) override
std::vector< CompilerContext > GetCompilerContextForUID(lldb::user_id_t uid) override
void FindTypes(const lldb_private::TypeQuery &match, lldb_private::TypeResults &results) override
Find types using a type-matching object that contains all search parameters.
size_t ParseVariablesForContext(const SymbolContext &sc) override
void GetCompileOptions(std::unordered_map< lldb::CompUnitSP, Args > &args) 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
size_t ParseFunctions(CompileUnit &comp_unit) override
bool ParseDebugMacros(CompileUnit &comp_unit) override
bool ParseSupportFiles(CompileUnit &comp_unit, SupportFileList &support_files) override
bool ParseImportedModules(const SymbolContext &sc, std::vector< SourceModule > &imported_modules) override
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
bool CompleteType(CompilerType &compiler_type) override
bool ParseLineTable(CompileUnit &comp_unit) override
lldb::TypeSP GetTypeEnclosingVariableUID(lldb::user_id_t uid) override
Get the semantically innermost non-function type that encloses the provided variable.
bool ParseIsOptimized(CompileUnit &comp_unit) override
void SetFileIndex(std::optional< uint64_t > file_index)
XcodeSDKAndSysroot ParseXcodeSDK(CompileUnit &comp_unit) override
Return the Xcode SDK comp_unit was compiled against.
void FindFunctions(const Module::LookupInfo &lookup_info, const CompilerDeclContext &parent_decl_ctx, bool include_inlines, SymbolContextList &sc_list) override
uint32_t ResolveSymbolContext(const Address &so_addr, lldb::SymbolContextItem resolve_scope, SymbolContext &sc) override
bool HasForwardDeclForCompilerType(const CompilerType &compiler_type)
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.
std::vector< std::unique_ptr< CallEdge > > ParseCallEdgesInFunction(UserID func_id) override
lldb::LanguageType ParseLanguage(CompileUnit &comp_unit) override
CompilerDeclContext GetDeclContextForUID(lldb::user_id_t uid) override
std::optional< uint64_t > GetFileIndex() const
#define LLDB_INVALID_ADDRESS
#define UINT32_MAX
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition Log.h:338
int(* ComparisonFunction)(const void *, const void *)
IterationAction
Useful for callbacks whose return type indicates whether to continue iteration or short-circuit.
std::weak_ptr< lldb_private::Module > ModuleWP
std::shared_ptr< lldb_private::ObjectFile > ObjectFileSP
LanguageType
Programming language type.
@ eLanguageTypeUnknown
Unknown or invalid language value.
std::shared_ptr< lldb_private::Type > TypeSP
@ eSymbolTypeObjCClass
@ eSymbolTypeObjectFile
@ eSymbolTypeSourceFile
uint64_t user_id_t
Definition lldb-types.h:83
std::shared_ptr< lldb_private::Section > SectionSP
uint64_t addr_t
Definition lldb-types.h:80
std::shared_ptr< lldb_private::Module > ModuleSP
std::shared_ptr< lldb_private::CompileUnit > CompUnitSP
Holds parsed information about a function call label that LLDB attaches as an AsmLabel to function AS...
Definition Expression.h:110
lldb::user_id_t symbol_id
Unique identifier of the function symbol on which to perform the function call.
Definition Expression.h:122
BaseType GetRangeBase() const
Definition RangeMap.h:45
SizeType GetByteSize() const
Definition RangeMap.h:87
BaseType GetRangeEnd() const
Definition RangeMap.h:78
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
const FileRangeMap & GetFileRangeMap(SymbolFileDWARFDebugMap *exe_symfile)