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