blob: d394118cba7de6b93075e0c840133d0087aaa457 [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
Richard Mittonf86248d2013-09-12 02:20:34 +000012#include "lldb/Core/AddressResolverFileLine.h"
Enrico Granata17598482012-11-08 02:22:02 +000013#include "lldb/Core/Error.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000014#include "lldb/Core/Module.h"
Greg Claytonc9660542012-02-05 02:38:54 +000015#include "lldb/Core/DataBuffer.h"
16#include "lldb/Core/DataBufferHeap.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000017#include "lldb/Core/Log.h"
18#include "lldb/Core/ModuleList.h"
Greg Clayton1f746072012-08-29 21:13:06 +000019#include "lldb/Core/ModuleSpec.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000020#include "lldb/Core/RegularExpression.h"
Greg Clayton1f746072012-08-29 21:13:06 +000021#include "lldb/Core/Section.h"
Greg Claytonc982b3d2011-11-28 01:45:00 +000022#include "lldb/Core/StreamString.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000023#include "lldb/Core/Timer.h"
Greg Claytone38a5ed2012-01-05 03:57:59 +000024#include "lldb/Host/Host.h"
Enrico Granata17598482012-11-08 02:22:02 +000025#include "lldb/Host/Symbols.h"
26#include "lldb/Interpreter/CommandInterpreter.h"
27#include "lldb/Interpreter/ScriptInterpreter.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000028#include "lldb/lldb-private-log.h"
Zachary Turner88c6b622015-03-03 18:34:26 +000029#include "lldb/Symbol/ClangASTContext.h"
Greg Clayton1f746072012-08-29 21:13:06 +000030#include "lldb/Symbol/CompileUnit.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000031#include "lldb/Symbol/ObjectFile.h"
32#include "lldb/Symbol/SymbolContext.h"
33#include "lldb/Symbol/SymbolVendor.h"
Greg Clayton43fe2172013-04-03 02:00:15 +000034#include "lldb/Target/CPPLanguageRuntime.h"
35#include "lldb/Target/ObjCLanguageRuntime.h"
Greg Claytonc9660542012-02-05 02:38:54 +000036#include "lldb/Target/Process.h"
Greg Claytond5944cd2013-12-06 01:12:00 +000037#include "lldb/Target/SectionLoadList.h"
Greg Claytonc9660542012-02-05 02:38:54 +000038#include "lldb/Target/Target.h"
Michael Sartaina7499c92013-07-01 19:45:50 +000039#include "lldb/Symbol/SymbolFile.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000040
Greg Clayton23f8c952014-03-24 23:10:19 +000041#include "Plugins/ObjectFile/JIT/ObjectFileJIT.h"
42
Zachary Turnera893d302015-03-06 20:45:43 +000043#include "llvm/Support/raw_os_ostream.h"
44#include "llvm/Support/Signals.h"
45
Chris Lattner30fdc8d2010-06-08 16:52:24 +000046using namespace lldb;
47using namespace lldb_private;
48
Greg Clayton65a03992011-08-09 00:01:09 +000049// Shared pointers to modules track module lifetimes in
50// targets and in the global module, but this collection
51// will track all module objects that are still alive
52typedef std::vector<Module *> ModuleCollection;
53
54static ModuleCollection &
55GetModuleCollection()
56{
Jim Ingham549f7372011-10-31 23:47:10 +000057 // This module collection needs to live past any module, so we could either make it a
58 // shared pointer in each module or just leak is. Since it is only an empty vector by
59 // the time all the modules have gone away, we just leak it for now. If we decide this
60 // is a big problem we can introduce a Finalize method that will tear everything down in
61 // a predictable order.
62
63 static ModuleCollection *g_module_collection = NULL;
64 if (g_module_collection == NULL)
65 g_module_collection = new ModuleCollection();
66
67 return *g_module_collection;
Greg Clayton65a03992011-08-09 00:01:09 +000068}
69
Greg Claytonb26e6be2012-01-27 18:08:35 +000070Mutex *
Greg Clayton65a03992011-08-09 00:01:09 +000071Module::GetAllocationModuleCollectionMutex()
72{
Greg Claytonb26e6be2012-01-27 18:08:35 +000073 // NOTE: The mutex below must be leaked since the global module list in
74 // the ModuleList class will get torn at some point, and we can't know
75 // if it will tear itself down before the "g_module_collection_mutex" below
76 // will. So we leak a Mutex object below to safeguard against that
77
78 static Mutex *g_module_collection_mutex = NULL;
79 if (g_module_collection_mutex == NULL)
80 g_module_collection_mutex = new Mutex (Mutex::eMutexTypeRecursive); // NOTE: known leak
81 return g_module_collection_mutex;
Greg Clayton65a03992011-08-09 00:01:09 +000082}
83
84size_t
85Module::GetNumberAllocatedModules ()
86{
87 Mutex::Locker locker (GetAllocationModuleCollectionMutex());
88 return GetModuleCollection().size();
89}
90
91Module *
92Module::GetAllocatedModuleAtIndex (size_t idx)
93{
94 Mutex::Locker locker (GetAllocationModuleCollectionMutex());
95 ModuleCollection &modules = GetModuleCollection();
96 if (idx < modules.size())
97 return modules[idx];
98 return NULL;
99}
Greg Clayton29ad7b92012-01-27 18:45:39 +0000100#if 0
Greg Clayton65a03992011-08-09 00:01:09 +0000101
Greg Clayton29ad7b92012-01-27 18:45:39 +0000102// These functions help us to determine if modules are still loaded, yet don't require that
103// you have a command interpreter and can easily be called from an external debugger.
104namespace lldb {
Greg Clayton65a03992011-08-09 00:01:09 +0000105
Greg Clayton29ad7b92012-01-27 18:45:39 +0000106 void
107 ClearModuleInfo (void)
108 {
Greg Clayton0cd70862012-04-09 20:22:01 +0000109 const bool mandatory = true;
110 ModuleList::RemoveOrphanSharedModules(mandatory);
Greg Clayton29ad7b92012-01-27 18:45:39 +0000111 }
112
113 void
114 DumpModuleInfo (void)
115 {
116 Mutex::Locker locker (Module::GetAllocationModuleCollectionMutex());
117 ModuleCollection &modules = GetModuleCollection();
118 const size_t count = modules.size();
Daniel Malead01b2952012-11-29 21:49:15 +0000119 printf ("%s: %" PRIu64 " modules:\n", __PRETTY_FUNCTION__, (uint64_t)count);
Greg Clayton29ad7b92012-01-27 18:45:39 +0000120 for (size_t i=0; i<count; ++i)
121 {
122
123 StreamString strm;
124 Module *module = modules[i];
125 const bool in_shared_module_list = ModuleList::ModuleIsInCache (module);
126 module->GetDescription(&strm, eDescriptionLevelFull);
127 printf ("%p: shared = %i, ref_count = %3u, module = %s\n",
128 module,
129 in_shared_module_list,
130 (uint32_t)module->use_count(),
131 strm.GetString().c_str());
132 }
133 }
134}
135
136#endif
Greg Clayton3a18e312012-10-08 22:41:53 +0000137
Greg Claytonb9a01b32012-02-26 05:51:37 +0000138Module::Module (const ModuleSpec &module_spec) :
139 m_mutex (Mutex::eMutexTypeRecursive),
Greg Clayton34f11592014-03-04 21:20:23 +0000140 m_mod_time (),
141 m_arch (),
Greg Claytonb9a01b32012-02-26 05:51:37 +0000142 m_uuid (),
Greg Clayton34f11592014-03-04 21:20:23 +0000143 m_file (),
144 m_platform_file(),
Greg Claytonfbb76342013-11-20 21:07:01 +0000145 m_remote_install_file(),
Greg Clayton34f11592014-03-04 21:20:23 +0000146 m_symfile_spec (),
147 m_object_name (),
148 m_object_offset (),
149 m_object_mod_time (),
Greg Claytonb9a01b32012-02-26 05:51:37 +0000150 m_objfile_sp (),
151 m_symfile_ap (),
Zachary Turner88c6b622015-03-03 18:34:26 +0000152 m_ast (new ClangASTContext),
Greg Claytond804d282012-03-15 21:01:31 +0000153 m_source_mappings (),
Greg Clayton23f8c952014-03-24 23:10:19 +0000154 m_sections_ap(),
Greg Claytonb9a01b32012-02-26 05:51:37 +0000155 m_did_load_objfile (false),
156 m_did_load_symbol_vendor (false),
157 m_did_parse_uuid (false),
158 m_did_init_ast (false),
Greg Clayton1d609092012-07-12 22:51:12 +0000159 m_file_has_changed (false),
160 m_first_file_changed_log (false)
Greg Claytonb9a01b32012-02-26 05:51:37 +0000161{
162 // Scope for locker below...
163 {
164 Mutex::Locker locker (GetAllocationModuleCollectionMutex());
165 GetModuleCollection().push_back(this);
166 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000167
Greg Clayton5160ce52013-03-27 23:08:40 +0000168 Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_OBJECT|LIBLLDB_LOG_MODULES));
Greg Claytonb9a01b32012-02-26 05:51:37 +0000169 if (log)
Greg Claytonb5ad4ec2013-04-29 17:25:54 +0000170 log->Printf ("%p Module::Module((%s) '%s%s%s%s')",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000171 static_cast<void*>(this),
Greg Clayton34f11592014-03-04 21:20:23 +0000172 module_spec.GetArchitecture().GetArchitectureName(),
173 module_spec.GetFileSpec().GetPath().c_str(),
174 module_spec.GetObjectName().IsEmpty() ? "" : "(",
175 module_spec.GetObjectName().IsEmpty() ? "" : module_spec.GetObjectName().AsCString(""),
176 module_spec.GetObjectName().IsEmpty() ? "" : ")");
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000177
Greg Clayton34f11592014-03-04 21:20:23 +0000178 // First extract all module specifications from the file using the local
179 // file path. If there are no specifications, then don't fill anything in
180 ModuleSpecList modules_specs;
181 if (ObjectFile::GetModuleSpecifications(module_spec.GetFileSpec(), 0, 0, modules_specs) == 0)
182 return;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000183
Greg Clayton34f11592014-03-04 21:20:23 +0000184 // Now make sure that one of the module specifications matches what we just
185 // extract. We might have a module specification that specifies a file "/usr/lib/dyld"
186 // with UUID XXX, but we might have a local version of "/usr/lib/dyld" that has
187 // UUID YYY and we don't want those to match. If they don't match, just don't
188 // fill any ivars in so we don't accidentally grab the wrong file later since
189 // they don't match...
190 ModuleSpec matching_module_spec;
191 if (modules_specs.FindMatchingModuleSpec(module_spec, matching_module_spec) == 0)
192 return;
Greg Clayton7ab7f892014-05-29 21:33:45 +0000193
194 if (module_spec.GetFileSpec())
195 m_mod_time = module_spec.GetFileSpec().GetModificationTime();
196 else if (matching_module_spec.GetFileSpec())
197 m_mod_time = matching_module_spec.GetFileSpec().GetModificationTime();
198
199 // Copy the architecture from the actual spec if we got one back, else use the one that was specified
200 if (matching_module_spec.GetArchitecture().IsValid())
Greg Clayton34f11592014-03-04 21:20:23 +0000201 m_arch = matching_module_spec.GetArchitecture();
Greg Clayton7ab7f892014-05-29 21:33:45 +0000202 else if (module_spec.GetArchitecture().IsValid())
203 m_arch = module_spec.GetArchitecture();
204
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +0000205 // Copy the file spec over and use the specified one (if there was one) so we
Greg Clayton7ab7f892014-05-29 21:33:45 +0000206 // don't use a path that might have gotten resolved a path in 'matching_module_spec'
207 if (module_spec.GetFileSpec())
208 m_file = module_spec.GetFileSpec();
209 else if (matching_module_spec.GetFileSpec())
210 m_file = matching_module_spec.GetFileSpec();
211
212 // Copy the platform file spec over
213 if (module_spec.GetPlatformFileSpec())
214 m_platform_file = module_spec.GetPlatformFileSpec();
215 else if (matching_module_spec.GetPlatformFileSpec())
216 m_platform_file = matching_module_spec.GetPlatformFileSpec();
217
218 // Copy the symbol file spec over
219 if (module_spec.GetSymbolFileSpec())
220 m_symfile_spec = module_spec.GetSymbolFileSpec();
221 else if (matching_module_spec.GetSymbolFileSpec())
222 m_symfile_spec = matching_module_spec.GetSymbolFileSpec();
223
224 // Copy the object name over
225 if (matching_module_spec.GetObjectName())
226 m_object_name = matching_module_spec.GetObjectName();
227 else
228 m_object_name = module_spec.GetObjectName();
229
230 // Always trust the object offset (file offset) and object modification
231 // time (for mod time in a BSD static archive) of from the matching
232 // module specification
Greg Clayton36d7c892014-05-29 17:52:46 +0000233 m_object_offset = matching_module_spec.GetObjectOffset();
234 m_object_mod_time = matching_module_spec.GetObjectModificationTime();
Greg Clayton34f11592014-03-04 21:20:23 +0000235
Greg Claytonb9a01b32012-02-26 05:51:37 +0000236}
237
Greg Claytone72dfb32012-02-24 01:59:29 +0000238Module::Module(const FileSpec& file_spec,
239 const ArchSpec& arch,
240 const ConstString *object_name,
Zachary Turnera746e8e2014-07-02 17:24:07 +0000241 lldb::offset_t object_offset,
Greg Clayton57abc5d2013-05-10 21:47:16 +0000242 const TimeValue *object_mod_time_ptr) :
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000243 m_mutex (Mutex::eMutexTypeRecursive),
244 m_mod_time (file_spec.GetModificationTime()),
245 m_arch (arch),
246 m_uuid (),
247 m_file (file_spec),
Greg Clayton32e0a752011-03-30 18:16:51 +0000248 m_platform_file(),
Greg Claytonfbb76342013-11-20 21:07:01 +0000249 m_remote_install_file (),
Greg Claytone72dfb32012-02-24 01:59:29 +0000250 m_symfile_spec (),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000251 m_object_name (),
Greg Clayton8b82f082011-04-12 05:54:46 +0000252 m_object_offset (object_offset),
Greg Clayton57abc5d2013-05-10 21:47:16 +0000253 m_object_mod_time (),
Greg Clayton762f7132011-09-18 18:59:15 +0000254 m_objfile_sp (),
Greg Claytone83e7312010-09-07 23:40:05 +0000255 m_symfile_ap (),
Zachary Turner88c6b622015-03-03 18:34:26 +0000256 m_ast (new ClangASTContext),
Greg Claytond804d282012-03-15 21:01:31 +0000257 m_source_mappings (),
Greg Clayton23f8c952014-03-24 23:10:19 +0000258 m_sections_ap(),
Greg Claytone83e7312010-09-07 23:40:05 +0000259 m_did_load_objfile (false),
260 m_did_load_symbol_vendor (false),
261 m_did_parse_uuid (false),
Greg Clayton6beaaa62011-01-17 03:46:26 +0000262 m_did_init_ast (false),
Greg Clayton1d609092012-07-12 22:51:12 +0000263 m_file_has_changed (false),
264 m_first_file_changed_log (false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000265{
Greg Clayton65a03992011-08-09 00:01:09 +0000266 // Scope for locker below...
267 {
268 Mutex::Locker locker (GetAllocationModuleCollectionMutex());
269 GetModuleCollection().push_back(this);
270 }
271
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000272 if (object_name)
273 m_object_name = *object_name;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000274
Greg Clayton57abc5d2013-05-10 21:47:16 +0000275 if (object_mod_time_ptr)
276 m_object_mod_time = *object_mod_time_ptr;
277
Greg Clayton5160ce52013-03-27 23:08:40 +0000278 Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_OBJECT|LIBLLDB_LOG_MODULES));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000279 if (log)
Greg Claytonb5ad4ec2013-04-29 17:25:54 +0000280 log->Printf ("%p Module::Module((%s) '%s%s%s%s')",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000281 static_cast<void*>(this), m_arch.GetArchitectureName(),
Greg Claytonb5ad4ec2013-04-29 17:25:54 +0000282 m_file.GetPath().c_str(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000283 m_object_name.IsEmpty() ? "" : "(",
284 m_object_name.IsEmpty() ? "" : m_object_name.AsCString(""),
285 m_object_name.IsEmpty() ? "" : ")");
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000286}
287
Greg Clayton23f8c952014-03-24 23:10:19 +0000288Module::Module () :
289 m_mutex (Mutex::eMutexTypeRecursive),
290 m_mod_time (),
291 m_arch (),
292 m_uuid (),
293 m_file (),
294 m_platform_file(),
295 m_remote_install_file (),
296 m_symfile_spec (),
297 m_object_name (),
298 m_object_offset (0),
299 m_object_mod_time (),
300 m_objfile_sp (),
301 m_symfile_ap (),
Zachary Turner88c6b622015-03-03 18:34:26 +0000302 m_ast (new ClangASTContext),
Greg Clayton23f8c952014-03-24 23:10:19 +0000303 m_source_mappings (),
304 m_sections_ap(),
305 m_did_load_objfile (false),
306 m_did_load_symbol_vendor (false),
307 m_did_parse_uuid (false),
308 m_did_init_ast (false),
Greg Clayton23f8c952014-03-24 23:10:19 +0000309 m_file_has_changed (false),
310 m_first_file_changed_log (false)
311{
312 Mutex::Locker locker (GetAllocationModuleCollectionMutex());
313 GetModuleCollection().push_back(this);
314}
315
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000316Module::~Module()
317{
Greg Clayton217b28b2013-05-22 20:13:22 +0000318 // Lock our module down while we tear everything down to make sure
319 // we don't get any access to the module while it is being destroyed
320 Mutex::Locker locker (m_mutex);
Greg Clayton65a03992011-08-09 00:01:09 +0000321 // Scope for locker below...
322 {
323 Mutex::Locker locker (GetAllocationModuleCollectionMutex());
324 ModuleCollection &modules = GetModuleCollection();
325 ModuleCollection::iterator end = modules.end();
326 ModuleCollection::iterator pos = std::find(modules.begin(), end, this);
Greg Clayton3a18e312012-10-08 22:41:53 +0000327 assert (pos != end);
328 modules.erase(pos);
Greg Clayton65a03992011-08-09 00:01:09 +0000329 }
Greg Clayton5160ce52013-03-27 23:08:40 +0000330 Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_OBJECT|LIBLLDB_LOG_MODULES));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000331 if (log)
Greg Claytonb5ad4ec2013-04-29 17:25:54 +0000332 log->Printf ("%p Module::~Module((%s) '%s%s%s%s')",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000333 static_cast<void*>(this),
Greg Clayton64195a22011-02-23 00:35:02 +0000334 m_arch.GetArchitectureName(),
Greg Claytonb5ad4ec2013-04-29 17:25:54 +0000335 m_file.GetPath().c_str(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000336 m_object_name.IsEmpty() ? "" : "(",
337 m_object_name.IsEmpty() ? "" : m_object_name.AsCString(""),
338 m_object_name.IsEmpty() ? "" : ")");
Greg Clayton6beaaa62011-01-17 03:46:26 +0000339 // Release any auto pointers before we start tearing down our member
340 // variables since the object file and symbol files might need to make
341 // function calls back into this module object. The ordering is important
342 // here because symbol files can require the module object file. So we tear
343 // down the symbol file first, then the object file.
Greg Clayton3046e662013-07-10 01:23:25 +0000344 m_sections_ap.reset();
Greg Clayton6beaaa62011-01-17 03:46:26 +0000345 m_symfile_ap.reset();
Greg Clayton762f7132011-09-18 18:59:15 +0000346 m_objfile_sp.reset();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000347}
348
Greg Claytonc7f09cc2012-02-24 21:55:59 +0000349ObjectFile *
Andrew MacPherson17220c12014-03-05 10:12:43 +0000350Module::GetMemoryObjectFile (const lldb::ProcessSP &process_sp, lldb::addr_t header_addr, Error &error, size_t size_to_read)
Greg Claytonc7f09cc2012-02-24 21:55:59 +0000351{
352 if (m_objfile_sp)
353 {
354 error.SetErrorString ("object file already exists");
355 }
356 else
357 {
358 Mutex::Locker locker (m_mutex);
359 if (process_sp)
360 {
Greg Claytonc7f09cc2012-02-24 21:55:59 +0000361 m_did_load_objfile = true;
Andrew MacPherson17220c12014-03-05 10:12:43 +0000362 std::unique_ptr<DataBufferHeap> data_ap (new DataBufferHeap (size_to_read, 0));
Greg Claytonc7f09cc2012-02-24 21:55:59 +0000363 Error readmem_error;
364 const size_t bytes_read = process_sp->ReadMemory (header_addr,
365 data_ap->GetBytes(),
366 data_ap->GetByteSize(),
367 readmem_error);
Andrew MacPherson17220c12014-03-05 10:12:43 +0000368 if (bytes_read == size_to_read)
Greg Claytonc7f09cc2012-02-24 21:55:59 +0000369 {
370 DataBufferSP data_sp(data_ap.release());
371 m_objfile_sp = ObjectFile::FindPlugin(shared_from_this(), process_sp, header_addr, data_sp);
372 if (m_objfile_sp)
373 {
Greg Clayton3e10cf32012-04-20 19:50:20 +0000374 StreamString s;
Daniel Malead01b2952012-11-29 21:49:15 +0000375 s.Printf("0x%16.16" PRIx64, header_addr);
Greg Clayton3e10cf32012-04-20 19:50:20 +0000376 m_object_name.SetCString (s.GetData());
377
378 // Once we get the object file, update our module with the object file's
Greg Claytonc7f09cc2012-02-24 21:55:59 +0000379 // architecture since it might differ in vendor/os if some parts were
380 // unknown.
381 m_objfile_sp->GetArchitecture (m_arch);
382 }
383 else
384 {
385 error.SetErrorString ("unable to find suitable object file plug-in");
386 }
387 }
388 else
389 {
390 error.SetErrorStringWithFormat ("unable to read header from memory: %s", readmem_error.AsCString());
391 }
392 }
393 else
394 {
395 error.SetErrorString ("invalid process");
396 }
397 }
398 return m_objfile_sp.get();
399}
400
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000401
Greg Clayton60830262011-02-04 18:53:10 +0000402const lldb_private::UUID&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000403Module::GetUUID()
404{
405 Mutex::Locker locker (m_mutex);
Greg Claytone83e7312010-09-07 23:40:05 +0000406 if (m_did_parse_uuid == false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000407 {
408 ObjectFile * obj_file = GetObjectFile ();
409
410 if (obj_file != NULL)
411 {
412 obj_file->GetUUID(&m_uuid);
Greg Claytone83e7312010-09-07 23:40:05 +0000413 m_did_parse_uuid = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000414 }
415 }
416 return m_uuid;
417}
418
Greg Clayton6beaaa62011-01-17 03:46:26 +0000419ClangASTContext &
420Module::GetClangASTContext ()
421{
422 Mutex::Locker locker (m_mutex);
423 if (m_did_init_ast == false)
424 {
425 ObjectFile * objfile = GetObjectFile();
Greg Clayton514487e2011-02-15 21:59:32 +0000426 ArchSpec object_arch;
427 if (objfile && objfile->GetArchitecture(object_arch))
Greg Clayton6beaaa62011-01-17 03:46:26 +0000428 {
429 m_did_init_ast = true;
Jason Molenda981d4df2012-10-16 20:45:49 +0000430
431 // LLVM wants this to be set to iOS or MacOSX; if we're working on
432 // a bare-boards type image, change the triple for llvm's benefit.
433 if (object_arch.GetTriple().getVendor() == llvm::Triple::Apple
434 && object_arch.GetTriple().getOS() == llvm::Triple::UnknownOS)
435 {
436 if (object_arch.GetTriple().getArch() == llvm::Triple::arm ||
Todd Fialad8eaa172014-07-23 14:37:35 +0000437 object_arch.GetTriple().getArch() == llvm::Triple::aarch64 ||
Jason Molenda981d4df2012-10-16 20:45:49 +0000438 object_arch.GetTriple().getArch() == llvm::Triple::thumb)
439 {
440 object_arch.GetTriple().setOS(llvm::Triple::IOS);
441 }
442 else
443 {
444 object_arch.GetTriple().setOS(llvm::Triple::MacOSX);
445 }
446 }
Zachary Turner88c6b622015-03-03 18:34:26 +0000447 m_ast->SetArchitecture (object_arch);
Greg Clayton6beaaa62011-01-17 03:46:26 +0000448 }
449 }
Zachary Turner88c6b622015-03-03 18:34:26 +0000450 return *m_ast;
Greg Clayton6beaaa62011-01-17 03:46:26 +0000451}
452
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000453void
454Module::ParseAllDebugSymbols()
455{
456 Mutex::Locker locker (m_mutex);
Greg Claytonc7bece562013-01-25 18:06:21 +0000457 size_t num_comp_units = GetNumCompileUnits();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000458 if (num_comp_units == 0)
459 return;
460
Greg Claytona2eee182011-09-17 07:23:18 +0000461 SymbolContext sc;
Greg Claytone1cd1be2012-01-29 20:56:30 +0000462 sc.module_sp = shared_from_this();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000463 SymbolVendor *symbols = GetSymbolVendor ();
464
Greg Claytonc7bece562013-01-25 18:06:21 +0000465 for (size_t cu_idx = 0; cu_idx < num_comp_units; cu_idx++)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000466 {
467 sc.comp_unit = symbols->GetCompileUnitAtIndex(cu_idx).get();
468 if (sc.comp_unit)
469 {
470 sc.function = NULL;
471 symbols->ParseVariablesForContext(sc);
472
473 symbols->ParseCompileUnitFunctions(sc);
474
Greg Claytonc7bece562013-01-25 18:06:21 +0000475 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 +0000476 {
477 symbols->ParseFunctionBlocks(sc);
478
479 // Parse the variables for this function and all its blocks
480 symbols->ParseVariablesForContext(sc);
481 }
482
483
484 // Parse all types for this compile unit
485 sc.function = NULL;
486 symbols->ParseTypes(sc);
487 }
488 }
489}
490
491void
492Module::CalculateSymbolContext(SymbolContext* sc)
493{
Greg Claytone1cd1be2012-01-29 20:56:30 +0000494 sc->module_sp = shared_from_this();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000495}
496
Greg Claytone72dfb32012-02-24 01:59:29 +0000497ModuleSP
Greg Clayton7e9b1fd2011-08-12 21:40:01 +0000498Module::CalculateSymbolContextModule ()
499{
Greg Claytone72dfb32012-02-24 01:59:29 +0000500 return shared_from_this();
Greg Clayton7e9b1fd2011-08-12 21:40:01 +0000501}
502
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000503void
504Module::DumpSymbolContext(Stream *s)
505{
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000506 s->Printf(", Module{%p}", static_cast<void*>(this));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000507}
508
Greg Claytonc7bece562013-01-25 18:06:21 +0000509size_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000510Module::GetNumCompileUnits()
511{
512 Mutex::Locker locker (m_mutex);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000513 Timer scoped_timer(__PRETTY_FUNCTION__,
514 "Module::GetNumCompileUnits (module = %p)",
515 static_cast<void*>(this));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000516 SymbolVendor *symbols = GetSymbolVendor ();
517 if (symbols)
518 return symbols->GetNumCompileUnits();
519 return 0;
520}
521
522CompUnitSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000523Module::GetCompileUnitAtIndex (size_t index)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000524{
525 Mutex::Locker locker (m_mutex);
Greg Claytonc7bece562013-01-25 18:06:21 +0000526 size_t num_comp_units = GetNumCompileUnits ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000527 CompUnitSP cu_sp;
528
529 if (index < num_comp_units)
530 {
531 SymbolVendor *symbols = GetSymbolVendor ();
532 if (symbols)
533 cu_sp = symbols->GetCompileUnitAtIndex(index);
534 }
535 return cu_sp;
536}
537
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000538bool
539Module::ResolveFileAddress (lldb::addr_t vm_addr, Address& so_addr)
540{
541 Mutex::Locker locker (m_mutex);
Daniel Malead01b2952012-11-29 21:49:15 +0000542 Timer scoped_timer(__PRETTY_FUNCTION__, "Module::ResolveFileAddress (vm_addr = 0x%" PRIx64 ")", vm_addr);
Greg Clayton3046e662013-07-10 01:23:25 +0000543 SectionList *section_list = GetSectionList();
544 if (section_list)
545 return so_addr.ResolveAddressUsingFileSections(vm_addr, section_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000546 return false;
547}
548
549uint32_t
Ashok Thirumurthi35729bb2013-09-24 15:34:13 +0000550Module::ResolveSymbolContextForAddress (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc,
551 bool resolve_tail_call_address)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000552{
553 Mutex::Locker locker (m_mutex);
554 uint32_t resolved_flags = 0;
555
Greg Clayton72310352013-02-23 04:12:47 +0000556 // Clear the result symbol context in case we don't find anything, but don't clear the target
557 sc.Clear(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000558
559 // Get the section from the section/offset address.
Greg Claytone72dfb32012-02-24 01:59:29 +0000560 SectionSP section_sp (so_addr.GetSection());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000561
562 // Make sure the section matches this module before we try and match anything
Greg Claytone72dfb32012-02-24 01:59:29 +0000563 if (section_sp && section_sp->GetModule().get() == this)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000564 {
565 // If the section offset based address resolved itself, then this
566 // is the right module.
Greg Claytone1cd1be2012-01-29 20:56:30 +0000567 sc.module_sp = shared_from_this();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000568 resolved_flags |= eSymbolContextModule;
569
Ashok Thirumurthi38807142013-09-16 22:00:17 +0000570 SymbolVendor* sym_vendor = GetSymbolVendor();
571 if (!sym_vendor)
572 return resolved_flags;
573
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000574 // Resolve the compile unit, function, block, line table or line
575 // entry if requested.
576 if (resolve_scope & eSymbolContextCompUnit ||
577 resolve_scope & eSymbolContextFunction ||
578 resolve_scope & eSymbolContextBlock ||
579 resolve_scope & eSymbolContextLineEntry )
580 {
Ashok Thirumurthi38807142013-09-16 22:00:17 +0000581 resolved_flags |= sym_vendor->ResolveSymbolContext (so_addr, resolve_scope, sc);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000582 }
583
Jim Ingham680e1772010-08-31 23:51:36 +0000584 // Resolve the symbol if requested, but don't re-look it up if we've already found it.
585 if (resolve_scope & eSymbolContextSymbol && !(resolved_flags & eSymbolContextSymbol))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000586 {
Ashok Thirumurthi38807142013-09-16 22:00:17 +0000587 Symtab *symtab = sym_vendor->GetSymtab();
588 if (symtab && so_addr.IsSectionOffset())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000589 {
Ashok Thirumurthi38807142013-09-16 22:00:17 +0000590 sc.symbol = symtab->FindSymbolContainingFileAddress(so_addr.GetFileAddress());
Ashok Thirumurthi35729bb2013-09-24 15:34:13 +0000591 if (!sc.symbol &&
592 resolve_scope & eSymbolContextFunction && !(resolved_flags & eSymbolContextFunction))
593 {
594 bool verify_unique = false; // No need to check again since ResolveSymbolContext failed to find a symbol at this address.
595 if (ObjectFile *obj_file = sc.module_sp->GetObjectFile())
596 sc.symbol = obj_file->ResolveSymbolForAddress(so_addr, verify_unique);
597 }
598
Ashok Thirumurthi38807142013-09-16 22:00:17 +0000599 if (sc.symbol)
Greg Clayton93e28612013-10-11 22:03:48 +0000600 {
601 if (sc.symbol->IsSynthetic())
602 {
603 // We have a synthetic symbol so lets check if the object file
604 // from the symbol file in the symbol vendor is different than
605 // the object file for the module, and if so search its symbol
606 // table to see if we can come up with a better symbol. For example
607 // dSYM files on MacOSX have an unstripped symbol table inside of
608 // them.
609 ObjectFile *symtab_objfile = symtab->GetObjectFile();
610 if (symtab_objfile && symtab_objfile->IsStripped())
611 {
612 SymbolFile *symfile = sym_vendor->GetSymbolFile();
613 if (symfile)
614 {
615 ObjectFile *symfile_objfile = symfile->GetObjectFile();
616 if (symfile_objfile != symtab_objfile)
617 {
618 Symtab *symfile_symtab = symfile_objfile->GetSymtab();
619 if (symfile_symtab)
620 {
621 Symbol *symbol = symfile_symtab->FindSymbolContainingFileAddress(so_addr.GetFileAddress());
622 if (symbol && !symbol->IsSynthetic())
623 {
624 sc.symbol = symbol;
625 }
626 }
627 }
628 }
629 }
630 }
Ashok Thirumurthi38807142013-09-16 22:00:17 +0000631 resolved_flags |= eSymbolContextSymbol;
Greg Clayton93e28612013-10-11 22:03:48 +0000632 }
Ashok Thirumurthi38807142013-09-16 22:00:17 +0000633 }
634 }
635
636 // For function symbols, so_addr may be off by one. This is a convention consistent
637 // with FDE row indices in eh_frame sections, but requires extra logic here to permit
638 // symbol lookup for disassembly and unwind.
639 if (resolve_scope & eSymbolContextSymbol && !(resolved_flags & eSymbolContextSymbol) &&
Ashok Thirumurthi35729bb2013-09-24 15:34:13 +0000640 resolve_tail_call_address && so_addr.IsSectionOffset())
Ashok Thirumurthi38807142013-09-16 22:00:17 +0000641 {
642 Address previous_addr = so_addr;
Greg Claytonedfaae32013-09-18 20:03:31 +0000643 previous_addr.Slide(-1);
Ashok Thirumurthi38807142013-09-16 22:00:17 +0000644
Ashok Thirumurthi35729bb2013-09-24 15:34:13 +0000645 bool do_resolve_tail_call_address = false; // prevent recursion
646 const uint32_t flags = ResolveSymbolContextForAddress(previous_addr, resolve_scope, sc,
647 do_resolve_tail_call_address);
Ashok Thirumurthi38807142013-09-16 22:00:17 +0000648 if (flags & eSymbolContextSymbol)
649 {
650 AddressRange addr_range;
651 if (sc.GetAddressRange (eSymbolContextFunction | eSymbolContextSymbol, 0, false, addr_range))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000652 {
Ashok Thirumurthi38807142013-09-16 22:00:17 +0000653 if (addr_range.GetBaseAddress().GetSection() == so_addr.GetSection())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000654 {
Ashok Thirumurthi38807142013-09-16 22:00:17 +0000655 // If the requested address is one past the address range of a function (i.e. a tail call),
656 // or the decremented address is the start of a function (i.e. some forms of trampoline),
657 // indicate that the symbol has been resolved.
658 if (so_addr.GetOffset() == addr_range.GetBaseAddress().GetOffset() ||
659 so_addr.GetOffset() == addr_range.GetBaseAddress().GetOffset() + addr_range.GetByteSize())
660 {
661 resolved_flags |= flags;
662 }
663 }
664 else
665 {
666 sc.symbol = nullptr; // Don't trust the symbol if the sections didn't match.
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000667 }
668 }
669 }
670 }
671 }
672 return resolved_flags;
673}
674
675uint32_t
Greg Clayton274060b2010-10-20 20:54:39 +0000676Module::ResolveSymbolContextForFilePath
677(
678 const char *file_path,
679 uint32_t line,
680 bool check_inlines,
681 uint32_t resolve_scope,
682 SymbolContextList& sc_list
683)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000684{
Greg Clayton274060b2010-10-20 20:54:39 +0000685 FileSpec file_spec(file_path, false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000686 return ResolveSymbolContextsForFileSpec (file_spec, line, check_inlines, resolve_scope, sc_list);
687}
688
689uint32_t
690Module::ResolveSymbolContextsForFileSpec (const FileSpec &file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list)
691{
692 Mutex::Locker locker (m_mutex);
693 Timer scoped_timer(__PRETTY_FUNCTION__,
Greg Claytonb5ad4ec2013-04-29 17:25:54 +0000694 "Module::ResolveSymbolContextForFilePath (%s:%u, check_inlines = %s, resolve_scope = 0x%8.8x)",
695 file_spec.GetPath().c_str(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000696 line,
697 check_inlines ? "yes" : "no",
698 resolve_scope);
699
700 const uint32_t initial_count = sc_list.GetSize();
701
702 SymbolVendor *symbols = GetSymbolVendor ();
703 if (symbols)
704 symbols->ResolveSymbolContext (file_spec, line, check_inlines, resolve_scope, sc_list);
705
706 return sc_list.GetSize() - initial_count;
707}
708
709
Greg Claytonc7bece562013-01-25 18:06:21 +0000710size_t
711Module::FindGlobalVariables (const ConstString &name,
712 const ClangNamespaceDecl *namespace_decl,
713 bool append,
714 size_t max_matches,
715 VariableList& variables)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000716{
717 SymbolVendor *symbols = GetSymbolVendor ();
718 if (symbols)
Sean Callanan213fdb82011-10-13 01:49:10 +0000719 return symbols->FindGlobalVariables(name, namespace_decl, append, max_matches, variables);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000720 return 0;
721}
Greg Claytonc7bece562013-01-25 18:06:21 +0000722
723size_t
724Module::FindGlobalVariables (const RegularExpression& regex,
725 bool append,
726 size_t max_matches,
727 VariableList& variables)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000728{
729 SymbolVendor *symbols = GetSymbolVendor ();
730 if (symbols)
731 return symbols->FindGlobalVariables(regex, append, max_matches, variables);
732 return 0;
733}
734
Greg Claytonc7bece562013-01-25 18:06:21 +0000735size_t
Greg Clayton644247c2011-07-07 01:59:51 +0000736Module::FindCompileUnits (const FileSpec &path,
737 bool append,
738 SymbolContextList &sc_list)
739{
740 if (!append)
741 sc_list.Clear();
742
Greg Claytonc7bece562013-01-25 18:06:21 +0000743 const size_t start_size = sc_list.GetSize();
744 const size_t num_compile_units = GetNumCompileUnits();
Greg Clayton644247c2011-07-07 01:59:51 +0000745 SymbolContext sc;
Greg Claytone1cd1be2012-01-29 20:56:30 +0000746 sc.module_sp = shared_from_this();
Sean Callananddd7a2a2013-10-03 22:27:29 +0000747 const bool compare_directory = (bool)path.GetDirectory();
Greg Claytonc7bece562013-01-25 18:06:21 +0000748 for (size_t i=0; i<num_compile_units; ++i)
Greg Clayton644247c2011-07-07 01:59:51 +0000749 {
750 sc.comp_unit = GetCompileUnitAtIndex(i).get();
Greg Clayton2dafd8e2012-04-23 22:00:21 +0000751 if (sc.comp_unit)
752 {
753 if (FileSpec::Equal (*sc.comp_unit, path, compare_directory))
754 sc_list.Append(sc);
755 }
Greg Clayton644247c2011-07-07 01:59:51 +0000756 }
757 return sc_list.GetSize() - start_size;
758}
759
Greg Claytonc7bece562013-01-25 18:06:21 +0000760size_t
Sean Callananb6d70eb2011-10-12 02:08:07 +0000761Module::FindFunctions (const ConstString &name,
762 const ClangNamespaceDecl *namespace_decl,
Greg Claytonc7bece562013-01-25 18:06:21 +0000763 uint32_t name_type_mask,
Sean Callanan9df05fb2012-02-10 22:52:19 +0000764 bool include_symbols,
765 bool include_inlines,
Greg Clayton931180e2011-01-27 06:44:37 +0000766 bool append,
767 SymbolContextList& sc_list)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000768{
Greg Clayton931180e2011-01-27 06:44:37 +0000769 if (!append)
770 sc_list.Clear();
771
Greg Clayton43fe2172013-04-03 02:00:15 +0000772 const size_t old_size = sc_list.GetSize();
Greg Clayton931180e2011-01-27 06:44:37 +0000773
774 // Find all the functions (not symbols, but debug information functions...
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000775 SymbolVendor *symbols = GetSymbolVendor ();
Greg Clayton43fe2172013-04-03 02:00:15 +0000776
777 if (name_type_mask & eFunctionNameTypeAuto)
Greg Clayton931180e2011-01-27 06:44:37 +0000778 {
Greg Clayton43fe2172013-04-03 02:00:15 +0000779 ConstString lookup_name;
780 uint32_t lookup_name_type_mask = 0;
781 bool match_name_after_lookup = false;
782 Module::PrepareForFunctionNameLookup (name,
783 name_type_mask,
784 lookup_name,
785 lookup_name_type_mask,
786 match_name_after_lookup);
787
788 if (symbols)
Michael Sartaina7499c92013-07-01 19:45:50 +0000789 {
Greg Clayton43fe2172013-04-03 02:00:15 +0000790 symbols->FindFunctions(lookup_name,
791 namespace_decl,
792 lookup_name_type_mask,
793 include_inlines,
794 append,
795 sc_list);
796
Michael Sartaina7499c92013-07-01 19:45:50 +0000797 // Now check our symbol table for symbols that are code symbols if requested
798 if (include_symbols)
Greg Clayton931180e2011-01-27 06:44:37 +0000799 {
Michael Sartaina7499c92013-07-01 19:45:50 +0000800 Symtab *symtab = symbols->GetSymtab();
Greg Clayton43fe2172013-04-03 02:00:15 +0000801 if (symtab)
802 symtab->FindFunctionSymbols(lookup_name, lookup_name_type_mask, sc_list);
803 }
804 }
805
806 if (match_name_after_lookup)
807 {
808 SymbolContext sc;
809 size_t i = old_size;
810 while (i<sc_list.GetSize())
811 {
812 if (sc_list.GetContextAtIndex(i, sc))
Greg Clayton931180e2011-01-27 06:44:37 +0000813 {
Greg Clayton43fe2172013-04-03 02:00:15 +0000814 const char *func_name = sc.GetFunctionName().GetCString();
815 if (func_name && strstr (func_name, name.GetCString()) == NULL)
Greg Clayton931180e2011-01-27 06:44:37 +0000816 {
Greg Clayton43fe2172013-04-03 02:00:15 +0000817 // Remove the current context
818 sc_list.RemoveContextAtIndex(i);
819 // Don't increment i and continue in the loop
820 continue;
Greg Clayton931180e2011-01-27 06:44:37 +0000821 }
822 }
Greg Clayton43fe2172013-04-03 02:00:15 +0000823 ++i;
824 }
825 }
Greg Clayton43fe2172013-04-03 02:00:15 +0000826 }
827 else
828 {
829 if (symbols)
Michael Sartaina7499c92013-07-01 19:45:50 +0000830 {
Greg Clayton43fe2172013-04-03 02:00:15 +0000831 symbols->FindFunctions(name, namespace_decl, name_type_mask, include_inlines, append, sc_list);
832
Michael Sartaina7499c92013-07-01 19:45:50 +0000833 // Now check our symbol table for symbols that are code symbols if requested
834 if (include_symbols)
Greg Clayton43fe2172013-04-03 02:00:15 +0000835 {
Michael Sartaina7499c92013-07-01 19:45:50 +0000836 Symtab *symtab = symbols->GetSymtab();
Greg Clayton43fe2172013-04-03 02:00:15 +0000837 if (symtab)
838 symtab->FindFunctionSymbols(name, name_type_mask, sc_list);
Greg Clayton931180e2011-01-27 06:44:37 +0000839 }
840 }
841 }
Greg Clayton43fe2172013-04-03 02:00:15 +0000842
843 return sc_list.GetSize() - old_size;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000844}
845
Greg Claytonc7bece562013-01-25 18:06:21 +0000846size_t
Greg Clayton931180e2011-01-27 06:44:37 +0000847Module::FindFunctions (const RegularExpression& regex,
Sean Callanan9df05fb2012-02-10 22:52:19 +0000848 bool include_symbols,
849 bool include_inlines,
Greg Clayton931180e2011-01-27 06:44:37 +0000850 bool append,
851 SymbolContextList& sc_list)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000852{
Greg Clayton931180e2011-01-27 06:44:37 +0000853 if (!append)
854 sc_list.Clear();
855
Greg Claytonc7bece562013-01-25 18:06:21 +0000856 const size_t start_size = sc_list.GetSize();
Greg Clayton931180e2011-01-27 06:44:37 +0000857
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000858 SymbolVendor *symbols = GetSymbolVendor ();
859 if (symbols)
Greg Clayton931180e2011-01-27 06:44:37 +0000860 {
Michael Sartaina7499c92013-07-01 19:45:50 +0000861 symbols->FindFunctions(regex, include_inlines, append, sc_list);
862
863 // Now check our symbol table for symbols that are code symbols if requested
864 if (include_symbols)
Greg Clayton931180e2011-01-27 06:44:37 +0000865 {
Michael Sartaina7499c92013-07-01 19:45:50 +0000866 Symtab *symtab = symbols->GetSymtab();
Greg Clayton931180e2011-01-27 06:44:37 +0000867 if (symtab)
868 {
869 std::vector<uint32_t> symbol_indexes;
Matt Kopec00049b82013-02-27 20:13:38 +0000870 symtab->AppendSymbolIndexesMatchingRegExAndType (regex, eSymbolTypeAny, Symtab::eDebugAny, Symtab::eVisibilityAny, symbol_indexes);
Greg Claytonc7bece562013-01-25 18:06:21 +0000871 const size_t num_matches = symbol_indexes.size();
Greg Clayton931180e2011-01-27 06:44:37 +0000872 if (num_matches)
873 {
874 SymbolContext sc(this);
Greg Claytond8cf1a12013-06-12 00:46:38 +0000875 const size_t end_functions_added_index = sc_list.GetSize();
876 size_t num_functions_added_to_sc_list = end_functions_added_index - start_size;
877 if (num_functions_added_to_sc_list == 0)
Greg Clayton931180e2011-01-27 06:44:37 +0000878 {
Greg Claytond8cf1a12013-06-12 00:46:38 +0000879 // No functions were added, just symbols, so we can just append them
880 for (size_t i=0; i<num_matches; ++i)
881 {
882 sc.symbol = symtab->SymbolAtIndex(symbol_indexes[i]);
883 SymbolType sym_type = sc.symbol->GetType();
884 if (sc.symbol && (sym_type == eSymbolTypeCode ||
885 sym_type == eSymbolTypeResolver))
886 sc_list.Append(sc);
887 }
888 }
889 else
890 {
891 typedef std::map<lldb::addr_t, uint32_t> FileAddrToIndexMap;
892 FileAddrToIndexMap file_addr_to_index;
893 for (size_t i=start_size; i<end_functions_added_index; ++i)
894 {
895 const SymbolContext &sc = sc_list[i];
896 if (sc.block)
897 continue;
898 file_addr_to_index[sc.function->GetAddressRange().GetBaseAddress().GetFileAddress()] = i;
899 }
900
901 FileAddrToIndexMap::const_iterator end = file_addr_to_index.end();
902 // Functions were added so we need to merge symbols into any
903 // existing function symbol contexts
904 for (size_t i=start_size; i<num_matches; ++i)
905 {
906 sc.symbol = symtab->SymbolAtIndex(symbol_indexes[i]);
907 SymbolType sym_type = sc.symbol->GetType();
908 if (sc.symbol && (sym_type == eSymbolTypeCode ||
909 sym_type == eSymbolTypeResolver))
910 {
911 FileAddrToIndexMap::const_iterator pos = file_addr_to_index.find(sc.symbol->GetAddress().GetFileAddress());
912 if (pos == end)
913 sc_list.Append(sc);
914 else
915 sc_list[pos->second].symbol = sc.symbol;
916 }
917 }
Greg Clayton931180e2011-01-27 06:44:37 +0000918 }
919 }
920 }
921 }
922 }
923 return sc_list.GetSize() - start_size;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000924}
925
Richard Mittonf86248d2013-09-12 02:20:34 +0000926void
927Module::FindAddressesForLine (const lldb::TargetSP target_sp,
928 const FileSpec &file, uint32_t line,
929 Function *function,
930 std::vector<Address> &output_local, std::vector<Address> &output_extern)
931{
932 SearchFilterByModule filter(target_sp, m_file);
933 AddressResolverFileLine resolver(file, line, true);
934 resolver.ResolveAddress (filter);
935
936 for (size_t n=0;n<resolver.GetNumberOfAddresses();n++)
937 {
938 Address addr = resolver.GetAddressRangeAtIndex(n).GetBaseAddress();
939 Function *f = addr.CalculateSymbolContextFunction();
940 if (f && f == function)
941 output_local.push_back (addr);
942 else
943 output_extern.push_back (addr);
944 }
945}
946
Greg Claytonc7bece562013-01-25 18:06:21 +0000947size_t
Greg Clayton84db9102012-03-26 23:03:23 +0000948Module::FindTypes_Impl (const SymbolContext& sc,
949 const ConstString &name,
950 const ClangNamespaceDecl *namespace_decl,
951 bool append,
Greg Claytonc7bece562013-01-25 18:06:21 +0000952 size_t max_matches,
Greg Clayton84db9102012-03-26 23:03:23 +0000953 TypeList& types)
Greg Clayton3504eee2010-08-03 01:26:16 +0000954{
955 Timer scoped_timer(__PRETTY_FUNCTION__, __PRETTY_FUNCTION__);
956 if (sc.module_sp.get() == NULL || sc.module_sp.get() == this)
957 {
958 SymbolVendor *symbols = GetSymbolVendor ();
959 if (symbols)
Sean Callanan213fdb82011-10-13 01:49:10 +0000960 return symbols->FindTypes(sc, name, namespace_decl, append, max_matches, types);
Greg Clayton3504eee2010-08-03 01:26:16 +0000961 }
962 return 0;
963}
964
Greg Claytonc7bece562013-01-25 18:06:21 +0000965size_t
Greg Clayton84db9102012-03-26 23:03:23 +0000966Module::FindTypesInNamespace (const SymbolContext& sc,
967 const ConstString &type_name,
968 const ClangNamespaceDecl *namespace_decl,
Greg Claytonc7bece562013-01-25 18:06:21 +0000969 size_t max_matches,
Greg Clayton84db9102012-03-26 23:03:23 +0000970 TypeList& type_list)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000971{
Greg Clayton84db9102012-03-26 23:03:23 +0000972 const bool append = true;
973 return FindTypes_Impl(sc, type_name, namespace_decl, append, max_matches, type_list);
Enrico Granata6f3533f2011-07-29 19:53:35 +0000974}
975
Greg Claytonb43165b2012-12-05 21:24:42 +0000976lldb::TypeSP
977Module::FindFirstType (const SymbolContext& sc,
978 const ConstString &name,
979 bool exact_match)
980{
981 TypeList type_list;
Greg Claytonc7bece562013-01-25 18:06:21 +0000982 const size_t num_matches = FindTypes (sc, name, exact_match, 1, type_list);
Greg Claytonb43165b2012-12-05 21:24:42 +0000983 if (num_matches)
984 return type_list.GetTypeAtIndex(0);
985 return TypeSP();
986}
987
988
Greg Claytonc7bece562013-01-25 18:06:21 +0000989size_t
Greg Clayton84db9102012-03-26 23:03:23 +0000990Module::FindTypes (const SymbolContext& sc,
991 const ConstString &name,
992 bool exact_match,
Greg Claytonc7bece562013-01-25 18:06:21 +0000993 size_t max_matches,
Greg Clayton84db9102012-03-26 23:03:23 +0000994 TypeList& types)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000995{
Greg Claytonc7bece562013-01-25 18:06:21 +0000996 size_t num_matches = 0;
Greg Clayton84db9102012-03-26 23:03:23 +0000997 const char *type_name_cstr = name.GetCString();
998 std::string type_scope;
999 std::string type_basename;
1000 const bool append = true;
Greg Clayton7bc31332012-10-22 16:19:56 +00001001 TypeClass type_class = eTypeClassAny;
1002 if (Type::GetTypeScopeAndBasename (type_name_cstr, type_scope, type_basename, type_class))
Enrico Granata6f3533f2011-07-29 19:53:35 +00001003 {
Greg Clayton84db9102012-03-26 23:03:23 +00001004 // Check if "name" starts with "::" which means the qualified type starts
1005 // from the root namespace and implies and exact match. The typenames we
1006 // get back from clang do not start with "::" so we need to strip this off
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00001007 // in order to get the qualified names to match
Greg Clayton84db9102012-03-26 23:03:23 +00001008
1009 if (type_scope.size() >= 2 && type_scope[0] == ':' && type_scope[1] == ':')
1010 {
1011 type_scope.erase(0,2);
1012 exact_match = true;
1013 }
1014 ConstString type_basename_const_str (type_basename.c_str());
1015 if (FindTypes_Impl(sc, type_basename_const_str, NULL, append, max_matches, types))
1016 {
Greg Clayton7bc31332012-10-22 16:19:56 +00001017 types.RemoveMismatchedTypes (type_scope, type_basename, type_class, exact_match);
Greg Clayton84db9102012-03-26 23:03:23 +00001018 num_matches = types.GetSize();
1019 }
Enrico Granata6f3533f2011-07-29 19:53:35 +00001020 }
1021 else
Greg Clayton84db9102012-03-26 23:03:23 +00001022 {
1023 // The type is not in a namespace/class scope, just search for it by basename
Greg Clayton7bc31332012-10-22 16:19:56 +00001024 if (type_class != eTypeClassAny)
1025 {
1026 // The "type_name_cstr" will have been modified if we have a valid type class
1027 // prefix (like "struct", "class", "union", "typedef" etc).
Arnaud A. de Grandmaison62e5f4d2014-03-22 20:23:26 +00001028 FindTypes_Impl(sc, ConstString(type_name_cstr), NULL, append, max_matches, types);
Greg Clayton7bc31332012-10-22 16:19:56 +00001029 types.RemoveMismatchedTypes (type_class);
1030 num_matches = types.GetSize();
1031 }
1032 else
1033 {
1034 num_matches = FindTypes_Impl(sc, name, NULL, append, max_matches, types);
1035 }
Greg Clayton84db9102012-03-26 23:03:23 +00001036 }
1037
1038 return num_matches;
Enrico Granata6f3533f2011-07-29 19:53:35 +00001039
1040}
1041
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001042SymbolVendor*
Greg Clayton136dff82012-12-14 02:15:00 +00001043Module::GetSymbolVendor (bool can_create, lldb_private::Stream *feedback_strm)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001044{
1045 Mutex::Locker locker (m_mutex);
Greg Claytone83e7312010-09-07 23:40:05 +00001046 if (m_did_load_symbol_vendor == false && can_create)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001047 {
1048 ObjectFile *obj_file = GetObjectFile ();
1049 if (obj_file != NULL)
1050 {
1051 Timer scoped_timer(__PRETTY_FUNCTION__, __PRETTY_FUNCTION__);
Greg Clayton136dff82012-12-14 02:15:00 +00001052 m_symfile_ap.reset(SymbolVendor::FindPlugin(shared_from_this(), feedback_strm));
Greg Claytone83e7312010-09-07 23:40:05 +00001053 m_did_load_symbol_vendor = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001054 }
1055 }
1056 return m_symfile_ap.get();
1057}
1058
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001059void
1060Module::SetFileSpecAndObjectName (const FileSpec &file, const ConstString &object_name)
1061{
1062 // Container objects whose paths do not specify a file directly can call
1063 // this function to correct the file and object names.
1064 m_file = file;
1065 m_mod_time = file.GetModificationTime();
1066 m_object_name = object_name;
1067}
1068
1069const ArchSpec&
1070Module::GetArchitecture () const
1071{
1072 return m_arch;
1073}
1074
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00001075std::string
1076Module::GetSpecificationDescription () const
1077{
1078 std::string spec(GetFileSpec().GetPath());
1079 if (m_object_name)
1080 {
1081 spec += '(';
1082 spec += m_object_name.GetCString();
1083 spec += ')';
1084 }
1085 return spec;
1086}
1087
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001088void
Greg Claytonc982b3d2011-11-28 01:45:00 +00001089Module::GetDescription (Stream *s, lldb::DescriptionLevel level)
Caroline Ticeceb6b132010-10-26 03:11:13 +00001090{
1091 Mutex::Locker locker (m_mutex);
1092
Greg Claytonc982b3d2011-11-28 01:45:00 +00001093 if (level >= eDescriptionLevelFull)
1094 {
1095 if (m_arch.IsValid())
1096 s->Printf("(%s) ", m_arch.GetArchitectureName());
1097 }
Caroline Ticeceb6b132010-10-26 03:11:13 +00001098
Greg Claytonc982b3d2011-11-28 01:45:00 +00001099 if (level == eDescriptionLevelBrief)
1100 {
1101 const char *filename = m_file.GetFilename().GetCString();
1102 if (filename)
1103 s->PutCString (filename);
1104 }
1105 else
1106 {
1107 char path[PATH_MAX];
1108 if (m_file.GetPath(path, sizeof(path)))
1109 s->PutCString(path);
1110 }
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001111
1112 const char *object_name = m_object_name.GetCString();
1113 if (object_name)
1114 s->Printf("(%s)", object_name);
Caroline Ticeceb6b132010-10-26 03:11:13 +00001115}
1116
1117void
Greg Claytonc982b3d2011-11-28 01:45:00 +00001118Module::ReportError (const char *format, ...)
1119{
Greg Claytone38a5ed2012-01-05 03:57:59 +00001120 if (format && format[0])
1121 {
1122 StreamString strm;
1123 strm.PutCString("error: ");
1124 GetDescription(&strm, lldb::eDescriptionLevelBrief);
Greg Clayton8b353342012-01-11 01:59:18 +00001125 strm.PutChar (' ');
Greg Claytone38a5ed2012-01-05 03:57:59 +00001126 va_list args;
1127 va_start (args, format);
1128 strm.PrintfVarArg(format, args);
1129 va_end (args);
1130
1131 const int format_len = strlen(format);
1132 if (format_len > 0)
1133 {
1134 const char last_char = format[format_len-1];
1135 if (last_char != '\n' || last_char != '\r')
1136 strm.EOL();
1137 }
1138 Host::SystemLog (Host::eSystemLogError, "%s", strm.GetString().c_str());
1139
1140 }
1141}
1142
Greg Clayton1d609092012-07-12 22:51:12 +00001143bool
1144Module::FileHasChanged () const
1145{
1146 if (m_file_has_changed == false)
1147 m_file_has_changed = (m_file.GetModificationTime() != m_mod_time);
1148 return m_file_has_changed;
1149}
1150
Greg Claytone38a5ed2012-01-05 03:57:59 +00001151void
1152Module::ReportErrorIfModifyDetected (const char *format, ...)
1153{
Greg Clayton1d609092012-07-12 22:51:12 +00001154 if (m_first_file_changed_log == false)
Greg Claytone38a5ed2012-01-05 03:57:59 +00001155 {
Greg Clayton1d609092012-07-12 22:51:12 +00001156 if (FileHasChanged ())
Greg Claytone38a5ed2012-01-05 03:57:59 +00001157 {
Greg Clayton1d609092012-07-12 22:51:12 +00001158 m_first_file_changed_log = true;
1159 if (format)
Greg Claytone38a5ed2012-01-05 03:57:59 +00001160 {
Greg Clayton1d609092012-07-12 22:51:12 +00001161 StreamString strm;
1162 strm.PutCString("error: the object file ");
1163 GetDescription(&strm, lldb::eDescriptionLevelFull);
1164 strm.PutCString (" has been modified\n");
1165
1166 va_list args;
1167 va_start (args, format);
1168 strm.PrintfVarArg(format, args);
1169 va_end (args);
1170
1171 const int format_len = strlen(format);
1172 if (format_len > 0)
1173 {
1174 const char last_char = format[format_len-1];
1175 if (last_char != '\n' || last_char != '\r')
1176 strm.EOL();
1177 }
1178 strm.PutCString("The debug session should be aborted as the original debug information has been overwritten.\n");
1179 Host::SystemLog (Host::eSystemLogError, "%s", strm.GetString().c_str());
Greg Claytone38a5ed2012-01-05 03:57:59 +00001180 }
Greg Claytone38a5ed2012-01-05 03:57:59 +00001181 }
1182 }
Greg Claytonc982b3d2011-11-28 01:45:00 +00001183}
1184
1185void
1186Module::ReportWarning (const char *format, ...)
1187{
Greg Claytone38a5ed2012-01-05 03:57:59 +00001188 if (format && format[0])
1189 {
1190 StreamString strm;
1191 strm.PutCString("warning: ");
Greg Clayton8b353342012-01-11 01:59:18 +00001192 GetDescription(&strm, lldb::eDescriptionLevelFull);
1193 strm.PutChar (' ');
Greg Claytone38a5ed2012-01-05 03:57:59 +00001194
1195 va_list args;
1196 va_start (args, format);
1197 strm.PrintfVarArg(format, args);
1198 va_end (args);
1199
1200 const int format_len = strlen(format);
1201 if (format_len > 0)
1202 {
1203 const char last_char = format[format_len-1];
1204 if (last_char != '\n' || last_char != '\r')
1205 strm.EOL();
1206 }
1207 Host::SystemLog (Host::eSystemLogWarning, "%s", strm.GetString().c_str());
1208 }
Greg Claytonc982b3d2011-11-28 01:45:00 +00001209}
1210
1211void
1212Module::LogMessage (Log *log, const char *format, ...)
1213{
1214 if (log)
1215 {
1216 StreamString log_message;
Greg Clayton8b353342012-01-11 01:59:18 +00001217 GetDescription(&log_message, lldb::eDescriptionLevelFull);
Greg Claytonc982b3d2011-11-28 01:45:00 +00001218 log_message.PutCString (": ");
1219 va_list args;
1220 va_start (args, format);
1221 log_message.PrintfVarArg (format, args);
1222 va_end (args);
1223 log->PutCString(log_message.GetString().c_str());
1224 }
1225}
1226
Greg Claytond61c0fc2012-04-23 22:55:20 +00001227void
1228Module::LogMessageVerboseBacktrace (Log *log, const char *format, ...)
1229{
1230 if (log)
1231 {
1232 StreamString log_message;
1233 GetDescription(&log_message, lldb::eDescriptionLevelFull);
1234 log_message.PutCString (": ");
1235 va_list args;
1236 va_start (args, format);
1237 log_message.PrintfVarArg (format, args);
1238 va_end (args);
1239 if (log->GetVerbose())
Zachary Turnera893d302015-03-06 20:45:43 +00001240 {
1241 std::string back_trace;
1242 llvm::raw_string_ostream stream(back_trace);
1243 llvm::sys::PrintStackTrace(stream);
1244 log_message.PutCString(back_trace.c_str());
1245 }
Greg Claytond61c0fc2012-04-23 22:55:20 +00001246 log->PutCString(log_message.GetString().c_str());
1247 }
1248}
1249
Greg Claytonc982b3d2011-11-28 01:45:00 +00001250void
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001251Module::Dump(Stream *s)
1252{
1253 Mutex::Locker locker (m_mutex);
Greg Clayton89411422010-10-08 00:21:05 +00001254 //s->Printf("%.*p: ", (int)sizeof(void*) * 2, this);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001255 s->Indent();
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00001256 s->Printf("Module %s%s%s%s\n",
1257 m_file.GetPath().c_str(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001258 m_object_name ? "(" : "",
1259 m_object_name ? m_object_name.GetCString() : "",
1260 m_object_name ? ")" : "");
1261
1262 s->IndentMore();
Michael Sartaina7499c92013-07-01 19:45:50 +00001263
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001264 ObjectFile *objfile = GetObjectFile ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001265 if (objfile)
1266 objfile->Dump(s);
1267
1268 SymbolVendor *symbols = GetSymbolVendor ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001269 if (symbols)
1270 symbols->Dump(s);
1271
1272 s->IndentLess();
1273}
1274
1275
1276TypeList*
1277Module::GetTypeList ()
1278{
1279 SymbolVendor *symbols = GetSymbolVendor ();
1280 if (symbols)
1281 return &symbols->GetTypeList();
1282 return NULL;
1283}
1284
1285const ConstString &
1286Module::GetObjectName() const
1287{
1288 return m_object_name;
1289}
1290
1291ObjectFile *
1292Module::GetObjectFile()
1293{
1294 Mutex::Locker locker (m_mutex);
Greg Claytone83e7312010-09-07 23:40:05 +00001295 if (m_did_load_objfile == false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001296 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001297 Timer scoped_timer(__PRETTY_FUNCTION__,
1298 "Module::GetObjectFile () module = %s", GetFileSpec().GetFilename().AsCString(""));
Greg Clayton5ce9c562013-02-06 17:22:03 +00001299 DataBufferSP data_sp;
1300 lldb::offset_t data_offset = 0;
Greg Clayton2540a8a2013-07-12 22:07:46 +00001301 const lldb::offset_t file_size = m_file.GetByteSize();
1302 if (file_size > m_object_offset)
Greg Clayton593577a2011-09-21 03:57:31 +00001303 {
Greg Clayton2540a8a2013-07-12 22:07:46 +00001304 m_did_load_objfile = true;
1305 m_objfile_sp = ObjectFile::FindPlugin (shared_from_this(),
1306 &m_file,
1307 m_object_offset,
1308 file_size - m_object_offset,
1309 data_sp,
1310 data_offset);
1311 if (m_objfile_sp)
1312 {
Zachary Turner5e6f4522015-01-22 18:59:05 +00001313 // Once we get the object file, update our module with the object file's
Greg Clayton2540a8a2013-07-12 22:07:46 +00001314 // architecture since it might differ in vendor/os if some parts were
Zachary Turner5e6f4522015-01-22 18:59:05 +00001315 // unknown. But since the matching arch might already be more specific
1316 // than the generic COFF architecture, only merge in those values that
1317 // overwrite unspecified unknown values.
1318 ArchSpec new_arch;
1319 m_objfile_sp->GetArchitecture(new_arch);
1320 m_arch.MergeFrom(new_arch);
Greg Clayton2540a8a2013-07-12 22:07:46 +00001321 }
Todd Fiala0ee56ce2014-09-05 14:48:49 +00001322 else
1323 {
1324 ReportError ("failed to load objfile for %s", GetFileSpec().GetPath().c_str());
1325 }
Greg Clayton593577a2011-09-21 03:57:31 +00001326 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001327 }
Greg Clayton762f7132011-09-18 18:59:15 +00001328 return m_objfile_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001329}
1330
Michael Sartaina7499c92013-07-01 19:45:50 +00001331SectionList *
Greg Clayton3046e662013-07-10 01:23:25 +00001332Module::GetSectionList()
1333{
1334 // Populate m_unified_sections_ap with sections from objfile.
1335 if (m_sections_ap.get() == NULL)
1336 {
1337 ObjectFile *obj_file = GetObjectFile();
1338 if (obj_file)
1339 obj_file->CreateSections(*GetUnifiedSectionList());
1340 }
1341 return m_sections_ap.get();
1342}
1343
Jason Molenda05a09c62014-08-22 02:46:46 +00001344void
1345Module::SectionFileAddressesChanged ()
1346{
1347 ObjectFile *obj_file = GetObjectFile ();
1348 if (obj_file)
1349 obj_file->SectionFileAddressesChanged ();
1350 SymbolVendor* sym_vendor = GetSymbolVendor();
1351 if (sym_vendor)
1352 sym_vendor->SectionFileAddressesChanged ();
1353}
1354
Greg Clayton3046e662013-07-10 01:23:25 +00001355SectionList *
Michael Sartaina7499c92013-07-01 19:45:50 +00001356Module::GetUnifiedSectionList()
1357{
Greg Clayton3046e662013-07-10 01:23:25 +00001358 // Populate m_unified_sections_ap with sections from objfile.
1359 if (m_sections_ap.get() == NULL)
1360 m_sections_ap.reset(new SectionList());
1361 return m_sections_ap.get();
Michael Sartaina7499c92013-07-01 19:45:50 +00001362}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001363
1364const Symbol *
1365Module::FindFirstSymbolWithNameAndType (const ConstString &name, SymbolType symbol_type)
1366{
1367 Timer scoped_timer(__PRETTY_FUNCTION__,
1368 "Module::FindFirstSymbolWithNameAndType (name = %s, type = %i)",
1369 name.AsCString(),
1370 symbol_type);
Michael Sartaina7499c92013-07-01 19:45:50 +00001371 SymbolVendor* sym_vendor = GetSymbolVendor();
1372 if (sym_vendor)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001373 {
Michael Sartaina7499c92013-07-01 19:45:50 +00001374 Symtab *symtab = sym_vendor->GetSymtab();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001375 if (symtab)
Greg Claytonbcf2cfb2010-09-11 03:13:28 +00001376 return symtab->FindFirstSymbolWithNameAndType (name, symbol_type, Symtab::eDebugAny, Symtab::eVisibilityAny);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001377 }
1378 return NULL;
1379}
1380void
1381Module::SymbolIndicesToSymbolContextList (Symtab *symtab, std::vector<uint32_t> &symbol_indexes, SymbolContextList &sc_list)
1382{
1383 // No need to protect this call using m_mutex all other method calls are
1384 // already thread safe.
1385
1386 size_t num_indices = symbol_indexes.size();
1387 if (num_indices > 0)
1388 {
1389 SymbolContext sc;
1390 CalculateSymbolContext (&sc);
1391 for (size_t i = 0; i < num_indices; i++)
1392 {
1393 sc.symbol = symtab->SymbolAtIndex (symbol_indexes[i]);
1394 if (sc.symbol)
1395 sc_list.Append (sc);
1396 }
1397 }
1398}
1399
1400size_t
Greg Claytonc1b2ccf2013-01-08 00:01:36 +00001401Module::FindFunctionSymbols (const ConstString &name,
1402 uint32_t name_type_mask,
1403 SymbolContextList& sc_list)
1404{
1405 Timer scoped_timer(__PRETTY_FUNCTION__,
1406 "Module::FindSymbolsFunctions (name = %s, mask = 0x%8.8x)",
1407 name.AsCString(),
1408 name_type_mask);
Michael Sartaina7499c92013-07-01 19:45:50 +00001409 SymbolVendor* sym_vendor = GetSymbolVendor();
1410 if (sym_vendor)
Greg Claytonc1b2ccf2013-01-08 00:01:36 +00001411 {
Michael Sartaina7499c92013-07-01 19:45:50 +00001412 Symtab *symtab = sym_vendor->GetSymtab();
Greg Claytonc1b2ccf2013-01-08 00:01:36 +00001413 if (symtab)
1414 return symtab->FindFunctionSymbols (name, name_type_mask, sc_list);
1415 }
1416 return 0;
1417}
1418
1419size_t
Sean Callananb96ff332011-10-13 16:49:47 +00001420Module::FindSymbolsWithNameAndType (const ConstString &name, SymbolType symbol_type, SymbolContextList &sc_list)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001421{
1422 // No need to protect this call using m_mutex all other method calls are
1423 // already thread safe.
1424
1425
1426 Timer scoped_timer(__PRETTY_FUNCTION__,
1427 "Module::FindSymbolsWithNameAndType (name = %s, type = %i)",
1428 name.AsCString(),
1429 symbol_type);
1430 const size_t initial_size = sc_list.GetSize();
Michael Sartaina7499c92013-07-01 19:45:50 +00001431 SymbolVendor* sym_vendor = GetSymbolVendor();
1432 if (sym_vendor)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001433 {
Michael Sartaina7499c92013-07-01 19:45:50 +00001434 Symtab *symtab = sym_vendor->GetSymtab();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001435 if (symtab)
1436 {
1437 std::vector<uint32_t> symbol_indexes;
1438 symtab->FindAllSymbolsWithNameAndType (name, symbol_type, symbol_indexes);
1439 SymbolIndicesToSymbolContextList (symtab, symbol_indexes, sc_list);
1440 }
1441 }
1442 return sc_list.GetSize() - initial_size;
1443}
1444
1445size_t
1446Module::FindSymbolsMatchingRegExAndType (const RegularExpression &regex, SymbolType symbol_type, SymbolContextList &sc_list)
1447{
1448 // No need to protect this call using m_mutex all other method calls are
1449 // already thread safe.
1450
1451 Timer scoped_timer(__PRETTY_FUNCTION__,
1452 "Module::FindSymbolsMatchingRegExAndType (regex = %s, type = %i)",
1453 regex.GetText(),
1454 symbol_type);
1455 const size_t initial_size = sc_list.GetSize();
Michael Sartaina7499c92013-07-01 19:45:50 +00001456 SymbolVendor* sym_vendor = GetSymbolVendor();
1457 if (sym_vendor)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001458 {
Michael Sartaina7499c92013-07-01 19:45:50 +00001459 Symtab *symtab = sym_vendor->GetSymtab();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001460 if (symtab)
1461 {
1462 std::vector<uint32_t> symbol_indexes;
Greg Claytonbcf2cfb2010-09-11 03:13:28 +00001463 symtab->FindAllSymbolsMatchingRexExAndType (regex, symbol_type, Symtab::eDebugAny, Symtab::eVisibilityAny, symbol_indexes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001464 SymbolIndicesToSymbolContextList (symtab, symbol_indexes, sc_list);
1465 }
1466 }
1467 return sc_list.GetSize() - initial_size;
1468}
1469
Greg Claytone01e07b2013-04-18 18:10:51 +00001470void
1471Module::SetSymbolFileFileSpec (const FileSpec &file)
1472{
Michael Sartaina7499c92013-07-01 19:45:50 +00001473 // Remove any sections in the unified section list that come from the current symbol vendor.
1474 if (m_symfile_ap)
1475 {
Greg Clayton3046e662013-07-10 01:23:25 +00001476 SectionList *section_list = GetSectionList();
Michael Sartaina7499c92013-07-01 19:45:50 +00001477 SymbolFile *symbol_file = m_symfile_ap->GetSymbolFile();
1478 if (section_list && symbol_file)
1479 {
1480 ObjectFile *obj_file = symbol_file->GetObjectFile();
Greg Clayton540fbbf2013-08-13 16:46:35 +00001481 // Make sure we have an object file and that the symbol vendor's objfile isn't
1482 // the same as the module's objfile before we remove any sections for it...
1483 if (obj_file && obj_file != m_objfile_sp.get())
Michael Sartaina7499c92013-07-01 19:45:50 +00001484 {
1485 size_t num_sections = section_list->GetNumSections (0);
1486 for (size_t idx = num_sections; idx > 0; --idx)
1487 {
1488 lldb::SectionSP section_sp (section_list->GetSectionAtIndex (idx - 1));
1489 if (section_sp->GetObjectFile() == obj_file)
1490 {
Greg Clayton3046e662013-07-10 01:23:25 +00001491 section_list->DeleteSection (idx - 1);
Michael Sartaina7499c92013-07-01 19:45:50 +00001492 }
1493 }
Michael Sartaina7499c92013-07-01 19:45:50 +00001494 }
1495 }
1496 }
1497
Greg Claytone01e07b2013-04-18 18:10:51 +00001498 m_symfile_spec = file;
1499 m_symfile_ap.reset();
1500 m_did_load_symbol_vendor = false;
1501}
1502
Jim Ingham5aee1622010-08-09 23:31:02 +00001503bool
1504Module::IsExecutable ()
1505{
1506 if (GetObjectFile() == NULL)
1507 return false;
1508 else
1509 return GetObjectFile()->IsExecutable();
1510}
1511
Jim Inghamb53cb272011-08-03 01:03:17 +00001512bool
1513Module::IsLoadedInTarget (Target *target)
1514{
1515 ObjectFile *obj_file = GetObjectFile();
1516 if (obj_file)
1517 {
Greg Clayton3046e662013-07-10 01:23:25 +00001518 SectionList *sections = GetSectionList();
Jim Inghamb53cb272011-08-03 01:03:17 +00001519 if (sections != NULL)
1520 {
1521 size_t num_sections = sections->GetSize();
Jim Inghamb53cb272011-08-03 01:03:17 +00001522 for (size_t sect_idx = 0; sect_idx < num_sections; sect_idx++)
1523 {
1524 SectionSP section_sp = sections->GetSectionAtIndex(sect_idx);
1525 if (section_sp->GetLoadBaseAddress(target) != LLDB_INVALID_ADDRESS)
1526 {
1527 return true;
1528 }
1529 }
1530 }
1531 }
1532 return false;
1533}
Enrico Granata17598482012-11-08 02:22:02 +00001534
1535bool
Enrico Granata97303392013-05-21 00:00:30 +00001536Module::LoadScriptingResourceInTarget (Target *target, Error& error, Stream* feedback_stream)
Enrico Granata17598482012-11-08 02:22:02 +00001537{
1538 if (!target)
1539 {
1540 error.SetErrorString("invalid destination Target");
1541 return false;
1542 }
1543
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00001544 LoadScriptFromSymFile should_load = target->TargetProperties::GetLoadScriptFromSymbolFile();
Enrico Granata2ea43cd2013-05-13 17:03:52 +00001545
Greg Clayton994740f2014-08-18 21:08:44 +00001546 if (should_load == eLoadScriptFromSymFileFalse)
1547 return false;
1548
Greg Clayton91c0e742013-01-11 23:44:27 +00001549 Debugger &debugger = target->GetDebugger();
1550 const ScriptLanguage script_language = debugger.GetScriptLanguage();
1551 if (script_language != eScriptLanguageNone)
Enrico Granata17598482012-11-08 02:22:02 +00001552 {
Greg Clayton91c0e742013-01-11 23:44:27 +00001553
1554 PlatformSP platform_sp(target->GetPlatform());
1555
1556 if (!platform_sp)
1557 {
1558 error.SetErrorString("invalid Platform");
1559 return false;
1560 }
Enrico Granata17598482012-11-08 02:22:02 +00001561
Greg Claytonb9d88902013-03-23 00:50:58 +00001562 FileSpecList file_specs = platform_sp->LocateExecutableScriptingResources (target,
Enrico Granatafe7295d2014-08-16 00:32:58 +00001563 *this,
1564 feedback_stream);
Greg Claytonb9d88902013-03-23 00:50:58 +00001565
1566
1567 const uint32_t num_specs = file_specs.GetSize();
1568 if (num_specs)
Enrico Granata17598482012-11-08 02:22:02 +00001569 {
Greg Claytonb9d88902013-03-23 00:50:58 +00001570 ScriptInterpreter *script_interpreter = debugger.GetCommandInterpreter().GetScriptInterpreter();
1571 if (script_interpreter)
Greg Clayton91c0e742013-01-11 23:44:27 +00001572 {
1573 for (uint32_t i=0; i<num_specs; ++i)
1574 {
1575 FileSpec scripting_fspec (file_specs.GetFileSpecAtIndex(i));
1576 if (scripting_fspec && scripting_fspec.Exists())
1577 {
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00001578 if (should_load == eLoadScriptFromSymFileWarn)
Enrico Granata2ea43cd2013-05-13 17:03:52 +00001579 {
Enrico Granata397ddd52013-05-21 20:13:34 +00001580 if (feedback_stream)
Jim Inghamd516deb2013-07-01 18:49:43 +00001581 feedback_stream->Printf("warning: '%s' contains a debug script. To run this script in "
1582 "this debug session:\n\n command script import \"%s\"\n\n"
1583 "To run all discovered debug scripts in this session:\n\n"
1584 " settings set target.load-script-from-symbol-file true\n",
1585 GetFileSpec().GetFileNameStrippingExtension().GetCString(),
1586 scripting_fspec.GetPath().c_str());
Enrico Granata2ea43cd2013-05-13 17:03:52 +00001587 return false;
1588 }
Greg Clayton91c0e742013-01-11 23:44:27 +00001589 StreamString scripting_stream;
1590 scripting_fspec.Dump(&scripting_stream);
Enrico Granatae0c70f12013-05-31 01:03:09 +00001591 const bool can_reload = true;
Greg Clayton91c0e742013-01-11 23:44:27 +00001592 const bool init_lldb_globals = false;
Jim Inghamd516deb2013-07-01 18:49:43 +00001593 bool did_load = script_interpreter->LoadScriptingModule(scripting_stream.GetData(),
1594 can_reload,
1595 init_lldb_globals,
1596 error);
Greg Clayton91c0e742013-01-11 23:44:27 +00001597 if (!did_load)
1598 return false;
1599 }
1600 }
1601 }
Greg Claytonb9d88902013-03-23 00:50:58 +00001602 else
1603 {
1604 error.SetErrorString("invalid ScriptInterpreter");
1605 return false;
1606 }
Enrico Granata17598482012-11-08 02:22:02 +00001607 }
1608 }
1609 return true;
1610}
1611
1612bool
Jim Ingham5aee1622010-08-09 23:31:02 +00001613Module::SetArchitecture (const ArchSpec &new_arch)
1614{
Greg Clayton64195a22011-02-23 00:35:02 +00001615 if (!m_arch.IsValid())
Jim Ingham5aee1622010-08-09 23:31:02 +00001616 {
1617 m_arch = new_arch;
1618 return true;
Greg Clayton64195a22011-02-23 00:35:02 +00001619 }
Chaoren Linb6cd5fe2015-02-26 22:15:16 +00001620 return m_arch.IsCompatibleMatch(new_arch);
Jim Ingham5aee1622010-08-09 23:31:02 +00001621}
1622
Greg Claytonc9660542012-02-05 02:38:54 +00001623bool
Greg Clayton751caf62014-02-07 22:54:47 +00001624Module::SetLoadAddress (Target &target, lldb::addr_t value, bool value_is_offset, bool &changed)
Greg Claytonc9660542012-02-05 02:38:54 +00001625{
Steve Pucci9e02dac2014-02-06 19:02:19 +00001626 ObjectFile *object_file = GetObjectFile();
1627 if (object_file)
Greg Claytonc9660542012-02-05 02:38:54 +00001628 {
Greg Clayton751caf62014-02-07 22:54:47 +00001629 changed = object_file->SetLoadAddress(target, value, value_is_offset);
Greg Clayton7524e092014-02-06 20:10:16 +00001630 return true;
1631 }
1632 else
1633 {
1634 changed = false;
Greg Claytonc9660542012-02-05 02:38:54 +00001635 }
Steve Pucci9e02dac2014-02-06 19:02:19 +00001636 return false;
Greg Claytonc9660542012-02-05 02:38:54 +00001637}
1638
Greg Claytonb9a01b32012-02-26 05:51:37 +00001639
1640bool
1641Module::MatchesModuleSpec (const ModuleSpec &module_ref)
1642{
1643 const UUID &uuid = module_ref.GetUUID();
1644
1645 if (uuid.IsValid())
1646 {
1647 // If the UUID matches, then nothing more needs to match...
1648 if (uuid == GetUUID())
1649 return true;
1650 else
1651 return false;
1652 }
1653
1654 const FileSpec &file_spec = module_ref.GetFileSpec();
1655 if (file_spec)
1656 {
Sean Callananddd7a2a2013-10-03 22:27:29 +00001657 if (!FileSpec::Equal (file_spec, m_file, (bool)file_spec.GetDirectory()))
Greg Claytonb9a01b32012-02-26 05:51:37 +00001658 return false;
1659 }
1660
1661 const FileSpec &platform_file_spec = module_ref.GetPlatformFileSpec();
1662 if (platform_file_spec)
1663 {
Sean Callananddd7a2a2013-10-03 22:27:29 +00001664 if (!FileSpec::Equal (platform_file_spec, GetPlatformFileSpec (), (bool)platform_file_spec.GetDirectory()))
Greg Claytonb9a01b32012-02-26 05:51:37 +00001665 return false;
1666 }
1667
1668 const ArchSpec &arch = module_ref.GetArchitecture();
1669 if (arch.IsValid())
1670 {
Sean Callananbf4b7be2012-12-13 22:07:14 +00001671 if (!m_arch.IsCompatibleMatch(arch))
Greg Claytonb9a01b32012-02-26 05:51:37 +00001672 return false;
1673 }
1674
1675 const ConstString &object_name = module_ref.GetObjectName();
1676 if (object_name)
1677 {
1678 if (object_name != GetObjectName())
1679 return false;
1680 }
1681 return true;
1682}
1683
Greg Claytond804d282012-03-15 21:01:31 +00001684bool
1685Module::FindSourceFile (const FileSpec &orig_spec, FileSpec &new_spec) const
1686{
1687 Mutex::Locker locker (m_mutex);
1688 return m_source_mappings.FindFile (orig_spec, new_spec);
1689}
1690
Greg Claytonf9be6932012-03-19 22:22:41 +00001691bool
1692Module::RemapSourceFile (const char *path, std::string &new_path) const
1693{
1694 Mutex::Locker locker (m_mutex);
1695 return m_source_mappings.RemapPath(path, new_path);
1696}
1697
Enrico Granata3467d802012-09-04 18:47:54 +00001698uint32_t
1699Module::GetVersion (uint32_t *versions, uint32_t num_versions)
1700{
1701 ObjectFile *obj_file = GetObjectFile();
1702 if (obj_file)
1703 return obj_file->GetVersion (versions, num_versions);
1704
1705 if (versions && num_versions)
1706 {
1707 for (uint32_t i=0; i<num_versions; ++i)
Enrico Granataafcbdb12014-03-25 20:53:33 +00001708 versions[i] = LLDB_INVALID_MODULE_VERSION;
Enrico Granata3467d802012-09-04 18:47:54 +00001709 }
1710 return 0;
1711}
Greg Clayton43fe2172013-04-03 02:00:15 +00001712
1713void
1714Module::PrepareForFunctionNameLookup (const ConstString &name,
1715 uint32_t name_type_mask,
1716 ConstString &lookup_name,
1717 uint32_t &lookup_name_type_mask,
1718 bool &match_name_after_lookup)
1719{
1720 const char *name_cstr = name.GetCString();
1721 lookup_name_type_mask = eFunctionNameTypeNone;
1722 match_name_after_lookup = false;
Jim Inghamfa39bb42014-10-25 00:33:55 +00001723
1724 llvm::StringRef basename;
1725 llvm::StringRef context;
Greg Clayton43fe2172013-04-03 02:00:15 +00001726
1727 if (name_type_mask & eFunctionNameTypeAuto)
1728 {
1729 if (CPPLanguageRuntime::IsCPPMangledName (name_cstr))
1730 lookup_name_type_mask = eFunctionNameTypeFull;
1731 else if (ObjCLanguageRuntime::IsPossibleObjCMethodName (name_cstr))
1732 lookup_name_type_mask = eFunctionNameTypeFull;
1733 else
1734 {
1735 if (ObjCLanguageRuntime::IsPossibleObjCSelector(name_cstr))
1736 lookup_name_type_mask |= eFunctionNameTypeSelector;
1737
Greg Clayton6ecb2322013-05-18 00:11:21 +00001738 CPPLanguageRuntime::MethodName cpp_method (name);
Jim Inghamfa39bb42014-10-25 00:33:55 +00001739 basename = cpp_method.GetBasename();
Greg Clayton6ecb2322013-05-18 00:11:21 +00001740 if (basename.empty())
1741 {
Jim Inghamfa39bb42014-10-25 00:33:55 +00001742 if (CPPLanguageRuntime::ExtractContextAndIdentifier (name_cstr, context, basename))
Greg Clayton6ecb2322013-05-18 00:11:21 +00001743 lookup_name_type_mask |= (eFunctionNameTypeMethod | eFunctionNameTypeBase);
Greg Claytonc3795402014-10-22 21:47:13 +00001744 else
Greg Clayton65b0e762015-01-28 01:08:39 +00001745 lookup_name_type_mask |= eFunctionNameTypeFull;
Greg Clayton6ecb2322013-05-18 00:11:21 +00001746 }
1747 else
1748 {
Greg Clayton43fe2172013-04-03 02:00:15 +00001749 lookup_name_type_mask |= (eFunctionNameTypeMethod | eFunctionNameTypeBase);
Greg Clayton6ecb2322013-05-18 00:11:21 +00001750 }
Greg Clayton43fe2172013-04-03 02:00:15 +00001751 }
1752 }
1753 else
1754 {
1755 lookup_name_type_mask = name_type_mask;
1756 if (lookup_name_type_mask & eFunctionNameTypeMethod || name_type_mask & eFunctionNameTypeBase)
1757 {
1758 // If they've asked for a CPP method or function name and it can't be that, we don't
1759 // even need to search for CPP methods or names.
Greg Clayton6ecb2322013-05-18 00:11:21 +00001760 CPPLanguageRuntime::MethodName cpp_method (name);
1761 if (cpp_method.IsValid())
Greg Clayton43fe2172013-04-03 02:00:15 +00001762 {
Jim Inghamfa39bb42014-10-25 00:33:55 +00001763 basename = cpp_method.GetBasename();
Greg Clayton6ecb2322013-05-18 00:11:21 +00001764
1765 if (!cpp_method.GetQualifiers().empty())
1766 {
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00001767 // There is a "const" or other qualifier following the end of the function parens,
Greg Clayton6ecb2322013-05-18 00:11:21 +00001768 // this can't be a eFunctionNameTypeBase
1769 lookup_name_type_mask &= ~(eFunctionNameTypeBase);
1770 if (lookup_name_type_mask == eFunctionNameTypeNone)
1771 return;
1772 }
1773 }
1774 else
1775 {
Jim Inghamfa39bb42014-10-25 00:33:55 +00001776 // If the CPP method parser didn't manage to chop this up, try to fill in the base name if we can.
1777 // If a::b::c is passed in, we need to just look up "c", and then we'll filter the result later.
1778 CPPLanguageRuntime::ExtractContextAndIdentifier (name_cstr, context, basename);
Greg Clayton43fe2172013-04-03 02:00:15 +00001779 }
1780 }
1781
1782 if (lookup_name_type_mask & eFunctionNameTypeSelector)
1783 {
1784 if (!ObjCLanguageRuntime::IsPossibleObjCSelector(name_cstr))
1785 {
1786 lookup_name_type_mask &= ~(eFunctionNameTypeSelector);
1787 if (lookup_name_type_mask == eFunctionNameTypeNone)
1788 return;
1789 }
1790 }
1791 }
1792
Jim Inghamfa39bb42014-10-25 00:33:55 +00001793 if (!basename.empty())
Greg Clayton43fe2172013-04-03 02:00:15 +00001794 {
1795 // The name supplied was a partial C++ path like "a::count". In this case we want to do a
1796 // lookup on the basename "count" and then make sure any matching results contain "a::count"
1797 // so that it would match "b::a::count" and "a::count". This is why we set "match_name_after_lookup"
1798 // to true
Jim Inghamfa39bb42014-10-25 00:33:55 +00001799 lookup_name.SetString(basename);
Greg Clayton43fe2172013-04-03 02:00:15 +00001800 match_name_after_lookup = true;
1801 }
1802 else
1803 {
1804 // The name is already correct, just use the exact name as supplied, and we won't need
1805 // to check if any matches contain "name"
1806 lookup_name = name;
1807 match_name_after_lookup = false;
1808 }
Richard Mittonf86248d2013-09-12 02:20:34 +00001809}
Greg Clayton23f8c952014-03-24 23:10:19 +00001810
1811ModuleSP
1812Module::CreateJITModule (const lldb::ObjectFileJITDelegateSP &delegate_sp)
1813{
1814 if (delegate_sp)
1815 {
1816 // Must create a module and place it into a shared pointer before
1817 // we can create an object file since it has a std::weak_ptr back
1818 // to the module, so we need to control the creation carefully in
1819 // this static function
1820 ModuleSP module_sp(new Module());
1821 module_sp->m_objfile_sp.reset (new ObjectFileJIT (module_sp, delegate_sp));
1822 if (module_sp->m_objfile_sp)
1823 {
1824 // Once we get the object file, update our module with the object file's
1825 // architecture since it might differ in vendor/os if some parts were
1826 // unknown.
1827 module_sp->m_objfile_sp->GetArchitecture (module_sp->m_arch);
1828 }
1829 return module_sp;
1830 }
1831 return ModuleSP();
1832}
1833
Greg Clayton08928f32015-02-05 02:01:34 +00001834bool
1835Module::GetIsDynamicLinkEditor()
1836{
1837 ObjectFile * obj_file = GetObjectFile ();
1838
1839 if (obj_file)
1840 return obj_file->GetIsDynamicLinkEditor();
1841
1842 return false;
1843}