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 ConstString object_name, off_t object_offset,
183 const llvm::sys::TimePoint<> object_mod_time)
184 : Module(file_spec, arch, object_name, object_offset, object_mod_time),
185 m_exe_module_wp(exe_module_sp), m_cu_idx(cu_idx) {}
186
187 ~DebugMapModule() override = default;
188
189 SymbolFile *
190 GetSymbolFile(bool can_create = true,
191 lldb_private::Stream *feedback_strm = nullptr) override {
192 // Scope for locker
193 if (m_symfile_up.get() || !can_create)
194 return m_symfile_up ? m_symfile_up->GetSymbolFile() : nullptr;
195
196 ModuleSP exe_module_sp(m_exe_module_wp.lock());
197 if (exe_module_sp) {
198 // Now get the object file outside of a locking scope
199 ObjectFile *oso_objfile = GetObjectFile();
200 if (oso_objfile) {
201 std::lock_guard<std::recursive_mutex> guard(m_mutex);
202 if (SymbolFile *symfile =
203 Module::GetSymbolFile(can_create, feedback_strm)) {
204 // Set a pointer to this class to set our OSO DWARF file know that
205 // the DWARF is being used along with a debug map and that it will
206 // have the remapped sections that we do below.
207 SymbolFileDWARF *oso_symfile =
209
210 if (!oso_symfile)
211 return nullptr;
212
213 ObjectFile *exe_objfile = exe_module_sp->GetObjectFile();
214 SymbolFile *exe_symfile = exe_module_sp->GetSymbolFile();
215
216 if (exe_objfile && exe_symfile) {
217 oso_symfile->SetDebugMapModule(exe_module_sp);
218 // Set the ID of the symbol file DWARF to the index of the OSO
219 // shifted left by 32 bits to provide a unique prefix for any
220 // UserID's that get created in the symbol file.
221 oso_symfile->SetFileIndex((uint64_t)m_cu_idx);
222 }
223 return symfile;
224 }
225 }
226 }
227 return nullptr;
228 }
229
230protected:
232 const uint32_t m_cu_idx;
233};
234} // namespace dwarf
235} // namespace lldb_private::plugin
236
241
245
247 return "DWARF and DWARF3 debug symbol file reader (debug map).";
248}
249
251 return new SymbolFileDWARFDebugMap(std::move(objfile_sp));
252}
253
257
259
261
264 return;
265
267
268 // If the object file has been stripped, there is no sense in looking further
269 // as all of the debug symbols for the debug map will not be available
270 if (m_objfile_sp->IsStripped())
271 return;
272
273 // Also make sure the file type is some sort of executable. Core files, debug
274 // info files (dSYM), object files (.o files), and stub libraries all can
275 switch (m_objfile_sp->GetType()) {
283 return;
284
288 break;
289 }
290
291 // In order to get the abilities of this plug-in, we look at the list of
292 // N_OSO entries (object files) from the symbol table and make sure that
293 // these files exist and also contain valid DWARF. If we get any of that then
294 // we return the abilities of the first N_OSO's DWARF.
295
296 Symtab *symtab = m_objfile_sp->GetSymtab();
297 if (!symtab)
298 return;
299
301
302 std::vector<uint32_t> oso_indexes;
303 // When a mach-o symbol is encoded, the n_type field is encoded in bits
304 // 23:16, and the n_desc field is encoded in bits 15:0.
305 //
306 // To find all N_OSO entries that are part of the DWARF + debug map we find
307 // only object file symbols with the flags value as follows: bits 23:16 ==
308 // 0x66 (N_OSO) bits 15: 0 == 0x0001 (specifies this is a debug map object
309 // file)
310 const uint32_t k_oso_symbol_flags_value = 0x660001u;
311
312 const uint32_t oso_index_count =
314 eSymbolTypeObjectFile, k_oso_symbol_flags_value, oso_indexes);
315
316 if (oso_index_count == 0)
317 return;
318
323
326
327 for (uint32_t sym_idx :
328 llvm::concat<uint32_t>(m_func_indexes, m_glob_indexes)) {
329 const Symbol *symbol = symtab->SymbolAtIndex(sym_idx);
330 lldb::addr_t file_addr = symbol->GetAddressRef().GetFileAddress();
331 lldb::addr_t byte_size = symbol->GetByteSize();
332 DebugMap::Entry debug_map_entry(file_addr, byte_size,
334 m_debug_map.Append(debug_map_entry);
335 }
336 m_debug_map.Sort();
337
338 m_compile_unit_infos.resize(oso_index_count);
339
340 for (uint32_t i = 0; i < oso_index_count; ++i) {
341 const uint32_t so_idx = oso_indexes[i] - 1;
342 const uint32_t oso_idx = oso_indexes[i];
343 const Symbol *so_symbol = symtab->SymbolAtIndex(so_idx);
344 const Symbol *oso_symbol = symtab->SymbolAtIndex(oso_idx);
345 if (so_symbol && oso_symbol &&
346 so_symbol->GetType() == eSymbolTypeSourceFile &&
347 oso_symbol->GetType() == eSymbolTypeObjectFile) {
348 m_compile_unit_infos[i].so_file.SetFile(
349 so_symbol->GetName().GetStringRef(), FileSpec::Style::native);
350 m_compile_unit_infos[i].oso_path = oso_symbol->GetName();
351 m_compile_unit_infos[i].oso_mod_time =
352 llvm::sys::toTimePoint(oso_symbol->GetIntegerValue(0));
353 uint32_t sibling_idx = so_symbol->GetSiblingIndex();
354 // The sibling index can't be less that or equal to the current index
355 // "i"
356 if (sibling_idx <= i || sibling_idx == UINT32_MAX) {
357 m_objfile_sp->GetModule()->ReportError(
358 "N_SO in symbol with UID {0} has invalid sibling in debug "
359 "map, "
360 "please file a bug and attach the binary listed in this error",
361 so_symbol->GetID());
362 } else {
363 const Symbol *last_symbol = symtab->SymbolAtIndex(sibling_idx - 1);
364 m_compile_unit_infos[i].first_symbol_index = so_idx;
365 m_compile_unit_infos[i].last_symbol_index = sibling_idx - 1;
366 m_compile_unit_infos[i].first_symbol_id = so_symbol->GetID();
367 m_compile_unit_infos[i].last_symbol_id = last_symbol->GetID();
368
369 LLDB_LOGF(log, "Initialized OSO 0x%8.8x: file=%s", i,
370 oso_symbol->GetName().GetCString());
371 }
372 } else {
373 if (oso_symbol == nullptr)
374 m_objfile_sp->GetModule()->ReportError(
375 "N_OSO symbol[{0}] can't be found, please file a bug and "
376 "attach "
377 "the binary listed in this error",
378 oso_idx);
379 else if (so_symbol == nullptr)
380 m_objfile_sp->GetModule()->ReportError(
381 "N_SO not found for N_OSO symbol[{0}], please file a bug and "
382 "attach the binary listed in this error",
383 oso_idx);
384 else if (so_symbol->GetType() != eSymbolTypeSourceFile)
385 m_objfile_sp->GetModule()->ReportError(
386 "N_SO has incorrect symbol type ({0}) for N_OSO "
387 "symbol[{1}], "
388 "please file a bug and attach the binary listed in this error",
389 so_symbol->GetType(), oso_idx);
390 else if (oso_symbol->GetType() != eSymbolTypeSourceFile)
391 m_objfile_sp->GetModule()->ReportError(
392 "N_OSO has incorrect symbol type ({0}) for N_OSO "
393 "symbol[{1}], "
394 "please file a bug and attach the binary listed in this error",
395 oso_symbol->GetType(), oso_idx);
396 }
397 }
398}
399
401 const uint32_t cu_count = GetNumCompileUnits();
402 if (oso_idx < cu_count)
404 return nullptr;
405}
406
408 CompileUnitInfo *comp_unit_info) {
409 if (!comp_unit_info->oso_sp) {
410 auto pos = m_oso_map.find(
411 {comp_unit_info->oso_path, comp_unit_info->oso_mod_time});
412 if (pos != m_oso_map.end()) {
413 comp_unit_info->oso_sp = pos->second;
414 } else {
415 ObjectFile *obj_file = GetObjectFile();
416 comp_unit_info->oso_sp = std::make_shared<OSOInfo>();
417 m_oso_map[{comp_unit_info->oso_path, comp_unit_info->oso_mod_time}] =
418 comp_unit_info->oso_sp;
419 const char *oso_path = comp_unit_info->oso_path.GetCString();
420 FileSpec oso_file(oso_path);
421 ConstString oso_object;
422 if (FileSystem::Instance().Exists(oso_file)) {
423 // The modification time returned by the FS can have a higher precision
424 // than the one from the CU.
425 auto oso_mod_time = std::chrono::time_point_cast<std::chrono::seconds>(
426 FileSystem::Instance().GetModificationTime(oso_file));
427 // A timestamp of 0 means that the linker was in deterministic mode. In
428 // that case, we should skip the check against the filesystem last
429 // modification timestamp, since it will never match.
430 if (comp_unit_info->oso_mod_time != llvm::sys::TimePoint<>() &&
431 oso_mod_time != comp_unit_info->oso_mod_time) {
433 "debug map object file \"%s\" changed (actual: 0x%8.8x, debug "
434 "map: 0x%8.8x) since this executable was linked, debug info "
435 "will not be loaded",
436 oso_file.GetPath().c_str(),
437 (uint32_t)llvm::sys::toTimeT(oso_mod_time),
438 (uint32_t)llvm::sys::toTimeT(comp_unit_info->oso_mod_time));
439 obj_file->GetModule()->ReportError(
440 "{0}", comp_unit_info->oso_load_error.AsCString());
441 return nullptr;
442 }
443
444 } else {
445 const bool must_exist = true;
446
447 if (!ObjectFile::SplitArchivePathWithObject(oso_path, oso_file,
448 oso_object, must_exist)) {
450 "debug map object file \"%s\" containing debug info does not "
451 "exist, debug info will not be loaded",
452 comp_unit_info->oso_path.GetCString());
453 obj_file->GetModule()->ReportError(
454 "{0}", comp_unit_info->oso_load_error.AsCString());
455 return nullptr;
456 }
457 }
458 // Always create a new module for .o files. Why? Because we use the debug
459 // map, to add new sections to each .o file and even though a .o file
460 // might not have changed, the sections that get added to the .o file can
461 // change.
462 ArchSpec oso_arch;
463 // Only adopt the architecture from the module (not the vendor or OS)
464 // since .o files for "i386-apple-ios" will historically show up as "i386
465 // -apple-macosx" due to the lack of a LC_VERSION_MIN_MACOSX or
466 // LC_VERSION_MIN_IPHONEOS load command...
467 oso_arch.SetTriple(m_objfile_sp->GetModule()
468 ->GetArchitecture()
469 .GetTriple()
470 .getArchName()
471 .str()
472 .c_str());
473 comp_unit_info->oso_sp->module_sp = std::make_shared<DebugMapModule>(
474 obj_file->GetModule(), GetCompUnitInfoIndex(comp_unit_info), oso_file,
475 oso_arch, oso_object, 0,
476 oso_object ? comp_unit_info->oso_mod_time : llvm::sys::TimePoint<>());
477
478 if (oso_object && !comp_unit_info->oso_sp->module_sp->GetObjectFile() &&
479 FileSystem::Instance().Exists(oso_file)) {
480 // If we are loading a .o file from a .a file the "oso_object" will
481 // have a valid value name and if the .a file exists, either the .o
482 // file didn't exist in the .a file or the mod time didn't match.
484 "\"%s\" object from the \"%s\" archive: "
485 "either the .o file doesn't exist in the archive or the "
486 "modification time (0x%8.8x) of the .o file doesn't match",
487 oso_object.AsCString(""), oso_file.GetPath().c_str(),
488 (uint32_t)llvm::sys::toTimeT(comp_unit_info->oso_mod_time));
489 }
490 }
491 }
492 if (comp_unit_info->oso_sp)
493 return comp_unit_info->oso_sp->module_sp.get();
494 return nullptr;
495}
496
498 FileSpec &file_spec) {
499 if (oso_idx < m_compile_unit_infos.size()) {
500 if (m_compile_unit_infos[oso_idx].so_file) {
501 file_spec = m_compile_unit_infos[oso_idx].so_file;
502 return true;
503 }
504 }
505 return false;
506}
507
509 Module *oso_module = GetModuleByOSOIndex(oso_idx);
510 if (oso_module)
511 return oso_module->GetObjectFile();
512 return nullptr;
513}
514
519
522 CompileUnitInfo *comp_unit_info = GetCompUnitInfo(comp_unit);
523 if (comp_unit_info)
524 return GetSymbolFileByCompUnitInfo(comp_unit_info);
525 return nullptr;
526}
527
529 CompileUnitInfo *comp_unit_info) {
530 Module *oso_module = GetModuleByCompUnitInfo(comp_unit_info);
531 if (oso_module)
532 return oso_module->GetObjectFile();
533 return nullptr;
534}
535
537 const CompileUnitInfo *comp_unit_info) {
538 if (!m_compile_unit_infos.empty()) {
539 const CompileUnitInfo *first_comp_unit_info = &m_compile_unit_infos.front();
540 const CompileUnitInfo *last_comp_unit_info = &m_compile_unit_infos.back();
541 if (first_comp_unit_info <= comp_unit_info &&
542 comp_unit_info <= last_comp_unit_info)
543 return comp_unit_info - first_comp_unit_info;
544 }
545 return UINT32_MAX;
546}
547
550 unsigned size = m_compile_unit_infos.size();
551 if (oso_idx < size)
553 return nullptr;
554}
555
558 if (sym_file &&
560 return static_cast<SymbolFileDWARF *>(sym_file);
561 return nullptr;
562}
563
565 CompileUnitInfo *comp_unit_info) {
566 if (Module *oso_module = GetModuleByCompUnitInfo(comp_unit_info))
567 return GetSymbolFileAsSymbolFileDWARF(oso_module->GetSymbolFile());
568 return nullptr;
569}
570
572 // In order to get the abilities of this plug-in, we look at the list of
573 // N_OSO entries (object files) from the symbol table and make sure that
574 // these files exist and also contain valid DWARF. If we get any of that then
575 // we return the abilities of the first N_OSO's DWARF.
576
577 const uint32_t oso_index_count = GetNumCompileUnits();
578 if (oso_index_count > 0) {
579 InitOSO();
580 if (!m_compile_unit_infos.empty()) {
585 }
586 }
587 return 0;
588}
589
594
596 CompUnitSP comp_unit_sp;
597 const uint32_t cu_count = GetNumCompileUnits();
598
599 if (cu_idx < cu_count) {
600 auto &cu_info = m_compile_unit_infos[cu_idx];
601 Module *oso_module = GetModuleByCompUnitInfo(&cu_info);
602 if (oso_module) {
603 FileSpec so_file_spec;
604 if (GetFileSpecForSO(cu_idx, so_file_spec)) {
605 // Apply the module's source path remappings so that compile units
606 // created from N_SO stabs (which may contain paths rewritten by
607 // -fdebug-prefix-map at build time) report their real on-disk paths.
608 // This mirrors what MakeAbsoluteAndRemap does for the dSYM case.
609 if (ModuleSP module_sp = m_objfile_sp->GetModule())
610 if (auto remapped =
611 module_sp->RemapSourceFile(so_file_spec.GetPath()))
612 so_file_spec.SetFile(*remapped, FileSpec::Style::native);
613
614 // User zero as the ID to match the compile unit at offset zero in each
615 // .o file.
616 lldb::user_id_t cu_id = 0;
617 cu_info.compile_units_sps.push_back(std::make_shared<CompileUnit>(
618 m_objfile_sp->GetModule(), nullptr,
619 std::make_shared<SupportFile>(so_file_spec), cu_id,
621 cu_info.id_to_index_map.insert({0, 0});
622 SetCompileUnitAtIndex(cu_idx, cu_info.compile_units_sps[0]);
623 // If there's a symbol file also register all the extra compile units.
624 if (SymbolFileDWARF *oso_symfile =
625 GetSymbolFileByCompUnitInfo(&cu_info)) {
626 auto num_dwarf_units = oso_symfile->DebugInfo().GetNumUnits();
627 for (size_t i = 0; i < num_dwarf_units; ++i) {
628 auto *dwarf_unit = oso_symfile->DebugInfo().GetUnitAtIndex(i);
629 if (auto *dwarf_cu = llvm::dyn_cast<DWARFCompileUnit>(dwarf_unit)) {
630 // The "main" one was already registered.
631 if (dwarf_cu->GetID() == 0)
632 continue;
633 cu_info.compile_units_sps.push_back(std::make_shared<CompileUnit>(
634 m_objfile_sp->GetModule(), nullptr,
635 std::make_shared<SupportFile>(so_file_spec),
636 dwarf_cu->GetID(), eLanguageTypeUnknown, eLazyBoolCalculate));
637 cu_info.id_to_index_map.insert(
638 {dwarf_cu->GetID(), cu_info.compile_units_sps.size() - 1});
639 }
640 }
641 }
642 }
643 }
644 if (!cu_info.compile_units_sps.empty())
645 comp_unit_sp = cu_info.compile_units_sps[0];
646 }
647
648 return comp_unit_sp;
649}
650
655
658 const uint32_t cu_count = GetNumCompileUnits();
659 for (uint32_t i = 0; i < cu_count; ++i) {
660 auto &id_to_index_map = m_compile_unit_infos[i].id_to_index_map;
661
662 auto it = id_to_index_map.find(comp_unit.GetID());
663 if (it != id_to_index_map.end() &&
664 &comp_unit ==
665 m_compile_unit_infos[i].compile_units_sps[it->getSecond()].get())
666 return &m_compile_unit_infos[i];
667 }
668 return nullptr;
669}
670
672 const lldb_private::Module *module,
673 std::vector<CompileUnitInfo *> &cu_infos) {
674 const uint32_t cu_count = GetNumCompileUnits();
675 for (uint32_t i = 0; i < cu_count; ++i) {
677 cu_infos.push_back(&m_compile_unit_infos[i]);
678 }
679 return cu_infos.size();
680}
681
684 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
685 SymbolFileDWARF *oso_dwarf = GetSymbolFile(comp_unit);
686 if (oso_dwarf)
687 return oso_dwarf->ParseLanguage(comp_unit);
689}
690
692 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
693 SymbolFileDWARF *oso_dwarf = GetSymbolFile(comp_unit);
694 if (oso_dwarf)
695 return oso_dwarf->ParseXcodeSDK(comp_unit);
696 return {};
697}
698
699llvm::SmallSet<lldb::LanguageType, 4>
701 lldb_private::CompileUnit &comp_unit) {
702 llvm::SmallSet<lldb::LanguageType, 4> langs;
703 auto *info = GetCompUnitInfo(comp_unit);
704 for (auto &comp_unit : info->compile_units_sps) {
705 langs.insert(comp_unit->GetLanguage());
706 }
707 return langs;
708}
709
711 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
712 SymbolFileDWARF *oso_dwarf = GetSymbolFile(comp_unit);
713 if (oso_dwarf)
714 return oso_dwarf->ParseFunctions(comp_unit);
715 return 0;
716}
717
719 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
720 SymbolFileDWARF *oso_dwarf = GetSymbolFile(comp_unit);
721 if (oso_dwarf)
722 return oso_dwarf->ParseLineTable(comp_unit);
723 return false;
724}
725
727 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
728 SymbolFileDWARF *oso_dwarf = GetSymbolFile(comp_unit);
729 if (oso_dwarf)
730 return oso_dwarf->ParseDebugMacros(comp_unit);
731 return false;
732}
733
735 std::string description,
736 std::function<IterationAction(SymbolFileDWARF &)> closure) {
737 const size_t num_oso_idxs = m_compile_unit_infos.size();
738 Progress progress(std::move(description), "", num_oso_idxs,
739 /*debugger=*/nullptr,
741 for (uint32_t oso_idx = 0; oso_idx < num_oso_idxs; ++oso_idx) {
742 if (SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex(oso_idx)) {
743 progress.Increment(oso_idx, oso_dwarf->GetObjectName());
744 if (closure(*oso_dwarf) == IterationAction::Stop)
745 return;
746 }
747 }
748}
749
751 CompileUnit &comp_unit,
752 llvm::DenseSet<lldb_private::SymbolFile *> &visited_symbol_files,
753 llvm::function_ref<bool(Module &)> f) {
754 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
755 SymbolFileDWARF *oso_dwarf = GetSymbolFile(comp_unit);
756 if (oso_dwarf)
757 return oso_dwarf->ForEachExternalModule(comp_unit, visited_symbol_files, f);
758 return false;
759}
760
762 CompileUnit &comp_unit, SupportFileList &support_files) {
763 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
764 SymbolFileDWARF *oso_dwarf = GetSymbolFile(comp_unit);
765 if (oso_dwarf)
766 return oso_dwarf->ParseSupportFiles(comp_unit, support_files);
767 return false;
768}
769
771 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
772 SymbolFileDWARF *oso_dwarf = GetSymbolFile(comp_unit);
773 if (oso_dwarf)
774 return oso_dwarf->ParseIsOptimized(comp_unit);
775 return false;
776}
777
779 const SymbolContext &sc, std::vector<SourceModule> &imported_modules) {
780 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
781 SymbolFileDWARF *oso_dwarf = GetSymbolFile(sc);
782 if (oso_dwarf)
783 return oso_dwarf->ParseImportedModules(sc, imported_modules);
784 return false;
785}
786
788 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
789 CompileUnit *comp_unit = func.GetCompileUnit();
790 if (!comp_unit)
791 return 0;
792
793 SymbolFileDWARF *oso_dwarf = GetSymbolFile(*comp_unit);
794 if (oso_dwarf)
795 return oso_dwarf->ParseBlocksRecursive(func);
796 return 0;
797}
798
800 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
801 SymbolFileDWARF *oso_dwarf = GetSymbolFile(comp_unit);
802 if (oso_dwarf)
803 return oso_dwarf->ParseTypes(comp_unit);
804 return 0;
805}
806
807size_t
809 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
810 SymbolFileDWARF *oso_dwarf = GetSymbolFile(sc);
811 if (oso_dwarf)
812 return oso_dwarf->ParseVariablesForContext(sc);
813 return 0;
814}
815
817 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
818 const uint64_t oso_idx = GetOSOIndexFromUserID(type_uid);
819 SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex(oso_idx);
820 if (oso_dwarf)
821 return oso_dwarf->ResolveTypeUID(type_uid);
822 return nullptr;
823}
824
825std::optional<SymbolFile::ArrayInfo>
827 lldb::user_id_t type_uid, const lldb_private::ExecutionContext *exe_ctx) {
828 const uint64_t oso_idx = GetOSOIndexFromUserID(type_uid);
829 SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex(oso_idx);
830 if (oso_dwarf)
831 return oso_dwarf->GetDynamicArrayInfoForUID(type_uid, exe_ctx);
832 return std::nullopt;
833}
834
836 bool success = false;
837 if (compiler_type) {
838 ForEachSymbolFile("Completing type", [&](SymbolFileDWARF &oso_dwarf) {
839 if (oso_dwarf.HasForwardDeclForCompilerType(compiler_type)) {
840 oso_dwarf.CompleteType(compiler_type);
841 success = true;
843 }
845 });
846 }
847 return success;
848}
849
850uint32_t
852 SymbolContextItem resolve_scope,
853 SymbolContext &sc) {
854 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
855 uint32_t resolved_flags = 0;
856 Symtab *symtab = m_objfile_sp->GetSymtab();
857 if (symtab) {
858 const addr_t exe_file_addr = exe_so_addr.GetFileAddress();
859
860 const DebugMap::Entry *debug_map_entry =
861 m_debug_map.FindEntryThatContains(exe_file_addr);
862 if (debug_map_entry) {
863
864 sc.symbol =
865 symtab->SymbolAtIndex(debug_map_entry->data.GetExeSymbolIndex());
866
867 if (sc.symbol != nullptr) {
868 resolved_flags |= eSymbolContextSymbol;
869
870 uint32_t oso_idx = 0;
871 CompileUnitInfo *comp_unit_info =
873 if (comp_unit_info) {
874 comp_unit_info->GetFileRangeMap(this);
875 Module *oso_module = GetModuleByCompUnitInfo(comp_unit_info);
876 if (oso_module) {
877 lldb::addr_t oso_file_addr =
878 exe_file_addr - debug_map_entry->GetRangeBase() +
879 debug_map_entry->data.GetOSOFileAddress();
880 Address oso_so_addr;
881 if (oso_module->ResolveFileAddress(oso_file_addr, oso_so_addr)) {
882 if (SymbolFile *sym_file = oso_module->GetSymbolFile()) {
883 resolved_flags |= sym_file->ResolveSymbolContext(
884 oso_so_addr, resolve_scope, sc);
885 } else {
886 ObjectFile *obj_file = GetObjectFile();
888 "Failed to get symfile for OSO: {0} in module: {1}",
889 oso_module->GetFileSpec(),
890 obj_file ? obj_file->GetFileSpec()
891 : FileSpec("unknown"));
892 }
893 }
894 }
895 }
896 }
897 }
898 }
899 return resolved_flags;
900}
901
903 const SourceLocationSpec &src_location_spec,
904 SymbolContextItem resolve_scope, SymbolContextList &sc_list) {
905 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
906 const uint32_t initial = sc_list.GetSize();
907 const uint32_t cu_count = GetNumCompileUnits();
908
909 for (uint32_t i = 0; i < cu_count; ++i) {
910 // If we are checking for inlines, then we need to look through all compile
911 // units no matter if "file_spec" matches.
912 bool resolve = src_location_spec.GetCheckInlines();
913
914 if (!resolve) {
915 FileSpec so_file_spec;
916 if (GetFileSpecForSO(i, so_file_spec))
917 resolve =
918 FileSpec::Match(src_location_spec.GetFileSpec(), so_file_spec);
919 }
920 if (resolve) {
922 if (oso_dwarf)
923 oso_dwarf->ResolveSymbolContext(src_location_spec, resolve_scope,
924 sc_list);
925 }
926 }
927 return sc_list.GetSize() - initial;
928}
929
931 ConstString name, const CompilerDeclContext &parent_decl_ctx,
932 const std::vector<uint32_t>
933 &indexes, // Indexes into the symbol table that match "name"
934 uint32_t max_matches, VariableList &variables) {
935 const size_t match_count = indexes.size();
936 for (size_t i = 0; i < match_count; ++i) {
937 uint32_t oso_idx;
938 CompileUnitInfo *comp_unit_info =
939 GetCompileUnitInfoForSymbolWithIndex(indexes[i], &oso_idx);
940 if (comp_unit_info) {
941 SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex(oso_idx);
942 if (oso_dwarf) {
943 oso_dwarf->FindGlobalVariables(name, parent_decl_ctx, max_matches,
944 variables);
945 if (variables.GetSize() > max_matches)
946 break;
947 }
948 }
949 }
950}
951
953 ConstString name, const CompilerDeclContext &parent_decl_ctx,
954 uint32_t max_matches, VariableList &variables) {
955 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
956 uint32_t total_matches = 0;
957
959 "Looking up global variables", [&](SymbolFileDWARF &oso_dwarf) {
960 const uint32_t old_size = variables.GetSize();
961 oso_dwarf.FindGlobalVariables(name, parent_decl_ctx, max_matches,
962 variables);
963 const uint32_t oso_matches = variables.GetSize() - old_size;
964 if (oso_matches > 0) {
965 total_matches += oso_matches;
966
967 // If we are getting all matches, keep going.
968 if (max_matches == UINT32_MAX)
970
971 // If we have found enough matches, lets get out
972 if (max_matches >= total_matches)
974
975 // Update the max matches for any subsequent calls to find globals in
976 // any other object files with DWARF
977 max_matches -= oso_matches;
978 }
979
981 });
982}
983
985 const RegularExpression &regex, uint32_t max_matches,
986 VariableList &variables) {
987 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
988 uint32_t total_matches = 0;
990 "Looking up global variables", [&](SymbolFileDWARF &oso_dwarf) {
991 const uint32_t old_size = variables.GetSize();
992 oso_dwarf.FindGlobalVariables(regex, max_matches, variables);
993
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 uint32_t *symbol_idx_ptr, const CompileUnitInfo *comp_unit_info) {
1017 const uint32_t symbol_idx = *symbol_idx_ptr;
1018
1019 if (symbol_idx < comp_unit_info->first_symbol_index)
1020 return -1;
1021
1022 if (symbol_idx <= comp_unit_info->last_symbol_index)
1023 return 0;
1024
1025 return 1;
1026}
1027
1029 user_id_t *symbol_idx_ptr, const CompileUnitInfo *comp_unit_info) {
1030 const user_id_t symbol_id = *symbol_idx_ptr;
1031
1032 if (symbol_id < comp_unit_info->first_symbol_id)
1033 return -1;
1034
1035 if (symbol_id <= comp_unit_info->last_symbol_id)
1036 return 0;
1037
1038 return 1;
1039}
1040
1043 uint32_t symbol_idx, uint32_t *oso_idx_ptr) {
1044 const uint32_t oso_index_count = m_compile_unit_infos.size();
1045 CompileUnitInfo *comp_unit_info = nullptr;
1046 if (oso_index_count) {
1047 comp_unit_info = (CompileUnitInfo *)bsearch(
1048 &symbol_idx, &m_compile_unit_infos[0], m_compile_unit_infos.size(),
1049 sizeof(CompileUnitInfo),
1051 }
1052
1053 if (oso_idx_ptr) {
1054 if (comp_unit_info != nullptr)
1055 *oso_idx_ptr = comp_unit_info - &m_compile_unit_infos[0];
1056 else
1057 *oso_idx_ptr = UINT32_MAX;
1058 }
1059 return comp_unit_info;
1060}
1061
1064 user_id_t symbol_id, uint32_t *oso_idx_ptr) {
1065 const uint32_t oso_index_count = m_compile_unit_infos.size();
1066 CompileUnitInfo *comp_unit_info = nullptr;
1067 if (oso_index_count) {
1068 comp_unit_info = (CompileUnitInfo *)::bsearch(
1069 &symbol_id, &m_compile_unit_infos[0], m_compile_unit_infos.size(),
1070 sizeof(CompileUnitInfo),
1072 }
1073
1074 if (oso_idx_ptr) {
1075 if (comp_unit_info != nullptr)
1076 *oso_idx_ptr = comp_unit_info - &m_compile_unit_infos[0];
1077 else
1078 *oso_idx_ptr = UINT32_MAX;
1079 }
1080 return comp_unit_info;
1081}
1082
1084 SymbolContextList &sc_list,
1085 uint32_t start_idx) {
1086 // We found functions in .o files. Not all functions in the .o files will
1087 // have made it into the final output file. The ones that did make it into
1088 // the final output file will have a section whose module matches the module
1089 // from the ObjectFile for this SymbolFile. When the modules don't match,
1090 // then we have something that was in a .o file, but doesn't map to anything
1091 // in the final executable.
1092 uint32_t i = start_idx;
1093 while (i < sc_list.GetSize()) {
1094 SymbolContext sc;
1095 sc_list.GetContextAtIndex(i, sc);
1096 if (sc.function) {
1097 const SectionSP section_sp = sc.function->GetAddress().GetSection();
1098 if (section_sp->GetModule() != module_sp) {
1099 sc_list.RemoveContextAtIndex(i);
1100 continue;
1101 }
1102 }
1103 ++i;
1104 }
1105}
1106
1108 const Module::LookupInfo &lookup_info,
1109 const CompilerDeclContext &parent_decl_ctx, bool include_inlines,
1110 SymbolContextList &sc_list) {
1111 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1112 LLDB_SCOPED_TIMERF("SymbolFileDWARFDebugMap::FindFunctions (name = %s)",
1113 lookup_info.GetLookupName().GetCString());
1114
1115 ForEachSymbolFile("Looking up functions", [&](SymbolFileDWARF &oso_dwarf) {
1116 uint32_t sc_idx = sc_list.GetSize();
1117 oso_dwarf.FindFunctions(lookup_info, parent_decl_ctx, include_inlines,
1118 sc_list);
1119 if (!sc_list.IsEmpty()) {
1121 sc_idx);
1122 }
1124 });
1125}
1126
1128 bool include_inlines,
1129 SymbolContextList &sc_list) {
1130 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1131 LLDB_SCOPED_TIMERF("SymbolFileDWARFDebugMap::FindFunctions (regex = '%s')",
1132 regex.GetText().str().c_str());
1133
1134 ForEachSymbolFile("Looking up functions", [&](SymbolFileDWARF &oso_dwarf) {
1135 uint32_t sc_idx = sc_list.GetSize();
1136
1137 oso_dwarf.FindFunctions(regex, include_inlines, sc_list);
1138 if (!sc_list.IsEmpty()) {
1140 sc_idx);
1141 }
1143 });
1144}
1145
1147 lldb::TypeClass type_mask,
1148 TypeList &type_list) {
1149 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1150 LLDB_SCOPED_TIMERF("SymbolFileDWARFDebugMap::GetTypes (type_mask = 0x%8.8x)",
1151 type_mask);
1152
1153 SymbolFileDWARF *oso_dwarf = nullptr;
1154 if (sc_scope) {
1155 SymbolContext sc;
1156 sc_scope->CalculateSymbolContext(&sc);
1157
1158 CompileUnitInfo *cu_info = GetCompUnitInfo(sc);
1159 if (cu_info) {
1160 oso_dwarf = GetSymbolFileByCompUnitInfo(cu_info);
1161 if (oso_dwarf)
1162 oso_dwarf->GetTypes(sc_scope, type_mask, type_list);
1163 }
1164 } else {
1165 ForEachSymbolFile("Looking up types", [&](SymbolFileDWARF &oso_dwarf) {
1166 oso_dwarf.GetTypes(sc_scope, type_mask, type_list);
1168 });
1169 }
1170}
1171
1172std::vector<std::unique_ptr<lldb_private::CallEdge>>
1174 lldb_private::UserID func_id) {
1175 uint32_t oso_idx = GetOSOIndexFromUserID(func_id.GetID());
1176 SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex(oso_idx);
1177 if (oso_dwarf)
1178 return oso_dwarf->ParseCallEdgesInFunction(func_id);
1179 return {};
1180}
1181
1183 DWARFDIE result;
1185 "Looking up type definition", [&](SymbolFileDWARF &oso_dwarf) {
1186 result = oso_dwarf.FindDefinitionDIE(die);
1188 });
1189 return result;
1190}
1191
1193 const DWARFDIE &die, ConstString type_name, bool must_be_implementation) {
1194 // If we have a debug map, we will have an Objective-C symbol whose name is
1195 // the type name and whose type is eSymbolTypeObjCClass. If we can find that
1196 // symbol and find its containing parent, we can locate the .o file that will
1197 // contain the implementation definition since it will be scoped inside the
1198 // N_SO and we can then locate the SymbolFileDWARF that corresponds to that
1199 // N_SO.
1200 SymbolFileDWARF *oso_dwarf = nullptr;
1201 TypeSP type_sp;
1202 ObjectFile *module_objfile = m_objfile_sp->GetModule()->GetObjectFile();
1203 if (module_objfile) {
1204 Symtab *symtab = module_objfile->GetSymtab();
1205 if (symtab) {
1206 Symbol *objc_class_symbol = symtab->FindFirstSymbolWithNameAndType(
1209 if (objc_class_symbol) {
1210 // Get the N_SO symbol that contains the objective C class symbol as
1211 // this should be the .o file that contains the real definition...
1212 const Symbol *source_file_symbol = symtab->GetParent(objc_class_symbol);
1213
1214 if (source_file_symbol &&
1215 source_file_symbol->GetType() == eSymbolTypeSourceFile) {
1216 const uint32_t source_file_symbol_idx =
1217 symtab->GetIndexForSymbol(source_file_symbol);
1218 if (source_file_symbol_idx != UINT32_MAX) {
1219 CompileUnitInfo *compile_unit_info =
1220 GetCompileUnitInfoForSymbolWithIndex(source_file_symbol_idx,
1221 nullptr);
1222 if (compile_unit_info) {
1223 oso_dwarf = GetSymbolFileByCompUnitInfo(compile_unit_info);
1224 if (oso_dwarf) {
1226 die, type_name, must_be_implementation));
1227 if (type_sp) {
1228 return type_sp;
1229 }
1230 }
1231 }
1232 }
1233 }
1234 }
1235 }
1236 }
1237
1238 // Only search all .o files for the definition if we don't need the
1239 // implementation because otherwise, with a valid debug map we should have
1240 // the ObjC class symbol and the code above should have found it.
1241 if (!must_be_implementation) {
1242 TypeSP type_sp;
1243
1245 "Looking up Objective-C definition", [&](SymbolFileDWARF &oso_dwarf) {
1246 type_sp = oso_dwarf.FindCompleteObjCDefinitionTypeForDIE(
1247 die, type_name, must_be_implementation);
1249 });
1250
1251 return type_sp;
1252 }
1253 return TypeSP();
1254}
1255
1257 TypeResults &results) {
1258 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1259 ForEachSymbolFile("Looking up type", [&](SymbolFileDWARF &oso_dwarf) {
1260 oso_dwarf.FindTypes(query, results);
1261 return results.Done(query) ? IterationAction::Stop
1263 });
1264}
1265
1267 lldb_private::ConstString name, const CompilerDeclContext &parent_decl_ctx,
1268 bool only_root_namespaces) {
1269 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1270 CompilerDeclContext matching_namespace;
1271
1272 ForEachSymbolFile("Looking up namespace", [&](SymbolFileDWARF &oso_dwarf) {
1273 matching_namespace =
1274 oso_dwarf.FindNamespace(name, parent_decl_ctx, only_root_namespaces);
1275
1276 return matching_namespace ? IterationAction::Stop
1278 });
1279
1280 return matching_namespace;
1281}
1282
1283void SymbolFileDWARFDebugMap::DumpClangAST(Stream &s, llvm::StringRef filter,
1284 bool show_color) {
1285 ForEachSymbolFile("Dumping clang AST", [&](SymbolFileDWARF &oso_dwarf) {
1286 oso_dwarf.DumpClangAST(s, filter, show_color);
1287 // The underlying assumption is that DumpClangAST(...) will obtain the
1288 // AST from the underlying TypeSystem and therefore we only need to do
1289 // this once and can stop after the first iteration hence we return true.
1290 return IterationAction::Stop;
1291 });
1292}
1293
1296 const uint32_t cu_count = GetNumCompileUnits();
1298 for (uint32_t cu_idx = 0; cu_idx < cu_count; ++cu_idx) {
1299 const auto &info = m_compile_unit_infos[cu_idx];
1300 if (info.so_file.GetPath().empty())
1301 continue;
1302
1303 ModuleSpec spec;
1304 FileSpec oso_file;
1305 ConstString oso_object;
1306 if (ObjectFile::SplitArchivePathWithObject(info.oso_path.GetStringRef(),
1307 oso_file, oso_object,
1308 /*must_exist=*/false)) {
1309 spec.GetFileSpec() = oso_file;
1310 spec.GetObjectName() = oso_object;
1311 } else {
1312 spec.GetFileSpec() = FileSpec(info.oso_path.GetStringRef());
1313 }
1314
1315 spec.GetObjectModificationTime() = info.oso_mod_time;
1316 spec_list.Append(spec);
1317 }
1318 return spec_list;
1319}
1320
1322 lldb_private::StructuredData::Dictionary &d, bool errors_only,
1323 bool load_all_debug_info) {
1324 StructuredData::Array separate_debug_info_files;
1325 const uint32_t cu_count = GetNumCompileUnits();
1326 for (uint32_t cu_idx = 0; cu_idx < cu_count; ++cu_idx) {
1327 const auto &info = m_compile_unit_infos[cu_idx];
1329 std::make_shared<StructuredData::Dictionary>();
1330 oso_data->AddStringItem("so_file", info.so_file.GetPath());
1331 oso_data->AddStringItem("oso_path", info.oso_path);
1332 oso_data->AddIntegerItem("oso_mod_time",
1333 (uint32_t)llvm::sys::toTimeT(info.oso_mod_time));
1334
1335 bool loaded_successfully = false;
1336 if (GetModuleByOSOIndex(cu_idx)) {
1337 // If we have a valid pointer to the module, we successfully
1338 // loaded the oso if there are no load errors.
1339 if (!info.oso_load_error.Fail()) {
1340 loaded_successfully = true;
1341 }
1342 }
1343 if (!loaded_successfully) {
1344 oso_data->AddStringItem("error", info.oso_load_error.AsCString());
1345 }
1346 oso_data->AddBooleanItem("loaded", loaded_successfully);
1347 if (!errors_only || oso_data->HasKey("error"))
1348 separate_debug_info_files.AddItem(oso_data);
1349 }
1350
1351 d.AddStringItem("type", "oso");
1352 d.AddStringItem("symfile", GetMainObjectFile()->GetFileSpec().GetPath());
1353 d.AddItem("separate-debug-info-files",
1354 std::make_shared<StructuredData::Array>(
1355 std::move(separate_debug_info_files)));
1356 return true;
1357}
1358
1361 DWARFCompileUnit &dwarf_cu) {
1362 if (oso_dwarf) {
1363 const uint32_t cu_count = GetNumCompileUnits();
1364 for (uint32_t cu_idx = 0; cu_idx < cu_count; ++cu_idx) {
1365 SymbolFileDWARF *oso_symfile =
1367 if (oso_symfile == oso_dwarf) {
1368 if (m_compile_unit_infos[cu_idx].compile_units_sps.empty())
1370
1371 auto &id_to_index_map = m_compile_unit_infos[cu_idx].id_to_index_map;
1372 auto it = id_to_index_map.find(dwarf_cu.GetID());
1373 if (it != id_to_index_map.end())
1374 return m_compile_unit_infos[cu_idx]
1375 .compile_units_sps[it->getSecond()];
1376 }
1377 }
1378 }
1379 llvm_unreachable("this shouldn't happen");
1380}
1381
1384 if (oso_dwarf) {
1385 const uint32_t cu_count = GetNumCompileUnits();
1386 for (uint32_t cu_idx = 0; cu_idx < cu_count; ++cu_idx) {
1387 SymbolFileDWARF *oso_symfile =
1389 if (oso_symfile == oso_dwarf) {
1390 return &m_compile_unit_infos[cu_idx];
1391 }
1392 }
1393 }
1394 return nullptr;
1395}
1396
1398 const CompUnitSP &cu_sp) {
1399 if (oso_dwarf) {
1400 const uint32_t cu_count = GetNumCompileUnits();
1401 for (uint32_t cu_idx = 0; cu_idx < cu_count; ++cu_idx) {
1402 SymbolFileDWARF *oso_symfile =
1404 if (oso_symfile == oso_dwarf) {
1405 if (!m_compile_unit_infos[cu_idx].compile_units_sps.empty()) {
1406 assert(m_compile_unit_infos[cu_idx].compile_units_sps[0].get() ==
1407 cu_sp.get());
1408 } else {
1409 assert(cu_sp->GetID() == 0 &&
1410 "Setting first compile unit but with id different than 0!");
1411 auto &compile_units_sps =
1412 m_compile_unit_infos[cu_idx].compile_units_sps;
1413 compile_units_sps.push_back(cu_sp);
1414 m_compile_unit_infos[cu_idx].id_to_index_map.insert(
1415 {cu_sp->GetID(), compile_units_sps.size() - 1});
1416
1417 SetCompileUnitAtIndex(cu_idx, cu_sp);
1418 }
1419 }
1420 }
1421 }
1422}
1423
1426 const uint64_t oso_idx = GetOSOIndexFromUserID(type_uid);
1427 if (SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex(oso_idx))
1428 return oso_dwarf->GetDeclContextForUID(type_uid);
1429 return {};
1430}
1431
1434 const uint64_t oso_idx = GetOSOIndexFromUserID(type_uid);
1435 if (SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex(oso_idx))
1436 return oso_dwarf->GetDeclContextContainingUID(type_uid);
1437 return {};
1438}
1439
1440std::vector<CompilerContext>
1442 const uint64_t oso_idx = GetOSOIndexFromUserID(type_uid);
1443 if (SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex(oso_idx))
1444 return oso_dwarf->GetCompilerContextForUID(type_uid);
1445 return {};
1446}
1447
1450 ForEachSymbolFile("Parsing declarations", [&](SymbolFileDWARF &oso_dwarf) {
1451 oso_dwarf.ParseDeclsForContext(decl_ctx);
1453 });
1454}
1455
1457 lldb::addr_t exe_file_addr,
1458 lldb::addr_t exe_byte_size,
1459 lldb::addr_t oso_file_addr,
1460 lldb::addr_t oso_byte_size) {
1461 const uint32_t debug_map_idx =
1462 m_debug_map.FindEntryIndexThatContains(exe_file_addr);
1463 if (debug_map_idx != UINT32_MAX) {
1464 DebugMap::Entry *debug_map_entry =
1465 m_debug_map.FindEntryThatContains(exe_file_addr);
1466 debug_map_entry->data.SetOSOFileAddress(oso_file_addr);
1467 addr_t range_size = std::min<addr_t>(exe_byte_size, oso_byte_size);
1468 if (range_size == 0) {
1469 range_size = std::max<addr_t>(exe_byte_size, oso_byte_size);
1470 if (range_size == 0)
1471 range_size = 1;
1472 }
1473 cu_info->file_range_map.Append(
1474 FileRangeMap::Entry(oso_file_addr, range_size, exe_file_addr));
1475 return true;
1476 }
1477 return false;
1478}
1479
1481 cu_info->file_range_map.Sort();
1482#if defined(DEBUG_OSO_DMAP)
1483 const FileRangeMap &oso_file_range_map = cu_info->GetFileRangeMap(this);
1484 const size_t n = oso_file_range_map.GetSize();
1485 printf("SymbolFileDWARFDebugMap::FinalizeOSOFileRanges (cu_info = %p) %s\n",
1486 cu_info, cu_info->oso_sp->module_sp->GetFileSpec().GetPath().c_str());
1487 for (size_t i = 0; i < n; ++i) {
1488 const FileRangeMap::Entry &entry = oso_file_range_map.GetEntryRef(i);
1489 printf("oso [0x%16.16" PRIx64 " - 0x%16.16" PRIx64
1490 ") ==> exe [0x%16.16" PRIx64 " - 0x%16.16" PRIx64 ")\n",
1491 entry.GetRangeBase(), entry.GetRangeEnd(), entry.data,
1492 entry.data + entry.GetByteSize());
1493 }
1494#endif
1495}
1496
1499 lldb::addr_t oso_file_addr) {
1500 CompileUnitInfo *cu_info = GetCompileUnitInfo(oso_symfile);
1501 if (cu_info) {
1502 const FileRangeMap::Entry *oso_range_entry =
1503 cu_info->GetFileRangeMap(this).FindEntryThatContains(oso_file_addr);
1504 if (oso_range_entry) {
1505 const DebugMap::Entry *debug_map_entry =
1506 m_debug_map.FindEntryThatContains(oso_range_entry->data);
1507 if (debug_map_entry) {
1508 const lldb::addr_t offset =
1509 oso_file_addr - oso_range_entry->GetRangeBase();
1510 const lldb::addr_t exe_file_addr =
1511 debug_map_entry->GetRangeBase() + offset;
1512 return exe_file_addr;
1513 }
1514 }
1515 }
1516 return LLDB_INVALID_ADDRESS;
1517}
1518
1520 // Make sure this address hasn't been fixed already
1521 Module *exe_module = GetObjectFile()->GetModule().get();
1522 Module *addr_module = addr.GetModule().get();
1523 if (addr_module == exe_module)
1524 return true; // Address is already in terms of the main executable module
1525
1528 if (cu_info) {
1529 const lldb::addr_t oso_file_addr = addr.GetFileAddress();
1530 const FileRangeMap::Entry *oso_range_entry =
1531 cu_info->GetFileRangeMap(this).FindEntryThatContains(oso_file_addr);
1532 if (oso_range_entry) {
1533 const DebugMap::Entry *debug_map_entry =
1534 m_debug_map.FindEntryThatContains(oso_range_entry->data);
1535 if (debug_map_entry) {
1536 const lldb::addr_t offset =
1537 oso_file_addr - oso_range_entry->GetRangeBase();
1538 const lldb::addr_t exe_file_addr =
1539 debug_map_entry->GetRangeBase() + offset;
1540 return exe_module->ResolveFileAddress(exe_file_addr, addr);
1541 }
1542 }
1543 }
1544 return true;
1545}
1546
1548 LineTable *line_table) {
1549 CompileUnitInfo *cu_info = GetCompileUnitInfo(oso_dwarf);
1550 if (cu_info)
1551 return line_table->LinkLineTable(cu_info->GetFileRangeMap(this));
1552 return nullptr;
1553}
1554
1555size_t
1557 DWARFDebugAranges *debug_aranges) {
1558 size_t num_line_entries_added = 0;
1559 if (debug_aranges && dwarf2Data) {
1560 CompileUnitInfo *compile_unit_info = GetCompileUnitInfo(dwarf2Data);
1561 if (compile_unit_info) {
1562 const FileRangeMap &file_range_map =
1563 compile_unit_info->GetFileRangeMap(this);
1564 for (size_t idx = 0; idx < file_range_map.GetSize(); idx++) {
1565 const FileRangeMap::Entry *entry = file_range_map.GetEntryAtIndex(idx);
1566 if (entry) {
1567 debug_aranges->AppendRange(*dwarf2Data->GetFileIndex(),
1568 entry->GetRangeBase(),
1569 entry->GetRangeEnd());
1570 num_line_entries_added++;
1571 }
1572 }
1573 }
1574 }
1575 return num_line_entries_added;
1576}
1577
1579 ModuleList oso_modules;
1580 ForEachSymbolFile("Parsing modules", [&](SymbolFileDWARF &oso_dwarf) {
1581 ObjectFile *oso_objfile = oso_dwarf.GetObjectFile();
1582 if (oso_objfile) {
1583 ModuleSP module_sp = oso_objfile->GetModule();
1584 if (module_sp)
1585 oso_modules.Append(module_sp);
1586 }
1588 });
1589 return oso_modules;
1590}
1591
1593 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1594
1595 // We need to make sure that our PC value from the frame matches the module
1596 // for this object file since we will lookup the PC file address in the debug
1597 // map below.
1598 Address pc_addr = frame.GetFrameCodeAddress();
1599 if (pc_addr.GetModule() == m_objfile_sp->GetModule()) {
1600 Symtab *symtab = m_objfile_sp->GetSymtab();
1601 if (symtab) {
1602 const DebugMap::Entry *debug_map_entry =
1603 m_debug_map.FindEntryThatContains(pc_addr.GetFileAddress());
1604 if (debug_map_entry) {
1605 const Symbol *symbol =
1606 symtab->SymbolAtIndex(debug_map_entry->data.GetExeSymbolIndex());
1607 if (symbol) {
1608 uint32_t oso_idx = 0;
1609 CompileUnitInfo *comp_unit_info =
1610 GetCompileUnitInfoForSymbolWithID(symbol->GetID(), &oso_idx);
1611 if (comp_unit_info) {
1612 Module *oso_module = GetModuleByCompUnitInfo(comp_unit_info);
1613 if (oso_module) {
1614 // Check the .o file's DWARF in case it has an error to display.
1615 SymbolFile *oso_sym_file = oso_module->GetSymbolFile();
1616 if (oso_sym_file)
1617 return oso_sym_file->GetFrameVariableError(frame);
1618 }
1619 // If we don't have a valid OSO module here, then something went
1620 // wrong as we have a symbol for the address in the debug map, but
1621 // we weren't able to open the .o file. Display an appropriate
1622 // error
1623 if (comp_unit_info->oso_load_error.Fail())
1624 return comp_unit_info->oso_load_error.Clone();
1625 else
1627 "unable to load debug map object file \"%s\" "
1628 "exist, debug info will not be loaded",
1629 comp_unit_info->oso_path.GetCString());
1630 }
1631 }
1632 }
1633 }
1634 }
1635 return Status();
1636}
1637
1639 std::unordered_map<lldb::CompUnitSP, lldb_private::Args> &args) {
1640
1641 ForEachSymbolFile("Parsing compile options", [&](SymbolFileDWARF &oso_dwarf) {
1642 oso_dwarf.GetCompileOptions(args);
1644 });
1645}
1646
1649 lldb::TypeSP type;
1650 ForEachSymbolFile("Looking up enclosing type for variable",
1651 [&](SymbolFileDWARF &oso_dwarf) {
1652 type = oso_dwarf.GetTypeEnclosingVariableUID(uid);
1653 return type ? IterationAction::Stop
1655 });
1656 return type;
1657}
1658
1659llvm::Expected<SymbolContext>
1661 const uint64_t oso_idx = GetOSOIndexFromUserID(label.symbol_id);
1662 SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex(oso_idx);
1663 if (!oso_dwarf)
1664 return llvm::createStringErrorV(
1665 "couldn't find symbol file for {0} in debug-map.", label);
1666
1667 return oso_dwarf->ResolveFunctionCallLabel(label);
1668}
#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)
#define LLDB_SCOPED_TIMERF(...)
Definition Timer.h:86
A section + offset based address class.
Definition Address.h:62
lldb::SectionSP GetSection() const
Get const accessor for the section.
Definition Address.h:426
lldb::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:949
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.
const char * AsCString(const char *value_if_empty) 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
static FileSystem & Instance()
A class that describes a function.
Definition Function.h:377
const Address & GetAddress() const
Return the address of the function (its entry point).
Definition Function.h:430
CompileUnit * GetCompileUnit()
Get accessor for the compile unit that owns this function.
Definition Function.cpp:418
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:369
lldb::ModuleSP GetModule() const
Get const accessor for the module pointer.
A collection class for Module objects.
Definition ModuleList.h:125
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
ConstString & GetObjectName()
Definition ModuleSpec.h:107
FileSpec & GetFileSpec()
Definition ModuleSpec.h:57
llvm::sys::TimePoint & GetObjectModificationTime()
Definition ModuleSpec.h:130
A class that encapsulates name lookup information.
Definition Module.h:935
ConstString GetLookupName() const
Definition Module.h:974
A class that describes an executable image and its associated object and symbol files.
Definition Module.h:91
virtual ObjectFile * GetObjectFile()
Get the object file representation for the current architecture.
Definition Module.cpp:1179
virtual SymbolFile * GetSymbolFile(bool can_create=true, Stream *feedback_strm=nullptr)
Get the module's symbol file.
Definition Module.cpp:975
std::recursive_mutex m_mutex
A mutex to keep this object happy in multi-threaded environments.
Definition Module.h:1053
bool ResolveFileAddress(lldb::addr_t vm_addr, Address &so_addr)
Definition Module.cpp:421
lldb::SymbolVendorUP m_symfile_up
A pointer to the symbol vendor for this module.
Definition Module.h:1093
Module(const FileSpec &file_spec, const ArchSpec &arch, ConstString object_name=ConstString(), 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:231
friend class ObjectFile
Definition Module.h:1155
std::string GetSpecificationDescription() const
Get the module path and object name.
Definition Module.cpp:1019
const FileSpec & GetFileSpec() const
Get const accessor for the module file specification.
Definition Module.h:447
friend class SymbolFile
Definition Module.h:1156
A plug-in interface definition class for object file parsers.
Definition ObjectFile.h:46
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:280
static bool SplitArchivePathWithObject(llvm::StringRef path_with_object, lldb_private::FileSpec &archive_file, lldb_private::ConstString &archive_object, bool must_exist)
Split a path into a file path with object name.
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:62
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
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:588
lldb::ObjectFileSP m_objfile_sp
Definition SymbolFile.h:664
ObjectFile * GetMainObjectFile() override
void SetCompileUnitAtIndex(uint32_t idx, const lldb::CompUnitSP &cu_sp)
SymbolFileCommon(lldb::ObjectFileSP objfile_sp)
Definition SymbolFile.h:573
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:280
std::unordered_map< lldb::CompUnitSP, Args > GetCompileOptions()
Returns a map of compilation unit to the compile option arguments associated with that compilation un...
Definition SymbolFile.h:532
uint32_t GetSiblingIndex() const
Definition Symbol.cpp:241
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:191
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:469
ConstString GetName() const
Definition Symbol.cpp:612
lldb::SymbolType GetType() const
Definition Symbol.h:197
Symbol * SymbolAtIndex(size_t idx)
Definition Symtab.cpp:225
Symbol * FindFirstSymbolWithNameAndType(ConstString name, lldb::SymbolType symbol_type, Debug symbol_debug_type, Visibility symbol_visibility)
Definition Symtab.cpp:860
void SortSymbolIndexesByValue(std::vector< uint32_t > &indexes, bool remove_duplicates) const
Definition Symtab.cpp:622
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:496
uint32_t GetIndexForSymbol(const Symbol *symbol) const
Definition Symtab.cpp:557
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:514
const Symbol * GetParent(Symbol *symbol) const
Get the parent symbol for the given symbol.
Definition Symtab.cpp:1145
A class that contains all state required for type lookups.
Definition Type.h:104
This class tracks the state and results of a TypeQuery.
Definition Type.h:344
bool Done(const TypeQuery &query) const
Check if the type matching has found all of the matches that it needs.
Definition Type.cpp:201
An abstraction for Xcode-style SDKs that works like ArchSpec.
Definition XcodeSDK.h:25
void AppendRange(dw_offset_t cu_offset, dw_addr_t low_pc, dw_addr_t high_pc)
DebugMapModule(const ModuleSP &exe_module_sp, uint32_t cu_idx, const FileSpec &file_spec, const ArchSpec &arch, ConstString object_name, off_t object_offset, const llvm::sys::TimePoint<> object_mod_time)
SymbolFile * GetSymbolFile(bool can_create=true, lldb_private::Stream *feedback_strm=nullptr) override
Get the module's symbol file.
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
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
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)
XcodeSDK ParseXcodeSDK(CompileUnit &comp_unit) override
Return the Xcode SDK comp_unit was compiled against.
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
XcodeSDK ParseXcodeSDK(CompileUnit &comp_unit) override
Return the Xcode SDK comp_unit was compiled against.
bool ParseImportedModules(const SymbolContext &sc, std::vector< SourceModule > &imported_modules) override
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)
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)