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" |
Greg Clayton | 917c000 | 2011-06-29 22:09:02 +0000 | [diff] [blame^] | 18 | #include "lldb/Core/ValueObjectList.h" |
| 19 | #include "lldb/Core/ValueObjectVariable.h" |
| 20 | #include "lldb/Symbol/VariableList.h" |
| 21 | #include "lldb/Target/Target.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 22 | |
| 23 | using namespace lldb; |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 24 | using namespace lldb_private; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 25 | |
| 26 | |
| 27 | SBModule::SBModule () : |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 28 | m_opaque_sp () |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 29 | { |
| 30 | } |
| 31 | |
| 32 | SBModule::SBModule (const lldb::ModuleSP& module_sp) : |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 33 | m_opaque_sp (module_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 34 | { |
| 35 | } |
| 36 | |
Greg Clayton | 538eb82 | 2010-11-05 23:17:00 +0000 | [diff] [blame] | 37 | SBModule::SBModule(const SBModule &rhs) : |
| 38 | m_opaque_sp (rhs.m_opaque_sp) |
| 39 | { |
| 40 | } |
| 41 | |
| 42 | const SBModule & |
| 43 | SBModule::operator = (const SBModule &rhs) |
| 44 | { |
| 45 | if (this != &rhs) |
| 46 | m_opaque_sp = rhs.m_opaque_sp; |
| 47 | return *this; |
| 48 | } |
| 49 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 50 | SBModule::~SBModule () |
| 51 | { |
| 52 | } |
| 53 | |
| 54 | bool |
| 55 | SBModule::IsValid () const |
| 56 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 57 | return m_opaque_sp.get() != NULL; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | SBFileSpec |
| 61 | SBModule::GetFileSpec () const |
| 62 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 63 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 64 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 65 | SBFileSpec file_spec; |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 66 | if (m_opaque_sp) |
| 67 | file_spec.SetFileSpec(m_opaque_sp->GetFileSpec()); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 68 | |
| 69 | if (log) |
| 70 | { |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 71 | log->Printf ("SBModule(%p)::GetFileSpec () => SBFileSpec(%p)", |
| 72 | m_opaque_sp.get(), file_spec.get()); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 73 | } |
| 74 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 75 | return file_spec; |
| 76 | } |
| 77 | |
Greg Clayton | 180546b | 2011-04-30 01:09:13 +0000 | [diff] [blame] | 78 | lldb::SBFileSpec |
| 79 | SBModule::GetPlatformFileSpec () const |
| 80 | { |
| 81 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 82 | |
| 83 | SBFileSpec file_spec; |
| 84 | if (m_opaque_sp) |
| 85 | file_spec.SetFileSpec(m_opaque_sp->GetPlatformFileSpec()); |
| 86 | |
| 87 | if (log) |
| 88 | { |
| 89 | log->Printf ("SBModule(%p)::GetPlatformFileSpec () => SBFileSpec(%p)", |
| 90 | m_opaque_sp.get(), file_spec.get()); |
| 91 | } |
| 92 | |
| 93 | return file_spec; |
| 94 | |
| 95 | } |
| 96 | |
| 97 | bool |
| 98 | SBModule::SetPlatformFileSpec (const lldb::SBFileSpec &platform_file) |
| 99 | { |
| 100 | bool result = false; |
| 101 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 102 | |
| 103 | if (m_opaque_sp) |
| 104 | { |
| 105 | m_opaque_sp->SetPlatformFileSpec(*platform_file); |
| 106 | result = true; |
| 107 | } |
| 108 | |
| 109 | if (log) |
| 110 | { |
| 111 | log->Printf ("SBModule(%p)::SetPlatformFileSpec (SBFileSpec(%p (%s%s%s)) => %i", |
| 112 | m_opaque_sp.get(), |
| 113 | platform_file.get(), |
| 114 | platform_file->GetDirectory().GetCString(), |
| 115 | platform_file->GetDirectory() ? "/" : "", |
| 116 | platform_file->GetFilename().GetCString(), |
| 117 | result); |
| 118 | } |
| 119 | return result; |
| 120 | } |
| 121 | |
| 122 | |
| 123 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 124 | const uint8_t * |
| 125 | SBModule::GetUUIDBytes () const |
| 126 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 127 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 128 | |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 129 | const uint8_t *uuid_bytes = NULL; |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 130 | if (m_opaque_sp) |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 131 | uuid_bytes = (const uint8_t *)m_opaque_sp->GetUUID().GetBytes(); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 132 | |
| 133 | if (log) |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 134 | { |
| 135 | if (uuid_bytes) |
| 136 | { |
| 137 | StreamString s; |
| 138 | m_opaque_sp->GetUUID().Dump (&s); |
| 139 | log->Printf ("SBModule(%p)::GetUUIDBytes () => %s", m_opaque_sp.get(), s.GetData()); |
| 140 | } |
| 141 | else |
| 142 | log->Printf ("SBModule(%p)::GetUUIDBytes () => NULL", m_opaque_sp.get()); |
| 143 | } |
| 144 | return uuid_bytes; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | |
Johnny Chen | 919ee60 | 2011-04-01 00:35:55 +0000 | [diff] [blame] | 148 | const char * |
| 149 | SBModule::GetUUIDString () const |
| 150 | { |
| 151 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 152 | |
| 153 | static char uuid_string[80]; |
| 154 | const char * uuid_c_string = NULL; |
| 155 | if (m_opaque_sp) |
| 156 | uuid_c_string = (const char *)m_opaque_sp->GetUUID().GetAsCString(uuid_string, sizeof(uuid_string)); |
| 157 | |
| 158 | if (log) |
| 159 | { |
| 160 | if (uuid_c_string) |
| 161 | { |
| 162 | StreamString s; |
| 163 | m_opaque_sp->GetUUID().Dump (&s); |
| 164 | log->Printf ("SBModule(%p)::GetUUIDString () => %s", m_opaque_sp.get(), s.GetData()); |
| 165 | } |
| 166 | else |
| 167 | log->Printf ("SBModule(%p)::GetUUIDString () => NULL", m_opaque_sp.get()); |
| 168 | } |
| 169 | return uuid_c_string; |
| 170 | } |
| 171 | |
| 172 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 173 | bool |
| 174 | SBModule::operator == (const SBModule &rhs) const |
| 175 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 176 | if (m_opaque_sp) |
| 177 | return m_opaque_sp.get() == rhs.m_opaque_sp.get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 178 | return false; |
| 179 | } |
| 180 | |
| 181 | bool |
| 182 | SBModule::operator != (const SBModule &rhs) const |
| 183 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 184 | if (m_opaque_sp) |
| 185 | return m_opaque_sp.get() != rhs.m_opaque_sp.get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 186 | return false; |
| 187 | } |
| 188 | |
| 189 | lldb::ModuleSP & |
| 190 | SBModule::operator *() |
| 191 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 192 | return m_opaque_sp; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | lldb_private::Module * |
| 196 | SBModule::operator ->() |
| 197 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 198 | return m_opaque_sp.get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | const lldb_private::Module * |
| 202 | SBModule::operator ->() const |
| 203 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 204 | return m_opaque_sp.get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | lldb_private::Module * |
| 208 | SBModule::get() |
| 209 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 210 | return m_opaque_sp.get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | const lldb_private::Module * |
| 214 | SBModule::get() const |
| 215 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 216 | return m_opaque_sp.get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | |
| 220 | void |
| 221 | SBModule::SetModule (const lldb::ModuleSP& module_sp) |
| 222 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 223 | m_opaque_sp = module_sp; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 224 | } |
| 225 | |
Greg Clayton | 466f6c4 | 2010-09-10 18:31:35 +0000 | [diff] [blame] | 226 | |
| 227 | bool |
| 228 | SBModule::ResolveFileAddress (lldb::addr_t vm_addr, SBAddress& addr) |
| 229 | { |
Johnny Chen | b7a9d64 | 2011-06-28 22:32:15 +0000 | [diff] [blame] | 230 | if (m_opaque_sp && addr.IsValid()) |
Greg Clayton | 466f6c4 | 2010-09-10 18:31:35 +0000 | [diff] [blame] | 231 | return m_opaque_sp->ResolveFileAddress (vm_addr, *addr); |
| 232 | |
Johnny Chen | b7a9d64 | 2011-06-28 22:32:15 +0000 | [diff] [blame] | 233 | if (addr.IsValid()) |
| 234 | addr->Clear(); |
Greg Clayton | 466f6c4 | 2010-09-10 18:31:35 +0000 | [diff] [blame] | 235 | return false; |
| 236 | } |
| 237 | |
| 238 | SBSymbolContext |
| 239 | SBModule::ResolveSymbolContextForAddress (const SBAddress& addr, uint32_t resolve_scope) |
| 240 | { |
| 241 | SBSymbolContext sb_sc; |
| 242 | if (m_opaque_sp && addr.IsValid()) |
| 243 | m_opaque_sp->ResolveSymbolContextForAddress (*addr, resolve_scope, *sb_sc); |
| 244 | return sb_sc; |
| 245 | } |
| 246 | |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 247 | bool |
| 248 | SBModule::GetDescription (SBStream &description) |
| 249 | { |
| 250 | if (m_opaque_sp) |
| 251 | { |
Caroline Tice | e49ec18 | 2010-09-22 23:01:29 +0000 | [diff] [blame] | 252 | description.ref(); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 253 | m_opaque_sp->GetDescription (description.get()); |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 254 | } |
| 255 | else |
| 256 | description.Printf ("No value"); |
| 257 | |
| 258 | return true; |
| 259 | } |
Greg Clayton | 43edca3 | 2010-12-07 05:40:31 +0000 | [diff] [blame] | 260 | |
| 261 | size_t |
| 262 | SBModule::GetNumSymbols () |
| 263 | { |
| 264 | if (m_opaque_sp) |
| 265 | { |
| 266 | ObjectFile *obj_file = m_opaque_sp->GetObjectFile(); |
| 267 | if (obj_file) |
| 268 | { |
| 269 | Symtab *symtab = obj_file->GetSymtab(); |
| 270 | if (symtab) |
| 271 | return symtab->GetNumSymbols(); |
| 272 | } |
| 273 | } |
| 274 | return 0; |
| 275 | } |
| 276 | |
| 277 | SBSymbol |
| 278 | SBModule::GetSymbolAtIndex (size_t idx) |
| 279 | { |
| 280 | SBSymbol sb_symbol; |
| 281 | if (m_opaque_sp) |
| 282 | { |
| 283 | ObjectFile *obj_file = m_opaque_sp->GetObjectFile(); |
| 284 | if (obj_file) |
| 285 | { |
| 286 | Symtab *symtab = obj_file->GetSymtab(); |
| 287 | if (symtab) |
| 288 | sb_symbol.SetSymbol(symtab->SymbolAtIndex (idx)); |
| 289 | } |
| 290 | } |
| 291 | return sb_symbol; |
| 292 | } |
Greg Clayton | 4ed315f | 2011-06-21 01:34:41 +0000 | [diff] [blame] | 293 | |
| 294 | uint32_t |
| 295 | SBModule::FindFunctions (const char *name, |
| 296 | uint32_t name_type_mask, |
| 297 | bool append, |
| 298 | lldb::SBSymbolContextList& sc_list) |
| 299 | { |
| 300 | if (!append) |
| 301 | sc_list.Clear(); |
| 302 | if (m_opaque_sp) |
| 303 | { |
| 304 | const bool symbols_ok = true; |
| 305 | return m_opaque_sp->FindFunctions (ConstString(name), |
| 306 | name_type_mask, |
| 307 | symbols_ok, |
| 308 | append, |
| 309 | *sc_list); |
| 310 | } |
| 311 | return 0; |
| 312 | } |
| 313 | |
Greg Clayton | 917c000 | 2011-06-29 22:09:02 +0000 | [diff] [blame^] | 314 | |
| 315 | SBValueList |
| 316 | SBModule::FindGlobalVariables (SBTarget &target, const char *name, uint32_t max_matches) |
| 317 | { |
| 318 | SBValueList sb_value_list; |
| 319 | if (m_opaque_sp) |
| 320 | { |
| 321 | VariableList variable_list; |
| 322 | const uint32_t match_count = m_opaque_sp->FindGlobalVariables (ConstString (name), |
| 323 | false, |
| 324 | max_matches, |
| 325 | variable_list); |
| 326 | |
| 327 | if (match_count > 0) |
| 328 | { |
| 329 | ValueObjectList &value_object_list = sb_value_list.ref(); |
| 330 | for (uint32_t i=0; i<match_count; ++i) |
| 331 | { |
| 332 | lldb::ValueObjectSP valobj_sp; |
| 333 | if (target.IsValid()) |
| 334 | valobj_sp = ValueObjectVariable::Create (target.get(), variable_list.GetVariableAtIndex(i)); |
| 335 | else |
| 336 | valobj_sp = ValueObjectVariable::Create (NULL, variable_list.GetVariableAtIndex(i)); |
| 337 | if (valobj_sp) |
| 338 | value_object_list.Append(valobj_sp); |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | |
| 343 | return sb_value_list; |
| 344 | } |