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 ReportMissingOSOs(*comp_unit_info);
455 return nullptr;
456 }
457 }
458 // Always create a new module for .o files. Why? Because we use the debug
459 // map, to add new sections to each .o file and even though a .o file
460 // might not have changed, the sections that get added to the .o file can
461 // change.
462 ArchSpec oso_arch;
463 // Only adopt the architecture from the module (not the vendor or OS)
464 // since .o files for "i386-apple-ios" will historically show up as "i386
465 // -apple-macosx" due to the lack of a LC_VERSION_MIN_MACOSX or
466 // LC_VERSION_MIN_IPHONEOS load command...
467 oso_arch.SetTriple(m_objfile_sp->GetModule()
468 ->GetArchitecture()
469 .GetTriple()
470 .getArchName()
471 .str()
472 .c_str());
473 comp_unit_info->oso_sp->module_sp = std::make_shared<DebugMapModule>(
474 obj_file->GetModule(), GetCompUnitInfoIndex(comp_unit_info), oso_file,
475 oso_arch, oso_object.str(), 0,
476 !oso_object.empty() ? comp_unit_info->oso_mod_time
477 : llvm::sys::TimePoint<>());
478
479 if (!oso_object.empty() &&
480 !comp_unit_info->oso_sp->module_sp->GetObjectFile() &&
481 FileSystem::Instance().Exists(oso_file)) {
482 // If we are loading a .o file from a .a file the "oso_object" will
483 // have a valid value name and if the .a file exists, either the .o
484 // file didn't exist in the .a file or the mod time didn't match.
486 "\"{0}\" object from the \"{1}\" archive: "
487 "either the .o file doesn't exist in the archive or the "
488 "modification time (0x{2:x-8}) of the .o file doesn't match",
489 oso_object, oso_file.GetPath(),
490 (uint32_t)llvm::sys::toTimeT(comp_unit_info->oso_mod_time));
491 }
492 }
493 }
494 if (comp_unit_info->oso_sp)
495 return comp_unit_info->oso_sp->module_sp.get();
496 return nullptr;
497}
498
499static bool OSOExists(llvm::StringRef oso_path) {
500 FileSpec oso_file(oso_path);
501 llvm::StringRef oso_object;
502 return FileSystem::Instance().Exists(oso_file) ||
503 ObjectFile::SplitArchivePathWithObject(oso_path, oso_file, oso_object,
504 /*must_exist=*/true);
505}
506
508 const CompileUnitInfo &missing_info) {
509 // Users have no control over shared cache images, so the error is not
510 // actionable.
511 if (m_objfile_sp->IsSharedCacheBinary())
512 return;
513
515 return;
517
518 size_t num_missing =
519 llvm::count_if(m_compile_unit_infos, [](const CompileUnitInfo &info) {
520 return !OSOExists(info.oso_path.GetStringRef());
521 });
522 ModuleSP module_sp = m_objfile_sp->GetModule();
523 if (num_missing <= 1) {
524 module_sp->ReportError("{0}", missing_info.oso_load_error.AsCString());
525 return;
526 }
527 module_sp->ReportError(
528 "{0} of {1} debug map object files do not exist: debug info cannot be "
529 "loaded for them. Run \"image dump separate-debug-info --errors-only\" "
530 "to list them",
531 num_missing, m_compile_unit_infos.size());
532}
533
535 FileSpec &file_spec) {
536 if (oso_idx < m_compile_unit_infos.size()) {
537 if (m_compile_unit_infos[oso_idx].so_file) {
538 file_spec = m_compile_unit_infos[oso_idx].so_file;
539 return true;
540 }
541 }
542 return false;
543}
544
546 Module *oso_module = GetModuleByOSOIndex(oso_idx);
547 if (oso_module)
548 return oso_module->GetObjectFile();
549 return nullptr;
550}
551
556
559 CompileUnitInfo *comp_unit_info = GetCompUnitInfo(comp_unit);
560 if (comp_unit_info)
561 return GetSymbolFileByCompUnitInfo(comp_unit_info);
562 return nullptr;
563}
564
566 CompileUnitInfo *comp_unit_info) {
567 Module *oso_module = GetModuleByCompUnitInfo(comp_unit_info);
568 if (oso_module)
569 return oso_module->GetObjectFile();
570 return nullptr;
571}
572
574 const CompileUnitInfo *comp_unit_info) {
575 if (!m_compile_unit_infos.empty()) {
576 const CompileUnitInfo *first_comp_unit_info = &m_compile_unit_infos.front();
577 const CompileUnitInfo *last_comp_unit_info = &m_compile_unit_infos.back();
578 if (first_comp_unit_info <= comp_unit_info &&
579 comp_unit_info <= last_comp_unit_info)
580 return comp_unit_info - first_comp_unit_info;
581 }
582 return UINT32_MAX;
583}
584
587 unsigned size = m_compile_unit_infos.size();
588 if (oso_idx < size)
590 return nullptr;
591}
592
595 if (sym_file &&
597 return static_cast<SymbolFileDWARF *>(sym_file);
598 return nullptr;
599}
600
602 CompileUnitInfo *comp_unit_info) {
603 if (Module *oso_module = GetModuleByCompUnitInfo(comp_unit_info))
604 return GetSymbolFileAsSymbolFileDWARF(oso_module->GetSymbolFile());
605 return nullptr;
606}
607
609 // In order to get the abilities of this plug-in, we look at the list of
610 // N_OSO entries (object files) from the symbol table and make sure that
611 // these files exist and also contain valid DWARF. If we get any of that then
612 // we return the abilities of the first N_OSO's DWARF.
613
614 const uint32_t oso_index_count = GetNumCompileUnits();
615 if (oso_index_count > 0) {
616 InitOSO();
617 if (!m_compile_unit_infos.empty()) {
622 }
623 }
624 return 0;
625}
626
631
633 CompUnitSP comp_unit_sp;
634 const uint32_t cu_count = GetNumCompileUnits();
635
636 if (cu_idx < cu_count) {
637 auto &cu_info = m_compile_unit_infos[cu_idx];
638 Module *oso_module = GetModuleByCompUnitInfo(&cu_info);
639 if (oso_module) {
640 FileSpec so_file_spec;
641 if (GetFileSpecForSO(cu_idx, so_file_spec)) {
642 // Apply the module's source path remappings so that compile units
643 // created from N_SO stabs (which may contain paths rewritten by
644 // -fdebug-prefix-map at build time) report their real on-disk paths.
645 // This mirrors what MakeAbsoluteAndRemap does for the dSYM case.
646 if (ModuleSP module_sp = m_objfile_sp->GetModule())
647 if (auto remapped =
648 module_sp->RemapSourceFile(so_file_spec.GetPath()))
649 so_file_spec.SetFile(*remapped, FileSpec::Style::native);
650
651 // User zero as the ID to match the compile unit at offset zero in each
652 // .o file.
653 lldb::user_id_t cu_id = 0;
654 cu_info.compile_units_sps.push_back(std::make_shared<CompileUnit>(
655 m_objfile_sp->GetModule(), nullptr,
656 std::make_shared<SupportFile>(so_file_spec), cu_id,
658 cu_info.id_to_index_map.insert({0, 0});
659 SetCompileUnitAtIndex(cu_idx, cu_info.compile_units_sps[0]);
660 // If there's a symbol file also register all the extra compile units.
661 if (SymbolFileDWARF *oso_symfile =
662 GetSymbolFileByCompUnitInfo(&cu_info)) {
663 auto num_dwarf_units = oso_symfile->DebugInfo().GetNumUnits();
664 for (size_t i = 0; i < num_dwarf_units; ++i) {
665 auto *dwarf_unit = oso_symfile->DebugInfo().GetUnitAtIndex(i);
666 if (auto *dwarf_cu = llvm::dyn_cast<DWARFCompileUnit>(dwarf_unit)) {
667 // The "main" one was already registered.
668 if (dwarf_cu->GetID() == 0)
669 continue;
670 cu_info.compile_units_sps.push_back(std::make_shared<CompileUnit>(
671 m_objfile_sp->GetModule(), nullptr,
672 std::make_shared<SupportFile>(so_file_spec),
673 dwarf_cu->GetID(), eLanguageTypeUnknown, eLazyBoolCalculate));
674 cu_info.id_to_index_map.insert(
675 {dwarf_cu->GetID(), cu_info.compile_units_sps.size() - 1});
676 }
677 }
678 }
679 }
680 }
681 if (!cu_info.compile_units_sps.empty())
682 comp_unit_sp = cu_info.compile_units_sps[0];
683 }
684
685 return comp_unit_sp;
686}
687
692
695 const uint32_t cu_count = GetNumCompileUnits();
696 for (uint32_t i = 0; i < cu_count; ++i) {
697 auto &id_to_index_map = m_compile_unit_infos[i].id_to_index_map;
698
699 auto it = id_to_index_map.find(comp_unit.GetID());
700 if (it != id_to_index_map.end() &&
701 &comp_unit ==
702 m_compile_unit_infos[i].compile_units_sps[it->getSecond()].get())
703 return &m_compile_unit_infos[i];
704 }
705 return nullptr;
706}
707
709 const lldb_private::Module *module,
710 std::vector<CompileUnitInfo *> &cu_infos) {
711 const uint32_t cu_count = GetNumCompileUnits();
712 for (uint32_t i = 0; i < cu_count; ++i) {
714 cu_infos.push_back(&m_compile_unit_infos[i]);
715 }
716 return cu_infos.size();
717}
718
721 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
722 SymbolFileDWARF *oso_dwarf = GetSymbolFile(comp_unit);
723 if (oso_dwarf)
724 return oso_dwarf->ParseLanguage(comp_unit);
726}
727
730 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
731 SymbolFileDWARF *oso_dwarf = GetSymbolFile(comp_unit);
732 if (oso_dwarf)
733 return oso_dwarf->ParseXcodeSDK(comp_unit);
734 return {};
735}
736
737llvm::SmallSet<lldb::LanguageType, 4>
739 lldb_private::CompileUnit &comp_unit) {
740 llvm::SmallSet<lldb::LanguageType, 4> langs;
741 auto *info = GetCompUnitInfo(comp_unit);
742 for (auto &comp_unit : info->compile_units_sps) {
743 langs.insert(comp_unit->GetLanguage());
744 }
745 return langs;
746}
747
749 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
750 SymbolFileDWARF *oso_dwarf = GetSymbolFile(comp_unit);
751 if (oso_dwarf)
752 return oso_dwarf->ParseFunctions(comp_unit);
753 return 0;
754}
755
757 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
758 SymbolFileDWARF *oso_dwarf = GetSymbolFile(comp_unit);
759 if (oso_dwarf)
760 return oso_dwarf->ParseLineTable(comp_unit);
761 return false;
762}
763
765 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
766 SymbolFileDWARF *oso_dwarf = GetSymbolFile(comp_unit);
767 if (oso_dwarf)
768 return oso_dwarf->ParseDebugMacros(comp_unit);
769 return false;
770}
771
773 std::string description,
774 std::function<IterationAction(SymbolFileDWARF &)> closure) {
775 const size_t num_oso_idxs = m_compile_unit_infos.size();
776 Progress progress(std::move(description), "", num_oso_idxs,
777 /*debugger=*/nullptr,
779 for (uint32_t oso_idx = 0; oso_idx < num_oso_idxs; ++oso_idx) {
780 if (SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex(oso_idx)) {
781 progress.Increment(oso_idx, oso_dwarf->GetObjectName());
782 if (closure(*oso_dwarf) == IterationAction::Stop)
783 return;
784 }
785 }
786}
787
789 CompileUnit &comp_unit,
790 llvm::DenseSet<lldb_private::SymbolFile *> &visited_symbol_files,
791 llvm::function_ref<bool(Module &)> f) {
792 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
793 SymbolFileDWARF *oso_dwarf = GetSymbolFile(comp_unit);
794 if (oso_dwarf)
795 return oso_dwarf->ForEachExternalModule(comp_unit, visited_symbol_files, f);
796 return false;
797}
798
800 CompileUnit &comp_unit, SupportFileList &support_files) {
801 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
802 SymbolFileDWARF *oso_dwarf = GetSymbolFile(comp_unit);
803 if (oso_dwarf)
804 return oso_dwarf->ParseSupportFiles(comp_unit, support_files);
805 return false;
806}
807
809 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
810 SymbolFileDWARF *oso_dwarf = GetSymbolFile(comp_unit);
811 if (oso_dwarf)
812 return oso_dwarf->ParseIsOptimized(comp_unit);
813 return false;
814}
815
817 const SymbolContext &sc, std::vector<SourceModule> &imported_modules) {
818 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
819 SymbolFileDWARF *oso_dwarf = GetSymbolFile(sc);
820 if (oso_dwarf)
821 return oso_dwarf->ParseImportedModules(sc, imported_modules);
822 return false;
823}
824
826 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
827 CompileUnit *comp_unit = func.GetCompileUnit();
828 if (!comp_unit)
829 return 0;
830
831 SymbolFileDWARF *oso_dwarf = GetSymbolFile(*comp_unit);
832 if (oso_dwarf)
833 return oso_dwarf->ParseBlocksRecursive(func);
834 return 0;
835}
836
838 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
839 SymbolFileDWARF *oso_dwarf = GetSymbolFile(comp_unit);
840 if (oso_dwarf)
841 return oso_dwarf->ParseTypes(comp_unit);
842 return 0;
843}
844
845size_t
847 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
848 SymbolFileDWARF *oso_dwarf = GetSymbolFile(sc);
849 if (oso_dwarf)
850 return oso_dwarf->ParseVariablesForContext(sc);
851 return 0;
852}
853
855 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
856 const uint64_t oso_idx = GetOSOIndexFromUserID(type_uid);
857 SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex(oso_idx);
858 if (oso_dwarf)
859 return oso_dwarf->ResolveTypeUID(type_uid);
860 return nullptr;
861}
862
863std::optional<SymbolFile::ArrayInfo>
865 lldb::user_id_t type_uid, const lldb_private::ExecutionContext *exe_ctx) {
866 const uint64_t oso_idx = GetOSOIndexFromUserID(type_uid);
867 SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex(oso_idx);
868 if (oso_dwarf)
869 return oso_dwarf->GetDynamicArrayInfoForUID(type_uid, exe_ctx);
870 return std::nullopt;
871}
872
874 bool success = false;
875 if (compiler_type) {
876 ForEachSymbolFile("Completing type", [&](SymbolFileDWARF &oso_dwarf) {
877 if (oso_dwarf.HasForwardDeclForCompilerType(compiler_type)) {
878 oso_dwarf.CompleteType(compiler_type);
879 success = true;
881 }
883 });
884 }
885 return success;
886}
887
888uint32_t
890 SymbolContextItem resolve_scope,
891 SymbolContext &sc) {
892 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
893 uint32_t resolved_flags = 0;
894 Symtab *symtab = m_objfile_sp->GetSymtab();
895 if (symtab) {
896 const addr_t exe_file_addr = exe_so_addr.GetFileAddress();
897
898 const DebugMap::Entry *debug_map_entry =
899 m_debug_map.FindEntryThatContains(exe_file_addr);
900 if (debug_map_entry) {
901
902 sc.symbol =
903 symtab->SymbolAtIndex(debug_map_entry->data.GetExeSymbolIndex());
904
905 if (sc.symbol != nullptr) {
906 resolved_flags |= eSymbolContextSymbol;
907
908 uint32_t oso_idx = 0;
909 CompileUnitInfo *comp_unit_info =
911 if (comp_unit_info) {
912 comp_unit_info->GetFileRangeMap(this);
913 Module *oso_module = GetModuleByCompUnitInfo(comp_unit_info);
914 if (oso_module) {
915 lldb::addr_t oso_file_addr =
916 exe_file_addr - debug_map_entry->GetRangeBase() +
917 debug_map_entry->data.GetOSOFileAddress();
918 Address oso_so_addr;
919 if (oso_module->ResolveFileAddress(oso_file_addr, oso_so_addr)) {
920 if (SymbolFile *sym_file = oso_module->GetSymbolFile()) {
921 resolved_flags |= sym_file->ResolveSymbolContext(
922 oso_so_addr, resolve_scope, sc);
923 } else {
924 ObjectFile *obj_file = GetObjectFile();
926 "Failed to get symfile for OSO: {0} in module: {1}",
927 oso_module->GetFileSpec(),
928 obj_file ? obj_file->GetFileSpec()
929 : FileSpec("unknown"));
930 }
931 }
932 }
933 }
934 }
935 }
936 }
937 return resolved_flags;
938}
939
941 const SourceLocationSpec &src_location_spec,
942 SymbolContextItem resolve_scope, SymbolContextList &sc_list) {
943 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
944 const uint32_t initial = sc_list.GetSize();
945 const uint32_t cu_count = GetNumCompileUnits();
946
947 for (uint32_t i = 0; i < cu_count; ++i) {
948 // If we are checking for inlines, then we need to look through all compile
949 // units no matter if "file_spec" matches.
950 bool resolve = src_location_spec.GetCheckInlines();
951
952 if (!resolve) {
953 FileSpec so_file_spec;
954 if (GetFileSpecForSO(i, so_file_spec))
955 resolve =
956 FileSpec::Match(src_location_spec.GetFileSpec(), so_file_spec);
957 }
958 if (resolve) {
960 if (oso_dwarf)
961 oso_dwarf->ResolveSymbolContext(src_location_spec, resolve_scope,
962 sc_list);
963 }
964 }
965 return sc_list.GetSize() - initial;
966}
967
969 ConstString name, const CompilerDeclContext &parent_decl_ctx,
970 const std::vector<uint32_t>
971 &indexes, // Indexes into the symbol table that match "name"
972 uint32_t max_matches, VariableList &variables) {
973 const size_t match_count = indexes.size();
974 for (size_t i = 0; i < match_count; ++i) {
975 uint32_t oso_idx;
976 CompileUnitInfo *comp_unit_info =
977 GetCompileUnitInfoForSymbolWithIndex(indexes[i], &oso_idx);
978 if (comp_unit_info) {
979 SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex(oso_idx);
980 if (oso_dwarf) {
981 oso_dwarf->FindGlobalVariables(name, parent_decl_ctx, max_matches,
982 variables);
983 if (variables.GetSize() > max_matches)
984 break;
985 }
986 }
987 }
988}
989
991 ConstString name, const CompilerDeclContext &parent_decl_ctx,
992 uint32_t max_matches, VariableList &variables) {
993 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
994 uint32_t total_matches = 0;
995
997 "Looking up global variables", [&](SymbolFileDWARF &oso_dwarf) {
998 const uint32_t old_size = variables.GetSize();
999 oso_dwarf.FindGlobalVariables(name, parent_decl_ctx, max_matches,
1000 variables);
1001 const uint32_t oso_matches = variables.GetSize() - old_size;
1002 if (oso_matches > 0) {
1003 total_matches += oso_matches;
1004
1005 // If we are getting all matches, keep going.
1006 if (max_matches == UINT32_MAX)
1008
1009 // If we have found enough matches, lets get out
1010 if (max_matches >= total_matches)
1011 return IterationAction::Stop;
1012
1013 // Update the max matches for any subsequent calls to find globals in
1014 // any other object files with DWARF
1015 max_matches -= oso_matches;
1016 }
1017
1019 });
1020}
1021
1023 const RegularExpression &regex, uint32_t max_matches,
1024 VariableList &variables) {
1025 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1026 uint32_t total_matches = 0;
1028 "Looking up global variables", [&](SymbolFileDWARF &oso_dwarf) {
1029 const uint32_t old_size = variables.GetSize();
1030 oso_dwarf.FindGlobalVariables(regex, max_matches, variables);
1031
1032 const uint32_t oso_matches = variables.GetSize() - old_size;
1033 if (oso_matches > 0) {
1034 total_matches += oso_matches;
1035
1036 // If we are getting all matches, keep going.
1037 if (max_matches == UINT32_MAX)
1039
1040 // If we have found enough matches, lets get out
1041 if (max_matches >= total_matches)
1042 return IterationAction::Stop;
1043
1044 // Update the max matches for any subsequent calls to find globals in
1045 // any other object files with DWARF
1046 max_matches -= oso_matches;
1047 }
1048
1050 });
1051}
1052
1054 uint32_t *symbol_idx_ptr, const CompileUnitInfo *comp_unit_info) {
1055 const uint32_t symbol_idx = *symbol_idx_ptr;
1056
1057 if (symbol_idx < comp_unit_info->first_symbol_index)
1058 return -1;
1059
1060 if (symbol_idx <= comp_unit_info->last_symbol_index)
1061 return 0;
1062
1063 return 1;
1064}
1065
1067 user_id_t *symbol_idx_ptr, const CompileUnitInfo *comp_unit_info) {
1068 const user_id_t symbol_id = *symbol_idx_ptr;
1069
1070 if (symbol_id < comp_unit_info->first_symbol_id)
1071 return -1;
1072
1073 if (symbol_id <= comp_unit_info->last_symbol_id)
1074 return 0;
1075
1076 return 1;
1077}
1078
1081 uint32_t symbol_idx, uint32_t *oso_idx_ptr) {
1082 const uint32_t oso_index_count = m_compile_unit_infos.size();
1083 CompileUnitInfo *comp_unit_info = nullptr;
1084 if (oso_index_count) {
1085 comp_unit_info = (CompileUnitInfo *)bsearch(
1086 &symbol_idx, &m_compile_unit_infos[0], m_compile_unit_infos.size(),
1087 sizeof(CompileUnitInfo),
1089 }
1090
1091 if (oso_idx_ptr) {
1092 if (comp_unit_info != nullptr)
1093 *oso_idx_ptr = comp_unit_info - &m_compile_unit_infos[0];
1094 else
1095 *oso_idx_ptr = UINT32_MAX;
1096 }
1097 return comp_unit_info;
1098}
1099
1102 user_id_t symbol_id, uint32_t *oso_idx_ptr) {
1103 const uint32_t oso_index_count = m_compile_unit_infos.size();
1104 CompileUnitInfo *comp_unit_info = nullptr;
1105 if (oso_index_count) {
1106 comp_unit_info = (CompileUnitInfo *)::bsearch(
1107 &symbol_id, &m_compile_unit_infos[0], m_compile_unit_infos.size(),
1108 sizeof(CompileUnitInfo),
1110 }
1111
1112 if (oso_idx_ptr) {
1113 if (comp_unit_info != nullptr)
1114 *oso_idx_ptr = comp_unit_info - &m_compile_unit_infos[0];
1115 else
1116 *oso_idx_ptr = UINT32_MAX;
1117 }
1118 return comp_unit_info;
1119}
1120
1122 SymbolContextList &sc_list,
1123 uint32_t start_idx) {
1124 // We found functions in .o files. Not all functions in the .o files will
1125 // have made it into the final output file. The ones that did make it into
1126 // the final output file will have a section whose module matches the module
1127 // from the ObjectFile for this SymbolFile. When the modules don't match,
1128 // then we have something that was in a .o file, but doesn't map to anything
1129 // in the final executable.
1130 uint32_t i = start_idx;
1131 while (i < sc_list.GetSize()) {
1132 SymbolContext sc;
1133 sc_list.GetContextAtIndex(i, sc);
1134 if (sc.function) {
1135 const SectionSP section_sp = sc.function->GetAddress().GetSection();
1136 if (section_sp->GetModule() != module_sp) {
1137 sc_list.RemoveContextAtIndex(i);
1138 continue;
1139 }
1140 }
1141 ++i;
1142 }
1143}
1144
1146 const Module::LookupInfo &lookup_info,
1147 const CompilerDeclContext &parent_decl_ctx, bool include_inlines,
1148 SymbolContextList &sc_list) {
1149 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1150 LLDB_SCOPED_TIMERF("SymbolFileDWARFDebugMap::FindFunctions (name = %s)",
1151 lookup_info.GetLookupName().GetCString());
1152
1153 ForEachSymbolFile("Looking up functions", [&](SymbolFileDWARF &oso_dwarf) {
1154 uint32_t sc_idx = sc_list.GetSize();
1155 oso_dwarf.FindFunctions(lookup_info, parent_decl_ctx, include_inlines,
1156 sc_list);
1157 if (!sc_list.IsEmpty()) {
1159 sc_idx);
1160 }
1162 });
1163}
1164
1166 bool include_inlines,
1167 SymbolContextList &sc_list) {
1168 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1169 LLDB_SCOPED_TIMERF("SymbolFileDWARFDebugMap::FindFunctions (regex = '%s')",
1170 regex.GetText().str().c_str());
1171
1172 ForEachSymbolFile("Looking up functions", [&](SymbolFileDWARF &oso_dwarf) {
1173 uint32_t sc_idx = sc_list.GetSize();
1174
1175 oso_dwarf.FindFunctions(regex, include_inlines, sc_list);
1176 if (!sc_list.IsEmpty()) {
1178 sc_idx);
1179 }
1181 });
1182}
1183
1185 lldb::TypeClass type_mask,
1186 TypeList &type_list) {
1187 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1188 LLDB_SCOPED_TIMERF("SymbolFileDWARFDebugMap::GetTypes (type_mask = 0x%8.8x)",
1189 type_mask);
1190
1191 SymbolFileDWARF *oso_dwarf = nullptr;
1192 if (sc_scope) {
1193 SymbolContext sc;
1194 sc_scope->CalculateSymbolContext(&sc);
1195
1196 CompileUnitInfo *cu_info = GetCompUnitInfo(sc);
1197 if (cu_info) {
1198 oso_dwarf = GetSymbolFileByCompUnitInfo(cu_info);
1199 if (oso_dwarf)
1200 oso_dwarf->GetTypes(sc_scope, type_mask, type_list);
1201 }
1202 } else {
1203 ForEachSymbolFile("Looking up types", [&](SymbolFileDWARF &oso_dwarf) {
1204 oso_dwarf.GetTypes(sc_scope, type_mask, type_list);
1206 });
1207 }
1208}
1209
1210std::vector<std::unique_ptr<lldb_private::CallEdge>>
1212 lldb_private::UserID func_id) {
1213 uint32_t oso_idx = GetOSOIndexFromUserID(func_id.GetID());
1214 SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex(oso_idx);
1215 if (oso_dwarf)
1216 return oso_dwarf->ParseCallEdgesInFunction(func_id);
1217 return {};
1218}
1219
1221 DWARFDIE result;
1223 "Looking up type definition", [&](SymbolFileDWARF &oso_dwarf) {
1224 result = oso_dwarf.FindDefinitionDIE(die);
1226 });
1227 return result;
1228}
1229
1231 const DWARFDIE &die, ConstString type_name, bool must_be_implementation) {
1232 // If we have a debug map, we will have an Objective-C symbol whose name is
1233 // the type name and whose type is eSymbolTypeObjCClass. If we can find that
1234 // symbol and find its containing parent, we can locate the .o file that will
1235 // contain the implementation definition since it will be scoped inside the
1236 // N_SO and we can then locate the SymbolFileDWARF that corresponds to that
1237 // N_SO.
1238 SymbolFileDWARF *oso_dwarf = nullptr;
1239 TypeSP type_sp;
1240 ObjectFile *module_objfile = m_objfile_sp->GetModule()->GetObjectFile();
1241 if (module_objfile) {
1242 Symtab *symtab = module_objfile->GetSymtab();
1243 if (symtab) {
1244 Symbol *objc_class_symbol = symtab->FindFirstSymbolWithNameAndType(
1247 if (objc_class_symbol) {
1248 // Get the N_SO symbol that contains the objective C class symbol as
1249 // this should be the .o file that contains the real definition...
1250 const Symbol *source_file_symbol = symtab->GetParent(objc_class_symbol);
1251
1252 if (source_file_symbol &&
1253 source_file_symbol->GetType() == eSymbolTypeSourceFile) {
1254 const uint32_t source_file_symbol_idx =
1255 symtab->GetIndexForSymbol(source_file_symbol);
1256 if (source_file_symbol_idx != UINT32_MAX) {
1257 CompileUnitInfo *compile_unit_info =
1258 GetCompileUnitInfoForSymbolWithIndex(source_file_symbol_idx,
1259 nullptr);
1260 if (compile_unit_info) {
1261 oso_dwarf = GetSymbolFileByCompUnitInfo(compile_unit_info);
1262 if (oso_dwarf) {
1264 die, type_name, must_be_implementation));
1265 if (type_sp) {
1266 return type_sp;
1267 }
1268 }
1269 }
1270 }
1271 }
1272 }
1273 }
1274 }
1275
1276 // Only search all .o files for the definition if we don't need the
1277 // implementation because otherwise, with a valid debug map we should have
1278 // the ObjC class symbol and the code above should have found it.
1279 if (!must_be_implementation) {
1280 TypeSP type_sp;
1281
1283 "Looking up Objective-C definition", [&](SymbolFileDWARF &oso_dwarf) {
1284 type_sp = oso_dwarf.FindCompleteObjCDefinitionTypeForDIE(
1285 die, type_name, must_be_implementation);
1287 });
1288
1289 return type_sp;
1290 }
1291 return TypeSP();
1292}
1293
1295 TypeResults &results) {
1296 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1297 ForEachSymbolFile("Looking up type", [&](SymbolFileDWARF &oso_dwarf) {
1298 oso_dwarf.FindTypes(query, results);
1299 return results.Done(query) ? IterationAction::Stop
1301 });
1302}
1303
1305 lldb_private::ConstString name, const CompilerDeclContext &parent_decl_ctx,
1306 bool only_root_namespaces) {
1307 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1308 CompilerDeclContext matching_namespace;
1309
1310 ForEachSymbolFile("Looking up namespace", [&](SymbolFileDWARF &oso_dwarf) {
1311 matching_namespace =
1312 oso_dwarf.FindNamespace(name, parent_decl_ctx, only_root_namespaces);
1313
1314 return matching_namespace ? IterationAction::Stop
1316 });
1317
1318 return matching_namespace;
1319}
1320
1321void SymbolFileDWARFDebugMap::DumpClangAST(Stream &s, llvm::StringRef filter,
1322 bool show_color) {
1323 ForEachSymbolFile("Dumping clang AST", [&](SymbolFileDWARF &oso_dwarf) {
1324 oso_dwarf.DumpClangAST(s, filter, show_color);
1325 // The underlying assumption is that DumpClangAST(...) will obtain the
1326 // AST from the underlying TypeSystem and therefore we only need to do
1327 // this once and can stop after the first iteration hence we return true.
1328 return IterationAction::Stop;
1329 });
1330}
1331
1334 const uint32_t cu_count = GetNumCompileUnits();
1336 for (uint32_t cu_idx = 0; cu_idx < cu_count; ++cu_idx) {
1337 const auto &info = m_compile_unit_infos[cu_idx];
1338 if (info.so_file.GetPath().empty())
1339 continue;
1340
1341 ModuleSpec spec;
1342 FileSpec oso_file;
1343 llvm::StringRef oso_object;
1344 if (ObjectFile::SplitArchivePathWithObject(info.oso_path.GetStringRef(),
1345 oso_file, oso_object,
1346 /*must_exist=*/false)) {
1347 spec.GetFileSpec() = oso_file;
1348 spec.SetObjectName(oso_object.str());
1349 } else {
1350 spec.GetFileSpec() = FileSpec(info.oso_path.GetStringRef());
1351 }
1352
1353 spec.GetObjectModificationTime() = info.oso_mod_time;
1354 spec_list.Append(spec);
1355 }
1356 return spec_list;
1357}
1358
1360 lldb_private::StructuredData::Dictionary &d, bool errors_only,
1361 bool load_all_debug_info) {
1362 StructuredData::Array separate_debug_info_files;
1363 const uint32_t cu_count = GetNumCompileUnits();
1364 for (uint32_t cu_idx = 0; cu_idx < cu_count; ++cu_idx) {
1365 const auto &info = m_compile_unit_infos[cu_idx];
1367 std::make_shared<StructuredData::Dictionary>();
1368 oso_data->AddStringItem("so_file", info.so_file.GetPath());
1369 oso_data->AddStringItem("oso_path", info.oso_path);
1370 oso_data->AddIntegerItem("oso_mod_time",
1371 (uint32_t)llvm::sys::toTimeT(info.oso_mod_time));
1372
1373 bool loaded_successfully = false;
1374 if (GetModuleByOSOIndex(cu_idx)) {
1375 // If we have a valid pointer to the module, we successfully
1376 // loaded the oso if there are no load errors.
1377 if (!info.oso_load_error.Fail()) {
1378 loaded_successfully = true;
1379 }
1380 }
1381 if (!loaded_successfully) {
1382 oso_data->AddStringItem("error", info.oso_load_error.AsCString());
1383 }
1384 oso_data->AddBooleanItem("loaded", loaded_successfully);
1385 if (!errors_only || oso_data->HasKey("error"))
1386 separate_debug_info_files.AddItem(oso_data);
1387 }
1388
1389 d.AddStringItem("type", "oso");
1390 d.AddStringItem("symfile", GetMainObjectFile()->GetFileSpec().GetPath());
1391 d.AddItem("separate-debug-info-files",
1392 std::make_shared<StructuredData::Array>(
1393 std::move(separate_debug_info_files)));
1394 return true;
1395}
1396
1399 DWARFCompileUnit &dwarf_cu) {
1400 if (oso_dwarf) {
1401 const uint32_t cu_count = GetNumCompileUnits();
1402 for (uint32_t cu_idx = 0; cu_idx < cu_count; ++cu_idx) {
1403 SymbolFileDWARF *oso_symfile =
1405 if (oso_symfile == oso_dwarf) {
1406 if (m_compile_unit_infos[cu_idx].compile_units_sps.empty())
1408
1409 auto &id_to_index_map = m_compile_unit_infos[cu_idx].id_to_index_map;
1410 auto it = id_to_index_map.find(dwarf_cu.GetID());
1411 if (it != id_to_index_map.end())
1412 return m_compile_unit_infos[cu_idx]
1413 .compile_units_sps[it->getSecond()];
1414 }
1415 }
1416 }
1417 llvm_unreachable("this shouldn't happen");
1418}
1419
1422 if (oso_dwarf) {
1423 const uint32_t cu_count = GetNumCompileUnits();
1424 for (uint32_t cu_idx = 0; cu_idx < cu_count; ++cu_idx) {
1425 SymbolFileDWARF *oso_symfile =
1427 if (oso_symfile == oso_dwarf) {
1428 return &m_compile_unit_infos[cu_idx];
1429 }
1430 }
1431 }
1432 return nullptr;
1433}
1434
1436 const CompUnitSP &cu_sp) {
1437 if (oso_dwarf) {
1438 const uint32_t cu_count = GetNumCompileUnits();
1439 for (uint32_t cu_idx = 0; cu_idx < cu_count; ++cu_idx) {
1440 SymbolFileDWARF *oso_symfile =
1442 if (oso_symfile == oso_dwarf) {
1443 if (!m_compile_unit_infos[cu_idx].compile_units_sps.empty()) {
1444 assert(m_compile_unit_infos[cu_idx].compile_units_sps[0].get() ==
1445 cu_sp.get());
1446 } else {
1447 assert(cu_sp->GetID() == 0 &&
1448 "Setting first compile unit but with id different than 0!");
1449 auto &compile_units_sps =
1450 m_compile_unit_infos[cu_idx].compile_units_sps;
1451 compile_units_sps.push_back(cu_sp);
1452 m_compile_unit_infos[cu_idx].id_to_index_map.insert(
1453 {cu_sp->GetID(), compile_units_sps.size() - 1});
1454
1455 SetCompileUnitAtIndex(cu_idx, cu_sp);
1456 }
1457 }
1458 }
1459 }
1460}
1461
1464 const uint64_t oso_idx = GetOSOIndexFromUserID(type_uid);
1465 if (SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex(oso_idx))
1466 return oso_dwarf->GetDeclContextForUID(type_uid);
1467 return {};
1468}
1469
1472 const uint64_t oso_idx = GetOSOIndexFromUserID(type_uid);
1473 if (SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex(oso_idx))
1474 return oso_dwarf->GetDeclContextContainingUID(type_uid);
1475 return {};
1476}
1477
1478std::vector<CompilerContext>
1480 const uint64_t oso_idx = GetOSOIndexFromUserID(type_uid);
1481 if (SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex(oso_idx))
1482 return oso_dwarf->GetCompilerContextForUID(type_uid);
1483 return {};
1484}
1485
1488 ForEachSymbolFile("Parsing declarations", [&](SymbolFileDWARF &oso_dwarf) {
1489 oso_dwarf.ParseDeclsForContext(decl_ctx);
1491 });
1492}
1493
1495 lldb::addr_t exe_file_addr,
1496 lldb::addr_t exe_byte_size,
1497 lldb::addr_t oso_file_addr,
1498 lldb::addr_t oso_byte_size) {
1499 const uint32_t debug_map_idx =
1500 m_debug_map.FindEntryIndexThatContains(exe_file_addr);
1501 if (debug_map_idx != UINT32_MAX) {
1502 DebugMap::Entry *debug_map_entry =
1503 m_debug_map.FindEntryThatContains(exe_file_addr);
1504 debug_map_entry->data.SetOSOFileAddress(oso_file_addr);
1505 addr_t range_size = std::min<addr_t>(exe_byte_size, oso_byte_size);
1506 if (range_size == 0) {
1507 range_size = std::max<addr_t>(exe_byte_size, oso_byte_size);
1508 if (range_size == 0)
1509 range_size = 1;
1510 }
1511 cu_info->file_range_map.Append(
1512 FileRangeMap::Entry(oso_file_addr, range_size, exe_file_addr));
1513 return true;
1514 }
1515 return false;
1516}
1517
1519 cu_info->file_range_map.Sort();
1520#if defined(DEBUG_OSO_DMAP)
1521 const FileRangeMap &oso_file_range_map = cu_info->GetFileRangeMap(this);
1522 const size_t n = oso_file_range_map.GetSize();
1523 printf("SymbolFileDWARFDebugMap::FinalizeOSOFileRanges (cu_info = %p) %s\n",
1524 cu_info, cu_info->oso_sp->module_sp->GetFileSpec().GetPath().c_str());
1525 for (size_t i = 0; i < n; ++i) {
1526 const FileRangeMap::Entry &entry = oso_file_range_map.GetEntryRef(i);
1527 printf("oso [0x%16.16" PRIx64 " - 0x%16.16" PRIx64
1528 ") ==> exe [0x%16.16" PRIx64 " - 0x%16.16" PRIx64 ")\n",
1529 entry.GetRangeBase(), entry.GetRangeEnd(), entry.data,
1530 entry.data + entry.GetByteSize());
1531 }
1532#endif
1533}
1534
1537 lldb::addr_t oso_file_addr) {
1538 CompileUnitInfo *cu_info = GetCompileUnitInfo(oso_symfile);
1539 if (cu_info) {
1540 const FileRangeMap::Entry *oso_range_entry =
1541 cu_info->GetFileRangeMap(this).FindEntryThatContains(oso_file_addr);
1542 if (oso_range_entry) {
1543 const DebugMap::Entry *debug_map_entry =
1544 m_debug_map.FindEntryThatContains(oso_range_entry->data);
1545 if (debug_map_entry) {
1546 const lldb::addr_t offset =
1547 oso_file_addr - oso_range_entry->GetRangeBase();
1548 const lldb::addr_t exe_file_addr =
1549 debug_map_entry->GetRangeBase() + offset;
1550 return exe_file_addr;
1551 }
1552 }
1553 }
1554 return LLDB_INVALID_ADDRESS;
1555}
1556
1558 // Make sure this address hasn't been fixed already
1559 Module *exe_module = GetObjectFile()->GetModule().get();
1560 Module *addr_module = addr.GetModule().get();
1561 if (addr_module == exe_module)
1562 return true; // Address is already in terms of the main executable module
1563
1566 if (cu_info) {
1567 const lldb::addr_t oso_file_addr = addr.GetFileAddress();
1568 const FileRangeMap::Entry *oso_range_entry =
1569 cu_info->GetFileRangeMap(this).FindEntryThatContains(oso_file_addr);
1570 if (oso_range_entry) {
1571 const DebugMap::Entry *debug_map_entry =
1572 m_debug_map.FindEntryThatContains(oso_range_entry->data);
1573 if (debug_map_entry) {
1574 const lldb::addr_t offset =
1575 oso_file_addr - oso_range_entry->GetRangeBase();
1576 const lldb::addr_t exe_file_addr =
1577 debug_map_entry->GetRangeBase() + offset;
1578 return exe_module->ResolveFileAddress(exe_file_addr, addr);
1579 }
1580 }
1581 }
1582 return true;
1583}
1584
1586 LineTable *line_table) {
1587 CompileUnitInfo *cu_info = GetCompileUnitInfo(oso_dwarf);
1588 if (cu_info)
1589 return line_table->LinkLineTable(cu_info->GetFileRangeMap(this));
1590 return nullptr;
1591}
1592
1593size_t
1595 DWARFDebugAranges *debug_aranges) {
1596 size_t num_line_entries_added = 0;
1597 if (debug_aranges && dwarf2Data) {
1598 CompileUnitInfo *compile_unit_info = GetCompileUnitInfo(dwarf2Data);
1599 if (compile_unit_info) {
1600 const FileRangeMap &file_range_map =
1601 compile_unit_info->GetFileRangeMap(this);
1602 for (size_t idx = 0; idx < file_range_map.GetSize(); idx++) {
1603 const FileRangeMap::Entry *entry = file_range_map.GetEntryAtIndex(idx);
1604 if (entry) {
1605 debug_aranges->AppendRange(*dwarf2Data->GetFileIndex(),
1606 entry->GetRangeBase(),
1607 entry->GetRangeEnd());
1608 num_line_entries_added++;
1609 }
1610 }
1611 }
1612 }
1613 return num_line_entries_added;
1614}
1615
1617 ModuleList oso_modules;
1618 ForEachSymbolFile("Parsing modules", [&](SymbolFileDWARF &oso_dwarf) {
1619 ObjectFile *oso_objfile = oso_dwarf.GetObjectFile();
1620 if (oso_objfile) {
1621 ModuleSP module_sp = oso_objfile->GetModule();
1622 if (module_sp)
1623 oso_modules.Append(module_sp);
1624 }
1626 });
1627 return oso_modules;
1628}
1629
1631 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1632
1633 // We need to make sure that our PC value from the frame matches the module
1634 // for this object file since we will lookup the PC file address in the debug
1635 // map below.
1636 Address pc_addr = frame.GetFrameCodeAddress();
1637 if (pc_addr.GetModule() == m_objfile_sp->GetModule()) {
1638 Symtab *symtab = m_objfile_sp->GetSymtab();
1639 if (symtab) {
1640 const DebugMap::Entry *debug_map_entry =
1641 m_debug_map.FindEntryThatContains(pc_addr.GetFileAddress());
1642 if (debug_map_entry) {
1643 const Symbol *symbol =
1644 symtab->SymbolAtIndex(debug_map_entry->data.GetExeSymbolIndex());
1645 if (symbol) {
1646 uint32_t oso_idx = 0;
1647 CompileUnitInfo *comp_unit_info =
1648 GetCompileUnitInfoForSymbolWithID(symbol->GetID(), &oso_idx);
1649 if (comp_unit_info) {
1650 Module *oso_module = GetModuleByCompUnitInfo(comp_unit_info);
1651 if (oso_module) {
1652 // Check the .o file's DWARF in case it has an error to display.
1653 SymbolFile *oso_sym_file = oso_module->GetSymbolFile();
1654 if (oso_sym_file)
1655 return oso_sym_file->GetFrameVariableError(frame);
1656 }
1657 // If we don't have a valid OSO module here, then something went
1658 // wrong as we have a symbol for the address in the debug map, but
1659 // we weren't able to open the .o file. Display an appropriate
1660 // error
1661 if (comp_unit_info->oso_load_error.Fail())
1662 return comp_unit_info->oso_load_error.Clone();
1663 else
1665 "unable to load debug map object file \"%s\" "
1666 "exist, debug info will not be loaded",
1667 comp_unit_info->oso_path.GetCString());
1668 }
1669 }
1670 }
1671 }
1672 }
1673 return Status();
1674}
1675
1677 std::unordered_map<lldb::CompUnitSP, lldb_private::Args> &args) {
1678
1679 ForEachSymbolFile("Parsing compile options", [&](SymbolFileDWARF &oso_dwarf) {
1680 oso_dwarf.GetCompileOptions(args);
1682 });
1683}
1684
1687 lldb::TypeSP type;
1688 ForEachSymbolFile("Looking up enclosing type for variable",
1689 [&](SymbolFileDWARF &oso_dwarf) {
1690 type = oso_dwarf.GetTypeEnclosingVariableUID(uid);
1691 return type ? IterationAction::Stop
1693 });
1694 return type;
1695}
1696
1697llvm::Expected<SymbolContext>
1699 const uint64_t oso_idx = GetOSOIndexFromUserID(label.symbol_id);
1700 SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex(oso_idx);
1701 if (!oso_dwarf)
1702 return llvm::createStringErrorV(
1703 "couldn't find symbol file for {0} in debug-map.", label);
1704
1705 return oso_dwarf->ResolveFunctionCallLabel(label);
1706}
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
Definition Log.h:375
#define LLDB_LOGF(log,...)
Definition Log.h:389
static void RemoveFunctionsWithModuleNotEqualTo(const ModuleSP &module_sp, SymbolContextList &sc_list, uint32_t start_idx)
static bool OSOExists(llvm::StringRef oso_path)
#define LLDB_SCOPED_TIMERF(...)
Definition Timer.h:91
A section + offset based address class.
Definition Address.h:62
lldb::SectionSP GetSection() const
Get const accessor for the section.
Definition Address.h:426
lldb::ModuleSP GetModule() const
Get accessor for the module for this address.
Definition Address.cpp:275
lldb::addr_t GetFileAddress() const
Get the file address.
Definition Address.cpp:283
An architecture specification class.
Definition ArchSpec.h:32
bool SetTriple(const llvm::Triple &triple)
Architecture triple setter.
Definition ArchSpec.cpp: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
bool Exists(const FileSpec &file_spec) const
Returns whether the given file exists.
static FileSystem & Instance()
A class that describes a function.
Definition Function.h:386
const Address & GetAddress() const
Return the address of the function (its entry point).
Definition Function.h:439
CompileUnit * GetCompileUnit()
Get accessor for the compile unit that owns this function.
Definition Function.cpp: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:284
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:614
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
void ReportMissingOSOs(const CompileUnitInfo &missing_info)
Report missing object files once per module, not once per object file, to avoid flooding the console.
size_t ParseVariablesForContext(const SymbolContext &sc) override
llvm::SmallSet< lldb::LanguageType, 4 > ParseAllLanguages(CompileUnit &comp_unit) override
This function exists because SymbolFileDWARFDebugMap may extra compile units which aren't exposed as ...
uint32_t GetCompUnitInfoIndex(const CompileUnitInfo *comp_unit_info)
Module * GetModuleByCompUnitInfo(CompileUnitInfo *comp_unit_info)
size_t AddOSOARanges(SymbolFileDWARF *dwarf2Data, DWARFDebugAranges *debug_aranges)
void FindFunctions(const Module::LookupInfo &lookup_info, const CompilerDeclContext &parent_decl_ctx, bool include_inlines, SymbolContextList &sc_list) override
void GetTypes(SymbolContextScope *sc_scope, lldb::TypeClass type_mask, TypeList &type_list) override
llvm::Expected< SymbolContext > ResolveFunctionCallLabel(FunctionCallLabel &label) override
Resolves the function corresponding to the specified LLDB function call label.
bool AddOSOFileRange(CompileUnitInfo *cu_info, lldb::addr_t exe_file_addr, lldb::addr_t exe_byte_size, lldb::addr_t oso_file_addr, lldb::addr_t oso_byte_size)
bool ParseSupportFiles(CompileUnit &comp_unit, SupportFileList &support_files) override
void SetCompileUnit(SymbolFileDWARF *oso_dwarf, const lldb::CompUnitSP &cu_sp)
Type * ResolveTypeUID(lldb::user_id_t type_uid) override
static int SymbolContainsSymbolWithID(lldb::user_id_t *symbol_idx_ptr, const CompileUnitInfo *comp_unit_info)
static int SymbolContainsSymbolWithIndex(uint32_t *symbol_idx_ptr, const CompileUnitInfo *comp_unit_info)
uint32_t CalculateNumCompileUnits() override
This function actually returns the number of object files, which may be less than the actual number o...
bool ParseImportedModules(const SymbolContext &sc, std::vector< SourceModule > &imported_modules) override
lldb::TypeSP GetTypeEnclosingVariableUID(lldb::user_id_t uid) override
Get the semantically innermost non-function type that encloses the provided variable.
size_t GetCompUnitInfosForModule(const Module *oso_module, std::vector< CompileUnitInfo * > &cu_infos)
bool LinkOSOAddress(Address &addr)
Convert addr from a .o file address, to an executable address.
void InitializeObject() override
Initialize the SymbolFile object.
CompilerDeclContext GetDeclContextForUID(lldb::user_id_t uid) override
CompileUnitInfo * GetCompileUnitInfoForSymbolWithID(lldb::user_id_t symbol_id, uint32_t *oso_idx_ptr)
LineTable * LinkOSOLineTable(SymbolFileDWARF *oso_symfile, LineTable *line_table)
Given a line table full of lines with "file addresses" that are for a .o file represented by oso_symf...
CompilerDeclContext GetDeclContextContainingUID(lldb::user_id_t uid) override
void FindGlobalVariables(ConstString name, const CompilerDeclContext &parent_decl_ctx, uint32_t max_matches, VariableList &variables) override
virtual DWARFDIE FindDefinitionDIE(const DWARFDIE &die)
bool ForEachExternalModule(CompileUnit &, llvm::DenseSet< SymbolFile * > &, llvm::function_ref< bool(Module &)>) override
virtual lldb::TypeSP FindCompleteObjCDefinitionTypeForDIE(const DWARFDIE &die, ConstString type_name, bool must_be_implementation)
llvm::Expected< SymbolContext > ResolveFunctionCallLabel(FunctionCallLabel &label) override
Resolves the function corresponding to the specified LLDB function call label.
void SetDebugMapModule(const lldb::ModuleSP &module_sp)
void DumpClangAST(Stream &s, llvm::StringRef filter, bool show_colors) override
std::vector< CompilerContext > GetCompilerContextForUID(lldb::user_id_t uid) override
void FindTypes(const lldb_private::TypeQuery &match, lldb_private::TypeResults &results) override
Find types using a type-matching object that contains all search parameters.
size_t ParseVariablesForContext(const SymbolContext &sc) override
void GetCompileOptions(std::unordered_map< lldb::CompUnitSP, Args > &args) override
std::optional< ArrayInfo > GetDynamicArrayInfoForUID(lldb::user_id_t type_uid, const ExecutionContext *exe_ctx) override
If type_uid points to an array type, return its characteristics.
size_t ParseBlocksRecursive(Function &func) override
Type * ResolveTypeUID(lldb::user_id_t type_uid) override
size_t ParseFunctions(CompileUnit &comp_unit) override
bool ParseDebugMacros(CompileUnit &comp_unit) override
bool ParseSupportFiles(CompileUnit &comp_unit, SupportFileList &support_files) override
bool ParseImportedModules(const SymbolContext &sc, std::vector< SourceModule > &imported_modules) override
void GetTypes(SymbolContextScope *sc_scope, lldb::TypeClass type_mask, TypeList &type_list) override
void ParseDeclsForContext(CompilerDeclContext decl_ctx) override
size_t ParseTypes(CompileUnit &comp_unit) override
bool CompleteType(CompilerType &compiler_type) override
bool ParseLineTable(CompileUnit &comp_unit) override
lldb::TypeSP GetTypeEnclosingVariableUID(lldb::user_id_t uid) override
Get the semantically innermost non-function type that encloses the provided variable.
bool ParseIsOptimized(CompileUnit &comp_unit) override
void SetFileIndex(std::optional< uint64_t > file_index)
XcodeSDKAndSysroot ParseXcodeSDK(CompileUnit &comp_unit) override
Return the Xcode SDK comp_unit was compiled against.
void FindFunctions(const Module::LookupInfo &lookup_info, const CompilerDeclContext &parent_decl_ctx, bool include_inlines, SymbolContextList &sc_list) override
uint32_t ResolveSymbolContext(const Address &so_addr, lldb::SymbolContextItem resolve_scope, SymbolContext &sc) override
bool HasForwardDeclForCompilerType(const CompilerType &compiler_type)
CompilerDeclContext FindNamespace(ConstString name, const CompilerDeclContext &parent_decl_ctx, bool only_root_namespaces) override
Finds a namespace of name name and whose parent context is parent_decl_ctx.
std::vector< std::unique_ptr< CallEdge > > ParseCallEdgesInFunction(UserID func_id) override
lldb::LanguageType ParseLanguage(CompileUnit &comp_unit) override
CompilerDeclContext GetDeclContextForUID(lldb::user_id_t uid) override
std::optional< uint64_t > GetFileIndex() const
#define LLDB_INVALID_ADDRESS
#define UINT32_MAX
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition Log.h:338
int(* ComparisonFunction)(const void *, const void *)
IterationAction
Useful for callbacks whose return type indicates whether to continue iteration or short-circuit.
std::weak_ptr< lldb_private::Module > ModuleWP
std::shared_ptr< lldb_private::ObjectFile > ObjectFileSP
LanguageType
Programming language type.
@ eLanguageTypeUnknown
Unknown or invalid language value.
std::shared_ptr< lldb_private::Type > TypeSP
@ eSymbolTypeObjCClass
@ eSymbolTypeObjectFile
@ eSymbolTypeSourceFile
uint64_t user_id_t
Definition lldb-types.h:83
std::shared_ptr< lldb_private::Section > SectionSP
uint64_t addr_t
Definition lldb-types.h:80
std::shared_ptr< lldb_private::Module > ModuleSP
std::shared_ptr< lldb_private::CompileUnit > CompUnitSP
Holds parsed information about a function call label that LLDB attaches as an AsmLabel to function AS...
Definition Expression.h:110
lldb::user_id_t symbol_id
Unique identifier of the function symbol on which to perform the function call.
Definition Expression.h:122
BaseType GetRangeBase() const
Definition RangeMap.h:45
SizeType GetByteSize() const
Definition RangeMap.h:87
BaseType GetRangeEnd() const
Definition RangeMap.h:78
A mix in class that contains a generic user ID.
Definition UserID.h:31
lldb::user_id_t GetID() const
Get accessor for the user ID.
Definition UserID.h:47
const FileRangeMap & GetFileRangeMap(SymbolFileDWARFDebugMap *exe_symfile)