Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 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" |
Greg Clayton | 466f6c4 | 2010-09-10 18:31:35 +0000 | [diff] [blame] | 11 | #include "lldb/API/SBAddress.h" |
| 12 | #include "lldb/API/SBFileSpec.h" |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 13 | #include "lldb/API/SBStream.h" |
Greg Clayton | 4ed315f | 2011-06-21 01:34:41 +0000 | [diff] [blame] | 14 | #include "lldb/API/SBSymbolContextList.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 15 | #include "lldb/Core/Module.h" |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 16 | #include "lldb/Core/Log.h" |
Greg Clayton | 135adf2 | 2010-10-31 19:57:43 +0000 | [diff] [blame] | 17 | #include "lldb/Core/StreamString.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 18 | |
| 19 | using namespace lldb; |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 20 | using namespace lldb_private; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 21 | |
| 22 | |
| 23 | SBModule::SBModule () : |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 24 | m_opaque_sp () |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 25 | { |
| 26 | } |
| 27 | |
| 28 | SBModule::SBModule (const lldb::ModuleSP& module_sp) : |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 29 | m_opaque_sp (module_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 30 | { |
| 31 | } |
| 32 | |
Greg Clayton | 538eb82 | 2010-11-05 23:17:00 +0000 | [diff] [blame] | 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 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 46 | SBModule::~SBModule () |
| 47 | { |
| 48 | } |
| 49 | |
| 50 | bool |
| 51 | SBModule::IsValid () const |
| 52 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 53 | return m_opaque_sp.get() != NULL; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | SBFileSpec |
| 57 | SBModule::GetFileSpec () const |
| 58 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 59 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 60 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 61 | SBFileSpec file_spec; |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 62 | if (m_opaque_sp) |
| 63 | file_spec.SetFileSpec(m_opaque_sp->GetFileSpec()); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 64 | |
| 65 | if (log) |
| 66 | { |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 67 | log->Printf ("SBModule(%p)::GetFileSpec () => SBFileSpec(%p)", |
| 68 | m_opaque_sp.get(), file_spec.get()); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 69 | } |
| 70 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 71 | return file_spec; |
| 72 | } |
| 73 | |
Greg Clayton | 180546b | 2011-04-30 01:09:13 +0000 | [diff] [blame] | 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 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 120 | const uint8_t * |
| 121 | SBModule::GetUUIDBytes () const |
| 122 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 123 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 124 | |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 125 | const uint8_t *uuid_bytes = NULL; |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 126 | if (m_opaque_sp) |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 127 | uuid_bytes = (const uint8_t *)m_opaque_sp->GetUUID().GetBytes(); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 128 | |
| 129 | if (log) |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 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; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | |
Johnny Chen | 919ee60 | 2011-04-01 00:35:55 +0000 | [diff] [blame] | 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 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 169 | bool |
| 170 | SBModule::operator == (const SBModule &rhs) const |
| 171 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 172 | if (m_opaque_sp) |
| 173 | return m_opaque_sp.get() == rhs.m_opaque_sp.get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 174 | return false; |
| 175 | } |
| 176 | |
| 177 | bool |
| 178 | SBModule::operator != (const SBModule &rhs) const |
| 179 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 180 | if (m_opaque_sp) |
| 181 | return m_opaque_sp.get() != rhs.m_opaque_sp.get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 182 | return false; |
| 183 | } |
| 184 | |
| 185 | lldb::ModuleSP & |
| 186 | SBModule::operator *() |
| 187 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 188 | return m_opaque_sp; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | lldb_private::Module * |
| 192 | SBModule::operator ->() |
| 193 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 194 | return m_opaque_sp.get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | const lldb_private::Module * |
| 198 | SBModule::operator ->() const |
| 199 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 200 | return m_opaque_sp.get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | lldb_private::Module * |
| 204 | SBModule::get() |
| 205 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 206 | return m_opaque_sp.get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | const lldb_private::Module * |
| 210 | SBModule::get() const |
| 211 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 212 | return m_opaque_sp.get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | |
| 216 | void |
| 217 | SBModule::SetModule (const lldb::ModuleSP& module_sp) |
| 218 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 219 | m_opaque_sp = module_sp; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 220 | } |
| 221 | |
Greg Clayton | 466f6c4 | 2010-09-10 18:31:35 +0000 | [diff] [blame] | 222 | |
| 223 | bool |
| 224 | SBModule::ResolveFileAddress (lldb::addr_t vm_addr, SBAddress& addr) |
| 225 | { |
Johnny Chen | b7a9d64 | 2011-06-28 22:32:15 +0000 | [diff] [blame^] | 226 | if (m_opaque_sp && addr.IsValid()) |
Greg Clayton | 466f6c4 | 2010-09-10 18:31:35 +0000 | [diff] [blame] | 227 | return m_opaque_sp->ResolveFileAddress (vm_addr, *addr); |
| 228 | |
Johnny Chen | b7a9d64 | 2011-06-28 22:32:15 +0000 | [diff] [blame^] | 229 | if (addr.IsValid()) |
| 230 | addr->Clear(); |
Greg Clayton | 466f6c4 | 2010-09-10 18:31:35 +0000 | [diff] [blame] | 231 | return false; |
| 232 | } |
| 233 | |
| 234 | SBSymbolContext |
| 235 | SBModule::ResolveSymbolContextForAddress (const SBAddress& addr, uint32_t resolve_scope) |
| 236 | { |
| 237 | SBSymbolContext sb_sc; |
| 238 | if (m_opaque_sp && addr.IsValid()) |
| 239 | m_opaque_sp->ResolveSymbolContextForAddress (*addr, resolve_scope, *sb_sc); |
| 240 | return sb_sc; |
| 241 | } |
| 242 | |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 243 | bool |
| 244 | SBModule::GetDescription (SBStream &description) |
| 245 | { |
| 246 | if (m_opaque_sp) |
| 247 | { |
Caroline Tice | e49ec18 | 2010-09-22 23:01:29 +0000 | [diff] [blame] | 248 | description.ref(); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 249 | m_opaque_sp->GetDescription (description.get()); |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 250 | } |
| 251 | else |
| 252 | description.Printf ("No value"); |
| 253 | |
| 254 | return true; |
| 255 | } |
Greg Clayton | 43edca3 | 2010-12-07 05:40:31 +0000 | [diff] [blame] | 256 | |
| 257 | size_t |
| 258 | SBModule::GetNumSymbols () |
| 259 | { |
| 260 | if (m_opaque_sp) |
| 261 | { |
| 262 | ObjectFile *obj_file = m_opaque_sp->GetObjectFile(); |
| 263 | if (obj_file) |
| 264 | { |
| 265 | Symtab *symtab = obj_file->GetSymtab(); |
| 266 | if (symtab) |
| 267 | return symtab->GetNumSymbols(); |
| 268 | } |
| 269 | } |
| 270 | return 0; |
| 271 | } |
| 272 | |
| 273 | SBSymbol |
| 274 | SBModule::GetSymbolAtIndex (size_t idx) |
| 275 | { |
| 276 | SBSymbol sb_symbol; |
| 277 | if (m_opaque_sp) |
| 278 | { |
| 279 | ObjectFile *obj_file = m_opaque_sp->GetObjectFile(); |
| 280 | if (obj_file) |
| 281 | { |
| 282 | Symtab *symtab = obj_file->GetSymtab(); |
| 283 | if (symtab) |
| 284 | sb_symbol.SetSymbol(symtab->SymbolAtIndex (idx)); |
| 285 | } |
| 286 | } |
| 287 | return sb_symbol; |
| 288 | } |
Greg Clayton | 4ed315f | 2011-06-21 01:34:41 +0000 | [diff] [blame] | 289 | |
| 290 | uint32_t |
| 291 | SBModule::FindFunctions (const char *name, |
| 292 | uint32_t name_type_mask, |
| 293 | bool append, |
| 294 | lldb::SBSymbolContextList& sc_list) |
| 295 | { |
| 296 | if (!append) |
| 297 | sc_list.Clear(); |
| 298 | if (m_opaque_sp) |
| 299 | { |
| 300 | const bool symbols_ok = true; |
| 301 | return m_opaque_sp->FindFunctions (ConstString(name), |
| 302 | name_type_mask, |
| 303 | symbols_ok, |
| 304 | append, |
| 305 | *sc_list); |
| 306 | } |
| 307 | return 0; |
| 308 | } |
| 309 | |