1 //===-- Module.cpp ----------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/Core/Module.h"
14 // Other libraries and framework includes
15 #include "llvm/Support/raw_os_ostream.h"
16 #include "llvm/Support/Signals.h"
19 #include "lldb/Core/AddressResolverFileLine.h"
20 #include "lldb/Core/Error.h"
21 #include "lldb/Core/DataBuffer.h"
22 #include "lldb/Core/DataBufferHeap.h"
23 #include "lldb/Core/Log.h"
24 #include "lldb/Core/ModuleList.h"
25 #include "lldb/Core/ModuleSpec.h"
26 #include "lldb/Core/PluginManager.h"
27 #include "lldb/Core/RegularExpression.h"
28 #include "lldb/Core/Section.h"
29 #include "lldb/Core/StreamString.h"
30 #include "lldb/Core/Timer.h"
31 #include "lldb/Host/Host.h"
32 #include "lldb/Host/Symbols.h"
33 #include "lldb/Interpreter/CommandInterpreter.h"
34 #include "lldb/Interpreter/ScriptInterpreter.h"
35 #include "lldb/Symbol/CompileUnit.h"
36 #include "lldb/Symbol/ObjectFile.h"
37 #include "lldb/Symbol/SymbolContext.h"
38 #include "lldb/Symbol/SymbolFile.h"
39 #include "lldb/Symbol/SymbolVendor.h"
40 #include "lldb/Symbol/TypeSystem.h"
41 #include "lldb/Target/Language.h"
42 #include "lldb/Target/Process.h"
43 #include "lldb/Target/SectionLoadList.h"
44 #include "lldb/Target/Target.h"
45 #include "Plugins/Language/CPlusPlus/CPlusPlusLanguage.h"
46 #include "Plugins/Language/ObjC/ObjCLanguage.h"
47 #include "lldb/Symbol/TypeMap.h"
49 #include "Plugins/ObjectFile/JIT/ObjectFileJIT.h"
52 using namespace lldb_private;
54 // Shared pointers to modules track module lifetimes in
55 // targets and in the global module, but this collection
56 // will track all module objects that are still alive
57 typedef std::vector<Module *> ModuleCollection;
59 static ModuleCollection &
62 // This module collection needs to live past any module, so we could either make it a
63 // shared pointer in each module or just leak is. Since it is only an empty vector by
64 // the time all the modules have gone away, we just leak it for now. If we decide this
65 // is a big problem we can introduce a Finalize method that will tear everything down in
66 // a predictable order.
68 static ModuleCollection *g_module_collection = nullptr;
69 if (g_module_collection == nullptr)
70 g_module_collection = new ModuleCollection();
72 return *g_module_collection;
75 std::recursive_mutex &
76 Module::GetAllocationModuleCollectionMutex()
78 // NOTE: The mutex below must be leaked since the global module list in
79 // the ModuleList class will get torn at some point, and we can't know
80 // if it will tear itself down before the "g_module_collection_mutex" below
81 // will. So we leak a Mutex object below to safeguard against that
83 static std::recursive_mutex *g_module_collection_mutex = nullptr;
84 if (g_module_collection_mutex == nullptr)
85 g_module_collection_mutex = new std::recursive_mutex; // NOTE: known leak
86 return *g_module_collection_mutex;
90 Module::GetNumberAllocatedModules ()
92 std::lock_guard<std::recursive_mutex> guard(GetAllocationModuleCollectionMutex());
93 return GetModuleCollection().size();
97 Module::GetAllocatedModuleAtIndex (size_t idx)
99 std::lock_guard<std::recursive_mutex> guard(GetAllocationModuleCollectionMutex());
100 ModuleCollection &modules = GetModuleCollection();
101 if (idx < modules.size())
107 // These functions help us to determine if modules are still loaded, yet don't require that
108 // you have a command interpreter and can easily be called from an external debugger.
112 ClearModuleInfo (void)
114 const bool mandatory = true;
115 ModuleList::RemoveOrphanSharedModules(mandatory);
119 DumpModuleInfo (void)
121 Mutex::Locker locker (Module::GetAllocationModuleCollectionMutex());
122 ModuleCollection &modules = GetModuleCollection();
123 const size_t count = modules.size();
124 printf ("%s: %" PRIu64 " modules:\n", __PRETTY_FUNCTION__, (uint64_t)count);
125 for (size_t i = 0; i < count; ++i)
129 Module *module = modules[i];
130 const bool in_shared_module_list = ModuleList::ModuleIsInCache (module);
131 module->GetDescription(&strm, eDescriptionLevelFull);
132 printf ("%p: shared = %i, ref_count = %3u, module = %s\n",
134 in_shared_module_list,
135 (uint32_t)module->use_count(),
136 strm.GetString().c_str());
143 Module::Module(const ModuleSpec &module_spec)
150 m_remote_install_file(),
160 m_did_load_objfile(false),
161 m_did_load_symbol_vendor(false),
162 m_did_parse_uuid(false),
163 m_file_has_changed(false),
164 m_first_file_changed_log(false)
166 // Scope for locker below...
168 std::lock_guard<std::recursive_mutex> guard(GetAllocationModuleCollectionMutex());
169 GetModuleCollection().push_back(this);
172 Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_OBJECT | LIBLLDB_LOG_MODULES));
174 log->Printf("%p Module::Module((%s) '%s%s%s%s')", static_cast<void *>(this),
175 module_spec.GetArchitecture().GetArchitectureName(), module_spec.GetFileSpec().GetPath().c_str(),
176 module_spec.GetObjectName().IsEmpty() ? "" : "(",
177 module_spec.GetObjectName().IsEmpty() ? "" : module_spec.GetObjectName().AsCString(""),
178 module_spec.GetObjectName().IsEmpty() ? "" : ")");
180 // First extract all module specifications from the file using the local
181 // file path. If there are no specifications, then don't fill anything in
182 ModuleSpecList modules_specs;
183 if (ObjectFile::GetModuleSpecifications(module_spec.GetFileSpec(), 0, 0, modules_specs) == 0)
186 // Now make sure that one of the module specifications matches what we just
187 // extract. We might have a module specification that specifies a file "/usr/lib/dyld"
188 // with UUID XXX, but we might have a local version of "/usr/lib/dyld" that has
189 // UUID YYY and we don't want those to match. If they don't match, just don't
190 // fill any ivars in so we don't accidentally grab the wrong file later since
191 // they don't match...
192 ModuleSpec matching_module_spec;
193 if (modules_specs.FindMatchingModuleSpec(module_spec, matching_module_spec) == 0)
196 if (module_spec.GetFileSpec())
197 m_mod_time = module_spec.GetFileSpec().GetModificationTime();
198 else if (matching_module_spec.GetFileSpec())
199 m_mod_time = matching_module_spec.GetFileSpec().GetModificationTime();
201 // Copy the architecture from the actual spec if we got one back, else use the one that was specified
202 if (matching_module_spec.GetArchitecture().IsValid())
203 m_arch = matching_module_spec.GetArchitecture();
204 else if (module_spec.GetArchitecture().IsValid())
205 m_arch = module_spec.GetArchitecture();
207 // Copy the file spec over and use the specified one (if there was one) so we
208 // don't use a path that might have gotten resolved a path in 'matching_module_spec'
209 if (module_spec.GetFileSpec())
210 m_file = module_spec.GetFileSpec();
211 else if (matching_module_spec.GetFileSpec())
212 m_file = matching_module_spec.GetFileSpec();
214 // Copy the platform file spec over
215 if (module_spec.GetPlatformFileSpec())
216 m_platform_file = module_spec.GetPlatformFileSpec();
217 else if (matching_module_spec.GetPlatformFileSpec())
218 m_platform_file = matching_module_spec.GetPlatformFileSpec();
220 // Copy the symbol file spec over
221 if (module_spec.GetSymbolFileSpec())
222 m_symfile_spec = module_spec.GetSymbolFileSpec();
223 else if (matching_module_spec.GetSymbolFileSpec())
224 m_symfile_spec = matching_module_spec.GetSymbolFileSpec();
226 // Copy the object name over
227 if (matching_module_spec.GetObjectName())
228 m_object_name = matching_module_spec.GetObjectName();
230 m_object_name = module_spec.GetObjectName();
232 // Always trust the object offset (file offset) and object modification
233 // time (for mod time in a BSD static archive) of from the matching
234 // module specification
235 m_object_offset = matching_module_spec.GetObjectOffset();
236 m_object_mod_time = matching_module_spec.GetObjectModificationTime();
239 Module::Module(const FileSpec &file_spec, const ArchSpec &arch, const ConstString *object_name,
240 lldb::offset_t object_offset, const TimeValue *object_mod_time_ptr)
242 m_mod_time(file_spec.GetModificationTime()),
247 m_remote_install_file(),
250 m_object_offset(object_offset),
257 m_did_load_objfile(false),
258 m_did_load_symbol_vendor(false),
259 m_did_parse_uuid(false),
260 m_file_has_changed(false),
261 m_first_file_changed_log(false)
263 // Scope for locker below...
265 std::lock_guard<std::recursive_mutex> guard(GetAllocationModuleCollectionMutex());
266 GetModuleCollection().push_back(this);
270 m_object_name = *object_name;
272 if (object_mod_time_ptr)
273 m_object_mod_time = *object_mod_time_ptr;
275 Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_OBJECT | LIBLLDB_LOG_MODULES));
277 log->Printf("%p Module::Module((%s) '%s%s%s%s')", static_cast<void *>(this), m_arch.GetArchitectureName(),
278 m_file.GetPath().c_str(), m_object_name.IsEmpty() ? "" : "(",
279 m_object_name.IsEmpty() ? "" : m_object_name.AsCString(""), m_object_name.IsEmpty() ? "" : ")");
289 m_remote_install_file(),
299 m_did_load_objfile(false),
300 m_did_load_symbol_vendor(false),
301 m_did_parse_uuid(false),
302 m_file_has_changed(false),
303 m_first_file_changed_log(false)
305 std::lock_guard<std::recursive_mutex> guard(GetAllocationModuleCollectionMutex());
306 GetModuleCollection().push_back(this);
311 // Lock our module down while we tear everything down to make sure
312 // we don't get any access to the module while it is being destroyed
313 std::lock_guard<std::recursive_mutex> guard(m_mutex);
314 // Scope for locker below...
316 std::lock_guard<std::recursive_mutex> guard(GetAllocationModuleCollectionMutex());
317 ModuleCollection &modules = GetModuleCollection();
318 ModuleCollection::iterator end = modules.end();
319 ModuleCollection::iterator pos = std::find(modules.begin(), end, this);
323 Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_OBJECT|LIBLLDB_LOG_MODULES));
325 log->Printf ("%p Module::~Module((%s) '%s%s%s%s')",
326 static_cast<void*>(this),
327 m_arch.GetArchitectureName(),
328 m_file.GetPath().c_str(),
329 m_object_name.IsEmpty() ? "" : "(",
330 m_object_name.IsEmpty() ? "" : m_object_name.AsCString(""),
331 m_object_name.IsEmpty() ? "" : ")");
332 // Release any auto pointers before we start tearing down our member
333 // variables since the object file and symbol files might need to make
334 // function calls back into this module object. The ordering is important
335 // here because symbol files can require the module object file. So we tear
336 // down the symbol file first, then the object file.
337 m_sections_ap.reset();
338 m_symfile_ap.reset();
339 m_objfile_sp.reset();
343 Module::GetMemoryObjectFile (const lldb::ProcessSP &process_sp, lldb::addr_t header_addr, Error &error, size_t size_to_read)
347 error.SetErrorString ("object file already exists");
351 std::lock_guard<std::recursive_mutex> guard(m_mutex);
354 m_did_load_objfile = true;
355 std::unique_ptr<DataBufferHeap> data_ap (new DataBufferHeap (size_to_read, 0));
357 const size_t bytes_read = process_sp->ReadMemory (header_addr,
359 data_ap->GetByteSize(),
361 if (bytes_read == size_to_read)
363 DataBufferSP data_sp(data_ap.release());
364 m_objfile_sp = ObjectFile::FindPlugin(shared_from_this(), process_sp, header_addr, data_sp);
368 s.Printf("0x%16.16" PRIx64, header_addr);
369 m_object_name.SetCString (s.GetData());
371 // Once we get the object file, update our module with the object file's
372 // architecture since it might differ in vendor/os if some parts were
374 m_objfile_sp->GetArchitecture (m_arch);
378 error.SetErrorString ("unable to find suitable object file plug-in");
383 error.SetErrorStringWithFormat ("unable to read header from memory: %s", readmem_error.AsCString());
388 error.SetErrorString ("invalid process");
391 return m_objfile_sp.get();
394 const lldb_private::UUID&
397 if (!m_did_parse_uuid.load())
399 std::lock_guard<std::recursive_mutex> guard(m_mutex);
400 if (!m_did_parse_uuid.load())
402 ObjectFile * obj_file = GetObjectFile ();
404 if (obj_file != nullptr)
406 obj_file->GetUUID(&m_uuid);
407 m_did_parse_uuid = true;
415 Module::GetTypeSystemForLanguage (LanguageType language)
417 return m_type_system_map.GetTypeSystemForLanguage(language, this, true);
421 Module::ParseAllDebugSymbols()
423 std::lock_guard<std::recursive_mutex> guard(m_mutex);
424 size_t num_comp_units = GetNumCompileUnits();
425 if (num_comp_units == 0)
429 sc.module_sp = shared_from_this();
430 SymbolVendor *symbols = GetSymbolVendor ();
432 for (size_t cu_idx = 0; cu_idx < num_comp_units; cu_idx++)
434 sc.comp_unit = symbols->GetCompileUnitAtIndex(cu_idx).get();
437 sc.function = nullptr;
438 symbols->ParseVariablesForContext(sc);
440 symbols->ParseCompileUnitFunctions(sc);
442 for (size_t func_idx = 0; (sc.function = sc.comp_unit->GetFunctionAtIndex(func_idx).get()) != nullptr; ++func_idx)
444 symbols->ParseFunctionBlocks(sc);
446 // Parse the variables for this function and all its blocks
447 symbols->ParseVariablesForContext(sc);
450 // Parse all types for this compile unit
451 sc.function = nullptr;
452 symbols->ParseTypes(sc);
458 Module::CalculateSymbolContext(SymbolContext* sc)
460 sc->module_sp = shared_from_this();
464 Module::CalculateSymbolContextModule ()
466 return shared_from_this();
470 Module::DumpSymbolContext(Stream *s)
472 s->Printf(", Module{%p}", static_cast<void*>(this));
476 Module::GetNumCompileUnits()
478 std::lock_guard<std::recursive_mutex> guard(m_mutex);
479 Timer scoped_timer(__PRETTY_FUNCTION__,
480 "Module::GetNumCompileUnits (module = %p)",
481 static_cast<void*>(this));
482 SymbolVendor *symbols = GetSymbolVendor ();
484 return symbols->GetNumCompileUnits();
489 Module::GetCompileUnitAtIndex (size_t index)
491 std::lock_guard<std::recursive_mutex> guard(m_mutex);
492 size_t num_comp_units = GetNumCompileUnits ();
495 if (index < num_comp_units)
497 SymbolVendor *symbols = GetSymbolVendor ();
499 cu_sp = symbols->GetCompileUnitAtIndex(index);
505 Module::ResolveFileAddress (lldb::addr_t vm_addr, Address& so_addr)
507 std::lock_guard<std::recursive_mutex> guard(m_mutex);
508 Timer scoped_timer(__PRETTY_FUNCTION__, "Module::ResolveFileAddress (vm_addr = 0x%" PRIx64 ")", vm_addr);
509 SectionList *section_list = GetSectionList();
511 return so_addr.ResolveAddressUsingFileSections(vm_addr, section_list);
516 Module::ResolveSymbolContextForAddress (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc,
517 bool resolve_tail_call_address)
519 std::lock_guard<std::recursive_mutex> guard(m_mutex);
520 uint32_t resolved_flags = 0;
522 // Clear the result symbol context in case we don't find anything, but don't clear the target
525 // Get the section from the section/offset address.
526 SectionSP section_sp (so_addr.GetSection());
528 // Make sure the section matches this module before we try and match anything
529 if (section_sp && section_sp->GetModule().get() == this)
531 // If the section offset based address resolved itself, then this
532 // is the right module.
533 sc.module_sp = shared_from_this();
534 resolved_flags |= eSymbolContextModule;
536 SymbolVendor* sym_vendor = GetSymbolVendor();
538 return resolved_flags;
540 // Resolve the compile unit, function, block, line table or line
541 // entry if requested.
542 if (resolve_scope & eSymbolContextCompUnit ||
543 resolve_scope & eSymbolContextFunction ||
544 resolve_scope & eSymbolContextBlock ||
545 resolve_scope & eSymbolContextLineEntry ||
546 resolve_scope & eSymbolContextVariable )
548 resolved_flags |= sym_vendor->ResolveSymbolContext (so_addr, resolve_scope, sc);
551 // Resolve the symbol if requested, but don't re-look it up if we've already found it.
552 if (resolve_scope & eSymbolContextSymbol && !(resolved_flags & eSymbolContextSymbol))
554 Symtab *symtab = sym_vendor->GetSymtab();
555 if (symtab && so_addr.IsSectionOffset())
557 Symbol *matching_symbol = nullptr;
559 symtab->ForEachSymbolContainingFileAddress(so_addr.GetFileAddress(),
560 [&matching_symbol](Symbol *symbol) -> bool {
561 if (symbol->GetType() != eSymbolTypeInvalid)
563 matching_symbol = symbol;
564 return false; // Stop iterating
566 return true; // Keep iterating
568 sc.symbol = matching_symbol;
570 resolve_scope & eSymbolContextFunction && !(resolved_flags & eSymbolContextFunction))
572 bool verify_unique = false; // No need to check again since ResolveSymbolContext failed to find a symbol at this address.
573 if (ObjectFile *obj_file = sc.module_sp->GetObjectFile())
574 sc.symbol = obj_file->ResolveSymbolForAddress(so_addr, verify_unique);
579 if (sc.symbol->IsSynthetic())
581 // We have a synthetic symbol so lets check if the object file
582 // from the symbol file in the symbol vendor is different than
583 // the object file for the module, and if so search its symbol
584 // table to see if we can come up with a better symbol. For example
585 // dSYM files on MacOSX have an unstripped symbol table inside of
587 ObjectFile *symtab_objfile = symtab->GetObjectFile();
588 if (symtab_objfile && symtab_objfile->IsStripped())
590 SymbolFile *symfile = sym_vendor->GetSymbolFile();
593 ObjectFile *symfile_objfile = symfile->GetObjectFile();
594 if (symfile_objfile != symtab_objfile)
596 Symtab *symfile_symtab = symfile_objfile->GetSymtab();
599 Symbol *symbol = symfile_symtab->FindSymbolContainingFileAddress(so_addr.GetFileAddress());
600 if (symbol && !symbol->IsSynthetic())
609 resolved_flags |= eSymbolContextSymbol;
614 // For function symbols, so_addr may be off by one. This is a convention consistent
615 // with FDE row indices in eh_frame sections, but requires extra logic here to permit
616 // symbol lookup for disassembly and unwind.
617 if (resolve_scope & eSymbolContextSymbol && !(resolved_flags & eSymbolContextSymbol) &&
618 resolve_tail_call_address && so_addr.IsSectionOffset())
620 Address previous_addr = so_addr;
621 previous_addr.Slide(-1);
623 bool do_resolve_tail_call_address = false; // prevent recursion
624 const uint32_t flags = ResolveSymbolContextForAddress(previous_addr, resolve_scope, sc,
625 do_resolve_tail_call_address);
626 if (flags & eSymbolContextSymbol)
628 AddressRange addr_range;
629 if (sc.GetAddressRange (eSymbolContextFunction | eSymbolContextSymbol, 0, false, addr_range))
631 if (addr_range.GetBaseAddress().GetSection() == so_addr.GetSection())
633 // If the requested address is one past the address range of a function (i.e. a tail call),
634 // or the decremented address is the start of a function (i.e. some forms of trampoline),
635 // indicate that the symbol has been resolved.
636 if (so_addr.GetOffset() == addr_range.GetBaseAddress().GetOffset() ||
637 so_addr.GetOffset() == addr_range.GetBaseAddress().GetOffset() + addr_range.GetByteSize())
639 resolved_flags |= flags;
644 sc.symbol = nullptr; // Don't trust the symbol if the sections didn't match.
650 return resolved_flags;
654 Module::ResolveSymbolContextForFilePath
656 const char *file_path,
659 uint32_t resolve_scope,
660 SymbolContextList& sc_list
663 FileSpec file_spec(file_path, false);
664 return ResolveSymbolContextsForFileSpec (file_spec, line, check_inlines, resolve_scope, sc_list);
668 Module::ResolveSymbolContextsForFileSpec (const FileSpec &file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list)
670 std::lock_guard<std::recursive_mutex> guard(m_mutex);
671 Timer scoped_timer(__PRETTY_FUNCTION__,
672 "Module::ResolveSymbolContextForFilePath (%s:%u, check_inlines = %s, resolve_scope = 0x%8.8x)",
673 file_spec.GetPath().c_str(),
675 check_inlines ? "yes" : "no",
678 const uint32_t initial_count = sc_list.GetSize();
680 SymbolVendor *symbols = GetSymbolVendor ();
682 symbols->ResolveSymbolContext (file_spec, line, check_inlines, resolve_scope, sc_list);
684 return sc_list.GetSize() - initial_count;
688 Module::FindGlobalVariables (const ConstString &name,
689 const CompilerDeclContext *parent_decl_ctx,
692 VariableList& variables)
694 SymbolVendor *symbols = GetSymbolVendor ();
696 return symbols->FindGlobalVariables(name, parent_decl_ctx, append, max_matches, variables);
701 Module::FindGlobalVariables (const RegularExpression& regex,
704 VariableList& variables)
706 SymbolVendor *symbols = GetSymbolVendor ();
708 return symbols->FindGlobalVariables(regex, append, max_matches, variables);
713 Module::FindCompileUnits (const FileSpec &path,
715 SymbolContextList &sc_list)
720 const size_t start_size = sc_list.GetSize();
721 const size_t num_compile_units = GetNumCompileUnits();
723 sc.module_sp = shared_from_this();
724 const bool compare_directory = (bool)path.GetDirectory();
725 for (size_t i = 0; i < num_compile_units; ++i)
727 sc.comp_unit = GetCompileUnitAtIndex(i).get();
730 if (FileSpec::Equal (*sc.comp_unit, path, compare_directory))
734 return sc_list.GetSize() - start_size;
737 Module::LookupInfo::LookupInfo(const ConstString &name, uint32_t name_type_mask, lldb::LanguageType language) :
740 m_language(language),
742 m_match_name_after_lookup(false)
744 const char *name_cstr = name.GetCString();
745 llvm::StringRef basename;
746 llvm::StringRef context;
748 if (name_type_mask & eFunctionNameTypeAuto)
750 if (CPlusPlusLanguage::IsCPPMangledName (name_cstr))
751 m_name_type_mask = eFunctionNameTypeFull;
752 else if ((language == eLanguageTypeUnknown ||
753 Language::LanguageIsObjC(language)) &&
754 ObjCLanguage::IsPossibleObjCMethodName (name_cstr))
755 m_name_type_mask = eFunctionNameTypeFull;
756 else if (Language::LanguageIsC(language))
758 m_name_type_mask = eFunctionNameTypeFull;
762 if ((language == eLanguageTypeUnknown ||
763 Language::LanguageIsObjC(language)) &&
764 ObjCLanguage::IsPossibleObjCSelector(name_cstr))
765 m_name_type_mask |= eFunctionNameTypeSelector;
767 CPlusPlusLanguage::MethodName cpp_method (name);
768 basename = cpp_method.GetBasename();
769 if (basename.empty())
771 if (CPlusPlusLanguage::ExtractContextAndIdentifier (name_cstr, context, basename))
772 m_name_type_mask |= (eFunctionNameTypeMethod | eFunctionNameTypeBase);
774 m_name_type_mask |= eFunctionNameTypeFull;
778 m_name_type_mask |= (eFunctionNameTypeMethod | eFunctionNameTypeBase);
784 m_name_type_mask = name_type_mask;
785 if (name_type_mask & eFunctionNameTypeMethod || name_type_mask & eFunctionNameTypeBase)
787 // If they've asked for a CPP method or function name and it can't be that, we don't
788 // even need to search for CPP methods or names.
789 CPlusPlusLanguage::MethodName cpp_method (name);
790 if (cpp_method.IsValid())
792 basename = cpp_method.GetBasename();
794 if (!cpp_method.GetQualifiers().empty())
796 // There is a "const" or other qualifier following the end of the function parens,
797 // this can't be a eFunctionNameTypeBase
798 m_name_type_mask &= ~(eFunctionNameTypeBase);
799 if (m_name_type_mask == eFunctionNameTypeNone)
805 // If the CPP method parser didn't manage to chop this up, try to fill in the base name if we can.
806 // If a::b::c is passed in, we need to just look up "c", and then we'll filter the result later.
807 CPlusPlusLanguage::ExtractContextAndIdentifier (name_cstr, context, basename);
811 if (name_type_mask & eFunctionNameTypeSelector)
813 if (!ObjCLanguage::IsPossibleObjCSelector(name_cstr))
815 m_name_type_mask &= ~(eFunctionNameTypeSelector);
816 if (m_name_type_mask == eFunctionNameTypeNone)
821 // Still try and get a basename in case someone specifies a name type mask of
822 // eFunctionNameTypeFull and a name like "A::func"
823 if (basename.empty())
825 if (name_type_mask & eFunctionNameTypeFull)
827 CPlusPlusLanguage::MethodName cpp_method (name);
828 basename = cpp_method.GetBasename();
829 if (basename.empty())
830 CPlusPlusLanguage::ExtractContextAndIdentifier (name_cstr, context, basename);
835 if (!basename.empty())
837 // The name supplied was a partial C++ path like "a::count". In this case we want to do a
838 // lookup on the basename "count" and then make sure any matching results contain "a::count"
839 // so that it would match "b::a::count" and "a::count". This is why we set "match_name_after_lookup"
841 m_lookup_name.SetString(basename);
842 m_match_name_after_lookup = true;
846 // The name is already correct, just use the exact name as supplied, and we won't need
847 // to check if any matches contain "name"
848 m_lookup_name = name;
849 m_match_name_after_lookup = false;
855 Module::LookupInfo::Prune(SymbolContextList &sc_list, size_t start_idx) const
857 if (m_match_name_after_lookup && m_name)
860 size_t i = start_idx;
861 while (i < sc_list.GetSize())
863 if (!sc_list.GetContextAtIndex(i, sc))
865 ConstString full_name(sc.GetFunctionName());
866 if (full_name && ::strstr(full_name.GetCString(), m_name.GetCString()) == nullptr)
868 sc_list.RemoveContextAtIndex(i);
877 // If we have only full name matches we might have tried to set breakpoint on "func"
878 // and specified eFunctionNameTypeFull, but we might have found "a::func()",
879 // "a::b::func()", "c::func()", "func()" and "func". Only "func()" and "func" should
881 if (m_name_type_mask == eFunctionNameTypeFull)
884 size_t i = start_idx;
885 while (i < sc_list.GetSize())
887 if (!sc_list.GetContextAtIndex(i, sc))
889 ConstString full_name(sc.GetFunctionName());
890 CPlusPlusLanguage::MethodName cpp_method(full_name);
891 if (cpp_method.IsValid())
893 if (cpp_method.GetContext().empty())
895 if (cpp_method.GetBasename().compare(m_name.GetStringRef()) != 0)
897 sc_list.RemoveContextAtIndex(i);
903 std::string qualified_name = cpp_method.GetScopeQualifiedName();
904 if (qualified_name.compare(m_name.GetCString()) != 0)
906 sc_list.RemoveContextAtIndex(i);
918 Module::FindFunctions (const ConstString &name,
919 const CompilerDeclContext *parent_decl_ctx,
920 uint32_t name_type_mask,
921 bool include_symbols,
922 bool include_inlines,
924 SymbolContextList& sc_list)
929 const size_t old_size = sc_list.GetSize();
931 // Find all the functions (not symbols, but debug information functions...
932 SymbolVendor *symbols = GetSymbolVendor ();
934 if (name_type_mask & eFunctionNameTypeAuto)
936 LookupInfo lookup_info(name, name_type_mask, eLanguageTypeUnknown);
940 symbols->FindFunctions(lookup_info.GetLookupName(),
942 lookup_info.GetNameTypeMask(),
947 // Now check our symbol table for symbols that are code symbols if requested
950 Symtab *symtab = symbols->GetSymtab();
952 symtab->FindFunctionSymbols(lookup_info.GetLookupName(), lookup_info.GetNameTypeMask(), sc_list);
956 const size_t new_size = sc_list.GetSize();
958 if (old_size < new_size)
959 lookup_info.Prune (sc_list, old_size);
965 symbols->FindFunctions(name, parent_decl_ctx, name_type_mask, include_inlines, append, sc_list);
967 // Now check our symbol table for symbols that are code symbols if requested
970 Symtab *symtab = symbols->GetSymtab();
972 symtab->FindFunctionSymbols(name, name_type_mask, sc_list);
977 return sc_list.GetSize() - old_size;
981 Module::FindFunctions (const RegularExpression& regex,
982 bool include_symbols,
983 bool include_inlines,
985 SymbolContextList& sc_list)
990 const size_t start_size = sc_list.GetSize();
992 SymbolVendor *symbols = GetSymbolVendor ();
995 symbols->FindFunctions(regex, include_inlines, append, sc_list);
997 // Now check our symbol table for symbols that are code symbols if requested
1000 Symtab *symtab = symbols->GetSymtab();
1003 std::vector<uint32_t> symbol_indexes;
1004 symtab->AppendSymbolIndexesMatchingRegExAndType (regex, eSymbolTypeAny, Symtab::eDebugAny, Symtab::eVisibilityAny, symbol_indexes);
1005 const size_t num_matches = symbol_indexes.size();
1008 SymbolContext sc(this);
1009 const size_t end_functions_added_index = sc_list.GetSize();
1010 size_t num_functions_added_to_sc_list = end_functions_added_index - start_size;
1011 if (num_functions_added_to_sc_list == 0)
1013 // No functions were added, just symbols, so we can just append them
1014 for (size_t i = 0; i < num_matches; ++i)
1016 sc.symbol = symtab->SymbolAtIndex(symbol_indexes[i]);
1017 SymbolType sym_type = sc.symbol->GetType();
1018 if (sc.symbol && (sym_type == eSymbolTypeCode ||
1019 sym_type == eSymbolTypeResolver))
1025 typedef std::map<lldb::addr_t, uint32_t> FileAddrToIndexMap;
1026 FileAddrToIndexMap file_addr_to_index;
1027 for (size_t i = start_size; i < end_functions_added_index; ++i)
1029 const SymbolContext &sc = sc_list[i];
1032 file_addr_to_index[sc.function->GetAddressRange().GetBaseAddress().GetFileAddress()] = i;
1035 FileAddrToIndexMap::const_iterator end = file_addr_to_index.end();
1036 // Functions were added so we need to merge symbols into any
1037 // existing function symbol contexts
1038 for (size_t i = start_size; i < num_matches; ++i)
1040 sc.symbol = symtab->SymbolAtIndex(symbol_indexes[i]);
1041 SymbolType sym_type = sc.symbol->GetType();
1042 if (sc.symbol && sc.symbol->ValueIsAddress() && (sym_type == eSymbolTypeCode || sym_type == eSymbolTypeResolver))
1044 FileAddrToIndexMap::const_iterator pos = file_addr_to_index.find(sc.symbol->GetAddressRef().GetFileAddress());
1048 sc_list[pos->second].symbol = sc.symbol;
1056 return sc_list.GetSize() - start_size;
1060 Module::FindAddressesForLine (const lldb::TargetSP target_sp,
1061 const FileSpec &file, uint32_t line,
1063 std::vector<Address> &output_local, std::vector<Address> &output_extern)
1065 SearchFilterByModule filter(target_sp, m_file);
1066 AddressResolverFileLine resolver(file, line, true);
1067 resolver.ResolveAddress (filter);
1069 for (size_t n = 0; n < resolver.GetNumberOfAddresses(); n++)
1071 Address addr = resolver.GetAddressRangeAtIndex(n).GetBaseAddress();
1072 Function *f = addr.CalculateSymbolContextFunction();
1073 if (f && f == function)
1074 output_local.push_back (addr);
1076 output_extern.push_back (addr);
1081 Module::FindTypes_Impl (const SymbolContext& sc,
1082 const ConstString &name,
1083 const CompilerDeclContext *parent_decl_ctx,
1086 llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
1089 Timer scoped_timer(__PRETTY_FUNCTION__, __PRETTY_FUNCTION__);
1090 if (!sc.module_sp || sc.module_sp.get() == this)
1092 SymbolVendor *symbols = GetSymbolVendor ();
1094 return symbols->FindTypes(sc, name, parent_decl_ctx, append, max_matches, searched_symbol_files, types);
1100 Module::FindTypesInNamespace (const SymbolContext& sc,
1101 const ConstString &type_name,
1102 const CompilerDeclContext *parent_decl_ctx,
1104 TypeList& type_list)
1106 const bool append = true;
1108 llvm::DenseSet<lldb_private::SymbolFile *> searched_symbol_files;
1109 size_t num_types = FindTypes_Impl(sc, type_name, parent_decl_ctx, append, max_matches, searched_symbol_files, types_map);
1111 sc.SortTypeList(types_map, type_list);
1116 Module::FindFirstType (const SymbolContext& sc,
1117 const ConstString &name,
1121 llvm::DenseSet<lldb_private::SymbolFile *> searched_symbol_files;
1122 const size_t num_matches = FindTypes (sc, name, exact_match, 1, searched_symbol_files, type_list);
1124 return type_list.GetTypeAtIndex(0);
1129 Module::FindTypes (const SymbolContext& sc,
1130 const ConstString &name,
1133 llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
1136 size_t num_matches = 0;
1137 const char *type_name_cstr = name.GetCString();
1138 std::string type_scope;
1139 std::string type_basename;
1140 const bool append = true;
1141 TypeClass type_class = eTypeClassAny;
1143 if (Type::GetTypeScopeAndBasename (type_name_cstr, type_scope, type_basename, type_class))
1145 // Check if "name" starts with "::" which means the qualified type starts
1146 // from the root namespace and implies and exact match. The typenames we
1147 // get back from clang do not start with "::" so we need to strip this off
1148 // in order to get the qualified names to match
1150 if (type_scope.size() >= 2 && type_scope[0] == ':' && type_scope[1] == ':')
1152 type_scope.erase(0,2);
1155 ConstString type_basename_const_str (type_basename.c_str());
1156 if (FindTypes_Impl(sc, type_basename_const_str, nullptr, append, max_matches, searched_symbol_files, typesmap))
1158 typesmap.RemoveMismatchedTypes (type_scope, type_basename, type_class, exact_match);
1159 num_matches = typesmap.GetSize();
1164 // The type is not in a namespace/class scope, just search for it by basename
1165 if (type_class != eTypeClassAny)
1167 // The "type_name_cstr" will have been modified if we have a valid type class
1168 // prefix (like "struct", "class", "union", "typedef" etc).
1169 FindTypes_Impl(sc, ConstString(type_name_cstr), nullptr, append, max_matches, searched_symbol_files, typesmap);
1170 typesmap.RemoveMismatchedTypes (type_class);
1171 num_matches = typesmap.GetSize();
1175 num_matches = FindTypes_Impl(sc, name, nullptr, append, max_matches, searched_symbol_files, typesmap);
1178 if (num_matches > 0)
1179 sc.SortTypeList(typesmap, types);
1184 Module::GetSymbolVendor (bool can_create, lldb_private::Stream *feedback_strm)
1186 if (!m_did_load_symbol_vendor.load())
1188 std::lock_guard<std::recursive_mutex> guard(m_mutex);
1189 if (!m_did_load_symbol_vendor.load() && can_create)
1191 ObjectFile *obj_file = GetObjectFile ();
1192 if (obj_file != nullptr)
1194 Timer scoped_timer(__PRETTY_FUNCTION__, __PRETTY_FUNCTION__);
1195 m_symfile_ap.reset(SymbolVendor::FindPlugin(shared_from_this(), feedback_strm));
1196 m_did_load_symbol_vendor = true;
1200 return m_symfile_ap.get();
1204 Module::SetFileSpecAndObjectName (const FileSpec &file, const ConstString &object_name)
1206 // Container objects whose paths do not specify a file directly can call
1207 // this function to correct the file and object names.
1209 m_mod_time = file.GetModificationTime();
1210 m_object_name = object_name;
1214 Module::GetArchitecture () const
1220 Module::GetSpecificationDescription () const
1222 std::string spec(GetFileSpec().GetPath());
1226 spec += m_object_name.GetCString();
1233 Module::GetDescription (Stream *s, lldb::DescriptionLevel level)
1235 std::lock_guard<std::recursive_mutex> guard(m_mutex);
1237 if (level >= eDescriptionLevelFull)
1239 if (m_arch.IsValid())
1240 s->Printf("(%s) ", m_arch.GetArchitectureName());
1243 if (level == eDescriptionLevelBrief)
1245 const char *filename = m_file.GetFilename().GetCString();
1247 s->PutCString (filename);
1251 char path[PATH_MAX];
1252 if (m_file.GetPath(path, sizeof(path)))
1253 s->PutCString(path);
1256 const char *object_name = m_object_name.GetCString();
1258 s->Printf("(%s)", object_name);
1262 Module::ReportError (const char *format, ...)
1264 if (format && format[0])
1267 strm.PutCString("error: ");
1268 GetDescription(&strm, lldb::eDescriptionLevelBrief);
1271 va_start (args, format);
1272 strm.PrintfVarArg(format, args);
1275 const int format_len = strlen(format);
1278 const char last_char = format[format_len-1];
1279 if (last_char != '\n' || last_char != '\r')
1282 Host::SystemLog (Host::eSystemLogError, "%s", strm.GetString().c_str());
1287 Module::FileHasChanged () const
1289 if (!m_file_has_changed)
1290 m_file_has_changed = (m_file.GetModificationTime() != m_mod_time);
1291 return m_file_has_changed;
1295 Module::ReportErrorIfModifyDetected (const char *format, ...)
1297 if (!m_first_file_changed_log)
1299 if (FileHasChanged ())
1301 m_first_file_changed_log = true;
1305 strm.PutCString("error: the object file ");
1306 GetDescription(&strm, lldb::eDescriptionLevelFull);
1307 strm.PutCString (" has been modified\n");
1310 va_start (args, format);
1311 strm.PrintfVarArg(format, args);
1314 const int format_len = strlen(format);
1317 const char last_char = format[format_len-1];
1318 if (last_char != '\n' || last_char != '\r')
1321 strm.PutCString("The debug session should be aborted as the original debug information has been overwritten.\n");
1322 Host::SystemLog (Host::eSystemLogError, "%s", strm.GetString().c_str());
1329 Module::ReportWarning (const char *format, ...)
1331 if (format && format[0])
1334 strm.PutCString("warning: ");
1335 GetDescription(&strm, lldb::eDescriptionLevelFull);
1339 va_start (args, format);
1340 strm.PrintfVarArg(format, args);
1343 const int format_len = strlen(format);
1346 const char last_char = format[format_len-1];
1347 if (last_char != '\n' || last_char != '\r')
1350 Host::SystemLog (Host::eSystemLogWarning, "%s", strm.GetString().c_str());
1355 Module::LogMessage (Log *log, const char *format, ...)
1359 StreamString log_message;
1360 GetDescription(&log_message, lldb::eDescriptionLevelFull);
1361 log_message.PutCString (": ");
1363 va_start (args, format);
1364 log_message.PrintfVarArg (format, args);
1366 log->PutCString(log_message.GetString().c_str());
1371 Module::LogMessageVerboseBacktrace (Log *log, const char *format, ...)
1375 StreamString log_message;
1376 GetDescription(&log_message, lldb::eDescriptionLevelFull);
1377 log_message.PutCString (": ");
1379 va_start (args, format);
1380 log_message.PrintfVarArg (format, args);
1382 if (log->GetVerbose())
1384 std::string back_trace;
1385 llvm::raw_string_ostream stream(back_trace);
1386 llvm::sys::PrintStackTrace(stream);
1387 log_message.PutCString(back_trace.c_str());
1389 log->PutCString(log_message.GetString().c_str());
1394 Module::Dump(Stream *s)
1396 std::lock_guard<std::recursive_mutex> guard(m_mutex);
1397 //s->Printf("%.*p: ", (int)sizeof(void*) * 2, this);
1399 s->Printf("Module %s%s%s%s\n",
1400 m_file.GetPath().c_str(),
1401 m_object_name ? "(" : "",
1402 m_object_name ? m_object_name.GetCString() : "",
1403 m_object_name ? ")" : "");
1407 ObjectFile *objfile = GetObjectFile ();
1411 SymbolVendor *symbols = GetSymbolVendor ();
1419 Module::GetTypeList ()
1421 SymbolVendor *symbols = GetSymbolVendor ();
1423 return &symbols->GetTypeList();
1428 Module::GetObjectName() const
1430 return m_object_name;
1434 Module::GetObjectFile()
1436 if (!m_did_load_objfile.load())
1438 std::lock_guard<std::recursive_mutex> guard(m_mutex);
1439 if (!m_did_load_objfile.load())
1441 Timer scoped_timer(__PRETTY_FUNCTION__,
1442 "Module::GetObjectFile () module = %s", GetFileSpec().GetFilename().AsCString(""));
1443 DataBufferSP data_sp;
1444 lldb::offset_t data_offset = 0;
1445 const lldb::offset_t file_size = m_file.GetByteSize();
1446 if (file_size > m_object_offset)
1448 m_did_load_objfile = true;
1449 m_objfile_sp = ObjectFile::FindPlugin (shared_from_this(),
1452 file_size - m_object_offset,
1457 // Once we get the object file, update our module with the object file's
1458 // architecture since it might differ in vendor/os if some parts were
1459 // unknown. But since the matching arch might already be more specific
1460 // than the generic COFF architecture, only merge in those values that
1461 // overwrite unspecified unknown values.
1463 m_objfile_sp->GetArchitecture(new_arch);
1464 m_arch.MergeFrom(new_arch);
1468 ReportError ("failed to load objfile for %s", GetFileSpec().GetPath().c_str());
1473 return m_objfile_sp.get();
1477 Module::GetSectionList()
1479 // Populate m_unified_sections_ap with sections from objfile.
1482 ObjectFile *obj_file = GetObjectFile();
1483 if (obj_file != nullptr)
1484 obj_file->CreateSections(*GetUnifiedSectionList());
1486 return m_sections_ap.get();
1490 Module::SectionFileAddressesChanged ()
1492 ObjectFile *obj_file = GetObjectFile ();
1494 obj_file->SectionFileAddressesChanged ();
1495 SymbolVendor* sym_vendor = GetSymbolVendor();
1496 if (sym_vendor != nullptr)
1497 sym_vendor->SectionFileAddressesChanged ();
1501 Module::GetUnifiedSectionList()
1503 // Populate m_unified_sections_ap with sections from objfile.
1505 m_sections_ap.reset(new SectionList());
1506 return m_sections_ap.get();
1510 Module::FindFirstSymbolWithNameAndType (const ConstString &name, SymbolType symbol_type)
1512 Timer scoped_timer(__PRETTY_FUNCTION__,
1513 "Module::FindFirstSymbolWithNameAndType (name = %s, type = %i)",
1516 SymbolVendor* sym_vendor = GetSymbolVendor();
1519 Symtab *symtab = sym_vendor->GetSymtab();
1521 return symtab->FindFirstSymbolWithNameAndType (name, symbol_type, Symtab::eDebugAny, Symtab::eVisibilityAny);
1526 Module::SymbolIndicesToSymbolContextList (Symtab *symtab, std::vector<uint32_t> &symbol_indexes, SymbolContextList &sc_list)
1528 // No need to protect this call using m_mutex all other method calls are
1529 // already thread safe.
1531 size_t num_indices = symbol_indexes.size();
1532 if (num_indices > 0)
1535 CalculateSymbolContext (&sc);
1536 for (size_t i = 0; i < num_indices; i++)
1538 sc.symbol = symtab->SymbolAtIndex (symbol_indexes[i]);
1540 sc_list.Append (sc);
1546 Module::FindFunctionSymbols (const ConstString &name,
1547 uint32_t name_type_mask,
1548 SymbolContextList& sc_list)
1550 Timer scoped_timer(__PRETTY_FUNCTION__,
1551 "Module::FindSymbolsFunctions (name = %s, mask = 0x%8.8x)",
1554 SymbolVendor* sym_vendor = GetSymbolVendor();
1557 Symtab *symtab = sym_vendor->GetSymtab();
1559 return symtab->FindFunctionSymbols (name, name_type_mask, sc_list);
1565 Module::FindSymbolsWithNameAndType (const ConstString &name, SymbolType symbol_type, SymbolContextList &sc_list)
1567 // No need to protect this call using m_mutex all other method calls are
1568 // already thread safe.
1570 Timer scoped_timer(__PRETTY_FUNCTION__,
1571 "Module::FindSymbolsWithNameAndType (name = %s, type = %i)",
1574 const size_t initial_size = sc_list.GetSize();
1575 SymbolVendor* sym_vendor = GetSymbolVendor();
1578 Symtab *symtab = sym_vendor->GetSymtab();
1581 std::vector<uint32_t> symbol_indexes;
1582 symtab->FindAllSymbolsWithNameAndType (name, symbol_type, symbol_indexes);
1583 SymbolIndicesToSymbolContextList (symtab, symbol_indexes, sc_list);
1586 return sc_list.GetSize() - initial_size;
1590 Module::FindSymbolsMatchingRegExAndType (const RegularExpression ®ex, SymbolType symbol_type, SymbolContextList &sc_list)
1592 // No need to protect this call using m_mutex all other method calls are
1593 // already thread safe.
1595 Timer scoped_timer(__PRETTY_FUNCTION__,
1596 "Module::FindSymbolsMatchingRegExAndType (regex = %s, type = %i)",
1599 const size_t initial_size = sc_list.GetSize();
1600 SymbolVendor* sym_vendor = GetSymbolVendor();
1603 Symtab *symtab = sym_vendor->GetSymtab();
1606 std::vector<uint32_t> symbol_indexes;
1607 symtab->FindAllSymbolsMatchingRexExAndType (regex, symbol_type, Symtab::eDebugAny, Symtab::eVisibilityAny, symbol_indexes);
1608 SymbolIndicesToSymbolContextList (symtab, symbol_indexes, sc_list);
1611 return sc_list.GetSize() - initial_size;
1615 Module::SetSymbolFileFileSpec (const FileSpec &file)
1621 // Remove any sections in the unified section list that come from the current symbol vendor.
1622 SectionList *section_list = GetSectionList();
1623 SymbolFile *symbol_file = m_symfile_ap->GetSymbolFile();
1624 if (section_list && symbol_file)
1626 ObjectFile *obj_file = symbol_file->GetObjectFile();
1627 // Make sure we have an object file and that the symbol vendor's objfile isn't
1628 // the same as the module's objfile before we remove any sections for it...
1631 // Check to make sure we aren't trying to specify the file we already have
1632 if (obj_file->GetFileSpec() == file)
1634 // We are being told to add the exact same file that we already have
1635 // we don't have to do anything.
1639 // Cleare the current symtab as we are going to replace it with a new one
1640 obj_file->ClearSymtab();
1642 // The symbol file might be a directory bundle ("/tmp/a.out.dSYM") instead
1643 // of a full path to the symbol file within the bundle
1644 // ("/tmp/a.out.dSYM/Contents/Resources/DWARF/a.out"). So we need to check this
1646 if (file.IsDirectory())
1648 std::string new_path(file.GetPath());
1649 std::string old_path(obj_file->GetFileSpec().GetPath());
1650 if (old_path.find(new_path) == 0)
1652 // We specified the same bundle as the symbol file that we already have
1657 if (obj_file != m_objfile_sp.get())
1659 size_t num_sections = section_list->GetNumSections (0);
1660 for (size_t idx = num_sections; idx > 0; --idx)
1662 lldb::SectionSP section_sp (section_list->GetSectionAtIndex (idx - 1));
1663 if (section_sp->GetObjectFile() == obj_file)
1665 section_list->DeleteSection (idx - 1);
1671 // Keep all old symbol files around in case there are any lingering type references in
1672 // any SBValue objects that might have been handed out.
1673 m_old_symfiles.push_back(std::move(m_symfile_ap));
1675 m_symfile_spec = file;
1676 m_symfile_ap.reset();
1677 m_did_load_symbol_vendor = false;
1681 Module::IsExecutable ()
1683 if (GetObjectFile() == nullptr)
1686 return GetObjectFile()->IsExecutable();
1690 Module::IsLoadedInTarget (Target *target)
1692 ObjectFile *obj_file = GetObjectFile();
1695 SectionList *sections = GetSectionList();
1696 if (sections != nullptr)
1698 size_t num_sections = sections->GetSize();
1699 for (size_t sect_idx = 0; sect_idx < num_sections; sect_idx++)
1701 SectionSP section_sp = sections->GetSectionAtIndex(sect_idx);
1702 if (section_sp->GetLoadBaseAddress(target) != LLDB_INVALID_ADDRESS)
1713 Module::LoadScriptingResourceInTarget (Target *target, Error& error, Stream* feedback_stream)
1717 error.SetErrorString("invalid destination Target");
1721 LoadScriptFromSymFile should_load = target->TargetProperties::GetLoadScriptFromSymbolFile();
1723 if (should_load == eLoadScriptFromSymFileFalse)
1726 Debugger &debugger = target->GetDebugger();
1727 const ScriptLanguage script_language = debugger.GetScriptLanguage();
1728 if (script_language != eScriptLanguageNone)
1731 PlatformSP platform_sp(target->GetPlatform());
1735 error.SetErrorString("invalid Platform");
1739 FileSpecList file_specs = platform_sp->LocateExecutableScriptingResources (target,
1743 const uint32_t num_specs = file_specs.GetSize();
1746 ScriptInterpreter *script_interpreter = debugger.GetCommandInterpreter().GetScriptInterpreter();
1747 if (script_interpreter)
1749 for (uint32_t i = 0; i < num_specs; ++i)
1751 FileSpec scripting_fspec (file_specs.GetFileSpecAtIndex(i));
1752 if (scripting_fspec && scripting_fspec.Exists())
1754 if (should_load == eLoadScriptFromSymFileWarn)
1756 if (feedback_stream)
1757 feedback_stream->Printf("warning: '%s' contains a debug script. To run this script in "
1758 "this debug session:\n\n command script import \"%s\"\n\n"
1759 "To run all discovered debug scripts in this session:\n\n"
1760 " settings set target.load-script-from-symbol-file true\n",
1761 GetFileSpec().GetFileNameStrippingExtension().GetCString(),
1762 scripting_fspec.GetPath().c_str());
1765 StreamString scripting_stream;
1766 scripting_fspec.Dump(&scripting_stream);
1767 const bool can_reload = true;
1768 const bool init_lldb_globals = false;
1769 bool did_load = script_interpreter->LoadScriptingModule(scripting_stream.GetData(),
1780 error.SetErrorString("invalid ScriptInterpreter");
1789 Module::SetArchitecture (const ArchSpec &new_arch)
1791 if (!m_arch.IsValid())
1796 return m_arch.IsCompatibleMatch(new_arch);
1800 Module::SetLoadAddress (Target &target, lldb::addr_t value, bool value_is_offset, bool &changed)
1802 ObjectFile *object_file = GetObjectFile();
1803 if (object_file != nullptr)
1805 changed = object_file->SetLoadAddress(target, value, value_is_offset);
1817 Module::MatchesModuleSpec (const ModuleSpec &module_ref)
1819 const UUID &uuid = module_ref.GetUUID();
1823 // If the UUID matches, then nothing more needs to match...
1824 return (uuid == GetUUID());
1827 const FileSpec &file_spec = module_ref.GetFileSpec();
1830 if (!FileSpec::Equal (file_spec, m_file, (bool)file_spec.GetDirectory()) &&
1831 !FileSpec::Equal (file_spec, m_platform_file, (bool)file_spec.GetDirectory()))
1835 const FileSpec &platform_file_spec = module_ref.GetPlatformFileSpec();
1836 if (platform_file_spec)
1838 if (!FileSpec::Equal (platform_file_spec, GetPlatformFileSpec (), (bool)platform_file_spec.GetDirectory()))
1842 const ArchSpec &arch = module_ref.GetArchitecture();
1845 if (!m_arch.IsCompatibleMatch(arch))
1849 const ConstString &object_name = module_ref.GetObjectName();
1852 if (object_name != GetObjectName())
1859 Module::FindSourceFile (const FileSpec &orig_spec, FileSpec &new_spec) const
1861 std::lock_guard<std::recursive_mutex> guard(m_mutex);
1862 return m_source_mappings.FindFile (orig_spec, new_spec);
1866 Module::RemapSourceFile (const char *path, std::string &new_path) const
1868 std::lock_guard<std::recursive_mutex> guard(m_mutex);
1869 return m_source_mappings.RemapPath(path, new_path);
1873 Module::GetVersion (uint32_t *versions, uint32_t num_versions)
1875 ObjectFile *obj_file = GetObjectFile();
1877 return obj_file->GetVersion (versions, num_versions);
1879 if (versions != nullptr && num_versions != 0)
1881 for (uint32_t i = 0; i < num_versions; ++i)
1882 versions[i] = LLDB_INVALID_MODULE_VERSION;
1888 Module::CreateJITModule (const lldb::ObjectFileJITDelegateSP &delegate_sp)
1892 // Must create a module and place it into a shared pointer before
1893 // we can create an object file since it has a std::weak_ptr back
1894 // to the module, so we need to control the creation carefully in
1895 // this static function
1896 ModuleSP module_sp(new Module());
1897 module_sp->m_objfile_sp.reset (new ObjectFileJIT (module_sp, delegate_sp));
1898 if (module_sp->m_objfile_sp)
1900 // Once we get the object file, update our module with the object file's
1901 // architecture since it might differ in vendor/os if some parts were
1903 module_sp->m_objfile_sp->GetArchitecture (module_sp->m_arch);
1911 Module::GetIsDynamicLinkEditor()
1913 ObjectFile * obj_file = GetObjectFile ();
1916 return obj_file->GetIsDynamicLinkEditor();