130fdc8d8SChris Lattner //===-- Module.cpp ----------------------------------------------*- C++ -*-===// 230fdc8d8SChris Lattner // 330fdc8d8SChris Lattner // The LLVM Compiler Infrastructure 430fdc8d8SChris Lattner // 530fdc8d8SChris Lattner // This file is distributed under the University of Illinois Open Source 630fdc8d8SChris Lattner // License. See LICENSE.TXT for details. 730fdc8d8SChris Lattner // 830fdc8d8SChris Lattner //===----------------------------------------------------------------------===// 930fdc8d8SChris Lattner 10c5dac77aSEugene Zelenko #include "lldb/Core/Module.h" 11c5dac77aSEugene Zelenko 12c5dac77aSEugene Zelenko // C Includes 13c5dac77aSEugene Zelenko // C++ Includes 14c5dac77aSEugene Zelenko // Other libraries and framework includes 15c5dac77aSEugene Zelenko #include "llvm/Support/raw_os_ostream.h" 16c5dac77aSEugene Zelenko #include "llvm/Support/Signals.h" 17c5dac77aSEugene Zelenko 18c5dac77aSEugene Zelenko // Project includes 19f86248d9SRichard Mitton #include "lldb/Core/AddressResolverFileLine.h" 201759848bSEnrico Granata #include "lldb/Core/Error.h" 21c9660546SGreg Clayton #include "lldb/Core/DataBuffer.h" 22c9660546SGreg Clayton #include "lldb/Core/DataBufferHeap.h" 2330fdc8d8SChris Lattner #include "lldb/Core/Log.h" 2430fdc8d8SChris Lattner #include "lldb/Core/ModuleList.h" 251f746071SGreg Clayton #include "lldb/Core/ModuleSpec.h" 2656939cb3SGreg Clayton #include "lldb/Core/PluginManager.h" 2730fdc8d8SChris Lattner #include "lldb/Core/RegularExpression.h" 281f746071SGreg Clayton #include "lldb/Core/Section.h" 29c982b3d6SGreg Clayton #include "lldb/Core/StreamString.h" 3030fdc8d8SChris Lattner #include "lldb/Core/Timer.h" 31e38a5eddSGreg Clayton #include "lldb/Host/Host.h" 321759848bSEnrico Granata #include "lldb/Host/Symbols.h" 331759848bSEnrico Granata #include "lldb/Interpreter/CommandInterpreter.h" 341759848bSEnrico Granata #include "lldb/Interpreter/ScriptInterpreter.h" 351f746071SGreg Clayton #include "lldb/Symbol/CompileUnit.h" 3630fdc8d8SChris Lattner #include "lldb/Symbol/ObjectFile.h" 3730fdc8d8SChris Lattner #include "lldb/Symbol/SymbolContext.h" 3856939cb3SGreg Clayton #include "lldb/Symbol/SymbolFile.h" 3930fdc8d8SChris Lattner #include "lldb/Symbol/SymbolVendor.h" 4056939cb3SGreg Clayton #include "lldb/Symbol/TypeSystem.h" 410e0984eeSJim Ingham #include "lldb/Target/Language.h" 42c9660546SGreg Clayton #include "lldb/Target/Process.h" 43d5944cd1SGreg Clayton #include "lldb/Target/SectionLoadList.h" 44c9660546SGreg Clayton #include "lldb/Target/Target.h" 45aa816b8fSJim Ingham #include "Plugins/Language/CPlusPlus/CPlusPlusLanguage.h" 46aa816b8fSJim Ingham #include "Plugins/Language/ObjC/ObjCLanguage.h" 474069730cSRavitheja Addepally #include "lldb/Symbol/TypeMap.h" 4830fdc8d8SChris Lattner 4923f8c95aSGreg Clayton #include "Plugins/ObjectFile/JIT/ObjectFileJIT.h" 5023f8c95aSGreg Clayton 5130fdc8d8SChris Lattner using namespace lldb; 5230fdc8d8SChris Lattner using namespace lldb_private; 5330fdc8d8SChris Lattner 5465a03991SGreg Clayton // Shared pointers to modules track module lifetimes in 5565a03991SGreg Clayton // targets and in the global module, but this collection 5665a03991SGreg Clayton // will track all module objects that are still alive 5765a03991SGreg Clayton typedef std::vector<Module *> ModuleCollection; 5865a03991SGreg Clayton 5965a03991SGreg Clayton static ModuleCollection & 6065a03991SGreg Clayton GetModuleCollection() 6165a03991SGreg Clayton { 62549f7374SJim Ingham // This module collection needs to live past any module, so we could either make it a 63549f7374SJim Ingham // shared pointer in each module or just leak is. Since it is only an empty vector by 64549f7374SJim Ingham // the time all the modules have gone away, we just leak it for now. If we decide this 65549f7374SJim Ingham // is a big problem we can introduce a Finalize method that will tear everything down in 66549f7374SJim Ingham // a predictable order. 67549f7374SJim Ingham 68c5dac77aSEugene Zelenko static ModuleCollection *g_module_collection = nullptr; 69c5dac77aSEugene Zelenko if (g_module_collection == nullptr) 70549f7374SJim Ingham g_module_collection = new ModuleCollection(); 71549f7374SJim Ingham 72549f7374SJim Ingham return *g_module_collection; 7365a03991SGreg Clayton } 7465a03991SGreg Clayton 7516ff8604SSaleem Abdulrasool std::recursive_mutex & 7665a03991SGreg Clayton Module::GetAllocationModuleCollectionMutex() 7765a03991SGreg Clayton { 78b26e6bebSGreg Clayton // NOTE: The mutex below must be leaked since the global module list in 79b26e6bebSGreg Clayton // the ModuleList class will get torn at some point, and we can't know 80b26e6bebSGreg Clayton // if it will tear itself down before the "g_module_collection_mutex" below 81b26e6bebSGreg Clayton // will. So we leak a Mutex object below to safeguard against that 82b26e6bebSGreg Clayton 8316ff8604SSaleem Abdulrasool static std::recursive_mutex *g_module_collection_mutex = nullptr; 84c5dac77aSEugene Zelenko if (g_module_collection_mutex == nullptr) 8516ff8604SSaleem Abdulrasool g_module_collection_mutex = new std::recursive_mutex; // NOTE: known leak 8616ff8604SSaleem Abdulrasool return *g_module_collection_mutex; 8765a03991SGreg Clayton } 8865a03991SGreg Clayton 8965a03991SGreg Clayton size_t 9065a03991SGreg Clayton Module::GetNumberAllocatedModules () 9165a03991SGreg Clayton { 9216ff8604SSaleem Abdulrasool std::lock_guard<std::recursive_mutex> guard(GetAllocationModuleCollectionMutex()); 9365a03991SGreg Clayton return GetModuleCollection().size(); 9465a03991SGreg Clayton } 9565a03991SGreg Clayton 9665a03991SGreg Clayton Module * 9765a03991SGreg Clayton Module::GetAllocatedModuleAtIndex (size_t idx) 9865a03991SGreg Clayton { 9916ff8604SSaleem Abdulrasool std::lock_guard<std::recursive_mutex> guard(GetAllocationModuleCollectionMutex()); 10065a03991SGreg Clayton ModuleCollection &modules = GetModuleCollection(); 10165a03991SGreg Clayton if (idx < modules.size()) 10265a03991SGreg Clayton return modules[idx]; 103c5dac77aSEugene Zelenko return nullptr; 10465a03991SGreg Clayton } 10565a03991SGreg Clayton 106c5dac77aSEugene Zelenko #if 0 10729ad7b91SGreg Clayton // These functions help us to determine if modules are still loaded, yet don't require that 10829ad7b91SGreg Clayton // you have a command interpreter and can easily be called from an external debugger. 10929ad7b91SGreg Clayton namespace lldb { 11065a03991SGreg Clayton 11129ad7b91SGreg Clayton void 11229ad7b91SGreg Clayton ClearModuleInfo (void) 11329ad7b91SGreg Clayton { 1140cd70866SGreg Clayton const bool mandatory = true; 1150cd70866SGreg Clayton ModuleList::RemoveOrphanSharedModules(mandatory); 11629ad7b91SGreg Clayton } 11729ad7b91SGreg Clayton 11829ad7b91SGreg Clayton void 11929ad7b91SGreg Clayton DumpModuleInfo (void) 12029ad7b91SGreg Clayton { 12129ad7b91SGreg Clayton Mutex::Locker locker (Module::GetAllocationModuleCollectionMutex()); 12229ad7b91SGreg Clayton ModuleCollection &modules = GetModuleCollection(); 12329ad7b91SGreg Clayton const size_t count = modules.size(); 124d01b2953SDaniel Malea printf ("%s: %" PRIu64 " modules:\n", __PRETTY_FUNCTION__, (uint64_t)count); 12529ad7b91SGreg Clayton for (size_t i = 0; i < count; ++i) 12629ad7b91SGreg Clayton { 12729ad7b91SGreg Clayton 12829ad7b91SGreg Clayton StreamString strm; 12929ad7b91SGreg Clayton Module *module = modules[i]; 13029ad7b91SGreg Clayton const bool in_shared_module_list = ModuleList::ModuleIsInCache (module); 13129ad7b91SGreg Clayton module->GetDescription(&strm, eDescriptionLevelFull); 13229ad7b91SGreg Clayton printf ("%p: shared = %i, ref_count = %3u, module = %s\n", 13329ad7b91SGreg Clayton module, 13429ad7b91SGreg Clayton in_shared_module_list, 13529ad7b91SGreg Clayton (uint32_t)module->use_count(), 13629ad7b91SGreg Clayton strm.GetString().c_str()); 13729ad7b91SGreg Clayton } 13829ad7b91SGreg Clayton } 13929ad7b91SGreg Clayton } 14029ad7b91SGreg Clayton 14129ad7b91SGreg Clayton #endif 14265a03991SGreg Clayton 14316ff8604SSaleem Abdulrasool Module::Module(const ModuleSpec &module_spec) 14416ff8604SSaleem Abdulrasool : m_mutex(), 14534f1159bSGreg Clayton m_mod_time(), 14634f1159bSGreg Clayton m_arch(), 147b9a01b39SGreg Clayton m_uuid(), 14834f1159bSGreg Clayton m_file(), 14934f1159bSGreg Clayton m_platform_file(), 150fbb76349SGreg Clayton m_remote_install_file(), 15134f1159bSGreg Clayton m_symfile_spec(), 15234f1159bSGreg Clayton m_object_name(), 15334f1159bSGreg Clayton m_object_offset(), 15434f1159bSGreg Clayton m_object_mod_time(), 155b9a01b39SGreg Clayton m_objfile_sp(), 156b9a01b39SGreg Clayton m_symfile_ap(), 15756939cb3SGreg Clayton m_type_system_map(), 158d804d285SGreg Clayton m_source_mappings(), 15923f8c95aSGreg Clayton m_sections_ap(), 160b9a01b39SGreg Clayton m_did_load_objfile(false), 161b9a01b39SGreg Clayton m_did_load_symbol_vendor(false), 162b9a01b39SGreg Clayton m_did_parse_uuid(false), 1631d60909eSGreg Clayton m_file_has_changed(false), 1641d60909eSGreg Clayton m_first_file_changed_log(false) 165b9a01b39SGreg Clayton { 166b9a01b39SGreg Clayton // Scope for locker below... 167b9a01b39SGreg Clayton { 16816ff8604SSaleem Abdulrasool std::lock_guard<std::recursive_mutex> guard(GetAllocationModuleCollectionMutex()); 169b9a01b39SGreg Clayton GetModuleCollection().push_back(this); 170b9a01b39SGreg Clayton } 171b9a01b39SGreg Clayton 1725160ce5cSGreg Clayton Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_OBJECT | LIBLLDB_LOG_MODULES)); 173c5dac77aSEugene Zelenko if (log != nullptr) 17416ff8604SSaleem Abdulrasool log->Printf("%p Module::Module((%s) '%s%s%s%s')", static_cast<void *>(this), 17516ff8604SSaleem Abdulrasool module_spec.GetArchitecture().GetArchitectureName(), module_spec.GetFileSpec().GetPath().c_str(), 17634f1159bSGreg Clayton module_spec.GetObjectName().IsEmpty() ? "" : "(", 17734f1159bSGreg Clayton module_spec.GetObjectName().IsEmpty() ? "" : module_spec.GetObjectName().AsCString(""), 17834f1159bSGreg Clayton module_spec.GetObjectName().IsEmpty() ? "" : ")"); 17934f1159bSGreg Clayton 18034f1159bSGreg Clayton // First extract all module specifications from the file using the local 18134f1159bSGreg Clayton // file path. If there are no specifications, then don't fill anything in 18234f1159bSGreg Clayton ModuleSpecList modules_specs; 18334f1159bSGreg Clayton if (ObjectFile::GetModuleSpecifications(module_spec.GetFileSpec(), 0, 0, modules_specs) == 0) 18434f1159bSGreg Clayton return; 18534f1159bSGreg Clayton 18634f1159bSGreg Clayton // Now make sure that one of the module specifications matches what we just 18734f1159bSGreg Clayton // extract. We might have a module specification that specifies a file "/usr/lib/dyld" 18834f1159bSGreg Clayton // with UUID XXX, but we might have a local version of "/usr/lib/dyld" that has 18934f1159bSGreg Clayton // UUID YYY and we don't want those to match. If they don't match, just don't 19034f1159bSGreg Clayton // fill any ivars in so we don't accidentally grab the wrong file later since 19134f1159bSGreg Clayton // they don't match... 19234f1159bSGreg Clayton ModuleSpec matching_module_spec; 19334f1159bSGreg Clayton if (modules_specs.FindMatchingModuleSpec(module_spec, matching_module_spec) == 0) 19434f1159bSGreg Clayton return; 1957ab7f89aSGreg Clayton 1967ab7f89aSGreg Clayton if (module_spec.GetFileSpec()) 19734f1159bSGreg Clayton m_mod_time = module_spec.GetFileSpec().GetModificationTime(); 1987ab7f89aSGreg Clayton else if (matching_module_spec.GetFileSpec()) 1997ab7f89aSGreg Clayton m_mod_time = matching_module_spec.GetFileSpec().GetModificationTime(); 2007ab7f89aSGreg Clayton 2017ab7f89aSGreg Clayton // Copy the architecture from the actual spec if we got one back, else use the one that was specified 2027ab7f89aSGreg Clayton if (matching_module_spec.GetArchitecture().IsValid()) 20334f1159bSGreg Clayton m_arch = matching_module_spec.GetArchitecture(); 2047ab7f89aSGreg Clayton else if (module_spec.GetArchitecture().IsValid()) 2057ab7f89aSGreg Clayton m_arch = module_spec.GetArchitecture(); 2067ab7f89aSGreg Clayton 207d93c4a33SBruce Mitchener // Copy the file spec over and use the specified one (if there was one) so we 2087ab7f89aSGreg Clayton // don't use a path that might have gotten resolved a path in 'matching_module_spec' 2097ab7f89aSGreg Clayton if (module_spec.GetFileSpec()) 21034f1159bSGreg Clayton m_file = module_spec.GetFileSpec(); 2117ab7f89aSGreg Clayton else if (matching_module_spec.GetFileSpec()) 2127ab7f89aSGreg Clayton m_file = matching_module_spec.GetFileSpec(); 2137ab7f89aSGreg Clayton 2147ab7f89aSGreg Clayton // Copy the platform file spec over 2157ab7f89aSGreg Clayton if (module_spec.GetPlatformFileSpec()) 21634f1159bSGreg Clayton m_platform_file = module_spec.GetPlatformFileSpec(); 2177ab7f89aSGreg Clayton else if (matching_module_spec.GetPlatformFileSpec()) 2187ab7f89aSGreg Clayton m_platform_file = matching_module_spec.GetPlatformFileSpec(); 2197ab7f89aSGreg Clayton 2207ab7f89aSGreg Clayton // Copy the symbol file spec over 2217ab7f89aSGreg Clayton if (module_spec.GetSymbolFileSpec()) 22234f1159bSGreg Clayton m_symfile_spec = module_spec.GetSymbolFileSpec(); 2237ab7f89aSGreg Clayton else if (matching_module_spec.GetSymbolFileSpec()) 2247ab7f89aSGreg Clayton m_symfile_spec = matching_module_spec.GetSymbolFileSpec(); 2257ab7f89aSGreg Clayton 2267ab7f89aSGreg Clayton // Copy the object name over 2277ab7f89aSGreg Clayton if (matching_module_spec.GetObjectName()) 2287ab7f89aSGreg Clayton m_object_name = matching_module_spec.GetObjectName(); 2297ab7f89aSGreg Clayton else 23034f1159bSGreg Clayton m_object_name = module_spec.GetObjectName(); 2317ab7f89aSGreg Clayton 2327ab7f89aSGreg Clayton // Always trust the object offset (file offset) and object modification 2337ab7f89aSGreg Clayton // time (for mod time in a BSD static archive) of from the matching 2347ab7f89aSGreg Clayton // module specification 23536d7c894SGreg Clayton m_object_offset = matching_module_spec.GetObjectOffset(); 23636d7c894SGreg Clayton m_object_mod_time = matching_module_spec.GetObjectModificationTime(); 237b9a01b39SGreg Clayton } 238b9a01b39SGreg Clayton 23916ff8604SSaleem Abdulrasool Module::Module(const FileSpec &file_spec, const ArchSpec &arch, const ConstString *object_name, 24016ff8604SSaleem Abdulrasool lldb::offset_t object_offset, const TimeValue *object_mod_time_ptr) 24116ff8604SSaleem Abdulrasool : m_mutex(), 24230fdc8d8SChris Lattner m_mod_time(file_spec.GetModificationTime()), 24330fdc8d8SChris Lattner m_arch(arch), 24430fdc8d8SChris Lattner m_uuid(), 24530fdc8d8SChris Lattner m_file(file_spec), 24632e0a750SGreg Clayton m_platform_file(), 247fbb76349SGreg Clayton m_remote_install_file(), 248e72dfb32SGreg Clayton m_symfile_spec(), 24930fdc8d8SChris Lattner m_object_name(), 2508b82f087SGreg Clayton m_object_offset(object_offset), 25157abc5d6SGreg Clayton m_object_mod_time(), 252762f7135SGreg Clayton m_objfile_sp(), 253e83e731eSGreg Clayton m_symfile_ap(), 25456939cb3SGreg Clayton m_type_system_map(), 255d804d285SGreg Clayton m_source_mappings(), 25623f8c95aSGreg Clayton m_sections_ap(), 257e83e731eSGreg Clayton m_did_load_objfile(false), 258e83e731eSGreg Clayton m_did_load_symbol_vendor(false), 259e83e731eSGreg Clayton m_did_parse_uuid(false), 2601d60909eSGreg Clayton m_file_has_changed(false), 2611d60909eSGreg Clayton m_first_file_changed_log(false) 26230fdc8d8SChris Lattner { 26365a03991SGreg Clayton // Scope for locker below... 26465a03991SGreg Clayton { 26516ff8604SSaleem Abdulrasool std::lock_guard<std::recursive_mutex> guard(GetAllocationModuleCollectionMutex()); 26665a03991SGreg Clayton GetModuleCollection().push_back(this); 26765a03991SGreg Clayton } 26865a03991SGreg Clayton 26930fdc8d8SChris Lattner if (object_name) 27030fdc8d8SChris Lattner m_object_name = *object_name; 27157abc5d6SGreg Clayton 27257abc5d6SGreg Clayton if (object_mod_time_ptr) 27357abc5d6SGreg Clayton m_object_mod_time = *object_mod_time_ptr; 27457abc5d6SGreg Clayton 2755160ce5cSGreg Clayton Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_OBJECT | LIBLLDB_LOG_MODULES)); 276c5dac77aSEugene Zelenko if (log != nullptr) 27716ff8604SSaleem Abdulrasool log->Printf("%p Module::Module((%s) '%s%s%s%s')", static_cast<void *>(this), m_arch.GetArchitectureName(), 27816ff8604SSaleem Abdulrasool m_file.GetPath().c_str(), m_object_name.IsEmpty() ? "" : "(", 27916ff8604SSaleem Abdulrasool m_object_name.IsEmpty() ? "" : m_object_name.AsCString(""), m_object_name.IsEmpty() ? "" : ")"); 28030fdc8d8SChris Lattner } 28130fdc8d8SChris Lattner 28216ff8604SSaleem Abdulrasool Module::Module() 28316ff8604SSaleem Abdulrasool : m_mutex(), 28423f8c95aSGreg Clayton m_mod_time(), 28523f8c95aSGreg Clayton m_arch(), 28623f8c95aSGreg Clayton m_uuid(), 28723f8c95aSGreg Clayton m_file(), 28823f8c95aSGreg Clayton m_platform_file(), 28923f8c95aSGreg Clayton m_remote_install_file(), 29023f8c95aSGreg Clayton m_symfile_spec(), 29123f8c95aSGreg Clayton m_object_name(), 29223f8c95aSGreg Clayton m_object_offset(0), 29323f8c95aSGreg Clayton m_object_mod_time(), 29423f8c95aSGreg Clayton m_objfile_sp(), 29523f8c95aSGreg Clayton m_symfile_ap(), 29656939cb3SGreg Clayton m_type_system_map(), 29723f8c95aSGreg Clayton m_source_mappings(), 29823f8c95aSGreg Clayton m_sections_ap(), 29923f8c95aSGreg Clayton m_did_load_objfile(false), 30023f8c95aSGreg Clayton m_did_load_symbol_vendor(false), 30123f8c95aSGreg Clayton m_did_parse_uuid(false), 30223f8c95aSGreg Clayton m_file_has_changed(false), 30323f8c95aSGreg Clayton m_first_file_changed_log(false) 30423f8c95aSGreg Clayton { 30516ff8604SSaleem Abdulrasool std::lock_guard<std::recursive_mutex> guard(GetAllocationModuleCollectionMutex()); 30623f8c95aSGreg Clayton GetModuleCollection().push_back(this); 30723f8c95aSGreg Clayton } 30823f8c95aSGreg Clayton 30930fdc8d8SChris Lattner Module::~Module() 31030fdc8d8SChris Lattner { 311217b28baSGreg Clayton // Lock our module down while we tear everything down to make sure 312217b28baSGreg Clayton // we don't get any access to the module while it is being destroyed 31316ff8604SSaleem Abdulrasool std::lock_guard<std::recursive_mutex> guard(m_mutex); 31465a03991SGreg Clayton // Scope for locker below... 31565a03991SGreg Clayton { 31616ff8604SSaleem Abdulrasool std::lock_guard<std::recursive_mutex> guard(GetAllocationModuleCollectionMutex()); 31765a03991SGreg Clayton ModuleCollection &modules = GetModuleCollection(); 31865a03991SGreg Clayton ModuleCollection::iterator end = modules.end(); 31965a03991SGreg Clayton ModuleCollection::iterator pos = std::find(modules.begin(), end, this); 3203a18e319SGreg Clayton assert (pos != end); 32165a03991SGreg Clayton modules.erase(pos); 32265a03991SGreg Clayton } 3235160ce5cSGreg Clayton Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_OBJECT|LIBLLDB_LOG_MODULES)); 324c5dac77aSEugene Zelenko if (log != nullptr) 325b5ad4ec7SGreg Clayton log->Printf ("%p Module::~Module((%s) '%s%s%s%s')", 326324a1036SSaleem Abdulrasool static_cast<void*>(this), 32764195a2cSGreg Clayton m_arch.GetArchitectureName(), 328b5ad4ec7SGreg Clayton m_file.GetPath().c_str(), 32930fdc8d8SChris Lattner m_object_name.IsEmpty() ? "" : "(", 33030fdc8d8SChris Lattner m_object_name.IsEmpty() ? "" : m_object_name.AsCString(""), 33130fdc8d8SChris Lattner m_object_name.IsEmpty() ? "" : ")"); 3326beaaa68SGreg Clayton // Release any auto pointers before we start tearing down our member 3336beaaa68SGreg Clayton // variables since the object file and symbol files might need to make 3346beaaa68SGreg Clayton // function calls back into this module object. The ordering is important 3356beaaa68SGreg Clayton // here because symbol files can require the module object file. So we tear 3366beaaa68SGreg Clayton // down the symbol file first, then the object file. 3373046e668SGreg Clayton m_sections_ap.reset(); 3386beaaa68SGreg Clayton m_symfile_ap.reset(); 339762f7135SGreg Clayton m_objfile_sp.reset(); 34030fdc8d8SChris Lattner } 34130fdc8d8SChris Lattner 342c7f09ccaSGreg Clayton ObjectFile * 34317220c18SAndrew MacPherson Module::GetMemoryObjectFile (const lldb::ProcessSP &process_sp, lldb::addr_t header_addr, Error &error, size_t size_to_read) 344c7f09ccaSGreg Clayton { 345c7f09ccaSGreg Clayton if (m_objfile_sp) 346c7f09ccaSGreg Clayton { 347c7f09ccaSGreg Clayton error.SetErrorString ("object file already exists"); 348c7f09ccaSGreg Clayton } 349c7f09ccaSGreg Clayton else 350c7f09ccaSGreg Clayton { 35116ff8604SSaleem Abdulrasool std::lock_guard<std::recursive_mutex> guard(m_mutex); 352c7f09ccaSGreg Clayton if (process_sp) 353c7f09ccaSGreg Clayton { 354c7f09ccaSGreg Clayton m_did_load_objfile = true; 35517220c18SAndrew MacPherson std::unique_ptr<DataBufferHeap> data_ap (new DataBufferHeap (size_to_read, 0)); 356c7f09ccaSGreg Clayton Error readmem_error; 357c7f09ccaSGreg Clayton const size_t bytes_read = process_sp->ReadMemory (header_addr, 358c7f09ccaSGreg Clayton data_ap->GetBytes(), 359c7f09ccaSGreg Clayton data_ap->GetByteSize(), 360c7f09ccaSGreg Clayton readmem_error); 36117220c18SAndrew MacPherson if (bytes_read == size_to_read) 362c7f09ccaSGreg Clayton { 363c7f09ccaSGreg Clayton DataBufferSP data_sp(data_ap.release()); 364c7f09ccaSGreg Clayton m_objfile_sp = ObjectFile::FindPlugin(shared_from_this(), process_sp, header_addr, data_sp); 365c7f09ccaSGreg Clayton if (m_objfile_sp) 366c7f09ccaSGreg Clayton { 3673e10cf3bSGreg Clayton StreamString s; 368d01b2953SDaniel Malea s.Printf("0x%16.16" PRIx64, header_addr); 3693e10cf3bSGreg Clayton m_object_name.SetCString (s.GetData()); 3703e10cf3bSGreg Clayton 371c7f09ccaSGreg Clayton // Once we get the object file, update our module with the object file's 372c7f09ccaSGreg Clayton // architecture since it might differ in vendor/os if some parts were 373c7f09ccaSGreg Clayton // unknown. 374c7f09ccaSGreg Clayton m_objfile_sp->GetArchitecture (m_arch); 375c7f09ccaSGreg Clayton } 376c7f09ccaSGreg Clayton else 377c7f09ccaSGreg Clayton { 378c7f09ccaSGreg Clayton error.SetErrorString ("unable to find suitable object file plug-in"); 379c7f09ccaSGreg Clayton } 380c7f09ccaSGreg Clayton } 381c7f09ccaSGreg Clayton else 382c7f09ccaSGreg Clayton { 383c7f09ccaSGreg Clayton error.SetErrorStringWithFormat ("unable to read header from memory: %s", readmem_error.AsCString()); 384c7f09ccaSGreg Clayton } 385c7f09ccaSGreg Clayton } 386c7f09ccaSGreg Clayton else 387c7f09ccaSGreg Clayton { 388c7f09ccaSGreg Clayton error.SetErrorString ("invalid process"); 389c7f09ccaSGreg Clayton } 390c7f09ccaSGreg Clayton } 391c7f09ccaSGreg Clayton return m_objfile_sp.get(); 392c7f09ccaSGreg Clayton } 393c7f09ccaSGreg Clayton 39460830268SGreg Clayton const lldb_private::UUID& 39530fdc8d8SChris Lattner Module::GetUUID() 39630fdc8d8SChris Lattner { 397c5dac77aSEugene Zelenko if (!m_did_parse_uuid.load()) 39888c05f54SGreg Clayton { 39916ff8604SSaleem Abdulrasool std::lock_guard<std::recursive_mutex> guard(m_mutex); 400c5dac77aSEugene Zelenko if (!m_did_parse_uuid.load()) 40130fdc8d8SChris Lattner { 40230fdc8d8SChris Lattner ObjectFile * obj_file = GetObjectFile (); 40330fdc8d8SChris Lattner 404c5dac77aSEugene Zelenko if (obj_file != nullptr) 40530fdc8d8SChris Lattner { 40630fdc8d8SChris Lattner obj_file->GetUUID(&m_uuid); 407e83e731eSGreg Clayton m_did_parse_uuid = true; 40830fdc8d8SChris Lattner } 40930fdc8d8SChris Lattner } 41088c05f54SGreg Clayton } 41130fdc8d8SChris Lattner return m_uuid; 41230fdc8d8SChris Lattner } 41330fdc8d8SChris Lattner 4148b4edba9SGreg Clayton TypeSystem * 4158b4edba9SGreg Clayton Module::GetTypeSystemForLanguage (LanguageType language) 4168b4edba9SGreg Clayton { 4175beec213SGreg Clayton return m_type_system_map.GetTypeSystemForLanguage(language, this, true); 4186beaaa68SGreg Clayton } 4196beaaa68SGreg Clayton 42030fdc8d8SChris Lattner void 42130fdc8d8SChris Lattner Module::ParseAllDebugSymbols() 42230fdc8d8SChris Lattner { 42316ff8604SSaleem Abdulrasool std::lock_guard<std::recursive_mutex> guard(m_mutex); 424c7bece56SGreg Clayton size_t num_comp_units = GetNumCompileUnits(); 42530fdc8d8SChris Lattner if (num_comp_units == 0) 42630fdc8d8SChris Lattner return; 42730fdc8d8SChris Lattner 428a2eee184SGreg Clayton SymbolContext sc; 429e1cd1be6SGreg Clayton sc.module_sp = shared_from_this(); 43030fdc8d8SChris Lattner SymbolVendor *symbols = GetSymbolVendor (); 43130fdc8d8SChris Lattner 432c7bece56SGreg Clayton for (size_t cu_idx = 0; cu_idx < num_comp_units; cu_idx++) 43330fdc8d8SChris Lattner { 43430fdc8d8SChris Lattner sc.comp_unit = symbols->GetCompileUnitAtIndex(cu_idx).get(); 43530fdc8d8SChris Lattner if (sc.comp_unit) 43630fdc8d8SChris Lattner { 437c5dac77aSEugene Zelenko sc.function = nullptr; 43830fdc8d8SChris Lattner symbols->ParseVariablesForContext(sc); 43930fdc8d8SChris Lattner 44030fdc8d8SChris Lattner symbols->ParseCompileUnitFunctions(sc); 44130fdc8d8SChris Lattner 442c5dac77aSEugene Zelenko for (size_t func_idx = 0; (sc.function = sc.comp_unit->GetFunctionAtIndex(func_idx).get()) != nullptr; ++func_idx) 44330fdc8d8SChris Lattner { 44430fdc8d8SChris Lattner symbols->ParseFunctionBlocks(sc); 44530fdc8d8SChris Lattner 44630fdc8d8SChris Lattner // Parse the variables for this function and all its blocks 44730fdc8d8SChris Lattner symbols->ParseVariablesForContext(sc); 44830fdc8d8SChris Lattner } 44930fdc8d8SChris Lattner 45030fdc8d8SChris Lattner // Parse all types for this compile unit 451c5dac77aSEugene Zelenko sc.function = nullptr; 45230fdc8d8SChris Lattner symbols->ParseTypes(sc); 45330fdc8d8SChris Lattner } 45430fdc8d8SChris Lattner } 45530fdc8d8SChris Lattner } 45630fdc8d8SChris Lattner 45730fdc8d8SChris Lattner void 45830fdc8d8SChris Lattner Module::CalculateSymbolContext(SymbolContext* sc) 45930fdc8d8SChris Lattner { 460e1cd1be6SGreg Clayton sc->module_sp = shared_from_this(); 46130fdc8d8SChris Lattner } 46230fdc8d8SChris Lattner 463e72dfb32SGreg Clayton ModuleSP 4647e9b1fd0SGreg Clayton Module::CalculateSymbolContextModule () 4657e9b1fd0SGreg Clayton { 466e72dfb32SGreg Clayton return shared_from_this(); 4677e9b1fd0SGreg Clayton } 4687e9b1fd0SGreg Clayton 46930fdc8d8SChris Lattner void 47030fdc8d8SChris Lattner Module::DumpSymbolContext(Stream *s) 47130fdc8d8SChris Lattner { 472324a1036SSaleem Abdulrasool s->Printf(", Module{%p}", static_cast<void*>(this)); 47330fdc8d8SChris Lattner } 47430fdc8d8SChris Lattner 475c7bece56SGreg Clayton size_t 47630fdc8d8SChris Lattner Module::GetNumCompileUnits() 47730fdc8d8SChris Lattner { 47816ff8604SSaleem Abdulrasool std::lock_guard<std::recursive_mutex> guard(m_mutex); 479324a1036SSaleem Abdulrasool Timer scoped_timer(__PRETTY_FUNCTION__, 480324a1036SSaleem Abdulrasool "Module::GetNumCompileUnits (module = %p)", 481324a1036SSaleem Abdulrasool static_cast<void*>(this)); 48230fdc8d8SChris Lattner SymbolVendor *symbols = GetSymbolVendor (); 48330fdc8d8SChris Lattner if (symbols) 48430fdc8d8SChris Lattner return symbols->GetNumCompileUnits(); 48530fdc8d8SChris Lattner return 0; 48630fdc8d8SChris Lattner } 48730fdc8d8SChris Lattner 48830fdc8d8SChris Lattner CompUnitSP 489c7bece56SGreg Clayton Module::GetCompileUnitAtIndex (size_t index) 49030fdc8d8SChris Lattner { 49116ff8604SSaleem Abdulrasool std::lock_guard<std::recursive_mutex> guard(m_mutex); 492c7bece56SGreg Clayton size_t num_comp_units = GetNumCompileUnits (); 49330fdc8d8SChris Lattner CompUnitSP cu_sp; 49430fdc8d8SChris Lattner 49530fdc8d8SChris Lattner if (index < num_comp_units) 49630fdc8d8SChris Lattner { 49730fdc8d8SChris Lattner SymbolVendor *symbols = GetSymbolVendor (); 49830fdc8d8SChris Lattner if (symbols) 49930fdc8d8SChris Lattner cu_sp = symbols->GetCompileUnitAtIndex(index); 50030fdc8d8SChris Lattner } 50130fdc8d8SChris Lattner return cu_sp; 50230fdc8d8SChris Lattner } 50330fdc8d8SChris Lattner 50430fdc8d8SChris Lattner bool 50530fdc8d8SChris Lattner Module::ResolveFileAddress (lldb::addr_t vm_addr, Address& so_addr) 50630fdc8d8SChris Lattner { 50716ff8604SSaleem Abdulrasool std::lock_guard<std::recursive_mutex> guard(m_mutex); 508d01b2953SDaniel Malea Timer scoped_timer(__PRETTY_FUNCTION__, "Module::ResolveFileAddress (vm_addr = 0x%" PRIx64 ")", vm_addr); 5093046e668SGreg Clayton SectionList *section_list = GetSectionList(); 5103046e668SGreg Clayton if (section_list) 5113046e668SGreg Clayton return so_addr.ResolveAddressUsingFileSections(vm_addr, section_list); 51230fdc8d8SChris Lattner return false; 51330fdc8d8SChris Lattner } 51430fdc8d8SChris Lattner 51530fdc8d8SChris Lattner uint32_t 51635729bb1SAshok Thirumurthi Module::ResolveSymbolContextForAddress (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc, 51735729bb1SAshok Thirumurthi bool resolve_tail_call_address) 51830fdc8d8SChris Lattner { 51916ff8604SSaleem Abdulrasool std::lock_guard<std::recursive_mutex> guard(m_mutex); 52030fdc8d8SChris Lattner uint32_t resolved_flags = 0; 52130fdc8d8SChris Lattner 52272310355SGreg Clayton // Clear the result symbol context in case we don't find anything, but don't clear the target 52372310355SGreg Clayton sc.Clear(false); 52430fdc8d8SChris Lattner 52530fdc8d8SChris Lattner // Get the section from the section/offset address. 526e72dfb32SGreg Clayton SectionSP section_sp (so_addr.GetSection()); 52730fdc8d8SChris Lattner 52830fdc8d8SChris Lattner // Make sure the section matches this module before we try and match anything 529e72dfb32SGreg Clayton if (section_sp && section_sp->GetModule().get() == this) 53030fdc8d8SChris Lattner { 53130fdc8d8SChris Lattner // If the section offset based address resolved itself, then this 53230fdc8d8SChris Lattner // is the right module. 533e1cd1be6SGreg Clayton sc.module_sp = shared_from_this(); 53430fdc8d8SChris Lattner resolved_flags |= eSymbolContextModule; 53530fdc8d8SChris Lattner 53638807141SAshok Thirumurthi SymbolVendor* sym_vendor = GetSymbolVendor(); 53738807141SAshok Thirumurthi if (!sym_vendor) 53838807141SAshok Thirumurthi return resolved_flags; 53938807141SAshok Thirumurthi 54030fdc8d8SChris Lattner // Resolve the compile unit, function, block, line table or line 54130fdc8d8SChris Lattner // entry if requested. 54230fdc8d8SChris Lattner if (resolve_scope & eSymbolContextCompUnit || 54330fdc8d8SChris Lattner resolve_scope & eSymbolContextFunction || 54430fdc8d8SChris Lattner resolve_scope & eSymbolContextBlock || 545*4c8e7828SGreg Clayton resolve_scope & eSymbolContextLineEntry || 546*4c8e7828SGreg Clayton resolve_scope & eSymbolContextVariable ) 54730fdc8d8SChris Lattner { 54838807141SAshok Thirumurthi resolved_flags |= sym_vendor->ResolveSymbolContext (so_addr, resolve_scope, sc); 54930fdc8d8SChris Lattner } 55030fdc8d8SChris Lattner 551680e1778SJim Ingham // Resolve the symbol if requested, but don't re-look it up if we've already found it. 552680e1778SJim Ingham if (resolve_scope & eSymbolContextSymbol && !(resolved_flags & eSymbolContextSymbol)) 55330fdc8d8SChris Lattner { 554a7499c98SMichael Sartain Symtab *symtab = sym_vendor->GetSymtab(); 55538807141SAshok Thirumurthi if (symtab && so_addr.IsSectionOffset()) 55630fdc8d8SChris Lattner { 5570d9dd7dfSMohit K. Bhakkad Symbol *matching_symbol = nullptr; 558c35b91ceSAdrian McCarthy 559c35b91ceSAdrian McCarthy symtab->ForEachSymbolContainingFileAddress(so_addr.GetFileAddress(), 560c35b91ceSAdrian McCarthy [&matching_symbol](Symbol *symbol) -> bool { 5610d9dd7dfSMohit K. Bhakkad if (symbol->GetType() != eSymbolTypeInvalid) 5620d9dd7dfSMohit K. Bhakkad { 5630d9dd7dfSMohit K. Bhakkad matching_symbol = symbol; 5640d9dd7dfSMohit K. Bhakkad return false; // Stop iterating 5650d9dd7dfSMohit K. Bhakkad } 5660d9dd7dfSMohit K. Bhakkad return true; // Keep iterating 5670d9dd7dfSMohit K. Bhakkad }); 5680d9dd7dfSMohit K. Bhakkad sc.symbol = matching_symbol; 56935729bb1SAshok Thirumurthi if (!sc.symbol && 57035729bb1SAshok Thirumurthi resolve_scope & eSymbolContextFunction && !(resolved_flags & eSymbolContextFunction)) 57135729bb1SAshok Thirumurthi { 57235729bb1SAshok Thirumurthi bool verify_unique = false; // No need to check again since ResolveSymbolContext failed to find a symbol at this address. 57335729bb1SAshok Thirumurthi if (ObjectFile *obj_file = sc.module_sp->GetObjectFile()) 57435729bb1SAshok Thirumurthi sc.symbol = obj_file->ResolveSymbolForAddress(so_addr, verify_unique); 57535729bb1SAshok Thirumurthi } 57635729bb1SAshok Thirumurthi 57730fdc8d8SChris Lattner if (sc.symbol) 57893e2861bSGreg Clayton { 57993e2861bSGreg Clayton if (sc.symbol->IsSynthetic()) 58093e2861bSGreg Clayton { 58193e2861bSGreg Clayton // We have a synthetic symbol so lets check if the object file 58293e2861bSGreg Clayton // from the symbol file in the symbol vendor is different than 58393e2861bSGreg Clayton // the object file for the module, and if so search its symbol 58493e2861bSGreg Clayton // table to see if we can come up with a better symbol. For example 58593e2861bSGreg Clayton // dSYM files on MacOSX have an unstripped symbol table inside of 58693e2861bSGreg Clayton // them. 58793e2861bSGreg Clayton ObjectFile *symtab_objfile = symtab->GetObjectFile(); 58893e2861bSGreg Clayton if (symtab_objfile && symtab_objfile->IsStripped()) 58993e2861bSGreg Clayton { 59093e2861bSGreg Clayton SymbolFile *symfile = sym_vendor->GetSymbolFile(); 59193e2861bSGreg Clayton if (symfile) 59293e2861bSGreg Clayton { 59393e2861bSGreg Clayton ObjectFile *symfile_objfile = symfile->GetObjectFile(); 59493e2861bSGreg Clayton if (symfile_objfile != symtab_objfile) 59593e2861bSGreg Clayton { 59693e2861bSGreg Clayton Symtab *symfile_symtab = symfile_objfile->GetSymtab(); 59793e2861bSGreg Clayton if (symfile_symtab) 59893e2861bSGreg Clayton { 59993e2861bSGreg Clayton Symbol *symbol = symfile_symtab->FindSymbolContainingFileAddress(so_addr.GetFileAddress()); 60093e2861bSGreg Clayton if (symbol && !symbol->IsSynthetic()) 60193e2861bSGreg Clayton { 60293e2861bSGreg Clayton sc.symbol = symbol; 60393e2861bSGreg Clayton } 60493e2861bSGreg Clayton } 60593e2861bSGreg Clayton } 60693e2861bSGreg Clayton } 60793e2861bSGreg Clayton } 60893e2861bSGreg Clayton } 60930fdc8d8SChris Lattner resolved_flags |= eSymbolContextSymbol; 61030fdc8d8SChris Lattner } 61130fdc8d8SChris Lattner } 61293e2861bSGreg Clayton } 61338807141SAshok Thirumurthi 61438807141SAshok Thirumurthi // For function symbols, so_addr may be off by one. This is a convention consistent 61538807141SAshok Thirumurthi // with FDE row indices in eh_frame sections, but requires extra logic here to permit 61638807141SAshok Thirumurthi // symbol lookup for disassembly and unwind. 61738807141SAshok Thirumurthi if (resolve_scope & eSymbolContextSymbol && !(resolved_flags & eSymbolContextSymbol) && 61835729bb1SAshok Thirumurthi resolve_tail_call_address && so_addr.IsSectionOffset()) 61938807141SAshok Thirumurthi { 62038807141SAshok Thirumurthi Address previous_addr = so_addr; 621edfaae39SGreg Clayton previous_addr.Slide(-1); 62238807141SAshok Thirumurthi 62335729bb1SAshok Thirumurthi bool do_resolve_tail_call_address = false; // prevent recursion 62435729bb1SAshok Thirumurthi const uint32_t flags = ResolveSymbolContextForAddress(previous_addr, resolve_scope, sc, 62535729bb1SAshok Thirumurthi do_resolve_tail_call_address); 62638807141SAshok Thirumurthi if (flags & eSymbolContextSymbol) 62738807141SAshok Thirumurthi { 62838807141SAshok Thirumurthi AddressRange addr_range; 62938807141SAshok Thirumurthi if (sc.GetAddressRange (eSymbolContextFunction | eSymbolContextSymbol, 0, false, addr_range)) 63038807141SAshok Thirumurthi { 63138807141SAshok Thirumurthi if (addr_range.GetBaseAddress().GetSection() == so_addr.GetSection()) 63238807141SAshok Thirumurthi { 63338807141SAshok Thirumurthi // If the requested address is one past the address range of a function (i.e. a tail call), 63438807141SAshok Thirumurthi // or the decremented address is the start of a function (i.e. some forms of trampoline), 63538807141SAshok Thirumurthi // indicate that the symbol has been resolved. 63638807141SAshok Thirumurthi if (so_addr.GetOffset() == addr_range.GetBaseAddress().GetOffset() || 63738807141SAshok Thirumurthi so_addr.GetOffset() == addr_range.GetBaseAddress().GetOffset() + addr_range.GetByteSize()) 63838807141SAshok Thirumurthi { 63938807141SAshok Thirumurthi resolved_flags |= flags; 64038807141SAshok Thirumurthi } 64138807141SAshok Thirumurthi } 64238807141SAshok Thirumurthi else 64338807141SAshok Thirumurthi { 64438807141SAshok Thirumurthi sc.symbol = nullptr; // Don't trust the symbol if the sections didn't match. 64538807141SAshok Thirumurthi } 64638807141SAshok Thirumurthi } 64730fdc8d8SChris Lattner } 64830fdc8d8SChris Lattner } 64930fdc8d8SChris Lattner } 65030fdc8d8SChris Lattner return resolved_flags; 65130fdc8d8SChris Lattner } 65230fdc8d8SChris Lattner 65330fdc8d8SChris Lattner uint32_t 654274060b6SGreg Clayton Module::ResolveSymbolContextForFilePath 655274060b6SGreg Clayton ( 656274060b6SGreg Clayton const char *file_path, 657274060b6SGreg Clayton uint32_t line, 658274060b6SGreg Clayton bool check_inlines, 659274060b6SGreg Clayton uint32_t resolve_scope, 660274060b6SGreg Clayton SymbolContextList& sc_list 661274060b6SGreg Clayton ) 66230fdc8d8SChris Lattner { 663274060b6SGreg Clayton FileSpec file_spec(file_path, false); 66430fdc8d8SChris Lattner return ResolveSymbolContextsForFileSpec (file_spec, line, check_inlines, resolve_scope, sc_list); 66530fdc8d8SChris Lattner } 66630fdc8d8SChris Lattner 66730fdc8d8SChris Lattner uint32_t 66830fdc8d8SChris Lattner Module::ResolveSymbolContextsForFileSpec (const FileSpec &file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list) 66930fdc8d8SChris Lattner { 67016ff8604SSaleem Abdulrasool std::lock_guard<std::recursive_mutex> guard(m_mutex); 67130fdc8d8SChris Lattner Timer scoped_timer(__PRETTY_FUNCTION__, 672b5ad4ec7SGreg Clayton "Module::ResolveSymbolContextForFilePath (%s:%u, check_inlines = %s, resolve_scope = 0x%8.8x)", 673b5ad4ec7SGreg Clayton file_spec.GetPath().c_str(), 67430fdc8d8SChris Lattner line, 67530fdc8d8SChris Lattner check_inlines ? "yes" : "no", 67630fdc8d8SChris Lattner resolve_scope); 67730fdc8d8SChris Lattner 67830fdc8d8SChris Lattner const uint32_t initial_count = sc_list.GetSize(); 67930fdc8d8SChris Lattner 68030fdc8d8SChris Lattner SymbolVendor *symbols = GetSymbolVendor (); 68130fdc8d8SChris Lattner if (symbols) 68230fdc8d8SChris Lattner symbols->ResolveSymbolContext (file_spec, line, check_inlines, resolve_scope, sc_list); 68330fdc8d8SChris Lattner 68430fdc8d8SChris Lattner return sc_list.GetSize() - initial_count; 68530fdc8d8SChris Lattner } 68630fdc8d8SChris Lattner 687c7bece56SGreg Clayton size_t 688c7bece56SGreg Clayton Module::FindGlobalVariables (const ConstString &name, 68999558cc4SGreg Clayton const CompilerDeclContext *parent_decl_ctx, 690c7bece56SGreg Clayton bool append, 691c7bece56SGreg Clayton size_t max_matches, 692c7bece56SGreg Clayton VariableList& variables) 69330fdc8d8SChris Lattner { 69430fdc8d8SChris Lattner SymbolVendor *symbols = GetSymbolVendor (); 69530fdc8d8SChris Lattner if (symbols) 69699558cc4SGreg Clayton return symbols->FindGlobalVariables(name, parent_decl_ctx, append, max_matches, variables); 69730fdc8d8SChris Lattner return 0; 69830fdc8d8SChris Lattner } 699c7bece56SGreg Clayton 700c7bece56SGreg Clayton size_t 701c7bece56SGreg Clayton Module::FindGlobalVariables (const RegularExpression& regex, 702c7bece56SGreg Clayton bool append, 703c7bece56SGreg Clayton size_t max_matches, 704c7bece56SGreg Clayton VariableList& variables) 70530fdc8d8SChris Lattner { 70630fdc8d8SChris Lattner SymbolVendor *symbols = GetSymbolVendor (); 70730fdc8d8SChris Lattner if (symbols) 70830fdc8d8SChris Lattner return symbols->FindGlobalVariables(regex, append, max_matches, variables); 70930fdc8d8SChris Lattner return 0; 71030fdc8d8SChris Lattner } 71130fdc8d8SChris Lattner 712c7bece56SGreg Clayton size_t 713644247c1SGreg Clayton Module::FindCompileUnits (const FileSpec &path, 714644247c1SGreg Clayton bool append, 715644247c1SGreg Clayton SymbolContextList &sc_list) 716644247c1SGreg Clayton { 717644247c1SGreg Clayton if (!append) 718644247c1SGreg Clayton sc_list.Clear(); 719644247c1SGreg Clayton 720c7bece56SGreg Clayton const size_t start_size = sc_list.GetSize(); 721c7bece56SGreg Clayton const size_t num_compile_units = GetNumCompileUnits(); 722644247c1SGreg Clayton SymbolContext sc; 723e1cd1be6SGreg Clayton sc.module_sp = shared_from_this(); 724ddd7a2a6SSean Callanan const bool compare_directory = (bool)path.GetDirectory(); 725c7bece56SGreg Clayton for (size_t i = 0; i < num_compile_units; ++i) 726644247c1SGreg Clayton { 727644247c1SGreg Clayton sc.comp_unit = GetCompileUnitAtIndex(i).get(); 7282dafd8edSGreg Clayton if (sc.comp_unit) 7292dafd8edSGreg Clayton { 730644247c1SGreg Clayton if (FileSpec::Equal (*sc.comp_unit, path, compare_directory)) 731644247c1SGreg Clayton sc_list.Append(sc); 732644247c1SGreg Clayton } 7332dafd8edSGreg Clayton } 734644247c1SGreg Clayton return sc_list.GetSize() - start_size; 735644247c1SGreg Clayton } 736644247c1SGreg Clayton 737c7bece56SGreg Clayton size_t 738931180e6SGreg Clayton Module::FindFunctions (const ConstString &name, 73999558cc4SGreg Clayton const CompilerDeclContext *parent_decl_ctx, 740931180e6SGreg Clayton uint32_t name_type_mask, 741931180e6SGreg Clayton bool include_symbols, 7429df05fbbSSean Callanan bool include_inlines, 743931180e6SGreg Clayton bool append, 744931180e6SGreg Clayton SymbolContextList& sc_list) 74530fdc8d8SChris Lattner { 746931180e6SGreg Clayton if (!append) 747931180e6SGreg Clayton sc_list.Clear(); 748931180e6SGreg Clayton 74943fe217bSGreg Clayton const size_t old_size = sc_list.GetSize(); 750931180e6SGreg Clayton 751931180e6SGreg Clayton // Find all the functions (not symbols, but debug information functions... 75230fdc8d8SChris Lattner SymbolVendor *symbols = GetSymbolVendor (); 75343fe217bSGreg Clayton 75443fe217bSGreg Clayton if (name_type_mask & eFunctionNameTypeAuto) 75543fe217bSGreg Clayton { 75643fe217bSGreg Clayton ConstString lookup_name; 75743fe217bSGreg Clayton uint32_t lookup_name_type_mask = 0; 75843fe217bSGreg Clayton bool match_name_after_lookup = false; 75943fe217bSGreg Clayton Module::PrepareForFunctionNameLookup (name, 76043fe217bSGreg Clayton name_type_mask, 76123b1decbSDawn Perchik eLanguageTypeUnknown, // TODO: add support 76243fe217bSGreg Clayton lookup_name, 76343fe217bSGreg Clayton lookup_name_type_mask, 76443fe217bSGreg Clayton match_name_after_lookup); 76543fe217bSGreg Clayton 76643fe217bSGreg Clayton if (symbols) 767a7499c98SMichael Sartain { 76843fe217bSGreg Clayton symbols->FindFunctions(lookup_name, 76999558cc4SGreg Clayton parent_decl_ctx, 77043fe217bSGreg Clayton lookup_name_type_mask, 77143fe217bSGreg Clayton include_inlines, 77243fe217bSGreg Clayton append, 77343fe217bSGreg Clayton sc_list); 77443fe217bSGreg Clayton 77543fe217bSGreg Clayton // Now check our symbol table for symbols that are code symbols if requested 77643fe217bSGreg Clayton if (include_symbols) 77743fe217bSGreg Clayton { 778a7499c98SMichael Sartain Symtab *symtab = symbols->GetSymtab(); 77943fe217bSGreg Clayton if (symtab) 78043fe217bSGreg Clayton symtab->FindFunctionSymbols(lookup_name, lookup_name_type_mask, sc_list); 78143fe217bSGreg Clayton } 78243fe217bSGreg Clayton } 78343fe217bSGreg Clayton 78443fe217bSGreg Clayton if (match_name_after_lookup) 78543fe217bSGreg Clayton { 78643fe217bSGreg Clayton SymbolContext sc; 78743fe217bSGreg Clayton size_t i = old_size; 78843fe217bSGreg Clayton while (i < sc_list.GetSize()) 78943fe217bSGreg Clayton { 79043fe217bSGreg Clayton if (sc_list.GetContextAtIndex(i, sc)) 79143fe217bSGreg Clayton { 79243fe217bSGreg Clayton const char *func_name = sc.GetFunctionName().GetCString(); 793c5dac77aSEugene Zelenko if (func_name && strstr(func_name, name.GetCString()) == nullptr) 79443fe217bSGreg Clayton { 79543fe217bSGreg Clayton // Remove the current context 79643fe217bSGreg Clayton sc_list.RemoveContextAtIndex(i); 79743fe217bSGreg Clayton // Don't increment i and continue in the loop 79843fe217bSGreg Clayton continue; 79943fe217bSGreg Clayton } 80043fe217bSGreg Clayton } 80143fe217bSGreg Clayton ++i; 80243fe217bSGreg Clayton } 80343fe217bSGreg Clayton } 80443fe217bSGreg Clayton } 80543fe217bSGreg Clayton else 80643fe217bSGreg Clayton { 80730fdc8d8SChris Lattner if (symbols) 808a7499c98SMichael Sartain { 80999558cc4SGreg Clayton symbols->FindFunctions(name, parent_decl_ctx, name_type_mask, include_inlines, append, sc_list); 810931180e6SGreg Clayton 811931180e6SGreg Clayton // Now check our symbol table for symbols that are code symbols if requested 812931180e6SGreg Clayton if (include_symbols) 813931180e6SGreg Clayton { 814a7499c98SMichael Sartain Symtab *symtab = symbols->GetSymtab(); 815931180e6SGreg Clayton if (symtab) 81643fe217bSGreg Clayton symtab->FindFunctionSymbols(name, name_type_mask, sc_list); 817931180e6SGreg Clayton } 818931180e6SGreg Clayton } 819931180e6SGreg Clayton } 82043fe217bSGreg Clayton 82143fe217bSGreg Clayton return sc_list.GetSize() - old_size; 82230fdc8d8SChris Lattner } 82330fdc8d8SChris Lattner 824c7bece56SGreg Clayton size_t 825931180e6SGreg Clayton Module::FindFunctions (const RegularExpression& regex, 826931180e6SGreg Clayton bool include_symbols, 8279df05fbbSSean Callanan bool include_inlines, 828931180e6SGreg Clayton bool append, 829931180e6SGreg Clayton SymbolContextList& sc_list) 83030fdc8d8SChris Lattner { 831931180e6SGreg Clayton if (!append) 832931180e6SGreg Clayton sc_list.Clear(); 833931180e6SGreg Clayton 834c7bece56SGreg Clayton const size_t start_size = sc_list.GetSize(); 835931180e6SGreg Clayton 83630fdc8d8SChris Lattner SymbolVendor *symbols = GetSymbolVendor (); 83730fdc8d8SChris Lattner if (symbols) 838a7499c98SMichael Sartain { 8399df05fbbSSean Callanan symbols->FindFunctions(regex, include_inlines, append, sc_list); 840a7499c98SMichael Sartain 841931180e6SGreg Clayton // Now check our symbol table for symbols that are code symbols if requested 842931180e6SGreg Clayton if (include_symbols) 843931180e6SGreg Clayton { 844a7499c98SMichael Sartain Symtab *symtab = symbols->GetSymtab(); 845931180e6SGreg Clayton if (symtab) 846931180e6SGreg Clayton { 847931180e6SGreg Clayton std::vector<uint32_t> symbol_indexes; 84800049b8bSMatt Kopec symtab->AppendSymbolIndexesMatchingRegExAndType (regex, eSymbolTypeAny, Symtab::eDebugAny, Symtab::eVisibilityAny, symbol_indexes); 849c7bece56SGreg Clayton const size_t num_matches = symbol_indexes.size(); 850931180e6SGreg Clayton if (num_matches) 851931180e6SGreg Clayton { 852931180e6SGreg Clayton SymbolContext sc(this); 853d8cf1a11SGreg Clayton const size_t end_functions_added_index = sc_list.GetSize(); 854d8cf1a11SGreg Clayton size_t num_functions_added_to_sc_list = end_functions_added_index - start_size; 855d8cf1a11SGreg Clayton if (num_functions_added_to_sc_list == 0) 856d8cf1a11SGreg Clayton { 857d8cf1a11SGreg Clayton // No functions were added, just symbols, so we can just append them 858d8cf1a11SGreg Clayton for (size_t i = 0; i < num_matches; ++i) 859931180e6SGreg Clayton { 860931180e6SGreg Clayton sc.symbol = symtab->SymbolAtIndex(symbol_indexes[i]); 86100049b8bSMatt Kopec SymbolType sym_type = sc.symbol->GetType(); 86200049b8bSMatt Kopec if (sc.symbol && (sym_type == eSymbolTypeCode || 86300049b8bSMatt Kopec sym_type == eSymbolTypeResolver)) 864d8cf1a11SGreg Clayton sc_list.Append(sc); 865d8cf1a11SGreg Clayton } 866d8cf1a11SGreg Clayton } 867d8cf1a11SGreg Clayton else 868d8cf1a11SGreg Clayton { 869d8cf1a11SGreg Clayton typedef std::map<lldb::addr_t, uint32_t> FileAddrToIndexMap; 870d8cf1a11SGreg Clayton FileAddrToIndexMap file_addr_to_index; 871d8cf1a11SGreg Clayton for (size_t i = start_size; i < end_functions_added_index; ++i) 872d8cf1a11SGreg Clayton { 873d8cf1a11SGreg Clayton const SymbolContext &sc = sc_list[i]; 874d8cf1a11SGreg Clayton if (sc.block) 875d8cf1a11SGreg Clayton continue; 876d8cf1a11SGreg Clayton file_addr_to_index[sc.function->GetAddressRange().GetBaseAddress().GetFileAddress()] = i; 877d8cf1a11SGreg Clayton } 878d8cf1a11SGreg Clayton 879d8cf1a11SGreg Clayton FileAddrToIndexMap::const_iterator end = file_addr_to_index.end(); 880d8cf1a11SGreg Clayton // Functions were added so we need to merge symbols into any 881d8cf1a11SGreg Clayton // existing function symbol contexts 882d8cf1a11SGreg Clayton for (size_t i = start_size; i < num_matches; ++i) 883d8cf1a11SGreg Clayton { 884d8cf1a11SGreg Clayton sc.symbol = symtab->SymbolAtIndex(symbol_indexes[i]); 885d8cf1a11SGreg Clayton SymbolType sym_type = sc.symbol->GetType(); 886358cf1eaSGreg Clayton if (sc.symbol && sc.symbol->ValueIsAddress() && (sym_type == eSymbolTypeCode || sym_type == eSymbolTypeResolver)) 887d8cf1a11SGreg Clayton { 888358cf1eaSGreg Clayton FileAddrToIndexMap::const_iterator pos = file_addr_to_index.find(sc.symbol->GetAddressRef().GetFileAddress()); 889d8cf1a11SGreg Clayton if (pos == end) 890d8cf1a11SGreg Clayton sc_list.Append(sc); 891d8cf1a11SGreg Clayton else 892d8cf1a11SGreg Clayton sc_list[pos->second].symbol = sc.symbol; 893d8cf1a11SGreg Clayton } 894d8cf1a11SGreg Clayton } 895931180e6SGreg Clayton } 896931180e6SGreg Clayton } 897931180e6SGreg Clayton } 898931180e6SGreg Clayton } 899931180e6SGreg Clayton } 900931180e6SGreg Clayton return sc_list.GetSize() - start_size; 90130fdc8d8SChris Lattner } 90230fdc8d8SChris Lattner 903f86248d9SRichard Mitton void 904f86248d9SRichard Mitton Module::FindAddressesForLine (const lldb::TargetSP target_sp, 905f86248d9SRichard Mitton const FileSpec &file, uint32_t line, 906f86248d9SRichard Mitton Function *function, 907f86248d9SRichard Mitton std::vector<Address> &output_local, std::vector<Address> &output_extern) 908f86248d9SRichard Mitton { 909f86248d9SRichard Mitton SearchFilterByModule filter(target_sp, m_file); 910f86248d9SRichard Mitton AddressResolverFileLine resolver(file, line, true); 911f86248d9SRichard Mitton resolver.ResolveAddress (filter); 912f86248d9SRichard Mitton 913f86248d9SRichard Mitton for (size_t n = 0; n < resolver.GetNumberOfAddresses(); n++) 914f86248d9SRichard Mitton { 915f86248d9SRichard Mitton Address addr = resolver.GetAddressRangeAtIndex(n).GetBaseAddress(); 916f86248d9SRichard Mitton Function *f = addr.CalculateSymbolContextFunction(); 917f86248d9SRichard Mitton if (f && f == function) 918f86248d9SRichard Mitton output_local.push_back (addr); 919f86248d9SRichard Mitton else 920f86248d9SRichard Mitton output_extern.push_back (addr); 921f86248d9SRichard Mitton } 922f86248d9SRichard Mitton } 923f86248d9SRichard Mitton 924c7bece56SGreg Clayton size_t 92584db9105SGreg Clayton Module::FindTypes_Impl (const SymbolContext& sc, 92684db9105SGreg Clayton const ConstString &name, 92799558cc4SGreg Clayton const CompilerDeclContext *parent_decl_ctx, 92884db9105SGreg Clayton bool append, 929c7bece56SGreg Clayton size_t max_matches, 930ae088e52SGreg Clayton llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files, 9314069730cSRavitheja Addepally TypeMap& types) 9323504eee8SGreg Clayton { 9333504eee8SGreg Clayton Timer scoped_timer(__PRETTY_FUNCTION__, __PRETTY_FUNCTION__); 934c5dac77aSEugene Zelenko if (!sc.module_sp || sc.module_sp.get() == this) 9353504eee8SGreg Clayton { 9363504eee8SGreg Clayton SymbolVendor *symbols = GetSymbolVendor (); 9373504eee8SGreg Clayton if (symbols) 938ae088e52SGreg Clayton return symbols->FindTypes(sc, name, parent_decl_ctx, append, max_matches, searched_symbol_files, types); 9393504eee8SGreg Clayton } 9403504eee8SGreg Clayton return 0; 9413504eee8SGreg Clayton } 9423504eee8SGreg Clayton 943c7bece56SGreg Clayton size_t 94484db9105SGreg Clayton Module::FindTypesInNamespace (const SymbolContext& sc, 94584db9105SGreg Clayton const ConstString &type_name, 94699558cc4SGreg Clayton const CompilerDeclContext *parent_decl_ctx, 947c7bece56SGreg Clayton size_t max_matches, 94884db9105SGreg Clayton TypeList& type_list) 9496f3533fbSEnrico Granata { 95084db9105SGreg Clayton const bool append = true; 9514069730cSRavitheja Addepally TypeMap types_map; 952ae088e52SGreg Clayton llvm::DenseSet<lldb_private::SymbolFile *> searched_symbol_files; 953ae088e52SGreg Clayton size_t num_types = FindTypes_Impl(sc, type_name, parent_decl_ctx, append, max_matches, searched_symbol_files, types_map); 9544069730cSRavitheja Addepally if (num_types > 0) 9554069730cSRavitheja Addepally sc.SortTypeList(types_map, type_list); 9564069730cSRavitheja Addepally return num_types; 9576f3533fbSEnrico Granata } 9586f3533fbSEnrico Granata 959b43165b7SGreg Clayton lldb::TypeSP 960b43165b7SGreg Clayton Module::FindFirstType (const SymbolContext& sc, 961b43165b7SGreg Clayton const ConstString &name, 962b43165b7SGreg Clayton bool exact_match) 963b43165b7SGreg Clayton { 964b43165b7SGreg Clayton TypeList type_list; 965ae088e52SGreg Clayton llvm::DenseSet<lldb_private::SymbolFile *> searched_symbol_files; 966ae088e52SGreg Clayton const size_t num_matches = FindTypes (sc, name, exact_match, 1, searched_symbol_files, type_list); 967b43165b7SGreg Clayton if (num_matches) 968b43165b7SGreg Clayton return type_list.GetTypeAtIndex(0); 969b43165b7SGreg Clayton return TypeSP(); 970b43165b7SGreg Clayton } 971b43165b7SGreg Clayton 972c7bece56SGreg Clayton size_t 97384db9105SGreg Clayton Module::FindTypes (const SymbolContext& sc, 97484db9105SGreg Clayton const ConstString &name, 97584db9105SGreg Clayton bool exact_match, 976c7bece56SGreg Clayton size_t max_matches, 977ae088e52SGreg Clayton llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files, 97884db9105SGreg Clayton TypeList& types) 9796f3533fbSEnrico Granata { 980c7bece56SGreg Clayton size_t num_matches = 0; 98184db9105SGreg Clayton const char *type_name_cstr = name.GetCString(); 98284db9105SGreg Clayton std::string type_scope; 98384db9105SGreg Clayton std::string type_basename; 98484db9105SGreg Clayton const bool append = true; 9857bc31332SGreg Clayton TypeClass type_class = eTypeClassAny; 9864069730cSRavitheja Addepally TypeMap typesmap; 9877bc31332SGreg Clayton if (Type::GetTypeScopeAndBasename (type_name_cstr, type_scope, type_basename, type_class)) 98884db9105SGreg Clayton { 98984db9105SGreg Clayton // Check if "name" starts with "::" which means the qualified type starts 99084db9105SGreg Clayton // from the root namespace and implies and exact match. The typenames we 99184db9105SGreg Clayton // get back from clang do not start with "::" so we need to strip this off 992d93c4a33SBruce Mitchener // in order to get the qualified names to match 9936f3533fbSEnrico Granata 99484db9105SGreg Clayton if (type_scope.size() >= 2 && type_scope[0] == ':' && type_scope[1] == ':') 9956f3533fbSEnrico Granata { 99684db9105SGreg Clayton type_scope.erase(0,2); 99784db9105SGreg Clayton exact_match = true; 99884db9105SGreg Clayton } 99984db9105SGreg Clayton ConstString type_basename_const_str (type_basename.c_str()); 1000c5dac77aSEugene Zelenko if (FindTypes_Impl(sc, type_basename_const_str, nullptr, append, max_matches, searched_symbol_files, typesmap)) 100184db9105SGreg Clayton { 10024069730cSRavitheja Addepally typesmap.RemoveMismatchedTypes (type_scope, type_basename, type_class, exact_match); 10034069730cSRavitheja Addepally num_matches = typesmap.GetSize(); 10046f3533fbSEnrico Granata } 100584db9105SGreg Clayton } 100684db9105SGreg Clayton else 100784db9105SGreg Clayton { 100884db9105SGreg Clayton // The type is not in a namespace/class scope, just search for it by basename 10097bc31332SGreg Clayton if (type_class != eTypeClassAny) 10107bc31332SGreg Clayton { 10117bc31332SGreg Clayton // The "type_name_cstr" will have been modified if we have a valid type class 10127bc31332SGreg Clayton // prefix (like "struct", "class", "union", "typedef" etc). 1013c5dac77aSEugene Zelenko FindTypes_Impl(sc, ConstString(type_name_cstr), nullptr, append, max_matches, searched_symbol_files, typesmap); 10144069730cSRavitheja Addepally typesmap.RemoveMismatchedTypes (type_class); 10154069730cSRavitheja Addepally num_matches = typesmap.GetSize(); 10167bc31332SGreg Clayton } 10177bc31332SGreg Clayton else 10187bc31332SGreg Clayton { 1019c5dac77aSEugene Zelenko num_matches = FindTypes_Impl(sc, name, nullptr, append, max_matches, searched_symbol_files, typesmap); 102084db9105SGreg Clayton } 10217bc31332SGreg Clayton } 10224069730cSRavitheja Addepally if (num_matches > 0) 10234069730cSRavitheja Addepally sc.SortTypeList(typesmap, types); 102484db9105SGreg Clayton return num_matches; 10256f3533fbSEnrico Granata } 10266f3533fbSEnrico Granata 102730fdc8d8SChris Lattner SymbolVendor* 1028136dff87SGreg Clayton Module::GetSymbolVendor (bool can_create, lldb_private::Stream *feedback_strm) 102930fdc8d8SChris Lattner { 1030c5dac77aSEugene Zelenko if (!m_did_load_symbol_vendor.load()) 103188c05f54SGreg Clayton { 103216ff8604SSaleem Abdulrasool std::lock_guard<std::recursive_mutex> guard(m_mutex); 1033c5dac77aSEugene Zelenko if (!m_did_load_symbol_vendor.load() && can_create) 103430fdc8d8SChris Lattner { 103530fdc8d8SChris Lattner ObjectFile *obj_file = GetObjectFile (); 1036c5dac77aSEugene Zelenko if (obj_file != nullptr) 103730fdc8d8SChris Lattner { 103830fdc8d8SChris Lattner Timer scoped_timer(__PRETTY_FUNCTION__, __PRETTY_FUNCTION__); 1039136dff87SGreg Clayton m_symfile_ap.reset(SymbolVendor::FindPlugin(shared_from_this(), feedback_strm)); 1040e83e731eSGreg Clayton m_did_load_symbol_vendor = true; 104130fdc8d8SChris Lattner } 104230fdc8d8SChris Lattner } 104388c05f54SGreg Clayton } 104430fdc8d8SChris Lattner return m_symfile_ap.get(); 104530fdc8d8SChris Lattner } 104630fdc8d8SChris Lattner 104730fdc8d8SChris Lattner void 104830fdc8d8SChris Lattner Module::SetFileSpecAndObjectName (const FileSpec &file, const ConstString &object_name) 104930fdc8d8SChris Lattner { 105030fdc8d8SChris Lattner // Container objects whose paths do not specify a file directly can call 105130fdc8d8SChris Lattner // this function to correct the file and object names. 105230fdc8d8SChris Lattner m_file = file; 105330fdc8d8SChris Lattner m_mod_time = file.GetModificationTime(); 105430fdc8d8SChris Lattner m_object_name = object_name; 105530fdc8d8SChris Lattner } 105630fdc8d8SChris Lattner 105730fdc8d8SChris Lattner const ArchSpec& 105830fdc8d8SChris Lattner Module::GetArchitecture () const 105930fdc8d8SChris Lattner { 106030fdc8d8SChris Lattner return m_arch; 106130fdc8d8SChris Lattner } 106230fdc8d8SChris Lattner 1063b5ad4ec7SGreg Clayton std::string 1064b5ad4ec7SGreg Clayton Module::GetSpecificationDescription () const 1065b5ad4ec7SGreg Clayton { 1066b5ad4ec7SGreg Clayton std::string spec(GetFileSpec().GetPath()); 1067b5ad4ec7SGreg Clayton if (m_object_name) 1068b5ad4ec7SGreg Clayton { 1069b5ad4ec7SGreg Clayton spec += '('; 1070b5ad4ec7SGreg Clayton spec += m_object_name.GetCString(); 1071b5ad4ec7SGreg Clayton spec += ')'; 1072b5ad4ec7SGreg Clayton } 1073b5ad4ec7SGreg Clayton return spec; 1074b5ad4ec7SGreg Clayton } 1075b5ad4ec7SGreg Clayton 107630fdc8d8SChris Lattner void 1077c982b3d6SGreg Clayton Module::GetDescription (Stream *s, lldb::DescriptionLevel level) 1078ceb6b139SCaroline Tice { 107916ff8604SSaleem Abdulrasool std::lock_guard<std::recursive_mutex> guard(m_mutex); 1080ceb6b139SCaroline Tice 1081c982b3d6SGreg Clayton if (level >= eDescriptionLevelFull) 1082c982b3d6SGreg Clayton { 1083cfd1acedSGreg Clayton if (m_arch.IsValid()) 108464195a2cSGreg Clayton s->Printf("(%s) ", m_arch.GetArchitectureName()); 1085c982b3d6SGreg Clayton } 1086ceb6b139SCaroline Tice 1087c982b3d6SGreg Clayton if (level == eDescriptionLevelBrief) 1088c982b3d6SGreg Clayton { 1089c982b3d6SGreg Clayton const char *filename = m_file.GetFilename().GetCString(); 1090c982b3d6SGreg Clayton if (filename) 1091c982b3d6SGreg Clayton s->PutCString (filename); 1092c982b3d6SGreg Clayton } 1093c982b3d6SGreg Clayton else 1094c982b3d6SGreg Clayton { 1095cfd1acedSGreg Clayton char path[PATH_MAX]; 1096cfd1acedSGreg Clayton if (m_file.GetPath(path, sizeof(path))) 1097cfd1acedSGreg Clayton s->PutCString(path); 1098c982b3d6SGreg Clayton } 1099cfd1acedSGreg Clayton 1100cfd1acedSGreg Clayton const char *object_name = m_object_name.GetCString(); 1101cfd1acedSGreg Clayton if (object_name) 1102cfd1acedSGreg Clayton s->Printf("(%s)", object_name); 1103ceb6b139SCaroline Tice } 1104ceb6b139SCaroline Tice 1105ceb6b139SCaroline Tice void 1106c982b3d6SGreg Clayton Module::ReportError (const char *format, ...) 1107c982b3d6SGreg Clayton { 1108e38a5eddSGreg Clayton if (format && format[0]) 1109e38a5eddSGreg Clayton { 1110e38a5eddSGreg Clayton StreamString strm; 1111e38a5eddSGreg Clayton strm.PutCString("error: "); 1112e38a5eddSGreg Clayton GetDescription(&strm, lldb::eDescriptionLevelBrief); 11138b35334eSGreg Clayton strm.PutChar (' '); 1114c982b3d6SGreg Clayton va_list args; 1115c982b3d6SGreg Clayton va_start (args, format); 1116e38a5eddSGreg Clayton strm.PrintfVarArg(format, args); 1117c982b3d6SGreg Clayton va_end (args); 1118e38a5eddSGreg Clayton 1119e38a5eddSGreg Clayton const int format_len = strlen(format); 1120e38a5eddSGreg Clayton if (format_len > 0) 1121e38a5eddSGreg Clayton { 1122e38a5eddSGreg Clayton const char last_char = format[format_len-1]; 1123e38a5eddSGreg Clayton if (last_char != '\n' || last_char != '\r') 1124e38a5eddSGreg Clayton strm.EOL(); 1125e38a5eddSGreg Clayton } 1126e38a5eddSGreg Clayton Host::SystemLog (Host::eSystemLogError, "%s", strm.GetString().c_str()); 1127e38a5eddSGreg Clayton } 1128e38a5eddSGreg Clayton } 1129e38a5eddSGreg Clayton 11301d60909eSGreg Clayton bool 11311d60909eSGreg Clayton Module::FileHasChanged () const 11321d60909eSGreg Clayton { 1133c5dac77aSEugene Zelenko if (!m_file_has_changed) 11341d60909eSGreg Clayton m_file_has_changed = (m_file.GetModificationTime() != m_mod_time); 11351d60909eSGreg Clayton return m_file_has_changed; 11361d60909eSGreg Clayton } 11371d60909eSGreg Clayton 1138e38a5eddSGreg Clayton void 1139e38a5eddSGreg Clayton Module::ReportErrorIfModifyDetected (const char *format, ...) 1140e38a5eddSGreg Clayton { 1141c5dac77aSEugene Zelenko if (!m_first_file_changed_log) 1142e38a5eddSGreg Clayton { 11431d60909eSGreg Clayton if (FileHasChanged ()) 11441d60909eSGreg Clayton { 11451d60909eSGreg Clayton m_first_file_changed_log = true; 1146e38a5eddSGreg Clayton if (format) 1147e38a5eddSGreg Clayton { 1148e38a5eddSGreg Clayton StreamString strm; 1149e38a5eddSGreg Clayton strm.PutCString("error: the object file "); 1150e38a5eddSGreg Clayton GetDescription(&strm, lldb::eDescriptionLevelFull); 1151e38a5eddSGreg Clayton strm.PutCString (" has been modified\n"); 1152e38a5eddSGreg Clayton 1153e38a5eddSGreg Clayton va_list args; 1154e38a5eddSGreg Clayton va_start (args, format); 1155e38a5eddSGreg Clayton strm.PrintfVarArg(format, args); 1156e38a5eddSGreg Clayton va_end (args); 1157e38a5eddSGreg Clayton 1158e38a5eddSGreg Clayton const int format_len = strlen(format); 1159e38a5eddSGreg Clayton if (format_len > 0) 1160e38a5eddSGreg Clayton { 1161e38a5eddSGreg Clayton const char last_char = format[format_len-1]; 1162e38a5eddSGreg Clayton if (last_char != '\n' || last_char != '\r') 1163e38a5eddSGreg Clayton strm.EOL(); 1164e38a5eddSGreg Clayton } 1165e38a5eddSGreg Clayton strm.PutCString("The debug session should be aborted as the original debug information has been overwritten.\n"); 1166e38a5eddSGreg Clayton Host::SystemLog (Host::eSystemLogError, "%s", strm.GetString().c_str()); 1167e38a5eddSGreg Clayton } 1168e38a5eddSGreg Clayton } 1169c982b3d6SGreg Clayton } 11701d60909eSGreg Clayton } 1171c982b3d6SGreg Clayton 1172c982b3d6SGreg Clayton void 1173c982b3d6SGreg Clayton Module::ReportWarning (const char *format, ...) 1174c982b3d6SGreg Clayton { 1175e38a5eddSGreg Clayton if (format && format[0]) 1176e38a5eddSGreg Clayton { 1177e38a5eddSGreg Clayton StreamString strm; 1178e38a5eddSGreg Clayton strm.PutCString("warning: "); 11798b35334eSGreg Clayton GetDescription(&strm, lldb::eDescriptionLevelFull); 11808b35334eSGreg Clayton strm.PutChar (' '); 1181c982b3d6SGreg Clayton 1182c982b3d6SGreg Clayton va_list args; 1183c982b3d6SGreg Clayton va_start (args, format); 1184e38a5eddSGreg Clayton strm.PrintfVarArg(format, args); 1185c982b3d6SGreg Clayton va_end (args); 1186e38a5eddSGreg Clayton 1187e38a5eddSGreg Clayton const int format_len = strlen(format); 1188e38a5eddSGreg Clayton if (format_len > 0) 1189e38a5eddSGreg Clayton { 1190e38a5eddSGreg Clayton const char last_char = format[format_len-1]; 1191e38a5eddSGreg Clayton if (last_char != '\n' || last_char != '\r') 1192e38a5eddSGreg Clayton strm.EOL(); 1193e38a5eddSGreg Clayton } 1194e38a5eddSGreg Clayton Host::SystemLog (Host::eSystemLogWarning, "%s", strm.GetString().c_str()); 1195e38a5eddSGreg Clayton } 1196c982b3d6SGreg Clayton } 1197c982b3d6SGreg Clayton 1198c982b3d6SGreg Clayton void 1199c982b3d6SGreg Clayton Module::LogMessage (Log *log, const char *format, ...) 1200c982b3d6SGreg Clayton { 1201c5dac77aSEugene Zelenko if (log != nullptr) 1202c982b3d6SGreg Clayton { 1203c982b3d6SGreg Clayton StreamString log_message; 12048b35334eSGreg Clayton GetDescription(&log_message, lldb::eDescriptionLevelFull); 1205c982b3d6SGreg Clayton log_message.PutCString (": "); 1206c982b3d6SGreg Clayton va_list args; 1207c982b3d6SGreg Clayton va_start (args, format); 1208c982b3d6SGreg Clayton log_message.PrintfVarArg (format, args); 1209c982b3d6SGreg Clayton va_end (args); 1210c982b3d6SGreg Clayton log->PutCString(log_message.GetString().c_str()); 1211c982b3d6SGreg Clayton } 1212c982b3d6SGreg Clayton } 1213c982b3d6SGreg Clayton 1214d61c0fc0SGreg Clayton void 1215d61c0fc0SGreg Clayton Module::LogMessageVerboseBacktrace (Log *log, const char *format, ...) 1216d61c0fc0SGreg Clayton { 1217c5dac77aSEugene Zelenko if (log != nullptr) 1218d61c0fc0SGreg Clayton { 1219d61c0fc0SGreg Clayton StreamString log_message; 1220d61c0fc0SGreg Clayton GetDescription(&log_message, lldb::eDescriptionLevelFull); 1221d61c0fc0SGreg Clayton log_message.PutCString (": "); 1222d61c0fc0SGreg Clayton va_list args; 1223d61c0fc0SGreg Clayton va_start (args, format); 1224d61c0fc0SGreg Clayton log_message.PrintfVarArg (format, args); 1225d61c0fc0SGreg Clayton va_end (args); 1226d61c0fc0SGreg Clayton if (log->GetVerbose()) 1227a893d301SZachary Turner { 1228a893d301SZachary Turner std::string back_trace; 1229a893d301SZachary Turner llvm::raw_string_ostream stream(back_trace); 1230a893d301SZachary Turner llvm::sys::PrintStackTrace(stream); 1231a893d301SZachary Turner log_message.PutCString(back_trace.c_str()); 1232a893d301SZachary Turner } 1233d61c0fc0SGreg Clayton log->PutCString(log_message.GetString().c_str()); 1234d61c0fc0SGreg Clayton } 1235d61c0fc0SGreg Clayton } 1236d61c0fc0SGreg Clayton 1237c982b3d6SGreg Clayton void 123830fdc8d8SChris Lattner Module::Dump(Stream *s) 123930fdc8d8SChris Lattner { 124016ff8604SSaleem Abdulrasool std::lock_guard<std::recursive_mutex> guard(m_mutex); 12418941142aSGreg Clayton //s->Printf("%.*p: ", (int)sizeof(void*) * 2, this); 124230fdc8d8SChris Lattner s->Indent(); 1243b5ad4ec7SGreg Clayton s->Printf("Module %s%s%s%s\n", 1244b5ad4ec7SGreg Clayton m_file.GetPath().c_str(), 124530fdc8d8SChris Lattner m_object_name ? "(" : "", 124630fdc8d8SChris Lattner m_object_name ? m_object_name.GetCString() : "", 124730fdc8d8SChris Lattner m_object_name ? ")" : ""); 124830fdc8d8SChris Lattner 124930fdc8d8SChris Lattner s->IndentMore(); 125030fdc8d8SChris Lattner 1251a7499c98SMichael Sartain ObjectFile *objfile = GetObjectFile (); 125230fdc8d8SChris Lattner if (objfile) 125330fdc8d8SChris Lattner objfile->Dump(s); 125430fdc8d8SChris Lattner 125530fdc8d8SChris Lattner SymbolVendor *symbols = GetSymbolVendor (); 125630fdc8d8SChris Lattner if (symbols) 125730fdc8d8SChris Lattner symbols->Dump(s); 125830fdc8d8SChris Lattner 125930fdc8d8SChris Lattner s->IndentLess(); 126030fdc8d8SChris Lattner } 126130fdc8d8SChris Lattner 126230fdc8d8SChris Lattner TypeList* 126330fdc8d8SChris Lattner Module::GetTypeList () 126430fdc8d8SChris Lattner { 126530fdc8d8SChris Lattner SymbolVendor *symbols = GetSymbolVendor (); 126630fdc8d8SChris Lattner if (symbols) 126730fdc8d8SChris Lattner return &symbols->GetTypeList(); 1268c5dac77aSEugene Zelenko return nullptr; 126930fdc8d8SChris Lattner } 127030fdc8d8SChris Lattner 127130fdc8d8SChris Lattner const ConstString & 127230fdc8d8SChris Lattner Module::GetObjectName() const 127330fdc8d8SChris Lattner { 127430fdc8d8SChris Lattner return m_object_name; 127530fdc8d8SChris Lattner } 127630fdc8d8SChris Lattner 127730fdc8d8SChris Lattner ObjectFile * 127830fdc8d8SChris Lattner Module::GetObjectFile() 127930fdc8d8SChris Lattner { 1280c5dac77aSEugene Zelenko if (!m_did_load_objfile.load()) 128188c05f54SGreg Clayton { 128216ff8604SSaleem Abdulrasool std::lock_guard<std::recursive_mutex> guard(m_mutex); 1283c5dac77aSEugene Zelenko if (!m_did_load_objfile.load()) 128430fdc8d8SChris Lattner { 128530fdc8d8SChris Lattner Timer scoped_timer(__PRETTY_FUNCTION__, 128630fdc8d8SChris Lattner "Module::GetObjectFile () module = %s", GetFileSpec().GetFilename().AsCString("")); 12875ce9c565SGreg Clayton DataBufferSP data_sp; 12885ce9c565SGreg Clayton lldb::offset_t data_offset = 0; 12892540a8a7SGreg Clayton const lldb::offset_t file_size = m_file.GetByteSize(); 12902540a8a7SGreg Clayton if (file_size > m_object_offset) 12912540a8a7SGreg Clayton { 12922540a8a7SGreg Clayton m_did_load_objfile = true; 1293e72dfb32SGreg Clayton m_objfile_sp = ObjectFile::FindPlugin (shared_from_this(), 1294e72dfb32SGreg Clayton &m_file, 1295e72dfb32SGreg Clayton m_object_offset, 12962540a8a7SGreg Clayton file_size - m_object_offset, 12975ce9c565SGreg Clayton data_sp, 12985ce9c565SGreg Clayton data_offset); 1299593577a1SGreg Clayton if (m_objfile_sp) 1300593577a1SGreg Clayton { 1301593577a1SGreg Clayton // Once we get the object file, update our module with the object file's 1302593577a1SGreg Clayton // architecture since it might differ in vendor/os if some parts were 13035e6f4520SZachary Turner // unknown. But since the matching arch might already be more specific 13045e6f4520SZachary Turner // than the generic COFF architecture, only merge in those values that 13055e6f4520SZachary Turner // overwrite unspecified unknown values. 13065e6f4520SZachary Turner ArchSpec new_arch; 13075e6f4520SZachary Turner m_objfile_sp->GetArchitecture(new_arch); 13085e6f4520SZachary Turner m_arch.MergeFrom(new_arch); 1309593577a1SGreg Clayton } 13100ee56ce6STodd Fiala else 13110ee56ce6STodd Fiala { 13120ee56ce6STodd Fiala ReportError ("failed to load objfile for %s", GetFileSpec().GetPath().c_str()); 13130ee56ce6STodd Fiala } 131430fdc8d8SChris Lattner } 13152540a8a7SGreg Clayton } 131688c05f54SGreg Clayton } 1317762f7135SGreg Clayton return m_objfile_sp.get(); 131830fdc8d8SChris Lattner } 131930fdc8d8SChris Lattner 1320a7499c98SMichael Sartain SectionList * 13213046e668SGreg Clayton Module::GetSectionList() 13223046e668SGreg Clayton { 13233046e668SGreg Clayton // Populate m_unified_sections_ap with sections from objfile. 1324c5dac77aSEugene Zelenko if (!m_sections_ap) 13253046e668SGreg Clayton { 13263046e668SGreg Clayton ObjectFile *obj_file = GetObjectFile(); 1327c5dac77aSEugene Zelenko if (obj_file != nullptr) 13283046e668SGreg Clayton obj_file->CreateSections(*GetUnifiedSectionList()); 13293046e668SGreg Clayton } 13303046e668SGreg Clayton return m_sections_ap.get(); 13313046e668SGreg Clayton } 13323046e668SGreg Clayton 133305a09c67SJason Molenda void 133405a09c67SJason Molenda Module::SectionFileAddressesChanged () 133505a09c67SJason Molenda { 133605a09c67SJason Molenda ObjectFile *obj_file = GetObjectFile (); 133705a09c67SJason Molenda if (obj_file) 133805a09c67SJason Molenda obj_file->SectionFileAddressesChanged (); 133905a09c67SJason Molenda SymbolVendor* sym_vendor = GetSymbolVendor(); 1340c5dac77aSEugene Zelenko if (sym_vendor != nullptr) 134105a09c67SJason Molenda sym_vendor->SectionFileAddressesChanged (); 134205a09c67SJason Molenda } 134305a09c67SJason Molenda 13443046e668SGreg Clayton SectionList * 1345a7499c98SMichael Sartain Module::GetUnifiedSectionList() 1346a7499c98SMichael Sartain { 13473046e668SGreg Clayton // Populate m_unified_sections_ap with sections from objfile. 1348c5dac77aSEugene Zelenko if (!m_sections_ap) 13493046e668SGreg Clayton m_sections_ap.reset(new SectionList()); 13503046e668SGreg Clayton return m_sections_ap.get(); 1351a7499c98SMichael Sartain } 135230fdc8d8SChris Lattner 135330fdc8d8SChris Lattner const Symbol * 135430fdc8d8SChris Lattner Module::FindFirstSymbolWithNameAndType (const ConstString &name, SymbolType symbol_type) 135530fdc8d8SChris Lattner { 135630fdc8d8SChris Lattner Timer scoped_timer(__PRETTY_FUNCTION__, 135730fdc8d8SChris Lattner "Module::FindFirstSymbolWithNameAndType (name = %s, type = %i)", 135830fdc8d8SChris Lattner name.AsCString(), 135930fdc8d8SChris Lattner symbol_type); 1360a7499c98SMichael Sartain SymbolVendor* sym_vendor = GetSymbolVendor(); 1361a7499c98SMichael Sartain if (sym_vendor) 136230fdc8d8SChris Lattner { 1363a7499c98SMichael Sartain Symtab *symtab = sym_vendor->GetSymtab(); 136430fdc8d8SChris Lattner if (symtab) 1365bcf2cfbdSGreg Clayton return symtab->FindFirstSymbolWithNameAndType (name, symbol_type, Symtab::eDebugAny, Symtab::eVisibilityAny); 136630fdc8d8SChris Lattner } 1367c5dac77aSEugene Zelenko return nullptr; 136830fdc8d8SChris Lattner } 136930fdc8d8SChris Lattner void 137030fdc8d8SChris Lattner Module::SymbolIndicesToSymbolContextList (Symtab *symtab, std::vector<uint32_t> &symbol_indexes, SymbolContextList &sc_list) 137130fdc8d8SChris Lattner { 137230fdc8d8SChris Lattner // No need to protect this call using m_mutex all other method calls are 137330fdc8d8SChris Lattner // already thread safe. 137430fdc8d8SChris Lattner 137530fdc8d8SChris Lattner size_t num_indices = symbol_indexes.size(); 137630fdc8d8SChris Lattner if (num_indices > 0) 137730fdc8d8SChris Lattner { 137830fdc8d8SChris Lattner SymbolContext sc; 137930fdc8d8SChris Lattner CalculateSymbolContext (&sc); 138030fdc8d8SChris Lattner for (size_t i = 0; i < num_indices; i++) 138130fdc8d8SChris Lattner { 138230fdc8d8SChris Lattner sc.symbol = symtab->SymbolAtIndex (symbol_indexes[i]); 138330fdc8d8SChris Lattner if (sc.symbol) 138430fdc8d8SChris Lattner sc_list.Append (sc); 138530fdc8d8SChris Lattner } 138630fdc8d8SChris Lattner } 138730fdc8d8SChris Lattner } 138830fdc8d8SChris Lattner 138930fdc8d8SChris Lattner size_t 1390c1b2ccfdSGreg Clayton Module::FindFunctionSymbols (const ConstString &name, 1391c1b2ccfdSGreg Clayton uint32_t name_type_mask, 1392c1b2ccfdSGreg Clayton SymbolContextList& sc_list) 1393c1b2ccfdSGreg Clayton { 1394c1b2ccfdSGreg Clayton Timer scoped_timer(__PRETTY_FUNCTION__, 1395c1b2ccfdSGreg Clayton "Module::FindSymbolsFunctions (name = %s, mask = 0x%8.8x)", 1396c1b2ccfdSGreg Clayton name.AsCString(), 1397c1b2ccfdSGreg Clayton name_type_mask); 1398a7499c98SMichael Sartain SymbolVendor* sym_vendor = GetSymbolVendor(); 1399a7499c98SMichael Sartain if (sym_vendor) 1400c1b2ccfdSGreg Clayton { 1401a7499c98SMichael Sartain Symtab *symtab = sym_vendor->GetSymtab(); 1402c1b2ccfdSGreg Clayton if (symtab) 1403c1b2ccfdSGreg Clayton return symtab->FindFunctionSymbols (name, name_type_mask, sc_list); 1404c1b2ccfdSGreg Clayton } 1405c1b2ccfdSGreg Clayton return 0; 1406c1b2ccfdSGreg Clayton } 1407c1b2ccfdSGreg Clayton 1408c1b2ccfdSGreg Clayton size_t 1409b96ff33bSSean Callanan Module::FindSymbolsWithNameAndType (const ConstString &name, SymbolType symbol_type, SymbolContextList &sc_list) 141030fdc8d8SChris Lattner { 141130fdc8d8SChris Lattner // No need to protect this call using m_mutex all other method calls are 141230fdc8d8SChris Lattner // already thread safe. 141330fdc8d8SChris Lattner 141430fdc8d8SChris Lattner Timer scoped_timer(__PRETTY_FUNCTION__, 141530fdc8d8SChris Lattner "Module::FindSymbolsWithNameAndType (name = %s, type = %i)", 141630fdc8d8SChris Lattner name.AsCString(), 141730fdc8d8SChris Lattner symbol_type); 141830fdc8d8SChris Lattner const size_t initial_size = sc_list.GetSize(); 1419a7499c98SMichael Sartain SymbolVendor* sym_vendor = GetSymbolVendor(); 1420a7499c98SMichael Sartain if (sym_vendor) 142130fdc8d8SChris Lattner { 1422a7499c98SMichael Sartain Symtab *symtab = sym_vendor->GetSymtab(); 142330fdc8d8SChris Lattner if (symtab) 142430fdc8d8SChris Lattner { 142530fdc8d8SChris Lattner std::vector<uint32_t> symbol_indexes; 142630fdc8d8SChris Lattner symtab->FindAllSymbolsWithNameAndType (name, symbol_type, symbol_indexes); 142730fdc8d8SChris Lattner SymbolIndicesToSymbolContextList (symtab, symbol_indexes, sc_list); 142830fdc8d8SChris Lattner } 142930fdc8d8SChris Lattner } 143030fdc8d8SChris Lattner return sc_list.GetSize() - initial_size; 143130fdc8d8SChris Lattner } 143230fdc8d8SChris Lattner 143330fdc8d8SChris Lattner size_t 143430fdc8d8SChris Lattner Module::FindSymbolsMatchingRegExAndType (const RegularExpression ®ex, SymbolType symbol_type, SymbolContextList &sc_list) 143530fdc8d8SChris Lattner { 143630fdc8d8SChris Lattner // No need to protect this call using m_mutex all other method calls are 143730fdc8d8SChris Lattner // already thread safe. 143830fdc8d8SChris Lattner 143930fdc8d8SChris Lattner Timer scoped_timer(__PRETTY_FUNCTION__, 144030fdc8d8SChris Lattner "Module::FindSymbolsMatchingRegExAndType (regex = %s, type = %i)", 144130fdc8d8SChris Lattner regex.GetText(), 144230fdc8d8SChris Lattner symbol_type); 144330fdc8d8SChris Lattner const size_t initial_size = sc_list.GetSize(); 1444a7499c98SMichael Sartain SymbolVendor* sym_vendor = GetSymbolVendor(); 1445a7499c98SMichael Sartain if (sym_vendor) 144630fdc8d8SChris Lattner { 1447a7499c98SMichael Sartain Symtab *symtab = sym_vendor->GetSymtab(); 144830fdc8d8SChris Lattner if (symtab) 144930fdc8d8SChris Lattner { 145030fdc8d8SChris Lattner std::vector<uint32_t> symbol_indexes; 1451bcf2cfbdSGreg Clayton symtab->FindAllSymbolsMatchingRexExAndType (regex, symbol_type, Symtab::eDebugAny, Symtab::eVisibilityAny, symbol_indexes); 145230fdc8d8SChris Lattner SymbolIndicesToSymbolContextList (symtab, symbol_indexes, sc_list); 145330fdc8d8SChris Lattner } 145430fdc8d8SChris Lattner } 145530fdc8d8SChris Lattner return sc_list.GetSize() - initial_size; 145630fdc8d8SChris Lattner } 145730fdc8d8SChris Lattner 1458e01e07b6SGreg Clayton void 1459e01e07b6SGreg Clayton Module::SetSymbolFileFileSpec (const FileSpec &file) 1460e01e07b6SGreg Clayton { 146190271672SGreg Clayton if (!file.Exists()) 146290271672SGreg Clayton return; 1463a7499c98SMichael Sartain if (m_symfile_ap) 1464a7499c98SMichael Sartain { 146590271672SGreg Clayton // Remove any sections in the unified section list that come from the current symbol vendor. 14663046e668SGreg Clayton SectionList *section_list = GetSectionList(); 1467a7499c98SMichael Sartain SymbolFile *symbol_file = m_symfile_ap->GetSymbolFile(); 1468a7499c98SMichael Sartain if (section_list && symbol_file) 1469a7499c98SMichael Sartain { 1470a7499c98SMichael Sartain ObjectFile *obj_file = symbol_file->GetObjectFile(); 1471540fbbfaSGreg Clayton // Make sure we have an object file and that the symbol vendor's objfile isn't 1472540fbbfaSGreg Clayton // the same as the module's objfile before we remove any sections for it... 147390271672SGreg Clayton if (obj_file) 147490271672SGreg Clayton { 147590271672SGreg Clayton // Check to make sure we aren't trying to specify the file we already have 147690271672SGreg Clayton if (obj_file->GetFileSpec() == file) 147790271672SGreg Clayton { 147890271672SGreg Clayton // We are being told to add the exact same file that we already have 147990271672SGreg Clayton // we don't have to do anything. 148090271672SGreg Clayton return; 148190271672SGreg Clayton } 1482d00438e8STamas Berghammer 1483d00438e8STamas Berghammer // Cleare the current symtab as we are going to replace it with a new one 1484d00438e8STamas Berghammer obj_file->ClearSymtab(); 148590271672SGreg Clayton 148690271672SGreg Clayton // The symbol file might be a directory bundle ("/tmp/a.out.dSYM") instead 148790271672SGreg Clayton // of a full path to the symbol file within the bundle 148890271672SGreg Clayton // ("/tmp/a.out.dSYM/Contents/Resources/DWARF/a.out"). So we need to check this 148990271672SGreg Clayton 149090271672SGreg Clayton if (file.IsDirectory()) 149190271672SGreg Clayton { 149290271672SGreg Clayton std::string new_path(file.GetPath()); 149390271672SGreg Clayton std::string old_path(obj_file->GetFileSpec().GetPath()); 149490271672SGreg Clayton if (old_path.find(new_path) == 0) 149590271672SGreg Clayton { 149690271672SGreg Clayton // We specified the same bundle as the symbol file that we already have 149790271672SGreg Clayton return; 149890271672SGreg Clayton } 149990271672SGreg Clayton } 150090271672SGreg Clayton 150190271672SGreg Clayton if (obj_file != m_objfile_sp.get()) 1502a7499c98SMichael Sartain { 1503a7499c98SMichael Sartain size_t num_sections = section_list->GetNumSections (0); 1504a7499c98SMichael Sartain for (size_t idx = num_sections; idx > 0; --idx) 1505a7499c98SMichael Sartain { 1506a7499c98SMichael Sartain lldb::SectionSP section_sp (section_list->GetSectionAtIndex (idx - 1)); 1507a7499c98SMichael Sartain if (section_sp->GetObjectFile() == obj_file) 1508a7499c98SMichael Sartain { 15093046e668SGreg Clayton section_list->DeleteSection (idx - 1); 1510a7499c98SMichael Sartain } 1511a7499c98SMichael Sartain } 1512a7499c98SMichael Sartain } 1513a7499c98SMichael Sartain } 1514a7499c98SMichael Sartain } 151590271672SGreg Clayton // Keep all old symbol files around in case there are any lingering type references in 151690271672SGreg Clayton // any SBValue objects that might have been handed out. 151790271672SGreg Clayton m_old_symfiles.push_back(std::move(m_symfile_ap)); 151890271672SGreg Clayton } 1519e01e07b6SGreg Clayton m_symfile_spec = file; 1520e01e07b6SGreg Clayton m_symfile_ap.reset(); 1521e01e07b6SGreg Clayton m_did_load_symbol_vendor = false; 1522e01e07b6SGreg Clayton } 1523e01e07b6SGreg Clayton 15245aee162fSJim Ingham bool 15255aee162fSJim Ingham Module::IsExecutable () 15265aee162fSJim Ingham { 1527c5dac77aSEugene Zelenko if (GetObjectFile() == nullptr) 15285aee162fSJim Ingham return false; 15295aee162fSJim Ingham else 15305aee162fSJim Ingham return GetObjectFile()->IsExecutable(); 15315aee162fSJim Ingham } 15325aee162fSJim Ingham 15335aee162fSJim Ingham bool 1534b53cb271SJim Ingham Module::IsLoadedInTarget (Target *target) 1535b53cb271SJim Ingham { 1536b53cb271SJim Ingham ObjectFile *obj_file = GetObjectFile(); 1537b53cb271SJim Ingham if (obj_file) 1538b53cb271SJim Ingham { 15393046e668SGreg Clayton SectionList *sections = GetSectionList(); 1540c5dac77aSEugene Zelenko if (sections != nullptr) 1541b53cb271SJim Ingham { 1542b53cb271SJim Ingham size_t num_sections = sections->GetSize(); 1543b53cb271SJim Ingham for (size_t sect_idx = 0; sect_idx < num_sections; sect_idx++) 1544b53cb271SJim Ingham { 1545b53cb271SJim Ingham SectionSP section_sp = sections->GetSectionAtIndex(sect_idx); 1546b53cb271SJim Ingham if (section_sp->GetLoadBaseAddress(target) != LLDB_INVALID_ADDRESS) 1547b53cb271SJim Ingham { 1548b53cb271SJim Ingham return true; 1549b53cb271SJim Ingham } 1550b53cb271SJim Ingham } 1551b53cb271SJim Ingham } 1552b53cb271SJim Ingham } 1553b53cb271SJim Ingham return false; 1554b53cb271SJim Ingham } 15551759848bSEnrico Granata 15561759848bSEnrico Granata bool 15579730339bSEnrico Granata Module::LoadScriptingResourceInTarget (Target *target, Error& error, Stream* feedback_stream) 15581759848bSEnrico Granata { 15591759848bSEnrico Granata if (!target) 15601759848bSEnrico Granata { 15611759848bSEnrico Granata error.SetErrorString("invalid destination Target"); 15621759848bSEnrico Granata return false; 15631759848bSEnrico Granata } 15641759848bSEnrico Granata 1565d93c4a33SBruce Mitchener LoadScriptFromSymFile should_load = target->TargetProperties::GetLoadScriptFromSymbolFile(); 15662ea43cdcSEnrico Granata 1567994740fbSGreg Clayton if (should_load == eLoadScriptFromSymFileFalse) 1568994740fbSGreg Clayton return false; 1569994740fbSGreg Clayton 157091c0e749SGreg Clayton Debugger &debugger = target->GetDebugger(); 157191c0e749SGreg Clayton const ScriptLanguage script_language = debugger.GetScriptLanguage(); 157291c0e749SGreg Clayton if (script_language != eScriptLanguageNone) 157391c0e749SGreg Clayton { 157491c0e749SGreg Clayton 15751759848bSEnrico Granata PlatformSP platform_sp(target->GetPlatform()); 15761759848bSEnrico Granata 15771759848bSEnrico Granata if (!platform_sp) 15781759848bSEnrico Granata { 15791759848bSEnrico Granata error.SetErrorString("invalid Platform"); 15801759848bSEnrico Granata return false; 15811759848bSEnrico Granata } 15821759848bSEnrico Granata 158391c0e749SGreg Clayton FileSpecList file_specs = platform_sp->LocateExecutableScriptingResources (target, 1584fe7295dcSEnrico Granata *this, 1585fe7295dcSEnrico Granata feedback_stream); 158691c0e749SGreg Clayton 158791c0e749SGreg Clayton const uint32_t num_specs = file_specs.GetSize(); 158891c0e749SGreg Clayton if (num_specs) 158991c0e749SGreg Clayton { 1590b9d8890bSGreg Clayton ScriptInterpreter *script_interpreter = debugger.GetCommandInterpreter().GetScriptInterpreter(); 1591b9d8890bSGreg Clayton if (script_interpreter) 1592b9d8890bSGreg Clayton { 159391c0e749SGreg Clayton for (uint32_t i = 0; i < num_specs; ++i) 159491c0e749SGreg Clayton { 159591c0e749SGreg Clayton FileSpec scripting_fspec (file_specs.GetFileSpecAtIndex(i)); 159691c0e749SGreg Clayton if (scripting_fspec && scripting_fspec.Exists()) 159791c0e749SGreg Clayton { 1598d93c4a33SBruce Mitchener if (should_load == eLoadScriptFromSymFileWarn) 15992ea43cdcSEnrico Granata { 1600397ddd5fSEnrico Granata if (feedback_stream) 1601d516deb4SJim Ingham feedback_stream->Printf("warning: '%s' contains a debug script. To run this script in " 1602d516deb4SJim Ingham "this debug session:\n\n command script import \"%s\"\n\n" 1603d516deb4SJim Ingham "To run all discovered debug scripts in this session:\n\n" 1604d516deb4SJim Ingham " settings set target.load-script-from-symbol-file true\n", 1605d516deb4SJim Ingham GetFileSpec().GetFileNameStrippingExtension().GetCString(), 1606d516deb4SJim Ingham scripting_fspec.GetPath().c_str()); 16072ea43cdcSEnrico Granata return false; 16082ea43cdcSEnrico Granata } 16091759848bSEnrico Granata StreamString scripting_stream; 16101759848bSEnrico Granata scripting_fspec.Dump(&scripting_stream); 1611e0c70f1bSEnrico Granata const bool can_reload = true; 16126a51085eSJim Ingham const bool init_lldb_globals = false; 1613d516deb4SJim Ingham bool did_load = script_interpreter->LoadScriptingModule(scripting_stream.GetData(), 1614d516deb4SJim Ingham can_reload, 1615d516deb4SJim Ingham init_lldb_globals, 1616d516deb4SJim Ingham error); 16171759848bSEnrico Granata if (!did_load) 16181759848bSEnrico Granata return false; 16191759848bSEnrico Granata } 162091c0e749SGreg Clayton } 162191c0e749SGreg Clayton } 16221759848bSEnrico Granata else 16231759848bSEnrico Granata { 16241759848bSEnrico Granata error.SetErrorString("invalid ScriptInterpreter"); 16251759848bSEnrico Granata return false; 16261759848bSEnrico Granata } 16271759848bSEnrico Granata } 1628b9d8890bSGreg Clayton } 16291759848bSEnrico Granata return true; 16301759848bSEnrico Granata } 16311759848bSEnrico Granata 1632b53cb271SJim Ingham bool 16335aee162fSJim Ingham Module::SetArchitecture (const ArchSpec &new_arch) 16345aee162fSJim Ingham { 163564195a2cSGreg Clayton if (!m_arch.IsValid()) 16365aee162fSJim Ingham { 16375aee162fSJim Ingham m_arch = new_arch; 16385aee162fSJim Ingham return true; 16395aee162fSJim Ingham } 1640b6cd5fe9SChaoren Lin return m_arch.IsCompatibleMatch(new_arch); 16415aee162fSJim Ingham } 16425aee162fSJim Ingham 1643c9660546SGreg Clayton bool 1644751caf65SGreg Clayton Module::SetLoadAddress (Target &target, lldb::addr_t value, bool value_is_offset, bool &changed) 1645c9660546SGreg Clayton { 16469e02dacdSSteve Pucci ObjectFile *object_file = GetObjectFile(); 1647c5dac77aSEugene Zelenko if (object_file != nullptr) 1648c9660546SGreg Clayton { 1649751caf65SGreg Clayton changed = object_file->SetLoadAddress(target, value, value_is_offset); 16507524e090SGreg Clayton return true; 16517524e090SGreg Clayton } 16527524e090SGreg Clayton else 16537524e090SGreg Clayton { 16547524e090SGreg Clayton changed = false; 1655c9660546SGreg Clayton } 16569e02dacdSSteve Pucci return false; 1657c9660546SGreg Clayton } 1658c9660546SGreg Clayton 1659b9a01b39SGreg Clayton 1660b9a01b39SGreg Clayton bool 1661b9a01b39SGreg Clayton Module::MatchesModuleSpec (const ModuleSpec &module_ref) 1662b9a01b39SGreg Clayton { 1663b9a01b39SGreg Clayton const UUID &uuid = module_ref.GetUUID(); 1664b9a01b39SGreg Clayton 1665b9a01b39SGreg Clayton if (uuid.IsValid()) 1666b9a01b39SGreg Clayton { 1667b9a01b39SGreg Clayton // If the UUID matches, then nothing more needs to match... 1668c5dac77aSEugene Zelenko return (uuid == GetUUID()); 1669b9a01b39SGreg Clayton } 1670b9a01b39SGreg Clayton 1671b9a01b39SGreg Clayton const FileSpec &file_spec = module_ref.GetFileSpec(); 1672b9a01b39SGreg Clayton if (file_spec) 1673b9a01b39SGreg Clayton { 1674980662eeSTamas Berghammer if (!FileSpec::Equal (file_spec, m_file, (bool)file_spec.GetDirectory()) && 1675980662eeSTamas Berghammer !FileSpec::Equal (file_spec, m_platform_file, (bool)file_spec.GetDirectory())) 1676b9a01b39SGreg Clayton return false; 1677b9a01b39SGreg Clayton } 1678b9a01b39SGreg Clayton 1679b9a01b39SGreg Clayton const FileSpec &platform_file_spec = module_ref.GetPlatformFileSpec(); 1680b9a01b39SGreg Clayton if (platform_file_spec) 1681b9a01b39SGreg Clayton { 1682ddd7a2a6SSean Callanan if (!FileSpec::Equal (platform_file_spec, GetPlatformFileSpec (), (bool)platform_file_spec.GetDirectory())) 1683b9a01b39SGreg Clayton return false; 1684b9a01b39SGreg Clayton } 1685b9a01b39SGreg Clayton 1686b9a01b39SGreg Clayton const ArchSpec &arch = module_ref.GetArchitecture(); 1687b9a01b39SGreg Clayton if (arch.IsValid()) 1688b9a01b39SGreg Clayton { 1689bf4b7be6SSean Callanan if (!m_arch.IsCompatibleMatch(arch)) 1690b9a01b39SGreg Clayton return false; 1691b9a01b39SGreg Clayton } 1692b9a01b39SGreg Clayton 1693b9a01b39SGreg Clayton const ConstString &object_name = module_ref.GetObjectName(); 1694b9a01b39SGreg Clayton if (object_name) 1695b9a01b39SGreg Clayton { 1696b9a01b39SGreg Clayton if (object_name != GetObjectName()) 1697b9a01b39SGreg Clayton return false; 1698b9a01b39SGreg Clayton } 1699b9a01b39SGreg Clayton return true; 1700b9a01b39SGreg Clayton } 1701b9a01b39SGreg Clayton 1702d804d285SGreg Clayton bool 1703d804d285SGreg Clayton Module::FindSourceFile (const FileSpec &orig_spec, FileSpec &new_spec) const 1704d804d285SGreg Clayton { 170516ff8604SSaleem Abdulrasool std::lock_guard<std::recursive_mutex> guard(m_mutex); 1706d804d285SGreg Clayton return m_source_mappings.FindFile (orig_spec, new_spec); 1707d804d285SGreg Clayton } 1708d804d285SGreg Clayton 1709f9be6933SGreg Clayton bool 1710f9be6933SGreg Clayton Module::RemapSourceFile (const char *path, std::string &new_path) const 1711f9be6933SGreg Clayton { 171216ff8604SSaleem Abdulrasool std::lock_guard<std::recursive_mutex> guard(m_mutex); 1713f9be6933SGreg Clayton return m_source_mappings.RemapPath(path, new_path); 1714f9be6933SGreg Clayton } 1715f9be6933SGreg Clayton 17163467d80bSEnrico Granata uint32_t 17173467d80bSEnrico Granata Module::GetVersion (uint32_t *versions, uint32_t num_versions) 17183467d80bSEnrico Granata { 17193467d80bSEnrico Granata ObjectFile *obj_file = GetObjectFile(); 17203467d80bSEnrico Granata if (obj_file) 17213467d80bSEnrico Granata return obj_file->GetVersion (versions, num_versions); 17223467d80bSEnrico Granata 1723c5dac77aSEugene Zelenko if (versions != nullptr && num_versions != 0) 17243467d80bSEnrico Granata { 17253467d80bSEnrico Granata for (uint32_t i = 0; i < num_versions; ++i) 1726afcbdb15SEnrico Granata versions[i] = LLDB_INVALID_MODULE_VERSION; 17273467d80bSEnrico Granata } 17283467d80bSEnrico Granata return 0; 17293467d80bSEnrico Granata } 173043fe217bSGreg Clayton 173143fe217bSGreg Clayton void 173243fe217bSGreg Clayton Module::PrepareForFunctionNameLookup (const ConstString &name, 173343fe217bSGreg Clayton uint32_t name_type_mask, 173423b1decbSDawn Perchik LanguageType language, 173543fe217bSGreg Clayton ConstString &lookup_name, 173643fe217bSGreg Clayton uint32_t &lookup_name_type_mask, 173743fe217bSGreg Clayton bool &match_name_after_lookup) 173843fe217bSGreg Clayton { 173943fe217bSGreg Clayton const char *name_cstr = name.GetCString(); 174043fe217bSGreg Clayton lookup_name_type_mask = eFunctionNameTypeNone; 174143fe217bSGreg Clayton match_name_after_lookup = false; 1742fa39bb4aSJim Ingham 1743fa39bb4aSJim Ingham llvm::StringRef basename; 1744fa39bb4aSJim Ingham llvm::StringRef context; 174543fe217bSGreg Clayton 174643fe217bSGreg Clayton if (name_type_mask & eFunctionNameTypeAuto) 174743fe217bSGreg Clayton { 1748aa816b8fSJim Ingham if (CPlusPlusLanguage::IsCPPMangledName (name_cstr)) 174943fe217bSGreg Clayton lookup_name_type_mask = eFunctionNameTypeFull; 175023b1decbSDawn Perchik else if ((language == eLanguageTypeUnknown || 17510e0984eeSJim Ingham Language::LanguageIsObjC(language)) && 1752aa816b8fSJim Ingham ObjCLanguage::IsPossibleObjCMethodName (name_cstr)) 175343fe217bSGreg Clayton lookup_name_type_mask = eFunctionNameTypeFull; 17540e0984eeSJim Ingham else if (Language::LanguageIsC(language)) 175523b1decbSDawn Perchik { 175623b1decbSDawn Perchik lookup_name_type_mask = eFunctionNameTypeFull; 175723b1decbSDawn Perchik } 175843fe217bSGreg Clayton else 175943fe217bSGreg Clayton { 176023b1decbSDawn Perchik if ((language == eLanguageTypeUnknown || 17610e0984eeSJim Ingham Language::LanguageIsObjC(language)) && 1762aa816b8fSJim Ingham ObjCLanguage::IsPossibleObjCSelector(name_cstr)) 176343fe217bSGreg Clayton lookup_name_type_mask |= eFunctionNameTypeSelector; 176443fe217bSGreg Clayton 1765aa816b8fSJim Ingham CPlusPlusLanguage::MethodName cpp_method (name); 1766fa39bb4aSJim Ingham basename = cpp_method.GetBasename(); 17676ecb232bSGreg Clayton if (basename.empty()) 17686ecb232bSGreg Clayton { 1769aa816b8fSJim Ingham if (CPlusPlusLanguage::ExtractContextAndIdentifier (name_cstr, context, basename)) 177043fe217bSGreg Clayton lookup_name_type_mask |= (eFunctionNameTypeMethod | eFunctionNameTypeBase); 1771c3795409SGreg Clayton else 177265b0e763SGreg Clayton lookup_name_type_mask |= eFunctionNameTypeFull; 177343fe217bSGreg Clayton } 17746ecb232bSGreg Clayton else 17756ecb232bSGreg Clayton { 17766ecb232bSGreg Clayton lookup_name_type_mask |= (eFunctionNameTypeMethod | eFunctionNameTypeBase); 17776ecb232bSGreg Clayton } 17786ecb232bSGreg Clayton } 177943fe217bSGreg Clayton } 178043fe217bSGreg Clayton else 178143fe217bSGreg Clayton { 178243fe217bSGreg Clayton lookup_name_type_mask = name_type_mask; 178343fe217bSGreg Clayton if (lookup_name_type_mask & eFunctionNameTypeMethod || name_type_mask & eFunctionNameTypeBase) 178443fe217bSGreg Clayton { 178543fe217bSGreg Clayton // If they've asked for a CPP method or function name and it can't be that, we don't 178643fe217bSGreg Clayton // even need to search for CPP methods or names. 1787aa816b8fSJim Ingham CPlusPlusLanguage::MethodName cpp_method (name); 17886ecb232bSGreg Clayton if (cpp_method.IsValid()) 17896ecb232bSGreg Clayton { 1790fa39bb4aSJim Ingham basename = cpp_method.GetBasename(); 17916ecb232bSGreg Clayton 17926ecb232bSGreg Clayton if (!cpp_method.GetQualifiers().empty()) 17936ecb232bSGreg Clayton { 1794d93c4a33SBruce Mitchener // There is a "const" or other qualifier following the end of the function parens, 17956ecb232bSGreg Clayton // this can't be a eFunctionNameTypeBase 17966ecb232bSGreg Clayton lookup_name_type_mask &= ~(eFunctionNameTypeBase); 17976ecb232bSGreg Clayton if (lookup_name_type_mask == eFunctionNameTypeNone) 17986ecb232bSGreg Clayton return; 17996ecb232bSGreg Clayton } 18006ecb232bSGreg Clayton } 18016ecb232bSGreg Clayton else 18026ecb232bSGreg Clayton { 1803fa39bb4aSJim Ingham // If the CPP method parser didn't manage to chop this up, try to fill in the base name if we can. 1804fa39bb4aSJim Ingham // If a::b::c is passed in, we need to just look up "c", and then we'll filter the result later. 1805aa816b8fSJim Ingham CPlusPlusLanguage::ExtractContextAndIdentifier (name_cstr, context, basename); 180643fe217bSGreg Clayton } 18076ecb232bSGreg Clayton } 180843fe217bSGreg Clayton 180943fe217bSGreg Clayton if (lookup_name_type_mask & eFunctionNameTypeSelector) 181043fe217bSGreg Clayton { 1811aa816b8fSJim Ingham if (!ObjCLanguage::IsPossibleObjCSelector(name_cstr)) 181243fe217bSGreg Clayton { 181343fe217bSGreg Clayton lookup_name_type_mask &= ~(eFunctionNameTypeSelector); 181443fe217bSGreg Clayton if (lookup_name_type_mask == eFunctionNameTypeNone) 181543fe217bSGreg Clayton return; 181643fe217bSGreg Clayton } 181743fe217bSGreg Clayton } 181843fe217bSGreg Clayton } 181943fe217bSGreg Clayton 1820fa39bb4aSJim Ingham if (!basename.empty()) 182143fe217bSGreg Clayton { 182243fe217bSGreg Clayton // The name supplied was a partial C++ path like "a::count". In this case we want to do a 182343fe217bSGreg Clayton // lookup on the basename "count" and then make sure any matching results contain "a::count" 182443fe217bSGreg Clayton // so that it would match "b::a::count" and "a::count". This is why we set "match_name_after_lookup" 182543fe217bSGreg Clayton // to true 1826fa39bb4aSJim Ingham lookup_name.SetString(basename); 182743fe217bSGreg Clayton match_name_after_lookup = true; 182843fe217bSGreg Clayton } 182943fe217bSGreg Clayton else 183043fe217bSGreg Clayton { 183143fe217bSGreg Clayton // The name is already correct, just use the exact name as supplied, and we won't need 183243fe217bSGreg Clayton // to check if any matches contain "name" 183343fe217bSGreg Clayton lookup_name = name; 183443fe217bSGreg Clayton match_name_after_lookup = false; 183543fe217bSGreg Clayton } 183643fe217bSGreg Clayton } 183723f8c95aSGreg Clayton 183823f8c95aSGreg Clayton ModuleSP 183923f8c95aSGreg Clayton Module::CreateJITModule (const lldb::ObjectFileJITDelegateSP &delegate_sp) 184023f8c95aSGreg Clayton { 184123f8c95aSGreg Clayton if (delegate_sp) 184223f8c95aSGreg Clayton { 184323f8c95aSGreg Clayton // Must create a module and place it into a shared pointer before 184423f8c95aSGreg Clayton // we can create an object file since it has a std::weak_ptr back 184523f8c95aSGreg Clayton // to the module, so we need to control the creation carefully in 184623f8c95aSGreg Clayton // this static function 184723f8c95aSGreg Clayton ModuleSP module_sp(new Module()); 184823f8c95aSGreg Clayton module_sp->m_objfile_sp.reset (new ObjectFileJIT (module_sp, delegate_sp)); 184923f8c95aSGreg Clayton if (module_sp->m_objfile_sp) 185023f8c95aSGreg Clayton { 185123f8c95aSGreg Clayton // Once we get the object file, update our module with the object file's 185223f8c95aSGreg Clayton // architecture since it might differ in vendor/os if some parts were 185323f8c95aSGreg Clayton // unknown. 185423f8c95aSGreg Clayton module_sp->m_objfile_sp->GetArchitecture (module_sp->m_arch); 185523f8c95aSGreg Clayton } 185623f8c95aSGreg Clayton return module_sp; 185723f8c95aSGreg Clayton } 185823f8c95aSGreg Clayton return ModuleSP(); 185923f8c95aSGreg Clayton } 186023f8c95aSGreg Clayton 186108928f30SGreg Clayton bool 186208928f30SGreg Clayton Module::GetIsDynamicLinkEditor() 186308928f30SGreg Clayton { 186408928f30SGreg Clayton ObjectFile * obj_file = GetObjectFile (); 186508928f30SGreg Clayton 186608928f30SGreg Clayton if (obj_file) 186708928f30SGreg Clayton return obj_file->GetIsDynamicLinkEditor(); 186808928f30SGreg Clayton 186908928f30SGreg Clayton return false; 187008928f30SGreg Clayton } 1871