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/SBStream.h" 14 #include "lldb/API/SBSymbolContextList.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 lldb::SBFileSpec 75 SBModule::GetPlatformFileSpec () const 76 { 77 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 78 79 SBFileSpec file_spec; 80 if (m_opaque_sp) 81 file_spec.SetFileSpec(m_opaque_sp->GetPlatformFileSpec()); 82 83 if (log) 84 { 85 log->Printf ("SBModule(%p)::GetPlatformFileSpec () => SBFileSpec(%p)", 86 m_opaque_sp.get(), file_spec.get()); 87 } 88 89 return file_spec; 90 91 } 92 93 bool 94 SBModule::SetPlatformFileSpec (const lldb::SBFileSpec &platform_file) 95 { 96 bool result = false; 97 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 98 99 if (m_opaque_sp) 100 { 101 m_opaque_sp->SetPlatformFileSpec(*platform_file); 102 result = true; 103 } 104 105 if (log) 106 { 107 log->Printf ("SBModule(%p)::SetPlatformFileSpec (SBFileSpec(%p (%s%s%s)) => %i", 108 m_opaque_sp.get(), 109 platform_file.get(), 110 platform_file->GetDirectory().GetCString(), 111 platform_file->GetDirectory() ? "/" : "", 112 platform_file->GetFilename().GetCString(), 113 result); 114 } 115 return result; 116 } 117 118 119 120 const uint8_t * 121 SBModule::GetUUIDBytes () const 122 { 123 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 124 125 const uint8_t *uuid_bytes = NULL; 126 if (m_opaque_sp) 127 uuid_bytes = (const uint8_t *)m_opaque_sp->GetUUID().GetBytes(); 128 129 if (log) 130 { 131 if (uuid_bytes) 132 { 133 StreamString s; 134 m_opaque_sp->GetUUID().Dump (&s); 135 log->Printf ("SBModule(%p)::GetUUIDBytes () => %s", m_opaque_sp.get(), s.GetData()); 136 } 137 else 138 log->Printf ("SBModule(%p)::GetUUIDBytes () => NULL", m_opaque_sp.get()); 139 } 140 return uuid_bytes; 141 } 142 143 144 const char * 145 SBModule::GetUUIDString () const 146 { 147 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 148 149 static char uuid_string[80]; 150 const char * uuid_c_string = NULL; 151 if (m_opaque_sp) 152 uuid_c_string = (const char *)m_opaque_sp->GetUUID().GetAsCString(uuid_string, sizeof(uuid_string)); 153 154 if (log) 155 { 156 if (uuid_c_string) 157 { 158 StreamString s; 159 m_opaque_sp->GetUUID().Dump (&s); 160 log->Printf ("SBModule(%p)::GetUUIDString () => %s", m_opaque_sp.get(), s.GetData()); 161 } 162 else 163 log->Printf ("SBModule(%p)::GetUUIDString () => NULL", m_opaque_sp.get()); 164 } 165 return uuid_c_string; 166 } 167 168 169 bool 170 SBModule::operator == (const SBModule &rhs) const 171 { 172 if (m_opaque_sp) 173 return m_opaque_sp.get() == rhs.m_opaque_sp.get(); 174 return false; 175 } 176 177 bool 178 SBModule::operator != (const SBModule &rhs) const 179 { 180 if (m_opaque_sp) 181 return m_opaque_sp.get() != rhs.m_opaque_sp.get(); 182 return false; 183 } 184 185 lldb::ModuleSP & 186 SBModule::operator *() 187 { 188 return m_opaque_sp; 189 } 190 191 lldb_private::Module * 192 SBModule::operator ->() 193 { 194 return m_opaque_sp.get(); 195 } 196 197 const lldb_private::Module * 198 SBModule::operator ->() const 199 { 200 return m_opaque_sp.get(); 201 } 202 203 lldb_private::Module * 204 SBModule::get() 205 { 206 return m_opaque_sp.get(); 207 } 208 209 const lldb_private::Module * 210 SBModule::get() const 211 { 212 return m_opaque_sp.get(); 213 } 214 215 216 void 217 SBModule::SetModule (const lldb::ModuleSP& module_sp) 218 { 219 m_opaque_sp = module_sp; 220 } 221 222 223 bool 224 SBModule::ResolveFileAddress (lldb::addr_t vm_addr, SBAddress& addr) 225 { 226 if (m_opaque_sp) 227 return m_opaque_sp->ResolveFileAddress (vm_addr, *addr); 228 229 addr->Clear(); 230 return false; 231 } 232 233 SBSymbolContext 234 SBModule::ResolveSymbolContextForAddress (const SBAddress& addr, uint32_t resolve_scope) 235 { 236 SBSymbolContext sb_sc; 237 if (m_opaque_sp && addr.IsValid()) 238 m_opaque_sp->ResolveSymbolContextForAddress (*addr, resolve_scope, *sb_sc); 239 return sb_sc; 240 } 241 242 bool 243 SBModule::GetDescription (SBStream &description) 244 { 245 if (m_opaque_sp) 246 { 247 description.ref(); 248 m_opaque_sp->GetDescription (description.get()); 249 } 250 else 251 description.Printf ("No value"); 252 253 return true; 254 } 255 256 size_t 257 SBModule::GetNumSymbols () 258 { 259 if (m_opaque_sp) 260 { 261 ObjectFile *obj_file = m_opaque_sp->GetObjectFile(); 262 if (obj_file) 263 { 264 Symtab *symtab = obj_file->GetSymtab(); 265 if (symtab) 266 return symtab->GetNumSymbols(); 267 } 268 } 269 return 0; 270 } 271 272 SBSymbol 273 SBModule::GetSymbolAtIndex (size_t idx) 274 { 275 SBSymbol sb_symbol; 276 if (m_opaque_sp) 277 { 278 ObjectFile *obj_file = m_opaque_sp->GetObjectFile(); 279 if (obj_file) 280 { 281 Symtab *symtab = obj_file->GetSymtab(); 282 if (symtab) 283 sb_symbol.SetSymbol(symtab->SymbolAtIndex (idx)); 284 } 285 } 286 return sb_symbol; 287 } 288 289 uint32_t 290 SBModule::FindFunctions (const char *name, 291 uint32_t name_type_mask, 292 bool append, 293 lldb::SBSymbolContextList& sc_list) 294 { 295 if (!append) 296 sc_list.Clear(); 297 if (m_opaque_sp) 298 { 299 const bool symbols_ok = true; 300 return m_opaque_sp->FindFunctions (ConstString(name), 301 name_type_mask, 302 symbols_ok, 303 append, 304 *sc_list); 305 } 306 return 0; 307 } 308 309