1 //===-- SBModule.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 10 #include "lldb/API/SBModule.h" 11 #include "lldb/API/SBAddress.h" 12 #include "lldb/API/SBFileSpec.h" 13 #include "lldb/API/SBFileSpec.h" 14 #include "lldb/API/SBStream.h" 15 #include "lldb/Core/Module.h" 16 #include "lldb/Core/Log.h" 17 #include "lldb/Core/STreamString.h" 18 19 using namespace lldb; 20 using namespace lldb_private; 21 22 23 SBModule::SBModule () : 24 m_opaque_sp () 25 { 26 } 27 28 SBModule::SBModule (const lldb::ModuleSP& module_sp) : 29 m_opaque_sp (module_sp) 30 { 31 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API); 32 33 if (log) 34 log->Printf ("SBModule::SBModule (module_sp=%p) => this.sp = %p", module_sp.get(), m_opaque_sp.get()); 35 } 36 37 SBModule::~SBModule () 38 { 39 } 40 41 bool 42 SBModule::IsValid () const 43 { 44 return m_opaque_sp.get() != NULL; 45 } 46 47 SBFileSpec 48 SBModule::GetFileSpec () const 49 { 50 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API); 51 52 //if (log) 53 // log->Printf ("SBModule::GetFileSpec ()"); 54 55 SBFileSpec file_spec; 56 if (m_opaque_sp) 57 file_spec.SetFileSpec(m_opaque_sp->GetFileSpec()); 58 59 if (log) 60 { 61 SBStream sstr; 62 file_spec.GetDescription (sstr); 63 log->Printf ("SBModule::GetFileSpec (this.sp=%p) => SBFileSpec : this.ap = %p, 's'", m_opaque_sp.get(), 64 file_spec.get(), sstr.GetData()); 65 } 66 67 return file_spec; 68 } 69 70 const uint8_t * 71 SBModule::GetUUIDBytes () const 72 { 73 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API); 74 75 //if (log) 76 // log->Printf ("SBModule::GetUUIDBytes ()"); 77 78 if (m_opaque_sp) 79 { 80 if (log) 81 { 82 StreamString sstr; 83 m_opaque_sp->GetUUID().Dump (&sstr); 84 log->Printf ("SBModule::GetUUIDBytes (this.sp=%p) => '%s'", m_opaque_sp.get(), sstr.GetData()); 85 } 86 return (const uint8_t *)m_opaque_sp->GetUUID().GetBytes(); 87 } 88 89 if (log) 90 log->Printf ("SBModule::GetUUIDBytes (this.sp=%p) => NULL", m_opaque_sp.get()); 91 return NULL; 92 } 93 94 95 bool 96 SBModule::operator == (const SBModule &rhs) const 97 { 98 if (m_opaque_sp) 99 return m_opaque_sp.get() == rhs.m_opaque_sp.get(); 100 return false; 101 } 102 103 bool 104 SBModule::operator != (const SBModule &rhs) const 105 { 106 if (m_opaque_sp) 107 return m_opaque_sp.get() != rhs.m_opaque_sp.get(); 108 return false; 109 } 110 111 lldb::ModuleSP & 112 SBModule::operator *() 113 { 114 return m_opaque_sp; 115 } 116 117 lldb_private::Module * 118 SBModule::operator ->() 119 { 120 return m_opaque_sp.get(); 121 } 122 123 const lldb_private::Module * 124 SBModule::operator ->() const 125 { 126 return m_opaque_sp.get(); 127 } 128 129 lldb_private::Module * 130 SBModule::get() 131 { 132 return m_opaque_sp.get(); 133 } 134 135 const lldb_private::Module * 136 SBModule::get() const 137 { 138 return m_opaque_sp.get(); 139 } 140 141 142 void 143 SBModule::SetModule (const lldb::ModuleSP& module_sp) 144 { 145 m_opaque_sp = module_sp; 146 } 147 148 149 bool 150 SBModule::ResolveFileAddress (lldb::addr_t vm_addr, SBAddress& addr) 151 { 152 if (m_opaque_sp) 153 return m_opaque_sp->ResolveFileAddress (vm_addr, *addr); 154 155 addr->Clear(); 156 return false; 157 } 158 159 SBSymbolContext 160 SBModule::ResolveSymbolContextForAddress (const SBAddress& addr, uint32_t resolve_scope) 161 { 162 SBSymbolContext sb_sc; 163 if (m_opaque_sp && addr.IsValid()) 164 m_opaque_sp->ResolveSymbolContextForAddress (*addr, resolve_scope, *sb_sc); 165 return sb_sc; 166 } 167 168 bool 169 SBModule::GetDescription (SBStream &description) 170 { 171 if (m_opaque_sp) 172 { 173 description.ref(); 174 m_opaque_sp->GetDescription (description.get()); 175 } 176 else 177 description.Printf ("No value"); 178 179 return true; 180 } 181