Added the ability to get a ObjectFile versions from the ObjectFile
subclasses if the object files support version numbering. Exposed
this through SBModule for upcoming data formatter version checking stuff.



git-svn-id: https://llvm.org/svn/llvm-project/lldb/trunk@151190 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/API/SBModule.cpp b/source/API/SBModule.cpp
index 09f354e..77a7af2 100644
--- a/source/API/SBModule.cpp
+++ b/source/API/SBModule.cpp
@@ -86,13 +86,14 @@
     LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
 
     SBFileSpec file_spec;
-    if (m_opaque_sp)
-        file_spec.SetFileSpec(m_opaque_sp->GetFileSpec());
+    ModuleSP module_sp (GetSP ());
+    if (module_sp)
+        file_spec.SetFileSpec(module_sp->GetFileSpec());
 
     if (log)
     {
         log->Printf ("SBModule(%p)::GetFileSpec () => SBFileSpec(%p)", 
-        m_opaque_sp.get(), file_spec.get());
+        module_sp.get(), file_spec.get());
     }
 
     return file_spec;
@@ -104,13 +105,14 @@
     LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
     
     SBFileSpec file_spec;
-    if (m_opaque_sp)
-        file_spec.SetFileSpec(m_opaque_sp->GetPlatformFileSpec());
+    ModuleSP module_sp (GetSP ());
+    if (module_sp)
+        file_spec.SetFileSpec(module_sp->GetPlatformFileSpec());
     
     if (log)
     {
         log->Printf ("SBModule(%p)::GetPlatformFileSpec () => SBFileSpec(%p)", 
-                     m_opaque_sp.get(), file_spec.get());
+                     module_sp.get(), file_spec.get());
     }
     
     return file_spec;
@@ -123,16 +125,17 @@
     bool result = false;
     LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
     
-    if (m_opaque_sp)
+    ModuleSP module_sp (GetSP ());
+    if (module_sp)
     {
-        m_opaque_sp->SetPlatformFileSpec(*platform_file);
+        module_sp->SetPlatformFileSpec(*platform_file);
         result = true;
     }
     
     if (log)
     {
         log->Printf ("SBModule(%p)::SetPlatformFileSpec (SBFileSpec(%p (%s%s%s)) => %i", 
-                     m_opaque_sp.get(), 
+                     module_sp.get(), 
                      platform_file.get(),
                      platform_file->GetDirectory().GetCString(),
                      platform_file->GetDirectory() ? "/" : "",
@@ -150,19 +153,20 @@
     LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
 
     const uint8_t *uuid_bytes = NULL;
-    if (m_opaque_sp)
-        uuid_bytes = (const uint8_t *)m_opaque_sp->GetUUID().GetBytes();
+    ModuleSP module_sp (GetSP ());
+    if (module_sp)
+        uuid_bytes = (const uint8_t *)module_sp->GetUUID().GetBytes();
 
     if (log)
     {
         if (uuid_bytes)
         {
             StreamString s;
-            m_opaque_sp->GetUUID().Dump (&s);
-            log->Printf ("SBModule(%p)::GetUUIDBytes () => %s", m_opaque_sp.get(), s.GetData());
+            module_sp->GetUUID().Dump (&s);
+            log->Printf ("SBModule(%p)::GetUUIDBytes () => %s", module_sp.get(), s.GetData());
         }
         else
-            log->Printf ("SBModule(%p)::GetUUIDBytes () => NULL", m_opaque_sp.get());
+            log->Printf ("SBModule(%p)::GetUUIDBytes () => NULL", module_sp.get());
     }
     return uuid_bytes;
 }
@@ -175,19 +179,20 @@
 
     static char uuid_string[80];
     const char * uuid_c_string = NULL;
-    if (m_opaque_sp)
-        uuid_c_string = (const char *)m_opaque_sp->GetUUID().GetAsCString(uuid_string, sizeof(uuid_string));
+    ModuleSP module_sp (GetSP ());
+    if (module_sp)
+        uuid_c_string = (const char *)module_sp->GetUUID().GetAsCString(uuid_string, sizeof(uuid_string));
 
     if (log)
     {
         if (uuid_c_string)
         {
             StreamString s;
-            m_opaque_sp->GetUUID().Dump (&s);
-            log->Printf ("SBModule(%p)::GetUUIDString () => %s", m_opaque_sp.get(), s.GetData());
+            module_sp->GetUUID().Dump (&s);
+            log->Printf ("SBModule(%p)::GetUUIDString () => %s", module_sp.get(), s.GetData());
         }
         else
-            log->Printf ("SBModule(%p)::GetUUIDString () => NULL", m_opaque_sp.get());
+            log->Printf ("SBModule(%p)::GetUUIDString () => NULL", module_sp.get());
     }
     return uuid_c_string;
 }
