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
301 // Avoid searching for N_OSO entries when we know none exist.
302 if (!symtab->HasDebugMap())
303 return;
304
306
307 std::vector<uint32_t> oso_indexes;
308 // When a mach-o symbol is encoded, the n_type field is encoded in bits
309 // 23:16, and the n_desc field is encoded in bits 15:0.
310 //
311 // To find all N_OSO entries that are part of the DWARF + debug map we find
312 // only object file symbols with the flags value as follows: bits 23:16 ==
313 // 0x66 (N_OSO) bits 15: 0 == 0x0001 (specifies this is a debug map object
314 // file)
315 const uint32_t k_oso_symbol_flags_value = 0x660001u;
316
317 const uint32_t oso_index_count =
319 eSymbolTypeObjectFile, k_oso_symbol_flags_value, oso_indexes);
320
321 if (oso_index_count == 0)
322 return;
323
328
331
332 for (uint32_t sym_idx :
333 llvm::concat<uint32_t>(m_func_indexes, m_glob_indexes)) {
334 const Symbol *symbol = symtab->SymbolAtIndex(sym_idx);
335 lldb::addr_t file_addr = symbol->GetAddressRef().GetFileAddress();
336 lldb::addr_t byte_size = symbol->GetByteSize();
337 DebugMap::Entry debug_map_entry(file_addr, byte_size,
339 m_debug_map.Append(debug_map_entry);
340 }
341 m_debug_map.Sort();
342
343 m_compile_unit_infos.resize(oso_index_count);
344
345 for (uint32_t i = 0; i < oso_index_count; ++i) {
346 const uint32_t so_idx = oso_indexes[i] - 1;
347 const uint32_t oso_idx = oso_indexes[i];
348 const Symbol *so_symbol = symtab->SymbolAtIndex(so_idx);
349 const Symbol *oso_symbol = symtab->SymbolAtIndex(oso_idx);
350 if (so_symbol && oso_symbol &&
351 so_symbol->GetType() == eSymbolTypeSourceFile &&
352 oso_symbol->GetType() == eSymbolTypeObjectFile) {
353 m_compile_unit_infos[i].so_file.SetFile(
354 so_symbol->GetName().GetStringRef(), FileSpec::Style::native);
355 m_compile_unit_infos[i].oso_path = oso_symbol->GetName();
356 m_compile_unit_infos[i].oso_mod_time =
357 llvm::sys::toTimePoint(oso_symbol->GetIntegerValue(0));
358 uint32_t sibling_idx = so_symbol->GetSiblingIndex();
359 // The sibling index can't be less that or equal to the current index
360 // "i"
361 if (sibling_idx <= i || sibling_idx == UINT32_MAX) {
362 m_objfile_sp->GetModule()->ReportInternalError(
363 "N_SO in symbol with UID {0} has invalid sibling in debug map",
364 so_symbol->GetID());
365 } else {
366 const Symbol *last_symbol = symtab->SymbolAtIndex(sibling_idx - 1);
367 m_compile_unit_infos[i].first_symbol_index = so_idx;
368 m_compile_unit_infos[i].last_symbol_index = sibling_idx - 1;
369 m_compile_unit_infos[i].first_symbol_id = so_symbol->GetID();
370 m_compile_unit_infos[i].last_symbol_id = last_symbol->GetID();
371
372 LLDB_LOGF(log, "Initialized OSO 0x%8.8x: file=%s", i,
373 oso_symbol->GetName().GetCString());
374 }
375 } else {
376 if (oso_symbol == nullptr)
377 m_objfile_sp->GetModule()->ReportInternalError(
378 "N_OSO symbol[{0}] can't be found", oso_idx);
379 else if (so_symbol == nullptr)
380 m_objfile_sp->GetModule()->ReportInternalError(
381 "N_SO not found for N_OSO symbol[{0}]", oso_idx);
382 else if (so_symbol->GetType() != eSymbolTypeSourceFile)
383 m_objfile_sp->GetModule()->ReportInternalError(
384 "N_SO has incorrect symbol type ({0}) for N_OSO symbol[{1}]",
385 so_symbol->GetType(), oso_idx);
386 else if (oso_symbol->GetType() != eSymbolTypeSourceFile)
387 m_objfile_sp->GetModule()->ReportInternalError(
388 "N_OSO has incorrect symbol type ({0}) for N_OSO symbol[{1}]",
389 oso_symbol->GetType(), oso_idx);
390 }
391 }
392}
393
395 const uint32_t cu_count = GetNumCompileUnits();
396 if (oso_idx < cu_count)
398 return nullptr;
399}
400
402 CompileUnitInfo *comp_unit_info) {
403 if (!comp_unit_info->oso_sp) {
404 auto pos = m_oso_map.find(
405 {comp_unit_info->oso_path, comp_unit_info->oso_mod_time});
406 if (pos != m_oso_map.end()) {
407 comp_unit_info->oso_sp = pos->second;
408 } else {
409 ObjectFile *obj_file = GetObjectFile();
410 comp_unit_info->oso_sp = std::make_shared<OSOInfo>();
411 m_oso_map[{comp_unit_info->oso_path, comp_unit_info->oso_mod_time}] =
412 comp_unit_info->oso_sp;
413 const char *oso_path = comp_unit_info->oso_path.GetCString();
414 FileSpec oso_file(oso_path);
415 llvm::StringRef oso_object;
416 if (FileSystem::Instance().Exists(oso_file)) {
417 // The modification time returned by the FS can have a higher precision
418 // than the one from the CU.
419 auto oso_mod_time = std::chrono::time_point_cast<std::chrono::seconds>(
420 FileSystem::Instance().GetModificationTime(oso_file));
421 // A timestamp of 0 means that the linker was in deterministic mode. In
422 // that case, we should skip the check against the filesystem last
423 // modification timestamp, since it will never match.
424 if (comp_unit_info->oso_mod_time != llvm::sys::TimePoint<>() &&
425 oso_mod_time != comp_unit_info->oso_mod_time) {
427 "debug map object file \"%s\" changed (actual: 0x%8.8x, debug "
428 "map: 0x%8.8x) since this executable was linked, debug info "
429 "will not be loaded",
430 oso_file.GetPath().c_str(),
431 (uint32_t)llvm::sys::toTimeT(oso_mod_time),
432 (uint32_t)llvm::sys::toTimeT(comp_unit_info->oso_mod_time));
433 obj_file->GetModule()->ReportError(
434 "{0}", comp_unit_info->oso_load_error.AsCString());
435 return nullptr;
436 }
437
438 } else {
439 const bool must_exist = true;
440
441 if (!ObjectFile::SplitArchivePathWithObject(oso_path, oso_file,
442 oso_object, must_exist)) {
444 "debug map object file \"%s\" containing debug info does not "
445 "exist, debug info will not be loaded",
446 comp_unit_info->oso_path.GetCString());
447 ReportMissingOSOs(*comp_unit_info);
448 return nullptr;
449 }
450 }
451 // Always create a new module for .o files. Why? Because we use the debug
452 // map, to add new sections to each .o file and even though a .o file
453 // might not have changed, the sections that get added to the .o file can
454 // change.
455 ArchSpec oso_arch;
456 // Only adopt the architecture from the module (not the vendor or OS)
457 // since .o files for "i386-apple-ios" will historically show up as "i386
458 // -apple-macosx" due to the lack of a LC_VERSION_MIN_MACOSX or
459 // LC_VERSION_MIN_IPHONEOS load command...
460 oso_arch.SetTriple(m_objfile_sp->GetModule()
461 ->GetArchitecture()
462 .GetTriple()
463 .getArchName()
464 .str()
465 .c_str());
466 comp_unit_info->oso_sp->module_sp = std::make_shared<DebugMapModule>(
467 obj_file->GetModule(), GetCompUnitInfoIndex(comp_unit_info), oso_file,
468 oso_arch, oso_object.str(), 0,
469 !oso_object.empty() ? comp_unit_info->oso_mod_time
470 : llvm::sys::TimePoint<>());
471
472 if (!oso_object.empty() &&
473 !comp_unit_info->oso_sp->module_sp->GetObjectFile() &&
474 FileSystem::Instance().Exists(oso_file)) {
475 // If we are loading a .o file from a .a file the "oso_object" will
476 // have a valid value name and if the .a file exists, either the .o
477 // file didn't exist in the .a file or the mod time didn't match.
479 "\"{0}\" object from the \"{1}\" archive: "
480 "either the .o file doesn't exist in the archive or the "
481 "modification time (0x{2:x-8}) of the .o file doesn't match",
482 oso_object, oso_file.GetPath(),
483 (uint32_t)llvm::sys::toTimeT(comp_unit_info->oso_mod_time));
484 }
485 }
486 }
487 if (comp_unit_info->oso_sp)
488 return comp_unit_info->oso_sp->module_sp.get();
489 return nullptr;
490}
491
492static bool OSOExists(llvm::StringRef oso_path) {
493 FileSpec oso_file(oso_path);
494 llvm::StringRef oso_object;
495 return FileSystem::Instance().Exists(oso_file) ||
496 ObjectFile::SplitArchivePathWithObject(oso_path, oso_file, oso_object,
497 /*must_exist=*/true);
498}
499
501 const CompileUnitInfo &missing_info) {
502 // Users have no control over shared cache images, so the error is not
503 // actionable.
504 if (m_objfile_sp->IsSharedCacheBinary())
505 return;
506
508 return;
510
511 size_t num_missing =
512 llvm::count_if(m_compile_unit_infos, [](const CompileUnitInfo &info) {
513 return !OSOExists(info.oso_path.GetStringRef());
514 });
515 ModuleSP module_sp = m_objfile_sp->GetModule();
516 if (num_missing <= 1) {
517 module_sp->ReportError("{0}", missing_info.oso_load_error.AsCString());
518 return;
519 }
520 module_sp->ReportError(
521 "{0} of {1} debug map object files do not exist: debug info cannot be "
522 "loaded for them. Run \"image dump separate-debug-info --errors-only\" "
523 "to list them",
524 num_missing, m_compile_unit_infos.size());
525}
526
528 FileSpec &file_spec) {
529 if (oso_idx < m_compile_unit_infos.size()) {
530 if (m_compile_unit_infos[oso_idx].so_file) {
531 file_spec = m_compile_unit_infos[oso_idx].so_file;
532 return true;
533 }
534 }
535 return false;
536}
537
539 Module *oso_module = GetModuleByOSOIndex(oso_idx);
540 if (oso_module)
541 return oso_module->GetObjectFile();
542 return nullptr;
543}
544
549
552 CompileUnitInfo *comp_unit_info = GetCompUnitInfo(comp_unit);
553 if (comp_unit_info)
554 return GetSymbolFileByCompUnitInfo(comp_unit_info);
555 return nullptr;
556}
557
559 CompileUnitInfo *comp_unit_info) {
560 Module *oso_module = GetModuleByCompUnitInfo(comp_unit_info);
561 if (oso_module)
562 return oso_module->GetObjectFile();
563 return nullptr;
564}
565
567 const CompileUnitInfo *comp_unit_info) {
568 if (!m_compile_unit_infos.empty()) {
569 const CompileUnitInfo *first_comp_unit_info = &m_compile_unit_infos.front();
570 const CompileUnitInfo *last_comp_unit_info = &m_compile_unit_infos.back();
571 if (first_comp_unit_info <= comp_unit_info &&
572 comp_unit_info <= last_comp_unit_info)
573 return comp_unit_info - first_comp_unit_info;
574 }
575 return UINT32_MAX;
576}
577
580 unsigned size = m_compile_unit_infos.size();
581 if (oso_idx < size)
583 return nullptr;
584}
585
588 if (sym_file &&
590 return static_cast<SymbolFileDWARF *>(sym_file);
591 return nullptr;
592}
593
595 CompileUnitInfo *comp_unit_info) {
596 if (Module *oso_module = GetModuleByCompUnitInfo(comp_unit_info))
597 return GetSymbolFileAsSymbolFileDWARF(oso_module->GetSymbolFile());
598 return nullptr;
599}
600
602 // In order to get the abilities of this plug-in, we look at the list of
603 // N_OSO entries (object files) from the symbol table and make sure that
604 // these files exist and also contain valid DWARF. If we get any of that then
605 // we return the abilities of the first N_OSO's DWARF.
606
607 const uint32_t oso_index_count = GetNumCompileUnits();
608 if (oso_index_count > 0) {
609 InitOSO();
610 if (!m_compile_unit_infos.empty()) {
615 }
616 }
617 return 0;
618}
619
624
626 CompUnitSP comp_unit_sp;
627 const uint32_t cu_count = GetNumCompileUnits();
628
629 if (cu_idx < cu_count) {
630 auto &cu_info = m_compile_unit_infos[cu_idx];
631 Module *oso_module = GetModuleByCompUnitInfo(&cu_info);
632 if (oso_module) {
633 FileSpec so_file_spec;
634 if (GetFileSpecForSO(cu_idx, so_file_spec)) {
635 // Apply the module's source path remappings so that compile units
636 // created from N_SO stabs (which may contain paths rewritten by
637 // -fdebug-prefix-map at build time) report their real on-disk paths.
638 // This mirrors what MakeAbsoluteAndRemap does for the dSYM case.
639 if (ModuleSP module_sp = m_objfile_sp->GetModule())
640 if (auto remapped =
641 module_sp->RemapSourceFile(so_file_spec.GetPath()))
642 so_file_spec.SetFile(*remapped, FileSpec::Style::native);
643
644 // User zero as the ID to match the compile unit at offset zero in each
645 // .o file.
646 lldb::user_id_t cu_id = 0;
647 cu_info.compile_units_sps.push_back(std::make_shared<CompileUnit>(
648 m_objfile_sp->GetModule(), nullptr,
649 std::make_shared<SupportFile>(so_file_spec), cu_id,
651 cu_info.id_to_index_map.insert({0, 0});
652 SetCompileUnitAtIndex(cu_idx, cu_info.compile_units_sps[0]);
653 // If there's a symbol file also register all the extra compile units.
654 if (SymbolFileDWARF *oso_symfile =
655 GetSymbolFileByCompUnitInfo(&cu_info)) {
656 auto num_dwarf_units = oso_symfile->DebugInfo().GetNumUnits();
657 for (size_t i = 0; i < num_dwarf_units; ++i) {
658 auto *dwarf_unit = oso_symfile->DebugInfo().GetUnitAtIndex(i);
659 if (auto *dwarf_cu = llvm::dyn_cast<DWARFCompileUnit>(dwarf_unit)) {
660 // The "main" one was already registered.
661 if (dwarf_cu->GetID() == 0)
662 continue;
663 cu_info.compile_units_sps.push_back(std::make_shared<CompileUnit>(
664 m_objfile_sp->GetModule(), nullptr,
665 std::make_shared<SupportFile>(so_file_spec),
666 dwarf_cu->GetID(), eLanguageTypeUnknown, eLazyBoolCalculate));
667 cu_info.id_to_index_map.insert(
668 {dwarf_cu->GetID(), cu_info.compile_units_sps.size() - 1});
669 }
670 }
671 }
672 }
673 }
674 if (!cu_info.compile_units_sps.empty())
675 comp_unit_sp = cu_info.compile_units_sps[0];
676 }
677
678 return comp_unit_sp;
679}
680
685
688 const uint32_t cu_count = GetNumCompileUnits();
689 for (uint32_t i = 0; i < cu_count; ++i) {
690 auto &id_to_index_map = m_compile_unit_infos[i].id_to_index_map;
691
692 auto it = id_to_index_map.find(comp_unit.GetID());
693 if (it != id_to_index_map.end() &&
694 &comp_unit ==
695 m_compile_unit_infos[i].compile_units_sps[it->getSecond()].get())
696 return &m_compile_unit_infos[i];
697 }
698 return nullptr;
699}
700
702 const lldb_private::Module *module,
703 std::vector<CompileUnitInfo *> &cu_infos) {
704 const uint32_t cu_count = GetNumCompileUnits();
705 for (uint32_t i = 0; i < cu_count; ++i) {
707 cu_infos.push_back(&m_compile_unit_infos[i]);
708 }
709 return cu_infos.size();
710}
711
714 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
715 SymbolFileDWARF *oso_dwarf = GetSymbolFile(comp_unit);
716 if (oso_dwarf)
717 return oso_dwarf->ParseLanguage(comp_unit);
719}
720
723 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
724 SymbolFileDWARF *oso_dwarf = GetSymbolFile(comp_unit);
725 if (oso_dwarf)
726 return oso_dwarf->ParseXcodeSDK(comp_unit);
727 return {};
728}
729
730llvm::SmallSet<lldb::LanguageType, 4>
732 lldb_private::CompileUnit &comp_unit) {
733 llvm::SmallSet<lldb::LanguageType, 4> langs;
734 auto *info = GetCompUnitInfo(comp_unit);
735 for (auto &comp_unit : info->compile_units_sps) {
736 langs.insert(comp_unit->GetLanguage());
737 }
738 return langs;
739}
740
742 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
743 SymbolFileDWARF *oso_dwarf = GetSymbolFile(comp_unit);
744 if (oso_dwarf)
745 return oso_dwarf->ParseFunctions(comp_unit);
746 return 0;
747}
748
750 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
751 SymbolFileDWARF *oso_dwarf = GetSymbolFile(comp_unit);
752 if (oso_dwarf)
753 return oso_dwarf->ParseLineTable(comp_unit);
754 return false;
755}
756
758 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
759 SymbolFileDWARF *oso_dwarf = GetSymbolFile(comp_unit);
760 if (oso_dwarf)
761 return oso_dwarf->ParseDebugMacros(comp_unit);
762 return false;
763}
764
766 std::string description,
767 std::function<IterationAction(SymbolFileDWARF &)> closure) {
768 const size_t num_oso_idxs = m_compile_unit_infos.size();
769 Progress progress(std::move(description), "", num_oso_idxs,
770 /*debugger=*/nullptr,
772 for (uint32_t oso_idx = 0; oso_idx < num_oso_idxs; ++oso_idx) {
773 if (SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex(oso_idx)) {
774 progress.Increment(oso_idx, oso_dwarf->GetObjectName());
775 if (closure(*oso_dwarf) == IterationAction::Stop)
776 return;
777 }
778 }
779}
780
782 CompileUnit &comp_unit,
783 llvm::DenseSet<lldb_private::SymbolFile *> &visited_symbol_files,
784 llvm::function_ref<bool(Module &)> f) {
785 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
786 SymbolFileDWARF *oso_dwarf = GetSymbolFile(comp_unit);
787 if (oso_dwarf)
788 return oso_dwarf->ForEachExternalModule(comp_unit, visited_symbol_files, f);
789 return false;
790}
791
793 CompileUnit &comp_unit, SupportFileList &support_files) {
794 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
795 SymbolFileDWARF *oso_dwarf = GetSymbolFile(comp_unit);
796 if (oso_dwarf)
797 return oso_dwarf->ParseSupportFiles(comp_unit, support_files);
798 return false;
799}
800
802 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
803 SymbolFileDWARF *oso_dwarf = GetSymbolFile(comp_unit);
804 if (oso_dwarf)
805 return oso_dwarf->ParseIsOptimized(comp_unit);
806 return false;
807}
808
810 const SymbolContext &sc, std::vector<SourceModule> &imported_modules) {
811 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
812 SymbolFileDWARF *oso_dwarf = GetSymbolFile(sc);
813 if (oso_dwarf)
814 return oso_dwarf->ParseImportedModules(sc, imported_modules);
815 return false;
816}
817
819 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
820 CompileUnit *comp_unit = func.GetCompileUnit();
821 if (!comp_unit)
822 return 0;
823
824 SymbolFileDWARF *oso_dwarf = GetSymbolFile(*comp_unit);
825 if (oso_dwarf)
826 return oso_dwarf->ParseBlocksRecursive(func);
827 return 0;
828}
829
831 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
832 SymbolFileDWARF *oso_dwarf = GetSymbolFile(comp_unit);
833 if (oso_dwarf)
834 return oso_dwarf->ParseTypes(comp_unit);
835 return 0;
836}
837
838size_t
840 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
841 SymbolFileDWARF *oso_dwarf = GetSymbolFile(sc);
842 if (oso_dwarf)
843 return oso_dwarf->ParseVariablesForContext(sc);
844 return 0;
845}
846
848 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
849 const uint64_t oso_idx = GetOSOIndexFromUserID(type_uid);
850 SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex(oso_idx);
851 if (oso_dwarf)
852 return oso_dwarf->ResolveTypeUID(type_uid);
853 return nullptr;
854}
855
856std::optional<SymbolFile::ArrayInfo>
858 lldb::user_id_t type_uid, const lldb_private::ExecutionContext *exe_ctx) {
859 const uint64_t oso_idx = GetOSOIndexFromUserID(type_uid);
860 SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex(oso_idx);
861 if (oso_dwarf)
862 return oso_dwarf->GetDynamicArrayInfoForUID(type_uid, exe_ctx);
863 return std::nullopt;
864}
865
867 bool success = false;
868 if (compiler_type) {
869 ForEachSymbolFile("Completing type", [&](SymbolFileDWARF &oso_dwarf) {
870 if (oso_dwarf.HasForwardDeclForCompilerType(compiler_type)) {
871 oso_dwarf.CompleteType(compiler_type);
872 success = true;
874 }
876 });
877 }
878 return success;
879}
880
881uint32_t
883 SymbolContextItem resolve_scope,
884 SymbolContext &sc) {
885 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
886 uint32_t resolved_flags = 0;
887 Symtab *symtab = m_objfile_sp->GetSymtab();
888 if (symtab) {
889 const addr_t exe_file_addr = exe_so_addr.GetFileAddress();
890
891 const DebugMap::Entry *debug_map_entry =
892 m_debug_map.FindEntryThatContains(exe_file_addr);
893 if (debug_map_entry) {
894
895 sc.symbol =
896 symtab->SymbolAtIndex(debug_map_entry->data.GetExeSymbolIndex());
897
898 if (sc.symbol != nullptr) {
899 resolved_flags |= eSymbolContextSymbol;
900
901 uint32_t oso_idx = 0;
902 CompileUnitInfo *comp_unit_info =
904 if (comp_unit_info) {
905 comp_unit_info->GetFileRangeMap(this);
906 Module *oso_module = GetModuleByCompUnitInfo(comp_unit_info);
907 if (oso_module) {
908 lldb::addr_t oso_file_addr =
909 exe_file_addr - debug_map_entry->GetRangeBase() +
910 debug_map_entry->data.GetOSOFileAddress();
911 Address oso_so_addr;
912 if (oso_module->ResolveFileAddress(oso_file_addr, oso_so_addr)) {
913 if (SymbolFile *sym_file = oso_module->GetSymbolFile()) {
914 resolved_flags |= sym_file->ResolveSymbolContext(
915 oso_so_addr, resolve_scope, sc);
916 } else {
917 ObjectFile *obj_file = GetObjectFile();
919 "Failed to get symfile for OSO: {0} in module: {1}",
920 oso_module->GetFileSpec(),
921 obj_file ? obj_file->GetFileSpec()
922 : FileSpec("unknown"));
923 }
924 }
925 }
926 }
927 }
928 }
929 }
930 return resolved_flags;
931}
932
934 const SourceLocationSpec &src_location_spec,
935 SymbolContextItem resolve_scope, SymbolContextList &sc_list) {
936 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
937 const uint32_t initial = sc_list.GetSize();
938 const uint32_t cu_count = GetNumCompileUnits();
939
940 for (uint32_t i = 0; i < cu_count; ++i) {
941 // If we are checking for inlines, then we need to look through all compile
942 // units no matter if "file_spec" matches.
943 bool resolve = src_location_spec.GetCheckInlines();
944
945 if (!resolve) {
946 FileSpec so_file_spec;
947 if (GetFileSpecForSO(i, so_file_spec))
948 resolve =
949 FileSpec::Match(src_location_spec.GetFileSpec(), so_file_spec);
950 }
951 if (resolve) {
953 if (oso_dwarf)
954 oso_dwarf->ResolveSymbolContext(src_location_spec, resolve_scope,
955 sc_list);
956 }
957 }
958 return sc_list.GetSize() - initial;
959}
960
962 ConstString name, const CompilerDeclContext &parent_decl_ctx,
963 const std::vector<uint32_t>
964 &indexes, // Indexes into the symbol table that match "name"
965 uint32_t max_matches, VariableList &variables) {
966 const size_t match_count = indexes.size();
967 for (size_t i = 0; i < match_count; ++i) {
968 uint32_t oso_idx;
969 CompileUnitInfo *comp_unit_info =
970 GetCompileUnitInfoForSymbolWithIndex(indexes[i], &oso_idx);
971 if (comp_unit_info) {
972 SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex(oso_idx);
973 if (oso_dwarf) {
974 oso_dwarf->FindGlobalVariables(name, parent_decl_ctx, max_matches,
975 variables);
976 if (variables.GetSize() > max_matches)
977 break;
978 }
979 }
980 }
981}
982
984 ConstString name, const CompilerDeclContext &parent_decl_ctx,
985 uint32_t max_matches, VariableList &variables) {
986 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
987 uint32_t total_matches = 0;
988
990 "Looking up global variables", [&](SymbolFileDWARF &oso_dwarf) {
991 const uint32_t old_size = variables.GetSize();
992 oso_dwarf.FindGlobalVariables(name, parent_decl_ctx, max_matches,
993 variables);
994 const uint32_t oso_matches = variables.GetSize() - old_size;
995 if (oso_matches > 0) {
996 total_matches += oso_matches;
997
998 // If we are getting all matches, keep going.
999 if (max_matches == UINT32_MAX)
1001
1002 // If we have found enough matches, lets get out
1003 if (max_matches >= total_matches)
1004 return IterationAction::Stop;
1005
1006 // Update the max matches for any subsequent calls to find globals in
1007 // any other object files with DWARF
1008 max_matches -= oso_matches;
1009 }
1010
1012 });
1013}
1014
1016 const RegularExpression &regex, uint32_t max_matches,
1017 VariableList &variables) {
1018 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1019 uint32_t total_matches = 0;
1021 "Looking up global variables", [&](SymbolFileDWARF &oso_dwarf) {
1022 const uint32_t old_size = variables.GetSize();
1023 oso_dwarf.FindGlobalVariables(regex, max_matches, variables);
1024
1025 const uint32_t oso_matches = variables.GetSize() - old_size;
1026 if (oso_matches > 0) {
1027 total_matches += oso_matches;
1028
1029 // If we are getting all matches, keep going.
1030 if (max_matches == UINT32_MAX)
1032
1033 // If we have found enough matches, lets get out
1034 if (max_matches >= total_matches)
1035 return IterationAction::Stop;
1036
1037 // Update the max matches for any subsequent calls to find globals in
1038 // any other object files with DWARF
1039 max_matches -= oso_matches;
1040 }
1041
1043 });
1044}
1045
1047 uint32_t *symbol_idx_ptr, const CompileUnitInfo *comp_unit_info) {
1048 const uint32_t symbol_idx = *symbol_idx_ptr;
1049
1050 if (symbol_idx < comp_unit_info->first_symbol_index)
1051 return -1;
1052
1053 if (symbol_idx <= comp_unit_info->last_symbol_index)
1054 return 0;
1055
1056 return 1;
1057}
1058
1060 user_id_t *symbol_idx_ptr, const CompileUnitInfo *comp_unit_info) {
1061 const user_id_t symbol_id = *symbol_idx_ptr;
1062
1063 if (symbol_id < comp_unit_info->first_symbol_id)
1064 return -1;
1065
1066 if (symbol_id <= comp_unit_info->last_symbol_id)
1067 return 0;
1068
1069 return 1;
1070}
1071
1074 uint32_t symbol_idx, uint32_t *oso_idx_ptr) {
1075 const uint32_t oso_index_count = m_compile_unit_infos.size();
1076 CompileUnitInfo *comp_unit_info = nullptr;
1077 if (oso_index_count) {
1078 comp_unit_info = (CompileUnitInfo *)bsearch(
1079 &symbol_idx, &m_compile_unit_infos[0], m_compile_unit_infos.size(),
1080 sizeof(CompileUnitInfo),
1082 }
1083
1084 if (oso_idx_ptr) {
1085 if (comp_unit_info != nullptr)
1086 *oso_idx_ptr = comp_unit_info - &m_compile_unit_infos[0];
1087 else
1088 *oso_idx_ptr = UINT32_MAX;
1089 }
1090 return comp_unit_info;
1091}
1092
1095 user_id_t symbol_id, uint32_t *oso_idx_ptr) {
1096 const uint32_t oso_index_count = m_compile_unit_infos.size();
1097 CompileUnitInfo *comp_unit_info = nullptr;
1098 if (oso_index_count) {
1099 comp_unit_info = (CompileUnitInfo *)::bsearch(
1100 &symbol_id, &m_compile_unit_infos[0], m_compile_unit_infos.size(),
1101 sizeof(CompileUnitInfo),
1103 }
1104
1105 if (oso_idx_ptr) {
1106 if (comp_unit_info != nullptr)
1107 *oso_idx_ptr = comp_unit_info - &m_compile_unit_infos[0];
1108 else
1109 *oso_idx_ptr = UINT32_MAX;
1110 }
1111 return comp_unit_info;
1112}
1113
1115 SymbolContextList &sc_list,
1116 uint32_t start_idx) {
1117 // We found functions in .o files. Not all functions in the .o files will
1118 // have made it into the final output file. The ones that did make it into
1119 // the final output file will have a section whose module matches the module
1120 // from the ObjectFile for this SymbolFile. When the modules don't match,
1121 // then we have something that was in a .o file, but doesn't map to anything
1122 // in the final executable.
1123 uint32_t i = start_idx;
1124 while (i < sc_list.GetSize()) {
1125 SymbolContext sc;
1126 sc_list.GetContextAtIndex(i, sc);
1127 if (sc.function) {
1128 const SectionSP section_sp = sc.function->GetAddress().GetSection();
1129 if (section_sp->GetModule() != module_sp) {
1130 sc_list.RemoveContextAtIndex(i);
1131 continue;
1132 }
1133 }
1134 ++i;
1135 }
1136}
1137
1139 const Module::LookupInfo &lookup_info,
1140 const CompilerDeclContext &parent_decl_ctx, bool include_inlines,
1141 SymbolContextList &sc_list) {
1142 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1143 LLDB_SCOPED_TIMERF("SymbolFileDWARFDebugMap::FindFunctions (name = %s)",
1144 lookup_info.GetLookupName().GetCString());
1145
1146 ForEachSymbolFile("Looking up functions", [&](SymbolFileDWARF &oso_dwarf) {
1147 uint32_t sc_idx = sc_list.GetSize();
1148 oso_dwarf.FindFunctions(lookup_info, parent_decl_ctx, include_inlines,
1149 sc_list);
1150 if (!sc_list.IsEmpty()) {
1152 sc_idx);
1153 }
1155 });
1156}
1157
1159 bool include_inlines,
1160 SymbolContextList &sc_list) {
1161 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1162 LLDB_SCOPED_TIMERF("SymbolFileDWARFDebugMap::FindFunctions (regex = '%s')",
1163 regex.GetText().str().c_str());
1164
1165 ForEachSymbolFile("Looking up functions", [&](SymbolFileDWARF &oso_dwarf) {
1166 uint32_t sc_idx = sc_list.GetSize();
1167
1168 oso_dwarf.FindFunctions(regex, include_inlines, sc_list);
1169 if (!sc_list.IsEmpty()) {
1171 sc_idx);
1172 }
1174 });
1175}
1176
1178 lldb::TypeClass type_mask,
1179 TypeList &type_list) {
1180 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1181 LLDB_SCOPED_TIMERF("SymbolFileDWARFDebugMap::GetTypes (type_mask = 0x%8.8x)",
1182 type_mask);
1183
1184 SymbolFileDWARF *oso_dwarf = nullptr;
1185 if (sc_scope) {
1186 SymbolContext sc;
1187 sc_scope->CalculateSymbolContext(&sc);
1188
1189 CompileUnitInfo *cu_info = GetCompUnitInfo(sc);
1190 if (cu_info) {
1191 oso_dwarf = GetSymbolFileByCompUnitInfo(cu_info);
1192 if (oso_dwarf)
1193 oso_dwarf->GetTypes(sc_scope, type_mask, type_list);
1194 }
1195 } else {
1196 ForEachSymbolFile("Looking up types", [&](SymbolFileDWARF &oso_dwarf) {
1197 oso_dwarf.GetTypes(sc_scope, type_mask, type_list);
1199 });
1200 }
1201}
1202
1203std::vector<std::unique_ptr<lldb_private::CallEdge>>
1205 lldb_private::UserID func_id) {
1206 uint32_t oso_idx = GetOSOIndexFromUserID(func_id.GetID());
1207 SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex(oso_idx);
1208 if (oso_dwarf)
1209 return oso_dwarf->ParseCallEdgesInFunction(func_id);
1210 return {};
1211}
1212
1214 DWARFDIE result;
1216 "Looking up type definition", [&](SymbolFileDWARF &oso_dwarf) {
1217 result = oso_dwarf.FindDefinitionDIE(die);
1219 });
1220 return result;
1221}
1222
1224 const DWARFDIE &die, ConstString type_name, bool must_be_implementation) {
1225 // If we have a debug map, we will have an Objective-C symbol whose name is
1226 // the type name and whose type is eSymbolTypeObjCClass. If we can find that
1227 // symbol and find its containing parent, we can locate the .o file that will
1228 // contain the implementation definition since it will be scoped inside the
1229 // N_SO and we can then locate the SymbolFileDWARF that corresponds to that
1230 // N_SO.
1231 SymbolFileDWARF *oso_dwarf = nullptr;
1232 TypeSP type_sp;
1233 ObjectFile *module_objfile = m_objfile_sp->GetModule()->GetObjectFile();
1234 if (module_objfile) {
1235 Symtab *symtab = module_objfile->GetSymtab();
1236 if (symtab) {
1237 Symbol *objc_class_symbol = symtab->FindFirstSymbolWithNameAndType(
1240 if (objc_class_symbol) {
1241 // Get the N_SO symbol that contains the objective C class symbol as
1242 // this should be the .o file that contains the real definition...
1243 const Symbol *source_file_symbol = symtab->GetParent(objc_class_symbol);
1244
1245 if (source_file_symbol &&
1246 source_file_symbol->GetType() == eSymbolTypeSourceFile) {
1247 const uint32_t source_file_symbol_idx =
1248 symtab->GetIndexForSymbol(source_file_symbol);
1249 if (source_file_symbol_idx != UINT32_MAX) {
1250 CompileUnitInfo *compile_unit_info =
1251 GetCompileUnitInfoForSymbolWithIndex(source_file_symbol_idx,
1252 nullptr);
1253 if (compile_unit_info) {
1254 oso_dwarf = GetSymbolFileByCompUnitInfo(compile_unit_info);
1255 if (oso_dwarf) {
1257 die, type_name, must_be_implementation));
1258 if (type_sp) {
1259 return type_sp;
1260 }
1261 }
1262 }
1263 }
1264 }
1265 }
1266 }
1267 }
1268
1269 // Only search all .o files for the definition if we don't need the
1270 // implementation because otherwise, with a valid debug map we should have
1271 // the ObjC class symbol and the code above should have found it.
1272 if (!must_be_implementation) {
1273 TypeSP type_sp;
1274
1276 "Looking up Objective-C definition", [&](SymbolFileDWARF &oso_dwarf) {
1277 type_sp = oso_dwarf.FindCompleteObjCDefinitionTypeForDIE(
1278 die, type_name, must_be_implementation);
1280 });
1281
1282 return type_sp;
1283 }
1284 return TypeSP();
1285}
1286
1288 TypeResults &results) {
1289 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1290 ForEachSymbolFile("Looking up type", [&](SymbolFileDWARF &oso_dwarf) {
1291 oso_dwarf.FindTypes(query, results);
1292 return results.Done(query) ? IterationAction::Stop
1294 });
1295}
1296
1298 lldb_private::ConstString name, const CompilerDeclContext &parent_decl_ctx,
1299 bool only_root_namespaces) {
1300 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1301 CompilerDeclContext matching_namespace;
1302
1303 ForEachSymbolFile("Looking up namespace", [&](SymbolFileDWARF &oso_dwarf) {
1304 matching_namespace =
1305 oso_dwarf.FindNamespace(name, parent_decl_ctx, only_root_namespaces);
1306
1307 return matching_namespace ? IterationAction::Stop
1309 });
1310
1311 return matching_namespace;
1312}
1313
1314void SymbolFileDWARFDebugMap::DumpClangAST(Stream &s, llvm::StringRef filter,
1315 bool show_color) {
1316 ForEachSymbolFile("Dumping clang AST", [&](SymbolFileDWARF &oso_dwarf) {
1317 oso_dwarf.DumpClangAST(s, filter, show_color);
1318 // The underlying assumption is that DumpClangAST(...) will obtain the
1319 // AST from the underlying TypeSystem and therefore we only need to do
1320 // this once and can stop after the first iteration hence we return true.
1321 return IterationAction::Stop;
1322 });
1323}
1324
1327 const uint32_t cu_count = GetNumCompileUnits();
1329 for (uint32_t cu_idx = 0; cu_idx < cu_count; ++cu_idx) {
1330 const auto &info = m_compile_unit_infos[cu_idx];
1331 if (info.so_file.GetPath().empty())
1332 continue;
1333
1334 ModuleSpec spec;
1335 FileSpec oso_file;
1336 llvm::StringRef oso_object;
1337 if (ObjectFile::SplitArchivePathWithObject(info.oso_path.GetStringRef(),
1338 oso_file, oso_object,
1339 /*must_exist=*/false)) {
1340 spec.GetFileSpec() = oso_file;
1341 spec.SetObjectName(oso_object.str());
1342 } else {
1343 spec.GetFileSpec() = FileSpec(info.oso_path.GetStringRef());
1344 }
1345
1346 spec.GetObjectModificationTime() = info.oso_mod_time;
1347 spec_list.Append(spec);
1348 }
1349 return spec_list;
1350}
1351
1353 lldb_private::StructuredData::Dictionary &d, bool errors_only,
1354 bool load_all_debug_info) {
1355 StructuredData::Array separate_debug_info_files;
1356 const uint32_t cu_count = GetNumCompileUnits();
1357 for (uint32_t cu_idx = 0; cu_idx < cu_count; ++cu_idx) {
1358 const auto &info = m_compile_unit_infos[cu_idx];
1360 std::make_shared<StructuredData::Dictionary>();
1361 oso_data->AddStringItem("so_file", info.so_file.GetPath());
1362 oso_data->AddStringItem("oso_path", info.oso_path);
1363 oso_data->AddIntegerItem("oso_mod_time",
1364 (uint32_t)llvm::sys::toTimeT(info.oso_mod_time));
1365
1366 bool loaded_successfully = false;
1367 if (GetModuleByOSOIndex(cu_idx)) {
1368 // If we have a valid pointer to the module, we successfully
1369 // loaded the oso if there are no load errors.
1370 if (!info.oso_load_error.Fail()) {
1371 loaded_successfully = true;
1372 }
1373 }
1374 if (!loaded_successfully) {
1375 oso_data->AddStringItem("error", info.oso_load_error.AsCString());
1376 }
1377 oso_data->AddBooleanItem("loaded", loaded_successfully);
1378 if (!errors_only || oso_data->HasKey("error"))
1379 separate_debug_info_files.AddItem(oso_data);
1380 }
1381
1382 d.AddStringItem("type", "oso");
1383 d.AddStringItem("symfile", GetMainObjectFile()->GetFileSpec().GetPath());
1384 d.AddItem("separate-debug-info-files",
1385 std::make_shared<StructuredData::Array>(
1386 std::move(separate_debug_info_files)));
1387 return true;
1388}
1389
1392 DWARFCompileUnit &dwarf_cu) {
1393 if (oso_dwarf) {
1394 const uint32_t cu_count = GetNumCompileUnits();
1395 for (uint32_t cu_idx = 0; cu_idx < cu_count; ++cu_idx) {
1396 SymbolFileDWARF *oso_symfile =
1398 if (oso_symfile == oso_dwarf) {
1399 if (m_compile_unit_infos[cu_idx].compile_units_sps.empty())
1401
1402 auto &id_to_index_map = m_compile_unit_infos[cu_idx].id_to_index_map;
1403 auto it = id_to_index_map.find(dwarf_cu.GetID());
1404 if (it != id_to_index_map.end())
1405 return m_compile_unit_infos[cu_idx]
1406 .compile_units_sps[it->getSecond()];
1407 }
1408 }
1409 }
1410 llvm_unreachable("this shouldn't happen");
1411}
1412
1415 if (oso_dwarf) {
1416 const uint32_t cu_count = GetNumCompileUnits();
1417 for (uint32_t cu_idx = 0; cu_idx < cu_count; ++cu_idx) {
1418 SymbolFileDWARF *oso_symfile =
1420 if (oso_symfile == oso_dwarf) {
1421 return &m_compile_unit_infos[cu_idx];
1422 }
1423 }
1424 }
1425 return nullptr;
1426}
1427
1429 const CompUnitSP &cu_sp) {
1430 if (oso_dwarf) {
1431 const uint32_t cu_count = GetNumCompileUnits();
1432 for (uint32_t cu_idx = 0; cu_idx < cu_count; ++cu_idx) {
1433 SymbolFileDWARF *oso_symfile =
1435 if (oso_symfile == oso_dwarf) {
1436 if (!m_compile_unit_infos[cu_idx].compile_units_sps.empty()) {
1437 assert(m_compile_unit_infos[cu_idx].compile_units_sps[0].get() ==
1438 cu_sp.get());
1439 } else {
1440 assert(cu_sp->GetID() == 0 &&
1441 "Setting first compile unit but with id different than 0!");
1442 auto &compile_units_sps =
1443 m_compile_unit_infos[cu_idx].compile_units_sps;
1444 compile_units_sps.push_back(cu_sp);
1445 m_compile_unit_infos[cu_idx].id_to_index_map.insert(
1446 {cu_sp->GetID(), compile_units_sps.size() - 1});
1447
1448 SetCompileUnitAtIndex(cu_idx, cu_sp);
1449 }
1450 }
1451 }
1452 }
1453}
1454
1457 const uint64_t oso_idx = GetOSOIndexFromUserID(type_uid);
1458 if (SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex(oso_idx))
1459 return oso_dwarf->GetDeclContextForUID(type_uid);
1460 return {};
1461}
1462
1465 const uint64_t oso_idx = GetOSOIndexFromUserID(type_uid);
1466 if (SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex(oso_idx))
1467 return oso_dwarf->GetDeclContextContainingUID(type_uid);
1468 return {};
1469}
1470
1471std::vector<CompilerContext>
1473 const uint64_t oso_idx = GetOSOIndexFromUserID(type_uid);
1474 if (SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex(oso_idx))
1475 return oso_dwarf->GetCompilerContextForUID(type_uid);
1476 return {};
1477}
1478
1481 ForEachSymbolFile("Parsing declarations", [&](SymbolFileDWARF &oso_dwarf) {
1482 oso_dwarf.ParseDeclsForContext(decl_ctx);
1484 });
1485}
1486
1488 lldb::addr_t exe_file_addr,
1489 lldb::addr_t exe_byte_size,
1490 lldb::addr_t oso_file_addr,
1491 lldb::addr_t oso_byte_size) {
1492 const uint32_t debug_map_idx =
1493 m_debug_map.FindEntryIndexThatContains(exe_file_addr);
1494 if (debug_map_idx != UINT32_MAX) {
1495 DebugMap::Entry *debug_map_entry =
1496 m_debug_map.FindEntryThatContains(exe_file_addr);
1497 debug_map_entry->data.SetOSOFileAddress(oso_file_addr);
1498 addr_t range_size = std::min<addr_t>(exe_byte_size, oso_byte_size);
1499 if (range_size == 0) {
1500 range_size = std::max<addr_t>(exe_byte_size, oso_byte_size);
1501 if (range_size == 0)
1502 range_size = 1;
1503 }
1504 cu_info->file_range_map.Append(
1505 FileRangeMap::Entry(oso_file_addr, range_size, exe_file_addr));
1506 return true;
1507 }
1508 return false;
1509}
1510
1512 cu_info->file_range_map.Sort();
1513#if defined(DEBUG_OSO_DMAP)
1514 const FileRangeMap &oso_file_range_map = cu_info->GetFileRangeMap(this);
1515 const size_t n = oso_file_range_map.GetSize();
1516 printf("SymbolFileDWARFDebugMap::FinalizeOSOFileRanges (cu_info = %p) %s\n",
1517 cu_info, cu_info->oso_sp->module_sp->GetFileSpec().GetPath().c_str());
1518 for (size_t i = 0; i < n; ++i) {
1519 const FileRangeMap::Entry &entry = oso_file_range_map.GetEntryRef(i);
1520 printf("oso [0x%16.16" PRIx64 " - 0x%16.16" PRIx64
1521 ") ==> exe [0x%16.16" PRIx64 " - 0x%16.16" PRIx64 ")\n",
1522 entry.GetRangeBase(), entry.GetRangeEnd(), entry.data,
1523 entry.data + entry.GetByteSize());
1524 }
1525#endif
1526}
1527
1530 lldb::addr_t oso_file_addr) {
1531 CompileUnitInfo *cu_info = GetCompileUnitInfo(oso_symfile);
1532 if (cu_info) {
1533 const FileRangeMap::Entry *oso_range_entry =
1534 cu_info->GetFileRangeMap(this).FindEntryThatContains(oso_file_addr);
1535 if (oso_range_entry) {
1536 const DebugMap::Entry *debug_map_entry =
1537 m_debug_map.FindEntryThatContains(oso_range_entry->data);
1538 if (debug_map_entry) {
1539 const lldb::addr_t offset =
1540 oso_file_addr - oso_range_entry->GetRangeBase();
1541 const lldb::addr_t exe_file_addr =
1542 debug_map_entry->GetRangeBase() + offset;
1543 return exe_file_addr;
1544 }
1545 }
1546 }
1547 return LLDB_INVALID_ADDRESS;
1548}
1549
1551 // Make sure this address hasn't been fixed already
1552 Module *exe_module = GetObjectFile()->GetModule().get();
1553 Module *addr_module = addr.GetModule().get();
1554 if (addr_module == exe_module)
1555 return true; // Address is already in terms of the main executable module
1556
1559 if (cu_info) {
1560 const lldb::addr_t oso_file_addr = addr.GetFileAddress();
1561 const FileRangeMap::Entry *oso_range_entry =
1562 cu_info->GetFileRangeMap(this).FindEntryThatContains(oso_file_addr);
1563 if (oso_range_entry) {
1564 const DebugMap::Entry *debug_map_entry =
1565 m_debug_map.FindEntryThatContains(oso_range_entry->data);
1566 if (debug_map_entry) {
1567 const lldb::addr_t offset =
1568 oso_file_addr - oso_range_entry->GetRangeBase();
1569 const lldb::addr_t exe_file_addr =
1570 debug_map_entry->GetRangeBase() + offset;
1571 return exe_module->ResolveFileAddress(exe_file_addr, addr);
1572 }
1573 }
1574 }
1575 return true;
1576}
1577
1579 LineTable *line_table) {
1580 CompileUnitInfo *cu_info = GetCompileUnitInfo(oso_dwarf);
1581 if (cu_info)
1582 return line_table->LinkLineTable(cu_info->GetFileRangeMap(this));
1583 return nullptr;
1584}
1585
1586size_t
1588 DWARFDebugAranges *debug_aranges) {
1589 size_t num_line_entries_added = 0;
1590 if (debug_aranges && dwarf2Data) {
1591 CompileUnitInfo *compile_unit_info = GetCompileUnitInfo(dwarf2Data);
1592 if (compile_unit_info) {
1593 const FileRangeMap &file_range_map =
1594 compile_unit_info->GetFileRangeMap(this);
1595 for (size_t idx = 0; idx < file_range_map.GetSize(); idx++) {
1596 const FileRangeMap::Entry *entry = file_range_map.GetEntryAtIndex(idx);
1597 if (entry) {
1598 debug_aranges->AppendRange(*dwarf2Data->GetFileIndex(),
1599 entry->GetRangeBase(),
1600 entry->GetRangeEnd());
1601 num_line_entries_added++;
1602 }
1603 }
1604 }
1605 }
1606 return num_line_entries_added;
1607}
1608
1610 ModuleList oso_modules;
1611 ForEachSymbolFile("Parsing modules", [&](SymbolFileDWARF &oso_dwarf) {
1612 ObjectFile *oso_objfile = oso_dwarf.GetObjectFile();
1613 if (oso_objfile) {
1614 ModuleSP module_sp = oso_objfile->GetModule();
1615 if (module_sp)
1616 oso_modules.Append(module_sp);
1617 }
1619 });
1620 return oso_modules;
1621}
1622
1624 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1625
1626 // We need to make sure that our PC value from the frame matches the module
1627 // for this object file since we will lookup the PC file address in the debug
1628 // map below.
1629 Address pc_addr = frame.GetFrameCodeAddress();
1630 if (pc_addr.GetModule() == m_objfile_sp->GetModule()) {
1631 Symtab *symtab = m_objfile_sp->GetSymtab();
1632 if (symtab) {
1633 const DebugMap::Entry *debug_map_entry =
1634 m_debug_map.FindEntryThatContains(pc_addr.GetFileAddress());
1635 if (debug_map_entry) {
1636 const Symbol *symbol =
1637 symtab->SymbolAtIndex(debug_map_entry->data.GetExeSymbolIndex());
1638 if (symbol) {
1639 uint32_t oso_idx = 0;
1640 CompileUnitInfo *comp_unit_info =
1641 GetCompileUnitInfoForSymbolWithID(symbol->GetID(), &oso_idx);
1642 if (comp_unit_info) {
1643 Module *oso_module = GetModuleByCompUnitInfo(comp_unit_info);
1644 if (oso_module) {
1645 // Check the .o file's DWARF in case it has an error to display.
1646 SymbolFile *oso_sym_file = oso_module->GetSymbolFile();
1647 if (oso_sym_file)
1648 return oso_sym_file->GetFrameVariableError(frame);
1649 }
1650 // If we don't have a valid OSO module here, then something went
1651 // wrong as we have a symbol for the address in the debug map, but
1652 // we weren't able to open the .o file. Display an appropriate
1653 // error
1654 if (comp_unit_info->oso_load_error.Fail())
1655 return comp_unit_info->oso_load_error.Clone();
1656 else
1658 "unable to load debug map object file \"%s\" "
1659 "exist, debug info will not be loaded",
1660 comp_unit_info->oso_path.GetCString());
1661 }
1662 }
1663 }
1664 }
1665 }
1666 return Status();
1667}
1668
1670 std::unordered_map<lldb::CompUnitSP, lldb_private::Args> &args) {
1671
1672 ForEachSymbolFile("Parsing compile options", [&](SymbolFileDWARF &oso_dwarf) {
1673 oso_dwarf.GetCompileOptions(args);
1675 });
1676}
1677
1680 lldb::TypeSP type;
1681 ForEachSymbolFile("Looking up enclosing type for variable",
1682 [&](SymbolFileDWARF &oso_dwarf) {
1683 type = oso_dwarf.GetTypeEnclosingVariableUID(uid);
1684 return type ? IterationAction::Stop
1686 });
1687 return type;
1688}
1689
1690llvm::Expected<SymbolContext>
1692 const uint64_t oso_idx = GetOSOIndexFromUserID(label.symbol_id);
1693 SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex(oso_idx);
1694 if (!oso_dwarf)
1695 return llvm::createStringErrorV(
1696 "couldn't find symbol file for {0} in debug-map.", label);
1697
1698 return oso_dwarf->ResolveFunctionCallLabel(label);
1699}
#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:415
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:139
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:973
ConstString GetLookupName() const
Definition Module.h:1013
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:1235
virtual SymbolFile * GetSymbolFile(bool can_create=true, Stream *feedback_strm=nullptr)
Get the module's symbol file.
Definition Module.cpp:1017
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:238
std::recursive_mutex m_mutex
A mutex to keep this object happy in multi-threaded environments.
Definition Module.h:1115
bool ResolveFileAddress(lldb::addr_t vm_addr, Address &so_addr)
Definition Module.cpp:448
lldb::SymbolVendorUP m_symfile_up
A pointer to the symbol vendor for this module.
Definition Module.h:1156
friend class ObjectFile
Definition Module.h:1215
std::string GetSpecificationDescription() const
Get the module path and object name.
Definition Module.cpp:1072
const FileSpec & GetFileSpec() const
Get const accessor for the module file specification.
Definition Module.h:448
friend class SymbolFile
Definition Module.h:1216
A plug-in interface definition class for object file parsers.
Definition ObjectFile.h:47
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:56
@ eTypeDebugInfo
An object file that contains only debug information.
Definition ObjectFile.h:58
@ eTypeStubLibrary
A library that can be linked against but not used for execution.
Definition ObjectFile.h:66
@ eTypeObjectFile
An intermediate object file.
Definition ObjectFile.h:62
@ eTypeDynamicLinker
The platform's dynamic linker executable.
Definition ObjectFile.h:60
@ eTypeCoreFile
A core file that has a checkpoint of a program's execution state.
Definition ObjectFile.h:54
@ eTypeSharedLibrary
A shared library that can be used during execution.
Definition ObjectFile.h:64
@ eTypeJIT
JIT code that has symbols, sections and possibly debug info.
Definition ObjectFile.h:68
virtual void ClearSymtab()
Frees the symbol table.
virtual FileSpec & GetFileSpec()
Get accessor to the object file specification.
Definition ObjectFile.h:285
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:262
Symbol * FindFirstSymbolWithNameAndType(ConstString name, lldb::SymbolType symbol_type, Debug symbol_debug_type, Visibility symbol_visibility)
Definition Symtab.cpp:850
void SortSymbolIndexesByValue(std::vector< uint32_t > &indexes, bool remove_duplicates) const
Definition Symtab.cpp:612
bool HasDebugMap() const
Check if this symbol table has a debug map, see SetHasDebugMap().
Definition Symtab.cpp:99
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:486
uint32_t GetIndexForSymbol(const Symbol *symbol) const
Definition Symtab.cpp:547
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:504
const Symbol * GetParent(Symbol *symbol) const
Get the parent symbol for the given symbol.
Definition Symtab.cpp:1137
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)