1 //===-- ModuleSpec.h --------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_ModuleSpec_h_
11 #define liblldb_ModuleSpec_h_
13 #include "lldb/Core/ArchSpec.h"
14 #include "lldb/Core/Stream.h"
15 #include "lldb/Core/UUID.h"
16 #include "lldb/Host/FileSpec.h"
17 #include "lldb/Target/PathMappingList.h"
19 namespace lldb_private {
37 ModuleSpec (const FileSpec &file_spec) :
50 ModuleSpec (const FileSpec &file_spec, const ArchSpec &arch) :
63 ModuleSpec (const ModuleSpec &rhs) :
65 m_platform_file (rhs.m_platform_file),
66 m_symbol_file (rhs.m_symbol_file),
69 m_object_name (rhs.m_object_name),
70 m_object_offset (rhs.m_object_offset),
71 m_object_mod_time (rhs.m_object_mod_time),
72 m_source_mappings (rhs.m_source_mappings)
77 operator = (const ModuleSpec &rhs)
82 m_platform_file = rhs.m_platform_file;
83 m_symbol_file = rhs.m_symbol_file;
86 m_object_name = rhs.m_object_name;
87 m_object_offset = rhs.m_object_offset;
88 m_object_mod_time = rhs.m_object_mod_time;
89 m_source_mappings = rhs.m_source_mappings;
103 GetFileSpecPtr () const
122 GetPlatformFileSpecPtr ()
125 return &m_platform_file;
130 GetPlatformFileSpecPtr () const
133 return &m_platform_file;
138 GetPlatformFileSpec ()
140 return m_platform_file;
144 GetPlatformFileSpec () const
146 return m_platform_file;
150 GetSymbolFileSpecPtr ()
153 return &m_symbol_file;
158 GetSymbolFileSpecPtr () const
161 return &m_symbol_file;
168 return m_symbol_file;
172 GetSymbolFileSpec () const
174 return m_symbol_file;
179 GetArchitecturePtr ()
181 if (m_arch.IsValid())
187 GetArchitecturePtr () const
189 if (m_arch.IsValid())
201 GetArchitecture () const
209 if (m_uuid.IsValid())
217 if (m_uuid.IsValid())
237 return m_object_name;
241 GetObjectName () const
243 return m_object_name;
247 GetObjectOffset () const
249 return m_object_offset;
253 SetObjectOffset (uint64_t object_offset)
255 m_object_offset = object_offset;
259 GetObjectModificationTime ()
261 return m_object_mod_time;
265 GetObjectModificationTime () const
267 return m_object_mod_time;
271 GetSourceMappingList () const
273 return m_source_mappings;
280 m_platform_file.Clear();
281 m_symbol_file.Clear();
284 m_object_name.Clear();
286 m_source_mappings.Clear(false);
287 m_object_mod_time.Clear();
291 operator bool () const
299 if (m_arch.IsValid())
301 if (m_uuid.IsValid())
305 if (m_object_mod_time.IsValid())
313 bool dumped_something = false;
316 strm.PutCString("file = '");
318 strm.PutCString("'");
319 dumped_something = true;
323 if (dumped_something)
324 strm.PutCString(", ");
325 strm.PutCString("platform_file = '");
326 strm << m_platform_file;
327 strm.PutCString("'");
328 dumped_something = true;
332 if (dumped_something)
333 strm.PutCString(", ");
334 strm.PutCString("symbol_file = '");
335 strm << m_symbol_file;
336 strm.PutCString("'");
337 dumped_something = true;
339 if (m_arch.IsValid())
341 if (dumped_something)
342 strm.PutCString(", ");
343 strm.Printf("arch = %s", m_arch.GetTriple().str().c_str());
344 dumped_something = true;
346 if (m_uuid.IsValid())
348 if (dumped_something)
349 strm.PutCString(", ");
350 strm.PutCString("uuid = ");
352 dumped_something = true;
356 if (dumped_something)
357 strm.PutCString(", ");
358 strm.Printf("object_name = %s", m_object_name.GetCString());
359 dumped_something = true;
361 if (m_object_offset > 0)
363 if (dumped_something)
364 strm.PutCString(", ");
365 strm.Printf("object_offset = 0x%" PRIx64, m_object_offset);
366 dumped_something = true;
368 if (m_object_mod_time.IsValid())
370 if (dumped_something)
371 strm.PutCString(", ");
372 strm.Printf("object_mod_time = 0x%" PRIx64, m_object_mod_time.GetAsSecondsSinceJan1_1970());
373 dumped_something = true;
378 Matches (const ModuleSpec &match_module_spec, bool exact_arch_match) const
380 if (match_module_spec.GetUUIDPtr() && match_module_spec.GetUUID() != GetUUID())
382 if (match_module_spec.GetObjectName() && match_module_spec.GetObjectName() != GetObjectName())
384 if (match_module_spec.GetFileSpecPtr())
386 const FileSpec &fspec = match_module_spec.GetFileSpec();
387 if (!FileSpec::Equal(fspec, GetFileSpec(), fspec.GetDirectory().IsEmpty() == false))
390 if (match_module_spec.GetPlatformFileSpecPtr())
392 const FileSpec &fspec = match_module_spec.GetPlatformFileSpec();
393 if (!FileSpec::Equal(fspec, GetPlatformFileSpec(), fspec.GetDirectory().IsEmpty() == false))
397 if (match_module_spec.GetSymbolFileSpecPtr())
399 const FileSpec &fspec = match_module_spec.GetSymbolFileSpec();
400 if (!FileSpec::Equal(fspec, GetSymbolFileSpec(), fspec.GetDirectory().IsEmpty() == false))
404 if (match_module_spec.GetArchitecturePtr())
406 if (exact_arch_match)
408 if (!GetArchitecture().IsExactMatch(match_module_spec.GetArchitecture()))
413 if (!GetArchitecture().IsCompatibleMatch(match_module_spec.GetArchitecture()))
422 FileSpec m_platform_file;
423 FileSpec m_symbol_file;
426 ConstString m_object_name;
427 uint64_t m_object_offset;
428 TimeValue m_object_mod_time;
429 mutable PathMappingList m_source_mappings;
437 m_mutex(Mutex::eMutexTypeRecursive)
441 ModuleSpecList (const ModuleSpecList &rhs) :
443 m_mutex(Mutex::eMutexTypeRecursive)
445 Mutex::Locker lhs_locker(m_mutex);
446 Mutex::Locker rhs_locker(rhs.m_mutex);
447 m_specs = rhs.m_specs;
455 operator = (const ModuleSpecList &rhs)
459 Mutex::Locker lhs_locker(m_mutex);
460 Mutex::Locker rhs_locker(rhs.m_mutex);
461 m_specs = rhs.m_specs;
469 Mutex::Locker locker(m_mutex);
470 return m_specs.size();
476 Mutex::Locker locker(m_mutex);
481 Append (const ModuleSpec &spec)
483 Mutex::Locker locker(m_mutex);
484 m_specs.push_back (spec);
488 Append (const ModuleSpecList &rhs)
490 Mutex::Locker lhs_locker(m_mutex);
491 Mutex::Locker rhs_locker(rhs.m_mutex);
492 m_specs.insert(m_specs.end(), rhs.m_specs.begin(), rhs.m_specs.end());
495 // The index "i" must be valid and this can't be used in
496 // multi-threaded code as no mutex lock is taken.
498 GetModuleSpecRefAtIndex (size_t i)
503 GetModuleSpecAtIndex (size_t i, ModuleSpec &module_spec) const
505 Mutex::Locker locker(m_mutex);
506 if (i < m_specs.size())
508 module_spec = m_specs[i];
517 FindMatchingModuleSpec (const ModuleSpec &module_spec, ModuleSpec &match_module_spec) const
519 Mutex::Locker locker(m_mutex);
520 bool exact_arch_match = true;
521 for (auto spec: m_specs)
523 if (spec.Matches(module_spec, exact_arch_match))
525 match_module_spec = spec;
530 // If there was an architecture, retry with a compatible arch
531 if (module_spec.GetArchitecturePtr())
533 exact_arch_match = false;
534 for (auto spec: m_specs)
536 if (spec.Matches(module_spec, exact_arch_match))
538 match_module_spec = spec;
543 match_module_spec.Clear();
548 FindMatchingModuleSpecs (const ModuleSpec &module_spec, ModuleSpecList &matching_list) const
550 Mutex::Locker locker(m_mutex);
551 bool exact_arch_match = true;
552 const size_t initial_match_count = matching_list.GetSize();
553 for (auto spec: m_specs)
555 if (spec.Matches(module_spec, exact_arch_match))
556 matching_list.Append (spec);
559 // If there was an architecture, retry with a compatible arch if no matches were found
560 if (module_spec.GetArchitecturePtr() && (initial_match_count == matching_list.GetSize()))
562 exact_arch_match = false;
563 for (auto spec: m_specs)
565 if (spec.Matches(module_spec, exact_arch_match))
566 matching_list.Append (spec);
569 return matching_list.GetSize() - initial_match_count;
575 Mutex::Locker locker(m_mutex);
577 for (auto spec: m_specs)
579 strm.Printf("[%u] ", idx);
587 typedef std::vector<ModuleSpec> collection; ///< The module collection type.
588 collection m_specs; ///< The collection of modules.
589 mutable Mutex m_mutex;
592 } // namespace lldb_private
594 #endif // liblldb_ModuleSpec_h_