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(so_symbol->GetName().AsCString(),
349 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 return nullptr;
454 }
455 }
456 // Always create a new module for .o files. Why? Because we use the debug
457 // map, to add new sections to each .o file and even though a .o file
458 // might not have changed, the sections that get added to the .o file can
459 // change.
460 ArchSpec oso_arch;
461 // Only adopt the architecture from the module (not the vendor or OS)
462 // since .o files for "i386-apple-ios" will historically show up as "i386
463 // -apple-macosx" due to the lack of a LC_VERSION_MIN_MACOSX or
464 // LC_VERSION_MIN_IPHONEOS load command...
465 oso_arch.SetTriple(m_objfile_sp->GetModule()
466 ->GetArchitecture()
467 .GetTriple()
468 .getArchName()
469 .str()
470 .c_str());
471 comp_unit_info->oso_sp->module_sp = std::make_shared<DebugMapModule>(
472 obj_file->GetModule(), GetCompUnitInfoIndex(comp_unit_info), oso_file,
473 oso_arch, oso_object, 0,
474 oso_object ? comp_unit_info->oso_mod_time : llvm::sys::TimePoint<>());
475
476 if (oso_object && !comp_unit_info->oso_sp->module_sp->GetObjectFile() &&
477 FileSystem::Instance().Exists(oso_file)) {
478 // If we are loading a .o file from a .a file the "oso_object" will
479 // have a valid value name and if the .a file exists, either the .o
480 // file didn't exist in the .a file or the mod time didn't match.
482 "\"%s\" object from the \"%s\" archive: "
483 "either the .o file doesn't exist in the archive or the "
484 "modification time (0x%8.8x) of the .o file doesn't match",
485 oso_object.AsCString(), oso_file.GetPath().c_str(),
486 (uint32_t)llvm::sys::toTimeT(comp_unit_info->oso_mod_time));
487 }
488 }
489 }
490 if (comp_unit_info->oso_sp)
491 return comp_unit_info->oso_sp->module_sp.get();
492 return nullptr;
493}
494
496 FileSpec &file_spec) {
497 if (oso_idx < m_compile_unit_infos.size()) {
498 if (m_compile_unit_infos[oso_idx].so_file) {
499 file_spec = m_compile_unit_infos[oso_idx].so_file;
500 return true;
501 }
502 }
503 return false;
504}
505
507 Module *oso_module = GetModuleByOSOIndex(oso_idx);
508 if (oso_module)
509 return oso_module->GetObjectFile();
510 return nullptr;
511}
512
517
520 CompileUnitInfo *comp_unit_info = GetCompUnitInfo(comp_unit);
521 if (comp_unit_info)
522 return GetSymbolFileByCompUnitInfo(comp_unit_info);
523 return nullptr;
524}
525
527 CompileUnitInfo *comp_unit_info) {
528 Module *oso_module = GetModuleByCompUnitInfo(comp_unit_info);
529 if (oso_module)
530 return oso_module->GetObjectFile();
531 return nullptr;
532}
533
535 const CompileUnitInfo *comp_unit_info) {
536 if (!m_compile_unit_infos.empty()) {
537 const CompileUnitInfo *first_comp_unit_info = &m_compile_unit_infos.front();
538 const CompileUnitInfo *last_comp_unit_info = &m_compile_unit_infos.back();
539 if (first_comp_unit_info <= comp_unit_info &&
540 comp_unit_info <= last_comp_unit_info)
541 return comp_unit_info - first_comp_unit_info;
542 }
543 return UINT32_MAX;
544}
545
548 unsigned size = m_compile_unit_infos.size();
549 if (oso_idx < size)
551 return nullptr;
552}
553
556 if (sym_file &&
558 return static_cast<SymbolFileDWARF *>(sym_file);
559 return nullptr;
560}
561
563 CompileUnitInfo *comp_unit_info) {
564 if (Module *oso_module = GetModuleByCompUnitInfo(comp_unit_info))
565 return GetSymbolFileAsSymbolFileDWARF(oso_module->GetSymbolFile());
566 return nullptr;
567}
568
570 // In order to get the abilities of this plug-in, we look at the list of
571 // N_OSO entries (object files) from the symbol table and make sure that
572 // these files exist and also contain valid DWARF. If we get any of that then
573 // we return the abilities of the first N_OSO's DWARF.
574
575 const uint32_t oso_index_count = GetNumCompileUnits();
576 if (oso_index_count > 0) {
577 InitOSO();
578 if (!m_compile_unit_infos.empty()) {
583 }
584 }
585 return 0;
586}
587
592
594 CompUnitSP comp_unit_sp;
595 const uint32_t cu_count = GetNumCompileUnits();
596
597 if (cu_idx < cu_count) {
598 auto &cu_info = m_compile_unit_infos[cu_idx];
599 Module *oso_module = GetModuleByCompUnitInfo(&cu_info);
600 if (oso_module) {
601 FileSpec so_file_spec;
602 if (GetFileSpecForSO(cu_idx, so_file_spec)) {
603 // Apply the module's source path remappings so that compile units
604 // created from N_SO stabs (which may contain paths rewritten by
605 // -fdebug-prefix-map at build time) report their real on-disk paths.
606 // This mirrors what MakeAbsoluteAndRemap does for the dSYM case.
607 if (ModuleSP module_sp = m_objfile_sp->GetModule())
608 if (auto remapped =
609 module_sp->RemapSourceFile(so_file_spec.GetPath()))
610 so_file_spec.SetFile(*remapped, FileSpec::Style::native);
611
612 // User zero as the ID to match the compile unit at offset zero in each
613 // .o file.
614 lldb::user_id_t cu_id = 0;
615 cu_info.compile_units_sps.push_back(std::make_shared<CompileUnit>(
616 m_objfile_sp->GetModule(), nullptr,
617 std::make_shared<SupportFile>(so_file_spec), cu_id,
619 cu_info.id_to_index_map.insert({0, 0});
620 SetCompileUnitAtIndex(cu_idx, cu_info.compile_units_sps[0]);
621 // If there's a symbol file also register all the extra compile units.
622 if (SymbolFileDWARF *oso_symfile =
623 GetSymbolFileByCompUnitInfo(&cu_info)) {
624 auto num_dwarf_units = oso_symfile->DebugInfo().GetNumUnits();
625 for (size_t i = 0; i < num_dwarf_units; ++i) {
626 auto *dwarf_unit = oso_symfile->DebugInfo().GetUnitAtIndex(i);
627 if (auto *dwarf_cu = llvm::dyn_cast<DWARFCompileUnit>(dwarf_unit)) {
628 // The "main" one was already registered.
629 if (dwarf_cu->GetID() == 0)
630 continue;
631 cu_info.compile_units_sps.push_back(std::make_shared<CompileUnit>(
632 m_objfile_sp->GetModule(), nullptr,
633 std::make_shared<SupportFile>(so_file_spec),
634 dwarf_cu->GetID(), eLanguageTypeUnknown, eLazyBoolCalculate));
635 cu_info.id_to_index_map.insert(
636 {dwarf_cu->GetID(), cu_info.compile_units_sps.size() - 1});
637 }
638 }
639 }
640 }
641 }
642 if (!cu_info.compile_units_sps.empty())
643 comp_unit_sp = cu_info.compile_units_sps[0];
644 }
645
646 return comp_unit_sp;
647}
648
653
656 const uint32_t cu_count = GetNumCompileUnits();
657 for (uint32_t i = 0; i < cu_count; ++i) {
658 auto &id_to_index_map = m_compile_unit_infos[i].id_to_index_map;
659
660 auto it = id_to_index_map.find(comp_unit.GetID());
661 if (it != id_to_index_map.end() &&
662 &comp_unit ==
663 m_compile_unit_infos[i].compile_units_sps[it->getSecond()].get())
664 return &m_compile_unit_infos[i];
665 }
666 return nullptr;
667}
668
670 const lldb_private::Module *module,
671 std::vector<CompileUnitInfo *> &cu_infos) {
672 const uint32_t cu_count = GetNumCompileUnits();
673 for (uint32_t i = 0; i < cu_count; ++i) {
675 cu_infos.push_back(&m_compile_unit_infos[i]);
676 }
677 return cu_infos.size();
678}
679
682 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
683 SymbolFileDWARF *oso_dwarf = GetSymbolFile(comp_unit);
684 if (oso_dwarf)
685 return oso_dwarf->ParseLanguage(comp_unit);
687}
688
690 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
691 SymbolFileDWARF *oso_dwarf = GetSymbolFile(comp_unit);
692 if (oso_dwarf)
693 return oso_dwarf->ParseXcodeSDK(comp_unit);
694 return {};
695}
696
697llvm::SmallSet<lldb::LanguageType, 4>
699 lldb_private::CompileUnit &comp_unit) {
700 llvm::SmallSet<lldb::LanguageType, 4> langs;
701 auto *info = GetCompUnitInfo(comp_unit);
702 for (auto &comp_unit : info->compile_units_sps) {
703 langs.insert(comp_unit->GetLanguage());
704 }
705 return langs;
706}
707
709 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
710 SymbolFileDWARF *oso_dwarf = GetSymbolFile(comp_unit);
711 if (oso_dwarf)
712 return oso_dwarf->ParseFunctions(comp_unit);
713 return 0;
714}
715
717 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
718 SymbolFileDWARF *oso_dwarf = GetSymbolFile(comp_unit);
719 if (oso_dwarf)
720 return oso_dwarf->ParseLineTable(comp_unit);
721 return false;
722}
723
725 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
726 SymbolFileDWARF *oso_dwarf = GetSymbolFile(comp_unit);
727 if (oso_dwarf)
728 return oso_dwarf->ParseDebugMacros(comp_unit);
729 return false;
730}
731
733 std::string description,
734 std::function<IterationAction(SymbolFileDWARF &)> closure) {
735 const size_t num_oso_idxs = m_compile_unit_infos.size();
736 Progress progress(std::move(description), "", num_oso_idxs,
737 /*debugger=*/nullptr,
739 for (uint32_t oso_idx = 0; oso_idx < num_oso_idxs; ++oso_idx) {
740 if (SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex(oso_idx)) {
741 progress.Increment(oso_idx, oso_dwarf->GetObjectName());
742 if (closure(*oso_dwarf) == IterationAction::Stop)
743 return;
744 }
745 }
746}
747
749 CompileUnit &comp_unit,
750 llvm::DenseSet<lldb_private::SymbolFile *> &visited_symbol_files,
751 llvm::function_ref<bool(Module &)> f) {
752 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
753 SymbolFileDWARF *oso_dwarf = GetSymbolFile(comp_unit);
754 if (oso_dwarf)
755 return oso_dwarf->ForEachExternalModule(comp_unit, visited_symbol_files, f);
756 return false;
757}
758
760 CompileUnit &comp_unit, SupportFileList &support_files) {
761 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
762 SymbolFileDWARF *oso_dwarf = GetSymbolFile(comp_unit);
763 if (oso_dwarf)
764 return oso_dwarf->ParseSupportFiles(comp_unit, support_files);
765 return false;
766}
767
769 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
770 SymbolFileDWARF *oso_dwarf = GetSymbolFile(comp_unit);
771 if (oso_dwarf)
772 return oso_dwarf->ParseIsOptimized(comp_unit);
773 return false;
774}
775
777 const SymbolContext &sc, std::vector<SourceModule> &imported_modules) {
778 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
779 SymbolFileDWARF *oso_dwarf = GetSymbolFile(sc);
780 if (oso_dwarf)
781 return oso_dwarf->ParseImportedModules(sc, imported_modules);
782 return false;
783}
784
786 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
787 CompileUnit *comp_unit = func.GetCompileUnit();
788 if (!comp_unit)
789 return 0;
790
791 SymbolFileDWARF *oso_dwarf = GetSymbolFile(*comp_unit);
792 if (oso_dwarf)
793 return oso_dwarf->ParseBlocksRecursive(func);
794 return 0;
795}
796
798 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
799 SymbolFileDWARF *oso_dwarf = GetSymbolFile(comp_unit);
800 if (oso_dwarf)
801 return oso_dwarf->ParseTypes(comp_unit);
802 return 0;
803}
804
805size_t
807 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
808 SymbolFileDWARF *oso_dwarf = GetSymbolFile(sc);
809 if (oso_dwarf)
810 return oso_dwarf->ParseVariablesForContext(sc);
811 return 0;
812}
813
815 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
816 const uint64_t oso_idx = GetOSOIndexFromUserID(type_uid);
817 SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex(oso_idx);
818 if (oso_dwarf)
819 return oso_dwarf->ResolveTypeUID(type_uid);
820 return nullptr;
821}
822
823std::optional<SymbolFile::ArrayInfo>
825 lldb::user_id_t type_uid, const lldb_private::ExecutionContext *exe_ctx) {
826 const uint64_t oso_idx = GetOSOIndexFromUserID(type_uid);
827 SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex(oso_idx);
828 if (oso_dwarf)
829 return oso_dwarf->GetDynamicArrayInfoForUID(type_uid, exe_ctx);
830 return std::nullopt;
831}
832
834 bool success = false;
835 if (compiler_type) {
836 ForEachSymbolFile("Completing type", [&](SymbolFileDWARF &oso_dwarf) {
837 if (oso_dwarf.HasForwardDeclForCompilerType(compiler_type)) {
838 oso_dwarf.CompleteType(compiler_type);
839 success = true;
841 }
843 });
844 }
845 return success;
846}
847
848uint32_t
850 SymbolContextItem resolve_scope,
851 SymbolContext &sc) {
852 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
853 uint32_t resolved_flags = 0;
854 Symtab *symtab = m_objfile_sp->GetSymtab();
855 if (symtab) {
856 const addr_t exe_file_addr = exe_so_addr.GetFileAddress();
857
858 const DebugMap::Entry *debug_map_entry =
859 m_debug_map.FindEntryThatContains(exe_file_addr);
860 if (debug_map_entry) {
861
862 sc.symbol =
863 symtab->SymbolAtIndex(debug_map_entry->data.GetExeSymbolIndex());
864
865 if (sc.symbol != nullptr) {
866 resolved_flags |= eSymbolContextSymbol;
867
868 uint32_t oso_idx = 0;
869 CompileUnitInfo *comp_unit_info =
871 if (comp_unit_info) {
872 comp_unit_info->GetFileRangeMap(this);
873 Module *oso_module = GetModuleByCompUnitInfo(comp_unit_info);
874 if (oso_module) {
875 lldb::addr_t oso_file_addr =
876 exe_file_addr - debug_map_entry->GetRangeBase() +
877 debug_map_entry->data.GetOSOFileAddress();
878 Address oso_so_addr;
879 if (oso_module->ResolveFileAddress(oso_file_addr, oso_so_addr)) {
880 if (SymbolFile *sym_file = oso_module->GetSymbolFile()) {
881 resolved_flags |= sym_file->ResolveSymbolContext(
882 oso_so_addr, resolve_scope, sc);
883 } else {
884 ObjectFile *obj_file = GetObjectFile();
886 "Failed to get symfile for OSO: {0} in module: {1}",
887 oso_module->GetFileSpec(),
888 obj_file ? obj_file->GetFileSpec()
889 : FileSpec("unknown"));
890 }
891 }
892 }
893 }
894 }
895 }
896 }
897 return resolved_flags;
898}
899
901 const SourceLocationSpec &src_location_spec,
902 SymbolContextItem resolve_scope, SymbolContextList &sc_list) {
903 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
904 const uint32_t initial = sc_list.GetSize();
905 const uint32_t cu_count = GetNumCompileUnits();
906
907 for (uint32_t i = 0; i < cu_count; ++i) {
908 // If we are checking for inlines, then we need to look through all compile
909 // units no matter if "file_spec" matches.
910 bool resolve = src_location_spec.GetCheckInlines();
911
912 if (!resolve) {
913 FileSpec so_file_spec;
914 if (GetFileSpecForSO(i, so_file_spec))
915 resolve =
916 FileSpec::Match(src_location_spec.GetFileSpec(), so_file_spec);
917 }
918 if (resolve) {
920 if (oso_dwarf)
921 oso_dwarf->ResolveSymbolContext(src_location_spec, resolve_scope,
922 sc_list);
923 }
924 }
925 return sc_list.GetSize() - initial;
926}
927
929 ConstString name, const CompilerDeclContext &parent_decl_ctx,
930 const std::vector<uint32_t>
931 &indexes, // Indexes into the symbol table that match "name"
932 uint32_t max_matches, VariableList &variables) {
933 const size_t match_count = indexes.size();
934 for (size_t i = 0; i < match_count; ++i) {
935 uint32_t oso_idx;
936 CompileUnitInfo *comp_unit_info =
937 GetCompileUnitInfoForSymbolWithIndex(indexes[i], &oso_idx);
938 if (comp_unit_info) {
939 SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex(oso_idx);
940 if (oso_dwarf) {
941 oso_dwarf->FindGlobalVariables(name, parent_decl_ctx, max_matches,
942 variables);
943 if (variables.GetSize() > max_matches)
944 break;
945 }
946 }
947 }
948}
949
951 ConstString name, const CompilerDeclContext &parent_decl_ctx,
952 uint32_t max_matches, VariableList &variables) {
953 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
954 uint32_t total_matches = 0;
955
957 "Looking up global variables", [&](SymbolFileDWARF &oso_dwarf) {
958 const uint32_t old_size = variables.GetSize();
959 oso_dwarf.FindGlobalVariables(name, parent_decl_ctx, max_matches,
960 variables);
961 const uint32_t oso_matches = variables.GetSize() - old_size;
962 if (oso_matches > 0) {
963 total_matches += oso_matches;
964
965 // If we are getting all matches, keep going.
966 if (max_matches == UINT32_MAX)
968
969 // If we have found enough matches, lets get out
970 if (max_matches >= total_matches)
972
973 // Update the max matches for any subsequent calls to find globals in
974 // any other object files with DWARF
975 max_matches -= oso_matches;
976 }
977
979 });
980}
981
983 const RegularExpression &regex, uint32_t max_matches,
984 VariableList &variables) {
985 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
986 uint32_t total_matches = 0;
988 "Looking up global variables", [&](SymbolFileDWARF &oso_dwarf) {
989 const uint32_t old_size = variables.GetSize();
990 oso_dwarf.FindGlobalVariables(regex, max_matches, variables);
991
992 const uint32_t oso_matches = variables.GetSize() - old_size;
993 if (oso_matches > 0) {
994 total_matches += oso_matches;
995
996 // If we are getting all matches, keep going.
997 if (max_matches == UINT32_MAX)
999
1000 // If we have found enough matches, lets get out
1001 if (max_matches >= total_matches)
1002 return IterationAction::Stop;
1003
1004 // Update the max matches for any subsequent calls to find globals in
1005 // any other object files with DWARF
1006 max_matches -= oso_matches;
1007 }
1008
1010 });
1011}
1012
1014 uint32_t *symbol_idx_ptr, const CompileUnitInfo *comp_unit_info) {
1015 const uint32_t symbol_idx = *symbol_idx_ptr;
1016
1017 if (symbol_idx < comp_unit_info->first_symbol_index)
1018 return -1;
1019
1020 if (symbol_idx <= comp_unit_info->last_symbol_index)
1021 return 0;
1022
1023 return 1;
1024}
1025
1027 user_id_t *symbol_idx_ptr, const CompileUnitInfo *comp_unit_info) {
1028 const user_id_t symbol_id = *symbol_idx_ptr;
1029
1030 if (symbol_id < comp_unit_info->first_symbol_id)
1031 return -1;
1032
1033 if (symbol_id <= comp_unit_info->last_symbol_id)
1034 return 0;
1035
1036 return 1;
1037}
1038
1041 uint32_t symbol_idx, uint32_t *oso_idx_ptr) {
1042 const uint32_t oso_index_count = m_compile_unit_infos.size();
1043 CompileUnitInfo *comp_unit_info = nullptr;
1044 if (oso_index_count) {
1045 comp_unit_info = (CompileUnitInfo *)bsearch(
1046 &symbol_idx, &m_compile_unit_infos[0], m_compile_unit_infos.size(),
1047 sizeof(CompileUnitInfo),
1049 }
1050
1051 if (oso_idx_ptr) {
1052 if (comp_unit_info != nullptr)
1053 *oso_idx_ptr = comp_unit_info - &m_compile_unit_infos[0];
1054 else
1055 *oso_idx_ptr = UINT32_MAX;
1056 }
1057 return comp_unit_info;
1058}
1059
1062 user_id_t symbol_id, uint32_t *oso_idx_ptr) {
1063 const uint32_t oso_index_count = m_compile_unit_infos.size();
1064 CompileUnitInfo *comp_unit_info = nullptr;
1065 if (oso_index_count) {
1066 comp_unit_info = (CompileUnitInfo *)::bsearch(
1067 &symbol_id, &m_compile_unit_infos[0], m_compile_unit_infos.size(),
1068 sizeof(CompileUnitInfo),
1070 }
1071
1072 if (oso_idx_ptr) {
1073 if (comp_unit_info != nullptr)
1074 *oso_idx_ptr = comp_unit_info - &m_compile_unit_infos[0];
1075 else
1076 *oso_idx_ptr = UINT32_MAX;
1077 }
1078 return comp_unit_info;
1079}
1080
1082 SymbolContextList &sc_list,
1083 uint32_t start_idx) {
1084 // We found functions in .o files. Not all functions in the .o files will
1085 // have made it into the final output file. The ones that did make it into
1086 // the final output file will have a section whose module matches the module
1087 // from the ObjectFile for this SymbolFile. When the modules don't match,
1088 // then we have something that was in a .o file, but doesn't map to anything
1089 // in the final executable.
1090 uint32_t i = start_idx;
1091 while (i < sc_list.GetSize()) {
1092 SymbolContext sc;
1093 sc_list.GetContextAtIndex(i, sc);
1094 if (sc.function) {
1095 const SectionSP section_sp = sc.function->GetAddress().GetSection();
1096 if (section_sp->GetModule() != module_sp) {
1097 sc_list.RemoveContextAtIndex(i);
1098 continue;
1099 }
1100 }
1101 ++i;
1102 }
1103}
1104
1106 const Module::LookupInfo &lookup_info,
1107 const CompilerDeclContext &parent_decl_ctx, bool include_inlines,
1108 SymbolContextList &sc_list) {
1109 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1110 LLDB_SCOPED_TIMERF("SymbolFileDWARFDebugMap::FindFunctions (name = %s)",
1111 lookup_info.GetLookupName().GetCString());
1112
1113 ForEachSymbolFile("Looking up functions", [&](SymbolFileDWARF &oso_dwarf) {
1114 uint32_t sc_idx = sc_list.GetSize();
1115 oso_dwarf.FindFunctions(lookup_info, parent_decl_ctx, include_inlines,
1116 sc_list);
1117 if (!sc_list.IsEmpty()) {
1119 sc_idx);
1120 }
1122 });
1123}
1124
1126 bool include_inlines,
1127 SymbolContextList &sc_list) {
1128 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1129 LLDB_SCOPED_TIMERF("SymbolFileDWARFDebugMap::FindFunctions (regex = '%s')",
1130 regex.GetText().str().c_str());
1131
1132 ForEachSymbolFile("Looking up functions", [&](SymbolFileDWARF &oso_dwarf) {
1133 uint32_t sc_idx = sc_list.GetSize();
1134
1135 oso_dwarf.FindFunctions(regex, include_inlines, sc_list);
1136 if (!sc_list.IsEmpty()) {
1138 sc_idx);
1139 }
1141 });
1142}
1143
1145 lldb::TypeClass type_mask,
1146 TypeList &type_list) {
1147 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1148 LLDB_SCOPED_TIMERF("SymbolFileDWARFDebugMap::GetTypes (type_mask = 0x%8.8x)",
1149 type_mask);
1150
1151 SymbolFileDWARF *oso_dwarf = nullptr;
1152 if (sc_scope) {
1153 SymbolContext sc;
1154 sc_scope->CalculateSymbolContext(&sc);
1155
1156 CompileUnitInfo *cu_info = GetCompUnitInfo(sc);
1157 if (cu_info) {
1158 oso_dwarf = GetSymbolFileByCompUnitInfo(cu_info);
1159 if (oso_dwarf)
1160 oso_dwarf->GetTypes(sc_scope, type_mask, type_list);
1161 }
1162 } else {
1163 ForEachSymbolFile("Looking up types", [&](SymbolFileDWARF &oso_dwarf) {
1164 oso_dwarf.GetTypes(sc_scope, type_mask, type_list);
1166 });
1167 }
1168}
1169
1170std::vector<std::unique_ptr<lldb_private::CallEdge>>
1172 lldb_private::UserID func_id) {
1173 uint32_t oso_idx = GetOSOIndexFromUserID(func_id.GetID());
1174 SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex(oso_idx);
1175 if (oso_dwarf)
1176 return oso_dwarf->ParseCallEdgesInFunction(func_id);
1177 return {};
1178}
1179
1181 DWARFDIE result;
1183 "Looking up type definition", [&](SymbolFileDWARF &oso_dwarf) {
1184 result = oso_dwarf.FindDefinitionDIE(die);
1186 });
1187 return result;
1188}
1189
1191 const DWARFDIE &die, ConstString type_name, bool must_be_implementation) {
1192 // If we have a debug map, we will have an Objective-C symbol whose name is
1193 // the type name and whose type is eSymbolTypeObjCClass. If we can find that
1194 // symbol and find its containing parent, we can locate the .o file that will
1195 // contain the implementation definition since it will be scoped inside the
1196 // N_SO and we can then locate the SymbolFileDWARF that corresponds to that
1197 // N_SO.
1198 SymbolFileDWARF *oso_dwarf = nullptr;
1199 TypeSP type_sp;
1200 ObjectFile *module_objfile = m_objfile_sp->GetModule()->GetObjectFile();
1201 if (module_objfile) {
1202 Symtab *symtab = module_objfile->GetSymtab();
1203 if (symtab) {
1204 Symbol *objc_class_symbol = symtab->FindFirstSymbolWithNameAndType(
1207 if (objc_class_symbol) {
1208 // Get the N_SO symbol that contains the objective C class symbol as
1209 // this should be the .o file that contains the real definition...
1210 const Symbol *source_file_symbol = symtab->GetParent(objc_class_symbol);
1211
1212 if (source_file_symbol &&
1213 source_file_symbol->GetType() == eSymbolTypeSourceFile) {
1214 const uint32_t source_file_symbol_idx =
1215 symtab->GetIndexForSymbol(source_file_symbol);
1216 if (source_file_symbol_idx != UINT32_MAX) {
1217 CompileUnitInfo *compile_unit_info =
1218 GetCompileUnitInfoForSymbolWithIndex(source_file_symbol_idx,
1219 nullptr);
1220 if (compile_unit_info) {
1221 oso_dwarf = GetSymbolFileByCompUnitInfo(compile_unit_info);
1222 if (oso_dwarf) {
1224 die, type_name, must_be_implementation));
1225 if (type_sp) {
1226 return type_sp;
1227 }
1228 }
1229 }
1230 }
1231 }
1232 }
1233 }
1234 }
1235
1236 // Only search all .o files for the definition if we don't need the
1237 // implementation because otherwise, with a valid debug map we should have
1238 // the ObjC class symbol and the code above should have found it.
1239 if (!must_be_implementation) {
1240 TypeSP type_sp;
1241
1243 "Looking up Objective-C definition", [&](SymbolFileDWARF &oso_dwarf) {
1244 type_sp = oso_dwarf.FindCompleteObjCDefinitionTypeForDIE(
1245 die, type_name, must_be_implementation);
1247 });
1248
1249 return type_sp;
1250 }
1251 return TypeSP();
1252}
1253
1255 TypeResults &results) {
1256 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1257 ForEachSymbolFile("Looking up type", [&](SymbolFileDWARF &oso_dwarf) {
1258 oso_dwarf.FindTypes(query, results);
1259 return results.Done(query) ? IterationAction::Stop
1261 });
1262}
1263
1265 lldb_private::ConstString name, const CompilerDeclContext &parent_decl_ctx,
1266 bool only_root_namespaces) {
1267 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1268 CompilerDeclContext matching_namespace;
1269
1270 ForEachSymbolFile("Looking up namespace", [&](SymbolFileDWARF &oso_dwarf) {
1271 matching_namespace =
1272 oso_dwarf.FindNamespace(name, parent_decl_ctx, only_root_namespaces);
1273
1274 return matching_namespace ? IterationAction::Stop
1276 });
1277
1278 return matching_namespace;
1279}
1280
1281void SymbolFileDWARFDebugMap::DumpClangAST(Stream &s, llvm::StringRef filter,
1282 bool show_color) {
1283 ForEachSymbolFile("Dumping clang AST", [&](SymbolFileDWARF &oso_dwarf) {
1284 oso_dwarf.DumpClangAST(s, filter, show_color);
1285 // The underlying assumption is that DumpClangAST(...) will obtain the
1286 // AST from the underlying TypeSystem and therefore we only need to do
1287 // this once and can stop after the first iteration hence we return true.
1288 return IterationAction::Stop;
1289 });
1290}
1291
1293 lldb_private::StructuredData::Dictionary &d, bool errors_only,
1294 bool load_all_debug_info) {
1295 StructuredData::Array separate_debug_info_files;
1296 const uint32_t cu_count = GetNumCompileUnits();
1297 for (uint32_t cu_idx = 0; cu_idx < cu_count; ++cu_idx) {
1298 const auto &info = m_compile_unit_infos[cu_idx];
1300 std::make_shared<StructuredData::Dictionary>();
1301 oso_data->AddStringItem("so_file", info.so_file.GetPath());
1302 oso_data->AddStringItem("oso_path", info.oso_path);
1303 oso_data->AddIntegerItem("oso_mod_time",
1304 (uint32_t)llvm::sys::toTimeT(info.oso_mod_time));
1305
1306 bool loaded_successfully = false;
1307 if (GetModuleByOSOIndex(cu_idx)) {
1308 // If we have a valid pointer to the module, we successfully
1309 // loaded the oso if there are no load errors.
1310 if (!info.oso_load_error.Fail()) {
1311 loaded_successfully = true;
1312 }
1313 }
1314 if (!loaded_successfully) {
1315 oso_data->AddStringItem("error", info.oso_load_error.AsCString());
1316 }
1317 oso_data->AddBooleanItem("loaded", loaded_successfully);
1318 if (!errors_only || oso_data->HasKey("error"))
1319 separate_debug_info_files.AddItem(oso_data);
1320 }
1321
1322 d.AddStringItem("type", "oso");
1323 d.AddStringItem("symfile", GetMainObjectFile()->GetFileSpec().GetPath());
1324 d.AddItem("separate-debug-info-files",
1325 std::make_shared<StructuredData::Array>(
1326 std::move(separate_debug_info_files)));
1327 return true;
1328}
1329
1332 DWARFCompileUnit &dwarf_cu) {
1333 if (oso_dwarf) {
1334 const uint32_t cu_count = GetNumCompileUnits();
1335 for (uint32_t cu_idx = 0; cu_idx < cu_count; ++cu_idx) {
1336 SymbolFileDWARF *oso_symfile =
1338 if (oso_symfile == oso_dwarf) {
1339 if (m_compile_unit_infos[cu_idx].compile_units_sps.empty())
1341
1342 auto &id_to_index_map = m_compile_unit_infos[cu_idx].id_to_index_map;
1343 auto it = id_to_index_map.find(dwarf_cu.GetID());
1344 if (it != id_to_index_map.end())
1345 return m_compile_unit_infos[cu_idx]
1346 .compile_units_sps[it->getSecond()];
1347 }
1348 }
1349 }
1350 llvm_unreachable("this shouldn't happen");
1351}
1352
1355 if (oso_dwarf) {
1356 const uint32_t cu_count = GetNumCompileUnits();
1357 for (uint32_t cu_idx = 0; cu_idx < cu_count; ++cu_idx) {
1358 SymbolFileDWARF *oso_symfile =
1360 if (oso_symfile == oso_dwarf) {
1361 return &m_compile_unit_infos[cu_idx];
1362 }
1363 }
1364 }
1365 return nullptr;
1366}
1367
1369 const CompUnitSP &cu_sp) {
1370 if (oso_dwarf) {
1371 const uint32_t cu_count = GetNumCompileUnits();
1372 for (uint32_t cu_idx = 0; cu_idx < cu_count; ++cu_idx) {
1373 SymbolFileDWARF *oso_symfile =
1375 if (oso_symfile == oso_dwarf) {
1376 if (!m_compile_unit_infos[cu_idx].compile_units_sps.empty()) {
1377 assert(m_compile_unit_infos[cu_idx].compile_units_sps[0].get() ==
1378 cu_sp.get());
1379 } else {
1380 assert(cu_sp->GetID() == 0 &&
1381 "Setting first compile unit but with id different than 0!");
1382 auto &compile_units_sps =
1383 m_compile_unit_infos[cu_idx].compile_units_sps;
1384 compile_units_sps.push_back(cu_sp);
1385 m_compile_unit_infos[cu_idx].id_to_index_map.insert(
1386 {cu_sp->GetID(), compile_units_sps.size() - 1});
1387
1388 SetCompileUnitAtIndex(cu_idx, cu_sp);
1389 }
1390 }
1391 }
1392 }
1393}
1394
1397 const uint64_t oso_idx = GetOSOIndexFromUserID(type_uid);
1398 if (SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex(oso_idx))
1399 return oso_dwarf->GetDeclContextForUID(type_uid);
1400 return {};
1401}
1402
1405 const uint64_t oso_idx = GetOSOIndexFromUserID(type_uid);
1406 if (SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex(oso_idx))
1407 return oso_dwarf->GetDeclContextContainingUID(type_uid);
1408 return {};
1409}
1410
1411std::vector<CompilerContext>
1413 const uint64_t oso_idx = GetOSOIndexFromUserID(type_uid);
1414 if (SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex(oso_idx))
1415 return oso_dwarf->GetCompilerContextForUID(type_uid);
1416 return {};
1417}
1418
1421 ForEachSymbolFile("Parsing declarations", [&](SymbolFileDWARF &oso_dwarf) {
1422 oso_dwarf.ParseDeclsForContext(decl_ctx);
1424 });
1425}
1426
1428 lldb::addr_t exe_file_addr,
1429 lldb::addr_t exe_byte_size,
1430 lldb::addr_t oso_file_addr,
1431 lldb::addr_t oso_byte_size) {
1432 const uint32_t debug_map_idx =
1433 m_debug_map.FindEntryIndexThatContains(exe_file_addr);
1434 if (debug_map_idx != UINT32_MAX) {
1435 DebugMap::Entry *debug_map_entry =
1436 m_debug_map.FindEntryThatContains(exe_file_addr);
1437 debug_map_entry->data.SetOSOFileAddress(oso_file_addr);
1438 addr_t range_size = std::min<addr_t>(exe_byte_size, oso_byte_size);
1439 if (range_size == 0) {
1440 range_size = std::max<addr_t>(exe_byte_size, oso_byte_size);
1441 if (range_size == 0)
1442 range_size = 1;
1443 }
1444 cu_info->file_range_map.Append(
1445 FileRangeMap::Entry(oso_file_addr, range_size, exe_file_addr));
1446 return true;
1447 }
1448 return false;
1449}
1450
1452 cu_info->file_range_map.Sort();
1453#if defined(DEBUG_OSO_DMAP)
1454 const FileRangeMap &oso_file_range_map = cu_info->GetFileRangeMap(this);
1455 const size_t n = oso_file_range_map.GetSize();
1456 printf("SymbolFileDWARFDebugMap::FinalizeOSOFileRanges (cu_info = %p) %s\n",
1457 cu_info, cu_info->oso_sp->module_sp->GetFileSpec().GetPath().c_str());
1458 for (size_t i = 0; i < n; ++i) {
1459 const FileRangeMap::Entry &entry = oso_file_range_map.GetEntryRef(i);
1460 printf("oso [0x%16.16" PRIx64 " - 0x%16.16" PRIx64
1461 ") ==> exe [0x%16.16" PRIx64 " - 0x%16.16" PRIx64 ")\n",
1462 entry.GetRangeBase(), entry.GetRangeEnd(), entry.data,
1463 entry.data + entry.GetByteSize());
1464 }
1465#endif
1466}
1467
1470 lldb::addr_t oso_file_addr) {
1471 CompileUnitInfo *cu_info = GetCompileUnitInfo(oso_symfile);
1472 if (cu_info) {
1473 const FileRangeMap::Entry *oso_range_entry =
1474 cu_info->GetFileRangeMap(this).FindEntryThatContains(oso_file_addr);
1475 if (oso_range_entry) {
1476 const DebugMap::Entry *debug_map_entry =
1477 m_debug_map.FindEntryThatContains(oso_range_entry->data);
1478 if (debug_map_entry) {
1479 const lldb::addr_t offset =
1480 oso_file_addr - oso_range_entry->GetRangeBase();
1481 const lldb::addr_t exe_file_addr =
1482 debug_map_entry->GetRangeBase() + offset;
1483 return exe_file_addr;
1484 }
1485 }
1486 }
1487 return LLDB_INVALID_ADDRESS;
1488}
1489
1491 // Make sure this address hasn't been fixed already
1492 Module *exe_module = GetObjectFile()->GetModule().get();
1493 Module *addr_module = addr.GetModule().get();
1494 if (addr_module == exe_module)
1495 return true; // Address is already in terms of the main executable module
1496
1499 if (cu_info) {
1500 const lldb::addr_t oso_file_addr = addr.GetFileAddress();
1501 const FileRangeMap::Entry *oso_range_entry =
1502 cu_info->GetFileRangeMap(this).FindEntryThatContains(oso_file_addr);
1503 if (oso_range_entry) {
1504 const DebugMap::Entry *debug_map_entry =
1505 m_debug_map.FindEntryThatContains(oso_range_entry->data);
1506 if (debug_map_entry) {
1507 const lldb::addr_t offset =
1508 oso_file_addr - oso_range_entry->GetRangeBase();
1509 const lldb::addr_t exe_file_addr =
1510 debug_map_entry->GetRangeBase() + offset;
1511 return exe_module->ResolveFileAddress(exe_file_addr, addr);
1512 }
1513 }
1514 }
1515 return true;
1516}
1517
1519 LineTable *line_table) {
1520 CompileUnitInfo *cu_info = GetCompileUnitInfo(oso_dwarf);
1521 if (cu_info)
1522 return line_table->LinkLineTable(cu_info->GetFileRangeMap(this));
1523 return nullptr;
1524}
1525
1526size_t
1528 DWARFDebugAranges *debug_aranges) {
1529 size_t num_line_entries_added = 0;
1530 if (debug_aranges && dwarf2Data) {
1531 CompileUnitInfo *compile_unit_info = GetCompileUnitInfo(dwarf2Data);
1532 if (compile_unit_info) {
1533 const FileRangeMap &file_range_map =
1534 compile_unit_info->GetFileRangeMap(this);
1535 for (size_t idx = 0; idx < file_range_map.GetSize(); idx++) {
1536 const FileRangeMap::Entry *entry = file_range_map.GetEntryAtIndex(idx);
1537 if (entry) {
1538 debug_aranges->AppendRange(*dwarf2Data->GetFileIndex(),
1539 entry->GetRangeBase(),
1540 entry->GetRangeEnd());
1541 num_line_entries_added++;
1542 }
1543 }
1544 }
1545 }
1546 return num_line_entries_added;
1547}
1548
1550 ModuleList oso_modules;
1551 ForEachSymbolFile("Parsing modules", [&](SymbolFileDWARF &oso_dwarf) {
1552 ObjectFile *oso_objfile = oso_dwarf.GetObjectFile();
1553 if (oso_objfile) {
1554 ModuleSP module_sp = oso_objfile->GetModule();
1555 if (module_sp)
1556 oso_modules.Append(module_sp);
1557 }
1559 });
1560 return oso_modules;
1561}
1562
1564 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1565
1566 // We need to make sure that our PC value from the frame matches the module
1567 // for this object file since we will lookup the PC file address in the debug
1568 // map below.
1569 Address pc_addr = frame.GetFrameCodeAddress();
1570 if (pc_addr.GetModule() == m_objfile_sp->GetModule()) {
1571 Symtab *symtab = m_objfile_sp->GetSymtab();
1572 if (symtab) {
1573 const DebugMap::Entry *debug_map_entry =
1574 m_debug_map.FindEntryThatContains(pc_addr.GetFileAddress());
1575 if (debug_map_entry) {
1576 const Symbol *symbol =
1577 symtab->SymbolAtIndex(debug_map_entry->data.GetExeSymbolIndex());
1578 if (symbol) {
1579 uint32_t oso_idx = 0;
1580 CompileUnitInfo *comp_unit_info =
1581 GetCompileUnitInfoForSymbolWithID(symbol->GetID(), &oso_idx);
1582 if (comp_unit_info) {
1583 Module *oso_module = GetModuleByCompUnitInfo(comp_unit_info);
1584 if (oso_module) {
1585 // Check the .o file's DWARF in case it has an error to display.
1586 SymbolFile *oso_sym_file = oso_module->GetSymbolFile();
1587 if (oso_sym_file)
1588 return oso_sym_file->GetFrameVariableError(frame);
1589 }
1590 // If we don't have a valid OSO module here, then something went
1591 // wrong as we have a symbol for the address in the debug map, but
1592 // we weren't able to open the .o file. Display an appropriate
1593 // error
1594 if (comp_unit_info->oso_load_error.Fail())
1595 return comp_unit_info->oso_load_error.Clone();
1596 else
1598 "unable to load debug map object file \"%s\" "
1599 "exist, debug info will not be loaded",
1600 comp_unit_info->oso_path.GetCString());
1601 }
1602 }
1603 }
1604 }
1605 }
1606 return Status();
1607}
1608
1610 std::unordered_map<lldb::CompUnitSP, lldb_private::Args> &args) {
1611
1612 ForEachSymbolFile("Parsing compile options", [&](SymbolFileDWARF &oso_dwarf) {
1613 oso_dwarf.GetCompileOptions(args);
1615 });
1616}
1617
1618llvm::Expected<SymbolContext>
1620 const uint64_t oso_idx = GetOSOIndexFromUserID(label.symbol_id);
1621 SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex(oso_idx);
1622 if (!oso_dwarf)
1623 return llvm::createStringErrorV(
1624 "couldn't find symbol file for {0} in debug-map.", label);
1625
1626 return oso_dwarf->ResolveFunctionCallLabel(label);
1627}
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
Definition Log.h:369
#define LLDB_LOGF(log,...)
Definition Log.h:383
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:432
lldb::ModuleSP GetModule() const
Get accessor for the module for this address.
Definition Address.cpp:273
lldb::addr_t GetFileAddress() const
Get the file address.
Definition Address.cpp:281
An architecture specification class.
Definition ArchSpec.h:32
bool SetTriple(const llvm::Triple &triple)
Architecture triple setter.
Definition ArchSpec.cpp:739
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
const char * AsCString(const char *value_if_empty=nullptr) const
Get the string value as a C string.
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:57
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:301
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
Definition FileSpec.cpp:374
static FileSystem & Instance()
A class that describes a function.
Definition Function.h:400
const Address & GetAddress() const
Return the address of the function (its entry point).
Definition Function.h:453
CompileUnit * GetCompileUnit()
Get accessor for the compile unit that owns this function.
Definition Function.cpp:398
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.
A class that encapsulates name lookup information.
Definition Module.h:912
ConstString GetLookupName() const
Definition Module.h:951
A class that describes an executable image and its associated object and symbol files.
Definition Module.h:90
virtual ObjectFile * GetObjectFile()
Get the object file representation for the current architecture.
Definition Module.cpp:1184
virtual SymbolFile * GetSymbolFile(bool can_create=true, Stream *feedback_strm=nullptr)
Get the module's symbol file.
Definition Module.cpp:984
std::recursive_mutex m_mutex
A mutex to keep this object happy in multi-threaded environments.
Definition Module.h:1026
bool ResolveFileAddress(lldb::addr_t vm_addr, Address &so_addr)
Definition Module.cpp:431
lldb::SymbolVendorUP m_symfile_up
A pointer to the symbol vendor for this module.
Definition Module.h:1063
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:234
friend class ObjectFile
Definition Module.h:1121
std::string GetSpecificationDescription() const
Get the module path and object name.
Definition Module.cpp:1028
const FileSpec & GetFileSpec() const
Get const accessor for the module file specification.
Definition Module.h:446
friend class SymbolFile
Definition Module.h:1122
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:570
lldb::ObjectFileSP m_objfile_sp
Definition SymbolFile.h:646
ObjectFile * GetMainObjectFile() override
void SetCompileUnitAtIndex(uint32_t idx, const lldb::CompUnitSP &cu_sp)
SymbolFileCommon(lldb::ObjectFileSP objfile_sp)
Definition SymbolFile.h:555
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:520
uint32_t GetSiblingIndex() const
Definition Symbol.cpp:217
uint64_t GetIntegerValue(uint64_t fail_value=0) const
Definition Symbol.h:118
uint32_t GetID() const
Definition Symbol.h:137
bool ValueIsAddress() const
Definition Symbol.cpp:165
bool IsDebug() const
Definition Symbol.h:193
Mangled & GetMangled()
Definition Symbol.h:147
Address & GetAddressRef()
Definition Symbol.h:73
lldb::addr_t GetByteSize() const
Definition Symbol.cpp:431
ConstString GetName() const
Definition Symbol.cpp:511
lldb::SymbolType GetType() const
Definition Symbol.h:169
Symbol * SymbolAtIndex(size_t idx)
Definition Symtab.cpp:228
Symbol * FindFirstSymbolWithNameAndType(ConstString name, lldb::SymbolType symbol_type, Debug symbol_debug_type, Visibility symbol_visibility)
Definition Symtab.cpp:867
void SortSymbolIndexesByValue(std::vector< uint32_t > &indexes, bool remove_duplicates) const
Definition Symtab.cpp:625
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:499
uint32_t GetIndexForSymbol(const Symbol *symbol) const
Definition Symtab.cpp:560
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:517
const Symbol * GetParent(Symbol *symbol) const
Get the parent symbol for the given symbol.
Definition Symtab.cpp:1153
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:200
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)
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
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
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:332
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:82
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)