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