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 // User zero as the ID to match the compile unit at offset zero in each
604 // .o file.
605 lldb::user_id_t cu_id = 0;
606 cu_info.compile_units_sps.push_back(std::make_shared<CompileUnit>(
607 m_objfile_sp->GetModule(), nullptr,
608 std::make_shared<SupportFile>(so_file_spec), cu_id,
610 cu_info.id_to_index_map.insert({0, 0});
611 SetCompileUnitAtIndex(cu_idx, cu_info.compile_units_sps[0]);
612 // If there's a symbol file also register all the extra compile units.
613 if (SymbolFileDWARF *oso_symfile =
614 GetSymbolFileByCompUnitInfo(&cu_info)) {
615 auto num_dwarf_units = oso_symfile->DebugInfo().GetNumUnits();
616 for (size_t i = 0; i < num_dwarf_units; ++i) {
617 auto *dwarf_unit = oso_symfile->DebugInfo().GetUnitAtIndex(i);
618 if (auto *dwarf_cu = llvm::dyn_cast<DWARFCompileUnit>(dwarf_unit)) {
619 // The "main" one was already registered.
620 if (dwarf_cu->GetID() == 0)
621 continue;
622 cu_info.compile_units_sps.push_back(std::make_shared<CompileUnit>(
623 m_objfile_sp->GetModule(), nullptr,
624 std::make_shared<SupportFile>(so_file_spec),
625 dwarf_cu->GetID(), eLanguageTypeUnknown, eLazyBoolCalculate));
626 cu_info.id_to_index_map.insert(
627 {dwarf_cu->GetID(), cu_info.compile_units_sps.size() - 1});
628 }
629 }
630 }
631 }
632 }
633 if (!cu_info.compile_units_sps.empty())
634 comp_unit_sp = cu_info.compile_units_sps[0];
635 }
636
637 return comp_unit_sp;
638}
639
644
647 const uint32_t cu_count = GetNumCompileUnits();
648 for (uint32_t i = 0; i < cu_count; ++i) {
649 auto &id_to_index_map = m_compile_unit_infos[i].id_to_index_map;
650
651 auto it = id_to_index_map.find(comp_unit.GetID());
652 if (it != id_to_index_map.end() &&
653 &comp_unit ==
654 m_compile_unit_infos[i].compile_units_sps[it->getSecond()].get())
655 return &m_compile_unit_infos[i];
656 }
657 return nullptr;
658}
659
661 const lldb_private::Module *module,
662 std::vector<CompileUnitInfo *> &cu_infos) {
663 const uint32_t cu_count = GetNumCompileUnits();
664 for (uint32_t i = 0; i < cu_count; ++i) {
666 cu_infos.push_back(&m_compile_unit_infos[i]);
667 }
668 return cu_infos.size();
669}
670
673 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
674 SymbolFileDWARF *oso_dwarf = GetSymbolFile(comp_unit);
675 if (oso_dwarf)
676 return oso_dwarf->ParseLanguage(comp_unit);
678}
679
681 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
682 SymbolFileDWARF *oso_dwarf = GetSymbolFile(comp_unit);
683 if (oso_dwarf)
684 return oso_dwarf->ParseXcodeSDK(comp_unit);
685 return {};
686}
687
688llvm::SmallSet<lldb::LanguageType, 4>
690 lldb_private::CompileUnit &comp_unit) {
691 llvm::SmallSet<lldb::LanguageType, 4> langs;
692 auto *info = GetCompUnitInfo(comp_unit);
693 for (auto &comp_unit : info->compile_units_sps) {
694 langs.insert(comp_unit->GetLanguage());
695 }
696 return langs;
697}
698
700 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
701 SymbolFileDWARF *oso_dwarf = GetSymbolFile(comp_unit);
702 if (oso_dwarf)
703 return oso_dwarf->ParseFunctions(comp_unit);
704 return 0;
705}
706
708 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
709 SymbolFileDWARF *oso_dwarf = GetSymbolFile(comp_unit);
710 if (oso_dwarf)
711 return oso_dwarf->ParseLineTable(comp_unit);
712 return false;
713}
714
716 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
717 SymbolFileDWARF *oso_dwarf = GetSymbolFile(comp_unit);
718 if (oso_dwarf)
719 return oso_dwarf->ParseDebugMacros(comp_unit);
720 return false;
721}
722
724 std::string description,
725 std::function<IterationAction(SymbolFileDWARF &)> closure) {
726 const size_t num_oso_idxs = m_compile_unit_infos.size();
727 Progress progress(std::move(description), "", num_oso_idxs,
728 /*debugger=*/nullptr,
730 for (uint32_t oso_idx = 0; oso_idx < num_oso_idxs; ++oso_idx) {
731 if (SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex(oso_idx)) {
732 progress.Increment(oso_idx, oso_dwarf->GetObjectName());
733 if (closure(*oso_dwarf) == IterationAction::Stop)
734 return;
735 }
736 }
737}
738
740 CompileUnit &comp_unit,
741 llvm::DenseSet<lldb_private::SymbolFile *> &visited_symbol_files,
742 llvm::function_ref<bool(Module &)> f) {
743 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
744 SymbolFileDWARF *oso_dwarf = GetSymbolFile(comp_unit);
745 if (oso_dwarf)
746 return oso_dwarf->ForEachExternalModule(comp_unit, visited_symbol_files, f);
747 return false;
748}
749
751 CompileUnit &comp_unit, SupportFileList &support_files) {
752 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
753 SymbolFileDWARF *oso_dwarf = GetSymbolFile(comp_unit);
754 if (oso_dwarf)
755 return oso_dwarf->ParseSupportFiles(comp_unit, support_files);
756 return false;
757}
758
760 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
761 SymbolFileDWARF *oso_dwarf = GetSymbolFile(comp_unit);
762 if (oso_dwarf)
763 return oso_dwarf->ParseIsOptimized(comp_unit);
764 return false;
765}
766
768 const SymbolContext &sc, std::vector<SourceModule> &imported_modules) {
769 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
770 SymbolFileDWARF *oso_dwarf = GetSymbolFile(sc);
771 if (oso_dwarf)
772 return oso_dwarf->ParseImportedModules(sc, imported_modules);
773 return false;
774}
775
777 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
778 CompileUnit *comp_unit = func.GetCompileUnit();
779 if (!comp_unit)
780 return 0;
781
782 SymbolFileDWARF *oso_dwarf = GetSymbolFile(*comp_unit);
783 if (oso_dwarf)
784 return oso_dwarf->ParseBlocksRecursive(func);
785 return 0;
786}
787
789 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
790 SymbolFileDWARF *oso_dwarf = GetSymbolFile(comp_unit);
791 if (oso_dwarf)
792 return oso_dwarf->ParseTypes(comp_unit);
793 return 0;
794}
795
796size_t
798 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
799 SymbolFileDWARF *oso_dwarf = GetSymbolFile(sc);
800 if (oso_dwarf)
801 return oso_dwarf->ParseVariablesForContext(sc);
802 return 0;
803}
804
806 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
807 const uint64_t oso_idx = GetOSOIndexFromUserID(type_uid);
808 SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex(oso_idx);
809 if (oso_dwarf)
810 return oso_dwarf->ResolveTypeUID(type_uid);
811 return nullptr;
812}
813
814std::optional<SymbolFile::ArrayInfo>
816 lldb::user_id_t type_uid, const lldb_private::ExecutionContext *exe_ctx) {
817 const uint64_t oso_idx = GetOSOIndexFromUserID(type_uid);
818 SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex(oso_idx);
819 if (oso_dwarf)
820 return oso_dwarf->GetDynamicArrayInfoForUID(type_uid, exe_ctx);
821 return std::nullopt;
822}
823
825 bool success = false;
826 if (compiler_type) {
827 ForEachSymbolFile("Completing type", [&](SymbolFileDWARF &oso_dwarf) {
828 if (oso_dwarf.HasForwardDeclForCompilerType(compiler_type)) {
829 oso_dwarf.CompleteType(compiler_type);
830 success = true;
832 }
834 });
835 }
836 return success;
837}
838
839uint32_t
841 SymbolContextItem resolve_scope,
842 SymbolContext &sc) {
843 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
844 uint32_t resolved_flags = 0;
845 Symtab *symtab = m_objfile_sp->GetSymtab();
846 if (symtab) {
847 const addr_t exe_file_addr = exe_so_addr.GetFileAddress();
848
849 const DebugMap::Entry *debug_map_entry =
850 m_debug_map.FindEntryThatContains(exe_file_addr);
851 if (debug_map_entry) {
852
853 sc.symbol =
854 symtab->SymbolAtIndex(debug_map_entry->data.GetExeSymbolIndex());
855
856 if (sc.symbol != nullptr) {
857 resolved_flags |= eSymbolContextSymbol;
858
859 uint32_t oso_idx = 0;
860 CompileUnitInfo *comp_unit_info =
862 if (comp_unit_info) {
863 comp_unit_info->GetFileRangeMap(this);
864 Module *oso_module = GetModuleByCompUnitInfo(comp_unit_info);
865 if (oso_module) {
866 lldb::addr_t oso_file_addr =
867 exe_file_addr - debug_map_entry->GetRangeBase() +
868 debug_map_entry->data.GetOSOFileAddress();
869 Address oso_so_addr;
870 if (oso_module->ResolveFileAddress(oso_file_addr, oso_so_addr)) {
871 if (SymbolFile *sym_file = oso_module->GetSymbolFile()) {
872 resolved_flags |= sym_file->ResolveSymbolContext(
873 oso_so_addr, resolve_scope, sc);
874 } else {
875 ObjectFile *obj_file = GetObjectFile();
877 "Failed to get symfile for OSO: {0} in module: {1}",
878 oso_module->GetFileSpec(),
879 obj_file ? obj_file->GetFileSpec()
880 : FileSpec("unknown"));
881 }
882 }
883 }
884 }
885 }
886 }
887 }
888 return resolved_flags;
889}
890
892 const SourceLocationSpec &src_location_spec,
893 SymbolContextItem resolve_scope, SymbolContextList &sc_list) {
894 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
895 const uint32_t initial = sc_list.GetSize();
896 const uint32_t cu_count = GetNumCompileUnits();
897
898 for (uint32_t i = 0; i < cu_count; ++i) {
899 // If we are checking for inlines, then we need to look through all compile
900 // units no matter if "file_spec" matches.
901 bool resolve = src_location_spec.GetCheckInlines();
902
903 if (!resolve) {
904 FileSpec so_file_spec;
905 if (GetFileSpecForSO(i, so_file_spec))
906 resolve =
907 FileSpec::Match(src_location_spec.GetFileSpec(), so_file_spec);
908 }
909 if (resolve) {
911 if (oso_dwarf)
912 oso_dwarf->ResolveSymbolContext(src_location_spec, resolve_scope,
913 sc_list);
914 }
915 }
916 return sc_list.GetSize() - initial;
917}
918
920 ConstString name, const CompilerDeclContext &parent_decl_ctx,
921 const std::vector<uint32_t>
922 &indexes, // Indexes into the symbol table that match "name"
923 uint32_t max_matches, VariableList &variables) {
924 const size_t match_count = indexes.size();
925 for (size_t i = 0; i < match_count; ++i) {
926 uint32_t oso_idx;
927 CompileUnitInfo *comp_unit_info =
928 GetCompileUnitInfoForSymbolWithIndex(indexes[i], &oso_idx);
929 if (comp_unit_info) {
930 SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex(oso_idx);
931 if (oso_dwarf) {
932 oso_dwarf->FindGlobalVariables(name, parent_decl_ctx, max_matches,
933 variables);
934 if (variables.GetSize() > max_matches)
935 break;
936 }
937 }
938 }
939}
940
942 ConstString name, const CompilerDeclContext &parent_decl_ctx,
943 uint32_t max_matches, VariableList &variables) {
944 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
945 uint32_t total_matches = 0;
946
948 "Looking up global variables", [&](SymbolFileDWARF &oso_dwarf) {
949 const uint32_t old_size = variables.GetSize();
950 oso_dwarf.FindGlobalVariables(name, parent_decl_ctx, max_matches,
951 variables);
952 const uint32_t oso_matches = variables.GetSize() - old_size;
953 if (oso_matches > 0) {
954 total_matches += oso_matches;
955
956 // If we are getting all matches, keep going.
957 if (max_matches == UINT32_MAX)
959
960 // If we have found enough matches, lets get out
961 if (max_matches >= total_matches)
963
964 // Update the max matches for any subsequent calls to find globals in
965 // any other object files with DWARF
966 max_matches -= oso_matches;
967 }
968
970 });
971}
972
974 const RegularExpression &regex, uint32_t max_matches,
975 VariableList &variables) {
976 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
977 uint32_t total_matches = 0;
979 "Looking up global variables", [&](SymbolFileDWARF &oso_dwarf) {
980 const uint32_t old_size = variables.GetSize();
981 oso_dwarf.FindGlobalVariables(regex, max_matches, variables);
982
983 const uint32_t oso_matches = variables.GetSize() - old_size;
984 if (oso_matches > 0) {
985 total_matches += oso_matches;
986
987 // If we are getting all matches, keep going.
988 if (max_matches == UINT32_MAX)
990
991 // If we have found enough matches, lets get out
992 if (max_matches >= total_matches)
994
995 // Update the max matches for any subsequent calls to find globals in
996 // any other object files with DWARF
997 max_matches -= oso_matches;
998 }
999
1001 });
1002}
1003
1005 uint32_t *symbol_idx_ptr, const CompileUnitInfo *comp_unit_info) {
1006 const uint32_t symbol_idx = *symbol_idx_ptr;
1007
1008 if (symbol_idx < comp_unit_info->first_symbol_index)
1009 return -1;
1010
1011 if (symbol_idx <= comp_unit_info->last_symbol_index)
1012 return 0;
1013
1014 return 1;
1015}
1016
1018 user_id_t *symbol_idx_ptr, const CompileUnitInfo *comp_unit_info) {
1019 const user_id_t symbol_id = *symbol_idx_ptr;
1020
1021 if (symbol_id < comp_unit_info->first_symbol_id)
1022 return -1;
1023
1024 if (symbol_id <= comp_unit_info->last_symbol_id)
1025 return 0;
1026
1027 return 1;
1028}
1029
1032 uint32_t symbol_idx, uint32_t *oso_idx_ptr) {
1033 const uint32_t oso_index_count = m_compile_unit_infos.size();
1034 CompileUnitInfo *comp_unit_info = nullptr;
1035 if (oso_index_count) {
1036 comp_unit_info = (CompileUnitInfo *)bsearch(
1037 &symbol_idx, &m_compile_unit_infos[0], m_compile_unit_infos.size(),
1038 sizeof(CompileUnitInfo),
1040 }
1041
1042 if (oso_idx_ptr) {
1043 if (comp_unit_info != nullptr)
1044 *oso_idx_ptr = comp_unit_info - &m_compile_unit_infos[0];
1045 else
1046 *oso_idx_ptr = UINT32_MAX;
1047 }
1048 return comp_unit_info;
1049}
1050
1053 user_id_t symbol_id, uint32_t *oso_idx_ptr) {
1054 const uint32_t oso_index_count = m_compile_unit_infos.size();
1055 CompileUnitInfo *comp_unit_info = nullptr;
1056 if (oso_index_count) {
1057 comp_unit_info = (CompileUnitInfo *)::bsearch(
1058 &symbol_id, &m_compile_unit_infos[0], m_compile_unit_infos.size(),
1059 sizeof(CompileUnitInfo),
1061 }
1062
1063 if (oso_idx_ptr) {
1064 if (comp_unit_info != nullptr)
1065 *oso_idx_ptr = comp_unit_info - &m_compile_unit_infos[0];
1066 else
1067 *oso_idx_ptr = UINT32_MAX;
1068 }
1069 return comp_unit_info;
1070}
1071
1073 SymbolContextList &sc_list,
1074 uint32_t start_idx) {
1075 // We found functions in .o files. Not all functions in the .o files will
1076 // have made it into the final output file. The ones that did make it into
1077 // the final output file will have a section whose module matches the module
1078 // from the ObjectFile for this SymbolFile. When the modules don't match,
1079 // then we have something that was in a .o file, but doesn't map to anything
1080 // in the final executable.
1081 uint32_t i = start_idx;
1082 while (i < sc_list.GetSize()) {
1083 SymbolContext sc;
1084 sc_list.GetContextAtIndex(i, sc);
1085 if (sc.function) {
1086 const SectionSP section_sp = sc.function->GetAddress().GetSection();
1087 if (section_sp->GetModule() != module_sp) {
1088 sc_list.RemoveContextAtIndex(i);
1089 continue;
1090 }
1091 }
1092 ++i;
1093 }
1094}
1095
1097 const Module::LookupInfo &lookup_info,
1098 const CompilerDeclContext &parent_decl_ctx, bool include_inlines,
1099 SymbolContextList &sc_list) {
1100 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1101 LLDB_SCOPED_TIMERF("SymbolFileDWARFDebugMap::FindFunctions (name = %s)",
1102 lookup_info.GetLookupName().GetCString());
1103
1104 ForEachSymbolFile("Looking up functions", [&](SymbolFileDWARF &oso_dwarf) {
1105 uint32_t sc_idx = sc_list.GetSize();
1106 oso_dwarf.FindFunctions(lookup_info, parent_decl_ctx, include_inlines,
1107 sc_list);
1108 if (!sc_list.IsEmpty()) {
1110 sc_idx);
1111 }
1113 });
1114}
1115
1117 bool include_inlines,
1118 SymbolContextList &sc_list) {
1119 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1120 LLDB_SCOPED_TIMERF("SymbolFileDWARFDebugMap::FindFunctions (regex = '%s')",
1121 regex.GetText().str().c_str());
1122
1123 ForEachSymbolFile("Looking up functions", [&](SymbolFileDWARF &oso_dwarf) {
1124 uint32_t sc_idx = sc_list.GetSize();
1125
1126 oso_dwarf.FindFunctions(regex, include_inlines, sc_list);
1127 if (!sc_list.IsEmpty()) {
1129 sc_idx);
1130 }
1132 });
1133}
1134
1136 lldb::TypeClass type_mask,
1137 TypeList &type_list) {
1138 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1139 LLDB_SCOPED_TIMERF("SymbolFileDWARFDebugMap::GetTypes (type_mask = 0x%8.8x)",
1140 type_mask);
1141
1142 SymbolFileDWARF *oso_dwarf = nullptr;
1143 if (sc_scope) {
1144 SymbolContext sc;
1145 sc_scope->CalculateSymbolContext(&sc);
1146
1147 CompileUnitInfo *cu_info = GetCompUnitInfo(sc);
1148 if (cu_info) {
1149 oso_dwarf = GetSymbolFileByCompUnitInfo(cu_info);
1150 if (oso_dwarf)
1151 oso_dwarf->GetTypes(sc_scope, type_mask, type_list);
1152 }
1153 } else {
1154 ForEachSymbolFile("Looking up types", [&](SymbolFileDWARF &oso_dwarf) {
1155 oso_dwarf.GetTypes(sc_scope, type_mask, type_list);
1157 });
1158 }
1159}
1160
1161std::vector<std::unique_ptr<lldb_private::CallEdge>>
1163 lldb_private::UserID func_id) {
1164 uint32_t oso_idx = GetOSOIndexFromUserID(func_id.GetID());
1165 SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex(oso_idx);
1166 if (oso_dwarf)
1167 return oso_dwarf->ParseCallEdgesInFunction(func_id);
1168 return {};
1169}
1170
1172 DWARFDIE result;
1174 "Looking up type definition", [&](SymbolFileDWARF &oso_dwarf) {
1175 result = oso_dwarf.FindDefinitionDIE(die);
1177 });
1178 return result;
1179}
1180
1182 const DWARFDIE &die, ConstString type_name, bool must_be_implementation) {
1183 // If we have a debug map, we will have an Objective-C symbol whose name is
1184 // the type name and whose type is eSymbolTypeObjCClass. If we can find that
1185 // symbol and find its containing parent, we can locate the .o file that will
1186 // contain the implementation definition since it will be scoped inside the
1187 // N_SO and we can then locate the SymbolFileDWARF that corresponds to that
1188 // N_SO.
1189 SymbolFileDWARF *oso_dwarf = nullptr;
1190 TypeSP type_sp;
1191 ObjectFile *module_objfile = m_objfile_sp->GetModule()->GetObjectFile();
1192 if (module_objfile) {
1193 Symtab *symtab = module_objfile->GetSymtab();
1194 if (symtab) {
1195 Symbol *objc_class_symbol = symtab->FindFirstSymbolWithNameAndType(
1198 if (objc_class_symbol) {
1199 // Get the N_SO symbol that contains the objective C class symbol as
1200 // this should be the .o file that contains the real definition...
1201 const Symbol *source_file_symbol = symtab->GetParent(objc_class_symbol);
1202
1203 if (source_file_symbol &&
1204 source_file_symbol->GetType() == eSymbolTypeSourceFile) {
1205 const uint32_t source_file_symbol_idx =
1206 symtab->GetIndexForSymbol(source_file_symbol);
1207 if (source_file_symbol_idx != UINT32_MAX) {
1208 CompileUnitInfo *compile_unit_info =
1209 GetCompileUnitInfoForSymbolWithIndex(source_file_symbol_idx,
1210 nullptr);
1211 if (compile_unit_info) {
1212 oso_dwarf = GetSymbolFileByCompUnitInfo(compile_unit_info);
1213 if (oso_dwarf) {
1215 die, type_name, must_be_implementation));
1216 if (type_sp) {
1217 return type_sp;
1218 }
1219 }
1220 }
1221 }
1222 }
1223 }
1224 }
1225 }
1226
1227 // Only search all .o files for the definition if we don't need the
1228 // implementation because otherwise, with a valid debug map we should have
1229 // the ObjC class symbol and the code above should have found it.
1230 if (!must_be_implementation) {
1231 TypeSP type_sp;
1232
1234 "Looking up Objective-C definition", [&](SymbolFileDWARF &oso_dwarf) {
1235 type_sp = oso_dwarf.FindCompleteObjCDefinitionTypeForDIE(
1236 die, type_name, must_be_implementation);
1238 });
1239
1240 return type_sp;
1241 }
1242 return TypeSP();
1243}
1244
1246 TypeResults &results) {
1247 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1248 ForEachSymbolFile("Looking up type", [&](SymbolFileDWARF &oso_dwarf) {
1249 oso_dwarf.FindTypes(query, results);
1250 return results.Done(query) ? IterationAction::Stop
1252 });
1253}
1254
1256 lldb_private::ConstString name, const CompilerDeclContext &parent_decl_ctx,
1257 bool only_root_namespaces) {
1258 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1259 CompilerDeclContext matching_namespace;
1260
1261 ForEachSymbolFile("Looking up namespace", [&](SymbolFileDWARF &oso_dwarf) {
1262 matching_namespace =
1263 oso_dwarf.FindNamespace(name, parent_decl_ctx, only_root_namespaces);
1264
1265 return matching_namespace ? IterationAction::Stop
1267 });
1268
1269 return matching_namespace;
1270}
1271
1272void SymbolFileDWARFDebugMap::DumpClangAST(Stream &s, llvm::StringRef filter,
1273 bool show_color) {
1274 ForEachSymbolFile("Dumping clang AST", [&](SymbolFileDWARF &oso_dwarf) {
1275 oso_dwarf.DumpClangAST(s, filter, show_color);
1276 // The underlying assumption is that DumpClangAST(...) will obtain the
1277 // AST from the underlying TypeSystem and therefore we only need to do
1278 // this once and can stop after the first iteration hence we return true.
1279 return IterationAction::Stop;
1280 });
1281}
1282
1284 lldb_private::StructuredData::Dictionary &d, bool errors_only,
1285 bool load_all_debug_info) {
1286 StructuredData::Array separate_debug_info_files;
1287 const uint32_t cu_count = GetNumCompileUnits();
1288 for (uint32_t cu_idx = 0; cu_idx < cu_count; ++cu_idx) {
1289 const auto &info = m_compile_unit_infos[cu_idx];
1291 std::make_shared<StructuredData::Dictionary>();
1292 oso_data->AddStringItem("so_file", info.so_file.GetPath());
1293 oso_data->AddStringItem("oso_path", info.oso_path);
1294 oso_data->AddIntegerItem("oso_mod_time",
1295 (uint32_t)llvm::sys::toTimeT(info.oso_mod_time));
1296
1297 bool loaded_successfully = false;
1298 if (GetModuleByOSOIndex(cu_idx)) {
1299 // If we have a valid pointer to the module, we successfully
1300 // loaded the oso if there are no load errors.
1301 if (!info.oso_load_error.Fail()) {
1302 loaded_successfully = true;
1303 }
1304 }
1305 if (!loaded_successfully) {
1306 oso_data->AddStringItem("error", info.oso_load_error.AsCString());
1307 }
1308 oso_data->AddBooleanItem("loaded", loaded_successfully);
1309 if (!errors_only || oso_data->HasKey("error"))
1310 separate_debug_info_files.AddItem(oso_data);
1311 }
1312
1313 d.AddStringItem("type", "oso");
1314 d.AddStringItem("symfile", GetMainObjectFile()->GetFileSpec().GetPath());
1315 d.AddItem("separate-debug-info-files",
1316 std::make_shared<StructuredData::Array>(
1317 std::move(separate_debug_info_files)));
1318 return true;
1319}
1320
1323 DWARFCompileUnit &dwarf_cu) {
1324 if (oso_dwarf) {
1325 const uint32_t cu_count = GetNumCompileUnits();
1326 for (uint32_t cu_idx = 0; cu_idx < cu_count; ++cu_idx) {
1327 SymbolFileDWARF *oso_symfile =
1329 if (oso_symfile == oso_dwarf) {
1330 if (m_compile_unit_infos[cu_idx].compile_units_sps.empty())
1332
1333 auto &id_to_index_map = m_compile_unit_infos[cu_idx].id_to_index_map;
1334 auto it = id_to_index_map.find(dwarf_cu.GetID());
1335 if (it != id_to_index_map.end())
1336 return m_compile_unit_infos[cu_idx]
1337 .compile_units_sps[it->getSecond()];
1338 }
1339 }
1340 }
1341 llvm_unreachable("this shouldn't happen");
1342}
1343
1346 if (oso_dwarf) {
1347 const uint32_t cu_count = GetNumCompileUnits();
1348 for (uint32_t cu_idx = 0; cu_idx < cu_count; ++cu_idx) {
1349 SymbolFileDWARF *oso_symfile =
1351 if (oso_symfile == oso_dwarf) {
1352 return &m_compile_unit_infos[cu_idx];
1353 }
1354 }
1355 }
1356 return nullptr;
1357}
1358
1360 const CompUnitSP &cu_sp) {
1361 if (oso_dwarf) {
1362 const uint32_t cu_count = GetNumCompileUnits();
1363 for (uint32_t cu_idx = 0; cu_idx < cu_count; ++cu_idx) {
1364 SymbolFileDWARF *oso_symfile =
1366 if (oso_symfile == oso_dwarf) {
1367 if (!m_compile_unit_infos[cu_idx].compile_units_sps.empty()) {
1368 assert(m_compile_unit_infos[cu_idx].compile_units_sps[0].get() ==
1369 cu_sp.get());
1370 } else {
1371 assert(cu_sp->GetID() == 0 &&
1372 "Setting first compile unit but with id different than 0!");
1373 auto &compile_units_sps =
1374 m_compile_unit_infos[cu_idx].compile_units_sps;
1375 compile_units_sps.push_back(cu_sp);
1376 m_compile_unit_infos[cu_idx].id_to_index_map.insert(
1377 {cu_sp->GetID(), compile_units_sps.size() - 1});
1378
1379 SetCompileUnitAtIndex(cu_idx, cu_sp);
1380 }
1381 }
1382 }
1383 }
1384}
1385
1388 const uint64_t oso_idx = GetOSOIndexFromUserID(type_uid);
1389 if (SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex(oso_idx))
1390 return oso_dwarf->GetDeclContextForUID(type_uid);
1391 return {};
1392}
1393
1396 const uint64_t oso_idx = GetOSOIndexFromUserID(type_uid);
1397 if (SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex(oso_idx))
1398 return oso_dwarf->GetDeclContextContainingUID(type_uid);
1399 return {};
1400}
1401
1402std::vector<CompilerContext>
1404 const uint64_t oso_idx = GetOSOIndexFromUserID(type_uid);
1405 if (SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex(oso_idx))
1406 return oso_dwarf->GetCompilerContextForUID(type_uid);
1407 return {};
1408}
1409
1412 ForEachSymbolFile("Parsing declarations", [&](SymbolFileDWARF &oso_dwarf) {
1413 oso_dwarf.ParseDeclsForContext(decl_ctx);
1415 });
1416}
1417
1419 lldb::addr_t exe_file_addr,
1420 lldb::addr_t exe_byte_size,
1421 lldb::addr_t oso_file_addr,
1422 lldb::addr_t oso_byte_size) {
1423 const uint32_t debug_map_idx =
1424 m_debug_map.FindEntryIndexThatContains(exe_file_addr);
1425 if (debug_map_idx != UINT32_MAX) {
1426 DebugMap::Entry *debug_map_entry =
1427 m_debug_map.FindEntryThatContains(exe_file_addr);
1428 debug_map_entry->data.SetOSOFileAddress(oso_file_addr);
1429 addr_t range_size = std::min<addr_t>(exe_byte_size, oso_byte_size);
1430 if (range_size == 0) {
1431 range_size = std::max<addr_t>(exe_byte_size, oso_byte_size);
1432 if (range_size == 0)
1433 range_size = 1;
1434 }
1435 cu_info->file_range_map.Append(
1436 FileRangeMap::Entry(oso_file_addr, range_size, exe_file_addr));
1437 return true;
1438 }
1439 return false;
1440}
1441
1443 cu_info->file_range_map.Sort();
1444#if defined(DEBUG_OSO_DMAP)
1445 const FileRangeMap &oso_file_range_map = cu_info->GetFileRangeMap(this);
1446 const size_t n = oso_file_range_map.GetSize();
1447 printf("SymbolFileDWARFDebugMap::FinalizeOSOFileRanges (cu_info = %p) %s\n",
1448 cu_info, cu_info->oso_sp->module_sp->GetFileSpec().GetPath().c_str());
1449 for (size_t i = 0; i < n; ++i) {
1450 const FileRangeMap::Entry &entry = oso_file_range_map.GetEntryRef(i);
1451 printf("oso [0x%16.16" PRIx64 " - 0x%16.16" PRIx64
1452 ") ==> exe [0x%16.16" PRIx64 " - 0x%16.16" PRIx64 ")\n",
1453 entry.GetRangeBase(), entry.GetRangeEnd(), entry.data,
1454 entry.data + entry.GetByteSize());
1455 }
1456#endif
1457}
1458
1461 lldb::addr_t oso_file_addr) {
1462 CompileUnitInfo *cu_info = GetCompileUnitInfo(oso_symfile);
1463 if (cu_info) {
1464 const FileRangeMap::Entry *oso_range_entry =
1465 cu_info->GetFileRangeMap(this).FindEntryThatContains(oso_file_addr);
1466 if (oso_range_entry) {
1467 const DebugMap::Entry *debug_map_entry =
1468 m_debug_map.FindEntryThatContains(oso_range_entry->data);
1469 if (debug_map_entry) {
1470 const lldb::addr_t offset =
1471 oso_file_addr - oso_range_entry->GetRangeBase();
1472 const lldb::addr_t exe_file_addr =
1473 debug_map_entry->GetRangeBase() + offset;
1474 return exe_file_addr;
1475 }
1476 }
1477 }
1478 return LLDB_INVALID_ADDRESS;
1479}
1480
1482 // Make sure this address hasn't been fixed already
1483 Module *exe_module = GetObjectFile()->GetModule().get();
1484 Module *addr_module = addr.GetModule().get();
1485 if (addr_module == exe_module)
1486 return true; // Address is already in terms of the main executable module
1487
1490 if (cu_info) {
1491 const lldb::addr_t oso_file_addr = addr.GetFileAddress();
1492 const FileRangeMap::Entry *oso_range_entry =
1493 cu_info->GetFileRangeMap(this).FindEntryThatContains(oso_file_addr);
1494 if (oso_range_entry) {
1495 const DebugMap::Entry *debug_map_entry =
1496 m_debug_map.FindEntryThatContains(oso_range_entry->data);
1497 if (debug_map_entry) {
1498 const lldb::addr_t offset =
1499 oso_file_addr - oso_range_entry->GetRangeBase();
1500 const lldb::addr_t exe_file_addr =
1501 debug_map_entry->GetRangeBase() + offset;
1502 return exe_module->ResolveFileAddress(exe_file_addr, addr);
1503 }
1504 }
1505 }
1506 return true;
1507}
1508
1510 LineTable *line_table) {
1511 CompileUnitInfo *cu_info = GetCompileUnitInfo(oso_dwarf);
1512 if (cu_info)
1513 return line_table->LinkLineTable(cu_info->GetFileRangeMap(this));
1514 return nullptr;
1515}
1516
1517size_t
1519 DWARFDebugAranges *debug_aranges) {
1520 size_t num_line_entries_added = 0;
1521 if (debug_aranges && dwarf2Data) {
1522 CompileUnitInfo *compile_unit_info = GetCompileUnitInfo(dwarf2Data);
1523 if (compile_unit_info) {
1524 const FileRangeMap &file_range_map =
1525 compile_unit_info->GetFileRangeMap(this);
1526 for (size_t idx = 0; idx < file_range_map.GetSize(); idx++) {
1527 const FileRangeMap::Entry *entry = file_range_map.GetEntryAtIndex(idx);
1528 if (entry) {
1529 debug_aranges->AppendRange(*dwarf2Data->GetFileIndex(),
1530 entry->GetRangeBase(),
1531 entry->GetRangeEnd());
1532 num_line_entries_added++;
1533 }
1534 }
1535 }
1536 }
1537 return num_line_entries_added;
1538}
1539
1541 ModuleList oso_modules;
1542 ForEachSymbolFile("Parsing modules", [&](SymbolFileDWARF &oso_dwarf) {
1543 ObjectFile *oso_objfile = oso_dwarf.GetObjectFile();
1544 if (oso_objfile) {
1545 ModuleSP module_sp = oso_objfile->GetModule();
1546 if (module_sp)
1547 oso_modules.Append(module_sp);
1548 }
1550 });
1551 return oso_modules;
1552}
1553
1555 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1556
1557 // We need to make sure that our PC value from the frame matches the module
1558 // for this object file since we will lookup the PC file address in the debug
1559 // map below.
1560 Address pc_addr = frame.GetFrameCodeAddress();
1561 if (pc_addr.GetModule() == m_objfile_sp->GetModule()) {
1562 Symtab *symtab = m_objfile_sp->GetSymtab();
1563 if (symtab) {
1564 const DebugMap::Entry *debug_map_entry =
1565 m_debug_map.FindEntryThatContains(pc_addr.GetFileAddress());
1566 if (debug_map_entry) {
1567 const Symbol *symbol =
1568 symtab->SymbolAtIndex(debug_map_entry->data.GetExeSymbolIndex());
1569 if (symbol) {
1570 uint32_t oso_idx = 0;
1571 CompileUnitInfo *comp_unit_info =
1572 GetCompileUnitInfoForSymbolWithID(symbol->GetID(), &oso_idx);
1573 if (comp_unit_info) {
1574 Module *oso_module = GetModuleByCompUnitInfo(comp_unit_info);
1575 if (oso_module) {
1576 // Check the .o file's DWARF in case it has an error to display.
1577 SymbolFile *oso_sym_file = oso_module->GetSymbolFile();
1578 if (oso_sym_file)
1579 return oso_sym_file->GetFrameVariableError(frame);
1580 }
1581 // If we don't have a valid OSO module here, then something went
1582 // wrong as we have a symbol for the address in the debug map, but
1583 // we weren't able to open the .o file. Display an appropriate
1584 // error
1585 if (comp_unit_info->oso_load_error.Fail())
1586 return comp_unit_info->oso_load_error.Clone();
1587 else
1589 "unable to load debug map object file \"%s\" "
1590 "exist, debug info will not be loaded",
1591 comp_unit_info->oso_path.GetCString());
1592 }
1593 }
1594 }
1595 }
1596 }
1597 return Status();
1598}
1599
1601 std::unordered_map<lldb::CompUnitSP, lldb_private::Args> &args) {
1602
1603 ForEachSymbolFile("Parsing compile options", [&](SymbolFileDWARF &oso_dwarf) {
1604 oso_dwarf.GetCompileOptions(args);
1606 });
1607}
1608
1609llvm::Expected<SymbolContext>
1611 const uint64_t oso_idx = GetOSOIndexFromUserID(label.symbol_id);
1612 SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex(oso_idx);
1613 if (!oso_dwarf)
1614 return llvm::createStringErrorV(
1615 "couldn't find symbol file for {0} in debug-map.", label);
1616
1617 return oso_dwarf->ResolveFunctionCallLabel(label);
1618}
#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:376
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:31
bool SetTriple(const llvm::Triple &triple)
Architecture triple setter.
Definition ArchSpec.cpp:741
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
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:101
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:908
ConstString GetLookupName() const
Definition Module.h:947
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:1198
virtual SymbolFile * GetSymbolFile(bool can_create=true, Stream *feedback_strm=nullptr)
Get the module's symbol file.
Definition Module.cpp:998
std::recursive_mutex m_mutex
A mutex to keep this object happy in multi-threaded environments.
Definition Module.h:1022
bool ResolveFileAddress(lldb::addr_t vm_addr, Address &so_addr)
Definition Module.cpp:445
lldb::SymbolVendorUP m_symfile_up
A pointer to the symbol vendor for this module.
Definition Module.h:1059
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:236
friend class ObjectFile
Definition Module.h:1110
std::string GetSpecificationDescription() const
Get the module path and object name.
Definition Module.cpp:1042
const FileSpec & GetFileSpec() const
Get const accessor for the module file specification.
Definition Module.h:446
friend class SymbolFile
Definition Module.h:1111
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:282
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:294
const char * AsCString(const char *default_error_str="unknown error") const
Get the error string associated with the current error.
Definition Status.cpp:195
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)