blob: f00afc10ad2be53af25247eee0876c9eb8d3461b [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- Module.cpp ----------------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Daniel Malea93a64302012-12-05 00:20:57 +000010#include "lldb/lldb-python.h"
11
Enrico Granata17598482012-11-08 02:22:02 +000012#include "lldb/Core/Error.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000013#include "lldb/Core/Module.h"
Greg Claytonc9660542012-02-05 02:38:54 +000014#include "lldb/Core/DataBuffer.h"
15#include "lldb/Core/DataBufferHeap.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000016#include "lldb/Core/Log.h"
17#include "lldb/Core/ModuleList.h"
Greg Clayton1f746072012-08-29 21:13:06 +000018#include "lldb/Core/ModuleSpec.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000019#include "lldb/Core/RegularExpression.h"
Greg Clayton1f746072012-08-29 21:13:06 +000020#include "lldb/Core/Section.h"
Greg Claytonc982b3d2011-11-28 01:45:00 +000021#include "lldb/Core/StreamString.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000022#include "lldb/Core/Timer.h"
Greg Claytone38a5ed2012-01-05 03:57:59 +000023#include "lldb/Host/Host.h"
Enrico Granata17598482012-11-08 02:22:02 +000024#include "lldb/Host/Symbols.h"
25#include "lldb/Interpreter/CommandInterpreter.h"
26#include "lldb/Interpreter/ScriptInterpreter.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000027#include "lldb/lldb-private-log.h"
Greg Clayton1f746072012-08-29 21:13:06 +000028#include "lldb/Symbol/CompileUnit.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000029#include "lldb/Symbol/ObjectFile.h"
30#include "lldb/Symbol/SymbolContext.h"
31#include "lldb/Symbol/SymbolVendor.h"
Greg Clayton43fe2172013-04-03 02:00:15 +000032#include "lldb/Target/CPPLanguageRuntime.h"
33#include "lldb/Target/ObjCLanguageRuntime.h"
Greg Claytonc9660542012-02-05 02:38:54 +000034#include "lldb/Target/Process.h"
35#include "lldb/Target/Target.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000036
37using namespace lldb;
38using namespace lldb_private;
39
Greg Clayton65a03992011-08-09 00:01:09 +000040// Shared pointers to modules track module lifetimes in
41// targets and in the global module, but this collection
42// will track all module objects that are still alive
43typedef std::vector<Module *> ModuleCollection;
44
45static ModuleCollection &
46GetModuleCollection()
47{
Jim Ingham549f7372011-10-31 23:47:10 +000048 // This module collection needs to live past any module, so we could either make it a
49 // shared pointer in each module or just leak is. Since it is only an empty vector by
50 // the time all the modules have gone away, we just leak it for now. If we decide this
51 // is a big problem we can introduce a Finalize method that will tear everything down in
52 // a predictable order.
53
54 static ModuleCollection *g_module_collection = NULL;
55 if (g_module_collection == NULL)
56 g_module_collection = new ModuleCollection();
57
58 return *g_module_collection;
Greg Clayton65a03992011-08-09 00:01:09 +000059}
60
Greg Claytonb26e6be2012-01-27 18:08:35 +000061Mutex *
Greg Clayton65a03992011-08-09 00:01:09 +000062Module::GetAllocationModuleCollectionMutex()
63{
Greg Claytonb26e6be2012-01-27 18:08:35 +000064 // NOTE: The mutex below must be leaked since the global module list in
65 // the ModuleList class will get torn at some point, and we can't know
66 // if it will tear itself down before the "g_module_collection_mutex" below
67 // will. So we leak a Mutex object below to safeguard against that
68
69 static Mutex *g_module_collection_mutex = NULL;
70 if (g_module_collection_mutex == NULL)
71 g_module_collection_mutex = new Mutex (Mutex::eMutexTypeRecursive); // NOTE: known leak
72 return g_module_collection_mutex;
Greg Clayton65a03992011-08-09 00:01:09 +000073}
74
75size_t
76Module::GetNumberAllocatedModules ()
77{
78 Mutex::Locker locker (GetAllocationModuleCollectionMutex());
79 return GetModuleCollection().size();
80}
81
82Module *
83Module::GetAllocatedModuleAtIndex (size_t idx)
84{
85 Mutex::Locker locker (GetAllocationModuleCollectionMutex());
86 ModuleCollection &modules = GetModuleCollection();
87 if (idx < modules.size())
88 return modules[idx];
89 return NULL;
90}
Greg Clayton29ad7b92012-01-27 18:45:39 +000091#if 0
Greg Clayton65a03992011-08-09 00:01:09 +000092
Greg Clayton29ad7b92012-01-27 18:45:39 +000093// These functions help us to determine if modules are still loaded, yet don't require that
94// you have a command interpreter and can easily be called from an external debugger.
95namespace lldb {
Greg Clayton65a03992011-08-09 00:01:09 +000096
Greg Clayton29ad7b92012-01-27 18:45:39 +000097 void
98 ClearModuleInfo (void)
99 {
Greg Clayton0cd70862012-04-09 20:22:01 +0000100 const bool mandatory = true;
101 ModuleList::RemoveOrphanSharedModules(mandatory);
Greg Clayton29ad7b92012-01-27 18:45:39 +0000102 }
103
104 void
105 DumpModuleInfo (void)
106 {
107 Mutex::Locker locker (Module::GetAllocationModuleCollectionMutex());
108 ModuleCollection &modules = GetModuleCollection();
109 const size_t count = modules.size();
Daniel Malead01b2952012-11-29 21:49:15 +0000110 printf ("%s: %" PRIu64 " modules:\n", __PRETTY_FUNCTION__, (uint64_t)count);
Greg Clayton29ad7b92012-01-27 18:45:39 +0000111 for (size_t i=0; i<count; ++i)
112 {
113
114 StreamString strm;
115 Module *module = modules[i];
116 const bool in_shared_module_list = ModuleList::ModuleIsInCache (module);
117 module->GetDescription(&strm, eDescriptionLevelFull);
118 printf ("%p: shared = %i, ref_count = %3u, module = %s\n",
119 module,
120 in_shared_module_list,
121 (uint32_t)module->use_count(),
122 strm.GetString().c_str());
123 }
124 }
125}
126
127#endif
Greg Clayton3a18e312012-10-08 22:41:53 +0000128
Greg Claytonb9a01b32012-02-26 05:51:37 +0000129Module::Module (const ModuleSpec &module_spec) :
130 m_mutex (Mutex::eMutexTypeRecursive),
131 m_mod_time (module_spec.GetFileSpec().GetModificationTime()),
132 m_arch (module_spec.GetArchitecture()),
133 m_uuid (),
134 m_file (module_spec.GetFileSpec()),
135 m_platform_file(module_spec.GetPlatformFileSpec()),
136 m_symfile_spec (module_spec.GetSymbolFileSpec()),
137 m_object_name (module_spec.GetObjectName()),
138 m_object_offset (module_spec.GetObjectOffset()),
Greg Clayton57abc5d2013-05-10 21:47:16 +0000139 m_object_mod_time (module_spec.GetObjectModificationTime()),
Greg Claytonb9a01b32012-02-26 05:51:37 +0000140 m_objfile_sp (),
141 m_symfile_ap (),
142 m_ast (),
Greg Claytond804d282012-03-15 21:01:31 +0000143 m_source_mappings (),
Greg Claytonb9a01b32012-02-26 05:51:37 +0000144 m_did_load_objfile (false),
145 m_did_load_symbol_vendor (false),
146 m_did_parse_uuid (false),
147 m_did_init_ast (false),
148 m_is_dynamic_loader_module (false),
Greg Clayton1d609092012-07-12 22:51:12 +0000149 m_file_has_changed (false),
150 m_first_file_changed_log (false)
Greg Claytonb9a01b32012-02-26 05:51:37 +0000151{
152 // Scope for locker below...
153 {
154 Mutex::Locker locker (GetAllocationModuleCollectionMutex());
155 GetModuleCollection().push_back(this);
156 }
157
Greg Clayton5160ce52013-03-27 23:08:40 +0000158 Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_OBJECT|LIBLLDB_LOG_MODULES));
Greg Claytonb9a01b32012-02-26 05:51:37 +0000159 if (log)
Greg Claytonb5ad4ec2013-04-29 17:25:54 +0000160 log->Printf ("%p Module::Module((%s) '%s%s%s%s')",
Greg Claytonb9a01b32012-02-26 05:51:37 +0000161 this,
162 m_arch.GetArchitectureName(),
Greg Claytonb5ad4ec2013-04-29 17:25:54 +0000163 m_file.GetPath().c_str(),
Greg Claytonb9a01b32012-02-26 05:51:37 +0000164 m_object_name.IsEmpty() ? "" : "(",
165 m_object_name.IsEmpty() ? "" : m_object_name.AsCString(""),
166 m_object_name.IsEmpty() ? "" : ")");
167}
168
Greg Claytone72dfb32012-02-24 01:59:29 +0000169Module::Module(const FileSpec& file_spec,
170 const ArchSpec& arch,
171 const ConstString *object_name,
Greg Clayton57abc5d2013-05-10 21:47:16 +0000172 off_t object_offset,
173 const TimeValue *object_mod_time_ptr) :
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000174 m_mutex (Mutex::eMutexTypeRecursive),
175 m_mod_time (file_spec.GetModificationTime()),
176 m_arch (arch),
177 m_uuid (),
178 m_file (file_spec),
Greg Clayton32e0a752011-03-30 18:16:51 +0000179 m_platform_file(),
Greg Claytone72dfb32012-02-24 01:59:29 +0000180 m_symfile_spec (),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000181 m_object_name (),
Greg Clayton8b82f082011-04-12 05:54:46 +0000182 m_object_offset (object_offset),
Greg Clayton57abc5d2013-05-10 21:47:16 +0000183 m_object_mod_time (),
Greg Clayton762f7132011-09-18 18:59:15 +0000184 m_objfile_sp (),
Greg Claytone83e7312010-09-07 23:40:05 +0000185 m_symfile_ap (),
Greg Clayton6beaaa62011-01-17 03:46:26 +0000186 m_ast (),
Greg Claytond804d282012-03-15 21:01:31 +0000187 m_source_mappings (),
Greg Claytone83e7312010-09-07 23:40:05 +0000188 m_did_load_objfile (false),
189 m_did_load_symbol_vendor (false),
190 m_did_parse_uuid (false),
Greg Clayton6beaaa62011-01-17 03:46:26 +0000191 m_did_init_ast (false),
Greg Claytone38a5ed2012-01-05 03:57:59 +0000192 m_is_dynamic_loader_module (false),
Greg Clayton1d609092012-07-12 22:51:12 +0000193 m_file_has_changed (false),
194 m_first_file_changed_log (false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000195{
Greg Clayton65a03992011-08-09 00:01:09 +0000196 // Scope for locker below...
197 {
198 Mutex::Locker locker (GetAllocationModuleCollectionMutex());
199 GetModuleCollection().push_back(this);
200 }
201
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000202 if (object_name)
203 m_object_name = *object_name;
Greg Clayton57abc5d2013-05-10 21:47:16 +0000204
205 if (object_mod_time_ptr)
206 m_object_mod_time = *object_mod_time_ptr;
207
Greg Clayton5160ce52013-03-27 23:08:40 +0000208 Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_OBJECT|LIBLLDB_LOG_MODULES));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000209 if (log)
Greg Claytonb5ad4ec2013-04-29 17:25:54 +0000210 log->Printf ("%p Module::Module((%s) '%s%s%s%s')",
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000211 this,
Greg Clayton64195a22011-02-23 00:35:02 +0000212 m_arch.GetArchitectureName(),
Greg Claytonb5ad4ec2013-04-29 17:25:54 +0000213 m_file.GetPath().c_str(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000214 m_object_name.IsEmpty() ? "" : "(",
215 m_object_name.IsEmpty() ? "" : m_object_name.AsCString(""),
216 m_object_name.IsEmpty() ? "" : ")");
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000217}
218
219Module::~Module()
220{
Greg Clayton65a03992011-08-09 00:01:09 +0000221 // Scope for locker below...
222 {
223 Mutex::Locker locker (GetAllocationModuleCollectionMutex());
224 ModuleCollection &modules = GetModuleCollection();
225 ModuleCollection::iterator end = modules.end();
226 ModuleCollection::iterator pos = std::find(modules.begin(), end, this);
Greg Clayton3a18e312012-10-08 22:41:53 +0000227 assert (pos != end);
228 modules.erase(pos);
Greg Clayton65a03992011-08-09 00:01:09 +0000229 }
Greg Clayton5160ce52013-03-27 23:08:40 +0000230 Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_OBJECT|LIBLLDB_LOG_MODULES));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000231 if (log)
Greg Claytonb5ad4ec2013-04-29 17:25:54 +0000232 log->Printf ("%p Module::~Module((%s) '%s%s%s%s')",
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000233 this,
Greg Clayton64195a22011-02-23 00:35:02 +0000234 m_arch.GetArchitectureName(),
Greg Claytonb5ad4ec2013-04-29 17:25:54 +0000235 m_file.GetPath().c_str(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000236 m_object_name.IsEmpty() ? "" : "(",
237 m_object_name.IsEmpty() ? "" : m_object_name.AsCString(""),
238 m_object_name.IsEmpty() ? "" : ")");
Greg Clayton6beaaa62011-01-17 03:46:26 +0000239 // Release any auto pointers before we start tearing down our member
240 // variables since the object file and symbol files might need to make
241 // function calls back into this module object. The ordering is important
242 // here because symbol files can require the module object file. So we tear
243 // down the symbol file first, then the object file.
244 m_symfile_ap.reset();
Greg Clayton762f7132011-09-18 18:59:15 +0000245 m_objfile_sp.reset();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000246}
247
Greg Claytonc7f09cc2012-02-24 21:55:59 +0000248ObjectFile *
249Module::GetMemoryObjectFile (const lldb::ProcessSP &process_sp, lldb::addr_t header_addr, Error &error)
250{
251 if (m_objfile_sp)
252 {
253 error.SetErrorString ("object file already exists");
254 }
255 else
256 {
257 Mutex::Locker locker (m_mutex);
258 if (process_sp)
259 {
Greg Claytonc7f09cc2012-02-24 21:55:59 +0000260 m_did_load_objfile = true;
Greg Clayton7b0992d2013-04-18 22:45:39 +0000261 std::unique_ptr<DataBufferHeap> data_ap (new DataBufferHeap (512, 0));
Greg Claytonc7f09cc2012-02-24 21:55:59 +0000262 Error readmem_error;
263 const size_t bytes_read = process_sp->ReadMemory (header_addr,
264 data_ap->GetBytes(),
265 data_ap->GetByteSize(),
266 readmem_error);
267 if (bytes_read == 512)
268 {
269 DataBufferSP data_sp(data_ap.release());
270 m_objfile_sp = ObjectFile::FindPlugin(shared_from_this(), process_sp, header_addr, data_sp);
271 if (m_objfile_sp)
272 {
Greg Clayton3e10cf32012-04-20 19:50:20 +0000273 StreamString s;
Daniel Malead01b2952012-11-29 21:49:15 +0000274 s.Printf("0x%16.16" PRIx64, header_addr);
Greg Clayton3e10cf32012-04-20 19:50:20 +0000275 m_object_name.SetCString (s.GetData());
276
277 // Once we get the object file, update our module with the object file's
Greg Claytonc7f09cc2012-02-24 21:55:59 +0000278 // architecture since it might differ in vendor/os if some parts were
279 // unknown.
280 m_objfile_sp->GetArchitecture (m_arch);
281 }
282 else
283 {
284 error.SetErrorString ("unable to find suitable object file plug-in");
285 }
286 }
287 else
288 {
289 error.SetErrorStringWithFormat ("unable to read header from memory: %s", readmem_error.AsCString());
290 }
291 }
292 else
293 {
294 error.SetErrorString ("invalid process");
295 }
296 }
297 return m_objfile_sp.get();
298}
299
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000300
Greg Clayton60830262011-02-04 18:53:10 +0000301const lldb_private::UUID&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000302Module::GetUUID()
303{
304 Mutex::Locker locker (m_mutex);
Greg Claytone83e7312010-09-07 23:40:05 +0000305 if (m_did_parse_uuid == false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000306 {
307 ObjectFile * obj_file = GetObjectFile ();
308
309 if (obj_file != NULL)
310 {
311 obj_file->GetUUID(&m_uuid);
Greg Claytone83e7312010-09-07 23:40:05 +0000312 m_did_parse_uuid = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000313 }
314 }
315 return m_uuid;
316}
317
Greg Clayton6beaaa62011-01-17 03:46:26 +0000318ClangASTContext &
319Module::GetClangASTContext ()
320{
321 Mutex::Locker locker (m_mutex);
322 if (m_did_init_ast == false)
323 {
324 ObjectFile * objfile = GetObjectFile();
Greg Clayton514487e2011-02-15 21:59:32 +0000325 ArchSpec object_arch;
326 if (objfile && objfile->GetArchitecture(object_arch))
Greg Clayton6beaaa62011-01-17 03:46:26 +0000327 {
328 m_did_init_ast = true;
Jason Molenda981d4df2012-10-16 20:45:49 +0000329
330 // LLVM wants this to be set to iOS or MacOSX; if we're working on
331 // a bare-boards type image, change the triple for llvm's benefit.
332 if (object_arch.GetTriple().getVendor() == llvm::Triple::Apple
333 && object_arch.GetTriple().getOS() == llvm::Triple::UnknownOS)
334 {
335 if (object_arch.GetTriple().getArch() == llvm::Triple::arm ||
336 object_arch.GetTriple().getArch() == llvm::Triple::thumb)
337 {
338 object_arch.GetTriple().setOS(llvm::Triple::IOS);
339 }
340 else
341 {
342 object_arch.GetTriple().setOS(llvm::Triple::MacOSX);
343 }
344 }
Greg Clayton514487e2011-02-15 21:59:32 +0000345 m_ast.SetArchitecture (object_arch);
Greg Clayton6beaaa62011-01-17 03:46:26 +0000346 }
347 }
348 return m_ast;
349}
350
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000351void
352Module::ParseAllDebugSymbols()
353{
354 Mutex::Locker locker (m_mutex);
Greg Claytonc7bece562013-01-25 18:06:21 +0000355 size_t num_comp_units = GetNumCompileUnits();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000356 if (num_comp_units == 0)
357 return;
358
Greg Claytona2eee182011-09-17 07:23:18 +0000359 SymbolContext sc;
Greg Claytone1cd1be2012-01-29 20:56:30 +0000360 sc.module_sp = shared_from_this();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000361 SymbolVendor *symbols = GetSymbolVendor ();
362
Greg Claytonc7bece562013-01-25 18:06:21 +0000363 for (size_t cu_idx = 0; cu_idx < num_comp_units; cu_idx++)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000364 {
365 sc.comp_unit = symbols->GetCompileUnitAtIndex(cu_idx).get();
366 if (sc.comp_unit)
367 {
368 sc.function = NULL;
369 symbols->ParseVariablesForContext(sc);
370
371 symbols->ParseCompileUnitFunctions(sc);
372
Greg Claytonc7bece562013-01-25 18:06:21 +0000373 for (size_t func_idx = 0; (sc.function = sc.comp_unit->GetFunctionAtIndex(func_idx).get()) != NULL; ++func_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000374 {
375 symbols->ParseFunctionBlocks(sc);
376
377 // Parse the variables for this function and all its blocks
378 symbols->ParseVariablesForContext(sc);
379 }
380
381
382 // Parse all types for this compile unit
383 sc.function = NULL;
384 symbols->ParseTypes(sc);
385 }
386 }
387}
388
389void
390Module::CalculateSymbolContext(SymbolContext* sc)
391{
Greg Claytone1cd1be2012-01-29 20:56:30 +0000392 sc->module_sp = shared_from_this();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000393}
394
Greg Claytone72dfb32012-02-24 01:59:29 +0000395ModuleSP
Greg Clayton7e9b1fd2011-08-12 21:40:01 +0000396Module::CalculateSymbolContextModule ()
397{
Greg Claytone72dfb32012-02-24 01:59:29 +0000398 return shared_from_this();
Greg Clayton7e9b1fd2011-08-12 21:40:01 +0000399}
400
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000401void
402Module::DumpSymbolContext(Stream *s)
403{
Jason Molendafd54b362011-09-20 21:44:10 +0000404 s->Printf(", Module{%p}", this);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000405}
406
Greg Claytonc7bece562013-01-25 18:06:21 +0000407size_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000408Module::GetNumCompileUnits()
409{
410 Mutex::Locker locker (m_mutex);
411 Timer scoped_timer(__PRETTY_FUNCTION__, "Module::GetNumCompileUnits (module = %p)", this);
412 SymbolVendor *symbols = GetSymbolVendor ();
413 if (symbols)
414 return symbols->GetNumCompileUnits();
415 return 0;
416}
417
418CompUnitSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000419Module::GetCompileUnitAtIndex (size_t index)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000420{
421 Mutex::Locker locker (m_mutex);
Greg Claytonc7bece562013-01-25 18:06:21 +0000422 size_t num_comp_units = GetNumCompileUnits ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000423 CompUnitSP cu_sp;
424
425 if (index < num_comp_units)
426 {
427 SymbolVendor *symbols = GetSymbolVendor ();
428 if (symbols)
429 cu_sp = symbols->GetCompileUnitAtIndex(index);
430 }
431 return cu_sp;
432}
433
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000434bool
435Module::ResolveFileAddress (lldb::addr_t vm_addr, Address& so_addr)
436{
437 Mutex::Locker locker (m_mutex);
Daniel Malead01b2952012-11-29 21:49:15 +0000438 Timer scoped_timer(__PRETTY_FUNCTION__, "Module::ResolveFileAddress (vm_addr = 0x%" PRIx64 ")", vm_addr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000439 ObjectFile* ofile = GetObjectFile();
440 if (ofile)
441 return so_addr.ResolveAddressUsingFileSections(vm_addr, ofile->GetSectionList());
442 return false;
443}
444
445uint32_t
446Module::ResolveSymbolContextForAddress (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc)
447{
448 Mutex::Locker locker (m_mutex);
449 uint32_t resolved_flags = 0;
450
Greg Clayton72310352013-02-23 04:12:47 +0000451 // Clear the result symbol context in case we don't find anything, but don't clear the target
452 sc.Clear(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000453
454 // Get the section from the section/offset address.
Greg Claytone72dfb32012-02-24 01:59:29 +0000455 SectionSP section_sp (so_addr.GetSection());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000456
457 // Make sure the section matches this module before we try and match anything
Greg Claytone72dfb32012-02-24 01:59:29 +0000458 if (section_sp && section_sp->GetModule().get() == this)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000459 {
460 // If the section offset based address resolved itself, then this
461 // is the right module.
Greg Claytone1cd1be2012-01-29 20:56:30 +0000462 sc.module_sp = shared_from_this();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000463 resolved_flags |= eSymbolContextModule;
464
465 // Resolve the compile unit, function, block, line table or line
466 // entry if requested.
467 if (resolve_scope & eSymbolContextCompUnit ||
468 resolve_scope & eSymbolContextFunction ||
469 resolve_scope & eSymbolContextBlock ||
470 resolve_scope & eSymbolContextLineEntry )
471 {
472 SymbolVendor *symbols = GetSymbolVendor ();
473 if (symbols)
474 resolved_flags |= symbols->ResolveSymbolContext (so_addr, resolve_scope, sc);
475 }
476
Jim Ingham680e1772010-08-31 23:51:36 +0000477 // Resolve the symbol if requested, but don't re-look it up if we've already found it.
478 if (resolve_scope & eSymbolContextSymbol && !(resolved_flags & eSymbolContextSymbol))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000479 {
480 ObjectFile* ofile = GetObjectFile();
481 if (ofile)
482 {
483 Symtab *symtab = ofile->GetSymtab();
484 if (symtab)
485 {
486 if (so_addr.IsSectionOffset())
487 {
488 sc.symbol = symtab->FindSymbolContainingFileAddress(so_addr.GetFileAddress());
489 if (sc.symbol)
490 resolved_flags |= eSymbolContextSymbol;
491 }
492 }
493 }
494 }
495 }
496 return resolved_flags;
497}
498
499uint32_t
Greg Clayton274060b2010-10-20 20:54:39 +0000500Module::ResolveSymbolContextForFilePath
501(
502 const char *file_path,
503 uint32_t line,
504 bool check_inlines,
505 uint32_t resolve_scope,
506 SymbolContextList& sc_list
507)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000508{
Greg Clayton274060b2010-10-20 20:54:39 +0000509 FileSpec file_spec(file_path, false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000510 return ResolveSymbolContextsForFileSpec (file_spec, line, check_inlines, resolve_scope, sc_list);
511}
512
513uint32_t
514Module::ResolveSymbolContextsForFileSpec (const FileSpec &file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list)
515{
516 Mutex::Locker locker (m_mutex);
517 Timer scoped_timer(__PRETTY_FUNCTION__,
Greg Claytonb5ad4ec2013-04-29 17:25:54 +0000518 "Module::ResolveSymbolContextForFilePath (%s:%u, check_inlines = %s, resolve_scope = 0x%8.8x)",
519 file_spec.GetPath().c_str(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000520 line,
521 check_inlines ? "yes" : "no",
522 resolve_scope);
523
524 const uint32_t initial_count = sc_list.GetSize();
525
526 SymbolVendor *symbols = GetSymbolVendor ();
527 if (symbols)
528 symbols->ResolveSymbolContext (file_spec, line, check_inlines, resolve_scope, sc_list);
529
530 return sc_list.GetSize() - initial_count;
531}
532
533
Greg Claytonc7bece562013-01-25 18:06:21 +0000534size_t
535Module::FindGlobalVariables (const ConstString &name,
536 const ClangNamespaceDecl *namespace_decl,
537 bool append,
538 size_t max_matches,
539 VariableList& variables)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000540{
541 SymbolVendor *symbols = GetSymbolVendor ();
542 if (symbols)
Sean Callanan213fdb82011-10-13 01:49:10 +0000543 return symbols->FindGlobalVariables(name, namespace_decl, append, max_matches, variables);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000544 return 0;
545}
Greg Claytonc7bece562013-01-25 18:06:21 +0000546
547size_t
548Module::FindGlobalVariables (const RegularExpression& regex,
549 bool append,
550 size_t max_matches,
551 VariableList& variables)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000552{
553 SymbolVendor *symbols = GetSymbolVendor ();
554 if (symbols)
555 return symbols->FindGlobalVariables(regex, append, max_matches, variables);
556 return 0;
557}
558
Greg Claytonc7bece562013-01-25 18:06:21 +0000559size_t
Greg Clayton644247c2011-07-07 01:59:51 +0000560Module::FindCompileUnits (const FileSpec &path,
561 bool append,
562 SymbolContextList &sc_list)
563{
564 if (!append)
565 sc_list.Clear();
566
Greg Claytonc7bece562013-01-25 18:06:21 +0000567 const size_t start_size = sc_list.GetSize();
568 const size_t num_compile_units = GetNumCompileUnits();
Greg Clayton644247c2011-07-07 01:59:51 +0000569 SymbolContext sc;
Greg Claytone1cd1be2012-01-29 20:56:30 +0000570 sc.module_sp = shared_from_this();
Greg Clayton644247c2011-07-07 01:59:51 +0000571 const bool compare_directory = path.GetDirectory();
Greg Claytonc7bece562013-01-25 18:06:21 +0000572 for (size_t i=0; i<num_compile_units; ++i)
Greg Clayton644247c2011-07-07 01:59:51 +0000573 {
574 sc.comp_unit = GetCompileUnitAtIndex(i).get();
Greg Clayton2dafd8e2012-04-23 22:00:21 +0000575 if (sc.comp_unit)
576 {
577 if (FileSpec::Equal (*sc.comp_unit, path, compare_directory))
578 sc_list.Append(sc);
579 }
Greg Clayton644247c2011-07-07 01:59:51 +0000580 }
581 return sc_list.GetSize() - start_size;
582}
583
Greg Claytonc7bece562013-01-25 18:06:21 +0000584size_t
Sean Callananb6d70eb2011-10-12 02:08:07 +0000585Module::FindFunctions (const ConstString &name,
586 const ClangNamespaceDecl *namespace_decl,
Greg Claytonc7bece562013-01-25 18:06:21 +0000587 uint32_t name_type_mask,
Sean Callanan9df05fb2012-02-10 22:52:19 +0000588 bool include_symbols,
589 bool include_inlines,
Greg Clayton931180e2011-01-27 06:44:37 +0000590 bool append,
591 SymbolContextList& sc_list)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000592{
Greg Clayton931180e2011-01-27 06:44:37 +0000593 if (!append)
594 sc_list.Clear();
595
Greg Clayton43fe2172013-04-03 02:00:15 +0000596 const size_t old_size = sc_list.GetSize();
Greg Clayton931180e2011-01-27 06:44:37 +0000597
598 // Find all the functions (not symbols, but debug information functions...
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000599 SymbolVendor *symbols = GetSymbolVendor ();
Greg Clayton43fe2172013-04-03 02:00:15 +0000600
601 if (name_type_mask & eFunctionNameTypeAuto)
Greg Clayton931180e2011-01-27 06:44:37 +0000602 {
Greg Clayton43fe2172013-04-03 02:00:15 +0000603 ConstString lookup_name;
604 uint32_t lookup_name_type_mask = 0;
605 bool match_name_after_lookup = false;
606 Module::PrepareForFunctionNameLookup (name,
607 name_type_mask,
608 lookup_name,
609 lookup_name_type_mask,
610 match_name_after_lookup);
611
612 if (symbols)
613 symbols->FindFunctions(lookup_name,
614 namespace_decl,
615 lookup_name_type_mask,
616 include_inlines,
617 append,
618 sc_list);
619
620 // Now check our symbol table for symbols that are code symbols if requested
621 if (include_symbols)
Greg Clayton931180e2011-01-27 06:44:37 +0000622 {
Greg Clayton43fe2172013-04-03 02:00:15 +0000623 ObjectFile *objfile = GetObjectFile();
624 if (objfile)
Greg Clayton931180e2011-01-27 06:44:37 +0000625 {
Greg Clayton43fe2172013-04-03 02:00:15 +0000626 Symtab *symtab = objfile->GetSymtab();
627 if (symtab)
628 symtab->FindFunctionSymbols(lookup_name, lookup_name_type_mask, sc_list);
629 }
630 }
631
632 if (match_name_after_lookup)
633 {
634 SymbolContext sc;
635 size_t i = old_size;
636 while (i<sc_list.GetSize())
637 {
638 if (sc_list.GetContextAtIndex(i, sc))
Greg Clayton931180e2011-01-27 06:44:37 +0000639 {
Greg Clayton43fe2172013-04-03 02:00:15 +0000640 const char *func_name = sc.GetFunctionName().GetCString();
641 if (func_name && strstr (func_name, name.GetCString()) == NULL)
Greg Clayton931180e2011-01-27 06:44:37 +0000642 {
Greg Clayton43fe2172013-04-03 02:00:15 +0000643 // Remove the current context
644 sc_list.RemoveContextAtIndex(i);
645 // Don't increment i and continue in the loop
646 continue;
Greg Clayton931180e2011-01-27 06:44:37 +0000647 }
648 }
Greg Clayton43fe2172013-04-03 02:00:15 +0000649 ++i;
650 }
651 }
652
653 }
654 else
655 {
656 if (symbols)
657 symbols->FindFunctions(name, namespace_decl, name_type_mask, include_inlines, append, sc_list);
658
659 // Now check our symbol table for symbols that are code symbols if requested
660 if (include_symbols)
661 {
662 ObjectFile *objfile = GetObjectFile();
663 if (objfile)
664 {
665 Symtab *symtab = objfile->GetSymtab();
666 if (symtab)
667 symtab->FindFunctionSymbols(name, name_type_mask, sc_list);
Greg Clayton931180e2011-01-27 06:44:37 +0000668 }
669 }
670 }
Greg Clayton43fe2172013-04-03 02:00:15 +0000671
672 return sc_list.GetSize() - old_size;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000673}
674
Greg Claytonc7bece562013-01-25 18:06:21 +0000675size_t
Greg Clayton931180e2011-01-27 06:44:37 +0000676Module::FindFunctions (const RegularExpression& regex,
Sean Callanan9df05fb2012-02-10 22:52:19 +0000677 bool include_symbols,
678 bool include_inlines,
Greg Clayton931180e2011-01-27 06:44:37 +0000679 bool append,
680 SymbolContextList& sc_list)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000681{
Greg Clayton931180e2011-01-27 06:44:37 +0000682 if (!append)
683 sc_list.Clear();
684
Greg Claytonc7bece562013-01-25 18:06:21 +0000685 const size_t start_size = sc_list.GetSize();
Greg Clayton931180e2011-01-27 06:44:37 +0000686
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000687 SymbolVendor *symbols = GetSymbolVendor ();
688 if (symbols)
Sean Callanan9df05fb2012-02-10 22:52:19 +0000689 symbols->FindFunctions(regex, include_inlines, append, sc_list);
Greg Clayton931180e2011-01-27 06:44:37 +0000690 // Now check our symbol table for symbols that are code symbols if requested
691 if (include_symbols)
692 {
693 ObjectFile *objfile = GetObjectFile();
694 if (objfile)
695 {
696 Symtab *symtab = objfile->GetSymtab();
697 if (symtab)
698 {
699 std::vector<uint32_t> symbol_indexes;
Matt Kopec00049b82013-02-27 20:13:38 +0000700 symtab->AppendSymbolIndexesMatchingRegExAndType (regex, eSymbolTypeAny, Symtab::eDebugAny, Symtab::eVisibilityAny, symbol_indexes);
Greg Claytonc7bece562013-01-25 18:06:21 +0000701 const size_t num_matches = symbol_indexes.size();
Greg Clayton931180e2011-01-27 06:44:37 +0000702 if (num_matches)
703 {
Greg Clayton357132e2011-03-26 19:14:58 +0000704 const bool merge_symbol_into_function = true;
Greg Clayton931180e2011-01-27 06:44:37 +0000705 SymbolContext sc(this);
Greg Claytonc7bece562013-01-25 18:06:21 +0000706 for (size_t i=0; i<num_matches; i++)
Greg Clayton931180e2011-01-27 06:44:37 +0000707 {
708 sc.symbol = symtab->SymbolAtIndex(symbol_indexes[i]);
Matt Kopec00049b82013-02-27 20:13:38 +0000709 SymbolType sym_type = sc.symbol->GetType();
710 if (sc.symbol && (sym_type == eSymbolTypeCode ||
711 sym_type == eSymbolTypeResolver))
712 sc_list.AppendIfUnique (sc, merge_symbol_into_function);
Greg Clayton931180e2011-01-27 06:44:37 +0000713 }
714 }
715 }
716 }
717 }
718 return sc_list.GetSize() - start_size;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000719}
720
Greg Claytonc7bece562013-01-25 18:06:21 +0000721size_t
Greg Clayton84db9102012-03-26 23:03:23 +0000722Module::FindTypes_Impl (const SymbolContext& sc,
723 const ConstString &name,
724 const ClangNamespaceDecl *namespace_decl,
725 bool append,
Greg Claytonc7bece562013-01-25 18:06:21 +0000726 size_t max_matches,
Greg Clayton84db9102012-03-26 23:03:23 +0000727 TypeList& types)
Greg Clayton3504eee2010-08-03 01:26:16 +0000728{
729 Timer scoped_timer(__PRETTY_FUNCTION__, __PRETTY_FUNCTION__);
730 if (sc.module_sp.get() == NULL || sc.module_sp.get() == this)
731 {
732 SymbolVendor *symbols = GetSymbolVendor ();
733 if (symbols)
Sean Callanan213fdb82011-10-13 01:49:10 +0000734 return symbols->FindTypes(sc, name, namespace_decl, append, max_matches, types);
Greg Clayton3504eee2010-08-03 01:26:16 +0000735 }
736 return 0;
737}
738
Greg Claytonc7bece562013-01-25 18:06:21 +0000739size_t
Greg Clayton84db9102012-03-26 23:03:23 +0000740Module::FindTypesInNamespace (const SymbolContext& sc,
741 const ConstString &type_name,
742 const ClangNamespaceDecl *namespace_decl,
Greg Claytonc7bece562013-01-25 18:06:21 +0000743 size_t max_matches,
Greg Clayton84db9102012-03-26 23:03:23 +0000744 TypeList& type_list)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000745{
Greg Clayton84db9102012-03-26 23:03:23 +0000746 const bool append = true;
747 return FindTypes_Impl(sc, type_name, namespace_decl, append, max_matches, type_list);
Enrico Granata6f3533f2011-07-29 19:53:35 +0000748}
749
Greg Claytonb43165b2012-12-05 21:24:42 +0000750lldb::TypeSP
751Module::FindFirstType (const SymbolContext& sc,
752 const ConstString &name,
753 bool exact_match)
754{
755 TypeList type_list;
Greg Claytonc7bece562013-01-25 18:06:21 +0000756 const size_t num_matches = FindTypes (sc, name, exact_match, 1, type_list);
Greg Claytonb43165b2012-12-05 21:24:42 +0000757 if (num_matches)
758 return type_list.GetTypeAtIndex(0);
759 return TypeSP();
760}
761
762
Greg Claytonc7bece562013-01-25 18:06:21 +0000763size_t
Greg Clayton84db9102012-03-26 23:03:23 +0000764Module::FindTypes (const SymbolContext& sc,
765 const ConstString &name,
766 bool exact_match,
Greg Claytonc7bece562013-01-25 18:06:21 +0000767 size_t max_matches,
Greg Clayton84db9102012-03-26 23:03:23 +0000768 TypeList& types)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000769{
Greg Claytonc7bece562013-01-25 18:06:21 +0000770 size_t num_matches = 0;
Greg Clayton84db9102012-03-26 23:03:23 +0000771 const char *type_name_cstr = name.GetCString();
772 std::string type_scope;
773 std::string type_basename;
774 const bool append = true;
Greg Clayton7bc31332012-10-22 16:19:56 +0000775 TypeClass type_class = eTypeClassAny;
776 if (Type::GetTypeScopeAndBasename (type_name_cstr, type_scope, type_basename, type_class))
Enrico Granata6f3533f2011-07-29 19:53:35 +0000777 {
Greg Clayton84db9102012-03-26 23:03:23 +0000778 // Check if "name" starts with "::" which means the qualified type starts
779 // from the root namespace and implies and exact match. The typenames we
780 // get back from clang do not start with "::" so we need to strip this off
781 // in order to get the qualfied names to match
782
783 if (type_scope.size() >= 2 && type_scope[0] == ':' && type_scope[1] == ':')
784 {
785 type_scope.erase(0,2);
786 exact_match = true;
787 }
788 ConstString type_basename_const_str (type_basename.c_str());
789 if (FindTypes_Impl(sc, type_basename_const_str, NULL, append, max_matches, types))
790 {
Greg Clayton7bc31332012-10-22 16:19:56 +0000791 types.RemoveMismatchedTypes (type_scope, type_basename, type_class, exact_match);
Greg Clayton84db9102012-03-26 23:03:23 +0000792 num_matches = types.GetSize();
793 }
Enrico Granata6f3533f2011-07-29 19:53:35 +0000794 }
795 else
Greg Clayton84db9102012-03-26 23:03:23 +0000796 {
797 // The type is not in a namespace/class scope, just search for it by basename
Greg Clayton7bc31332012-10-22 16:19:56 +0000798 if (type_class != eTypeClassAny)
799 {
800 // The "type_name_cstr" will have been modified if we have a valid type class
801 // prefix (like "struct", "class", "union", "typedef" etc).
802 num_matches = FindTypes_Impl(sc, ConstString(type_name_cstr), NULL, append, max_matches, types);
803 types.RemoveMismatchedTypes (type_class);
804 num_matches = types.GetSize();
805 }
806 else
807 {
808 num_matches = FindTypes_Impl(sc, name, NULL, append, max_matches, types);
809 }
Greg Clayton84db9102012-03-26 23:03:23 +0000810 }
811
812 return num_matches;
Enrico Granata6f3533f2011-07-29 19:53:35 +0000813
814}
815
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000816SymbolVendor*
Greg Clayton136dff82012-12-14 02:15:00 +0000817Module::GetSymbolVendor (bool can_create, lldb_private::Stream *feedback_strm)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000818{
819 Mutex::Locker locker (m_mutex);
Greg Claytone83e7312010-09-07 23:40:05 +0000820 if (m_did_load_symbol_vendor == false && can_create)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000821 {
822 ObjectFile *obj_file = GetObjectFile ();
823 if (obj_file != NULL)
824 {
825 Timer scoped_timer(__PRETTY_FUNCTION__, __PRETTY_FUNCTION__);
Greg Clayton136dff82012-12-14 02:15:00 +0000826 m_symfile_ap.reset(SymbolVendor::FindPlugin(shared_from_this(), feedback_strm));
Greg Claytone83e7312010-09-07 23:40:05 +0000827 m_did_load_symbol_vendor = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000828 }
829 }
830 return m_symfile_ap.get();
831}
832
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000833void
834Module::SetFileSpecAndObjectName (const FileSpec &file, const ConstString &object_name)
835{
836 // Container objects whose paths do not specify a file directly can call
837 // this function to correct the file and object names.
838 m_file = file;
839 m_mod_time = file.GetModificationTime();
840 m_object_name = object_name;
841}
842
843const ArchSpec&
844Module::GetArchitecture () const
845{
846 return m_arch;
847}
848
Greg Claytonb5ad4ec2013-04-29 17:25:54 +0000849std::string
850Module::GetSpecificationDescription () const
851{
852 std::string spec(GetFileSpec().GetPath());
853 if (m_object_name)
854 {
855 spec += '(';
856 spec += m_object_name.GetCString();
857 spec += ')';
858 }
859 return spec;
860}
861
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000862void
Greg Claytonc982b3d2011-11-28 01:45:00 +0000863Module::GetDescription (Stream *s, lldb::DescriptionLevel level)
Caroline Ticeceb6b132010-10-26 03:11:13 +0000864{
865 Mutex::Locker locker (m_mutex);
866
Greg Claytonc982b3d2011-11-28 01:45:00 +0000867 if (level >= eDescriptionLevelFull)
868 {
869 if (m_arch.IsValid())
870 s->Printf("(%s) ", m_arch.GetArchitectureName());
871 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000872
Greg Claytonc982b3d2011-11-28 01:45:00 +0000873 if (level == eDescriptionLevelBrief)
874 {
875 const char *filename = m_file.GetFilename().GetCString();
876 if (filename)
877 s->PutCString (filename);
878 }
879 else
880 {
881 char path[PATH_MAX];
882 if (m_file.GetPath(path, sizeof(path)))
883 s->PutCString(path);
884 }
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000885
886 const char *object_name = m_object_name.GetCString();
887 if (object_name)
888 s->Printf("(%s)", object_name);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000889}
890
891void
Greg Claytonc982b3d2011-11-28 01:45:00 +0000892Module::ReportError (const char *format, ...)
893{
Greg Claytone38a5ed2012-01-05 03:57:59 +0000894 if (format && format[0])
895 {
896 StreamString strm;
897 strm.PutCString("error: ");
898 GetDescription(&strm, lldb::eDescriptionLevelBrief);
Greg Clayton8b353342012-01-11 01:59:18 +0000899 strm.PutChar (' ');
Greg Claytone38a5ed2012-01-05 03:57:59 +0000900 va_list args;
901 va_start (args, format);
902 strm.PrintfVarArg(format, args);
903 va_end (args);
904
905 const int format_len = strlen(format);
906 if (format_len > 0)
907 {
908 const char last_char = format[format_len-1];
909 if (last_char != '\n' || last_char != '\r')
910 strm.EOL();
911 }
912 Host::SystemLog (Host::eSystemLogError, "%s", strm.GetString().c_str());
913
914 }
915}
916
Greg Clayton1d609092012-07-12 22:51:12 +0000917bool
918Module::FileHasChanged () const
919{
920 if (m_file_has_changed == false)
921 m_file_has_changed = (m_file.GetModificationTime() != m_mod_time);
922 return m_file_has_changed;
923}
924
Greg Claytone38a5ed2012-01-05 03:57:59 +0000925void
926Module::ReportErrorIfModifyDetected (const char *format, ...)
927{
Greg Clayton1d609092012-07-12 22:51:12 +0000928 if (m_first_file_changed_log == false)
Greg Claytone38a5ed2012-01-05 03:57:59 +0000929 {
Greg Clayton1d609092012-07-12 22:51:12 +0000930 if (FileHasChanged ())
Greg Claytone38a5ed2012-01-05 03:57:59 +0000931 {
Greg Clayton1d609092012-07-12 22:51:12 +0000932 m_first_file_changed_log = true;
933 if (format)
Greg Claytone38a5ed2012-01-05 03:57:59 +0000934 {
Greg Clayton1d609092012-07-12 22:51:12 +0000935 StreamString strm;
936 strm.PutCString("error: the object file ");
937 GetDescription(&strm, lldb::eDescriptionLevelFull);
938 strm.PutCString (" has been modified\n");
939
940 va_list args;
941 va_start (args, format);
942 strm.PrintfVarArg(format, args);
943 va_end (args);
944
945 const int format_len = strlen(format);
946 if (format_len > 0)
947 {
948 const char last_char = format[format_len-1];
949 if (last_char != '\n' || last_char != '\r')
950 strm.EOL();
951 }
952 strm.PutCString("The debug session should be aborted as the original debug information has been overwritten.\n");
953 Host::SystemLog (Host::eSystemLogError, "%s", strm.GetString().c_str());
Greg Claytone38a5ed2012-01-05 03:57:59 +0000954 }
Greg Claytone38a5ed2012-01-05 03:57:59 +0000955 }
956 }
Greg Claytonc982b3d2011-11-28 01:45:00 +0000957}
958
959void
960Module::ReportWarning (const char *format, ...)
961{
Greg Claytone38a5ed2012-01-05 03:57:59 +0000962 if (format && format[0])
963 {
964 StreamString strm;
965 strm.PutCString("warning: ");
Greg Clayton8b353342012-01-11 01:59:18 +0000966 GetDescription(&strm, lldb::eDescriptionLevelFull);
967 strm.PutChar (' ');
Greg Claytone38a5ed2012-01-05 03:57:59 +0000968
969 va_list args;
970 va_start (args, format);
971 strm.PrintfVarArg(format, args);
972 va_end (args);
973
974 const int format_len = strlen(format);
975 if (format_len > 0)
976 {
977 const char last_char = format[format_len-1];
978 if (last_char != '\n' || last_char != '\r')
979 strm.EOL();
980 }
981 Host::SystemLog (Host::eSystemLogWarning, "%s", strm.GetString().c_str());
982 }
Greg Claytonc982b3d2011-11-28 01:45:00 +0000983}
984
985void
986Module::LogMessage (Log *log, const char *format, ...)
987{
988 if (log)
989 {
990 StreamString log_message;
Greg Clayton8b353342012-01-11 01:59:18 +0000991 GetDescription(&log_message, lldb::eDescriptionLevelFull);
Greg Claytonc982b3d2011-11-28 01:45:00 +0000992 log_message.PutCString (": ");
993 va_list args;
994 va_start (args, format);
995 log_message.PrintfVarArg (format, args);
996 va_end (args);
997 log->PutCString(log_message.GetString().c_str());
998 }
999}
1000
Greg Claytond61c0fc2012-04-23 22:55:20 +00001001void
1002Module::LogMessageVerboseBacktrace (Log *log, const char *format, ...)
1003{
1004 if (log)
1005 {
1006 StreamString log_message;
1007 GetDescription(&log_message, lldb::eDescriptionLevelFull);
1008 log_message.PutCString (": ");
1009 va_list args;
1010 va_start (args, format);
1011 log_message.PrintfVarArg (format, args);
1012 va_end (args);
1013 if (log->GetVerbose())
1014 Host::Backtrace (log_message, 1024);
1015 log->PutCString(log_message.GetString().c_str());
1016 }
1017}
1018
Greg Claytonc982b3d2011-11-28 01:45:00 +00001019void
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001020Module::Dump(Stream *s)
1021{
1022 Mutex::Locker locker (m_mutex);
Greg Clayton89411422010-10-08 00:21:05 +00001023 //s->Printf("%.*p: ", (int)sizeof(void*) * 2, this);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001024 s->Indent();
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00001025 s->Printf("Module %s%s%s%s\n",
1026 m_file.GetPath().c_str(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001027 m_object_name ? "(" : "",
1028 m_object_name ? m_object_name.GetCString() : "",
1029 m_object_name ? ")" : "");
1030
1031 s->IndentMore();
1032 ObjectFile *objfile = GetObjectFile ();
1033
1034 if (objfile)
1035 objfile->Dump(s);
1036
1037 SymbolVendor *symbols = GetSymbolVendor ();
1038
1039 if (symbols)
1040 symbols->Dump(s);
1041
1042 s->IndentLess();
1043}
1044
1045
1046TypeList*
1047Module::GetTypeList ()
1048{
1049 SymbolVendor *symbols = GetSymbolVendor ();
1050 if (symbols)
1051 return &symbols->GetTypeList();
1052 return NULL;
1053}
1054
1055const ConstString &
1056Module::GetObjectName() const
1057{
1058 return m_object_name;
1059}
1060
1061ObjectFile *
1062Module::GetObjectFile()
1063{
1064 Mutex::Locker locker (m_mutex);
Greg Claytone83e7312010-09-07 23:40:05 +00001065 if (m_did_load_objfile == false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001066 {
Greg Claytone83e7312010-09-07 23:40:05 +00001067 m_did_load_objfile = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001068 Timer scoped_timer(__PRETTY_FUNCTION__,
1069 "Module::GetObjectFile () module = %s", GetFileSpec().GetFilename().AsCString(""));
Greg Clayton5ce9c562013-02-06 17:22:03 +00001070 DataBufferSP data_sp;
1071 lldb::offset_t data_offset = 0;
1072 m_objfile_sp = ObjectFile::FindPlugin (shared_from_this(),
Greg Claytone72dfb32012-02-24 01:59:29 +00001073 &m_file,
1074 m_object_offset,
1075 m_file.GetByteSize(),
Greg Clayton5ce9c562013-02-06 17:22:03 +00001076 data_sp,
1077 data_offset);
Greg Clayton593577a2011-09-21 03:57:31 +00001078 if (m_objfile_sp)
1079 {
1080 // Once we get the object file, update our module with the object file's
1081 // architecture since it might differ in vendor/os if some parts were
1082 // unknown.
1083 m_objfile_sp->GetArchitecture (m_arch);
1084 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001085 }
Greg Clayton762f7132011-09-18 18:59:15 +00001086 return m_objfile_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001087}
1088
1089
1090const Symbol *
1091Module::FindFirstSymbolWithNameAndType (const ConstString &name, SymbolType symbol_type)
1092{
1093 Timer scoped_timer(__PRETTY_FUNCTION__,
1094 "Module::FindFirstSymbolWithNameAndType (name = %s, type = %i)",
1095 name.AsCString(),
1096 symbol_type);
1097 ObjectFile *objfile = GetObjectFile();
1098 if (objfile)
1099 {
1100 Symtab *symtab = objfile->GetSymtab();
1101 if (symtab)
Greg Claytonbcf2cfb2010-09-11 03:13:28 +00001102 return symtab->FindFirstSymbolWithNameAndType (name, symbol_type, Symtab::eDebugAny, Symtab::eVisibilityAny);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001103 }
1104 return NULL;
1105}
1106void
1107Module::SymbolIndicesToSymbolContextList (Symtab *symtab, std::vector<uint32_t> &symbol_indexes, SymbolContextList &sc_list)
1108{
1109 // No need to protect this call using m_mutex all other method calls are
1110 // already thread safe.
1111
1112 size_t num_indices = symbol_indexes.size();
1113 if (num_indices > 0)
1114 {
1115 SymbolContext sc;
1116 CalculateSymbolContext (&sc);
1117 for (size_t i = 0; i < num_indices; i++)
1118 {
1119 sc.symbol = symtab->SymbolAtIndex (symbol_indexes[i]);
1120 if (sc.symbol)
1121 sc_list.Append (sc);
1122 }
1123 }
1124}
1125
1126size_t
Greg Claytonc1b2ccf2013-01-08 00:01:36 +00001127Module::FindFunctionSymbols (const ConstString &name,
1128 uint32_t name_type_mask,
1129 SymbolContextList& sc_list)
1130{
1131 Timer scoped_timer(__PRETTY_FUNCTION__,
1132 "Module::FindSymbolsFunctions (name = %s, mask = 0x%8.8x)",
1133 name.AsCString(),
1134 name_type_mask);
1135 ObjectFile *objfile = GetObjectFile ();
1136 if (objfile)
1137 {
1138 Symtab *symtab = objfile->GetSymtab();
1139 if (symtab)
1140 return symtab->FindFunctionSymbols (name, name_type_mask, sc_list);
1141 }
1142 return 0;
1143}
1144
1145size_t
Sean Callananb96ff332011-10-13 16:49:47 +00001146Module::FindSymbolsWithNameAndType (const ConstString &name, SymbolType symbol_type, SymbolContextList &sc_list)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001147{
1148 // No need to protect this call using m_mutex all other method calls are
1149 // already thread safe.
1150
1151
1152 Timer scoped_timer(__PRETTY_FUNCTION__,
1153 "Module::FindSymbolsWithNameAndType (name = %s, type = %i)",
1154 name.AsCString(),
1155 symbol_type);
1156 const size_t initial_size = sc_list.GetSize();
1157 ObjectFile *objfile = GetObjectFile ();
1158 if (objfile)
1159 {
1160 Symtab *symtab = objfile->GetSymtab();
1161 if (symtab)
1162 {
1163 std::vector<uint32_t> symbol_indexes;
1164 symtab->FindAllSymbolsWithNameAndType (name, symbol_type, symbol_indexes);
1165 SymbolIndicesToSymbolContextList (symtab, symbol_indexes, sc_list);
1166 }
1167 }
1168 return sc_list.GetSize() - initial_size;
1169}
1170
1171size_t
1172Module::FindSymbolsMatchingRegExAndType (const RegularExpression &regex, SymbolType symbol_type, SymbolContextList &sc_list)
1173{
1174 // No need to protect this call using m_mutex all other method calls are
1175 // already thread safe.
1176
1177 Timer scoped_timer(__PRETTY_FUNCTION__,
1178 "Module::FindSymbolsMatchingRegExAndType (regex = %s, type = %i)",
1179 regex.GetText(),
1180 symbol_type);
1181 const size_t initial_size = sc_list.GetSize();
1182 ObjectFile *objfile = GetObjectFile ();
1183 if (objfile)
1184 {
1185 Symtab *symtab = objfile->GetSymtab();
1186 if (symtab)
1187 {
1188 std::vector<uint32_t> symbol_indexes;
Greg Claytonbcf2cfb2010-09-11 03:13:28 +00001189 symtab->FindAllSymbolsMatchingRexExAndType (regex, symbol_type, Symtab::eDebugAny, Symtab::eVisibilityAny, symbol_indexes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001190 SymbolIndicesToSymbolContextList (symtab, symbol_indexes, sc_list);
1191 }
1192 }
1193 return sc_list.GetSize() - initial_size;
1194}
1195
Greg Claytone01e07b2013-04-18 18:10:51 +00001196void
1197Module::SetSymbolFileFileSpec (const FileSpec &file)
1198{
1199 m_symfile_spec = file;
1200 m_symfile_ap.reset();
1201 m_did_load_symbol_vendor = false;
1202}
1203
1204
Jim Ingham5aee1622010-08-09 23:31:02 +00001205bool
1206Module::IsExecutable ()
1207{
1208 if (GetObjectFile() == NULL)
1209 return false;
1210 else
1211 return GetObjectFile()->IsExecutable();
1212}
1213
Jim Inghamb53cb272011-08-03 01:03:17 +00001214bool
1215Module::IsLoadedInTarget (Target *target)
1216{
1217 ObjectFile *obj_file = GetObjectFile();
1218 if (obj_file)
1219 {
1220 SectionList *sections = obj_file->GetSectionList();
1221 if (sections != NULL)
1222 {
1223 size_t num_sections = sections->GetSize();
Jim Inghamb53cb272011-08-03 01:03:17 +00001224 for (size_t sect_idx = 0; sect_idx < num_sections; sect_idx++)
1225 {
1226 SectionSP section_sp = sections->GetSectionAtIndex(sect_idx);
1227 if (section_sp->GetLoadBaseAddress(target) != LLDB_INVALID_ADDRESS)
1228 {
1229 return true;
1230 }
1231 }
1232 }
1233 }
1234 return false;
1235}
Enrico Granata17598482012-11-08 02:22:02 +00001236
1237bool
Enrico Granata97303392013-05-21 00:00:30 +00001238Module::LoadScriptingResourceInTarget (Target *target, Error& error, Stream* feedback_stream)
Enrico Granata17598482012-11-08 02:22:02 +00001239{
1240 if (!target)
1241 {
1242 error.SetErrorString("invalid destination Target");
1243 return false;
1244 }
1245
Enrico Granata97303392013-05-21 00:00:30 +00001246 bool shoud_load = target->TargetProperties::GetLoadScriptFromSymbolFile();
1247 bool should_warn = target->TargetProperties::GetWarnForScriptInSymbolFile();
Enrico Granata2ea43cd2013-05-13 17:03:52 +00001248
Greg Clayton91c0e742013-01-11 23:44:27 +00001249 Debugger &debugger = target->GetDebugger();
1250 const ScriptLanguage script_language = debugger.GetScriptLanguage();
1251 if (script_language != eScriptLanguageNone)
Enrico Granata17598482012-11-08 02:22:02 +00001252 {
Greg Clayton91c0e742013-01-11 23:44:27 +00001253
1254 PlatformSP platform_sp(target->GetPlatform());
1255
1256 if (!platform_sp)
1257 {
1258 error.SetErrorString("invalid Platform");
1259 return false;
1260 }
Enrico Granata17598482012-11-08 02:22:02 +00001261
Greg Claytonb9d88902013-03-23 00:50:58 +00001262 FileSpecList file_specs = platform_sp->LocateExecutableScriptingResources (target,
1263 *this);
1264
1265
1266 const uint32_t num_specs = file_specs.GetSize();
1267 if (num_specs)
Enrico Granata17598482012-11-08 02:22:02 +00001268 {
Greg Claytonb9d88902013-03-23 00:50:58 +00001269 ScriptInterpreter *script_interpreter = debugger.GetCommandInterpreter().GetScriptInterpreter();
1270 if (script_interpreter)
Greg Clayton91c0e742013-01-11 23:44:27 +00001271 {
1272 for (uint32_t i=0; i<num_specs; ++i)
1273 {
1274 FileSpec scripting_fspec (file_specs.GetFileSpecAtIndex(i));
1275 if (scripting_fspec && scripting_fspec.Exists())
1276 {
Enrico Granata97303392013-05-21 00:00:30 +00001277 if (shoud_load == false)
Enrico Granata2ea43cd2013-05-13 17:03:52 +00001278 {
Enrico Granata97303392013-05-21 00:00:30 +00001279 if (should_warn == true && feedback_stream)
1280 feedback_stream->Printf("warning: the debug info scripting resource for '%s' was not loaded for security reasons. to override, set the \"target.load-script-from-symbol-file\" setting to true or manually run \"command script import %s\"\n",GetFileSpec().GetFileNameStrippingExtension().GetCString(),scripting_fspec.GetPath().c_str());
Enrico Granata2ea43cd2013-05-13 17:03:52 +00001281 return false;
1282 }
Greg Clayton91c0e742013-01-11 23:44:27 +00001283 StreamString scripting_stream;
1284 scripting_fspec.Dump(&scripting_stream);
1285 const bool can_reload = false;
1286 const bool init_lldb_globals = false;
1287 bool did_load = script_interpreter->LoadScriptingModule(scripting_stream.GetData(), can_reload, init_lldb_globals, error);
1288 if (!did_load)
1289 return false;
1290 }
1291 }
1292 }
Greg Claytonb9d88902013-03-23 00:50:58 +00001293 else
1294 {
1295 error.SetErrorString("invalid ScriptInterpreter");
1296 return false;
1297 }
Enrico Granata17598482012-11-08 02:22:02 +00001298 }
1299 }
1300 return true;
1301}
1302
1303bool
Jim Ingham5aee1622010-08-09 23:31:02 +00001304Module::SetArchitecture (const ArchSpec &new_arch)
1305{
Greg Clayton64195a22011-02-23 00:35:02 +00001306 if (!m_arch.IsValid())
Jim Ingham5aee1622010-08-09 23:31:02 +00001307 {
1308 m_arch = new_arch;
1309 return true;
Greg Clayton64195a22011-02-23 00:35:02 +00001310 }
Sean Callananbf4b7be2012-12-13 22:07:14 +00001311 return m_arch.IsExactMatch(new_arch);
Jim Ingham5aee1622010-08-09 23:31:02 +00001312}
1313
Greg Claytonc9660542012-02-05 02:38:54 +00001314bool
1315Module::SetLoadAddress (Target &target, lldb::addr_t offset, bool &changed)
1316{
Greg Clayton741f3f92012-03-27 21:10:07 +00001317 size_t num_loaded_sections = 0;
1318 ObjectFile *objfile = GetObjectFile();
1319 if (objfile)
Greg Claytonc9660542012-02-05 02:38:54 +00001320 {
Greg Clayton741f3f92012-03-27 21:10:07 +00001321 SectionList *section_list = objfile->GetSectionList ();
Greg Claytonc9660542012-02-05 02:38:54 +00001322 if (section_list)
1323 {
1324 const size_t num_sections = section_list->GetSize();
1325 size_t sect_idx = 0;
1326 for (sect_idx = 0; sect_idx < num_sections; ++sect_idx)
1327 {
1328 // Iterate through the object file sections to find the
1329 // first section that starts of file offset zero and that
1330 // has bytes in the file...
Greg Clayton7820bd12012-07-07 01:24:12 +00001331 SectionSP section_sp (section_list->GetSectionAtIndex (sect_idx));
Greg Clayton741f3f92012-03-27 21:10:07 +00001332 // Only load non-thread specific sections when given a slide
Greg Clayton7820bd12012-07-07 01:24:12 +00001333 if (section_sp && !section_sp->IsThreadSpecific())
Greg Claytonc9660542012-02-05 02:38:54 +00001334 {
Greg Clayton7820bd12012-07-07 01:24:12 +00001335 if (target.GetSectionLoadList().SetSectionLoadAddress (section_sp, section_sp->GetFileAddress() + offset))
Greg Clayton741f3f92012-03-27 21:10:07 +00001336 ++num_loaded_sections;
Greg Claytonc9660542012-02-05 02:38:54 +00001337 }
1338 }
Greg Claytonc9660542012-02-05 02:38:54 +00001339 }
1340 }
Greg Clayton741f3f92012-03-27 21:10:07 +00001341 changed = num_loaded_sections > 0;
1342 return num_loaded_sections > 0;
Greg Claytonc9660542012-02-05 02:38:54 +00001343}
1344
Greg Claytonb9a01b32012-02-26 05:51:37 +00001345
1346bool
1347Module::MatchesModuleSpec (const ModuleSpec &module_ref)
1348{
1349 const UUID &uuid = module_ref.GetUUID();
1350
1351 if (uuid.IsValid())
1352 {
1353 // If the UUID matches, then nothing more needs to match...
1354 if (uuid == GetUUID())
1355 return true;
1356 else
1357 return false;
1358 }
1359
1360 const FileSpec &file_spec = module_ref.GetFileSpec();
1361 if (file_spec)
1362 {
1363 if (!FileSpec::Equal (file_spec, m_file, file_spec.GetDirectory()))
1364 return false;
1365 }
1366
1367 const FileSpec &platform_file_spec = module_ref.GetPlatformFileSpec();
1368 if (platform_file_spec)
1369 {
Greg Clayton548e9a32012-10-02 06:04:17 +00001370 if (!FileSpec::Equal (platform_file_spec, GetPlatformFileSpec (), platform_file_spec.GetDirectory()))
Greg Claytonb9a01b32012-02-26 05:51:37 +00001371 return false;
1372 }
1373
1374 const ArchSpec &arch = module_ref.GetArchitecture();
1375 if (arch.IsValid())
1376 {
Sean Callananbf4b7be2012-12-13 22:07:14 +00001377 if (!m_arch.IsCompatibleMatch(arch))
Greg Claytonb9a01b32012-02-26 05:51:37 +00001378 return false;
1379 }
1380
1381 const ConstString &object_name = module_ref.GetObjectName();
1382 if (object_name)
1383 {
1384 if (object_name != GetObjectName())
1385 return false;
1386 }
1387 return true;
1388}
1389
Greg Claytond804d282012-03-15 21:01:31 +00001390bool
1391Module::FindSourceFile (const FileSpec &orig_spec, FileSpec &new_spec) const
1392{
1393 Mutex::Locker locker (m_mutex);
1394 return m_source_mappings.FindFile (orig_spec, new_spec);
1395}
1396
Greg Claytonf9be6932012-03-19 22:22:41 +00001397bool
1398Module::RemapSourceFile (const char *path, std::string &new_path) const
1399{
1400 Mutex::Locker locker (m_mutex);
1401 return m_source_mappings.RemapPath(path, new_path);
1402}
1403
Enrico Granata3467d802012-09-04 18:47:54 +00001404uint32_t
1405Module::GetVersion (uint32_t *versions, uint32_t num_versions)
1406{
1407 ObjectFile *obj_file = GetObjectFile();
1408 if (obj_file)
1409 return obj_file->GetVersion (versions, num_versions);
1410
1411 if (versions && num_versions)
1412 {
1413 for (uint32_t i=0; i<num_versions; ++i)
1414 versions[i] = UINT32_MAX;
1415 }
1416 return 0;
1417}
Greg Clayton43fe2172013-04-03 02:00:15 +00001418
1419void
1420Module::PrepareForFunctionNameLookup (const ConstString &name,
1421 uint32_t name_type_mask,
1422 ConstString &lookup_name,
1423 uint32_t &lookup_name_type_mask,
1424 bool &match_name_after_lookup)
1425{
1426 const char *name_cstr = name.GetCString();
1427 lookup_name_type_mask = eFunctionNameTypeNone;
1428 match_name_after_lookup = false;
1429 const char *base_name_start = NULL;
1430 const char *base_name_end = NULL;
1431
1432 if (name_type_mask & eFunctionNameTypeAuto)
1433 {
1434 if (CPPLanguageRuntime::IsCPPMangledName (name_cstr))
1435 lookup_name_type_mask = eFunctionNameTypeFull;
1436 else if (ObjCLanguageRuntime::IsPossibleObjCMethodName (name_cstr))
1437 lookup_name_type_mask = eFunctionNameTypeFull;
1438 else
1439 {
1440 if (ObjCLanguageRuntime::IsPossibleObjCSelector(name_cstr))
1441 lookup_name_type_mask |= eFunctionNameTypeSelector;
1442
Greg Clayton6ecb2322013-05-18 00:11:21 +00001443 CPPLanguageRuntime::MethodName cpp_method (name);
1444 llvm::StringRef basename (cpp_method.GetBasename());
1445 if (basename.empty())
1446 {
1447 if (CPPLanguageRuntime::StripNamespacesFromVariableName (name_cstr, base_name_start, base_name_end))
1448 lookup_name_type_mask |= (eFunctionNameTypeMethod | eFunctionNameTypeBase);
1449 }
1450 else
1451 {
1452 base_name_start = basename.data();
1453 base_name_end = base_name_start + basename.size();
Greg Clayton43fe2172013-04-03 02:00:15 +00001454 lookup_name_type_mask |= (eFunctionNameTypeMethod | eFunctionNameTypeBase);
Greg Clayton6ecb2322013-05-18 00:11:21 +00001455 }
Greg Clayton43fe2172013-04-03 02:00:15 +00001456 }
1457 }
1458 else
1459 {
1460 lookup_name_type_mask = name_type_mask;
1461 if (lookup_name_type_mask & eFunctionNameTypeMethod || name_type_mask & eFunctionNameTypeBase)
1462 {
1463 // If they've asked for a CPP method or function name and it can't be that, we don't
1464 // even need to search for CPP methods or names.
Greg Clayton6ecb2322013-05-18 00:11:21 +00001465 CPPLanguageRuntime::MethodName cpp_method (name);
1466 if (cpp_method.IsValid())
Greg Clayton43fe2172013-04-03 02:00:15 +00001467 {
Greg Clayton6ecb2322013-05-18 00:11:21 +00001468 llvm::StringRef basename (cpp_method.GetBasename());
1469 base_name_start = basename.data();
1470 base_name_end = base_name_start + basename.size();
1471
1472 if (!cpp_method.GetQualifiers().empty())
1473 {
1474 // There is a "const" or other qualifer following the end of the fucntion parens,
1475 // this can't be a eFunctionNameTypeBase
1476 lookup_name_type_mask &= ~(eFunctionNameTypeBase);
1477 if (lookup_name_type_mask == eFunctionNameTypeNone)
1478 return;
1479 }
1480 }
1481 else
1482 {
1483 if (!CPPLanguageRuntime::StripNamespacesFromVariableName (name_cstr, base_name_start, base_name_end))
1484 {
1485 lookup_name_type_mask &= ~(eFunctionNameTypeMethod | eFunctionNameTypeBase);
1486 if (lookup_name_type_mask == eFunctionNameTypeNone)
1487 return;
1488 }
Greg Clayton43fe2172013-04-03 02:00:15 +00001489 }
1490 }
1491
1492 if (lookup_name_type_mask & eFunctionNameTypeSelector)
1493 {
1494 if (!ObjCLanguageRuntime::IsPossibleObjCSelector(name_cstr))
1495 {
1496 lookup_name_type_mask &= ~(eFunctionNameTypeSelector);
1497 if (lookup_name_type_mask == eFunctionNameTypeNone)
1498 return;
1499 }
1500 }
1501 }
1502
1503 if (base_name_start &&
1504 base_name_end &&
1505 base_name_start != name_cstr &&
1506 base_name_start < base_name_end)
1507 {
1508 // The name supplied was a partial C++ path like "a::count". In this case we want to do a
1509 // lookup on the basename "count" and then make sure any matching results contain "a::count"
1510 // so that it would match "b::a::count" and "a::count". This is why we set "match_name_after_lookup"
1511 // to true
1512 lookup_name.SetCStringWithLength(base_name_start, base_name_end - base_name_start);
1513 match_name_after_lookup = true;
1514 }
1515 else
1516 {
1517 // The name is already correct, just use the exact name as supplied, and we won't need
1518 // to check if any matches contain "name"
1519 lookup_name = name;
1520 match_name_after_lookup = false;
1521 }
1522}