blob: 891bd87a20d494b0fc62ad91c5d3059e6650af54 [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"
Greg Clayton1f746072012-08-29 21:13:06 +000029#include "lldb/Symbol/CompileUnit.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000030#include "lldb/Symbol/ObjectFile.h"
31#include "lldb/Symbol/SymbolContext.h"
32#include "lldb/Symbol/SymbolVendor.h"
Greg Clayton43fe2172013-04-03 02:00:15 +000033#include "lldb/Target/CPPLanguageRuntime.h"
34#include "lldb/Target/ObjCLanguageRuntime.h"
Greg Claytonc9660542012-02-05 02:38:54 +000035#include "lldb/Target/Process.h"
Greg Claytond5944cd2013-12-06 01:12:00 +000036#include "lldb/Target/SectionLoadList.h"
Greg Claytonc9660542012-02-05 02:38:54 +000037#include "lldb/Target/Target.h"
Michael Sartaina7499c92013-07-01 19:45:50 +000038#include "lldb/Symbol/SymbolFile.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000039
Greg Clayton23f8c952014-03-24 23:10:19 +000040#include "Plugins/ObjectFile/JIT/ObjectFileJIT.h"
41
Chris Lattner30fdc8d2010-06-08 16:52:24 +000042using namespace lldb;
43using namespace lldb_private;
44
Greg Clayton65a03992011-08-09 00:01:09 +000045// Shared pointers to modules track module lifetimes in
46// targets and in the global module, but this collection
47// will track all module objects that are still alive
48typedef std::vector<Module *> ModuleCollection;
49
50static ModuleCollection &
51GetModuleCollection()
52{
Jim Ingham549f7372011-10-31 23:47:10 +000053 // This module collection needs to live past any module, so we could either make it a
54 // shared pointer in each module or just leak is. Since it is only an empty vector by
55 // the time all the modules have gone away, we just leak it for now. If we decide this
56 // is a big problem we can introduce a Finalize method that will tear everything down in
57 // a predictable order.
58
59 static ModuleCollection *g_module_collection = NULL;
60 if (g_module_collection == NULL)
61 g_module_collection = new ModuleCollection();
62
63 return *g_module_collection;
Greg Clayton65a03992011-08-09 00:01:09 +000064}
65
Greg Claytonb26e6be2012-01-27 18:08:35 +000066Mutex *
Greg Clayton65a03992011-08-09 00:01:09 +000067Module::GetAllocationModuleCollectionMutex()
68{
Greg Claytonb26e6be2012-01-27 18:08:35 +000069 // NOTE: The mutex below must be leaked since the global module list in
70 // the ModuleList class will get torn at some point, and we can't know
71 // if it will tear itself down before the "g_module_collection_mutex" below
72 // will. So we leak a Mutex object below to safeguard against that
73
74 static Mutex *g_module_collection_mutex = NULL;
75 if (g_module_collection_mutex == NULL)
76 g_module_collection_mutex = new Mutex (Mutex::eMutexTypeRecursive); // NOTE: known leak
77 return g_module_collection_mutex;
Greg Clayton65a03992011-08-09 00:01:09 +000078}
79
80size_t
81Module::GetNumberAllocatedModules ()
82{
83 Mutex::Locker locker (GetAllocationModuleCollectionMutex());
84 return GetModuleCollection().size();
85}
86
87Module *
88Module::GetAllocatedModuleAtIndex (size_t idx)
89{
90 Mutex::Locker locker (GetAllocationModuleCollectionMutex());
91 ModuleCollection &modules = GetModuleCollection();
92 if (idx < modules.size())
93 return modules[idx];
94 return NULL;
95}
Greg Clayton29ad7b92012-01-27 18:45:39 +000096#if 0
Greg Clayton65a03992011-08-09 00:01:09 +000097
Greg Clayton29ad7b92012-01-27 18:45:39 +000098// These functions help us to determine if modules are still loaded, yet don't require that
99// you have a command interpreter and can easily be called from an external debugger.
100namespace lldb {
Greg Clayton65a03992011-08-09 00:01:09 +0000101
Greg Clayton29ad7b92012-01-27 18:45:39 +0000102 void
103 ClearModuleInfo (void)
104 {
Greg Clayton0cd70862012-04-09 20:22:01 +0000105 const bool mandatory = true;
106 ModuleList::RemoveOrphanSharedModules(mandatory);
Greg Clayton29ad7b92012-01-27 18:45:39 +0000107 }
108
109 void
110 DumpModuleInfo (void)
111 {
112 Mutex::Locker locker (Module::GetAllocationModuleCollectionMutex());
113 ModuleCollection &modules = GetModuleCollection();
114 const size_t count = modules.size();
Daniel Malead01b2952012-11-29 21:49:15 +0000115 printf ("%s: %" PRIu64 " modules:\n", __PRETTY_FUNCTION__, (uint64_t)count);
Greg Clayton29ad7b92012-01-27 18:45:39 +0000116 for (size_t i=0; i<count; ++i)
117 {
118
119 StreamString strm;
120 Module *module = modules[i];
121 const bool in_shared_module_list = ModuleList::ModuleIsInCache (module);
122 module->GetDescription(&strm, eDescriptionLevelFull);
123 printf ("%p: shared = %i, ref_count = %3u, module = %s\n",
124 module,
125 in_shared_module_list,
126 (uint32_t)module->use_count(),
127 strm.GetString().c_str());
128 }
129 }
130}
131
132#endif
Greg Clayton3a18e312012-10-08 22:41:53 +0000133
Greg Claytonb9a01b32012-02-26 05:51:37 +0000134Module::Module (const ModuleSpec &module_spec) :
135 m_mutex (Mutex::eMutexTypeRecursive),
Greg Clayton34f11592014-03-04 21:20:23 +0000136 m_mod_time (),
137 m_arch (),
Greg Claytonb9a01b32012-02-26 05:51:37 +0000138 m_uuid (),
Greg Clayton34f11592014-03-04 21:20:23 +0000139 m_file (),
140 m_platform_file(),
Greg Claytonfbb76342013-11-20 21:07:01 +0000141 m_remote_install_file(),
Greg Clayton34f11592014-03-04 21:20:23 +0000142 m_symfile_spec (),
143 m_object_name (),
144 m_object_offset (),
145 m_object_mod_time (),
Greg Claytonb9a01b32012-02-26 05:51:37 +0000146 m_objfile_sp (),
147 m_symfile_ap (),
148 m_ast (),
Greg Claytond804d282012-03-15 21:01:31 +0000149 m_source_mappings (),
Greg Clayton23f8c952014-03-24 23:10:19 +0000150 m_sections_ap(),
Greg Claytonb9a01b32012-02-26 05:51:37 +0000151 m_did_load_objfile (false),
152 m_did_load_symbol_vendor (false),
153 m_did_parse_uuid (false),
154 m_did_init_ast (false),
Greg Clayton1d609092012-07-12 22:51:12 +0000155 m_file_has_changed (false),
156 m_first_file_changed_log (false)
Greg Claytonb9a01b32012-02-26 05:51:37 +0000157{
158 // Scope for locker below...
159 {
160 Mutex::Locker locker (GetAllocationModuleCollectionMutex());
161 GetModuleCollection().push_back(this);
162 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000163
Greg Clayton5160ce52013-03-27 23:08:40 +0000164 Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_OBJECT|LIBLLDB_LOG_MODULES));
Greg Claytonb9a01b32012-02-26 05:51:37 +0000165 if (log)
Greg Claytonb5ad4ec2013-04-29 17:25:54 +0000166 log->Printf ("%p Module::Module((%s) '%s%s%s%s')",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000167 static_cast<void*>(this),
Greg Clayton34f11592014-03-04 21:20:23 +0000168 module_spec.GetArchitecture().GetArchitectureName(),
169 module_spec.GetFileSpec().GetPath().c_str(),
170 module_spec.GetObjectName().IsEmpty() ? "" : "(",
171 module_spec.GetObjectName().IsEmpty() ? "" : module_spec.GetObjectName().AsCString(""),
172 module_spec.GetObjectName().IsEmpty() ? "" : ")");
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000173
Greg Clayton34f11592014-03-04 21:20:23 +0000174 // First extract all module specifications from the file using the local
175 // file path. If there are no specifications, then don't fill anything in
176 ModuleSpecList modules_specs;
177 if (ObjectFile::GetModuleSpecifications(module_spec.GetFileSpec(), 0, 0, modules_specs) == 0)
178 return;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000179
Greg Clayton34f11592014-03-04 21:20:23 +0000180 // Now make sure that one of the module specifications matches what we just
181 // extract. We might have a module specification that specifies a file "/usr/lib/dyld"
182 // with UUID XXX, but we might have a local version of "/usr/lib/dyld" that has
183 // UUID YYY and we don't want those to match. If they don't match, just don't
184 // fill any ivars in so we don't accidentally grab the wrong file later since
185 // they don't match...
186 ModuleSpec matching_module_spec;
187 if (modules_specs.FindMatchingModuleSpec(module_spec, matching_module_spec) == 0)
188 return;
Greg Clayton7ab7f892014-05-29 21:33:45 +0000189
190 if (module_spec.GetFileSpec())
191 m_mod_time = module_spec.GetFileSpec().GetModificationTime();
192 else if (matching_module_spec.GetFileSpec())
193 m_mod_time = matching_module_spec.GetFileSpec().GetModificationTime();
194
195 // Copy the architecture from the actual spec if we got one back, else use the one that was specified
196 if (matching_module_spec.GetArchitecture().IsValid())
Greg Clayton34f11592014-03-04 21:20:23 +0000197 m_arch = matching_module_spec.GetArchitecture();
Greg Clayton7ab7f892014-05-29 21:33:45 +0000198 else if (module_spec.GetArchitecture().IsValid())
199 m_arch = module_spec.GetArchitecture();
200
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +0000201 // Copy the file spec over and use the specified one (if there was one) so we
Greg Clayton7ab7f892014-05-29 21:33:45 +0000202 // don't use a path that might have gotten resolved a path in 'matching_module_spec'
203 if (module_spec.GetFileSpec())
204 m_file = module_spec.GetFileSpec();
205 else if (matching_module_spec.GetFileSpec())
206 m_file = matching_module_spec.GetFileSpec();
207
208 // Copy the platform file spec over
209 if (module_spec.GetPlatformFileSpec())
210 m_platform_file = module_spec.GetPlatformFileSpec();
211 else if (matching_module_spec.GetPlatformFileSpec())
212 m_platform_file = matching_module_spec.GetPlatformFileSpec();
213
214 // Copy the symbol file spec over
215 if (module_spec.GetSymbolFileSpec())
216 m_symfile_spec = module_spec.GetSymbolFileSpec();
217 else if (matching_module_spec.GetSymbolFileSpec())
218 m_symfile_spec = matching_module_spec.GetSymbolFileSpec();
219
220 // Copy the object name over
221 if (matching_module_spec.GetObjectName())
222 m_object_name = matching_module_spec.GetObjectName();
223 else
224 m_object_name = module_spec.GetObjectName();
225
226 // Always trust the object offset (file offset) and object modification
227 // time (for mod time in a BSD static archive) of from the matching
228 // module specification
Greg Clayton36d7c892014-05-29 17:52:46 +0000229 m_object_offset = matching_module_spec.GetObjectOffset();
230 m_object_mod_time = matching_module_spec.GetObjectModificationTime();
Greg Clayton34f11592014-03-04 21:20:23 +0000231
Greg Claytonb9a01b32012-02-26 05:51:37 +0000232}
233
Greg Claytone72dfb32012-02-24 01:59:29 +0000234Module::Module(const FileSpec& file_spec,
235 const ArchSpec& arch,
236 const ConstString *object_name,
Zachary Turnera746e8e2014-07-02 17:24:07 +0000237 lldb::offset_t object_offset,
Greg Clayton57abc5d2013-05-10 21:47:16 +0000238 const TimeValue *object_mod_time_ptr) :
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000239 m_mutex (Mutex::eMutexTypeRecursive),
240 m_mod_time (file_spec.GetModificationTime()),
241 m_arch (arch),
242 m_uuid (),
243 m_file (file_spec),
Greg Clayton32e0a752011-03-30 18:16:51 +0000244 m_platform_file(),
Greg Claytonfbb76342013-11-20 21:07:01 +0000245 m_remote_install_file (),
Greg Claytone72dfb32012-02-24 01:59:29 +0000246 m_symfile_spec (),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000247 m_object_name (),
Greg Clayton8b82f082011-04-12 05:54:46 +0000248 m_object_offset (object_offset),
Greg Clayton57abc5d2013-05-10 21:47:16 +0000249 m_object_mod_time (),
Greg Clayton762f7132011-09-18 18:59:15 +0000250 m_objfile_sp (),
Greg Claytone83e7312010-09-07 23:40:05 +0000251 m_symfile_ap (),
Greg Clayton6beaaa62011-01-17 03:46:26 +0000252 m_ast (),
Greg Claytond804d282012-03-15 21:01:31 +0000253 m_source_mappings (),
Greg Clayton23f8c952014-03-24 23:10:19 +0000254 m_sections_ap(),
Greg Claytone83e7312010-09-07 23:40:05 +0000255 m_did_load_objfile (false),
256 m_did_load_symbol_vendor (false),
257 m_did_parse_uuid (false),
Greg Clayton6beaaa62011-01-17 03:46:26 +0000258 m_did_init_ast (false),
Greg Clayton1d609092012-07-12 22:51:12 +0000259 m_file_has_changed (false),
260 m_first_file_changed_log (false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000261{
Greg Clayton65a03992011-08-09 00:01:09 +0000262 // Scope for locker below...
263 {
264 Mutex::Locker locker (GetAllocationModuleCollectionMutex());
265 GetModuleCollection().push_back(this);
266 }
267
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000268 if (object_name)
269 m_object_name = *object_name;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000270
Greg Clayton57abc5d2013-05-10 21:47:16 +0000271 if (object_mod_time_ptr)
272 m_object_mod_time = *object_mod_time_ptr;
273
Greg Clayton5160ce52013-03-27 23:08:40 +0000274 Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_OBJECT|LIBLLDB_LOG_MODULES));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000275 if (log)
Greg Claytonb5ad4ec2013-04-29 17:25:54 +0000276 log->Printf ("%p Module::Module((%s) '%s%s%s%s')",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000277 static_cast<void*>(this), m_arch.GetArchitectureName(),
Greg Claytonb5ad4ec2013-04-29 17:25:54 +0000278 m_file.GetPath().c_str(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000279 m_object_name.IsEmpty() ? "" : "(",
280 m_object_name.IsEmpty() ? "" : m_object_name.AsCString(""),
281 m_object_name.IsEmpty() ? "" : ")");
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000282}
283
Greg Clayton23f8c952014-03-24 23:10:19 +0000284Module::Module () :
285 m_mutex (Mutex::eMutexTypeRecursive),
286 m_mod_time (),
287 m_arch (),
288 m_uuid (),
289 m_file (),
290 m_platform_file(),
291 m_remote_install_file (),
292 m_symfile_spec (),
293 m_object_name (),
294 m_object_offset (0),
295 m_object_mod_time (),
296 m_objfile_sp (),
297 m_symfile_ap (),
298 m_ast (),
299 m_source_mappings (),
300 m_sections_ap(),
301 m_did_load_objfile (false),
302 m_did_load_symbol_vendor (false),
303 m_did_parse_uuid (false),
304 m_did_init_ast (false),
Greg Clayton23f8c952014-03-24 23:10:19 +0000305 m_file_has_changed (false),
306 m_first_file_changed_log (false)
307{
308 Mutex::Locker locker (GetAllocationModuleCollectionMutex());
309 GetModuleCollection().push_back(this);
310}
311
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000312Module::~Module()
313{
Greg Clayton217b28b2013-05-22 20:13:22 +0000314 // Lock our module down while we tear everything down to make sure
315 // we don't get any access to the module while it is being destroyed
316 Mutex::Locker locker (m_mutex);
Greg Clayton65a03992011-08-09 00:01:09 +0000317 // Scope for locker below...
318 {
319 Mutex::Locker locker (GetAllocationModuleCollectionMutex());
320 ModuleCollection &modules = GetModuleCollection();
321 ModuleCollection::iterator end = modules.end();
322 ModuleCollection::iterator pos = std::find(modules.begin(), end, this);
Greg Clayton3a18e312012-10-08 22:41:53 +0000323 assert (pos != end);
324 modules.erase(pos);
Greg Clayton65a03992011-08-09 00:01:09 +0000325 }
Greg Clayton5160ce52013-03-27 23:08:40 +0000326 Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_OBJECT|LIBLLDB_LOG_MODULES));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000327 if (log)
Greg Claytonb5ad4ec2013-04-29 17:25:54 +0000328 log->Printf ("%p Module::~Module((%s) '%s%s%s%s')",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000329 static_cast<void*>(this),
Greg Clayton64195a22011-02-23 00:35:02 +0000330 m_arch.GetArchitectureName(),
Greg Claytonb5ad4ec2013-04-29 17:25:54 +0000331 m_file.GetPath().c_str(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000332 m_object_name.IsEmpty() ? "" : "(",
333 m_object_name.IsEmpty() ? "" : m_object_name.AsCString(""),
334 m_object_name.IsEmpty() ? "" : ")");
Greg Clayton6beaaa62011-01-17 03:46:26 +0000335 // Release any auto pointers before we start tearing down our member
336 // variables since the object file and symbol files might need to make
337 // function calls back into this module object. The ordering is important
338 // here because symbol files can require the module object file. So we tear
339 // down the symbol file first, then the object file.
Greg Clayton3046e662013-07-10 01:23:25 +0000340 m_sections_ap.reset();
Greg Clayton6beaaa62011-01-17 03:46:26 +0000341 m_symfile_ap.reset();
Greg Clayton762f7132011-09-18 18:59:15 +0000342 m_objfile_sp.reset();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000343}
344
Greg Claytonc7f09cc2012-02-24 21:55:59 +0000345ObjectFile *
Andrew MacPherson17220c12014-03-05 10:12:43 +0000346Module::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 +0000347{
348 if (m_objfile_sp)
349 {
350 error.SetErrorString ("object file already exists");
351 }
352 else
353 {
354 Mutex::Locker locker (m_mutex);
355 if (process_sp)
356 {
Greg Claytonc7f09cc2012-02-24 21:55:59 +0000357 m_did_load_objfile = true;
Andrew MacPherson17220c12014-03-05 10:12:43 +0000358 std::unique_ptr<DataBufferHeap> data_ap (new DataBufferHeap (size_to_read, 0));
Greg Claytonc7f09cc2012-02-24 21:55:59 +0000359 Error readmem_error;
360 const size_t bytes_read = process_sp->ReadMemory (header_addr,
361 data_ap->GetBytes(),
362 data_ap->GetByteSize(),
363 readmem_error);
Andrew MacPherson17220c12014-03-05 10:12:43 +0000364 if (bytes_read == size_to_read)
Greg Claytonc7f09cc2012-02-24 21:55:59 +0000365 {
366 DataBufferSP data_sp(data_ap.release());
367 m_objfile_sp = ObjectFile::FindPlugin(shared_from_this(), process_sp, header_addr, data_sp);
368 if (m_objfile_sp)
369 {
Greg Clayton3e10cf32012-04-20 19:50:20 +0000370 StreamString s;
Daniel Malead01b2952012-11-29 21:49:15 +0000371 s.Printf("0x%16.16" PRIx64, header_addr);
Greg Clayton3e10cf32012-04-20 19:50:20 +0000372 m_object_name.SetCString (s.GetData());
373
374 // Once we get the object file, update our module with the object file's
Greg Claytonc7f09cc2012-02-24 21:55:59 +0000375 // architecture since it might differ in vendor/os if some parts were
376 // unknown.
377 m_objfile_sp->GetArchitecture (m_arch);
378 }
379 else
380 {
381 error.SetErrorString ("unable to find suitable object file plug-in");
382 }
383 }
384 else
385 {
386 error.SetErrorStringWithFormat ("unable to read header from memory: %s", readmem_error.AsCString());
387 }
388 }
389 else
390 {
391 error.SetErrorString ("invalid process");
392 }
393 }
394 return m_objfile_sp.get();
395}
396
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000397
Greg Clayton60830262011-02-04 18:53:10 +0000398const lldb_private::UUID&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000399Module::GetUUID()
400{
401 Mutex::Locker locker (m_mutex);
Greg Claytone83e7312010-09-07 23:40:05 +0000402 if (m_did_parse_uuid == false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000403 {
404 ObjectFile * obj_file = GetObjectFile ();
405
406 if (obj_file != NULL)
407 {
408 obj_file->GetUUID(&m_uuid);
Greg Claytone83e7312010-09-07 23:40:05 +0000409 m_did_parse_uuid = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000410 }
411 }
412 return m_uuid;
413}
414
Greg Clayton6beaaa62011-01-17 03:46:26 +0000415ClangASTContext &
416Module::GetClangASTContext ()
417{
418 Mutex::Locker locker (m_mutex);
419 if (m_did_init_ast == false)
420 {
421 ObjectFile * objfile = GetObjectFile();
Greg Clayton514487e2011-02-15 21:59:32 +0000422 ArchSpec object_arch;
423 if (objfile && objfile->GetArchitecture(object_arch))
Greg Clayton6beaaa62011-01-17 03:46:26 +0000424 {
425 m_did_init_ast = true;
Jason Molenda981d4df2012-10-16 20:45:49 +0000426
427 // LLVM wants this to be set to iOS or MacOSX; if we're working on
428 // a bare-boards type image, change the triple for llvm's benefit.
429 if (object_arch.GetTriple().getVendor() == llvm::Triple::Apple
430 && object_arch.GetTriple().getOS() == llvm::Triple::UnknownOS)
431 {
432 if (object_arch.GetTriple().getArch() == llvm::Triple::arm ||
Todd Fialad8eaa172014-07-23 14:37:35 +0000433 object_arch.GetTriple().getArch() == llvm::Triple::aarch64 ||
Jason Molenda981d4df2012-10-16 20:45:49 +0000434 object_arch.GetTriple().getArch() == llvm::Triple::thumb)
435 {
436 object_arch.GetTriple().setOS(llvm::Triple::IOS);
437 }
438 else
439 {
440 object_arch.GetTriple().setOS(llvm::Triple::MacOSX);
441 }
442 }
Greg Clayton514487e2011-02-15 21:59:32 +0000443 m_ast.SetArchitecture (object_arch);
Greg Clayton6beaaa62011-01-17 03:46:26 +0000444 }
445 }
446 return m_ast;
447}
448
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000449void
450Module::ParseAllDebugSymbols()
451{
452 Mutex::Locker locker (m_mutex);
Greg Claytonc7bece562013-01-25 18:06:21 +0000453 size_t num_comp_units = GetNumCompileUnits();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000454 if (num_comp_units == 0)
455 return;
456
Greg Claytona2eee182011-09-17 07:23:18 +0000457 SymbolContext sc;
Greg Claytone1cd1be2012-01-29 20:56:30 +0000458 sc.module_sp = shared_from_this();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000459 SymbolVendor *symbols = GetSymbolVendor ();
460
Greg Claytonc7bece562013-01-25 18:06:21 +0000461 for (size_t cu_idx = 0; cu_idx < num_comp_units; cu_idx++)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000462 {
463 sc.comp_unit = symbols->GetCompileUnitAtIndex(cu_idx).get();
464 if (sc.comp_unit)
465 {
466 sc.function = NULL;
467 symbols->ParseVariablesForContext(sc);
468
469 symbols->ParseCompileUnitFunctions(sc);
470
Greg Claytonc7bece562013-01-25 18:06:21 +0000471 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 +0000472 {
473 symbols->ParseFunctionBlocks(sc);
474
475 // Parse the variables for this function and all its blocks
476 symbols->ParseVariablesForContext(sc);
477 }
478
479
480 // Parse all types for this compile unit
481 sc.function = NULL;
482 symbols->ParseTypes(sc);
483 }
484 }
485}
486
487void
488Module::CalculateSymbolContext(SymbolContext* sc)
489{
Greg Claytone1cd1be2012-01-29 20:56:30 +0000490 sc->module_sp = shared_from_this();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000491}
492
Greg Claytone72dfb32012-02-24 01:59:29 +0000493ModuleSP
Greg Clayton7e9b1fd2011-08-12 21:40:01 +0000494Module::CalculateSymbolContextModule ()
495{
Greg Claytone72dfb32012-02-24 01:59:29 +0000496 return shared_from_this();
Greg Clayton7e9b1fd2011-08-12 21:40:01 +0000497}
498
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000499void
500Module::DumpSymbolContext(Stream *s)
501{
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000502 s->Printf(", Module{%p}", static_cast<void*>(this));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000503}
504
Greg Claytonc7bece562013-01-25 18:06:21 +0000505size_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000506Module::GetNumCompileUnits()
507{
508 Mutex::Locker locker (m_mutex);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000509 Timer scoped_timer(__PRETTY_FUNCTION__,
510 "Module::GetNumCompileUnits (module = %p)",
511 static_cast<void*>(this));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000512 SymbolVendor *symbols = GetSymbolVendor ();
513 if (symbols)
514 return symbols->GetNumCompileUnits();
515 return 0;
516}
517
518CompUnitSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000519Module::GetCompileUnitAtIndex (size_t index)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000520{
521 Mutex::Locker locker (m_mutex);
Greg Claytonc7bece562013-01-25 18:06:21 +0000522 size_t num_comp_units = GetNumCompileUnits ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000523 CompUnitSP cu_sp;
524
525 if (index < num_comp_units)
526 {
527 SymbolVendor *symbols = GetSymbolVendor ();
528 if (symbols)
529 cu_sp = symbols->GetCompileUnitAtIndex(index);
530 }
531 return cu_sp;
532}
533
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000534bool
535Module::ResolveFileAddress (lldb::addr_t vm_addr, Address& so_addr)
536{
537 Mutex::Locker locker (m_mutex);
Daniel Malead01b2952012-11-29 21:49:15 +0000538 Timer scoped_timer(__PRETTY_FUNCTION__, "Module::ResolveFileAddress (vm_addr = 0x%" PRIx64 ")", vm_addr);
Greg Clayton3046e662013-07-10 01:23:25 +0000539 SectionList *section_list = GetSectionList();
540 if (section_list)
541 return so_addr.ResolveAddressUsingFileSections(vm_addr, section_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000542 return false;
543}
544
545uint32_t
Ashok Thirumurthi35729bb2013-09-24 15:34:13 +0000546Module::ResolveSymbolContextForAddress (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc,
547 bool resolve_tail_call_address)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000548{
549 Mutex::Locker locker (m_mutex);
550 uint32_t resolved_flags = 0;
551
Greg Clayton72310352013-02-23 04:12:47 +0000552 // Clear the result symbol context in case we don't find anything, but don't clear the target
553 sc.Clear(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000554
555 // Get the section from the section/offset address.
Greg Claytone72dfb32012-02-24 01:59:29 +0000556 SectionSP section_sp (so_addr.GetSection());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000557
558 // Make sure the section matches this module before we try and match anything
Greg Claytone72dfb32012-02-24 01:59:29 +0000559 if (section_sp && section_sp->GetModule().get() == this)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000560 {
561 // If the section offset based address resolved itself, then this
562 // is the right module.
Greg Claytone1cd1be2012-01-29 20:56:30 +0000563 sc.module_sp = shared_from_this();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000564 resolved_flags |= eSymbolContextModule;
565
Ashok Thirumurthi38807142013-09-16 22:00:17 +0000566 SymbolVendor* sym_vendor = GetSymbolVendor();
567 if (!sym_vendor)
568 return resolved_flags;
569
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000570 // Resolve the compile unit, function, block, line table or line
571 // entry if requested.
572 if (resolve_scope & eSymbolContextCompUnit ||
573 resolve_scope & eSymbolContextFunction ||
574 resolve_scope & eSymbolContextBlock ||
575 resolve_scope & eSymbolContextLineEntry )
576 {
Ashok Thirumurthi38807142013-09-16 22:00:17 +0000577 resolved_flags |= sym_vendor->ResolveSymbolContext (so_addr, resolve_scope, sc);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000578 }
579
Jim Ingham680e1772010-08-31 23:51:36 +0000580 // Resolve the symbol if requested, but don't re-look it up if we've already found it.
581 if (resolve_scope & eSymbolContextSymbol && !(resolved_flags & eSymbolContextSymbol))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000582 {
Ashok Thirumurthi38807142013-09-16 22:00:17 +0000583 Symtab *symtab = sym_vendor->GetSymtab();
584 if (symtab && so_addr.IsSectionOffset())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000585 {
Ashok Thirumurthi38807142013-09-16 22:00:17 +0000586 sc.symbol = symtab->FindSymbolContainingFileAddress(so_addr.GetFileAddress());
Ashok Thirumurthi35729bb2013-09-24 15:34:13 +0000587 if (!sc.symbol &&
588 resolve_scope & eSymbolContextFunction && !(resolved_flags & eSymbolContextFunction))
589 {
590 bool verify_unique = false; // No need to check again since ResolveSymbolContext failed to find a symbol at this address.
591 if (ObjectFile *obj_file = sc.module_sp->GetObjectFile())
592 sc.symbol = obj_file->ResolveSymbolForAddress(so_addr, verify_unique);
593 }
594
Ashok Thirumurthi38807142013-09-16 22:00:17 +0000595 if (sc.symbol)
Greg Clayton93e28612013-10-11 22:03:48 +0000596 {
597 if (sc.symbol->IsSynthetic())
598 {
599 // We have a synthetic symbol so lets check if the object file
600 // from the symbol file in the symbol vendor is different than
601 // the object file for the module, and if so search its symbol
602 // table to see if we can come up with a better symbol. For example
603 // dSYM files on MacOSX have an unstripped symbol table inside of
604 // them.
605 ObjectFile *symtab_objfile = symtab->GetObjectFile();
606 if (symtab_objfile && symtab_objfile->IsStripped())
607 {
608 SymbolFile *symfile = sym_vendor->GetSymbolFile();
609 if (symfile)
610 {
611 ObjectFile *symfile_objfile = symfile->GetObjectFile();
612 if (symfile_objfile != symtab_objfile)
613 {
614 Symtab *symfile_symtab = symfile_objfile->GetSymtab();
615 if (symfile_symtab)
616 {
617 Symbol *symbol = symfile_symtab->FindSymbolContainingFileAddress(so_addr.GetFileAddress());
618 if (symbol && !symbol->IsSynthetic())
619 {
620 sc.symbol = symbol;
621 }
622 }
623 }
624 }
625 }
626 }
Ashok Thirumurthi38807142013-09-16 22:00:17 +0000627 resolved_flags |= eSymbolContextSymbol;
Greg Clayton93e28612013-10-11 22:03:48 +0000628 }
Ashok Thirumurthi38807142013-09-16 22:00:17 +0000629 }
630 }
631
632 // For function symbols, so_addr may be off by one. This is a convention consistent
633 // with FDE row indices in eh_frame sections, but requires extra logic here to permit
634 // symbol lookup for disassembly and unwind.
635 if (resolve_scope & eSymbolContextSymbol && !(resolved_flags & eSymbolContextSymbol) &&
Ashok Thirumurthi35729bb2013-09-24 15:34:13 +0000636 resolve_tail_call_address && so_addr.IsSectionOffset())
Ashok Thirumurthi38807142013-09-16 22:00:17 +0000637 {
638 Address previous_addr = so_addr;
Greg Claytonedfaae32013-09-18 20:03:31 +0000639 previous_addr.Slide(-1);
Ashok Thirumurthi38807142013-09-16 22:00:17 +0000640
Ashok Thirumurthi35729bb2013-09-24 15:34:13 +0000641 bool do_resolve_tail_call_address = false; // prevent recursion
642 const uint32_t flags = ResolveSymbolContextForAddress(previous_addr, resolve_scope, sc,
643 do_resolve_tail_call_address);
Ashok Thirumurthi38807142013-09-16 22:00:17 +0000644 if (flags & eSymbolContextSymbol)
645 {
646 AddressRange addr_range;
647 if (sc.GetAddressRange (eSymbolContextFunction | eSymbolContextSymbol, 0, false, addr_range))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000648 {
Ashok Thirumurthi38807142013-09-16 22:00:17 +0000649 if (addr_range.GetBaseAddress().GetSection() == so_addr.GetSection())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000650 {
Ashok Thirumurthi38807142013-09-16 22:00:17 +0000651 // If the requested address is one past the address range of a function (i.e. a tail call),
652 // or the decremented address is the start of a function (i.e. some forms of trampoline),
653 // indicate that the symbol has been resolved.
654 if (so_addr.GetOffset() == addr_range.GetBaseAddress().GetOffset() ||
655 so_addr.GetOffset() == addr_range.GetBaseAddress().GetOffset() + addr_range.GetByteSize())
656 {
657 resolved_flags |= flags;
658 }
659 }
660 else
661 {
662 sc.symbol = nullptr; // Don't trust the symbol if the sections didn't match.
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000663 }
664 }
665 }
666 }
667 }
668 return resolved_flags;
669}
670
671uint32_t
Greg Clayton274060b2010-10-20 20:54:39 +0000672Module::ResolveSymbolContextForFilePath
673(
674 const char *file_path,
675 uint32_t line,
676 bool check_inlines,
677 uint32_t resolve_scope,
678 SymbolContextList& sc_list
679)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000680{
Greg Clayton274060b2010-10-20 20:54:39 +0000681 FileSpec file_spec(file_path, false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000682 return ResolveSymbolContextsForFileSpec (file_spec, line, check_inlines, resolve_scope, sc_list);
683}
684
685uint32_t
686Module::ResolveSymbolContextsForFileSpec (const FileSpec &file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list)
687{
688 Mutex::Locker locker (m_mutex);
689 Timer scoped_timer(__PRETTY_FUNCTION__,
Greg Claytonb5ad4ec2013-04-29 17:25:54 +0000690 "Module::ResolveSymbolContextForFilePath (%s:%u, check_inlines = %s, resolve_scope = 0x%8.8x)",
691 file_spec.GetPath().c_str(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000692 line,
693 check_inlines ? "yes" : "no",
694 resolve_scope);
695
696 const uint32_t initial_count = sc_list.GetSize();
697
698 SymbolVendor *symbols = GetSymbolVendor ();
699 if (symbols)
700 symbols->ResolveSymbolContext (file_spec, line, check_inlines, resolve_scope, sc_list);
701
702 return sc_list.GetSize() - initial_count;
703}
704
705
Greg Claytonc7bece562013-01-25 18:06:21 +0000706size_t
707Module::FindGlobalVariables (const ConstString &name,
708 const ClangNamespaceDecl *namespace_decl,
709 bool append,
710 size_t max_matches,
711 VariableList& variables)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000712{
713 SymbolVendor *symbols = GetSymbolVendor ();
714 if (symbols)
Sean Callanan213fdb82011-10-13 01:49:10 +0000715 return symbols->FindGlobalVariables(name, namespace_decl, append, max_matches, variables);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000716 return 0;
717}
Greg Claytonc7bece562013-01-25 18:06:21 +0000718
719size_t
720Module::FindGlobalVariables (const RegularExpression& regex,
721 bool append,
722 size_t max_matches,
723 VariableList& variables)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000724{
725 SymbolVendor *symbols = GetSymbolVendor ();
726 if (symbols)
727 return symbols->FindGlobalVariables(regex, append, max_matches, variables);
728 return 0;
729}
730
Greg Claytonc7bece562013-01-25 18:06:21 +0000731size_t
Greg Clayton644247c2011-07-07 01:59:51 +0000732Module::FindCompileUnits (const FileSpec &path,
733 bool append,
734 SymbolContextList &sc_list)
735{
736 if (!append)
737 sc_list.Clear();
738
Greg Claytonc7bece562013-01-25 18:06:21 +0000739 const size_t start_size = sc_list.GetSize();
740 const size_t num_compile_units = GetNumCompileUnits();
Greg Clayton644247c2011-07-07 01:59:51 +0000741 SymbolContext sc;
Greg Claytone1cd1be2012-01-29 20:56:30 +0000742 sc.module_sp = shared_from_this();
Sean Callananddd7a2a2013-10-03 22:27:29 +0000743 const bool compare_directory = (bool)path.GetDirectory();
Greg Claytonc7bece562013-01-25 18:06:21 +0000744 for (size_t i=0; i<num_compile_units; ++i)
Greg Clayton644247c2011-07-07 01:59:51 +0000745 {
746 sc.comp_unit = GetCompileUnitAtIndex(i).get();
Greg Clayton2dafd8e2012-04-23 22:00:21 +0000747 if (sc.comp_unit)
748 {
749 if (FileSpec::Equal (*sc.comp_unit, path, compare_directory))
750 sc_list.Append(sc);
751 }
Greg Clayton644247c2011-07-07 01:59:51 +0000752 }
753 return sc_list.GetSize() - start_size;
754}
755
Greg Claytonc7bece562013-01-25 18:06:21 +0000756size_t
Sean Callananb6d70eb2011-10-12 02:08:07 +0000757Module::FindFunctions (const ConstString &name,
758 const ClangNamespaceDecl *namespace_decl,
Greg Claytonc7bece562013-01-25 18:06:21 +0000759 uint32_t name_type_mask,
Sean Callanan9df05fb2012-02-10 22:52:19 +0000760 bool include_symbols,
761 bool include_inlines,
Greg Clayton931180e2011-01-27 06:44:37 +0000762 bool append,
763 SymbolContextList& sc_list)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000764{
Greg Clayton931180e2011-01-27 06:44:37 +0000765 if (!append)
766 sc_list.Clear();
767
Greg Clayton43fe2172013-04-03 02:00:15 +0000768 const size_t old_size = sc_list.GetSize();
Greg Clayton931180e2011-01-27 06:44:37 +0000769
770 // Find all the functions (not symbols, but debug information functions...
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000771 SymbolVendor *symbols = GetSymbolVendor ();
Greg Clayton43fe2172013-04-03 02:00:15 +0000772
773 if (name_type_mask & eFunctionNameTypeAuto)
Greg Clayton931180e2011-01-27 06:44:37 +0000774 {
Greg Clayton43fe2172013-04-03 02:00:15 +0000775 ConstString lookup_name;
776 uint32_t lookup_name_type_mask = 0;
777 bool match_name_after_lookup = false;
778 Module::PrepareForFunctionNameLookup (name,
779 name_type_mask,
780 lookup_name,
781 lookup_name_type_mask,
782 match_name_after_lookup);
783
784 if (symbols)
Michael Sartaina7499c92013-07-01 19:45:50 +0000785 {
Greg Clayton43fe2172013-04-03 02:00:15 +0000786 symbols->FindFunctions(lookup_name,
787 namespace_decl,
788 lookup_name_type_mask,
789 include_inlines,
790 append,
791 sc_list);
792
Michael Sartaina7499c92013-07-01 19:45:50 +0000793 // Now check our symbol table for symbols that are code symbols if requested
794 if (include_symbols)
Greg Clayton931180e2011-01-27 06:44:37 +0000795 {
Michael Sartaina7499c92013-07-01 19:45:50 +0000796 Symtab *symtab = symbols->GetSymtab();
Greg Clayton43fe2172013-04-03 02:00:15 +0000797 if (symtab)
798 symtab->FindFunctionSymbols(lookup_name, lookup_name_type_mask, sc_list);
799 }
800 }
801
802 if (match_name_after_lookup)
803 {
804 SymbolContext sc;
805 size_t i = old_size;
806 while (i<sc_list.GetSize())
807 {
808 if (sc_list.GetContextAtIndex(i, sc))
Greg Clayton931180e2011-01-27 06:44:37 +0000809 {
Greg Clayton43fe2172013-04-03 02:00:15 +0000810 const char *func_name = sc.GetFunctionName().GetCString();
811 if (func_name && strstr (func_name, name.GetCString()) == NULL)
Greg Clayton931180e2011-01-27 06:44:37 +0000812 {
Greg Clayton43fe2172013-04-03 02:00:15 +0000813 // Remove the current context
814 sc_list.RemoveContextAtIndex(i);
815 // Don't increment i and continue in the loop
816 continue;
Greg Clayton931180e2011-01-27 06:44:37 +0000817 }
818 }
Greg Clayton43fe2172013-04-03 02:00:15 +0000819 ++i;
820 }
821 }
Greg Clayton43fe2172013-04-03 02:00:15 +0000822 }
823 else
824 {
825 if (symbols)
Michael Sartaina7499c92013-07-01 19:45:50 +0000826 {
Greg Clayton43fe2172013-04-03 02:00:15 +0000827 symbols->FindFunctions(name, namespace_decl, name_type_mask, include_inlines, append, sc_list);
828
Michael Sartaina7499c92013-07-01 19:45:50 +0000829 // Now check our symbol table for symbols that are code symbols if requested
830 if (include_symbols)
Greg Clayton43fe2172013-04-03 02:00:15 +0000831 {
Michael Sartaina7499c92013-07-01 19:45:50 +0000832 Symtab *symtab = symbols->GetSymtab();
Greg Clayton43fe2172013-04-03 02:00:15 +0000833 if (symtab)
834 symtab->FindFunctionSymbols(name, name_type_mask, sc_list);
Greg Clayton931180e2011-01-27 06:44:37 +0000835 }
836 }
837 }
Greg Clayton43fe2172013-04-03 02:00:15 +0000838
839 return sc_list.GetSize() - old_size;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000840}
841
Greg Claytonc7bece562013-01-25 18:06:21 +0000842size_t
Greg Clayton931180e2011-01-27 06:44:37 +0000843Module::FindFunctions (const RegularExpression& regex,
Sean Callanan9df05fb2012-02-10 22:52:19 +0000844 bool include_symbols,
845 bool include_inlines,
Greg Clayton931180e2011-01-27 06:44:37 +0000846 bool append,
847 SymbolContextList& sc_list)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000848{
Greg Clayton931180e2011-01-27 06:44:37 +0000849 if (!append)
850 sc_list.Clear();
851
Greg Claytonc7bece562013-01-25 18:06:21 +0000852 const size_t start_size = sc_list.GetSize();
Greg Clayton931180e2011-01-27 06:44:37 +0000853
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000854 SymbolVendor *symbols = GetSymbolVendor ();
855 if (symbols)
Greg Clayton931180e2011-01-27 06:44:37 +0000856 {
Michael Sartaina7499c92013-07-01 19:45:50 +0000857 symbols->FindFunctions(regex, include_inlines, append, sc_list);
858
859 // Now check our symbol table for symbols that are code symbols if requested
860 if (include_symbols)
Greg Clayton931180e2011-01-27 06:44:37 +0000861 {
Michael Sartaina7499c92013-07-01 19:45:50 +0000862 Symtab *symtab = symbols->GetSymtab();
Greg Clayton931180e2011-01-27 06:44:37 +0000863 if (symtab)
864 {
865 std::vector<uint32_t> symbol_indexes;
Matt Kopec00049b82013-02-27 20:13:38 +0000866 symtab->AppendSymbolIndexesMatchingRegExAndType (regex, eSymbolTypeAny, Symtab::eDebugAny, Symtab::eVisibilityAny, symbol_indexes);
Greg Claytonc7bece562013-01-25 18:06:21 +0000867 const size_t num_matches = symbol_indexes.size();
Greg Clayton931180e2011-01-27 06:44:37 +0000868 if (num_matches)
869 {
870 SymbolContext sc(this);
Greg Claytond8cf1a12013-06-12 00:46:38 +0000871 const size_t end_functions_added_index = sc_list.GetSize();
872 size_t num_functions_added_to_sc_list = end_functions_added_index - start_size;
873 if (num_functions_added_to_sc_list == 0)
Greg Clayton931180e2011-01-27 06:44:37 +0000874 {
Greg Claytond8cf1a12013-06-12 00:46:38 +0000875 // No functions were added, just symbols, so we can just append them
876 for (size_t i=0; i<num_matches; ++i)
877 {
878 sc.symbol = symtab->SymbolAtIndex(symbol_indexes[i]);
879 SymbolType sym_type = sc.symbol->GetType();
880 if (sc.symbol && (sym_type == eSymbolTypeCode ||
881 sym_type == eSymbolTypeResolver))
882 sc_list.Append(sc);
883 }
884 }
885 else
886 {
887 typedef std::map<lldb::addr_t, uint32_t> FileAddrToIndexMap;
888 FileAddrToIndexMap file_addr_to_index;
889 for (size_t i=start_size; i<end_functions_added_index; ++i)
890 {
891 const SymbolContext &sc = sc_list[i];
892 if (sc.block)
893 continue;
894 file_addr_to_index[sc.function->GetAddressRange().GetBaseAddress().GetFileAddress()] = i;
895 }
896
897 FileAddrToIndexMap::const_iterator end = file_addr_to_index.end();
898 // Functions were added so we need to merge symbols into any
899 // existing function symbol contexts
900 for (size_t i=start_size; i<num_matches; ++i)
901 {
902 sc.symbol = symtab->SymbolAtIndex(symbol_indexes[i]);
903 SymbolType sym_type = sc.symbol->GetType();
904 if (sc.symbol && (sym_type == eSymbolTypeCode ||
905 sym_type == eSymbolTypeResolver))
906 {
907 FileAddrToIndexMap::const_iterator pos = file_addr_to_index.find(sc.symbol->GetAddress().GetFileAddress());
908 if (pos == end)
909 sc_list.Append(sc);
910 else
911 sc_list[pos->second].symbol = sc.symbol;
912 }
913 }
Greg Clayton931180e2011-01-27 06:44:37 +0000914 }
915 }
916 }
917 }
918 }
919 return sc_list.GetSize() - start_size;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000920}
921
Richard Mittonf86248d2013-09-12 02:20:34 +0000922void
923Module::FindAddressesForLine (const lldb::TargetSP target_sp,
924 const FileSpec &file, uint32_t line,
925 Function *function,
926 std::vector<Address> &output_local, std::vector<Address> &output_extern)
927{
928 SearchFilterByModule filter(target_sp, m_file);
929 AddressResolverFileLine resolver(file, line, true);
930 resolver.ResolveAddress (filter);
931
932 for (size_t n=0;n<resolver.GetNumberOfAddresses();n++)
933 {
934 Address addr = resolver.GetAddressRangeAtIndex(n).GetBaseAddress();
935 Function *f = addr.CalculateSymbolContextFunction();
936 if (f && f == function)
937 output_local.push_back (addr);
938 else
939 output_extern.push_back (addr);
940 }
941}
942
Greg Claytonc7bece562013-01-25 18:06:21 +0000943size_t
Greg Clayton84db9102012-03-26 23:03:23 +0000944Module::FindTypes_Impl (const SymbolContext& sc,
945 const ConstString &name,
946 const ClangNamespaceDecl *namespace_decl,
947 bool append,
Greg Claytonc7bece562013-01-25 18:06:21 +0000948 size_t max_matches,
Greg Clayton84db9102012-03-26 23:03:23 +0000949 TypeList& types)
Greg Clayton3504eee2010-08-03 01:26:16 +0000950{
951 Timer scoped_timer(__PRETTY_FUNCTION__, __PRETTY_FUNCTION__);
952 if (sc.module_sp.get() == NULL || sc.module_sp.get() == this)
953 {
954 SymbolVendor *symbols = GetSymbolVendor ();
955 if (symbols)
Sean Callanan213fdb82011-10-13 01:49:10 +0000956 return symbols->FindTypes(sc, name, namespace_decl, append, max_matches, types);
Greg Clayton3504eee2010-08-03 01:26:16 +0000957 }
958 return 0;
959}
960
Greg Claytonc7bece562013-01-25 18:06:21 +0000961size_t
Greg Clayton84db9102012-03-26 23:03:23 +0000962Module::FindTypesInNamespace (const SymbolContext& sc,
963 const ConstString &type_name,
964 const ClangNamespaceDecl *namespace_decl,
Greg Claytonc7bece562013-01-25 18:06:21 +0000965 size_t max_matches,
Greg Clayton84db9102012-03-26 23:03:23 +0000966 TypeList& type_list)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000967{
Greg Clayton84db9102012-03-26 23:03:23 +0000968 const bool append = true;
969 return FindTypes_Impl(sc, type_name, namespace_decl, append, max_matches, type_list);
Enrico Granata6f3533f2011-07-29 19:53:35 +0000970}
971
Greg Claytonb43165b2012-12-05 21:24:42 +0000972lldb::TypeSP
973Module::FindFirstType (const SymbolContext& sc,
974 const ConstString &name,
975 bool exact_match)
976{
977 TypeList type_list;
Greg Claytonc7bece562013-01-25 18:06:21 +0000978 const size_t num_matches = FindTypes (sc, name, exact_match, 1, type_list);
Greg Claytonb43165b2012-12-05 21:24:42 +0000979 if (num_matches)
980 return type_list.GetTypeAtIndex(0);
981 return TypeSP();
982}
983
984
Greg Claytonc7bece562013-01-25 18:06:21 +0000985size_t
Greg Clayton84db9102012-03-26 23:03:23 +0000986Module::FindTypes (const SymbolContext& sc,
987 const ConstString &name,
988 bool exact_match,
Greg Claytonc7bece562013-01-25 18:06:21 +0000989 size_t max_matches,
Greg Clayton84db9102012-03-26 23:03:23 +0000990 TypeList& types)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000991{
Greg Claytonc7bece562013-01-25 18:06:21 +0000992 size_t num_matches = 0;
Greg Clayton84db9102012-03-26 23:03:23 +0000993 const char *type_name_cstr = name.GetCString();
994 std::string type_scope;
995 std::string type_basename;
996 const bool append = true;
Greg Clayton7bc31332012-10-22 16:19:56 +0000997 TypeClass type_class = eTypeClassAny;
998 if (Type::GetTypeScopeAndBasename (type_name_cstr, type_scope, type_basename, type_class))
Enrico Granata6f3533f2011-07-29 19:53:35 +0000999 {
Greg Clayton84db9102012-03-26 23:03:23 +00001000 // Check if "name" starts with "::" which means the qualified type starts
1001 // from the root namespace and implies and exact match. The typenames we
1002 // get back from clang do not start with "::" so we need to strip this off
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00001003 // in order to get the qualified names to match
Greg Clayton84db9102012-03-26 23:03:23 +00001004
1005 if (type_scope.size() >= 2 && type_scope[0] == ':' && type_scope[1] == ':')
1006 {
1007 type_scope.erase(0,2);
1008 exact_match = true;
1009 }
1010 ConstString type_basename_const_str (type_basename.c_str());
1011 if (FindTypes_Impl(sc, type_basename_const_str, NULL, append, max_matches, types))
1012 {
Greg Clayton7bc31332012-10-22 16:19:56 +00001013 types.RemoveMismatchedTypes (type_scope, type_basename, type_class, exact_match);
Greg Clayton84db9102012-03-26 23:03:23 +00001014 num_matches = types.GetSize();
1015 }
Enrico Granata6f3533f2011-07-29 19:53:35 +00001016 }
1017 else
Greg Clayton84db9102012-03-26 23:03:23 +00001018 {
1019 // The type is not in a namespace/class scope, just search for it by basename
Greg Clayton7bc31332012-10-22 16:19:56 +00001020 if (type_class != eTypeClassAny)
1021 {
1022 // The "type_name_cstr" will have been modified if we have a valid type class
1023 // prefix (like "struct", "class", "union", "typedef" etc).
Arnaud A. de Grandmaison62e5f4d2014-03-22 20:23:26 +00001024 FindTypes_Impl(sc, ConstString(type_name_cstr), NULL, append, max_matches, types);
Greg Clayton7bc31332012-10-22 16:19:56 +00001025 types.RemoveMismatchedTypes (type_class);
1026 num_matches = types.GetSize();
1027 }
1028 else
1029 {
1030 num_matches = FindTypes_Impl(sc, name, NULL, append, max_matches, types);
1031 }
Greg Clayton84db9102012-03-26 23:03:23 +00001032 }
1033
1034 return num_matches;
Enrico Granata6f3533f2011-07-29 19:53:35 +00001035
1036}
1037
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001038SymbolVendor*
Greg Clayton136dff82012-12-14 02:15:00 +00001039Module::GetSymbolVendor (bool can_create, lldb_private::Stream *feedback_strm)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001040{
1041 Mutex::Locker locker (m_mutex);
Greg Claytone83e7312010-09-07 23:40:05 +00001042 if (m_did_load_symbol_vendor == false && can_create)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001043 {
1044 ObjectFile *obj_file = GetObjectFile ();
1045 if (obj_file != NULL)
1046 {
1047 Timer scoped_timer(__PRETTY_FUNCTION__, __PRETTY_FUNCTION__);
Greg Clayton136dff82012-12-14 02:15:00 +00001048 m_symfile_ap.reset(SymbolVendor::FindPlugin(shared_from_this(), feedback_strm));
Greg Claytone83e7312010-09-07 23:40:05 +00001049 m_did_load_symbol_vendor = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001050 }
1051 }
1052 return m_symfile_ap.get();
1053}
1054
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001055void
1056Module::SetFileSpecAndObjectName (const FileSpec &file, const ConstString &object_name)
1057{
1058 // Container objects whose paths do not specify a file directly can call
1059 // this function to correct the file and object names.
1060 m_file = file;
1061 m_mod_time = file.GetModificationTime();
1062 m_object_name = object_name;
1063}
1064
1065const ArchSpec&
1066Module::GetArchitecture () const
1067{
1068 return m_arch;
1069}
1070
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00001071std::string
1072Module::GetSpecificationDescription () const
1073{
1074 std::string spec(GetFileSpec().GetPath());
1075 if (m_object_name)
1076 {
1077 spec += '(';
1078 spec += m_object_name.GetCString();
1079 spec += ')';
1080 }
1081 return spec;
1082}
1083
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001084void
Greg Claytonc982b3d2011-11-28 01:45:00 +00001085Module::GetDescription (Stream *s, lldb::DescriptionLevel level)
Caroline Ticeceb6b132010-10-26 03:11:13 +00001086{
1087 Mutex::Locker locker (m_mutex);
1088
Greg Claytonc982b3d2011-11-28 01:45:00 +00001089 if (level >= eDescriptionLevelFull)
1090 {
1091 if (m_arch.IsValid())
1092 s->Printf("(%s) ", m_arch.GetArchitectureName());
1093 }
Caroline Ticeceb6b132010-10-26 03:11:13 +00001094
Greg Claytonc982b3d2011-11-28 01:45:00 +00001095 if (level == eDescriptionLevelBrief)
1096 {
1097 const char *filename = m_file.GetFilename().GetCString();
1098 if (filename)
1099 s->PutCString (filename);
1100 }
1101 else
1102 {
1103 char path[PATH_MAX];
1104 if (m_file.GetPath(path, sizeof(path)))
1105 s->PutCString(path);
1106 }
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001107
1108 const char *object_name = m_object_name.GetCString();
1109 if (object_name)
1110 s->Printf("(%s)", object_name);
Caroline Ticeceb6b132010-10-26 03:11:13 +00001111}
1112
1113void
Greg Claytonc982b3d2011-11-28 01:45:00 +00001114Module::ReportError (const char *format, ...)
1115{
Greg Claytone38a5ed2012-01-05 03:57:59 +00001116 if (format && format[0])
1117 {
1118 StreamString strm;
1119 strm.PutCString("error: ");
1120 GetDescription(&strm, lldb::eDescriptionLevelBrief);
Greg Clayton8b353342012-01-11 01:59:18 +00001121 strm.PutChar (' ');
Greg Claytone38a5ed2012-01-05 03:57:59 +00001122 va_list args;
1123 va_start (args, format);
1124 strm.PrintfVarArg(format, args);
1125 va_end (args);
1126
1127 const int format_len = strlen(format);
1128 if (format_len > 0)
1129 {
1130 const char last_char = format[format_len-1];
1131 if (last_char != '\n' || last_char != '\r')
1132 strm.EOL();
1133 }
1134 Host::SystemLog (Host::eSystemLogError, "%s", strm.GetString().c_str());
1135
1136 }
1137}
1138
Greg Clayton1d609092012-07-12 22:51:12 +00001139bool
1140Module::FileHasChanged () const
1141{
1142 if (m_file_has_changed == false)
1143 m_file_has_changed = (m_file.GetModificationTime() != m_mod_time);
1144 return m_file_has_changed;
1145}
1146
Greg Claytone38a5ed2012-01-05 03:57:59 +00001147void
1148Module::ReportErrorIfModifyDetected (const char *format, ...)
1149{
Greg Clayton1d609092012-07-12 22:51:12 +00001150 if (m_first_file_changed_log == false)
Greg Claytone38a5ed2012-01-05 03:57:59 +00001151 {
Greg Clayton1d609092012-07-12 22:51:12 +00001152 if (FileHasChanged ())
Greg Claytone38a5ed2012-01-05 03:57:59 +00001153 {
Greg Clayton1d609092012-07-12 22:51:12 +00001154 m_first_file_changed_log = true;
1155 if (format)
Greg Claytone38a5ed2012-01-05 03:57:59 +00001156 {
Greg Clayton1d609092012-07-12 22:51:12 +00001157 StreamString strm;
1158 strm.PutCString("error: the object file ");
1159 GetDescription(&strm, lldb::eDescriptionLevelFull);
1160 strm.PutCString (" has been modified\n");
1161
1162 va_list args;
1163 va_start (args, format);
1164 strm.PrintfVarArg(format, args);
1165 va_end (args);
1166
1167 const int format_len = strlen(format);
1168 if (format_len > 0)
1169 {
1170 const char last_char = format[format_len-1];
1171 if (last_char != '\n' || last_char != '\r')
1172 strm.EOL();
1173 }
1174 strm.PutCString("The debug session should be aborted as the original debug information has been overwritten.\n");
1175 Host::SystemLog (Host::eSystemLogError, "%s", strm.GetString().c_str());
Greg Claytone38a5ed2012-01-05 03:57:59 +00001176 }
Greg Claytone38a5ed2012-01-05 03:57:59 +00001177 }
1178 }
Greg Claytonc982b3d2011-11-28 01:45:00 +00001179}
1180
1181void
1182Module::ReportWarning (const char *format, ...)
1183{
Greg Claytone38a5ed2012-01-05 03:57:59 +00001184 if (format && format[0])
1185 {
1186 StreamString strm;
1187 strm.PutCString("warning: ");
Greg Clayton8b353342012-01-11 01:59:18 +00001188 GetDescription(&strm, lldb::eDescriptionLevelFull);
1189 strm.PutChar (' ');
Greg Claytone38a5ed2012-01-05 03:57:59 +00001190
1191 va_list args;
1192 va_start (args, format);
1193 strm.PrintfVarArg(format, args);
1194 va_end (args);
1195
1196 const int format_len = strlen(format);
1197 if (format_len > 0)
1198 {
1199 const char last_char = format[format_len-1];
1200 if (last_char != '\n' || last_char != '\r')
1201 strm.EOL();
1202 }
1203 Host::SystemLog (Host::eSystemLogWarning, "%s", strm.GetString().c_str());
1204 }
Greg Claytonc982b3d2011-11-28 01:45:00 +00001205}
1206
1207void
1208Module::LogMessage (Log *log, const char *format, ...)
1209{
1210 if (log)
1211 {
1212 StreamString log_message;
Greg Clayton8b353342012-01-11 01:59:18 +00001213 GetDescription(&log_message, lldb::eDescriptionLevelFull);
Greg Claytonc982b3d2011-11-28 01:45:00 +00001214 log_message.PutCString (": ");
1215 va_list args;
1216 va_start (args, format);
1217 log_message.PrintfVarArg (format, args);
1218 va_end (args);
1219 log->PutCString(log_message.GetString().c_str());
1220 }
1221}
1222
Greg Claytond61c0fc2012-04-23 22:55:20 +00001223void
1224Module::LogMessageVerboseBacktrace (Log *log, const char *format, ...)
1225{
1226 if (log)
1227 {
1228 StreamString log_message;
1229 GetDescription(&log_message, lldb::eDescriptionLevelFull);
1230 log_message.PutCString (": ");
1231 va_list args;
1232 va_start (args, format);
1233 log_message.PrintfVarArg (format, args);
1234 va_end (args);
1235 if (log->GetVerbose())
1236 Host::Backtrace (log_message, 1024);
1237 log->PutCString(log_message.GetString().c_str());
1238 }
1239}
1240
Greg Claytonc982b3d2011-11-28 01:45:00 +00001241void
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001242Module::Dump(Stream *s)
1243{
1244 Mutex::Locker locker (m_mutex);
Greg Clayton89411422010-10-08 00:21:05 +00001245 //s->Printf("%.*p: ", (int)sizeof(void*) * 2, this);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001246 s->Indent();
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00001247 s->Printf("Module %s%s%s%s\n",
1248 m_file.GetPath().c_str(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001249 m_object_name ? "(" : "",
1250 m_object_name ? m_object_name.GetCString() : "",
1251 m_object_name ? ")" : "");
1252
1253 s->IndentMore();
Michael Sartaina7499c92013-07-01 19:45:50 +00001254
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001255 ObjectFile *objfile = GetObjectFile ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001256 if (objfile)
1257 objfile->Dump(s);
1258
1259 SymbolVendor *symbols = GetSymbolVendor ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001260 if (symbols)
1261 symbols->Dump(s);
1262
1263 s->IndentLess();
1264}
1265
1266
1267TypeList*
1268Module::GetTypeList ()
1269{
1270 SymbolVendor *symbols = GetSymbolVendor ();
1271 if (symbols)
1272 return &symbols->GetTypeList();
1273 return NULL;
1274}
1275
1276const ConstString &
1277Module::GetObjectName() const
1278{
1279 return m_object_name;
1280}
1281
1282ObjectFile *
1283Module::GetObjectFile()
1284{
1285 Mutex::Locker locker (m_mutex);
Greg Claytone83e7312010-09-07 23:40:05 +00001286 if (m_did_load_objfile == false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001287 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001288 Timer scoped_timer(__PRETTY_FUNCTION__,
1289 "Module::GetObjectFile () module = %s", GetFileSpec().GetFilename().AsCString(""));
Greg Clayton5ce9c562013-02-06 17:22:03 +00001290 DataBufferSP data_sp;
1291 lldb::offset_t data_offset = 0;
Greg Clayton2540a8a2013-07-12 22:07:46 +00001292 const lldb::offset_t file_size = m_file.GetByteSize();
1293 if (file_size > m_object_offset)
Greg Clayton593577a2011-09-21 03:57:31 +00001294 {
Greg Clayton2540a8a2013-07-12 22:07:46 +00001295 m_did_load_objfile = true;
1296 m_objfile_sp = ObjectFile::FindPlugin (shared_from_this(),
1297 &m_file,
1298 m_object_offset,
1299 file_size - m_object_offset,
1300 data_sp,
1301 data_offset);
1302 if (m_objfile_sp)
1303 {
Zachary Turner5e6f4522015-01-22 18:59:05 +00001304 // Once we get the object file, update our module with the object file's
Greg Clayton2540a8a2013-07-12 22:07:46 +00001305 // architecture since it might differ in vendor/os if some parts were
Zachary Turner5e6f4522015-01-22 18:59:05 +00001306 // unknown. But since the matching arch might already be more specific
1307 // than the generic COFF architecture, only merge in those values that
1308 // overwrite unspecified unknown values.
1309 ArchSpec new_arch;
1310 m_objfile_sp->GetArchitecture(new_arch);
1311 m_arch.MergeFrom(new_arch);
Greg Clayton2540a8a2013-07-12 22:07:46 +00001312 }
Todd Fiala0ee56ce2014-09-05 14:48:49 +00001313 else
1314 {
1315 ReportError ("failed to load objfile for %s", GetFileSpec().GetPath().c_str());
1316 }
Greg Clayton593577a2011-09-21 03:57:31 +00001317 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001318 }
Greg Clayton762f7132011-09-18 18:59:15 +00001319 return m_objfile_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001320}
1321
Michael Sartaina7499c92013-07-01 19:45:50 +00001322SectionList *
Greg Clayton3046e662013-07-10 01:23:25 +00001323Module::GetSectionList()
1324{
1325 // Populate m_unified_sections_ap with sections from objfile.
1326 if (m_sections_ap.get() == NULL)
1327 {
1328 ObjectFile *obj_file = GetObjectFile();
1329 if (obj_file)
1330 obj_file->CreateSections(*GetUnifiedSectionList());
1331 }
1332 return m_sections_ap.get();
1333}
1334
Jason Molenda05a09c62014-08-22 02:46:46 +00001335void
1336Module::SectionFileAddressesChanged ()
1337{
1338 ObjectFile *obj_file = GetObjectFile ();
1339 if (obj_file)
1340 obj_file->SectionFileAddressesChanged ();
1341 SymbolVendor* sym_vendor = GetSymbolVendor();
1342 if (sym_vendor)
1343 sym_vendor->SectionFileAddressesChanged ();
1344}
1345
Greg Clayton3046e662013-07-10 01:23:25 +00001346SectionList *
Michael Sartaina7499c92013-07-01 19:45:50 +00001347Module::GetUnifiedSectionList()
1348{
Greg Clayton3046e662013-07-10 01:23:25 +00001349 // Populate m_unified_sections_ap with sections from objfile.
1350 if (m_sections_ap.get() == NULL)
1351 m_sections_ap.reset(new SectionList());
1352 return m_sections_ap.get();
Michael Sartaina7499c92013-07-01 19:45:50 +00001353}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001354
1355const Symbol *
1356Module::FindFirstSymbolWithNameAndType (const ConstString &name, SymbolType symbol_type)
1357{
1358 Timer scoped_timer(__PRETTY_FUNCTION__,
1359 "Module::FindFirstSymbolWithNameAndType (name = %s, type = %i)",
1360 name.AsCString(),
1361 symbol_type);
Michael Sartaina7499c92013-07-01 19:45:50 +00001362 SymbolVendor* sym_vendor = GetSymbolVendor();
1363 if (sym_vendor)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001364 {
Michael Sartaina7499c92013-07-01 19:45:50 +00001365 Symtab *symtab = sym_vendor->GetSymtab();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001366 if (symtab)
Greg Claytonbcf2cfb2010-09-11 03:13:28 +00001367 return symtab->FindFirstSymbolWithNameAndType (name, symbol_type, Symtab::eDebugAny, Symtab::eVisibilityAny);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001368 }
1369 return NULL;
1370}
1371void
1372Module::SymbolIndicesToSymbolContextList (Symtab *symtab, std::vector<uint32_t> &symbol_indexes, SymbolContextList &sc_list)
1373{
1374 // No need to protect this call using m_mutex all other method calls are
1375 // already thread safe.
1376
1377 size_t num_indices = symbol_indexes.size();
1378 if (num_indices > 0)
1379 {
1380 SymbolContext sc;
1381 CalculateSymbolContext (&sc);
1382 for (size_t i = 0; i < num_indices; i++)
1383 {
1384 sc.symbol = symtab->SymbolAtIndex (symbol_indexes[i]);
1385 if (sc.symbol)
1386 sc_list.Append (sc);
1387 }
1388 }
1389}
1390
1391size_t
Greg Claytonc1b2ccf2013-01-08 00:01:36 +00001392Module::FindFunctionSymbols (const ConstString &name,
1393 uint32_t name_type_mask,
1394 SymbolContextList& sc_list)
1395{
1396 Timer scoped_timer(__PRETTY_FUNCTION__,
1397 "Module::FindSymbolsFunctions (name = %s, mask = 0x%8.8x)",
1398 name.AsCString(),
1399 name_type_mask);
Michael Sartaina7499c92013-07-01 19:45:50 +00001400 SymbolVendor* sym_vendor = GetSymbolVendor();
1401 if (sym_vendor)
Greg Claytonc1b2ccf2013-01-08 00:01:36 +00001402 {
Michael Sartaina7499c92013-07-01 19:45:50 +00001403 Symtab *symtab = sym_vendor->GetSymtab();
Greg Claytonc1b2ccf2013-01-08 00:01:36 +00001404 if (symtab)
1405 return symtab->FindFunctionSymbols (name, name_type_mask, sc_list);
1406 }
1407 return 0;
1408}
1409
1410size_t
Sean Callananb96ff332011-10-13 16:49:47 +00001411Module::FindSymbolsWithNameAndType (const ConstString &name, SymbolType symbol_type, SymbolContextList &sc_list)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001412{
1413 // No need to protect this call using m_mutex all other method calls are
1414 // already thread safe.
1415
1416
1417 Timer scoped_timer(__PRETTY_FUNCTION__,
1418 "Module::FindSymbolsWithNameAndType (name = %s, type = %i)",
1419 name.AsCString(),
1420 symbol_type);
1421 const size_t initial_size = sc_list.GetSize();
Michael Sartaina7499c92013-07-01 19:45:50 +00001422 SymbolVendor* sym_vendor = GetSymbolVendor();
1423 if (sym_vendor)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001424 {
Michael Sartaina7499c92013-07-01 19:45:50 +00001425 Symtab *symtab = sym_vendor->GetSymtab();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001426 if (symtab)
1427 {
1428 std::vector<uint32_t> symbol_indexes;
1429 symtab->FindAllSymbolsWithNameAndType (name, symbol_type, symbol_indexes);
1430 SymbolIndicesToSymbolContextList (symtab, symbol_indexes, sc_list);
1431 }
1432 }
1433 return sc_list.GetSize() - initial_size;
1434}
1435
1436size_t
1437Module::FindSymbolsMatchingRegExAndType (const RegularExpression &regex, SymbolType symbol_type, SymbolContextList &sc_list)
1438{
1439 // No need to protect this call using m_mutex all other method calls are
1440 // already thread safe.
1441
1442 Timer scoped_timer(__PRETTY_FUNCTION__,
1443 "Module::FindSymbolsMatchingRegExAndType (regex = %s, type = %i)",
1444 regex.GetText(),
1445 symbol_type);
1446 const size_t initial_size = sc_list.GetSize();
Michael Sartaina7499c92013-07-01 19:45:50 +00001447 SymbolVendor* sym_vendor = GetSymbolVendor();
1448 if (sym_vendor)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001449 {
Michael Sartaina7499c92013-07-01 19:45:50 +00001450 Symtab *symtab = sym_vendor->GetSymtab();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001451 if (symtab)
1452 {
1453 std::vector<uint32_t> symbol_indexes;
Greg Claytonbcf2cfb2010-09-11 03:13:28 +00001454 symtab->FindAllSymbolsMatchingRexExAndType (regex, symbol_type, Symtab::eDebugAny, Symtab::eVisibilityAny, symbol_indexes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001455 SymbolIndicesToSymbolContextList (symtab, symbol_indexes, sc_list);
1456 }
1457 }
1458 return sc_list.GetSize() - initial_size;
1459}
1460
Greg Claytone01e07b2013-04-18 18:10:51 +00001461void
1462Module::SetSymbolFileFileSpec (const FileSpec &file)
1463{
Michael Sartaina7499c92013-07-01 19:45:50 +00001464 // Remove any sections in the unified section list that come from the current symbol vendor.
1465 if (m_symfile_ap)
1466 {
Greg Clayton3046e662013-07-10 01:23:25 +00001467 SectionList *section_list = GetSectionList();
Michael Sartaina7499c92013-07-01 19:45:50 +00001468 SymbolFile *symbol_file = m_symfile_ap->GetSymbolFile();
1469 if (section_list && symbol_file)
1470 {
1471 ObjectFile *obj_file = symbol_file->GetObjectFile();
Greg Clayton540fbbf2013-08-13 16:46:35 +00001472 // Make sure we have an object file and that the symbol vendor's objfile isn't
1473 // the same as the module's objfile before we remove any sections for it...
1474 if (obj_file && obj_file != m_objfile_sp.get())
Michael Sartaina7499c92013-07-01 19:45:50 +00001475 {
1476 size_t num_sections = section_list->GetNumSections (0);
1477 for (size_t idx = num_sections; idx > 0; --idx)
1478 {
1479 lldb::SectionSP section_sp (section_list->GetSectionAtIndex (idx - 1));
1480 if (section_sp->GetObjectFile() == obj_file)
1481 {
Greg Clayton3046e662013-07-10 01:23:25 +00001482 section_list->DeleteSection (idx - 1);
Michael Sartaina7499c92013-07-01 19:45:50 +00001483 }
1484 }
Michael Sartaina7499c92013-07-01 19:45:50 +00001485 }
1486 }
1487 }
1488
Greg Claytone01e07b2013-04-18 18:10:51 +00001489 m_symfile_spec = file;
1490 m_symfile_ap.reset();
1491 m_did_load_symbol_vendor = false;
1492}
1493
Jim Ingham5aee1622010-08-09 23:31:02 +00001494bool
1495Module::IsExecutable ()
1496{
1497 if (GetObjectFile() == NULL)
1498 return false;
1499 else
1500 return GetObjectFile()->IsExecutable();
1501}
1502
Jim Inghamb53cb272011-08-03 01:03:17 +00001503bool
1504Module::IsLoadedInTarget (Target *target)
1505{
1506 ObjectFile *obj_file = GetObjectFile();
1507 if (obj_file)
1508 {
Greg Clayton3046e662013-07-10 01:23:25 +00001509 SectionList *sections = GetSectionList();
Jim Inghamb53cb272011-08-03 01:03:17 +00001510 if (sections != NULL)
1511 {
1512 size_t num_sections = sections->GetSize();
Jim Inghamb53cb272011-08-03 01:03:17 +00001513 for (size_t sect_idx = 0; sect_idx < num_sections; sect_idx++)
1514 {
1515 SectionSP section_sp = sections->GetSectionAtIndex(sect_idx);
1516 if (section_sp->GetLoadBaseAddress(target) != LLDB_INVALID_ADDRESS)
1517 {
1518 return true;
1519 }
1520 }
1521 }
1522 }
1523 return false;
1524}
Enrico Granata17598482012-11-08 02:22:02 +00001525
1526bool
Enrico Granata97303392013-05-21 00:00:30 +00001527Module::LoadScriptingResourceInTarget (Target *target, Error& error, Stream* feedback_stream)
Enrico Granata17598482012-11-08 02:22:02 +00001528{
1529 if (!target)
1530 {
1531 error.SetErrorString("invalid destination Target");
1532 return false;
1533 }
1534
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00001535 LoadScriptFromSymFile should_load = target->TargetProperties::GetLoadScriptFromSymbolFile();
Enrico Granata2ea43cd2013-05-13 17:03:52 +00001536
Greg Clayton994740f2014-08-18 21:08:44 +00001537 if (should_load == eLoadScriptFromSymFileFalse)
1538 return false;
1539
Greg Clayton91c0e742013-01-11 23:44:27 +00001540 Debugger &debugger = target->GetDebugger();
1541 const ScriptLanguage script_language = debugger.GetScriptLanguage();
1542 if (script_language != eScriptLanguageNone)
Enrico Granata17598482012-11-08 02:22:02 +00001543 {
Greg Clayton91c0e742013-01-11 23:44:27 +00001544
1545 PlatformSP platform_sp(target->GetPlatform());
1546
1547 if (!platform_sp)
1548 {
1549 error.SetErrorString("invalid Platform");
1550 return false;
1551 }
Enrico Granata17598482012-11-08 02:22:02 +00001552
Greg Claytonb9d88902013-03-23 00:50:58 +00001553 FileSpecList file_specs = platform_sp->LocateExecutableScriptingResources (target,
Enrico Granatafe7295d2014-08-16 00:32:58 +00001554 *this,
1555 feedback_stream);
Greg Claytonb9d88902013-03-23 00:50:58 +00001556
1557
1558 const uint32_t num_specs = file_specs.GetSize();
1559 if (num_specs)
Enrico Granata17598482012-11-08 02:22:02 +00001560 {
Greg Claytonb9d88902013-03-23 00:50:58 +00001561 ScriptInterpreter *script_interpreter = debugger.GetCommandInterpreter().GetScriptInterpreter();
1562 if (script_interpreter)
Greg Clayton91c0e742013-01-11 23:44:27 +00001563 {
1564 for (uint32_t i=0; i<num_specs; ++i)
1565 {
1566 FileSpec scripting_fspec (file_specs.GetFileSpecAtIndex(i));
1567 if (scripting_fspec && scripting_fspec.Exists())
1568 {
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00001569 if (should_load == eLoadScriptFromSymFileWarn)
Enrico Granata2ea43cd2013-05-13 17:03:52 +00001570 {
Enrico Granata397ddd52013-05-21 20:13:34 +00001571 if (feedback_stream)
Jim Inghamd516deb2013-07-01 18:49:43 +00001572 feedback_stream->Printf("warning: '%s' contains a debug script. To run this script in "
1573 "this debug session:\n\n command script import \"%s\"\n\n"
1574 "To run all discovered debug scripts in this session:\n\n"
1575 " settings set target.load-script-from-symbol-file true\n",
1576 GetFileSpec().GetFileNameStrippingExtension().GetCString(),
1577 scripting_fspec.GetPath().c_str());
Enrico Granata2ea43cd2013-05-13 17:03:52 +00001578 return false;
1579 }
Greg Clayton91c0e742013-01-11 23:44:27 +00001580 StreamString scripting_stream;
1581 scripting_fspec.Dump(&scripting_stream);
Enrico Granatae0c70f12013-05-31 01:03:09 +00001582 const bool can_reload = true;
Greg Clayton91c0e742013-01-11 23:44:27 +00001583 const bool init_lldb_globals = false;
Jim Inghamd516deb2013-07-01 18:49:43 +00001584 bool did_load = script_interpreter->LoadScriptingModule(scripting_stream.GetData(),
1585 can_reload,
1586 init_lldb_globals,
1587 error);
Greg Clayton91c0e742013-01-11 23:44:27 +00001588 if (!did_load)
1589 return false;
1590 }
1591 }
1592 }
Greg Claytonb9d88902013-03-23 00:50:58 +00001593 else
1594 {
1595 error.SetErrorString("invalid ScriptInterpreter");
1596 return false;
1597 }
Enrico Granata17598482012-11-08 02:22:02 +00001598 }
1599 }
1600 return true;
1601}
1602
1603bool
Jim Ingham5aee1622010-08-09 23:31:02 +00001604Module::SetArchitecture (const ArchSpec &new_arch)
1605{
Greg Clayton64195a22011-02-23 00:35:02 +00001606 if (!m_arch.IsValid())
Jim Ingham5aee1622010-08-09 23:31:02 +00001607 {
1608 m_arch = new_arch;
1609 return true;
Greg Clayton64195a22011-02-23 00:35:02 +00001610 }
Sean Callananbf4b7be2012-12-13 22:07:14 +00001611 return m_arch.IsExactMatch(new_arch);
Jim Ingham5aee1622010-08-09 23:31:02 +00001612}
1613
Greg Claytonc9660542012-02-05 02:38:54 +00001614bool
Greg Clayton751caf62014-02-07 22:54:47 +00001615Module::SetLoadAddress (Target &target, lldb::addr_t value, bool value_is_offset, bool &changed)
Greg Claytonc9660542012-02-05 02:38:54 +00001616{
Steve Pucci9e02dac2014-02-06 19:02:19 +00001617 ObjectFile *object_file = GetObjectFile();
1618 if (object_file)
Greg Claytonc9660542012-02-05 02:38:54 +00001619 {
Greg Clayton751caf62014-02-07 22:54:47 +00001620 changed = object_file->SetLoadAddress(target, value, value_is_offset);
Greg Clayton7524e092014-02-06 20:10:16 +00001621 return true;
1622 }
1623 else
1624 {
1625 changed = false;
Greg Claytonc9660542012-02-05 02:38:54 +00001626 }
Steve Pucci9e02dac2014-02-06 19:02:19 +00001627 return false;
Greg Claytonc9660542012-02-05 02:38:54 +00001628}
1629
Greg Claytonb9a01b32012-02-26 05:51:37 +00001630
1631bool
1632Module::MatchesModuleSpec (const ModuleSpec &module_ref)
1633{
1634 const UUID &uuid = module_ref.GetUUID();
1635
1636 if (uuid.IsValid())
1637 {
1638 // If the UUID matches, then nothing more needs to match...
1639 if (uuid == GetUUID())
1640 return true;
1641 else
1642 return false;
1643 }
1644
1645 const FileSpec &file_spec = module_ref.GetFileSpec();
1646 if (file_spec)
1647 {
Sean Callananddd7a2a2013-10-03 22:27:29 +00001648 if (!FileSpec::Equal (file_spec, m_file, (bool)file_spec.GetDirectory()))
Greg Claytonb9a01b32012-02-26 05:51:37 +00001649 return false;
1650 }
1651
1652 const FileSpec &platform_file_spec = module_ref.GetPlatformFileSpec();
1653 if (platform_file_spec)
1654 {
Sean Callananddd7a2a2013-10-03 22:27:29 +00001655 if (!FileSpec::Equal (platform_file_spec, GetPlatformFileSpec (), (bool)platform_file_spec.GetDirectory()))
Greg Claytonb9a01b32012-02-26 05:51:37 +00001656 return false;
1657 }
1658
1659 const ArchSpec &arch = module_ref.GetArchitecture();
1660 if (arch.IsValid())
1661 {
Sean Callananbf4b7be2012-12-13 22:07:14 +00001662 if (!m_arch.IsCompatibleMatch(arch))
Greg Claytonb9a01b32012-02-26 05:51:37 +00001663 return false;
1664 }
1665
1666 const ConstString &object_name = module_ref.GetObjectName();
1667 if (object_name)
1668 {
1669 if (object_name != GetObjectName())
1670 return false;
1671 }
1672 return true;
1673}
1674
Greg Claytond804d282012-03-15 21:01:31 +00001675bool
1676Module::FindSourceFile (const FileSpec &orig_spec, FileSpec &new_spec) const
1677{
1678 Mutex::Locker locker (m_mutex);
1679 return m_source_mappings.FindFile (orig_spec, new_spec);
1680}
1681
Greg Claytonf9be6932012-03-19 22:22:41 +00001682bool
1683Module::RemapSourceFile (const char *path, std::string &new_path) const
1684{
1685 Mutex::Locker locker (m_mutex);
1686 return m_source_mappings.RemapPath(path, new_path);
1687}
1688
Enrico Granata3467d802012-09-04 18:47:54 +00001689uint32_t
1690Module::GetVersion (uint32_t *versions, uint32_t num_versions)
1691{
1692 ObjectFile *obj_file = GetObjectFile();
1693 if (obj_file)
1694 return obj_file->GetVersion (versions, num_versions);
1695
1696 if (versions && num_versions)
1697 {
1698 for (uint32_t i=0; i<num_versions; ++i)
Enrico Granataafcbdb12014-03-25 20:53:33 +00001699 versions[i] = LLDB_INVALID_MODULE_VERSION;
Enrico Granata3467d802012-09-04 18:47:54 +00001700 }
1701 return 0;
1702}
Greg Clayton43fe2172013-04-03 02:00:15 +00001703
1704void
1705Module::PrepareForFunctionNameLookup (const ConstString &name,
1706 uint32_t name_type_mask,
1707 ConstString &lookup_name,
1708 uint32_t &lookup_name_type_mask,
1709 bool &match_name_after_lookup)
1710{
1711 const char *name_cstr = name.GetCString();
1712 lookup_name_type_mask = eFunctionNameTypeNone;
1713 match_name_after_lookup = false;
Jim Inghamfa39bb42014-10-25 00:33:55 +00001714
1715 llvm::StringRef basename;
1716 llvm::StringRef context;
Greg Clayton43fe2172013-04-03 02:00:15 +00001717
1718 if (name_type_mask & eFunctionNameTypeAuto)
1719 {
1720 if (CPPLanguageRuntime::IsCPPMangledName (name_cstr))
1721 lookup_name_type_mask = eFunctionNameTypeFull;
1722 else if (ObjCLanguageRuntime::IsPossibleObjCMethodName (name_cstr))
1723 lookup_name_type_mask = eFunctionNameTypeFull;
1724 else
1725 {
1726 if (ObjCLanguageRuntime::IsPossibleObjCSelector(name_cstr))
1727 lookup_name_type_mask |= eFunctionNameTypeSelector;
1728
Greg Clayton6ecb2322013-05-18 00:11:21 +00001729 CPPLanguageRuntime::MethodName cpp_method (name);
Jim Inghamfa39bb42014-10-25 00:33:55 +00001730 basename = cpp_method.GetBasename();
Greg Clayton6ecb2322013-05-18 00:11:21 +00001731 if (basename.empty())
1732 {
Jim Inghamfa39bb42014-10-25 00:33:55 +00001733 if (CPPLanguageRuntime::ExtractContextAndIdentifier (name_cstr, context, basename))
Greg Clayton6ecb2322013-05-18 00:11:21 +00001734 lookup_name_type_mask |= (eFunctionNameTypeMethod | eFunctionNameTypeBase);
Greg Claytonc3795402014-10-22 21:47:13 +00001735 else
Greg Clayton65b0e762015-01-28 01:08:39 +00001736 lookup_name_type_mask |= eFunctionNameTypeFull;
Greg Clayton6ecb2322013-05-18 00:11:21 +00001737 }
1738 else
1739 {
Greg Clayton43fe2172013-04-03 02:00:15 +00001740 lookup_name_type_mask |= (eFunctionNameTypeMethod | eFunctionNameTypeBase);
Greg Clayton6ecb2322013-05-18 00:11:21 +00001741 }
Greg Clayton43fe2172013-04-03 02:00:15 +00001742 }
1743 }
1744 else
1745 {
1746 lookup_name_type_mask = name_type_mask;
1747 if (lookup_name_type_mask & eFunctionNameTypeMethod || name_type_mask & eFunctionNameTypeBase)
1748 {
1749 // If they've asked for a CPP method or function name and it can't be that, we don't
1750 // even need to search for CPP methods or names.
Greg Clayton6ecb2322013-05-18 00:11:21 +00001751 CPPLanguageRuntime::MethodName cpp_method (name);
1752 if (cpp_method.IsValid())
Greg Clayton43fe2172013-04-03 02:00:15 +00001753 {
Jim Inghamfa39bb42014-10-25 00:33:55 +00001754 basename = cpp_method.GetBasename();
Greg Clayton6ecb2322013-05-18 00:11:21 +00001755
1756 if (!cpp_method.GetQualifiers().empty())
1757 {
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00001758 // There is a "const" or other qualifier following the end of the function parens,
Greg Clayton6ecb2322013-05-18 00:11:21 +00001759 // this can't be a eFunctionNameTypeBase
1760 lookup_name_type_mask &= ~(eFunctionNameTypeBase);
1761 if (lookup_name_type_mask == eFunctionNameTypeNone)
1762 return;
1763 }
1764 }
1765 else
1766 {
Jim Inghamfa39bb42014-10-25 00:33:55 +00001767 // If the CPP method parser didn't manage to chop this up, try to fill in the base name if we can.
1768 // If a::b::c is passed in, we need to just look up "c", and then we'll filter the result later.
1769 CPPLanguageRuntime::ExtractContextAndIdentifier (name_cstr, context, basename);
Greg Clayton43fe2172013-04-03 02:00:15 +00001770 }
1771 }
1772
1773 if (lookup_name_type_mask & eFunctionNameTypeSelector)
1774 {
1775 if (!ObjCLanguageRuntime::IsPossibleObjCSelector(name_cstr))
1776 {
1777 lookup_name_type_mask &= ~(eFunctionNameTypeSelector);
1778 if (lookup_name_type_mask == eFunctionNameTypeNone)
1779 return;
1780 }
1781 }
1782 }
1783
Jim Inghamfa39bb42014-10-25 00:33:55 +00001784 if (!basename.empty())
Greg Clayton43fe2172013-04-03 02:00:15 +00001785 {
1786 // The name supplied was a partial C++ path like "a::count". In this case we want to do a
1787 // lookup on the basename "count" and then make sure any matching results contain "a::count"
1788 // so that it would match "b::a::count" and "a::count". This is why we set "match_name_after_lookup"
1789 // to true
Jim Inghamfa39bb42014-10-25 00:33:55 +00001790 lookup_name.SetString(basename);
Greg Clayton43fe2172013-04-03 02:00:15 +00001791 match_name_after_lookup = true;
1792 }
1793 else
1794 {
1795 // The name is already correct, just use the exact name as supplied, and we won't need
1796 // to check if any matches contain "name"
1797 lookup_name = name;
1798 match_name_after_lookup = false;
1799 }
Richard Mittonf86248d2013-09-12 02:20:34 +00001800}
Greg Clayton23f8c952014-03-24 23:10:19 +00001801
1802ModuleSP
1803Module::CreateJITModule (const lldb::ObjectFileJITDelegateSP &delegate_sp)
1804{
1805 if (delegate_sp)
1806 {
1807 // Must create a module and place it into a shared pointer before
1808 // we can create an object file since it has a std::weak_ptr back
1809 // to the module, so we need to control the creation carefully in
1810 // this static function
1811 ModuleSP module_sp(new Module());
1812 module_sp->m_objfile_sp.reset (new ObjectFileJIT (module_sp, delegate_sp));
1813 if (module_sp->m_objfile_sp)
1814 {
1815 // Once we get the object file, update our module with the object file's
1816 // architecture since it might differ in vendor/os if some parts were
1817 // unknown.
1818 module_sp->m_objfile_sp->GetArchitecture (module_sp->m_arch);
1819 }
1820 return module_sp;
1821 }
1822 return ModuleSP();
1823}
1824
Greg Clayton08928f32015-02-05 02:01:34 +00001825bool
1826Module::GetIsDynamicLinkEditor()
1827{
1828 ObjectFile * obj_file = GetObjectFile ();
1829
1830 if (obj_file)
1831 return obj_file->GetIsDynamicLinkEditor();
1832
1833 return false;
1834}