@@ -225,10 +230,11 @@
 SBModule::ResolveFileAddress (lldb::addr_t vm_addr)
 {
     lldb::SBAddress sb_addr;
-    if (m_opaque_sp)
+    ModuleSP module_sp (GetSP ());
+    if (module_sp)
     {
         Address addr;
-        if (m_opaque_sp->ResolveFileAddress (vm_addr, addr))
+        if (module_sp->ResolveFileAddress (vm_addr, addr))
             sb_addr.ref() = addr;
     }
     return sb_addr;
@@ -238,8 +244,9 @@
 SBModule::ResolveSymbolContextForAddress (const SBAddress& addr, uint32_t resolve_scope)
 {
     SBSymbolContext sb_sc;
-    if (m_opaque_sp && addr.IsValid())
-        m_opaque_sp->ResolveSymbolContextForAddress (addr.ref(), resolve_scope, *sb_sc);
+    ModuleSP module_sp (GetSP ());
+    if (module_sp && addr.IsValid())
+        module_sp->ResolveSymbolContextForAddress (addr.ref(), resolve_scope, *sb_sc);
     return sb_sc;
 }
 
@@ -248,9 +255,10 @@
 {
     Stream &strm = description.ref();
 
-    if (m_opaque_sp)
+    ModuleSP module_sp (GetSP ());
+    if (module_sp)
     {
-        m_opaque_sp->GetDescription (&strm);
+        module_sp->GetDescription (&strm);
     }
     else
         strm.PutCString ("No value");
@@ -261,9 +269,10 @@
 size_t
 SBModule::GetNumSymbols ()
 {
-    if (m_opaque_sp)
+    ModuleSP module_sp (GetSP ());
+    if (module_sp)
     {
-        ObjectFile *obj_file = m_opaque_sp->GetObjectFile();
+        ObjectFile *obj_file = module_sp->GetObjectFile();
         if (obj_file)
         {
             Symtab *symtab = obj_file->GetSymtab();
@@ -278,9 +287,10 @@
 SBModule::GetSymbolAtIndex (size_t idx)
 {
     SBSymbol sb_symbol;
-    if (m_opaque_sp)
+    ModuleSP module_sp (GetSP ());
+    if (module_sp)
     {
-        ObjectFile *obj_file = m_opaque_sp->GetObjectFile();
+        ObjectFile *obj_file = module_sp->GetObjectFile();
         if (obj_file)
         {
             Symtab *symtab = obj_file->GetSymtab();
@@ -294,9 +304,10 @@
 size_t
 SBModule::GetNumSections ()
 {
-    if (m_opaque_sp)
+    ModuleSP module_sp (GetSP ());
+    if (module_sp)
     {
-        ObjectFile *obj_file = m_opaque_sp->GetObjectFile();
+        ObjectFile *obj_file = module_sp->GetObjectFile();
         if (obj_file)
         {
             SectionList *section_list = obj_file->GetSectionList ();
@@ -311,9 +322,10 @@
 SBModule::GetSectionAtIndex (size_t idx)
 {
     SBSection sb_section;
-    if (m_opaque_sp)
+    ModuleSP module_sp (GetSP ());
+    if (module_sp)
     {
-        ObjectFile *obj_file = m_opaque_sp->GetObjectFile();
+        ObjectFile *obj_file = module_sp->GetObjectFile();
         if (obj_file)
         {
             SectionList *section_list = obj_file->GetSectionList ();
@@ -330,18 +342,19 @@
                          uint32_t name_type_mask)
 {
     lldb::SBSymbolContextList sb_sc_list;
-    if (name && m_opaque_sp)
+    ModuleSP module_sp (GetSP ());
+    if (name && module_sp)
     {
         const bool append = true;
         const bool symbols_ok = true;
         const bool inlines_ok = true;
-        m_opaque_sp->FindFunctions (ConstString(name),
-                                    NULL,
-                                    name_type_mask, 
-                                    symbols_ok,
-                                    inlines_ok,
-                                    append, 
-                                    *sb_sc_list);
+        module_sp->FindFunctions (ConstString(name),
+                                  NULL,
+                                  name_type_mask, 
+                                  symbols_ok,
+                                  inlines_ok,
+                                  append, 
+                                  *sb_sc_list);
     }
     return sb_sc_list;
 }
@@ -351,14 +364,15 @@
 SBModule::FindGlobalVariables (SBTarget &target, const char *name, uint32_t max_matches)
 {
     SBValueList sb_value_list;
-    if (name && m_opaque_sp)
+    ModuleSP module_sp (GetSP ());
+    if (name && module_sp)
     {
         VariableList variable_list;
-        const uint32_t match_count = m_opaque_sp->FindGlobalVariables (ConstString (name),
-                                                                       NULL,
-                                                                       false, 
-                                                                       max_matches,
-                                                                       variable_list);
+        const uint32_t match_count = module_sp->FindGlobalVariables (ConstString (name),
+                                                                     NULL,
+                                                                     false, 
+                                                                     max_matches,
+                                                                     variable_list);
 
         if (match_count > 0)
         {
@@ -381,19 +395,20 @@
 SBModule::FindFirstType (const char *name_cstr)
 {
     SBType sb_type;
-    if (name_cstr && IsValid())
+    ModuleSP module_sp (GetSP ());
+    if (name_cstr && module_sp)
     {
         SymbolContext sc;
         TypeList type_list;
         uint32_t num_matches = 0;
         ConstString name(name_cstr);
 
-        num_matches = m_opaque_sp->FindTypes(sc,
-                                             name,
-                                             NULL,
-                                             false,
-                                             1,
-                                             type_list);
+        num_matches = module_sp->FindTypes (sc,
+                                            name,
+                                            NULL,
+                                            false,
+                                            1,
+                                            type_list);
         
         if (num_matches)
             sb_type = lldb::SBType(type_list.GetTypeAtIndex(0));
@@ -407,19 +422,20 @@
     
     SBTypeList retval;
     
-    if (type && IsValid())
+    ModuleSP module_sp (GetSP ());
+    if (type && module_sp)
     {
         SymbolContext sc;
         TypeList type_list;
         uint32_t num_matches = 0;
         ConstString name(type);
         
-        num_matches = m_opaque_sp->FindTypes(sc,
-                                             name,
-                                             NULL,
-                                             false,
-                                             UINT32_MAX,
-                                             type_list);
+        num_matches = module_sp->FindTypes (sc,
+                                            name,
+                                            NULL,
+                                            false,
+                                            UINT32_MAX,
+                                            type_list);
             
         for (size_t idx = 0; idx < num_matches; idx++)
         {
@@ -438,9 +454,10 @@
 {
     SBSection sb_section;
     
-    if (sect_name && IsValid())
+    ModuleSP module_sp (GetSP ());
+    if (sect_name && module_sp)
     {
-        ObjectFile *objfile = m_opaque_sp->GetObjectFile();
+        ObjectFile *objfile = module_sp->GetObjectFile();
         if (objfile)
         {
             SectionList *section_list = objfile->GetSectionList();
@@ -461,17 +478,19 @@
 lldb::ByteOrder
 SBModule::GetByteOrder ()
 {
-    if (m_opaque_sp)
-        return m_opaque_sp->GetArchitecture().GetByteOrder();
+    ModuleSP module_sp (GetSP ());
+    if (module_sp)
+        return module_sp->GetArchitecture().GetByteOrder();
     return eByteOrderInvalid;
 }
 
 const char *
 SBModule::GetTriple ()
 {
-    if (m_opaque_sp)
+    ModuleSP module_sp (GetSP ());
+    if (module_sp)
     {
-        std::string triple (m_opaque_sp->GetArchitecture().GetTriple().str());
+        std::string triple (module_sp->GetArchitecture().GetTriple().str());
         // Unique the string so we don't run into ownership issues since
         // the const strings put the string into the string pool once and
         // the strings never comes out
@@ -484,8 +503,29 @@
 uint32_t
 SBModule::GetAddressByteSize()
 {
-    if (m_opaque_sp)
-        return m_opaque_sp->GetArchitecture().GetAddressByteSize();
+    ModuleSP module_sp (GetSP ());
+    if (module_sp)
+        return module_sp->GetArchitecture().GetAddressByteSize();
     return sizeof(void*);
 }
 
+
+uint32_t
+SBModule::GetVersion (uint32_t *versions, uint32_t num_versions)
+{
+    ModuleSP module_sp (GetSP ());
+    if (module_sp)
+    {
+        ObjectFile *obj_file = module_sp->GetObjectFile();
+        if (obj_file)
+            return obj_file->GetVersion (versions, num_versions);
+    }
+    
+    if (versions && num_versions)
+    {
+        for (uint32_t i=0; i<num_versions; ++i)
+            versions[i] = UINT32_MAX;
+    }
+    return 0;
+}
+