blob: 2a1663be5cc1b5b7408bd1f5e89358eea5f3a376 [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
Chris Lattner30fdc8d2010-06-08 16:52:24 +000043using namespace lldb;
44using namespace lldb_private;
45
Greg Clayton65a03992011-08-09 00:01:09 +000046// Shared pointers to modules track module lifetimes in
47// targets and in the global module, but this collection
48// will track all module objects that are still alive
49typedef std::vector<Module *> ModuleCollection;
50
51static ModuleCollection &
52GetModuleCollection()
53{
Jim Ingham549f7372011-10-31 23:47:10 +000054 // This module collection needs to live past any module, so we could either make it a
55 // shared pointer in each module or just leak is. Since it is only an empty vector by
56 // the time all the modules have gone away, we just leak it for now. If we decide this
57 // is a big problem we can introduce a Finalize method that will tear everything down in
58 // a predictable order.
59
60 static ModuleCollection *g_module_collection = NULL;
61 if (g_module_collection == NULL)
62 g_module_collection = new ModuleCollection();
63
64 return *g_module_collection;
Greg Clayton65a03992011-08-09 00:01:09 +000065}
66
Greg Claytonb26e6be2012-01-27 18:08:35 +000067Mutex *
Greg Clayton65a03992011-08-09 00:01:09 +000068Module::GetAllocationModuleCollectionMutex()
69{
Greg Claytonb26e6be2012-01-27 18:08:35 +000070 // NOTE: The mutex below must be leaked since the global module list in
71 // the ModuleList class will get torn at some point, and we can't know
72 // if it will tear itself down before the "g_module_collection_mutex" below
73 // will. So we leak a Mutex object below to safeguard against that
74
75 static Mutex *g_module_collection_mutex = NULL;
76 if (g_module_collection_mutex == NULL)
77 g_module_collection_mutex = new Mutex (Mutex::eMutexTypeRecursive); // NOTE: known leak
78 return g_module_collection_mutex;
Greg Clayton65a03992011-08-09 00:01:09 +000079}
80
81size_t
82Module::GetNumberAllocatedModules ()
83{
84 Mutex::Locker locker (GetAllocationModuleCollectionMutex());
85 return GetModuleCollection().size();
86}
87
88Module *
89Module::GetAllocatedModuleAtIndex (size_t idx)
90{
91 Mutex::Locker locker (GetAllocationModuleCollectionMutex());
92 ModuleCollection &modules = GetModuleCollection();
93 if (idx < modules.size())
94 return modules[idx];
95 return NULL;
96}
Greg Clayton29ad7b92012-01-27 18:45:39 +000097#if 0
Greg Clayton65a03992011-08-09 00:01:09 +000098
Greg Clayton29ad7b92012-01-27 18:45:39 +000099// These functions help us to determine if modules are still loaded, yet don't require that
100// you have a command interpreter and can easily be called from an external debugger.
101namespace lldb {
Greg Clayton65a03992011-08-09 00:01:09 +0000102
Greg Clayton29ad7b92012-01-27 18:45:39 +0000103 void
104 ClearModuleInfo (void)
105 {
Greg Clayton0cd70862012-04-09 20:22:01 +0000106 const bool mandatory = true;
107 ModuleList::RemoveOrphanSharedModules(mandatory);
Greg Clayton29ad7b92012-01-27 18:45:39 +0000108 }
109
110 void
111 DumpModuleInfo (void)
112 {
113 Mutex::Locker locker (Module::GetAllocationModuleCollectionMutex());
114 ModuleCollection &modules = GetModuleCollection();
115 const size_t count = modules.size();
Daniel Malead01b2952012-11-29 21:49:15 +0000116 printf ("%s: %" PRIu64 " modules:\n", __PRETTY_FUNCTION__, (uint64_t)count);
Greg Clayton29ad7b92012-01-27 18:45:39 +0000117 for (size_t i=0; i<count; ++i)
118 {
119
120 StreamString strm;
121 Module *module = modules[i];
122 const bool in_shared_module_list = ModuleList::ModuleIsInCache (module);
123 module->GetDescription(&strm, eDescriptionLevelFull);
124 printf ("%p: shared = %i, ref_count = %3u, module = %s\n",
125 module,
126 in_shared_module_list,
127 (uint32_t)module->use_count(),
128 strm.GetString().c_str());
129 }
130 }
131}
132
133#endif
Greg Clayton3a18e312012-10-08 22:41:53 +0000134
Greg Claytonb9a01b32012-02-26 05:51:37 +0000135Module::Module (const ModuleSpec &module_spec) :
136 m_mutex (Mutex::eMutexTypeRecursive),
Greg Clayton34f11592014-03-04 21:20:23 +0000137 m_mod_time (),
138 m_arch (),
Greg Claytonb9a01b32012-02-26 05:51:37 +0000139 m_uuid (),
Greg Clayton34f11592014-03-04 21:20:23 +0000140 m_file (),
141 m_platform_file(),
Greg Claytonfbb76342013-11-20 21:07:01 +0000142 m_remote_install_file(),
Greg Clayton34f11592014-03-04 21:20:23 +0000143 m_symfile_spec (),
144 m_object_name (),
145 m_object_offset (),
146 m_object_mod_time (),
Greg Claytonb9a01b32012-02-26 05:51:37 +0000147 m_objfile_sp (),
148 m_symfile_ap (),
Zachary Turner88c6b622015-03-03 18:34:26 +0000149 m_ast (new ClangASTContext),
Greg Claytond804d282012-03-15 21:01:31 +0000150 m_source_mappings (),
Greg Clayton23f8c952014-03-24 23:10:19 +0000151 m_sections_ap(),
Greg Claytonb9a01b32012-02-26 05:51:37 +0000152 m_did_load_objfile (false),
153 m_did_load_symbol_vendor (false),
154 m_did_parse_uuid (false),
155 m_did_init_ast (false),
Greg Clayton1d609092012-07-12 22:51:12 +0000156 m_file_has_changed (false),
157 m_first_file_changed_log (false)
Greg Claytonb9a01b32012-02-26 05:51:37 +0000158{
159 // Scope for locker below...
160 {
161 Mutex::Locker locker (GetAllocationModuleCollectionMutex());
162 GetModuleCollection().push_back(this);
163 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000164
Greg Clayton5160ce52013-03-27 23:08:40 +0000165 Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_OBJECT|LIBLLDB_LOG_MODULES));
Greg Claytonb9a01b32012-02-26 05:51:37 +0000166 if (log)
Greg Claytonb5ad4ec2013-04-29 17:25:54 +0000167 log->Printf ("%p Module::Module((%s) '%s%s%s%s')",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000168 static_cast<void*>(this),
Greg Clayton34f11592014-03-04 21:20:23 +0000169 module_spec.GetArchitecture().GetArchitectureName(),
170 module_spec.GetFileSpec().GetPath().c_str(),
171 module_spec.GetObjectName().IsEmpty() ? "" : "(",
172 module_spec.GetObjectName().IsEmpty() ? "" : module_spec.GetObjectName().AsCString(""),
173 module_spec.GetObjectName().IsEmpty() ? "" : ")");
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000174
Greg Clayton34f11592014-03-04 21:20:23 +0000175 // First extract all module specifications from the file using the local
176 // file path. If there are no specifications, then don't fill anything in
177 ModuleSpecList modules_specs;
178 if (ObjectFile::GetModuleSpecifications(module_spec.GetFileSpec(), 0, 0, modules_specs) == 0)
179 return;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000180
Greg Clayton34f11592014-03-04 21:20:23 +0000181 // Now make sure that one of the module specifications matches what we just
182 // extract. We might have a module specification that specifies a file "/usr/lib/dyld"
183 // with UUID XXX, but we might have a local version of "/usr/lib/dyld" that has
184 // UUID YYY and we don't want those to match. If they don't match, just don't
185 // fill any ivars in so we don't accidentally grab the wrong file later since
186 // they don't match...
187 ModuleSpec matching_module_spec;
188 if (modules_specs.FindMatchingModuleSpec(module_spec, matching_module_spec) == 0)
189 return;
Greg Clayton7ab7f892014-05-29 21:33:45 +0000190
191 if (module_spec.GetFileSpec())
192 m_mod_time = module_spec.GetFileSpec().GetModificationTime();
193 else if (matching_module_spec.GetFileSpec())
194 m_mod_time = matching_module_spec.GetFileSpec().GetModificationTime();
195
196 // Copy the architecture from the actual spec if we got one back, else use the one that was specified
197 if (matching_module_spec.GetArchitecture().IsValid())
Greg Clayton34f11592014-03-04 21:20:23 +0000198 m_arch = matching_module_spec.GetArchitecture();
Greg Clayton7ab7f892014-05-29 21:33:45 +0000199 else if (module_spec.GetArchitecture().IsValid())
200 m_arch = module_spec.GetArchitecture();
201
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +0000202 // Copy the file spec over and use the specified one (if there was one) so we
Greg Clayton7ab7f892014-05-29 21:33:45 +0000203 // don't use a path that might have gotten resolved a path in 'matching_module_spec'
204 if (module_spec.GetFileSpec())
205 m_file = module_spec.GetFileSpec();
206 else if (matching_module_spec.GetFileSpec())
207 m_file = matching_module_spec.GetFileSpec();
208
209 // Copy the platform file spec over
210 if (module_spec.GetPlatformFileSpec())
211 m_platform_file = module_spec.GetPlatformFileSpec();
212 else if (matching_module_spec.GetPlatformFileSpec())
213 m_platform_file = matching_module_spec.GetPlatformFileSpec();
214
215 // Copy the symbol file spec over
216 if (module_spec.GetSymbolFileSpec())
217 m_symfile_spec = module_spec.GetSymbolFileSpec();
218 else if (matching_module_spec.GetSymbolFileSpec())
219 m_symfile_spec = matching_module_spec.GetSymbolFileSpec();
220
221 // Copy the object name over
222 if (matching_module_spec.GetObjectName())
223 m_object_name = matching_module_spec.GetObjectName();
224 else
225 m_object_name = module_spec.GetObjectName();
226
227 // Always trust the object offset (file offset) and object modification
228 // time (for mod time in a BSD static archive) of from the matching
229 // module specification
Greg Clayton36d7c892014-05-29 17:52:46 +0000230 m_object_offset = matching_module_spec.GetObjectOffset();
231 m_object_mod_time = matching_module_spec.GetObjectModificationTime();
Greg Clayton34f11592014-03-04 21:20:23 +0000232
Greg Claytonb9a01b32012-02-26 05:51:37 +0000233}
234
Greg Claytone72dfb32012-02-24 01:59:29 +0000235Module::Module(const FileSpec& file_spec,
236 const ArchSpec& arch,
237 const ConstString *object_name,
Zachary Turnera746e8e2014-07-02 17:24:07 +0000238 lldb::offset_t object_offset,
Greg Clayton57abc5d2013-05-10 21:47:16 +0000239 const TimeValue *object_mod_time_ptr) :
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000240 m_mutex (Mutex::eMutexTypeRecursive),
241 m_mod_time (file_spec.GetModificationTime()),
242 m_arch (arch),
243 m_uuid (),
244 m_file (file_spec),
Greg Clayton32e0a752011-03-30 18:16:51 +0000245 m_platform_file(),
Greg Claytonfbb76342013-11-20 21:07:01 +0000246 m_remote_install_file (),
Greg Claytone72dfb32012-02-24 01:59:29 +0000247 m_symfile_spec (),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000248 m_object_name (),
Greg Clayton8b82f082011-04-12 05:54:46 +0000249 m_object_offset (object_offset),
Greg Clayton57abc5d2013-05-10 21:47:16 +0000250 m_object_mod_time (),
Greg Clayton762f7132011-09-18 18:59:15 +0000251 m_objfile_sp (),
Greg Claytone83e7312010-09-07 23:40:05 +0000252 m_symfile_ap (),
Zachary Turner88c6b622015-03-03 18:34:26 +0000253 m_ast (new ClangASTContext),
Greg Claytond804d282012-03-15 21:01:31 +0000254 m_source_mappings (),
Greg Clayton23f8c952014-03-24 23:10:19 +0000255 m_sections_ap(),
Greg Claytone83e7312010-09-07 23:40:05 +0000256 m_did_load_objfile (false),
257 m_did_load_symbol_vendor (false),
258 m_did_parse_uuid (false),
Greg Clayton6beaaa62011-01-17 03:46:26 +0000259 m_did_init_ast (false),
Greg Clayton1d609092012-07-12 22:51:12 +0000260 m_file_has_changed (false),
261 m_first_file_changed_log (false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000262{
Greg Clayton65a03992011-08-09 00:01:09 +0000263 // Scope for locker below...
264 {
265 Mutex::Locker locker (GetAllocationModuleCollectionMutex());
266 GetModuleCollection().push_back(this);
267 }
268
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000269 if (object_name)
270 m_object_name = *object_name;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000271
Greg Clayton57abc5d2013-05-10 21:47:16 +0000272 if (object_mod_time_ptr)
273 m_object_mod_time = *object_mod_time_ptr;
274
Greg Clayton5160ce52013-03-27 23:08:40 +0000275 Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_OBJECT|LIBLLDB_LOG_MODULES));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000276 if (log)
Greg Claytonb5ad4ec2013-04-29 17:25:54 +0000277 log->Printf ("%p Module::Module((%s) '%s%s%s%s')",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000278 static_cast<void*>(this), m_arch.GetArchitectureName(),
Greg Claytonb5ad4ec2013-04-29 17:25:54 +0000279 m_file.GetPath().c_str(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000280 m_object_name.IsEmpty() ? "" : "(",
281 m_object_name.IsEmpty() ? "" : m_object_name.AsCString(""),
282 m_object_name.IsEmpty() ? "" : ")");
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000283}
284
Greg Clayton23f8c952014-03-24 23:10:19 +0000285Module::Module () :
286 m_mutex (Mutex::eMutexTypeRecursive),
287 m_mod_time (),
288 m_arch (),
289 m_uuid (),
290 m_file (),
291 m_platform_file(),
292 m_remote_install_file (),
293 m_symfile_spec (),
294 m_object_name (),
295 m_object_offset (0),
296 m_object_mod_time (),
297 m_objfile_sp (),
298 m_symfile_ap (),
Zachary Turner88c6b622015-03-03 18:34:26 +0000299 m_ast (new ClangASTContext),
Greg Clayton23f8c952014-03-24 23:10:19 +0000300 m_source_mappings (),
301 m_sections_ap(),
302 m_did_load_objfile (false),
303 m_did_load_symbol_vendor (false),
304 m_did_parse_uuid (false),
305 m_did_init_ast (false),
Greg Clayton23f8c952014-03-24 23:10:19 +0000306 m_file_has_changed (false),
307 m_first_file_changed_log (false)
308{
309 Mutex::Locker locker (GetAllocationModuleCollectionMutex());
310 GetModuleCollection().push_back(this);
311}
312
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000313Module::~Module()
314{
Greg Clayton217b28b2013-05-22 20:13:22 +0000315 // Lock our module down while we tear everything down to make sure
316 // we don't get any access to the module while it is being destroyed
317 Mutex::Locker locker (m_mutex);
Greg Clayton65a03992011-08-09 00:01:09 +0000318 // Scope for locker below...
319 {
320 Mutex::Locker locker (GetAllocationModuleCollectionMutex());
321 ModuleCollection &modules = GetModuleCollection();
322 ModuleCollection::iterator end = modules.end();
323 ModuleCollection::iterator pos = std::find(modules.begin(), end, this);
Greg Clayton3a18e312012-10-08 22:41:53 +0000324 assert (pos != end);
325 modules.erase(pos);
Greg Clayton65a03992011-08-09 00:01:09 +0000326 }
Greg Clayton5160ce52013-03-27 23:08:40 +0000327 Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_OBJECT|LIBLLDB_LOG_MODULES));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000328 if (log)
Greg Claytonb5ad4ec2013-04-29 17:25:54 +0000329 log->Printf ("%p Module::~Module((%s) '%s%s%s%s')",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000330 static_cast<void*>(this),
Greg Clayton64195a22011-02-23 00:35:02 +0000331 m_arch.GetArchitectureName(),
Greg Claytonb5ad4ec2013-04-29 17:25:54 +0000332 m_file.GetPath().c_str(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000333 m_object_name.IsEmpty() ? "" : "(",
334 m_object_name.IsEmpty() ? "" : m_object_name.AsCString(""),
335 m_object_name.IsEmpty() ? "" : ")");
Greg Clayton6beaaa62011-01-17 03:46:26 +0000336 // Release any auto pointers before we start tearing down our member
337 // variables since the object file and symbol files might need to make
338 // function calls back into this module object. The ordering is important
339 // here because symbol files can require the module object file. So we tear
340 // down the symbol file first, then the object file.
Greg Clayton3046e662013-07-10 01:23:25 +0000341 m_sections_ap.reset();
Greg Clayton6beaaa62011-01-17 03:46:26 +0000342 m_symfile_ap.reset();
Greg Clayton762f7132011-09-18 18:59:15 +0000343 m_objfile_sp.reset();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000344}
345
Greg Claytonc7f09cc2012-02-24 21:55:59 +0000346ObjectFile *
Andrew MacPherson17220c12014-03-05 10:12:43 +0000347Module::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 +0000348{
349 if (m_objfile_sp)
350 {
351 error.SetErrorString ("object file already exists");
352 }
353 else
354 {
355 Mutex::Locker locker (m_mutex);
356 if (process_sp)
357 {
Greg Claytonc7f09cc2012-02-24 21:55:59 +0000358 m_did_load_objfile = true;
Andrew MacPherson17220c12014-03-05 10:12:43 +0000359 std::unique_ptr<DataBufferHeap> data_ap (new DataBufferHeap (size_to_read, 0));
Greg Claytonc7f09cc2012-02-24 21:55:59 +0000360 Error readmem_error;
361 const size_t bytes_read = process_sp->ReadMemory (header_addr,
362 data_ap->GetBytes(),
363 data_ap->GetByteSize(),
364 readmem_error);
Andrew MacPherson17220c12014-03-05 10:12:43 +0000365 if (bytes_read == size_to_read)
Greg Claytonc7f09cc2012-02-24 21:55:59 +0000366 {
367 DataBufferSP data_sp(data_ap.release());
368 m_objfile_sp = ObjectFile::FindPlugin(shared_from_this(), process_sp, header_addr, data_sp);
369 if (m_objfile_sp)
370 {
Greg Clayton3e10cf32012-04-20 19:50:20 +0000371 StreamString s;
Daniel Malead01b2952012-11-29 21:49:15 +0000372 s.Printf("0x%16.16" PRIx64, header_addr);
Greg Clayton3e10cf32012-04-20 19:50:20 +0000373 m_object_name.SetCString (s.GetData());
374
375 // Once we get the object file, update our module with the object file's
Greg Claytonc7f09cc2012-02-24 21:55:59 +0000376 // architecture since it might differ in vendor/os if some parts were
377 // unknown.
378 m_objfile_sp->GetArchitecture (m_arch);
379 }
380 else
381 {
382 error.SetErrorString ("unable to find suitable object file plug-in");
383 }
384 }
385 else
386 {
387 error.SetErrorStringWithFormat ("unable to read header from memory: %s", readmem_error.AsCString());
388 }
389 }
390 else
391 {
392 error.SetErrorString ("invalid process");
393 }
394 }
395 return m_objfile_sp.get();
396}
397
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000398
Greg Clayton60830262011-02-04 18:53:10 +0000399const lldb_private::UUID&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000400Module::GetUUID()
401{
402 Mutex::Locker locker (m_mutex);
Greg Claytone83e7312010-09-07 23:40:05 +0000403 if (m_did_parse_uuid == false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000404 {
405 ObjectFile * obj_file = GetObjectFile ();
406
407 if (obj_file != NULL)
408 {
409 obj_file->GetUUID(&m_uuid);
Greg Claytone83e7312010-09-07 23:40:05 +0000410 m_did_parse_uuid = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000411 }
412 }
413 return m_uuid;
414}
415
Greg Clayton6beaaa62011-01-17 03:46:26 +0000416ClangASTContext &
417Module::GetClangASTContext ()
418{
419 Mutex::Locker locker (m_mutex);
420 if (m_did_init_ast == false)
421 {
422 ObjectFile * objfile = GetObjectFile();
Greg Clayton514487e2011-02-15 21:59:32 +0000423 ArchSpec object_arch;
424 if (objfile && objfile->GetArchitecture(object_arch))
Greg Clayton6beaaa62011-01-17 03:46:26 +0000425 {
426 m_did_init_ast = true;
Jason Molenda981d4df2012-10-16 20:45:49 +0000427
428 // LLVM wants this to be set to iOS or MacOSX; if we're working on
429 // a bare-boards type image, change the triple for llvm's benefit.
430 if (object_arch.GetTriple().getVendor() == llvm::Triple::Apple
431 && object_arch.GetTriple().getOS() == llvm::Triple::UnknownOS)
432 {
433 if (object_arch.GetTriple().getArch() == llvm::Triple::arm ||
Todd Fialad8eaa172014-07-23 14:37:35 +0000434 object_arch.GetTriple().getArch() == llvm::Triple::aarch64 ||
Jason Molenda981d4df2012-10-16 20:45:49 +0000435 object_arch.GetTriple().getArch() == llvm::Triple::thumb)
436 {
437 object_arch.GetTriple().setOS(llvm::Triple::IOS);
438 }
439 else
440 {
441 object_arch.GetTriple().setOS(llvm::Triple::MacOSX);
442 }
443 }
Zachary Turner88c6b622015-03-03 18:34:26 +0000444 m_ast->SetArchitecture (object_arch);
Greg Clayton6beaaa62011-01-17 03:46:26 +0000445 }
446 }
Zachary Turner88c6b622015-03-03 18:34:26 +0000447 return *m_ast;
Greg Clayton6beaaa62011-01-17 03:46:26 +0000448}
449
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000450void
451Module::ParseAllDebugSymbols()
452{
453 Mutex::Locker locker (m_mutex);
Greg Claytonc7bece562013-01-25 18:06:21 +0000454 size_t num_comp_units = GetNumCompileUnits();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000455 if (num_comp_units == 0)
456 return;
457
Greg Claytona2eee182011-09-17 07:23:18 +0000458 SymbolContext sc;
Greg Claytone1cd1be2012-01-29 20:56:30 +0000459 sc.module_sp = shared_from_this();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000460 SymbolVendor *symbols = GetSymbolVendor ();
461
Greg Claytonc7bece562013-01-25 18:06:21 +0000462 for (size_t cu_idx = 0; cu_idx < num_comp_units; cu_idx++)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000463 {
464 sc.comp_unit = symbols->GetCompileUnitAtIndex(cu_idx).get();
465 if (sc.comp_unit)
466 {
467 sc.function = NULL;
468 symbols->ParseVariablesForContext(sc);
469
470 symbols->ParseCompileUnitFunctions(sc);
471
Greg Claytonc7bece562013-01-25 18:06:21 +0000472 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 +0000473 {
474 symbols->ParseFunctionBlocks(sc);
475
476 // Parse the variables for this function and all its blocks
477 symbols->ParseVariablesForContext(sc);
478 }
479
480
481 // Parse all types for this compile unit
482 sc.function = NULL;
483 symbols->ParseTypes(sc);
484 }
485 }
486}
487
488void
489Module::CalculateSymbolContext(SymbolContext* sc)
490{
Greg Claytone1cd1be2012-01-29 20:56:30 +0000491 sc->module_sp = shared_from_this();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000492}
493
Greg Claytone72dfb32012-02-24 01:59:29 +0000494ModuleSP
Greg Clayton7e9b1fd2011-08-12 21:40:01 +0000495Module::CalculateSymbolContextModule ()
496{
Greg Claytone72dfb32012-02-24 01:59:29 +0000497 return shared_from_this();
Greg Clayton7e9b1fd2011-08-12 21:40:01 +0000498}
499
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000500void
501Module::DumpSymbolContext(Stream *s)
502{
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000503 s->Printf(", Module{%p}", static_cast<void*>(this));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000504}
505
Greg Claytonc7bece562013-01-25 18:06:21 +0000506size_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000507Module::GetNumCompileUnits()
508{
509 Mutex::Locker locker (m_mutex);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000510 Timer scoped_timer(__PRETTY_FUNCTION__,
511 "Module::GetNumCompileUnits (module = %p)",
512 static_cast<void*>(this));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000513 SymbolVendor *symbols = GetSymbolVendor ();
514 if (symbols)
515 return symbols->GetNumCompileUnits();
516 return 0;
517}
518
519CompUnitSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000520Module::GetCompileUnitAtIndex (size_t index)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000521{
522 Mutex::Locker locker (m_mutex);
Greg Claytonc7bece562013-01-25 18:06:21 +0000523 size_t num_comp_units = GetNumCompileUnits ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000524 CompUnitSP cu_sp;
525
526 if (index < num_comp_units)
527 {
528 SymbolVendor *symbols = GetSymbolVendor ();
529 if (symbols)
530 cu_sp = symbols->GetCompileUnitAtIndex(index);
531 }
532 return cu_sp;
533}
534
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000535bool
536Module::ResolveFileAddress (lldb::addr_t vm_addr, Address& so_addr)
537{
538 Mutex::Locker locker (m_mutex);
Daniel Malead01b2952012-11-29 21:49:15 +0000539 Timer scoped_timer(__PRETTY_FUNCTION__, "Module::ResolveFileAddress (vm_addr = 0x%" PRIx64 ")", vm_addr);
Greg Clayton3046e662013-07-10 01:23:25 +0000540 SectionList *section_list = GetSectionList();
541 if (section_list)
542 return so_addr.ResolveAddressUsingFileSections(vm_addr, section_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000543 return false;
544}
545
546uint32_t
Ashok Thirumurthi35729bb2013-09-24 15:34:13 +0000547Module::ResolveSymbolContextForAddress (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc,
548 bool resolve_tail_call_address)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000549{
550 Mutex::Locker locker (m_mutex);
551 uint32_t resolved_flags = 0;
552
Greg Clayton72310352013-02-23 04:12:47 +0000553 // Clear the result symbol context in case we don't find anything, but don't clear the target
554 sc.Clear(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000555
556 // Get the section from the section/offset address.
Greg Claytone72dfb32012-02-24 01:59:29 +0000557 SectionSP section_sp (so_addr.GetSection());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000558
559 // Make sure the section matches this module before we try and match anything
Greg Claytone72dfb32012-02-24 01:59:29 +0000560 if (section_sp && section_sp->GetModule().get() == this)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000561 {
562 // If the section offset based address resolved itself, then this
563 // is the right module.
Greg Claytone1cd1be2012-01-29 20:56:30 +0000564 sc.module_sp = shared_from_this();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000565 resolved_flags |= eSymbolContextModule;
566
Ashok Thirumurthi38807142013-09-16 22:00:17 +0000567 SymbolVendor* sym_vendor = GetSymbolVendor();
568 if (!sym_vendor)
569 return resolved_flags;
570
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000571 // Resolve the compile unit, function, block, line table or line
572 // entry if requested.
573 if (resolve_scope & eSymbolContextCompUnit ||
574 resolve_scope & eSymbolContextFunction ||
575 resolve_scope & eSymbolContextBlock ||
576 resolve_scope & eSymbolContextLineEntry )
577 {
Ashok Thirumurthi38807142013-09-16 22:00:17 +0000578 resolved_flags |= sym_vendor->ResolveSymbolContext (so_addr, resolve_scope, sc);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000579 }
580
Jim Ingham680e1772010-08-31 23:51:36 +0000581 // Resolve the symbol if requested, but don't re-look it up if we've already found it.
582 if (resolve_scope & eSymbolContextSymbol && !(resolved_flags & eSymbolContextSymbol))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000583 {
Ashok Thirumurthi38807142013-09-16 22:00:17 +0000584 Symtab *symtab = sym_vendor->GetSymtab();
585 if (symtab && so_addr.IsSectionOffset())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000586 {
Ashok Thirumurthi38807142013-09-16 22:00:17 +0000587 sc.symbol = symtab->FindSymbolContainingFileAddress(so_addr.GetFileAddress());
Ashok Thirumurthi35729bb2013-09-24 15:34:13 +0000588 if (!sc.symbol &&
589 resolve_scope & eSymbolContextFunction && !(resolved_flags & eSymbolContextFunction))
590 {
591 bool verify_unique = false; // No need to check again since ResolveSymbolContext failed to find a symbol at this address.
592 if (ObjectFile *obj_file = sc.module_sp->GetObjectFile())
593 sc.symbol = obj_file->ResolveSymbolForAddress(so_addr, verify_unique);
594 }
595
Ashok Thirumurthi38807142013-09-16 22:00:17 +0000596 if (sc.symbol)
Greg Clayton93e28612013-10-11 22:03:48 +0000597 {
598 if (sc.symbol->IsSynthetic())
599 {
600 // We have a synthetic symbol so lets check if the object file
601 // from the symbol file in the symbol vendor is different than
602 // the object file for the module, and if so search its symbol
603 // table to see if we can come up with a better symbol. For example
604 // dSYM files on MacOSX have an unstripped symbol table inside of
605 // them.
606 ObjectFile *symtab_objfile = symtab->GetObjectFile();
607 if (symtab_objfile && symtab_objfile->IsStripped())
608 {
609 SymbolFile *symfile = sym_vendor->GetSymbolFile();
610 if (symfile)
611 {
612 ObjectFile *symfile_objfile = symfile->GetObjectFile();
613 if (symfile_objfile != symtab_objfile)
614 {
615 Symtab *symfile_symtab = symfile_objfile->GetSymtab();
616 if (symfile_symtab)
617 {
618 Symbol *symbol = symfile_symtab->FindSymbolContainingFileAddress(so_addr.GetFileAddress());
619 if (symbol && !symbol->IsSynthetic())
620 {
621 sc.symbol = symbol;
622 }
623 }
624 }
625 }
626 }
627 }
Ashok Thirumurthi38807142013-09-16 22:00:17 +0000628 resolved_flags |= eSymbolContextSymbol;
Greg Clayton93e28612013-10-11 22:03:48 +0000629 }
Ashok Thirumurthi38807142013-09-16 22:00:17 +0000630 }
631 }
632
633 // For function symbols, so_addr may be off by one. This is a convention consistent
634 // with FDE row indices in eh_frame sections, but requires extra logic here to permit
635 // symbol lookup for disassembly and unwind.
636 if (resolve_scope & eSymbolContextSymbol && !(resolved_flags & eSymbolContextSymbol) &&
Ashok Thirumurthi35729bb2013-09-24 15:34:13 +0000637 resolve_tail_call_address && so_addr.IsSectionOffset())
Ashok Thirumurthi38807142013-09-16 22:00:17 +0000638 {
639 Address previous_addr = so_addr;
Greg Claytonedfaae32013-09-18 20:03:31 +0000640 previous_addr.Slide(-1);
Ashok Thirumurthi38807142013-09-16 22:00:17 +0000641
Ashok Thirumurthi35729bb2013-09-24 15:34:13 +0000642 bool do_resolve_tail_call_address = false; // prevent recursion
643 const uint32_t flags = ResolveSymbolContextForAddress(previous_addr, resolve_scope, sc,
644 do_resolve_tail_call_address);
Ashok Thirumurthi38807142013-09-16 22:00:17 +0000645 if (flags & eSymbolContextSymbol)
646 {
647 AddressRange addr_range;
648 if (sc.GetAddressRange (eSymbolContextFunction | eSymbolContextSymbol, 0, false, addr_range))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000649 {
Ashok Thirumurthi38807142013-09-16 22:00:17 +0000650 if (addr_range.GetBaseAddress().GetSection() == so_addr.GetSection())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000651 {
Ashok Thirumurthi38807142013-09-16 22:00:17 +0000652 // If the requested address is one past the address range of a function (i.e. a tail call),
653 // or the decremented address is the start of a function (i.e. some forms of trampoline),
654 // indicate that the symbol has been resolved.
655 if (so_addr.GetOffset() == addr_range.GetBaseAddress().GetOffset() ||
656 so_addr.GetOffset() == addr_range.GetBaseAddress().GetOffset() + addr_range.GetByteSize())
657 {
658 resolved_flags |= flags;
659 }
660 }
661 else
662 {
663 sc.symbol = nullptr; // Don't trust the symbol if the sections didn't match.
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000664 }
665 }
666 }
667 }
668 }
669 return resolved_flags;
670}
671
672uint32_t
Greg Clayton274060b2010-10-20 20:54:39 +0000673Module::ResolveSymbolContextForFilePath
674(
675 const char *file_path,
676 uint32_t line,
677 bool check_inlines,
678 uint32_t resolve_scope,
679 SymbolContextList& sc_list
680)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000681{
Greg Clayton274060b2010-10-20 20:54:39 +0000682 FileSpec file_spec(file_path, false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000683 return ResolveSymbolContextsForFileSpec (file_spec, line, check_inlines, resolve_scope, sc_list);
684}
685
686uint32_t
687Module::ResolveSymbolContextsForFileSpec (const FileSpec &file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list)
688{
689 Mutex::Locker locker (m_mutex);
690 Timer scoped_timer(__PRETTY_FUNCTION__,
Greg Claytonb5ad4ec2013-04-29 17:25:54 +0000691 "Module::ResolveSymbolContextForFilePath (%s:%u, check_inlines = %s, resolve_scope = 0x%8.8x)",
692 file_spec.GetPath().c_str(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000693 line,
694 check_inlines ? "yes" : "no",
695 resolve_scope);
696
697 const uint32_t initial_count = sc_list.GetSize();
698
699 SymbolVendor *symbols = GetSymbolVendor ();
700 if (symbols)
701 symbols->ResolveSymbolContext (file_spec, line, check_inlines, resolve_scope, sc_list);
702
703 return sc_list.GetSize() - initial_count;
704}
705
706
Greg Claytonc7bece562013-01-25 18:06:21 +0000707size_t
708Module::FindGlobalVariables (const ConstString &name,
709 const ClangNamespaceDecl *namespace_decl,
710 bool append,
711 size_t max_matches,
712 VariableList& variables)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000713{
714 SymbolVendor *symbols = GetSymbolVendor ();
715 if (symbols)
Sean Callanan213fdb82011-10-13 01:49:10 +0000716 return symbols->FindGlobalVariables(name, namespace_decl, append, max_matches, variables);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000717 return 0;
718}
Greg Claytonc7bece562013-01-25 18:06:21 +0000719
720size_t
721Module::FindGlobalVariables (const RegularExpression& regex,
722 bool append,
723 size_t max_matches,
724 VariableList& variables)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000725{
726 SymbolVendor *symbols = GetSymbolVendor ();
727 if (symbols)
728 return symbols->FindGlobalVariables(regex, append, max_matches, variables);
729 return 0;
730}
731
Greg Claytonc7bece562013-01-25 18:06:21 +0000732size_t
Greg Clayton644247c2011-07-07 01:59:51 +0000733Module::FindCompileUnits (const FileSpec &path,
734 bool append,
735 SymbolContextList &sc_list)
736{
737 if (!append)
738 sc_list.Clear();
739
Greg Claytonc7bece562013-01-25 18:06:21 +0000740 const size_t start_size = sc_list.GetSize();
741 const size_t num_compile_units = GetNumCompileUnits();
Greg Clayton644247c2011-07-07 01:59:51 +0000742 SymbolContext sc;
Greg Claytone1cd1be2012-01-29 20:56:30 +0000743 sc.module_sp = shared_from_this();
Sean Callananddd7a2a2013-10-03 22:27:29 +0000744 const bool compare_directory = (bool)path.GetDirectory();
Greg Claytonc7bece562013-01-25 18:06:21 +0000745 for (size_t i=0; i<num_compile_units; ++i)
Greg Clayton644247c2011-07-07 01:59:51 +0000746 {
747 sc.comp_unit = GetCompileUnitAtIndex(i).get();
Greg Clayton2dafd8e2012-04-23 22:00:21 +0000748 if (sc.comp_unit)
749 {
750 if (FileSpec::Equal (*sc.comp_unit, path, compare_directory))
751 sc_list.Append(sc);
752 }
Greg Clayton644247c2011-07-07 01:59:51 +0000753 }
754 return sc_list.GetSize() - start_size;
755}
756
Greg Claytonc7bece562013-01-25 18:06:21 +0000757size_t
Sean Callananb6d70eb2011-10-12 02:08:07 +0000758Module::FindFunctions (const ConstString &name,
759 const ClangNamespaceDecl *namespace_decl,
Greg Claytonc7bece562013-01-25 18:06:21 +0000760 uint32_t name_type_mask,
Sean Callanan9df05fb2012-02-10 22:52:19 +0000761 bool include_symbols,
762 bool include_inlines,
Greg Clayton931180e2011-01-27 06:44:37 +0000763 bool append,
764 SymbolContextList& sc_list)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000765{
Greg Clayton931180e2011-01-27 06:44:37 +0000766 if (!append)
767 sc_list.Clear();
768
Greg Clayton43fe2172013-04-03 02:00:15 +0000769 const size_t old_size = sc_list.GetSize();
Greg Clayton931180e2011-01-27 06:44:37 +0000770
771 // Find all the functions (not symbols, but debug information functions...
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000772 SymbolVendor *symbols = GetSymbolVendor ();
Greg Clayton43fe2172013-04-03 02:00:15 +0000773
774 if (name_type_mask & eFunctionNameTypeAuto)
Greg Clayton931180e2011-01-27 06:44:37 +0000775 {
Greg Clayton43fe2172013-04-03 02:00:15 +0000776 ConstString lookup_name;
777 uint32_t lookup_name_type_mask = 0;
778 bool match_name_after_lookup = false;
779 Module::PrepareForFunctionNameLookup (name,
780 name_type_mask,
781 lookup_name,
782 lookup_name_type_mask,
783 match_name_after_lookup);
784
785 if (symbols)
Michael Sartaina7499c92013-07-01 19:45:50 +0000786 {
Greg Clayton43fe2172013-04-03 02:00:15 +0000787 symbols->FindFunctions(lookup_name,
788 namespace_decl,
789 lookup_name_type_mask,
790 include_inlines,
791 append,
792 sc_list);
793
Michael Sartaina7499c92013-07-01 19:45:50 +0000794 // Now check our symbol table for symbols that are code symbols if requested
795 if (include_symbols)
Greg Clayton931180e2011-01-27 06:44:37 +0000796 {
Michael Sartaina7499c92013-07-01 19:45:50 +0000797 Symtab *symtab = symbols->GetSymtab();
Greg Clayton43fe2172013-04-03 02:00:15 +0000798 if (symtab)
799 symtab->FindFunctionSymbols(lookup_name, lookup_name_type_mask, sc_list);
800 }
801 }
802
803 if (match_name_after_lookup)
804 {
805 SymbolContext sc;
806 size_t i = old_size;
807 while (i<sc_list.GetSize())
808 {
809 if (sc_list.GetContextAtIndex(i, sc))
Greg Clayton931180e2011-01-27 06:44:37 +0000810 {
Greg Clayton43fe2172013-04-03 02:00:15 +0000811 const char *func_name = sc.GetFunctionName().GetCString();
812 if (func_name && strstr (func_name, name.GetCString()) == NULL)
Greg Clayton931180e2011-01-27 06:44:37 +0000813 {
Greg Clayton43fe2172013-04-03 02:00:15 +0000814 // Remove the current context
815 sc_list.RemoveContextAtIndex(i);
816 // Don't increment i and continue in the loop
817 continue;
Greg Clayton931180e2011-01-27 06:44:37 +0000818 }
819 }
Greg Clayton43fe2172013-04-03 02:00:15 +0000820 ++i;
821 }
822 }
Greg Clayton43fe2172013-04-03 02:00:15 +0000823 }
824 else
825 {
826 if (symbols)
Michael Sartaina7499c92013-07-01 19:45:50 +0000827 {
Greg Clayton43fe2172013-04-03 02:00:15 +0000828 symbols->FindFunctions(name, namespace_decl, name_type_mask, include_inlines, append, sc_list);
829
Michael Sartaina7499c92013-07-01 19:45:50 +0000830 // Now check our symbol table for symbols that are code symbols if requested
831 if (include_symbols)
Greg Clayton43fe2172013-04-03 02:00:15 +0000832 {
Michael Sartaina7499c92013-07-01 19:45:50 +0000833 Symtab *symtab = symbols->GetSymtab();
Greg Clayton43fe2172013-04-03 02:00:15 +0000834 if (symtab)
835 symtab->FindFunctionSymbols(name, name_type_mask, sc_list);
Greg Clayton931180e2011-01-27 06:44:37 +0000836 }
837 }
838 }
Greg Clayton43fe2172013-04-03 02:00:15 +0000839
840 return sc_list.GetSize() - old_size;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000841}
842
Greg Claytonc7bece562013-01-25 18:06:21 +0000843size_t
Greg Clayton931180e2011-01-27 06:44:37 +0000844Module::FindFunctions (const RegularExpression& regex,
Sean Callanan9df05fb2012-02-10 22:52:19 +0000845 bool include_symbols,
846 bool include_inlines,
Greg Clayton931180e2011-01-27 06:44:37 +0000847 bool append,
848 SymbolContextList& sc_list)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000849{
Greg Clayton931180e2011-01-27 06:44:37 +0000850 if (!append)
851 sc_list.Clear();
852
Greg Claytonc7bece562013-01-25 18:06:21 +0000853 const size_t start_size = sc_list.GetSize();
Greg Clayton931180e2011-01-27 06:44:37 +0000854
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000855 SymbolVendor *symbols = GetSymbolVendor ();
856 if (symbols)
Greg Clayton931180e2011-01-27 06:44:37 +0000857 {
Michael Sartaina7499c92013-07-01 19:45:50 +0000858 symbols->FindFunctions(regex, include_inlines, append, sc_list);
859
860 // Now check our symbol table for symbols that are code symbols if requested
861 if (include_symbols)
Greg Clayton931180e2011-01-27 06:44:37 +0000862 {
Michael Sartaina7499c92013-07-01 19:45:50 +0000863 Symtab *symtab = symbols->GetSymtab();
Greg Clayton931180e2011-01-27 06:44:37 +0000864 if (symtab)
865 {
866 std::vector<uint32_t> symbol_indexes;
Matt Kopec00049b82013-02-27 20:13:38 +0000867 symtab->AppendSymbolIndexesMatchingRegExAndType (regex, eSymbolTypeAny, Symtab::eDebugAny, Symtab::eVisibilityAny, symbol_indexes);
Greg Claytonc7bece562013-01-25 18:06:21 +0000868 const size_t num_matches = symbol_indexes.size();
Greg Clayton931180e2011-01-27 06:44:37 +0000869 if (num_matches)
870 {
871 SymbolContext sc(this);
Greg Claytond8cf1a12013-06-12 00:46:38 +0000872 const size_t end_functions_added_index = sc_list.GetSize();
873 size_t num_functions_added_to_sc_list = end_functions_added_index - start_size;
874 if (num_functions_added_to_sc_list == 0)
Greg Clayton931180e2011-01-27 06:44:37 +0000875 {
Greg Claytond8cf1a12013-06-12 00:46:38 +0000876 // No functions were added, just symbols, so we can just append them
877 for (size_t i=0; i<num_matches; ++i)
878 {
879 sc.symbol = symtab->SymbolAtIndex(symbol_indexes[i]);
880 SymbolType sym_type = sc.symbol->GetType();
881 if (sc.symbol && (sym_type == eSymbolTypeCode ||
882 sym_type == eSymbolTypeResolver))
883 sc_list.Append(sc);
884 }
885 }
886 else
887 {
888 typedef std::map<lldb::addr_t, uint32_t> FileAddrToIndexMap;
889 FileAddrToIndexMap file_addr_to_index;
890 for (size_t i=start_size; i<end_functions_added_index; ++i)
891 {
892 const SymbolContext &sc = sc_list[i];
893 if (sc.block)
894 continue;
895 file_addr_to_index[sc.function->GetAddressRange().GetBaseAddress().GetFileAddress()] = i;
896 }
897
898 FileAddrToIndexMap::const_iterator end = file_addr_to_index.end();
899 // Functions were added so we need to merge symbols into any
900 // existing function symbol contexts
901 for (size_t i=start_size; i<num_matches; ++i)
902 {
903 sc.symbol = symtab->SymbolAtIndex(symbol_indexes[i]);
904 SymbolType sym_type = sc.symbol->GetType();
905 if (sc.symbol && (sym_type == eSymbolTypeCode ||
906 sym_type == eSymbolTypeResolver))
907 {
908 FileAddrToIndexMap::const_iterator pos = file_addr_to_index.find(sc.symbol->GetAddress().GetFileAddress());
909 if (pos == end)
910 sc_list.Append(sc);
911 else
912 sc_list[pos->second].symbol = sc.symbol;
913 }
914 }
Greg Clayton931180e2011-01-27 06:44:37 +0000915 }
916 }
917 }
918 }
919 }
920 return sc_list.GetSize() - start_size;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000921}
922
Richard Mittonf86248d2013-09-12 02:20:34 +0000923void
924Module::FindAddressesForLine (const lldb::TargetSP target_sp,
925 const FileSpec &file, uint32_t line,
926 Function *function,
927 std::vector<Address> &output_local, std::vector<Address> &output_extern)
928{
929 SearchFilterByModule filter(target_sp, m_file);
930 AddressResolverFileLine resolver(file, line, true);
931 resolver.ResolveAddress (filter);
932
933 for (size_t n=0;n<resolver.GetNumberOfAddresses();n++)
934 {
935 Address addr = resolver.GetAddressRangeAtIndex(n).GetBaseAddress();
936 Function *f = addr.CalculateSymbolContextFunction();
937 if (f && f == function)
938 output_local.push_back (addr);
939 else
940 output_extern.push_back (addr);
941 }
942}
943
Greg Claytonc7bece562013-01-25 18:06:21 +0000944size_t
Greg Clayton84db9102012-03-26 23:03:23 +0000945Module::FindTypes_Impl (const SymbolContext& sc,
946 const ConstString &name,
947 const ClangNamespaceDecl *namespace_decl,
948 bool append,
Greg Claytonc7bece562013-01-25 18:06:21 +0000949 size_t max_matches,
Greg Clayton84db9102012-03-26 23:03:23 +0000950 TypeList& types)
Greg Clayton3504eee2010-08-03 01:26:16 +0000951{
952 Timer scoped_timer(__PRETTY_FUNCTION__, __PRETTY_FUNCTION__);
953 if (sc.module_sp.get() == NULL || sc.module_sp.get() == this)
954 {
955 SymbolVendor *symbols = GetSymbolVendor ();
956 if (symbols)
Sean Callanan213fdb82011-10-13 01:49:10 +0000957 return symbols->FindTypes(sc, name, namespace_decl, append, max_matches, types);
Greg Clayton3504eee2010-08-03 01:26:16 +0000958 }
959 return 0;
960}
961
Greg Claytonc7bece562013-01-25 18:06:21 +0000962size_t
Greg Clayton84db9102012-03-26 23:03:23 +0000963Module::FindTypesInNamespace (const SymbolContext& sc,
964 const ConstString &type_name,
965 const ClangNamespaceDecl *namespace_decl,
Greg Claytonc7bece562013-01-25 18:06:21 +0000966 size_t max_matches,
Greg Clayton84db9102012-03-26 23:03:23 +0000967 TypeList& type_list)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000968{
Greg Clayton84db9102012-03-26 23:03:23 +0000969 const bool append = true;
970 return FindTypes_Impl(sc, type_name, namespace_decl, append, max_matches, type_list);
Enrico Granata6f3533f2011-07-29 19:53:35 +0000971}
972
Greg Claytonb43165b2012-12-05 21:24:42 +0000973lldb::TypeSP
974Module::FindFirstType (const SymbolContext& sc,
975 const ConstString &name,
976 bool exact_match)
977{
978 TypeList type_list;
Greg Claytonc7bece562013-01-25 18:06:21 +0000979 const size_t num_matches = FindTypes (sc, name, exact_match, 1, type_list);
Greg Claytonb43165b2012-12-05 21:24:42 +0000980 if (num_matches)
981 return type_list.GetTypeAtIndex(0);
982 return TypeSP();
983}
984
985
Greg Claytonc7bece562013-01-25 18:06:21 +0000986size_t
Greg Clayton84db9102012-03-26 23:03:23 +0000987Module::FindTypes (const SymbolContext& sc,
988 const ConstString &name,
989 bool exact_match,
Greg Claytonc7bece562013-01-25 18:06:21 +0000990 size_t max_matches,
Greg Clayton84db9102012-03-26 23:03:23 +0000991 TypeList& types)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000992{
Greg Claytonc7bece562013-01-25 18:06:21 +0000993 size_t num_matches = 0;
Greg Clayton84db9102012-03-26 23:03:23 +0000994 const char *type_name_cstr = name.GetCString();
995 std::string type_scope;
996 std::string type_basename;
997 const bool append = true;
Greg Clayton7bc31332012-10-22 16:19:56 +0000998 TypeClass type_class = eTypeClassAny;
999 if (Type::GetTypeScopeAndBasename (type_name_cstr, type_scope, type_basename, type_class))
Enrico Granata6f3533f2011-07-29 19:53:35 +00001000 {
Greg Clayton84db9102012-03-26 23:03:23 +00001001 // Check if "name" starts with "::" which means the qualified type starts
1002 // from the root namespace and implies and exact match. The typenames we
1003 // get back from clang do not start with "::" so we need to strip this off
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00001004 // in order to get the qualified names to match
Greg Clayton84db9102012-03-26 23:03:23 +00001005
1006 if (type_scope.size() >= 2 && type_scope[0] == ':' && type_scope[1] == ':')
1007 {
1008 type_scope.erase(0,2);
1009 exact_match = true;
1010 }
1011 ConstString type_basename_const_str (type_basename.c_str());
1012 if (FindTypes_Impl(sc, type_basename_const_str, NULL, append, max_matches, types))
1013 {
Greg Clayton7bc31332012-10-22 16:19:56 +00001014 types.RemoveMismatchedTypes (type_scope, type_basename, type_class, exact_match);
Greg Clayton84db9102012-03-26 23:03:23 +00001015 num_matches = types.GetSize();
1016 }
Enrico Granata6f3533f2011-07-29 19:53:35 +00001017 }
1018 else
Greg Clayton84db9102012-03-26 23:03:23 +00001019 {
1020 // The type is not in a namespace/class scope, just search for it by basename
Greg Clayton7bc31332012-10-22 16:19:56 +00001021 if (type_class != eTypeClassAny)
1022 {
1023 // The "type_name_cstr" will have been modified if we have a valid type class
1024 // prefix (like "struct", "class", "union", "typedef" etc).
Arnaud A. de Grandmaison62e5f4d2014-03-22 20:23:26 +00001025 FindTypes_Impl(sc, ConstString(type_name_cstr), NULL, append, max_matches, types);
Greg Clayton7bc31332012-10-22 16:19:56 +00001026 types.RemoveMismatchedTypes (type_class);
1027 num_matches = types.GetSize();
1028 }
1029 else
1030 {
1031 num_matches = FindTypes_Impl(sc, name, NULL, append, max_matches, types);
1032 }
Greg Clayton84db9102012-03-26 23:03:23 +00001033 }
1034
1035 return num_matches;
Enrico Granata6f3533f2011-07-29 19:53:35 +00001036
1037}
1038
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001039SymbolVendor*
Greg Clayton136dff82012-12-14 02:15:00 +00001040Module::GetSymbolVendor (bool can_create, lldb_private::Stream *feedback_strm)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001041{
1042 Mutex::Locker locker (m_mutex);
Greg Claytone83e7312010-09-07 23:40:05 +00001043 if (m_did_load_symbol_vendor == false && can_create)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001044 {
1045 ObjectFile *obj_file = GetObjectFile ();
1046 if (obj_file != NULL)
1047 {
1048 Timer scoped_timer(__PRETTY_FUNCTION__, __PRETTY_FUNCTION__);
Greg Clayton136dff82012-12-14 02:15:00 +00001049 m_symfile_ap.reset(SymbolVendor::FindPlugin(shared_from_this(), feedback_strm));
Greg Claytone83e7312010-09-07 23:40:05 +00001050 m_did_load_symbol_vendor = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001051 }
1052 }
1053 return m_symfile_ap.get();
1054}
1055
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001056void
1057Module::SetFileSpecAndObjectName (const FileSpec &file, const ConstString &object_name)
1058{
1059 // Container objects whose paths do not specify a file directly can call
1060 // this function to correct the file and object names.
1061 m_file = file;
1062 m_mod_time = file.GetModificationTime();
1063 m_object_name = object_name;
1064}
1065
1066const ArchSpec&
1067Module::GetArchitecture () const
1068{
1069 return m_arch;
1070}
1071
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00001072std::string
1073Module::GetSpecificationDescription () const
1074{
1075 std::string spec(GetFileSpec().GetPath());
1076 if (m_object_name)
1077 {
1078 spec += '(';
1079 spec += m_object_name.GetCString();
1080 spec += ')';
1081 }
1082 return spec;
1083}
1084
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001085void
Greg Claytonc982b3d2011-11-28 01:45:00 +00001086Module::GetDescription (Stream *s, lldb::DescriptionLevel level)
Caroline Ticeceb6b132010-10-26 03:11:13 +00001087{
1088 Mutex::Locker locker (m_mutex);
1089
Greg Claytonc982b3d2011-11-28 01:45:00 +00001090 if (level >= eDescriptionLevelFull)
1091 {
1092 if (m_arch.IsValid())
1093 s->Printf("(%s) ", m_arch.GetArchitectureName());
1094 }
Caroline Ticeceb6b132010-10-26 03:11:13 +00001095
Greg Claytonc982b3d2011-11-28 01:45:00 +00001096 if (level == eDescriptionLevelBrief)
1097 {
1098 const char *filename = m_file.GetFilename().GetCString();
1099 if (filename)
1100 s->PutCString (filename);
1101 }
1102 else
1103 {
1104 char path[PATH_MAX];
1105 if (m_file.GetPath(path, sizeof(path)))
1106 s->PutCString(path);
1107 }
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001108
1109 const char *object_name = m_object_name.GetCString();
1110 if (object_name)
1111 s->Printf("(%s)", object_name);
Caroline Ticeceb6b132010-10-26 03:11:13 +00001112}
1113
1114void
Greg Claytonc982b3d2011-11-28 01:45:00 +00001115Module::ReportError (const char *format, ...)
1116{
Greg Claytone38a5ed2012-01-05 03:57:59 +00001117 if (format && format[0])
1118 {
1119 StreamString strm;
1120 strm.PutCString("error: ");
1121 GetDescription(&strm, lldb::eDescriptionLevelBrief);
Greg Clayton8b353342012-01-11 01:59:18 +00001122 strm.PutChar (' ');
Greg Claytone38a5ed2012-01-05 03:57:59 +00001123 va_list args;
1124 va_start (args, format);
1125 strm.PrintfVarArg(format, args);
1126 va_end (args);
1127
1128 const int format_len = strlen(format);
1129 if (format_len > 0)
1130 {
1131 const char last_char = format[format_len-1];
1132 if (last_char != '\n' || last_char != '\r')
1133 strm.EOL();
1134 }
1135 Host::SystemLog (Host::eSystemLogError, "%s", strm.GetString().c_str());
1136
1137 }
1138}
1139
Greg Clayton1d609092012-07-12 22:51:12 +00001140bool
1141Module::FileHasChanged () const
1142{
1143 if (m_file_has_changed == false)
1144 m_file_has_changed = (m_file.GetModificationTime() != m_mod_time);
1145 return m_file_has_changed;
1146}
1147
Greg Claytone38a5ed2012-01-05 03:57:59 +00001148void
1149Module::ReportErrorIfModifyDetected (const char *format, ...)
1150{
Greg Clayton1d609092012-07-12 22:51:12 +00001151 if (m_first_file_changed_log == false)
Greg Claytone38a5ed2012-01-05 03:57:59 +00001152 {
Greg Clayton1d609092012-07-12 22:51:12 +00001153 if (FileHasChanged ())
Greg Claytone38a5ed2012-01-05 03:57:59 +00001154 {
Greg Clayton1d609092012-07-12 22:51:12 +00001155 m_first_file_changed_log = true;
1156 if (format)
Greg Claytone38a5ed2012-01-05 03:57:59 +00001157 {
Greg Clayton1d609092012-07-12 22:51:12 +00001158 StreamString strm;
1159 strm.PutCString("error: the object file ");
1160 GetDescription(&strm, lldb::eDescriptionLevelFull);
1161 strm.PutCString (" has been modified\n");
1162
1163 va_list args;
1164 va_start (args, format);
1165 strm.PrintfVarArg(format, args);
1166 va_end (args);
1167
1168 const int format_len = strlen(format);
1169 if (format_len > 0)
1170 {
1171 const char last_char = format[format_len-1];
1172 if (last_char != '\n' || last_char != '\r')
1173 strm.EOL();
1174 }
1175 strm.PutCString("The debug session should be aborted as the original debug information has been overwritten.\n");
1176 Host::SystemLog (Host::eSystemLogError, "%s", strm.GetString().c_str());
Greg Claytone38a5ed2012-01-05 03:57:59 +00001177 }
Greg Claytone38a5ed2012-01-05 03:57:59 +00001178 }
1179 }
Greg Claytonc982b3d2011-11-28 01:45:00 +00001180}
1181
1182void
1183Module::ReportWarning (const char *format, ...)
1184{
Greg Claytone38a5ed2012-01-05 03:57:59 +00001185 if (format && format[0])
1186 {
1187 StreamString strm;
1188 strm.PutCString("warning: ");
Greg Clayton8b353342012-01-11 01:59:18 +00001189 GetDescription(&strm, lldb::eDescriptionLevelFull);
1190 strm.PutChar (' ');
Greg Claytone38a5ed2012-01-05 03:57:59 +00001191
1192 va_list args;
1193 va_start (args, format);
1194 strm.PrintfVarArg(format, args);
1195 va_end (args);
1196
1197 const int format_len = strlen(format);
1198 if (format_len > 0)
1199 {
1200 const char last_char = format[format_len-1];
1201 if (last_char != '\n' || last_char != '\r')
1202 strm.EOL();
1203 }
1204 Host::SystemLog (Host::eSystemLogWarning, "%s", strm.GetString().c_str());
1205 }
Greg Claytonc982b3d2011-11-28 01:45:00 +00001206}
1207
1208void
1209Module::LogMessage (Log *log, const char *format, ...)
1210{
1211 if (log)
1212 {
1213 StreamString log_message;
Greg Clayton8b353342012-01-11 01:59:18 +00001214 GetDescription(&log_message, lldb::eDescriptionLevelFull);
Greg Claytonc982b3d2011-11-28 01:45:00 +00001215 log_message.PutCString (": ");
1216 va_list args;
1217 va_start (args, format);
1218 log_message.PrintfVarArg (format, args);
1219 va_end (args);
1220 log->PutCString(log_message.GetString().c_str());
1221 }
1222}
1223
Greg Claytond61c0fc2012-04-23 22:55:20 +00001224void
1225Module::LogMessageVerboseBacktrace (Log *log, const char *format, ...)
1226{
1227 if (log)
1228 {
1229 StreamString log_message;
1230 GetDescription(&log_message, lldb::eDescriptionLevelFull);
1231 log_message.PutCString (": ");
1232 va_list args;
1233 va_start (args, format);
1234 log_message.PrintfVarArg (format, args);
1235 va_end (args);
1236 if (log->GetVerbose())
1237 Host::Backtrace (log_message, 1024);
1238 log->PutCString(log_message.GetString().c_str());
1239 }
1240}
1241
Greg Claytonc982b3d2011-11-28 01:45:00 +00001242void
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001243Module::Dump(Stream *s)
1244{
1245 Mutex::Locker locker (m_mutex);
Greg Clayton89411422010-10-08 00:21:05 +00001246 //s->Printf("%.*p: ", (int)sizeof(void*) * 2, this);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001247 s->Indent();
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00001248 s->Printf("Module %s%s%s%s\n",
1249 m_file.GetPath().c_str(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001250 m_object_name ? "(" : "",
1251 m_object_name ? m_object_name.GetCString() : "",
1252 m_object_name ? ")" : "");
1253
1254 s->IndentMore();
Michael Sartaina7499c92013-07-01 19:45:50 +00001255
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001256 ObjectFile *objfile = GetObjectFile ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001257 if (objfile)
1258 objfile->Dump(s);
1259
1260 SymbolVendor *symbols = GetSymbolVendor ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001261 if (symbols)
1262 symbols->Dump(s);
1263
1264 s->IndentLess();
1265}
1266
1267
1268TypeList*
1269Module::GetTypeList ()
1270{
1271 SymbolVendor *symbols = GetSymbolVendor ();
1272 if (symbols)
1273 return &symbols->GetTypeList();
1274 return NULL;
1275}
1276
1277const ConstString &
1278Module::GetObjectName() const
1279{
1280 return m_object_name;
1281}
1282
1283ObjectFile *
1284Module::GetObjectFile()
1285{
1286 Mutex::Locker locker (m_mutex);
Greg Claytone83e7312010-09-07 23:40:05 +00001287 if (m_did_load_objfile == false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001288 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001289 Timer scoped_timer(__PRETTY_FUNCTION__,
1290 "Module::GetObjectFile () module = %s", GetFileSpec().GetFilename().AsCString(""));
Greg Clayton5ce9c562013-02-06 17:22:03 +00001291 DataBufferSP data_sp;
1292 lldb::offset_t data_offset = 0;
Greg Clayton2540a8a2013-07-12 22:07:46 +00001293 const lldb::offset_t file_size = m_file.GetByteSize();
1294 if (file_size > m_object_offset)
Greg Clayton593577a2011-09-21 03:57:31 +00001295 {
Greg Clayton2540a8a2013-07-12 22:07:46 +00001296 m_did_load_objfile = true;
1297 m_objfile_sp = ObjectFile::FindPlugin (shared_from_this(),
1298 &m_file,
1299 m_object_offset,
1300 file_size - m_object_offset,
1301 data_sp,
1302 data_offset);
1303 if (m_objfile_sp)
1304 {
Zachary Turner5e6f4522015-01-22 18:59:05 +00001305 // Once we get the object file, update our module with the object file's
Greg Clayton2540a8a2013-07-12 22:07:46 +00001306 // architecture since it might differ in vendor/os if some parts were
Zachary Turner5e6f4522015-01-22 18:59:05 +00001307 // unknown. But since the matching arch might already be more specific
1308 // than the generic COFF architecture, only merge in those values that
1309 // overwrite unspecified unknown values.
1310 ArchSpec new_arch;
1311 m_objfile_sp->GetArchitecture(new_arch);
1312 m_arch.MergeFrom(new_arch);
Greg Clayton2540a8a2013-07-12 22:07:46 +00001313 }
Todd Fiala0ee56ce2014-09-05 14:48:49 +00001314 else
1315 {
1316 ReportError ("failed to load objfile for %s", GetFileSpec().GetPath().c_str());
1317 }
Greg Clayton593577a2011-09-21 03:57:31 +00001318 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001319 }
Greg Clayton762f7132011-09-18 18:59:15 +00001320 return m_objfile_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001321}
1322
Michael Sartaina7499c92013-07-01 19:45:50 +00001323SectionList *
Greg Clayton3046e662013-07-10 01:23:25 +00001324Module::GetSectionList()
1325{
1326 // Populate m_unified_sections_ap with sections from objfile.
1327 if (m_sections_ap.get() == NULL)
1328 {
1329 ObjectFile *obj_file = GetObjectFile();
1330 if (obj_file)
1331 obj_file->CreateSections(*GetUnifiedSectionList());
1332 }
1333 return m_sections_ap.get();
1334}
1335
Jason Molenda05a09c62014-08-22 02:46:46 +00001336void
1337Module::SectionFileAddressesChanged ()
1338{
1339 ObjectFile *obj_file = GetObjectFile ();
1340 if (obj_file)
1341 obj_file->SectionFileAddressesChanged ();
1342 SymbolVendor* sym_vendor = GetSymbolVendor();
1343 if (sym_vendor)
1344 sym_vendor->SectionFileAddressesChanged ();
1345}
1346
Greg Clayton3046e662013-07-10 01:23:25 +00001347SectionList *
Michael Sartaina7499c92013-07-01 19:45:50 +00001348Module::GetUnifiedSectionList()
1349{
Greg Clayton3046e662013-07-10 01:23:25 +00001350 // Populate m_unified_sections_ap with sections from objfile.
1351 if (m_sections_ap.get() == NULL)
1352 m_sections_ap.reset(new SectionList());
1353 return m_sections_ap.get();
Michael Sartaina7499c92013-07-01 19:45:50 +00001354}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001355
1356const Symbol *
1357Module::FindFirstSymbolWithNameAndType (const ConstString &name, SymbolType symbol_type)
1358{
1359 Timer scoped_timer(__PRETTY_FUNCTION__,
1360 "Module::FindFirstSymbolWithNameAndType (name = %s, type = %i)",
1361 name.AsCString(),
1362 symbol_type);
Michael Sartaina7499c92013-07-01 19:45:50 +00001363 SymbolVendor* sym_vendor = GetSymbolVendor();
1364 if (sym_vendor)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001365 {
Michael Sartaina7499c92013-07-01 19:45:50 +00001366 Symtab *symtab = sym_vendor->GetSymtab();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001367 if (symtab)
Greg Claytonbcf2cfb2010-09-11 03:13:28 +00001368 return symtab->FindFirstSymbolWithNameAndType (name, symbol_type, Symtab::eDebugAny, Symtab::eVisibilityAny);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001369 }
1370 return NULL;
1371}
1372void
1373Module::SymbolIndicesToSymbolContextList (Symtab *symtab, std::vector<uint32_t> &symbol_indexes, SymbolContextList &sc_list)
1374{
1375 // No need to protect this call using m_mutex all other method calls are
1376 // already thread safe.
1377
1378 size_t num_indices = symbol_indexes.size();
1379 if (num_indices > 0)
1380 {
1381 SymbolContext sc;
1382 CalculateSymbolContext (&sc);
1383 for (size_t i = 0; i < num_indices; i++)
1384 {
1385 sc.symbol = symtab->SymbolAtIndex (symbol_indexes[i]);
1386 if (sc.symbol)
1387 sc_list.Append (sc);
1388 }
1389 }
1390}
1391
1392size_t
Greg Claytonc1b2ccf2013-01-08 00:01:36 +00001393Module::FindFunctionSymbols (const ConstString &name,
1394 uint32_t name_type_mask,
1395 SymbolContextList& sc_list)
1396{
1397 Timer scoped_timer(__PRETTY_FUNCTION__,
1398 "Module::FindSymbolsFunctions (name = %s, mask = 0x%8.8x)",
1399 name.AsCString(),
1400 name_type_mask);
Michael Sartaina7499c92013-07-01 19:45:50 +00001401 SymbolVendor* sym_vendor = GetSymbolVendor();
1402 if (sym_vendor)
Greg Claytonc1b2ccf2013-01-08 00:01:36 +00001403 {
Michael Sartaina7499c92013-07-01 19:45:50 +00001404 Symtab *symtab = sym_vendor->GetSymtab();
Greg Claytonc1b2ccf2013-01-08 00:01:36 +00001405 if (symtab)
1406 return symtab->FindFunctionSymbols (name, name_type_mask, sc_list);
1407 }
1408 return 0;
1409}
1410
1411size_t
Sean Callananb96ff332011-10-13 16:49:47 +00001412Module::FindSymbolsWithNameAndType (const ConstString &name, SymbolType symbol_type, SymbolContextList &sc_list)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001413{
1414 // No need to protect this call using m_mutex all other method calls are
1415 // already thread safe.
1416
1417
1418 Timer scoped_timer(__PRETTY_FUNCTION__,
1419 "Module::FindSymbolsWithNameAndType (name = %s, type = %i)",
1420 name.AsCString(),
1421 symbol_type);
1422 const size_t initial_size = sc_list.GetSize();
Michael Sartaina7499c92013-07-01 19:45:50 +00001423 SymbolVendor* sym_vendor = GetSymbolVendor();
1424 if (sym_vendor)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001425 {
Michael Sartaina7499c92013-07-01 19:45:50 +00001426 Symtab *symtab = sym_vendor->GetSymtab();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001427 if (symtab)
1428 {
1429 std::vector<uint32_t> symbol_indexes;
1430 symtab->FindAllSymbolsWithNameAndType (name, symbol_type, symbol_indexes);
1431 SymbolIndicesToSymbolContextList (symtab, symbol_indexes, sc_list);
1432 }
1433 }
1434 return sc_list.GetSize() - initial_size;
1435}
1436
1437size_t
1438Module::FindSymbolsMatchingRegExAndType (const RegularExpression &regex, SymbolType symbol_type, SymbolContextList &sc_list)
1439{
1440 // No need to protect this call using m_mutex all other method calls are
1441 // already thread safe.
1442
1443 Timer scoped_timer(__PRETTY_FUNCTION__,
1444 "Module::FindSymbolsMatchingRegExAndType (regex = %s, type = %i)",
1445 regex.GetText(),
1446 symbol_type);
1447 const size_t initial_size = sc_list.GetSize();
Michael Sartaina7499c92013-07-01 19:45:50 +00001448 SymbolVendor* sym_vendor = GetSymbolVendor();
1449 if (sym_vendor)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001450 {
Michael Sartaina7499c92013-07-01 19:45:50 +00001451 Symtab *symtab = sym_vendor->GetSymtab();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001452 if (symtab)
1453 {
1454 std::vector<uint32_t> symbol_indexes;
Greg Claytonbcf2cfb2010-09-11 03:13:28 +00001455 symtab->FindAllSymbolsMatchingRexExAndType (regex, symbol_type, Symtab::eDebugAny, Symtab::eVisibilityAny, symbol_indexes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001456 SymbolIndicesToSymbolContextList (symtab, symbol_indexes, sc_list);
1457 }
1458 }
1459 return sc_list.GetSize() - initial_size;
1460}
1461
Greg Claytone01e07b2013-04-18 18:10:51 +00001462void
1463Module::SetSymbolFileFileSpec (const FileSpec &file)
1464{
Michael Sartaina7499c92013-07-01 19:45:50 +00001465 // Remove any sections in the unified section list that come from the current symbol vendor.
1466 if (m_symfile_ap)
1467 {
Greg Clayton3046e662013-07-10 01:23:25 +00001468 SectionList *section_list = GetSectionList();
Michael Sartaina7499c92013-07-01 19:45:50 +00001469 SymbolFile *symbol_file = m_symfile_ap->GetSymbolFile();
1470 if (section_list && symbol_file)
1471 {
1472 ObjectFile *obj_file = symbol_file->GetObjectFile();
Greg Clayton540fbbf2013-08-13 16:46:35 +00001473 // Make sure we have an object file and that the symbol vendor's objfile isn't
1474 // the same as the module's objfile before we remove any sections for it...
1475 if (obj_file && obj_file != m_objfile_sp.get())
Michael Sartaina7499c92013-07-01 19:45:50 +00001476 {
1477 size_t num_sections = section_list->GetNumSections (0);
1478 for (size_t idx = num_sections; idx > 0; --idx)
1479 {
1480 lldb::SectionSP section_sp (section_list->GetSectionAtIndex (idx - 1));
1481 if (section_sp->GetObjectFile() == obj_file)
1482 {
Greg Clayton3046e662013-07-10 01:23:25 +00001483 section_list->DeleteSection (idx - 1);
Michael Sartaina7499c92013-07-01 19:45:50 +00001484 }
1485 }
Michael Sartaina7499c92013-07-01 19:45:50 +00001486 }
1487 }
1488 }
1489
Greg Claytone01e07b2013-04-18 18:10:51 +00001490 m_symfile_spec = file;
1491 m_symfile_ap.reset();
1492 m_did_load_symbol_vendor = false;
1493}
1494
Jim Ingham5aee1622010-08-09 23:31:02 +00001495bool
1496Module::IsExecutable ()
1497{
1498 if (GetObjectFile() == NULL)
1499 return false;
1500 else
1501 return GetObjectFile()->IsExecutable();
1502}
1503
Jim Inghamb53cb272011-08-03 01:03:17 +00001504bool
1505Module::IsLoadedInTarget (Target *target)
1506{
1507 ObjectFile *obj_file = GetObjectFile();
1508 if (obj_file)
1509 {
Greg Clayton3046e662013-07-10 01:23:25 +00001510 SectionList *sections = GetSectionList();
Jim Inghamb53cb272011-08-03 01:03:17 +00001511 if (sections != NULL)
1512 {
1513 size_t num_sections = sections->GetSize();
Jim Inghamb53cb272011-08-03 01:03:17 +00001514 for (size_t sect_idx = 0; sect_idx < num_sections; sect_idx++)
1515 {
1516 SectionSP section_sp = sections->GetSectionAtIndex(sect_idx);
1517 if (section_sp->GetLoadBaseAddress(target) != LLDB_INVALID_ADDRESS)
1518 {
1519 return true;
1520 }
1521 }
1522 }
1523 }
1524 return false;
1525}
Enrico Granata17598482012-11-08 02:22:02 +00001526
1527bool
Enrico Granata97303392013-05-21 00:00:30 +00001528Module::LoadScriptingResourceInTarget (Target *target, Error& error, Stream* feedback_stream)
Enrico Granata17598482012-11-08 02:22:02 +00001529{
1530 if (!target)
1531 {
1532 error.SetErrorString("invalid destination Target");
1533 return false;
1534 }
1535
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00001536 LoadScriptFromSymFile should_load = target->TargetProperties::GetLoadScriptFromSymbolFile();
Enrico Granata2ea43cd2013-05-13 17:03:52 +00001537
Greg Clayton994740f2014-08-18 21:08:44 +00001538 if (should_load == eLoadScriptFromSymFileFalse)
1539 return false;
1540
Greg Clayton91c0e742013-01-11 23:44:27 +00001541 Debugger &debugger = target->GetDebugger();
1542 const ScriptLanguage script_language = debugger.GetScriptLanguage();
1543 if (script_language != eScriptLanguageNone)
Enrico Granata17598482012-11-08 02:22:02 +00001544 {
Greg Clayton91c0e742013-01-11 23:44:27 +00001545
1546 PlatformSP platform_sp(target->GetPlatform());
1547
1548 if (!platform_sp)
1549 {
1550 error.SetErrorString("invalid Platform");
1551 return false;
1552 }
Enrico Granata17598482012-11-08 02:22:02 +00001553
Greg Claytonb9d88902013-03-23 00:50:58 +00001554 FileSpecList file_specs = platform_sp->LocateExecutableScriptingResources (target,
Enrico Granatafe7295d2014-08-16 00:32:58 +00001555 *this,
1556 feedback_stream);
Greg Claytonb9d88902013-03-23 00:50:58 +00001557
1558
1559 const uint32_t num_specs = file_specs.GetSize();
1560 if (num_specs)
Enrico Granata17598482012-11-08 02:22:02 +00001561 {
Greg Claytonb9d88902013-03-23 00:50:58 +00001562 ScriptInterpreter *script_interpreter = debugger.GetCommandInterpreter().GetScriptInterpreter();
1563 if (script_interpreter)
Greg Clayton91c0e742013-01-11 23:44:27 +00001564 {
1565 for (uint32_t i=0; i<num_specs; ++i)
1566 {
1567 FileSpec scripting_fspec (file_specs.GetFileSpecAtIndex(i));
1568 if (scripting_fspec && scripting_fspec.Exists())
1569 {
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00001570 if (should_load == eLoadScriptFromSymFileWarn)
Enrico Granata2ea43cd2013-05-13 17:03:52 +00001571 {
Enrico Granata397ddd52013-05-21 20:13:34 +00001572 if (feedback_stream)
Jim Inghamd516deb2013-07-01 18:49:43 +00001573 feedback_stream->Printf("warning: '%s' contains a debug script. To run this script in "
1574 "this debug session:\n\n command script import \"%s\"\n\n"
1575 "To run all discovered debug scripts in this session:\n\n"
1576 " settings set target.load-script-from-symbol-file true\n",
1577 GetFileSpec().GetFileNameStrippingExtension().GetCString(),
1578 scripting_fspec.GetPath().c_str());
Enrico Granata2ea43cd2013-05-13 17:03:52 +00001579 return false;
1580 }
Greg Clayton91c0e742013-01-11 23:44:27 +00001581 StreamString scripting_stream;
1582 scripting_fspec.Dump(&scripting_stream);
Enrico Granatae0c70f12013-05-31 01:03:09 +00001583 const bool can_reload = true;
Greg Clayton91c0e742013-01-11 23:44:27 +00001584 const bool init_lldb_globals = false;
Jim Inghamd516deb2013-07-01 18:49:43 +00001585 bool did_load = script_interpreter->LoadScriptingModule(scripting_stream.GetData(),
1586 can_reload,
1587 init_lldb_globals,
1588 error);
Greg Clayton91c0e742013-01-11 23:44:27 +00001589 if (!did_load)
1590 return false;
1591 }
1592 }
1593 }
Greg Claytonb9d88902013-03-23 00:50:58 +00001594 else
1595 {
1596 error.SetErrorString("invalid ScriptInterpreter");
1597 return false;
1598 }
Enrico Granata17598482012-11-08 02:22:02 +00001599 }
1600 }
1601 return true;
1602}
1603
1604bool
Jim Ingham5aee1622010-08-09 23:31:02 +00001605Module::SetArchitecture (const ArchSpec &new_arch)
1606{
Greg Clayton64195a22011-02-23 00:35:02 +00001607 if (!m_arch.IsValid())
Jim Ingham5aee1622010-08-09 23:31:02 +00001608 {
1609 m_arch = new_arch;
1610 return true;
Greg Clayton64195a22011-02-23 00:35:02 +00001611 }
Chaoren Linb6cd5fe2015-02-26 22:15:16 +00001612 return m_arch.IsCompatibleMatch(new_arch);
Jim Ingham5aee1622010-08-09 23:31:02 +00001613}
1614
Greg Claytonc9660542012-02-05 02:38:54 +00001615bool
Greg Clayton751caf62014-02-07 22:54:47 +00001616Module::SetLoadAddress (Target &target, lldb::addr_t value, bool value_is_offset, bool &changed)
Greg Claytonc9660542012-02-05 02:38:54 +00001617{
Steve Pucci9e02dac2014-02-06 19:02:19 +00001618 ObjectFile *object_file = GetObjectFile();
1619 if (object_file)
Greg Claytonc9660542012-02-05 02:38:54 +00001620 {
Greg Clayton751caf62014-02-07 22:54:47 +00001621 changed = object_file->SetLoadAddress(target, value, value_is_offset);
Greg Clayton7524e092014-02-06 20:10:16 +00001622 return true;
1623 }
1624 else
1625 {
1626 changed = false;
Greg Claytonc9660542012-02-05 02:38:54 +00001627 }
Steve Pucci9e02dac2014-02-06 19:02:19 +00001628 return false;
Greg Claytonc9660542012-02-05 02:38:54 +00001629}
1630
Greg Claytonb9a01b32012-02-26 05:51:37 +00001631
1632bool
1633Module::MatchesModuleSpec (const ModuleSpec &module_ref)
1634{
1635 const UUID &uuid = module_ref.GetUUID();
1636
1637 if (uuid.IsValid())
1638 {
1639 // If the UUID matches, then nothing more needs to match...
1640 if (uuid == GetUUID())
1641 return true;
1642 else
1643 return false;
1644 }
1645
1646 const FileSpec &file_spec = module_ref.GetFileSpec();
1647 if (file_spec)
1648 {
Sean Callananddd7a2a2013-10-03 22:27:29 +00001649 if (!FileSpec::Equal (file_spec, m_file, (bool)file_spec.GetDirectory()))
Greg Claytonb9a01b32012-02-26 05:51:37 +00001650 return false;
1651 }
1652
1653 const FileSpec &platform_file_spec = module_ref.GetPlatformFileSpec();
1654 if (platform_file_spec)
1655 {
Sean Callananddd7a2a2013-10-03 22:27:29 +00001656 if (!FileSpec::Equal (platform_file_spec, GetPlatformFileSpec (), (bool)platform_file_spec.GetDirectory()))
Greg Claytonb9a01b32012-02-26 05:51:37 +00001657 return false;
1658 }
1659
1660 const ArchSpec &arch = module_ref.GetArchitecture();
1661 if (arch.IsValid())
1662 {
Sean Callananbf4b7be2012-12-13 22:07:14 +00001663 if (!m_arch.IsCompatibleMatch(arch))
Greg Claytonb9a01b32012-02-26 05:51:37 +00001664 return false;
1665 }
1666
1667 const ConstString &object_name = module_ref.GetObjectName();
1668 if (object_name)
1669 {
1670 if (object_name != GetObjectName())
1671 return false;
1672 }
1673 return true;
1674}
1675
Greg Claytond804d282012-03-15 21:01:31 +00001676bool
1677Module::FindSourceFile (const FileSpec &orig_spec, FileSpec &new_spec) const
1678{
1679 Mutex::Locker locker (m_mutex);
1680 return m_source_mappings.FindFile (orig_spec, new_spec);
1681}
1682
Greg Claytonf9be6932012-03-19 22:22:41 +00001683bool
1684Module::RemapSourceFile (const char *path, std::string &new_path) const
1685{
1686 Mutex::Locker locker (m_mutex);
1687 return m_source_mappings.RemapPath(path, new_path);
1688}
1689
Enrico Granata3467d802012-09-04 18:47:54 +00001690uint32_t
1691Module::GetVersion (uint32_t *versions, uint32_t num_versions)
1692{
1693 ObjectFile *obj_file = GetObjectFile();
1694 if (obj_file)
1695 return obj_file->GetVersion (versions, num_versions);
1696
1697 if (versions && num_versions)
1698 {
1699 for (uint32_t i=0; i<num_versions; ++i)
Enrico Granataafcbdb12014-03-25 20:53:33 +00001700 versions[i] = LLDB_INVALID_MODULE_VERSION;
Enrico Granata3467d802012-09-04 18:47:54 +00001701 }
1702 return 0;
1703}
Greg Clayton43fe2172013-04-03 02:00:15 +00001704
1705void
1706Module::PrepareForFunctionNameLookup (const ConstString &name,
1707 uint32_t name_type_mask,
1708 ConstString &lookup_name,
1709 uint32_t &lookup_name_type_mask,
1710 bool &match_name_after_lookup)
1711{
1712 const char *name_cstr = name.GetCString();
1713 lookup_name_type_mask = eFunctionNameTypeNone;
1714 match_name_after_lookup = false;
Jim Inghamfa39bb42014-10-25 00:33:55 +00001715
1716 llvm::StringRef basename;
1717 llvm::StringRef context;
Greg Clayton43fe2172013-04-03 02:00:15 +00001718
1719 if (name_type_mask & eFunctionNameTypeAuto)
1720 {
1721 if (CPPLanguageRuntime::IsCPPMangledName (name_cstr))
1722 lookup_name_type_mask = eFunctionNameTypeFull;
1723 else if (ObjCLanguageRuntime::IsPossibleObjCMethodName (name_cstr))
1724 lookup_name_type_mask = eFunctionNameTypeFull;
1725 else
1726 {
1727 if (ObjCLanguageRuntime::IsPossibleObjCSelector(name_cstr))
1728 lookup_name_type_mask |= eFunctionNameTypeSelector;
1729
Greg Clayton6ecb2322013-05-18 00:11:21 +00001730 CPPLanguageRuntime::MethodName cpp_method (name);
Jim Inghamfa39bb42014-10-25 00:33:55 +00001731 basename = cpp_method.GetBasename();
Greg Clayton6ecb2322013-05-18 00:11:21 +00001732 if (basename.empty())
1733 {
Jim Inghamfa39bb42014-10-25 00:33:55 +00001734 if (CPPLanguageRuntime::ExtractContextAndIdentifier (name_cstr, context, basename))
Greg Clayton6ecb2322013-05-18 00:11:21 +00001735 lookup_name_type_mask |= (eFunctionNameTypeMethod | eFunctionNameTypeBase);
Greg Claytonc3795402014-10-22 21:47:13 +00001736 else
Greg Clayton65b0e762015-01-28 01:08:39 +00001737 lookup_name_type_mask |= eFunctionNameTypeFull;
Greg Clayton6ecb2322013-05-18 00:11:21 +00001738 }
1739 else
1740 {
Greg Clayton43fe2172013-04-03 02:00:15 +00001741 lookup_name_type_mask |= (eFunctionNameTypeMethod | eFunctionNameTypeBase);
Greg Clayton6ecb2322013-05-18 00:11:21 +00001742 }
Greg Clayton43fe2172013-04-03 02:00:15 +00001743 }
1744 }
1745 else
1746 {
1747 lookup_name_type_mask = name_type_mask;
1748 if (lookup_name_type_mask & eFunctionNameTypeMethod || name_type_mask & eFunctionNameTypeBase)
1749 {
1750 // If they've asked for a CPP method or function name and it can't be that, we don't
1751 // even need to search for CPP methods or names.
Greg Clayton6ecb2322013-05-18 00:11:21 +00001752 CPPLanguageRuntime::MethodName cpp_method (name);
1753 if (cpp_method.IsValid())
Greg Clayton43fe2172013-04-03 02:00:15 +00001754 {
Jim Inghamfa39bb42014-10-25 00:33:55 +00001755 basename = cpp_method.GetBasename();
Greg Clayton6ecb2322013-05-18 00:11:21 +00001756
1757 if (!cpp_method.GetQualifiers().empty())
1758 {
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00001759 // There is a "const" or other qualifier following the end of the function parens,
Greg Clayton6ecb2322013-05-18 00:11:21 +00001760 // this can't be a eFunctionNameTypeBase
1761 lookup_name_type_mask &= ~(eFunctionNameTypeBase);
1762 if (lookup_name_type_mask == eFunctionNameTypeNone)
1763 return;
1764 }
1765 }
1766 else
1767 {
Jim Inghamfa39bb42014-10-25 00:33:55 +00001768 // If the CPP method parser didn't manage to chop this up, try to fill in the base name if we can.
1769 // If a::b::c is passed in, we need to just look up "c", and then we'll filter the result later.
1770 CPPLanguageRuntime::ExtractContextAndIdentifier (name_cstr, context, basename);
Greg Clayton43fe2172013-04-03 02:00:15 +00001771 }
1772 }
1773
1774 if (lookup_name_type_mask & eFunctionNameTypeSelector)
1775 {
1776 if (!ObjCLanguageRuntime::IsPossibleObjCSelector(name_cstr))
1777 {
1778 lookup_name_type_mask &= ~(eFunctionNameTypeSelector);
1779 if (lookup_name_type_mask == eFunctionNameTypeNone)
1780 return;
1781 }
1782 }
1783 }
1784
Jim Inghamfa39bb42014-10-25 00:33:55 +00001785 if (!basename.empty())
Greg Clayton43fe2172013-04-03 02:00:15 +00001786 {
1787 // The name supplied was a partial C++ path like "a::count". In this case we want to do a
1788 // lookup on the basename "count" and then make sure any matching results contain "a::count"
1789 // so that it would match "b::a::count" and "a::count". This is why we set "match_name_after_lookup"
1790 // to true
Jim Inghamfa39bb42014-10-25 00:33:55 +00001791 lookup_name.SetString(basename);
Greg Clayton43fe2172013-04-03 02:00:15 +00001792 match_name_after_lookup = true;
1793 }
1794 else
1795 {
1796 // The name is already correct, just use the exact name as supplied, and we won't need
1797 // to check if any matches contain "name"
1798 lookup_name = name;
1799 match_name_after_lookup = false;
1800 }
Richard Mittonf86248d2013-09-12 02:20:34 +00001801}
Greg Clayton23f8c952014-03-24 23:10:19 +00001802
1803ModuleSP
1804Module::CreateJITModule (const lldb::ObjectFileJITDelegateSP &delegate_sp)
1805{
1806 if (delegate_sp)
1807 {
1808 // Must create a module and place it into a shared pointer before
1809 // we can create an object file since it has a std::weak_ptr back
1810 // to the module, so we need to control the creation carefully in
1811 // this static function
1812 ModuleSP module_sp(new Module());
1813 module_sp->m_objfile_sp.reset (new ObjectFileJIT (module_sp, delegate_sp));
1814 if (module_sp->m_objfile_sp)
1815 {
1816 // Once we get the object file, update our module with the object file's
1817 // architecture since it might differ in vendor/os if some parts were
1818 // unknown.
1819 module_sp->m_objfile_sp->GetArchitecture (module_sp->m_arch);
1820 }
1821 return module_sp;
1822 }
1823 return ModuleSP();
1824}
1825
Greg Clayton08928f32015-02-05 02:01:34 +00001826bool
1827Module::GetIsDynamicLinkEditor()
1828{
1829 ObjectFile * obj_file = GetObjectFile ();
1830
1831 if (obj_file)
1832 return obj_file->GetIsDynamicLinkEditor();
1833
1834 return false;
1835}