1 //===-- Module.cpp ----------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/Core/AddressResolverFileLine.h"
11 #include "lldb/Core/Error.h"
12 #include "lldb/Core/Module.h"
13 #include "lldb/Core/DataBuffer.h"
14 #include "lldb/Core/DataBufferHeap.h"
15 #include "lldb/Core/Log.h"
16 #include "lldb/Core/ModuleList.h"
17 #include "lldb/Core/ModuleSpec.h"
18 #include "lldb/Core/RegularExpression.h"
19 #include "lldb/Core/Section.h"
20 #include "lldb/Core/StreamString.h"
21 #include "lldb/Core/Timer.h"
22 #include "lldb/Host/Host.h"
23 #include "lldb/Host/Symbols.h"
24 #include "lldb/Interpreter/CommandInterpreter.h"
25 #include "lldb/Interpreter/ScriptInterpreter.h"
26 #include "lldb/Symbol/ClangASTContext.h"
27 #include "lldb/Symbol/CompileUnit.h"
28 #include "lldb/Symbol/ObjectFile.h"
29 #include "lldb/Symbol/SymbolContext.h"
30 #include "lldb/Symbol/SymbolVendor.h"
31 #include "lldb/Target/CPPLanguageRuntime.h"
32 #include "lldb/Target/ObjCLanguageRuntime.h"
33 #include "lldb/Target/Process.h"
34 #include "lldb/Target/SectionLoadList.h"
35 #include "lldb/Target/Target.h"
36 #include "lldb/Symbol/SymbolFile.h"
38 #include "Plugins/ObjectFile/JIT/ObjectFileJIT.h"
40 #include "llvm/Support/raw_os_ostream.h"
41 #include "llvm/Support/Signals.h"
44 using namespace lldb_private;
46 // Shared pointers to modules track module lifetimes in
47 // targets and in the global module, but this collection
48 // will track all module objects that are still alive
49 typedef std::vector<Module *> ModuleCollection;
51 static ModuleCollection &
54 // This module collection needs to live past any module, so we could either make it a
55 // shared pointer in each module or just leak is. Since it is only an empty vector by
56 // the time all the modules have gone away, we just leak it for now. If we decide this
57 // is a big problem we can introduce a Finalize method that will tear everything down in
58 // a predictable order.
60 static ModuleCollection *g_module_collection = NULL;
61 if (g_module_collection == NULL)
62 g_module_collection = new ModuleCollection();
64 return *g_module_collection;
68 Module::GetAllocationModuleCollectionMutex()
70 // NOTE: The mutex below must be leaked since the global module list in
71 // the ModuleList class will get torn at some point, and we can't know
72 // if it will tear itself down before the "g_module_collection_mutex" below
73 // will. So we leak a Mutex object below to safeguard against that
75 static Mutex *g_module_collection_mutex = NULL;
76 if (g_module_collection_mutex == NULL)
77 g_module_collection_mutex = new Mutex (Mutex::eMutexTypeRecursive); // NOTE: known leak
78 return g_module_collection_mutex;
82 Module::GetNumberAllocatedModules ()
84 Mutex::Locker locker (GetAllocationModuleCollectionMutex());
85 return GetModuleCollection().size();
89 Module::GetAllocatedModuleAtIndex (size_t idx)
91 Mutex::Locker locker (GetAllocationModuleCollectionMutex());
92 ModuleCollection &modules = GetModuleCollection();
93 if (idx < modules.size())
99 // These functions help us to determine if modules are still loaded, yet don't require that
100 // you have a command interpreter and can easily be called from an external debugger.
104 ClearModuleInfo (void)
106 const bool mandatory = true;
107 ModuleList::RemoveOrphanSharedModules(mandatory);
111 DumpModuleInfo (void)
113 Mutex::Locker locker (Module::GetAllocationModuleCollectionMutex());
114 ModuleCollection &modules = GetModuleCollection();
115 const size_t count = modules.size();
116 printf ("%s: %" PRIu64 " modules:\n", __PRETTY_FUNCTION__, (uint64_t)count);
117 for (size_t i=0; i<count; ++i)
121 Module *module = modules[i];
122 const bool in_shared_module_list = ModuleList::ModuleIsInCache (module);
123 module->GetDescription(&strm, eDescriptionLevelFull);
124 printf ("%p: shared = %i, ref_count = %3u, module = %s\n",
126 in_shared_module_list,
127 (uint32_t)module->use_count(),
128 strm.GetString().c_str());
135 Module::Module (const ModuleSpec &module_spec) :
136 m_mutex (Mutex::eMutexTypeRecursive),
142 m_remote_install_file(),
146 m_object_mod_time (),
149 m_ast (new ClangASTContext),
150 m_source_mappings (),
152 m_did_load_objfile (false),
153 m_did_load_symbol_vendor (false),
154 m_did_parse_uuid (false),
155 m_did_init_ast (false),
156 m_file_has_changed (false),
157 m_first_file_changed_log (false)
159 // Scope for locker below...
161 Mutex::Locker locker (GetAllocationModuleCollectionMutex());
162 GetModuleCollection().push_back(this);
165 Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_OBJECT|LIBLLDB_LOG_MODULES));
167 log->Printf ("%p Module::Module((%s) '%s%s%s%s')",
168 static_cast<void*>(this),
169 module_spec.GetArchitecture().GetArchitectureName(),
170 module_spec.GetFileSpec().GetPath().c_str(),
171 module_spec.GetObjectName().IsEmpty() ? "" : "(",
172 module_spec.GetObjectName().IsEmpty() ? "" : module_spec.GetObjectName().AsCString(""),
173 module_spec.GetObjectName().IsEmpty() ? "" : ")");
175 // First extract all module specifications from the file using the local
176 // file path. If there are no specifications, then don't fill anything in
177 ModuleSpecList modules_specs;
178 if (ObjectFile::GetModuleSpecifications(module_spec.GetFileSpec(), 0, 0, modules_specs) == 0)
181 // Now make sure that one of the module specifications matches what we just
182 // extract. We might have a module specification that specifies a file "/usr/lib/dyld"
183 // with UUID XXX, but we might have a local version of "/usr/lib/dyld" that has
184 // UUID YYY and we don't want those to match. If they don't match, just don't
185 // fill any ivars in so we don't accidentally grab the wrong file later since
186 // they don't match...
187 ModuleSpec matching_module_spec;
188 if (modules_specs.FindMatchingModuleSpec(module_spec, matching_module_spec) == 0)
191 if (module_spec.GetFileSpec())
192 m_mod_time = module_spec.GetFileSpec().GetModificationTime();
193 else if (matching_module_spec.GetFileSpec())
194 m_mod_time = matching_module_spec.GetFileSpec().GetModificationTime();
196 // Copy the architecture from the actual spec if we got one back, else use the one that was specified
197 if (matching_module_spec.GetArchitecture().IsValid())
198 m_arch = matching_module_spec.GetArchitecture();
199 else if (module_spec.GetArchitecture().IsValid())
200 m_arch = module_spec.GetArchitecture();
202 // Copy the file spec over and use the specified one (if there was one) so we
203 // don't use a path that might have gotten resolved a path in 'matching_module_spec'
204 if (module_spec.GetFileSpec())
205 m_file = module_spec.GetFileSpec();
206 else if (matching_module_spec.GetFileSpec())
207 m_file = matching_module_spec.GetFileSpec();
209 // Copy the platform file spec over
210 if (module_spec.GetPlatformFileSpec())
211 m_platform_file = module_spec.GetPlatformFileSpec();
212 else if (matching_module_spec.GetPlatformFileSpec())
213 m_platform_file = matching_module_spec.GetPlatformFileSpec();
215 // Copy the symbol file spec over
216 if (module_spec.GetSymbolFileSpec())
217 m_symfile_spec = module_spec.GetSymbolFileSpec();
218 else if (matching_module_spec.GetSymbolFileSpec())
219 m_symfile_spec = matching_module_spec.GetSymbolFileSpec();
221 // Copy the object name over
222 if (matching_module_spec.GetObjectName())
223 m_object_name = matching_module_spec.GetObjectName();
225 m_object_name = module_spec.GetObjectName();
227 // Always trust the object offset (file offset) and object modification
228 // time (for mod time in a BSD static archive) of from the matching
229 // module specification
230 m_object_offset = matching_module_spec.GetObjectOffset();
231 m_object_mod_time = matching_module_spec.GetObjectModificationTime();
235 Module::Module(const FileSpec& file_spec,
236 const ArchSpec& arch,
237 const ConstString *object_name,
238 lldb::offset_t object_offset,
239 const TimeValue *object_mod_time_ptr) :
240 m_mutex (Mutex::eMutexTypeRecursive),
241 m_mod_time (file_spec.GetModificationTime()),
246 m_remote_install_file (),
249 m_object_offset (object_offset),
250 m_object_mod_time (),
253 m_ast (new ClangASTContext),
254 m_source_mappings (),
256 m_did_load_objfile (false),
257 m_did_load_symbol_vendor (false),
258 m_did_parse_uuid (false),
259 m_did_init_ast (false),
260 m_file_has_changed (false),
261 m_first_file_changed_log (false)
263 // Scope for locker below...
265 Mutex::Locker locker (GetAllocationModuleCollectionMutex());
266 GetModuleCollection().push_back(this);
270 m_object_name = *object_name;
272 if (object_mod_time_ptr)
273 m_object_mod_time = *object_mod_time_ptr;
275 Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_OBJECT|LIBLLDB_LOG_MODULES));
277 log->Printf ("%p Module::Module((%s) '%s%s%s%s')",
278 static_cast<void*>(this), m_arch.GetArchitectureName(),
279 m_file.GetPath().c_str(),
280 m_object_name.IsEmpty() ? "" : "(",
281 m_object_name.IsEmpty() ? "" : m_object_name.AsCString(""),
282 m_object_name.IsEmpty() ? "" : ")");
286 m_mutex (Mutex::eMutexTypeRecursive),
292 m_remote_install_file (),
296 m_object_mod_time (),
299 m_ast (new ClangASTContext),
300 m_source_mappings (),
302 m_did_load_objfile (false),
303 m_did_load_symbol_vendor (false),
304 m_did_parse_uuid (false),
305 m_did_init_ast (false),
306 m_file_has_changed (false),
307 m_first_file_changed_log (false)
309 Mutex::Locker locker (GetAllocationModuleCollectionMutex());
310 GetModuleCollection().push_back(this);
315 // Lock our module down while we tear everything down to make sure
316 // we don't get any access to the module while it is being destroyed
317 Mutex::Locker locker (m_mutex);
318 // Scope for locker below...
320 Mutex::Locker locker (GetAllocationModuleCollectionMutex());
321 ModuleCollection &modules = GetModuleCollection();
322 ModuleCollection::iterator end = modules.end();
323 ModuleCollection::iterator pos = std::find(modules.begin(), end, this);
327 Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_OBJECT|LIBLLDB_LOG_MODULES));
329 log->Printf ("%p Module::~Module((%s) '%s%s%s%s')",
330 static_cast<void*>(this),
331 m_arch.GetArchitectureName(),
332 m_file.GetPath().c_str(),
333 m_object_name.IsEmpty() ? "" : "(",
334 m_object_name.IsEmpty() ? "" : m_object_name.AsCString(""),
335 m_object_name.IsEmpty() ? "" : ")");
336 // Release any auto pointers before we start tearing down our member
337 // variables since the object file and symbol files might need to make
338 // function calls back into this module object. The ordering is important
339 // here because symbol files can require the module object file. So we tear
340 // down the symbol file first, then the object file.
341 m_sections_ap.reset();
342 m_symfile_ap.reset();
343 m_objfile_sp.reset();
347 Module::GetMemoryObjectFile (const lldb::ProcessSP &process_sp, lldb::addr_t header_addr, Error &error, size_t size_to_read)
351 error.SetErrorString ("object file already exists");
355 Mutex::Locker locker (m_mutex);
358 m_did_load_objfile = true;
359 std::unique_ptr<DataBufferHeap> data_ap (new DataBufferHeap (size_to_read, 0));
361 const size_t bytes_read = process_sp->ReadMemory (header_addr,
363 data_ap->GetByteSize(),
365 if (bytes_read == size_to_read)
367 DataBufferSP data_sp(data_ap.release());
368 m_objfile_sp = ObjectFile::FindPlugin(shared_from_this(), process_sp, header_addr, data_sp);
372 s.Printf("0x%16.16" PRIx64, header_addr);
373 m_object_name.SetCString (s.GetData());
375 // Once we get the object file, update our module with the object file's
376 // architecture since it might differ in vendor/os if some parts were
378 m_objfile_sp->GetArchitecture (m_arch);
382 error.SetErrorString ("unable to find suitable object file plug-in");
387 error.SetErrorStringWithFormat ("unable to read header from memory: %s", readmem_error.AsCString());
392 error.SetErrorString ("invalid process");
395 return m_objfile_sp.get();
399 const lldb_private::UUID&
402 Mutex::Locker locker (m_mutex);
403 if (m_did_parse_uuid == false)
405 ObjectFile * obj_file = GetObjectFile ();
407 if (obj_file != NULL)
409 obj_file->GetUUID(&m_uuid);
410 m_did_parse_uuid = true;
417 Module::GetClangASTContext ()
419 Mutex::Locker locker (m_mutex);
420 if (m_did_init_ast == false)
422 ObjectFile * objfile = GetObjectFile();
423 ArchSpec object_arch;
424 if (objfile && objfile->GetArchitecture(object_arch))
426 m_did_init_ast = true;
428 // LLVM wants this to be set to iOS or MacOSX; if we're working on
429 // a bare-boards type image, change the triple for llvm's benefit.
430 if (object_arch.GetTriple().getVendor() == llvm::Triple::Apple
431 && object_arch.GetTriple().getOS() == llvm::Triple::UnknownOS)
433 if (object_arch.GetTriple().getArch() == llvm::Triple::arm ||
434 object_arch.GetTriple().getArch() == llvm::Triple::aarch64 ||
435 object_arch.GetTriple().getArch() == llvm::Triple::thumb)
437 object_arch.GetTriple().setOS(llvm::Triple::IOS);
441 object_arch.GetTriple().setOS(llvm::Triple::MacOSX);
444 m_ast->SetArchitecture (object_arch);
451 Module::ParseAllDebugSymbols()
453 Mutex::Locker locker (m_mutex);
454 size_t num_comp_units = GetNumCompileUnits();
455 if (num_comp_units == 0)
459 sc.module_sp = shared_from_this();
460 SymbolVendor *symbols = GetSymbolVendor ();
462 for (size_t cu_idx = 0; cu_idx < num_comp_units; cu_idx++)
464 sc.comp_unit = symbols->GetCompileUnitAtIndex(cu_idx).get();
468 symbols->ParseVariablesForContext(sc);
470 symbols->ParseCompileUnitFunctions(sc);
472 for (size_t func_idx = 0; (sc.function = sc.comp_unit->GetFunctionAtIndex(func_idx).get()) != NULL; ++func_idx)
474 symbols->ParseFunctionBlocks(sc);
476 // Parse the variables for this function and all its blocks
477 symbols->ParseVariablesForContext(sc);
481 // Parse all types for this compile unit
483 symbols->ParseTypes(sc);
489 Module::CalculateSymbolContext(SymbolContext* sc)
491 sc->module_sp = shared_from_this();
495 Module::CalculateSymbolContextModule ()
497 return shared_from_this();
501 Module::DumpSymbolContext(Stream *s)
503 s->Printf(", Module{%p}", static_cast<void*>(this));
507 Module::GetNumCompileUnits()
509 Mutex::Locker locker (m_mutex);
510 Timer scoped_timer(__PRETTY_FUNCTION__,
511 "Module::GetNumCompileUnits (module = %p)",
512 static_cast<void*>(this));
513 SymbolVendor *symbols = GetSymbolVendor ();
515 return symbols->GetNumCompileUnits();
520 Module::GetCompileUnitAtIndex (size_t index)
522 Mutex::Locker locker (m_mutex);
523 size_t num_comp_units = GetNumCompileUnits ();
526 if (index < num_comp_units)
528 SymbolVendor *symbols = GetSymbolVendor ();
530 cu_sp = symbols->GetCompileUnitAtIndex(index);
536 Module::ResolveFileAddress (lldb::addr_t vm_addr, Address& so_addr)
538 Mutex::Locker locker (m_mutex);
539 Timer scoped_timer(__PRETTY_FUNCTION__, "Module::ResolveFileAddress (vm_addr = 0x%" PRIx64 ")", vm_addr);
540 SectionList *section_list = GetSectionList();
542 return so_addr.ResolveAddressUsingFileSections(vm_addr, section_list);
547 Module::ResolveSymbolContextForAddress (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc,
548 bool resolve_tail_call_address)
550 Mutex::Locker locker (m_mutex);
551 uint32_t resolved_flags = 0;
553 // Clear the result symbol context in case we don't find anything, but don't clear the target
556 // Get the section from the section/offset address.
557 SectionSP section_sp (so_addr.GetSection());
559 // Make sure the section matches this module before we try and match anything
560 if (section_sp && section_sp->GetModule().get() == this)
562 // If the section offset based address resolved itself, then this
563 // is the right module.
564 sc.module_sp = shared_from_this();
565 resolved_flags |= eSymbolContextModule;
567 SymbolVendor* sym_vendor = GetSymbolVendor();
569 return resolved_flags;
571 // Resolve the compile unit, function, block, line table or line
572 // entry if requested.
573 if (resolve_scope & eSymbolContextCompUnit ||
574 resolve_scope & eSymbolContextFunction ||
575 resolve_scope & eSymbolContextBlock ||
576 resolve_scope & eSymbolContextLineEntry )
578 resolved_flags |= sym_vendor->ResolveSymbolContext (so_addr, resolve_scope, sc);
581 // Resolve the symbol if requested, but don't re-look it up if we've already found it.
582 if (resolve_scope & eSymbolContextSymbol && !(resolved_flags & eSymbolContextSymbol))
584 Symtab *symtab = sym_vendor->GetSymtab();
585 if (symtab && so_addr.IsSectionOffset())
587 sc.symbol = symtab->FindSymbolContainingFileAddress(so_addr.GetFileAddress());
589 resolve_scope & eSymbolContextFunction && !(resolved_flags & eSymbolContextFunction))
591 bool verify_unique = false; // No need to check again since ResolveSymbolContext failed to find a symbol at this address.
592 if (ObjectFile *obj_file = sc.module_sp->GetObjectFile())
593 sc.symbol = obj_file->ResolveSymbolForAddress(so_addr, verify_unique);
598 if (sc.symbol->IsSynthetic())
600 // We have a synthetic symbol so lets check if the object file
601 // from the symbol file in the symbol vendor is different than
602 // the object file for the module, and if so search its symbol
603 // table to see if we can come up with a better symbol. For example
604 // dSYM files on MacOSX have an unstripped symbol table inside of
606 ObjectFile *symtab_objfile = symtab->GetObjectFile();
607 if (symtab_objfile && symtab_objfile->IsStripped())
609 SymbolFile *symfile = sym_vendor->GetSymbolFile();
612 ObjectFile *symfile_objfile = symfile->GetObjectFile();
613 if (symfile_objfile != symtab_objfile)
615 Symtab *symfile_symtab = symfile_objfile->GetSymtab();
618 Symbol *symbol = symfile_symtab->FindSymbolContainingFileAddress(so_addr.GetFileAddress());
619 if (symbol && !symbol->IsSynthetic())
628 resolved_flags |= eSymbolContextSymbol;
633 // For function symbols, so_addr may be off by one. This is a convention consistent
634 // with FDE row indices in eh_frame sections, but requires extra logic here to permit
635 // symbol lookup for disassembly and unwind.
636 if (resolve_scope & eSymbolContextSymbol && !(resolved_flags & eSymbolContextSymbol) &&
637 resolve_tail_call_address && so_addr.IsSectionOffset())
639 Address previous_addr = so_addr;
640 previous_addr.Slide(-1);
642 bool do_resolve_tail_call_address = false; // prevent recursion
643 const uint32_t flags = ResolveSymbolContextForAddress(previous_addr, resolve_scope, sc,
644 do_resolve_tail_call_address);
645 if (flags & eSymbolContextSymbol)
647 AddressRange addr_range;
648 if (sc.GetAddressRange (eSymbolContextFunction | eSymbolContextSymbol, 0, false, addr_range))
650 if (addr_range.GetBaseAddress().GetSection() == so_addr.GetSection())
652 // If the requested address is one past the address range of a function (i.e. a tail call),
653 // or the decremented address is the start of a function (i.e. some forms of trampoline),
654 // indicate that the symbol has been resolved.
655 if (so_addr.GetOffset() == addr_range.GetBaseAddress().GetOffset() ||
656 so_addr.GetOffset() == addr_range.GetBaseAddress().GetOffset() + addr_range.GetByteSize())
658 resolved_flags |= flags;
663 sc.symbol = nullptr; // Don't trust the symbol if the sections didn't match.
669 return resolved_flags;
673 Module::ResolveSymbolContextForFilePath
675 const char *file_path,
678 uint32_t resolve_scope,
679 SymbolContextList& sc_list
682 FileSpec file_spec(file_path, false);
683 return ResolveSymbolContextsForFileSpec (file_spec, line, check_inlines, resolve_scope, sc_list);
687 Module::ResolveSymbolContextsForFileSpec (const FileSpec &file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list)
689 Mutex::Locker locker (m_mutex);
690 Timer scoped_timer(__PRETTY_FUNCTION__,
691 "Module::ResolveSymbolContextForFilePath (%s:%u, check_inlines = %s, resolve_scope = 0x%8.8x)",
692 file_spec.GetPath().c_str(),
694 check_inlines ? "yes" : "no",
697 const uint32_t initial_count = sc_list.GetSize();
699 SymbolVendor *symbols = GetSymbolVendor ();
701 symbols->ResolveSymbolContext (file_spec, line, check_inlines, resolve_scope, sc_list);
703 return sc_list.GetSize() - initial_count;
708 Module::FindGlobalVariables (const ConstString &name,
709 const ClangNamespaceDecl *namespace_decl,
712 VariableList& variables)
714 SymbolVendor *symbols = GetSymbolVendor ();
716 return symbols->FindGlobalVariables(name, namespace_decl, append, max_matches, variables);
721 Module::FindGlobalVariables (const RegularExpression& regex,
724 VariableList& variables)
726 SymbolVendor *symbols = GetSymbolVendor ();
728 return symbols->FindGlobalVariables(regex, append, max_matches, variables);
733 Module::FindCompileUnits (const FileSpec &path,
735 SymbolContextList &sc_list)
740 const size_t start_size = sc_list.GetSize();
741 const size_t num_compile_units = GetNumCompileUnits();
743 sc.module_sp = shared_from_this();
744 const bool compare_directory = (bool)path.GetDirectory();
745 for (size_t i=0; i<num_compile_units; ++i)
747 sc.comp_unit = GetCompileUnitAtIndex(i).get();
750 if (FileSpec::Equal (*sc.comp_unit, path, compare_directory))
754 return sc_list.GetSize() - start_size;
758 Module::FindFunctions (const ConstString &name,
759 const ClangNamespaceDecl *namespace_decl,
760 uint32_t name_type_mask,
761 bool include_symbols,
762 bool include_inlines,
764 SymbolContextList& sc_list)
769 const size_t old_size = sc_list.GetSize();
771 // Find all the functions (not symbols, but debug information functions...
772 SymbolVendor *symbols = GetSymbolVendor ();
774 if (name_type_mask & eFunctionNameTypeAuto)
776 ConstString lookup_name;
777 uint32_t lookup_name_type_mask = 0;
778 bool match_name_after_lookup = false;
779 Module::PrepareForFunctionNameLookup (name,
782 lookup_name_type_mask,
783 match_name_after_lookup);
787 symbols->FindFunctions(lookup_name,
789 lookup_name_type_mask,
794 // Now check our symbol table for symbols that are code symbols if requested
797 Symtab *symtab = symbols->GetSymtab();
799 symtab->FindFunctionSymbols(lookup_name, lookup_name_type_mask, sc_list);
803 if (match_name_after_lookup)
807 while (i<sc_list.GetSize())
809 if (sc_list.GetContextAtIndex(i, sc))
811 const char *func_name = sc.GetFunctionName().GetCString();
812 if (func_name && strstr (func_name, name.GetCString()) == NULL)
814 // Remove the current context
815 sc_list.RemoveContextAtIndex(i);
816 // Don't increment i and continue in the loop
828 symbols->FindFunctions(name, namespace_decl, name_type_mask, include_inlines, append, sc_list);
830 // Now check our symbol table for symbols that are code symbols if requested
833 Symtab *symtab = symbols->GetSymtab();
835 symtab->FindFunctionSymbols(name, name_type_mask, sc_list);
840 return sc_list.GetSize() - old_size;
844 Module::FindFunctions (const RegularExpression& regex,
845 bool include_symbols,
846 bool include_inlines,
848 SymbolContextList& sc_list)
853 const size_t start_size = sc_list.GetSize();
855 SymbolVendor *symbols = GetSymbolVendor ();
858 symbols->FindFunctions(regex, include_inlines, append, sc_list);
860 // Now check our symbol table for symbols that are code symbols if requested
863 Symtab *symtab = symbols->GetSymtab();
866 std::vector<uint32_t> symbol_indexes;
867 symtab->AppendSymbolIndexesMatchingRegExAndType (regex, eSymbolTypeAny, Symtab::eDebugAny, Symtab::eVisibilityAny, symbol_indexes);
868 const size_t num_matches = symbol_indexes.size();
871 SymbolContext sc(this);
872 const size_t end_functions_added_index = sc_list.GetSize();
873 size_t num_functions_added_to_sc_list = end_functions_added_index - start_size;
874 if (num_functions_added_to_sc_list == 0)
876 // No functions were added, just symbols, so we can just append them
877 for (size_t i=0; i<num_matches; ++i)
879 sc.symbol = symtab->SymbolAtIndex(symbol_indexes[i]);
880 SymbolType sym_type = sc.symbol->GetType();
881 if (sc.symbol && (sym_type == eSymbolTypeCode ||
882 sym_type == eSymbolTypeResolver))
888 typedef std::map<lldb::addr_t, uint32_t> FileAddrToIndexMap;
889 FileAddrToIndexMap file_addr_to_index;
890 for (size_t i=start_size; i<end_functions_added_index; ++i)
892 const SymbolContext &sc = sc_list[i];
895 file_addr_to_index[sc.function->GetAddressRange().GetBaseAddress().GetFileAddress()] = i;
898 FileAddrToIndexMap::const_iterator end = file_addr_to_index.end();
899 // Functions were added so we need to merge symbols into any
900 // existing function symbol contexts
901 for (size_t i=start_size; i<num_matches; ++i)
903 sc.symbol = symtab->SymbolAtIndex(symbol_indexes[i]);
904 SymbolType sym_type = sc.symbol->GetType();
905 if (sc.symbol && sc.symbol->ValueIsAddress() && (sym_type == eSymbolTypeCode || sym_type == eSymbolTypeResolver))
907 FileAddrToIndexMap::const_iterator pos = file_addr_to_index.find(sc.symbol->GetAddressRef().GetFileAddress());
911 sc_list[pos->second].symbol = sc.symbol;
919 return sc_list.GetSize() - start_size;
923 Module::FindAddressesForLine (const lldb::TargetSP target_sp,
924 const FileSpec &file, uint32_t line,
926 std::vector<Address> &output_local, std::vector<Address> &output_extern)
928 SearchFilterByModule filter(target_sp, m_file);
929 AddressResolverFileLine resolver(file, line, true);
930 resolver.ResolveAddress (filter);
932 for (size_t n=0;n<resolver.GetNumberOfAddresses();n++)
934 Address addr = resolver.GetAddressRangeAtIndex(n).GetBaseAddress();
935 Function *f = addr.CalculateSymbolContextFunction();
936 if (f && f == function)
937 output_local.push_back (addr);
939 output_extern.push_back (addr);
944 Module::FindTypes_Impl (const SymbolContext& sc,
945 const ConstString &name,
946 const ClangNamespaceDecl *namespace_decl,
951 Timer scoped_timer(__PRETTY_FUNCTION__, __PRETTY_FUNCTION__);
952 if (sc.module_sp.get() == NULL || sc.module_sp.get() == this)
954 SymbolVendor *symbols = GetSymbolVendor ();
956 return symbols->FindTypes(sc, name, namespace_decl, append, max_matches, types);
962 Module::FindTypesInNamespace (const SymbolContext& sc,
963 const ConstString &type_name,
964 const ClangNamespaceDecl *namespace_decl,
968 const bool append = true;
969 return FindTypes_Impl(sc, type_name, namespace_decl, append, max_matches, type_list);
973 Module::FindFirstType (const SymbolContext& sc,
974 const ConstString &name,
978 const size_t num_matches = FindTypes (sc, name, exact_match, 1, type_list);
980 return type_list.GetTypeAtIndex(0);
986 Module::FindTypes (const SymbolContext& sc,
987 const ConstString &name,
992 size_t num_matches = 0;
993 const char *type_name_cstr = name.GetCString();
994 std::string type_scope;
995 std::string type_basename;
996 const bool append = true;
997 TypeClass type_class = eTypeClassAny;
998 if (Type::GetTypeScopeAndBasename (type_name_cstr, type_scope, type_basename, type_class))
1000 // Check if "name" starts with "::" which means the qualified type starts
1001 // from the root namespace and implies and exact match. The typenames we
1002 // get back from clang do not start with "::" so we need to strip this off
1003 // in order to get the qualified names to match
1005 if (type_scope.size() >= 2 && type_scope[0] == ':' && type_scope[1] == ':')
1007 type_scope.erase(0,2);
1010 ConstString type_basename_const_str (type_basename.c_str());
1011 if (FindTypes_Impl(sc, type_basename_const_str, NULL, append, max_matches, types))
1013 types.RemoveMismatchedTypes (type_scope, type_basename, type_class, exact_match);
1014 num_matches = types.GetSize();
1019 // The type is not in a namespace/class scope, just search for it by basename
1020 if (type_class != eTypeClassAny)
1022 // The "type_name_cstr" will have been modified if we have a valid type class
1023 // prefix (like "struct", "class", "union", "typedef" etc).
1024 FindTypes_Impl(sc, ConstString(type_name_cstr), NULL, append, max_matches, types);
1025 types.RemoveMismatchedTypes (type_class);
1026 num_matches = types.GetSize();
1030 num_matches = FindTypes_Impl(sc, name, NULL, append, max_matches, types);
1039 Module::GetSymbolVendor (bool can_create, lldb_private::Stream *feedback_strm)
1041 Mutex::Locker locker (m_mutex);
1042 if (m_did_load_symbol_vendor == false && can_create)
1044 ObjectFile *obj_file = GetObjectFile ();
1045 if (obj_file != NULL)
1047 Timer scoped_timer(__PRETTY_FUNCTION__, __PRETTY_FUNCTION__);
1048 m_symfile_ap.reset(SymbolVendor::FindPlugin(shared_from_this(), feedback_strm));
1049 m_did_load_symbol_vendor = true;
1052 return m_symfile_ap.get();
1056 Module::SetFileSpecAndObjectName (const FileSpec &file, const ConstString &object_name)
1058 // Container objects whose paths do not specify a file directly can call
1059 // this function to correct the file and object names.
1061 m_mod_time = file.GetModificationTime();
1062 m_object_name = object_name;
1066 Module::GetArchitecture () const
1072 Module::GetSpecificationDescription () const
1074 std::string spec(GetFileSpec().GetPath());
1078 spec += m_object_name.GetCString();
1085 Module::GetDescription (Stream *s, lldb::DescriptionLevel level)
1087 Mutex::Locker locker (m_mutex);
1089 if (level >= eDescriptionLevelFull)
1091 if (m_arch.IsValid())
1092 s->Printf("(%s) ", m_arch.GetArchitectureName());
1095 if (level == eDescriptionLevelBrief)
1097 const char *filename = m_file.GetFilename().GetCString();
1099 s->PutCString (filename);
1103 char path[PATH_MAX];
1104 if (m_file.GetPath(path, sizeof(path)))
1105 s->PutCString(path);
1108 const char *object_name = m_object_name.GetCString();
1110 s->Printf("(%s)", object_name);
1114 Module::ReportError (const char *format, ...)
1116 if (format && format[0])
1119 strm.PutCString("error: ");
1120 GetDescription(&strm, lldb::eDescriptionLevelBrief);
1123 va_start (args, format);
1124 strm.PrintfVarArg(format, args);
1127 const int format_len = strlen(format);
1130 const char last_char = format[format_len-1];
1131 if (last_char != '\n' || last_char != '\r')
1134 Host::SystemLog (Host::eSystemLogError, "%s", strm.GetString().c_str());
1140 Module::FileHasChanged () const
1142 if (m_file_has_changed == false)
1143 m_file_has_changed = (m_file.GetModificationTime() != m_mod_time);
1144 return m_file_has_changed;
1148 Module::ReportErrorIfModifyDetected (const char *format, ...)
1150 if (m_first_file_changed_log == false)
1152 if (FileHasChanged ())
1154 m_first_file_changed_log = true;
1158 strm.PutCString("error: the object file ");
1159 GetDescription(&strm, lldb::eDescriptionLevelFull);
1160 strm.PutCString (" has been modified\n");
1163 va_start (args, format);
1164 strm.PrintfVarArg(format, args);
1167 const int format_len = strlen(format);
1170 const char last_char = format[format_len-1];
1171 if (last_char != '\n' || last_char != '\r')
1174 strm.PutCString("The debug session should be aborted as the original debug information has been overwritten.\n");
1175 Host::SystemLog (Host::eSystemLogError, "%s", strm.GetString().c_str());
1182 Module::ReportWarning (const char *format, ...)
1184 if (format && format[0])
1187 strm.PutCString("warning: ");
1188 GetDescription(&strm, lldb::eDescriptionLevelFull);
1192 va_start (args, format);
1193 strm.PrintfVarArg(format, args);
1196 const int format_len = strlen(format);
1199 const char last_char = format[format_len-1];
1200 if (last_char != '\n' || last_char != '\r')
1203 Host::SystemLog (Host::eSystemLogWarning, "%s", strm.GetString().c_str());
1208 Module::LogMessage (Log *log, const char *format, ...)
1212 StreamString log_message;
1213 GetDescription(&log_message, lldb::eDescriptionLevelFull);
1214 log_message.PutCString (": ");
1216 va_start (args, format);
1217 log_message.PrintfVarArg (format, args);
1219 log->PutCString(log_message.GetString().c_str());
1224 Module::LogMessageVerboseBacktrace (Log *log, const char *format, ...)
1228 StreamString log_message;
1229 GetDescription(&log_message, lldb::eDescriptionLevelFull);
1230 log_message.PutCString (": ");
1232 va_start (args, format);
1233 log_message.PrintfVarArg (format, args);
1235 if (log->GetVerbose())
1237 std::string back_trace;
1238 llvm::raw_string_ostream stream(back_trace);
1239 llvm::sys::PrintStackTrace(stream);
1240 log_message.PutCString(back_trace.c_str());
1242 log->PutCString(log_message.GetString().c_str());
1247 Module::Dump(Stream *s)
1249 Mutex::Locker locker (m_mutex);
1250 //s->Printf("%.*p: ", (int)sizeof(void*) * 2, this);
1252 s->Printf("Module %s%s%s%s\n",
1253 m_file.GetPath().c_str(),
1254 m_object_name ? "(" : "",
1255 m_object_name ? m_object_name.GetCString() : "",
1256 m_object_name ? ")" : "");
1260 ObjectFile *objfile = GetObjectFile ();
1264 SymbolVendor *symbols = GetSymbolVendor ();
1273 Module::GetTypeList ()
1275 SymbolVendor *symbols = GetSymbolVendor ();
1277 return &symbols->GetTypeList();
1282 Module::GetObjectName() const
1284 return m_object_name;
1288 Module::GetObjectFile()
1290 Mutex::Locker locker (m_mutex);
1291 if (m_did_load_objfile == false)
1293 Timer scoped_timer(__PRETTY_FUNCTION__,
1294 "Module::GetObjectFile () module = %s", GetFileSpec().GetFilename().AsCString(""));
1295 DataBufferSP data_sp;
1296 lldb::offset_t data_offset = 0;
1297 const lldb::offset_t file_size = m_file.GetByteSize();
1298 if (file_size > m_object_offset)
1300 m_did_load_objfile = true;
1301 m_objfile_sp = ObjectFile::FindPlugin (shared_from_this(),
1304 file_size - m_object_offset,
1309 // Once we get the object file, update our module with the object file's
1310 // architecture since it might differ in vendor/os if some parts were
1311 // unknown. But since the matching arch might already be more specific
1312 // than the generic COFF architecture, only merge in those values that
1313 // overwrite unspecified unknown values.
1315 m_objfile_sp->GetArchitecture(new_arch);
1316 m_arch.MergeFrom(new_arch);
1320 ReportError ("failed to load objfile for %s", GetFileSpec().GetPath().c_str());
1324 return m_objfile_sp.get();
1328 Module::GetSectionList()
1330 // Populate m_unified_sections_ap with sections from objfile.
1331 if (m_sections_ap.get() == NULL)
1333 ObjectFile *obj_file = GetObjectFile();
1335 obj_file->CreateSections(*GetUnifiedSectionList());
1337 return m_sections_ap.get();
1341 Module::SectionFileAddressesChanged ()
1343 ObjectFile *obj_file = GetObjectFile ();
1345 obj_file->SectionFileAddressesChanged ();
1346 SymbolVendor* sym_vendor = GetSymbolVendor();
1348 sym_vendor->SectionFileAddressesChanged ();
1352 Module::GetUnifiedSectionList()
1354 // Populate m_unified_sections_ap with sections from objfile.
1355 if (m_sections_ap.get() == NULL)
1356 m_sections_ap.reset(new SectionList());
1357 return m_sections_ap.get();
1361 Module::FindFirstSymbolWithNameAndType (const ConstString &name, SymbolType symbol_type)
1363 Timer scoped_timer(__PRETTY_FUNCTION__,
1364 "Module::FindFirstSymbolWithNameAndType (name = %s, type = %i)",
1367 SymbolVendor* sym_vendor = GetSymbolVendor();
1370 Symtab *symtab = sym_vendor->GetSymtab();
1372 return symtab->FindFirstSymbolWithNameAndType (name, symbol_type, Symtab::eDebugAny, Symtab::eVisibilityAny);
1377 Module::SymbolIndicesToSymbolContextList (Symtab *symtab, std::vector<uint32_t> &symbol_indexes, SymbolContextList &sc_list)
1379 // No need to protect this call using m_mutex all other method calls are
1380 // already thread safe.
1382 size_t num_indices = symbol_indexes.size();
1383 if (num_indices > 0)
1386 CalculateSymbolContext (&sc);
1387 for (size_t i = 0; i < num_indices; i++)
1389 sc.symbol = symtab->SymbolAtIndex (symbol_indexes[i]);
1391 sc_list.Append (sc);
1397 Module::FindFunctionSymbols (const ConstString &name,
1398 uint32_t name_type_mask,
1399 SymbolContextList& sc_list)
1401 Timer scoped_timer(__PRETTY_FUNCTION__,
1402 "Module::FindSymbolsFunctions (name = %s, mask = 0x%8.8x)",
1405 SymbolVendor* sym_vendor = GetSymbolVendor();
1408 Symtab *symtab = sym_vendor->GetSymtab();
1410 return symtab->FindFunctionSymbols (name, name_type_mask, sc_list);
1416 Module::FindSymbolsWithNameAndType (const ConstString &name, SymbolType symbol_type, SymbolContextList &sc_list)
1418 // No need to protect this call using m_mutex all other method calls are
1419 // already thread safe.
1422 Timer scoped_timer(__PRETTY_FUNCTION__,
1423 "Module::FindSymbolsWithNameAndType (name = %s, type = %i)",
1426 const size_t initial_size = sc_list.GetSize();
1427 SymbolVendor* sym_vendor = GetSymbolVendor();
1430 Symtab *symtab = sym_vendor->GetSymtab();
1433 std::vector<uint32_t> symbol_indexes;
1434 symtab->FindAllSymbolsWithNameAndType (name, symbol_type, symbol_indexes);
1435 SymbolIndicesToSymbolContextList (symtab, symbol_indexes, sc_list);
1438 return sc_list.GetSize() - initial_size;
1442 Module::FindSymbolsMatchingRegExAndType (const RegularExpression ®ex, SymbolType symbol_type, SymbolContextList &sc_list)
1444 // No need to protect this call using m_mutex all other method calls are
1445 // already thread safe.
1447 Timer scoped_timer(__PRETTY_FUNCTION__,
1448 "Module::FindSymbolsMatchingRegExAndType (regex = %s, type = %i)",
1451 const size_t initial_size = sc_list.GetSize();
1452 SymbolVendor* sym_vendor = GetSymbolVendor();
1455 Symtab *symtab = sym_vendor->GetSymtab();
1458 std::vector<uint32_t> symbol_indexes;
1459 symtab->FindAllSymbolsMatchingRexExAndType (regex, symbol_type, Symtab::eDebugAny, Symtab::eVisibilityAny, symbol_indexes);
1460 SymbolIndicesToSymbolContextList (symtab, symbol_indexes, sc_list);
1463 return sc_list.GetSize() - initial_size;
1467 Module::SetSymbolFileFileSpec (const FileSpec &file)
1473 // Remove any sections in the unified section list that come from the current symbol vendor.
1474 SectionList *section_list = GetSectionList();
1475 SymbolFile *symbol_file = m_symfile_ap->GetSymbolFile();
1476 if (section_list && symbol_file)
1478 ObjectFile *obj_file = symbol_file->GetObjectFile();
1479 // Make sure we have an object file and that the symbol vendor's objfile isn't
1480 // the same as the module's objfile before we remove any sections for it...
1483 // Check to make sure we aren't trying to specify the file we already have
1484 if (obj_file->GetFileSpec() == file)
1486 // We are being told to add the exact same file that we already have
1487 // we don't have to do anything.
1491 // The symbol file might be a directory bundle ("/tmp/a.out.dSYM") instead
1492 // of a full path to the symbol file within the bundle
1493 // ("/tmp/a.out.dSYM/Contents/Resources/DWARF/a.out"). So we need to check this
1495 if (file.IsDirectory())
1497 std::string new_path(file.GetPath());
1498 std::string old_path(obj_file->GetFileSpec().GetPath());
1499 if (old_path.find(new_path) == 0)
1501 // We specified the same bundle as the symbol file that we already have
1506 if (obj_file != m_objfile_sp.get())
1508 size_t num_sections = section_list->GetNumSections (0);
1509 for (size_t idx = num_sections; idx > 0; --idx)
1511 lldb::SectionSP section_sp (section_list->GetSectionAtIndex (idx - 1));
1512 if (section_sp->GetObjectFile() == obj_file)
1514 section_list->DeleteSection (idx - 1);
1520 // Keep all old symbol files around in case there are any lingering type references in
1521 // any SBValue objects that might have been handed out.
1522 m_old_symfiles.push_back(std::move(m_symfile_ap));
1524 m_symfile_spec = file;
1525 m_symfile_ap.reset();
1526 m_did_load_symbol_vendor = false;
1530 Module::IsExecutable ()
1532 if (GetObjectFile() == NULL)
1535 return GetObjectFile()->IsExecutable();
1539 Module::IsLoadedInTarget (Target *target)
1541 ObjectFile *obj_file = GetObjectFile();
1544 SectionList *sections = GetSectionList();
1545 if (sections != NULL)
1547 size_t num_sections = sections->GetSize();
1548 for (size_t sect_idx = 0; sect_idx < num_sections; sect_idx++)
1550 SectionSP section_sp = sections->GetSectionAtIndex(sect_idx);
1551 if (section_sp->GetLoadBaseAddress(target) != LLDB_INVALID_ADDRESS)
1562 Module::LoadScriptingResourceInTarget (Target *target, Error& error, Stream* feedback_stream)
1566 error.SetErrorString("invalid destination Target");
1570 LoadScriptFromSymFile should_load = target->TargetProperties::GetLoadScriptFromSymbolFile();
1572 if (should_load == eLoadScriptFromSymFileFalse)
1575 Debugger &debugger = target->GetDebugger();
1576 const ScriptLanguage script_language = debugger.GetScriptLanguage();
1577 if (script_language != eScriptLanguageNone)
1580 PlatformSP platform_sp(target->GetPlatform());
1584 error.SetErrorString("invalid Platform");
1588 FileSpecList file_specs = platform_sp->LocateExecutableScriptingResources (target,
1593 const uint32_t num_specs = file_specs.GetSize();
1596 ScriptInterpreter *script_interpreter = debugger.GetCommandInterpreter().GetScriptInterpreter();
1597 if (script_interpreter)
1599 for (uint32_t i=0; i<num_specs; ++i)
1601 FileSpec scripting_fspec (file_specs.GetFileSpecAtIndex(i));
1602 if (scripting_fspec && scripting_fspec.Exists())
1604 if (should_load == eLoadScriptFromSymFileWarn)
1606 if (feedback_stream)
1607 feedback_stream->Printf("warning: '%s' contains a debug script. To run this script in "
1608 "this debug session:\n\n command script import \"%s\"\n\n"
1609 "To run all discovered debug scripts in this session:\n\n"
1610 " settings set target.load-script-from-symbol-file true\n",
1611 GetFileSpec().GetFileNameStrippingExtension().GetCString(),
1612 scripting_fspec.GetPath().c_str());
1615 StreamString scripting_stream;
1616 scripting_fspec.Dump(&scripting_stream);
1617 const bool can_reload = true;
1618 const bool init_lldb_globals = false;
1619 bool did_load = script_interpreter->LoadScriptingModule(scripting_stream.GetData(),
1630 error.SetErrorString("invalid ScriptInterpreter");
1639 Module::SetArchitecture (const ArchSpec &new_arch)
1641 if (!m_arch.IsValid())
1646 return m_arch.IsCompatibleMatch(new_arch);
1650 Module::SetLoadAddress (Target &target, lldb::addr_t value, bool value_is_offset, bool &changed)
1652 ObjectFile *object_file = GetObjectFile();
1655 changed = object_file->SetLoadAddress(target, value, value_is_offset);
1667 Module::MatchesModuleSpec (const ModuleSpec &module_ref)
1669 const UUID &uuid = module_ref.GetUUID();
1673 // If the UUID matches, then nothing more needs to match...
1674 if (uuid == GetUUID())
1680 const FileSpec &file_spec = module_ref.GetFileSpec();
1683 if (!FileSpec::Equal (file_spec, m_file, (bool)file_spec.GetDirectory()))
1687 const FileSpec &platform_file_spec = module_ref.GetPlatformFileSpec();
1688 if (platform_file_spec)
1690 if (!FileSpec::Equal (platform_file_spec, GetPlatformFileSpec (), (bool)platform_file_spec.GetDirectory()))
1694 const ArchSpec &arch = module_ref.GetArchitecture();
1697 if (!m_arch.IsCompatibleMatch(arch))
1701 const ConstString &object_name = module_ref.GetObjectName();
1704 if (object_name != GetObjectName())
1711 Module::FindSourceFile (const FileSpec &orig_spec, FileSpec &new_spec) const
1713 Mutex::Locker locker (m_mutex);
1714 return m_source_mappings.FindFile (orig_spec, new_spec);
1718 Module::RemapSourceFile (const char *path, std::string &new_path) const
1720 Mutex::Locker locker (m_mutex);
1721 return m_source_mappings.RemapPath(path, new_path);
1725 Module::GetVersion (uint32_t *versions, uint32_t num_versions)
1727 ObjectFile *obj_file = GetObjectFile();
1729 return obj_file->GetVersion (versions, num_versions);
1731 if (versions && num_versions)
1733 for (uint32_t i=0; i<num_versions; ++i)
1734 versions[i] = LLDB_INVALID_MODULE_VERSION;
1740 Module::PrepareForFunctionNameLookup (const ConstString &name,
1741 uint32_t name_type_mask,
1742 ConstString &lookup_name,
1743 uint32_t &lookup_name_type_mask,
1744 bool &match_name_after_lookup)
1746 const char *name_cstr = name.GetCString();
1747 lookup_name_type_mask = eFunctionNameTypeNone;
1748 match_name_after_lookup = false;
1750 llvm::StringRef basename;
1751 llvm::StringRef context;
1753 if (name_type_mask & eFunctionNameTypeAuto)
1755 if (CPPLanguageRuntime::IsCPPMangledName (name_cstr))
1756 lookup_name_type_mask = eFunctionNameTypeFull;
1757 else if (ObjCLanguageRuntime::IsPossibleObjCMethodName (name_cstr))
1758 lookup_name_type_mask = eFunctionNameTypeFull;
1761 if (ObjCLanguageRuntime::IsPossibleObjCSelector(name_cstr))
1762 lookup_name_type_mask |= eFunctionNameTypeSelector;
1764 CPPLanguageRuntime::MethodName cpp_method (name);
1765 basename = cpp_method.GetBasename();
1766 if (basename.empty())
1768 if (CPPLanguageRuntime::ExtractContextAndIdentifier (name_cstr, context, basename))
1769 lookup_name_type_mask |= (eFunctionNameTypeMethod | eFunctionNameTypeBase);
1771 lookup_name_type_mask |= eFunctionNameTypeFull;
1775 lookup_name_type_mask |= (eFunctionNameTypeMethod | eFunctionNameTypeBase);
1781 lookup_name_type_mask = name_type_mask;
1782 if (lookup_name_type_mask & eFunctionNameTypeMethod || name_type_mask & eFunctionNameTypeBase)
1784 // If they've asked for a CPP method or function name and it can't be that, we don't
1785 // even need to search for CPP methods or names.
1786 CPPLanguageRuntime::MethodName cpp_method (name);
1787 if (cpp_method.IsValid())
1789 basename = cpp_method.GetBasename();
1791 if (!cpp_method.GetQualifiers().empty())
1793 // There is a "const" or other qualifier following the end of the function parens,
1794 // this can't be a eFunctionNameTypeBase
1795 lookup_name_type_mask &= ~(eFunctionNameTypeBase);
1796 if (lookup_name_type_mask == eFunctionNameTypeNone)
1802 // If the CPP method parser didn't manage to chop this up, try to fill in the base name if we can.
1803 // If a::b::c is passed in, we need to just look up "c", and then we'll filter the result later.
1804 CPPLanguageRuntime::ExtractContextAndIdentifier (name_cstr, context, basename);
1808 if (lookup_name_type_mask & eFunctionNameTypeSelector)
1810 if (!ObjCLanguageRuntime::IsPossibleObjCSelector(name_cstr))
1812 lookup_name_type_mask &= ~(eFunctionNameTypeSelector);
1813 if (lookup_name_type_mask == eFunctionNameTypeNone)
1819 if (!basename.empty())
1821 // The name supplied was a partial C++ path like "a::count". In this case we want to do a
1822 // lookup on the basename "count" and then make sure any matching results contain "a::count"
1823 // so that it would match "b::a::count" and "a::count". This is why we set "match_name_after_lookup"
1825 lookup_name.SetString(basename);
1826 match_name_after_lookup = true;
1830 // The name is already correct, just use the exact name as supplied, and we won't need
1831 // to check if any matches contain "name"
1833 match_name_after_lookup = false;
1838 Module::CreateJITModule (const lldb::ObjectFileJITDelegateSP &delegate_sp)
1842 // Must create a module and place it into a shared pointer before
1843 // we can create an object file since it has a std::weak_ptr back
1844 // to the module, so we need to control the creation carefully in
1845 // this static function
1846 ModuleSP module_sp(new Module());
1847 module_sp->m_objfile_sp.reset (new ObjectFileJIT (module_sp, delegate_sp));
1848 if (module_sp->m_objfile_sp)
1850 // Once we get the object file, update our module with the object file's
1851 // architecture since it might differ in vendor/os if some parts were
1853 module_sp->m_objfile_sp->GetArchitecture (module_sp->m_arch);
1861 Module::GetIsDynamicLinkEditor()
1863 ObjectFile * obj_file = GetObjectFile ();
1866 return obj_file->GetIsDynamicLinkEditor();