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 | 4ed315f | 2011-06-21 01:34:41 +0000 | [diff] [blame] | 321 | uint32_t |
| 322 | SBModule::FindFunctions (const char *name, |
| 323 | uint32_t name_type_mask, |
| 324 | bool append, |
| 325 | lldb::SBSymbolContextList& sc_list) |
| 326 | { |
| 327 | if (!append) |
| 328 | sc_list.Clear(); |
Johnny Chen | 87b8c4c | 2011-12-19 20:16:22 +0000 | [diff] [blame] | 329 | if (name && m_opaque_sp) |
Greg Clayton | 4ed315f | 2011-06-21 01:34:41 +0000 | [diff] [blame] | 330 | { |
| 331 | const bool symbols_ok = true; |
Sean Callanan | 3e80cd9 | 2011-10-12 02:08:07 +0000 | [diff] [blame] | 332 | return m_opaque_sp->FindFunctions (ConstString(name), |
| 333 | NULL, |
Greg Clayton | 4ed315f | 2011-06-21 01:34:41 +0000 | [diff] [blame] | 334 | name_type_mask, |
| 335 | symbols_ok, |
| 336 | append, |
| 337 | *sc_list); |
| 338 | } |
| 339 | return 0; |
| 340 | } |
| 341 | |
Greg Clayton | 917c000 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 342 | |
| 343 | SBValueList |
| 344 | SBModule::FindGlobalVariables (SBTarget &target, const char *name, uint32_t max_matches) |
| 345 | { |
| 346 | SBValueList sb_value_list; |
Johnny Chen | 87b8c4c | 2011-12-19 20:16:22 +0000 | [diff] [blame] | 347 | if (name && m_opaque_sp) |
Greg Clayton | 917c000 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 348 | { |
| 349 | VariableList variable_list; |
Sean Callanan | 3e80cd9 | 2011-10-12 02:08:07 +0000 | [diff] [blame] | 350 | const uint32_t match_count = m_opaque_sp->FindGlobalVariables (ConstString (name), |
| 351 | NULL, |
Greg Clayton | 917c000 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 352 | false, |
| 353 | max_matches, |
| 354 | variable_list); |
| 355 | |
| 356 | if (match_count > 0) |
| 357 | { |
| 358 | ValueObjectList &value_object_list = sb_value_list.ref(); |
| 359 | for (uint32_t i=0; i<match_count; ++i) |
| 360 | { |
| 361 | lldb::ValueObjectSP valobj_sp; |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 362 | TargetSP target_sp (target.GetSP()); |
| 363 | valobj_sp = ValueObjectVariable::Create (target_sp.get(), variable_list.GetVariableAtIndex(i)); |
Greg Clayton | 917c000 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 364 | if (valobj_sp) |
| 365 | value_object_list.Append(valobj_sp); |
| 366 | } |
| 367 | } |
| 368 | } |
| 369 | |
| 370 | return sb_value_list; |
| 371 | } |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 372 | |
| 373 | lldb::SBType |
Johnny Chen | 87b8c4c | 2011-12-19 20:16:22 +0000 | [diff] [blame] | 374 | SBModule::FindFirstType (const char *name_cstr) |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 375 | { |
Greg Clayton | 0fb0bcc | 2011-08-03 22:57:10 +0000 | [diff] [blame] | 376 | SBType sb_type; |
Johnny Chen | 87b8c4c | 2011-12-19 20:16:22 +0000 | [diff] [blame] | 377 | if (name_cstr && IsValid()) |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 378 | { |
Greg Clayton | 0fb0bcc | 2011-08-03 22:57:10 +0000 | [diff] [blame] | 379 | SymbolContext sc; |
| 380 | TypeList type_list; |
| 381 | uint32_t num_matches = 0; |
| 382 | ConstString name(name_cstr); |
| 383 | |
| 384 | num_matches = m_opaque_sp->FindTypes(sc, |
| 385 | name, |
Sean Callanan | 3e80cd9 | 2011-10-12 02:08:07 +0000 | [diff] [blame] | 386 | NULL, |
Greg Clayton | 0fb0bcc | 2011-08-03 22:57:10 +0000 | [diff] [blame] | 387 | false, |
| 388 | 1, |
| 389 | type_list); |
| 390 | |
| 391 | if (num_matches) |
| 392 | sb_type = lldb::SBType(type_list.GetTypeAtIndex(0)); |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 393 | } |
Greg Clayton | 0fb0bcc | 2011-08-03 22:57:10 +0000 | [diff] [blame] | 394 | return sb_type; |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 395 | } |
| 396 | |
| 397 | lldb::SBTypeList |
Johnny Chen | 87b8c4c | 2011-12-19 20:16:22 +0000 | [diff] [blame] | 398 | SBModule::FindTypes (const char *type) |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 399 | { |
| 400 | |
| 401 | SBTypeList retval; |
| 402 | |
Johnny Chen | 87b8c4c | 2011-12-19 20:16:22 +0000 | [diff] [blame] | 403 | if (type && IsValid()) |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 404 | { |
Greg Clayton | 0fb0bcc | 2011-08-03 22:57:10 +0000 | [diff] [blame] | 405 | SymbolContext sc; |
| 406 | TypeList type_list; |
| 407 | uint32_t num_matches = 0; |
| 408 | ConstString name(type); |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 409 | |
Greg Clayton | 0fb0bcc | 2011-08-03 22:57:10 +0000 | [diff] [blame] | 410 | num_matches = m_opaque_sp->FindTypes(sc, |
| 411 | name, |
Sean Callanan | 3e80cd9 | 2011-10-12 02:08:07 +0000 | [diff] [blame] | 412 | NULL, |
Greg Clayton | 0fb0bcc | 2011-08-03 22:57:10 +0000 | [diff] [blame] | 413 | false, |
| 414 | UINT32_MAX, |
| 415 | type_list); |
| 416 | |
| 417 | for (size_t idx = 0; idx < num_matches; idx++) |
| 418 | { |
| 419 | TypeSP type_sp (type_list.GetTypeAtIndex(idx)); |
| 420 | if (type_sp) |
| 421 | retval.Append(SBType(type_sp)); |
| 422 | } |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 423 | } |
| 424 | |
| 425 | return retval; |
Greg Clayton | 153ccd7 | 2011-08-10 02:10:13 +0000 | [diff] [blame] | 426 | } |
Greg Clayton | 3e8c25f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 427 | |
| 428 | |
| 429 | SBSection |
| 430 | SBModule::FindSection (const char *sect_name) |
| 431 | { |
| 432 | SBSection sb_section; |
| 433 | |
Johnny Chen | 87b8c4c | 2011-12-19 20:16:22 +0000 | [diff] [blame] | 434 | if (sect_name && IsValid()) |
Greg Clayton | 3e8c25f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 435 | { |
| 436 | ObjectFile *objfile = m_opaque_sp->GetObjectFile(); |
| 437 | if (objfile) |
| 438 | { |
| 439 | SectionList *section_list = objfile->GetSectionList(); |
| 440 | if (section_list) |
| 441 | { |
| 442 | ConstString const_sect_name(sect_name); |
| 443 | SectionSP section_sp (section_list->FindSectionByName(const_sect_name)); |
| 444 | if (section_sp) |
| 445 | { |
| 446 | sb_section.SetSection(section_sp.get()); |
| 447 | } |
| 448 | } |
| 449 | } |
| 450 | } |
| 451 | return sb_section; |
| 452 | } |
| 453 | |
Greg Clayton | 1b92520 | 2012-01-29 06:07:39 +0000 | [diff] [blame] | 454 | lldb::ByteOrder |
| 455 | SBModule::GetByteOrder () |
| 456 | { |
| 457 | if (m_opaque_sp) |
| 458 | return m_opaque_sp->GetArchitecture().GetByteOrder(); |
| 459 | return eByteOrderInvalid; |
| 460 | } |
| 461 | |
| 462 | const char * |
| 463 | SBModule::GetTriple () |
| 464 | { |
| 465 | if (m_opaque_sp) |
| 466 | { |
| 467 | std::string triple (m_opaque_sp->GetArchitecture().GetTriple().str()); |
| 468 | // Unique the string so we don't run into ownership issues since |
| 469 | // the const strings put the string into the string pool once and |
| 470 | // the strings never comes out |
| 471 | ConstString const_triple (triple.c_str()); |
| 472 | return const_triple.GetCString(); |
| 473 | } |
| 474 | return NULL; |
| 475 | } |
| 476 | |
| 477 | uint32_t |
| 478 | SBModule::GetAddressByteSize() |
| 479 | { |
| 480 | if (m_opaque_sp) |
| 481 | return m_opaque_sp->GetArchitecture().GetAddressByteSize(); |
| 482 | return sizeof(void*); |
| 483 | } |
| 484 | |