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" |
Greg Clayton | b5a8f14 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 13 | #include "lldb/API/SBProcess.h" |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 14 | #include "lldb/API/SBStream.h" |
Greg Clayton | 4ed315f | 2011-06-21 01:34:41 +0000 | [diff] [blame] | 15 | #include "lldb/API/SBSymbolContextList.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 16 | #include "lldb/Core/Module.h" |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 17 | #include "lldb/Core/Log.h" |
Greg Clayton | 135adf2 | 2010-10-31 19:57:43 +0000 | [diff] [blame] | 18 | #include "lldb/Core/StreamString.h" |
Greg Clayton | 917c000 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 19 | #include "lldb/Core/ValueObjectList.h" |
| 20 | #include "lldb/Core/ValueObjectVariable.h" |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 21 | #include "lldb/Symbol/SymbolVendor.h" |
Greg Clayton | 917c000 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 22 | #include "lldb/Symbol/VariableList.h" |
| 23 | #include "lldb/Target/Target.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 24 | |
| 25 | using namespace lldb; |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 26 | using namespace lldb_private; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 27 | |
| 28 | |
| 29 | SBModule::SBModule () : |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 30 | m_opaque_sp () |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 31 | { |
| 32 | } |
| 33 | |
| 34 | SBModule::SBModule (const lldb::ModuleSP& module_sp) : |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 35 | m_opaque_sp (module_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 36 | { |
| 37 | } |
| 38 | |
Greg Clayton | 538eb82 | 2010-11-05 23:17:00 +0000 | [diff] [blame] | 39 | SBModule::SBModule(const SBModule &rhs) : |
| 40 | m_opaque_sp (rhs.m_opaque_sp) |
| 41 | { |
| 42 | } |
| 43 | |
Greg Clayton | b5a8f14 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 44 | SBModule::SBModule (lldb::SBProcess &process, lldb::addr_t header_addr) : |
| 45 | m_opaque_sp () |
| 46 | { |
| 47 | ProcessSP process_sp (process.GetSP()); |
| 48 | if (process_sp) |
| 49 | m_opaque_sp = process_sp->ReadModuleFromMemory (FileSpec(), header_addr); |
| 50 | } |
| 51 | |
Greg Clayton | 538eb82 | 2010-11-05 23:17:00 +0000 | [diff] [blame] | 52 | const SBModule & |
| 53 | SBModule::operator = (const SBModule &rhs) |
| 54 | { |
| 55 | if (this != &rhs) |
| 56 | m_opaque_sp = rhs.m_opaque_sp; |
| 57 | return *this; |
| 58 | } |
| 59 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 60 | SBModule::~SBModule () |
| 61 | { |
| 62 | } |
| 63 | |
| 64 | bool |
| 65 | SBModule::IsValid () const |
| 66 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 67 | return m_opaque_sp.get() != NULL; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 68 | } |
| 69 | |
Jim Ingham | e0bd571 | 2011-12-19 20:39:44 +0000 | [diff] [blame] | 70 | void |
| 71 | SBModule::Clear() |
| 72 | { |
| 73 | m_opaque_sp.reset(); |
| 74 | } |
| 75 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 76 | SBFileSpec |
| 77 | SBModule::GetFileSpec () const |
| 78 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 79 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 80 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 81 | SBFileSpec file_spec; |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 82 | if (m_opaque_sp) |
| 83 | file_spec.SetFileSpec(m_opaque_sp->GetFileSpec()); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 84 | |
| 85 | if (log) |
| 86 | { |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 87 | log->Printf ("SBModule(%p)::GetFileSpec () => SBFileSpec(%p)", |
| 88 | m_opaque_sp.get(), file_spec.get()); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 89 | } |
| 90 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 91 | return file_spec; |
| 92 | } |
| 93 | |
Greg Clayton | 180546b | 2011-04-30 01:09:13 +0000 | [diff] [blame] | 94 | lldb::SBFileSpec |
| 95 | SBModule::GetPlatformFileSpec () const |
| 96 | { |
| 97 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 98 | |
| 99 | SBFileSpec file_spec; |
| 100 | if (m_opaque_sp) |
| 101 | file_spec.SetFileSpec(m_opaque_sp->GetPlatformFileSpec()); |
| 102 | |
| 103 | if (log) |
| 104 | { |
| 105 | log->Printf ("SBModule(%p)::GetPlatformFileSpec () => SBFileSpec(%p)", |
| 106 | m_opaque_sp.get(), file_spec.get()); |
| 107 | } |
| 108 | |
| 109 | return file_spec; |
| 110 | |
| 111 | } |
| 112 | |
| 113 | bool |
| 114 | SBModule::SetPlatformFileSpec (const lldb::SBFileSpec &platform_file) |
| 115 | { |
| 116 | bool result = false; |
| 117 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 118 | |
| 119 | if (m_opaque_sp) |
| 120 | { |
| 121 | m_opaque_sp->SetPlatformFileSpec(*platform_file); |
| 122 | result = true; |
| 123 | } |
| 124 | |
| 125 | if (log) |
| 126 | { |
| 127 | log->Printf ("SBModule(%p)::SetPlatformFileSpec (SBFileSpec(%p (%s%s%s)) => %i", |
| 128 | m_opaque_sp.get(), |
| 129 | platform_file.get(), |
| 130 | platform_file->GetDirectory().GetCString(), |
| 131 | platform_file->GetDirectory() ? "/" : "", |
| 132 | platform_file->GetFilename().GetCString(), |
| 133 | result); |
| 134 | } |
| 135 | return result; |
| 136 | } |
| 137 | |
| 138 | |
| 139 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 140 | const uint8_t * |
| 141 | SBModule::GetUUIDBytes () const |
| 142 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 143 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 144 | |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 145 | const uint8_t *uuid_bytes = NULL; |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 146 | if (m_opaque_sp) |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 147 | uuid_bytes = (const uint8_t *)m_opaque_sp->GetUUID().GetBytes(); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 148 | |
| 149 | if (log) |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 150 | { |
| 151 | if (uuid_bytes) |
| 152 | { |
| 153 | StreamString s; |
| 154 | m_opaque_sp->GetUUID().Dump (&s); |
| 155 | log->Printf ("SBModule(%p)::GetUUIDBytes () => %s", m_opaque_sp.get(), s.GetData()); |
| 156 | } |
| 157 | else |
| 158 | log->Printf ("SBModule(%p)::GetUUIDBytes () => NULL", m_opaque_sp.get()); |
| 159 | } |
| 160 | return uuid_bytes; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | |
Johnny Chen | 919ee60 | 2011-04-01 00:35:55 +0000 | [diff] [blame] | 164 | const char * |
| 165 | SBModule::GetUUIDString () const |
| 166 | { |
| 167 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 168 | |
| 169 | static char uuid_string[80]; |
| 170 | const char * uuid_c_string = NULL; |
| 171 | if (m_opaque_sp) |
| 172 | uuid_c_string = (const char *)m_opaque_sp->GetUUID().GetAsCString(uuid_string, sizeof(uuid_string)); |
| 173 | |
| 174 | if (log) |
| 175 | { |
| 176 | if (uuid_c_string) |
| 177 | { |
| 178 | StreamString s; |
| 179 | m_opaque_sp->GetUUID().Dump (&s); |
| 180 | log->Printf ("SBModule(%p)::GetUUIDString () => %s", m_opaque_sp.get(), s.GetData()); |
| 181 | } |
| 182 | else |
| 183 | log->Printf ("SBModule(%p)::GetUUIDString () => NULL", m_opaque_sp.get()); |
| 184 | } |
| 185 | return uuid_c_string; |
| 186 | } |
| 187 | |
| 188 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 189 | bool |
| 190 | SBModule::operator == (const SBModule &rhs) const |
| 191 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 192 | if (m_opaque_sp) |
| 193 | return m_opaque_sp.get() == rhs.m_opaque_sp.get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 194 | return false; |
| 195 | } |
| 196 | |
| 197 | bool |
| 198 | SBModule::operator != (const SBModule &rhs) const |
| 199 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 200 | if (m_opaque_sp) |
| 201 | return m_opaque_sp.get() != rhs.m_opaque_sp.get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 202 | return false; |
| 203 | } |
| 204 | |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 205 | ModuleSP |
| 206 | SBModule::GetSP () const |
Greg Clayton | 3e8c25f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 207 | { |
| 208 | return m_opaque_sp; |
| 209 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 210 | |
| 211 | void |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 212 | SBModule::SetSP (const ModuleSP &module_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 213 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 214 | m_opaque_sp = module_sp; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 215 | } |
| 216 | |
Greg Clayton | 3e8c25f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 217 | SBAddress |
| 218 | SBModule::ResolveFileAddress (lldb::addr_t vm_addr) |
Greg Clayton | 466f6c4 | 2010-09-10 18:31:35 +0000 | [diff] [blame] | 219 | { |
Greg Clayton | 3e8c25f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 220 | lldb::SBAddress sb_addr; |
| 221 | if (m_opaque_sp) |
| 222 | { |
| 223 | Address addr; |
| 224 | if (m_opaque_sp->ResolveFileAddress (vm_addr, addr)) |
| 225 | sb_addr.ref() = addr; |
| 226 | } |
| 227 | return sb_addr; |
Greg Clayton | 466f6c4 | 2010-09-10 18:31:35 +0000 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | SBSymbolContext |
| 231 | SBModule::ResolveSymbolContextForAddress (const SBAddress& addr, uint32_t resolve_scope) |
| 232 | { |
| 233 | SBSymbolContext sb_sc; |
| 234 | if (m_opaque_sp && addr.IsValid()) |
Greg Clayton | a395506 | 2011-07-22 16:46:35 +0000 | [diff] [blame] | 235 | m_opaque_sp->ResolveSymbolContextForAddress (addr.ref(), resolve_scope, *sb_sc); |
Greg Clayton | 466f6c4 | 2010-09-10 18:31:35 +0000 | [diff] [blame] | 236 | return sb_sc; |
| 237 | } |
| 238 | |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 239 | bool |
| 240 | SBModule::GetDescription (SBStream &description) |
| 241 | { |
Greg Clayton | 96154be | 2011-11-13 06:57:31 +0000 | [diff] [blame] | 242 | Stream &strm = description.ref(); |
| 243 | |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 244 | if (m_opaque_sp) |
| 245 | { |
Greg Clayton | 96154be | 2011-11-13 06:57:31 +0000 | [diff] [blame] | 246 | m_opaque_sp->GetDescription (&strm); |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 247 | } |
| 248 | else |
Greg Clayton | 96154be | 2011-11-13 06:57:31 +0000 | [diff] [blame] | 249 | strm.PutCString ("No value"); |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 250 | |
| 251 | return true; |
| 252 | } |
Greg Clayton | 43edca3 | 2010-12-07 05:40:31 +0000 | [diff] [blame] | 253 | |
| 254 | size_t |
| 255 | SBModule::GetNumSymbols () |
| 256 | { |
| 257 | if (m_opaque_sp) |
| 258 | { |
| 259 | ObjectFile *obj_file = m_opaque_sp->GetObjectFile(); |
| 260 | if (obj_file) |
| 261 | { |
| 262 | Symtab *symtab = obj_file->GetSymtab(); |
| 263 | if (symtab) |
| 264 | return symtab->GetNumSymbols(); |
| 265 | } |
| 266 | } |
| 267 | return 0; |
| 268 | } |
| 269 | |
| 270 | SBSymbol |
| 271 | SBModule::GetSymbolAtIndex (size_t idx) |
| 272 | { |
| 273 | SBSymbol sb_symbol; |
| 274 | if (m_opaque_sp) |
| 275 | { |
| 276 | ObjectFile *obj_file = m_opaque_sp->GetObjectFile(); |
| 277 | if (obj_file) |
| 278 | { |
| 279 | Symtab *symtab = obj_file->GetSymtab(); |
| 280 | if (symtab) |
| 281 | sb_symbol.SetSymbol(symtab->SymbolAtIndex (idx)); |
| 282 | } |
| 283 | } |
| 284 | return sb_symbol; |
| 285 | } |
Greg Clayton | 4ed315f | 2011-06-21 01:34:41 +0000 | [diff] [blame] | 286 | |
Greg Clayton | 3e8c25f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 287 | size_t |
| 288 | SBModule::GetNumSections () |
| 289 | { |
| 290 | if (m_opaque_sp) |
| 291 | { |
| 292 | ObjectFile *obj_file = m_opaque_sp->GetObjectFile(); |
| 293 | if (obj_file) |
| 294 | { |
| 295 | SectionList *section_list = obj_file->GetSectionList (); |
| 296 | if (section_list) |
| 297 | return section_list->GetSize(); |
| 298 | } |
| 299 | } |
| 300 | return 0; |
| 301 | } |
| 302 | |
| 303 | SBSection |
| 304 | SBModule::GetSectionAtIndex (size_t idx) |
| 305 | { |
| 306 | SBSection sb_section; |
| 307 | if (m_opaque_sp) |
| 308 | { |
| 309 | ObjectFile *obj_file = m_opaque_sp->GetObjectFile(); |
| 310 | if (obj_file) |
| 311 | { |
| 312 | SectionList *section_list = obj_file->GetSectionList (); |
| 313 | |
| 314 | if (section_list) |
| 315 | sb_section.SetSection(section_list->GetSectionAtIndex (idx).get()); |
| 316 | } |
| 317 | } |
| 318 | return sb_section; |
| 319 | } |
| 320 | |
Greg Clayton | 7dd5c51 | 2012-02-06 01:44:54 +0000 | [diff] [blame^] | 321 | lldb::SBSymbolContextList |
Greg Clayton | 4ed315f | 2011-06-21 01:34:41 +0000 | [diff] [blame] | 322 | SBModule::FindFunctions (const char *name, |
Greg Clayton | 7dd5c51 | 2012-02-06 01:44:54 +0000 | [diff] [blame^] | 323 | uint32_t name_type_mask) |
Greg Clayton | 4ed315f | 2011-06-21 01:34:41 +0000 | [diff] [blame] | 324 | { |
Greg Clayton | 7dd5c51 | 2012-02-06 01:44:54 +0000 | [diff] [blame^] | 325 | lldb::SBSymbolContextList sb_sc_list; |
Johnny Chen | 87b8c4c | 2011-12-19 20:16:22 +0000 | [diff] [blame] | 326 | if (name && m_opaque_sp) |
Greg Clayton | 4ed315f | 2011-06-21 01:34:41 +0000 | [diff] [blame] | 327 | { |
Greg Clayton | 7dd5c51 | 2012-02-06 01:44:54 +0000 | [diff] [blame^] | 328 | const bool append = true; |
Greg Clayton | 4ed315f | 2011-06-21 01:34:41 +0000 | [diff] [blame] | 329 | const bool symbols_ok = true; |
Greg Clayton | 7dd5c51 | 2012-02-06 01:44:54 +0000 | [diff] [blame^] | 330 | m_opaque_sp->FindFunctions (ConstString(name), |
| 331 | NULL, |
| 332 | name_type_mask, |
| 333 | symbols_ok, |
| 334 | append, |
| 335 | *sb_sc_list); |
Greg Clayton | 4ed315f | 2011-06-21 01:34:41 +0000 | [diff] [blame] | 336 | } |
Greg Clayton | 7dd5c51 | 2012-02-06 01:44:54 +0000 | [diff] [blame^] | 337 | return sb_sc_list; |
Greg Clayton | 4ed315f | 2011-06-21 01:34:41 +0000 | [diff] [blame] | 338 | } |
| 339 | |
Greg Clayton | 917c000 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 340 | |
| 341 | SBValueList |
| 342 | SBModule::FindGlobalVariables (SBTarget &target, const char *name, uint32_t max_matches) |
| 343 | { |
| 344 | SBValueList sb_value_list; |
Johnny Chen | 87b8c4c | 2011-12-19 20:16:22 +0000 | [diff] [blame] | 345 | if (name && m_opaque_sp) |
Greg Clayton | 917c000 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 346 | { |
| 347 | VariableList variable_list; |
Sean Callanan | 3e80cd9 | 2011-10-12 02:08:07 +0000 | [diff] [blame] | 348 | const uint32_t match_count = m_opaque_sp->FindGlobalVariables (ConstString (name), |
| 349 | NULL, |
Greg Clayton | 917c000 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 350 | false, |
| 351 | max_matches, |
| 352 | variable_list); |
| 353 | |
| 354 | if (match_count > 0) |
| 355 | { |
| 356 | ValueObjectList &value_object_list = sb_value_list.ref(); |
| 357 | for (uint32_t i=0; i<match_count; ++i) |
| 358 | { |
| 359 | lldb::ValueObjectSP valobj_sp; |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 360 | TargetSP target_sp (target.GetSP()); |
| 361 | valobj_sp = ValueObjectVariable::Create (target_sp.get(), variable_list.GetVariableAtIndex(i)); |
Greg Clayton | 917c000 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 362 | if (valobj_sp) |
| 363 | value_object_list.Append(valobj_sp); |
| 364 | } |
| 365 | } |
| 366 | } |
| 367 | |
| 368 | return sb_value_list; |
| 369 | } |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 370 | |
| 371 | lldb::SBType |
Johnny Chen | 87b8c4c | 2011-12-19 20:16:22 +0000 | [diff] [blame] | 372 | SBModule::FindFirstType (const char *name_cstr) |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 373 | { |
Greg Clayton | 0fb0bcc | 2011-08-03 22:57:10 +0000 | [diff] [blame] | 374 | SBType sb_type; |
Johnny Chen | 87b8c4c | 2011-12-19 20:16:22 +0000 | [diff] [blame] | 375 | if (name_cstr && IsValid()) |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 376 | { |
Greg Clayton | 0fb0bcc | 2011-08-03 22:57:10 +0000 | [diff] [blame] | 377 | SymbolContext sc; |
| 378 | TypeList type_list; |
| 379 | uint32_t num_matches = 0; |
| 380 | ConstString name(name_cstr); |
| 381 | |
| 382 | num_matches = m_opaque_sp->FindTypes(sc, |
| 383 | name, |
Sean Callanan | 3e80cd9 | 2011-10-12 02:08:07 +0000 | [diff] [blame] | 384 | NULL, |
Greg Clayton | 0fb0bcc | 2011-08-03 22:57:10 +0000 | [diff] [blame] | 385 | false, |
| 386 | 1, |
| 387 | type_list); |
| 388 | |
| 389 | if (num_matches) |
| 390 | sb_type = lldb::SBType(type_list.GetTypeAtIndex(0)); |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 391 | } |
Greg Clayton | 0fb0bcc | 2011-08-03 22:57:10 +0000 | [diff] [blame] | 392 | return sb_type; |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 393 | } |
| 394 | |
| 395 | lldb::SBTypeList |
Johnny Chen | 87b8c4c | 2011-12-19 20:16:22 +0000 | [diff] [blame] | 396 | SBModule::FindTypes (const char *type) |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 397 | { |
| 398 | |
| 399 | SBTypeList retval; |
| 400 | |
Johnny Chen | 87b8c4c | 2011-12-19 20:16:22 +0000 | [diff] [blame] | 401 | if (type && IsValid()) |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 402 | { |
Greg Clayton | 0fb0bcc | 2011-08-03 22:57:10 +0000 | [diff] [blame] | 403 | SymbolContext sc; |
| 404 | TypeList type_list; |
| 405 | uint32_t num_matches = 0; |
| 406 | ConstString name(type); |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 407 | |
Greg Clayton | 0fb0bcc | 2011-08-03 22:57:10 +0000 | [diff] [blame] | 408 | num_matches = m_opaque_sp->FindTypes(sc, |
| 409 | name, |
Sean Callanan | 3e80cd9 | 2011-10-12 02:08:07 +0000 | [diff] [blame] | 410 | NULL, |
Greg Clayton | 0fb0bcc | 2011-08-03 22:57:10 +0000 | [diff] [blame] | 411 | false, |
| 412 | UINT32_MAX, |
| 413 | type_list); |
| 414 | |
| 415 | for (size_t idx = 0; idx < num_matches; idx++) |
| 416 | { |
| 417 | TypeSP type_sp (type_list.GetTypeAtIndex(idx)); |
| 418 | if (type_sp) |
| 419 | retval.Append(SBType(type_sp)); |
| 420 | } |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | return retval; |
Greg Clayton | 153ccd7 | 2011-08-10 02:10:13 +0000 | [diff] [blame] | 424 | } |
Greg Clayton | 3e8c25f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 425 | |
| 426 | |
| 427 | SBSection |
| 428 | SBModule::FindSection (const char *sect_name) |
| 429 | { |
| 430 | SBSection sb_section; |
| 431 | |
Johnny Chen | 87b8c4c | 2011-12-19 20:16:22 +0000 | [diff] [blame] | 432 | if (sect_name && IsValid()) |
Greg Clayton | 3e8c25f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 433 | { |
| 434 | ObjectFile *objfile = m_opaque_sp->GetObjectFile(); |
| 435 | if (objfile) |
| 436 | { |
| 437 | SectionList *section_list = objfile->GetSectionList(); |
| 438 | if (section_list) |
| 439 | { |
| 440 | ConstString const_sect_name(sect_name); |
| 441 | SectionSP section_sp (section_list->FindSectionByName(const_sect_name)); |
| 442 | if (section_sp) |
| 443 | { |
| 444 | sb_section.SetSection(section_sp.get()); |
| 445 | } |
| 446 | } |
| 447 | } |
| 448 | } |
| 449 | return sb_section; |
| 450 | } |
| 451 | |
Greg Clayton | 1b92520 | 2012-01-29 06:07:39 +0000 | [diff] [blame] | 452 | lldb::ByteOrder |
| 453 | SBModule::GetByteOrder () |
| 454 | { |
| 455 | if (m_opaque_sp) |
| 456 | return m_opaque_sp->GetArchitecture().GetByteOrder(); |
| 457 | return eByteOrderInvalid; |
| 458 | } |
| 459 | |
| 460 | const char * |
| 461 | SBModule::GetTriple () |
| 462 | { |
| 463 | if (m_opaque_sp) |
| 464 | { |
| 465 | std::string triple (m_opaque_sp->GetArchitecture().GetTriple().str()); |
| 466 | // Unique the string so we don't run into ownership issues since |
| 467 | // the const strings put the string into the string pool once and |
| 468 | // the strings never comes out |
| 469 | ConstString const_triple (triple.c_str()); |
| 470 | return const_triple.GetCString(); |
| 471 | } |
| 472 | return NULL; |
| 473 | } |
| 474 | |
| 475 | uint32_t |
| 476 | SBModule::GetAddressByteSize() |
| 477 | { |
| 478 | if (m_opaque_sp) |
| 479 | return m_opaque_sp->GetArchitecture().GetAddressByteSize(); |
| 480 | return sizeof(void*); |
| 481 | } |
| 482 | |