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 } 32 33 SBModule::SBModule(const SBModule &rhs) : 34 m_opaque_sp (rhs.m_opaque_sp) 35 { 36 } 37 38 const SBModule & 39 SBModule::operator = (const SBModule &rhs) 40 { 41 if (this != &rhs) 42 m_opaque_sp = rhs.m_opaque_sp; 43 return *this; 44 } 45 46 SBModule::~SBModule () 47 { 48 } 49 50 bool 51 SBModule::IsValid () const 52 { 53 return m_opaque_sp.get() != NULL; 54 } 55 56 SBFileSpec 57 SBModule::GetFileSpec () const 58 { 59 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 60 61 SBFileSpec file_spec; 62 if (m_opaque_sp) 63 file_spec.SetFileSpec(m_opaque_sp->GetFileSpec()); 64 65 if (log) 66 { 67 log->Printf ("SBModule(%p)::GetFileSpec () => SBFileSpec(%p)", 68 m_opaque_sp.get(), file_spec.get()); 69 } 70 71 return file_spec; 72 } 73 74 const uint8_t * 75 SBModule::GetUUIDBytes () const 76 { 77 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 78 79 const uint8_t *uuid_bytes = NULL; 80 if (m_opaque_sp) 81 uuid_bytes = (const uint8_t *)m_opaque_sp->GetUUID().GetBytes(); 82 83 if (log) 84 { 85 if (uuid_bytes) 86 { 87 StreamString s; 88 m_opaque_sp->GetUUID().Dump (&s); 89 log->Printf ("SBModule(%p)::GetUUIDBytes () => %s", m_opaque_sp.get(), s.GetData()); 90 } 91 else 92 log->Printf ("SBModule(%p)::GetUUIDBytes () => NULL", m_opaque_sp.get()); 93 } 94 return uuid_bytes; 95 } 96 97 98 bool 99 SBModule::operator == (const SBModule &rhs) const 100 { 101 if (m_opaque_sp) 102 return m_opaque_sp.get() == rhs.m_opaque_sp.get(); 103 return false; 104 } 105 106 bool 107 SBModule::operator != (const SBModule &rhs) const 108 { 109 if (m_opaque_sp) 110 return m_opaque_sp.get() != rhs.m_opaque_sp.get(); 111 return false; 112 } 113 114 lldb::ModuleSP & 115 SBModule::operator *() 116 { 117 return m_opaque_sp; 118 } 119 120 lldb_private::Module * 121 SBModule::operator ->() 122 { 123 return m_opaque_sp.get(); 124 } 125 126 const lldb_private::Module * 127 SBModule::operator ->() const 128 { 129 return m_opaque_sp.get(); 130 } 131 132 lldb_private::Module * 133 SBModule::get() 134 { 135 return m_opaque_sp.get(); 136 } 137 138 const lldb_private::Module * 139 SBModule::get() const 140 { 141 return m_opaque_sp.get(); 142 } 143 144 145 void 146 SBModule::SetModule (const lldb::ModuleSP& module_sp) 147 { 148 m_opaque_sp = module_sp; 149 } 150 151 152 bool 153 SBModule::ResolveFileAddress (lldb::addr_t vm_addr, SBAddress& addr) 154 { 155 if (m_opaque_sp) 156 return m_opaque_sp->ResolveFileAddress (vm_addr, *addr); 157 158 addr->Clear(); 159 return false; 160 } 161 162 SBSymbolContext 163 SBModule::ResolveSymbolContextForAddress (const SBAddress& addr, uint32_t resolve_scope) 164 { 165 SBSymbolContext sb_sc; 166 if (m_opaque_sp && addr.IsValid()) 167 m_opaque_sp->ResolveSymbolContextForAddress (*addr, resolve_scope, *sb_sc); 168 return sb_sc; 169 } 170 171 bool 172 SBModule::GetDescription (SBStream &description) 173 { 174 if (m_opaque_sp) 175 { 176 description.ref(); 177 m_opaque_sp->GetDescription (description.get()); 178 } 179 else 180 description.Printf ("No value"); 181 182 return true; 183 } 184 185 size_t 186 SBModule::GetNumSymbols () 187 { 188 if (m_opaque_sp) 189 { 190 ObjectFile *obj_file = m_opaque_sp->GetObjectFile(); 191 if (obj_file) 192 { 193 Symtab *symtab = obj_file->GetSymtab(); 194 if (symtab) 195 return symtab->GetNumSymbols(); 196 } 197 } 198 return 0; 199 } 200 201 SBSymbol 202 SBModule::GetSymbolAtIndex (size_t idx) 203 { 204 SBSymbol sb_symbol; 205 if (m_opaque_sp) 206 { 207 ObjectFile *obj_file = m_opaque_sp->GetObjectFile(); 208 if (obj_file) 209 { 210 Symtab *symtab = obj_file->GetSymtab(); 211 if (symtab) 212 sb_symbol.SetSymbol(symtab->SymbolAtIndex (idx)); 213 } 214 } 215 return sb_symbol; 216 } 217