blob: 11a2c6c419d4445a26247cb2b40111acf373ad5d [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- 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 Clayton09960032010-09-10 18:31:35 +000011#include "lldb/API/SBAddress.h"
12#include "lldb/API/SBFileSpec.h"
Greg Claytonc9660542012-02-05 02:38:54 +000013#include "lldb/API/SBProcess.h"
Caroline Ticedde9cff2010-09-20 05:20:02 +000014#include "lldb/API/SBStream.h"
Greg Claytonfe356d32011-06-21 01:34:41 +000015#include "lldb/API/SBSymbolContextList.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000016#include "lldb/Core/Module.h"
Caroline Ticeceb6b132010-10-26 03:11:13 +000017#include "lldb/Core/Log.h"
Greg Clayton1f746072012-08-29 21:13:06 +000018#include "lldb/Core/Section.h"
Greg Clayton38adbbb2010-10-31 19:57:43 +000019#include "lldb/Core/StreamString.h"
Greg Claytondea8cb42011-06-29 22:09:02 +000020#include "lldb/Core/ValueObjectList.h"
21#include "lldb/Core/ValueObjectVariable.h"
Greg Clayton1f746072012-08-29 21:13:06 +000022#include "lldb/Symbol/ObjectFile.h"
Enrico Granata6f3533f2011-07-29 19:53:35 +000023#include "lldb/Symbol/SymbolVendor.h"
Greg Clayton1f746072012-08-29 21:13:06 +000024#include "lldb/Symbol/Symtab.h"
Greg Claytondea8cb42011-06-29 22:09:02 +000025#include "lldb/Symbol/VariableList.h"
26#include "lldb/Target/Target.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000027
28using namespace lldb;
Caroline Ticeceb6b132010-10-26 03:11:13 +000029using namespace lldb_private;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000030
31
32SBModule::SBModule () :
Greg Clayton66111032010-06-23 01:19:29 +000033 m_opaque_sp ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +000034{
35}
36
37SBModule::SBModule (const lldb::ModuleSP& module_sp) :
Greg Clayton66111032010-06-23 01:19:29 +000038 m_opaque_sp (module_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000039{
40}
41
Greg Claytonefabb122010-11-05 23:17:00 +000042SBModule::SBModule(const SBModule &rhs) :
43 m_opaque_sp (rhs.m_opaque_sp)
44{
45}
46
Greg Claytonc9660542012-02-05 02:38:54 +000047SBModule::SBModule (lldb::SBProcess &process, lldb::addr_t header_addr) :
48 m_opaque_sp ()
49{
50 ProcessSP process_sp (process.GetSP());
51 if (process_sp)
Greg Claytonc859e2d2012-02-13 23:10:39 +000052 {
Greg Clayton39f7ee82013-02-01 21:38:35 +000053 m_opaque_sp = process_sp->ReadModuleFromMemory (FileSpec(), header_addr);
54 if (m_opaque_sp)
55 {
56 Target &target = process_sp->GetTarget();
57 bool changed = false;
58 m_opaque_sp->SetLoadAddress(target, 0, changed);
59 target.GetImages().Append(m_opaque_sp);
60 }
Greg Claytonc859e2d2012-02-13 23:10:39 +000061 }
Greg Claytonc9660542012-02-05 02:38:54 +000062}
63
Greg Claytonefabb122010-11-05 23:17:00 +000064const SBModule &
65SBModule::operator = (const SBModule &rhs)
66{
67 if (this != &rhs)
68 m_opaque_sp = rhs.m_opaque_sp;
69 return *this;
70}
71
Chris Lattner30fdc8d2010-06-08 16:52:24 +000072SBModule::~SBModule ()
73{
74}
75
76bool
77SBModule::IsValid () const
78{
Greg Clayton66111032010-06-23 01:19:29 +000079 return m_opaque_sp.get() != NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000080}
81
Jim Ingham5d3bca42011-12-19 20:39:44 +000082void
83SBModule::Clear()
84{
85 m_opaque_sp.reset();
86}
87
Chris Lattner30fdc8d2010-06-08 16:52:24 +000088SBFileSpec
89SBModule::GetFileSpec () const
90{
Greg Clayton5160ce52013-03-27 23:08:40 +000091 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +000092
Chris Lattner30fdc8d2010-06-08 16:52:24 +000093 SBFileSpec file_spec;
Greg Claytonc2ff9312012-02-22 19:41:02 +000094 ModuleSP module_sp (GetSP ());
95 if (module_sp)
96 file_spec.SetFileSpec(module_sp->GetFileSpec());
Caroline Ticeceb6b132010-10-26 03:11:13 +000097
98 if (log)
99 {
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000100 log->Printf ("SBModule(%p)::GetFileSpec () => SBFileSpec(%p)",
Greg Claytonc2ff9312012-02-22 19:41:02 +0000101 module_sp.get(), file_spec.get());
Caroline Ticeceb6b132010-10-26 03:11:13 +0000102 }
103
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000104 return file_spec;
105}
106
Greg Clayton2289fa42011-04-30 01:09:13 +0000107lldb::SBFileSpec
108SBModule::GetPlatformFileSpec () const
109{
Greg Clayton5160ce52013-03-27 23:08:40 +0000110 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton2289fa42011-04-30 01:09:13 +0000111
112 SBFileSpec file_spec;
Greg Claytonc2ff9312012-02-22 19:41:02 +0000113 ModuleSP module_sp (GetSP ());
114 if (module_sp)
115 file_spec.SetFileSpec(module_sp->GetPlatformFileSpec());
Greg Clayton2289fa42011-04-30 01:09:13 +0000116
117 if (log)
118 {
119 log->Printf ("SBModule(%p)::GetPlatformFileSpec () => SBFileSpec(%p)",
Greg Claytonc2ff9312012-02-22 19:41:02 +0000120 module_sp.get(), file_spec.get());
Greg Clayton2289fa42011-04-30 01:09:13 +0000121 }
122
123 return file_spec;
124
125}
126
127bool
128SBModule::SetPlatformFileSpec (const lldb::SBFileSpec &platform_file)
129{
130 bool result = false;
Greg Clayton5160ce52013-03-27 23:08:40 +0000131 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton2289fa42011-04-30 01:09:13 +0000132
Greg Claytonc2ff9312012-02-22 19:41:02 +0000133 ModuleSP module_sp (GetSP ());
134 if (module_sp)
Greg Clayton2289fa42011-04-30 01:09:13 +0000135 {
Greg Claytonc2ff9312012-02-22 19:41:02 +0000136 module_sp->SetPlatformFileSpec(*platform_file);
Greg Clayton2289fa42011-04-30 01:09:13 +0000137 result = true;
138 }
139
140 if (log)
141 {
Greg Claytonb5ad4ec2013-04-29 17:25:54 +0000142 log->Printf ("SBModule(%p)::SetPlatformFileSpec (SBFileSpec(%p (%s)) => %i",
Greg Claytonc2ff9312012-02-22 19:41:02 +0000143 module_sp.get(),
Greg Clayton2289fa42011-04-30 01:09:13 +0000144 platform_file.get(),
Greg Claytonb5ad4ec2013-04-29 17:25:54 +0000145 platform_file->GetPath().c_str(),
Greg Clayton2289fa42011-04-30 01:09:13 +0000146 result);
147 }
148 return result;
149}
150
151
152
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000153const uint8_t *
154SBModule::GetUUIDBytes () const
155{
Greg Clayton5160ce52013-03-27 23:08:40 +0000156 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000157
Greg Clayton48381312010-10-30 04:51:46 +0000158 const uint8_t *uuid_bytes = NULL;
Greg Claytonc2ff9312012-02-22 19:41:02 +0000159 ModuleSP module_sp (GetSP ());
160 if (module_sp)
161 uuid_bytes = (const uint8_t *)module_sp->GetUUID().GetBytes();
Caroline Ticeceb6b132010-10-26 03:11:13 +0000162
163 if (log)
Greg Clayton48381312010-10-30 04:51:46 +0000164 {
165 if (uuid_bytes)
166 {
167 StreamString s;
Greg Claytonc2ff9312012-02-22 19:41:02 +0000168 module_sp->GetUUID().Dump (&s);
169 log->Printf ("SBModule(%p)::GetUUIDBytes () => %s", module_sp.get(), s.GetData());
Greg Clayton48381312010-10-30 04:51:46 +0000170 }
171 else
Greg Claytonc2ff9312012-02-22 19:41:02 +0000172 log->Printf ("SBModule(%p)::GetUUIDBytes () => NULL", module_sp.get());
Greg Clayton48381312010-10-30 04:51:46 +0000173 }
174 return uuid_bytes;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000175}
176
177
Johnny Chendf2963e2011-04-01 00:35:55 +0000178const char *
179SBModule::GetUUIDString () const
180{
Greg Clayton5160ce52013-03-27 23:08:40 +0000181 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Johnny Chendf2963e2011-04-01 00:35:55 +0000182
Jason Molendac16b4af2013-05-03 23:56:12 +0000183 static char uuid_string_buffer[80];
184 const char *uuid_c_string = NULL;
185 std::string uuid_string;
Greg Claytonc2ff9312012-02-22 19:41:02 +0000186 ModuleSP module_sp (GetSP ());
187 if (module_sp)
Jason Molendac16b4af2013-05-03 23:56:12 +0000188 uuid_string = module_sp->GetUUID().GetAsString();
189
190 if (!uuid_string.empty())
191 {
192 strncpy (uuid_string_buffer, uuid_string.c_str(), sizeof (uuid_string_buffer));
193 uuid_c_string = uuid_string_buffer;
194 }
Johnny Chendf2963e2011-04-01 00:35:55 +0000195
196 if (log)
197 {
Jason Molendac16b4af2013-05-03 23:56:12 +0000198 if (!uuid_string.empty())
Johnny Chendf2963e2011-04-01 00:35:55 +0000199 {
200 StreamString s;
Greg Claytonc2ff9312012-02-22 19:41:02 +0000201 module_sp->GetUUID().Dump (&s);
202 log->Printf ("SBModule(%p)::GetUUIDString () => %s", module_sp.get(), s.GetData());
Johnny Chendf2963e2011-04-01 00:35:55 +0000203 }
204 else
Greg Claytonc2ff9312012-02-22 19:41:02 +0000205 log->Printf ("SBModule(%p)::GetUUIDString () => NULL", module_sp.get());
Johnny Chendf2963e2011-04-01 00:35:55 +0000206 }
207 return uuid_c_string;
208}
209
210
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000211bool
212SBModule::operator == (const SBModule &rhs) const
213{
Greg Clayton66111032010-06-23 01:19:29 +0000214 if (m_opaque_sp)
215 return m_opaque_sp.get() == rhs.m_opaque_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000216 return false;
217}
218
219bool
220SBModule::operator != (const SBModule &rhs) const
221{
Greg Clayton66111032010-06-23 01:19:29 +0000222 if (m_opaque_sp)
223 return m_opaque_sp.get() != rhs.m_opaque_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000224 return false;
225}
226
Greg Claytonacdbe812012-01-30 09:04:36 +0000227ModuleSP
228SBModule::GetSP () const
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000229{
230 return m_opaque_sp;
231}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000232
233void
Greg Claytonacdbe812012-01-30 09:04:36 +0000234SBModule::SetSP (const ModuleSP &module_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000235{
Greg Clayton66111032010-06-23 01:19:29 +0000236 m_opaque_sp = module_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000237}
238
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000239SBAddress
240SBModule::ResolveFileAddress (lldb::addr_t vm_addr)
Greg Clayton09960032010-09-10 18:31:35 +0000241{
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000242 lldb::SBAddress sb_addr;
Greg Claytonc2ff9312012-02-22 19:41:02 +0000243 ModuleSP module_sp (GetSP ());
244 if (module_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000245 {
246 Address addr;
Greg Claytonc2ff9312012-02-22 19:41:02 +0000247 if (module_sp->ResolveFileAddress (vm_addr, addr))
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000248 sb_addr.ref() = addr;
249 }
250 return sb_addr;
Greg Clayton09960032010-09-10 18:31:35 +0000251}
252
253SBSymbolContext
254SBModule::ResolveSymbolContextForAddress (const SBAddress& addr, uint32_t resolve_scope)
255{
256 SBSymbolContext sb_sc;
Greg Claytonc2ff9312012-02-22 19:41:02 +0000257 ModuleSP module_sp (GetSP ());
258 if (module_sp && addr.IsValid())
259 module_sp->ResolveSymbolContextForAddress (addr.ref(), resolve_scope, *sb_sc);
Greg Clayton09960032010-09-10 18:31:35 +0000260 return sb_sc;
261}
262
Caroline Ticedde9cff2010-09-20 05:20:02 +0000263bool
264SBModule::GetDescription (SBStream &description)
265{
Greg Claytonda7bc7d2011-11-13 06:57:31 +0000266 Stream &strm = description.ref();
267
Greg Claytonc2ff9312012-02-22 19:41:02 +0000268 ModuleSP module_sp (GetSP ());
269 if (module_sp)
Caroline Ticedde9cff2010-09-20 05:20:02 +0000270 {
Greg Claytonc2ff9312012-02-22 19:41:02 +0000271 module_sp->GetDescription (&strm);
Caroline Ticedde9cff2010-09-20 05:20:02 +0000272 }
273 else
Greg Claytonda7bc7d2011-11-13 06:57:31 +0000274 strm.PutCString ("No value");
Caroline Ticedde9cff2010-09-20 05:20:02 +0000275
276 return true;
277}
Greg Claytonbbdabce2010-12-07 05:40:31 +0000278
Johnny Chen873a7a42012-03-16 20:46:10 +0000279uint32_t
280SBModule::GetNumCompileUnits()
281{
282 ModuleSP module_sp (GetSP ());
283 if (module_sp)
284 {
285 return module_sp->GetNumCompileUnits ();
286 }
287 return 0;
288}
289
290SBCompileUnit
291SBModule::GetCompileUnitAtIndex (uint32_t index)
292{
293 SBCompileUnit sb_cu;
294 ModuleSP module_sp (GetSP ());
295 if (module_sp)
296 {
297 CompUnitSP cu_sp = module_sp->GetCompileUnitAtIndex (index);
298 sb_cu.reset(cu_sp.get());
299 }
300 return sb_cu;
301}
302
Michael Sartaina7499c92013-07-01 19:45:50 +0000303static Symtab *
304GetUnifiedSymbolTable (const lldb::ModuleSP& module_sp)
305{
306 if (module_sp)
307 {
308 SymbolVendor *symbols = module_sp->GetSymbolVendor();
309 if (symbols)
310 return symbols->GetSymtab();
311 }
312 return NULL;
313}
314
Greg Claytonbbdabce2010-12-07 05:40:31 +0000315size_t
316SBModule::GetNumSymbols ()
317{
Greg Claytonc2ff9312012-02-22 19:41:02 +0000318 ModuleSP module_sp (GetSP ());
319 if (module_sp)
Greg Claytonbbdabce2010-12-07 05:40:31 +0000320 {
Michael Sartaina7499c92013-07-01 19:45:50 +0000321 Symtab *symtab = GetUnifiedSymbolTable (module_sp);
322 if (symtab)
323 return symtab->GetNumSymbols();
Greg Claytonbbdabce2010-12-07 05:40:31 +0000324 }
325 return 0;
326}
327
328SBSymbol
329SBModule::GetSymbolAtIndex (size_t idx)
330{
331 SBSymbol sb_symbol;
Greg Claytonc2ff9312012-02-22 19:41:02 +0000332 ModuleSP module_sp (GetSP ());
Michael Sartaina7499c92013-07-01 19:45:50 +0000333 Symtab *symtab = GetUnifiedSymbolTable (module_sp);
334 if (symtab)
335 sb_symbol.SetSymbol(symtab->SymbolAtIndex (idx));
Greg Claytonbbdabce2010-12-07 05:40:31 +0000336 return sb_symbol;
337}
Greg Claytonfe356d32011-06-21 01:34:41 +0000338
Greg Claytone14e1922012-12-04 02:22:16 +0000339lldb::SBSymbol
340SBModule::FindSymbol (const char *name,
341 lldb::SymbolType symbol_type)
342{
343 SBSymbol sb_symbol;
344 if (name && name[0])
345 {
346 ModuleSP module_sp (GetSP ());
Michael Sartaina7499c92013-07-01 19:45:50 +0000347 Symtab *symtab = GetUnifiedSymbolTable (module_sp);
348 if (symtab)
349 sb_symbol.SetSymbol(symtab->FindFirstSymbolWithNameAndType(ConstString(name), symbol_type, Symtab::eDebugAny, Symtab::eVisibilityAny));
Greg Claytone14e1922012-12-04 02:22:16 +0000350 }
351 return sb_symbol;
352}
353
354
355lldb::SBSymbolContextList
356SBModule::FindSymbols (const char *name, lldb::SymbolType symbol_type)
357{
358 SBSymbolContextList sb_sc_list;
359 if (name && name[0])
360 {
361 ModuleSP module_sp (GetSP ());
Michael Sartaina7499c92013-07-01 19:45:50 +0000362 Symtab *symtab = GetUnifiedSymbolTable (module_sp);
363 if (symtab)
Greg Claytone14e1922012-12-04 02:22:16 +0000364 {
Michael Sartaina7499c92013-07-01 19:45:50 +0000365 std::vector<uint32_t> matching_symbol_indexes;
366 const size_t num_matches = symtab->FindAllSymbolsWithNameAndType(ConstString(name), symbol_type, matching_symbol_indexes);
367 if (num_matches)
Greg Claytone14e1922012-12-04 02:22:16 +0000368 {
Michael Sartaina7499c92013-07-01 19:45:50 +0000369 SymbolContext sc;
370 sc.module_sp = module_sp;
371 SymbolContextList &sc_list = *sb_sc_list;
372 for (size_t i=0; i<num_matches; ++i)
Greg Claytone14e1922012-12-04 02:22:16 +0000373 {
Michael Sartaina7499c92013-07-01 19:45:50 +0000374 sc.symbol = symtab->SymbolAtIndex (matching_symbol_indexes[i]);
375 if (sc.symbol)
376 sc_list.Append(sc);
Greg Claytone14e1922012-12-04 02:22:16 +0000377 }
378 }
379 }
380 }
381 return sb_sc_list;
382
383}
384
385
386
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000387size_t
388SBModule::GetNumSections ()
389{
Greg Claytonc2ff9312012-02-22 19:41:02 +0000390 ModuleSP module_sp (GetSP ());
391 if (module_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000392 {
Michael Sartaina7499c92013-07-01 19:45:50 +0000393 // Give the symbol vendor a chance to add to the unified section list.
394 module_sp->GetSymbolVendor();
395 SectionList *section_list = module_sp->GetUnifiedSectionList();
396 if (section_list)
397 return section_list->GetSize();
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000398 }
399 return 0;
400}
401
402SBSection
403SBModule::GetSectionAtIndex (size_t idx)
404{
405 SBSection sb_section;
Greg Claytonc2ff9312012-02-22 19:41:02 +0000406 ModuleSP module_sp (GetSP ());
407 if (module_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000408 {
Michael Sartaina7499c92013-07-01 19:45:50 +0000409 // Give the symbol vendor a chance to add to the unified section list.
410 module_sp->GetSymbolVendor();
411 SectionList *section_list = module_sp->GetUnifiedSectionList ();
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000412
Michael Sartaina7499c92013-07-01 19:45:50 +0000413 if (section_list)
414 sb_section.SetSP(section_list->GetSectionAtIndex (idx));
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000415 }
416 return sb_section;
417}
418
Greg Clayton5569e642012-02-06 01:44:54 +0000419lldb::SBSymbolContextList
Greg Claytonfe356d32011-06-21 01:34:41 +0000420SBModule::FindFunctions (const char *name,
Greg Clayton5569e642012-02-06 01:44:54 +0000421 uint32_t name_type_mask)
Greg Claytonfe356d32011-06-21 01:34:41 +0000422{
Greg Clayton5569e642012-02-06 01:44:54 +0000423 lldb::SBSymbolContextList sb_sc_list;
Greg Claytonc2ff9312012-02-22 19:41:02 +0000424 ModuleSP module_sp (GetSP ());
425 if (name && module_sp)
Greg Claytonfe356d32011-06-21 01:34:41 +0000426 {
Greg Clayton5569e642012-02-06 01:44:54 +0000427 const bool append = true;
Greg Claytonfe356d32011-06-21 01:34:41 +0000428 const bool symbols_ok = true;
Sean Callanan9df05fb2012-02-10 22:52:19 +0000429 const bool inlines_ok = true;
Greg Claytonc2ff9312012-02-22 19:41:02 +0000430 module_sp->FindFunctions (ConstString(name),
431 NULL,
432 name_type_mask,
433 symbols_ok,
434 inlines_ok,
435 append,
436 *sb_sc_list);
Greg Claytonfe356d32011-06-21 01:34:41 +0000437 }
Greg Clayton5569e642012-02-06 01:44:54 +0000438 return sb_sc_list;
Greg Claytonfe356d32011-06-21 01:34:41 +0000439}
440
Greg Claytondea8cb42011-06-29 22:09:02 +0000441
442SBValueList
443SBModule::FindGlobalVariables (SBTarget &target, const char *name, uint32_t max_matches)
444{
445 SBValueList sb_value_list;
Greg Claytonc2ff9312012-02-22 19:41:02 +0000446 ModuleSP module_sp (GetSP ());
447 if (name && module_sp)
Greg Claytondea8cb42011-06-29 22:09:02 +0000448 {
449 VariableList variable_list;
Greg Claytonc2ff9312012-02-22 19:41:02 +0000450 const uint32_t match_count = module_sp->FindGlobalVariables (ConstString (name),
451 NULL,
452 false,
453 max_matches,
454 variable_list);
Greg Claytondea8cb42011-06-29 22:09:02 +0000455
456 if (match_count > 0)
457 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000458 for (uint32_t i=0; i<match_count; ++i)
459 {
460 lldb::ValueObjectSP valobj_sp;
Greg Claytonb9556ac2012-01-30 07:41:31 +0000461 TargetSP target_sp (target.GetSP());
462 valobj_sp = ValueObjectVariable::Create (target_sp.get(), variable_list.GetVariableAtIndex(i));
Greg Claytondea8cb42011-06-29 22:09:02 +0000463 if (valobj_sp)
Enrico Granata85425d72013-02-07 18:23:56 +0000464 sb_value_list.Append(SBValue(valobj_sp));
Greg Claytondea8cb42011-06-29 22:09:02 +0000465 }
466 }
467 }
468
469 return sb_value_list;
470}
Enrico Granata6f3533f2011-07-29 19:53:35 +0000471
Enrico Granatabcd80b42013-01-16 18:53:52 +0000472lldb::SBValue
473SBModule::FindFirstGlobalVariable (lldb::SBTarget &target, const char *name)
474{
475 SBValueList sb_value_list(FindGlobalVariables(target, name, 1));
476 if (sb_value_list.IsValid() && sb_value_list.GetSize() > 0)
477 return sb_value_list.GetValueAtIndex(0);
478 return SBValue();
479}
480
Enrico Granata6f3533f2011-07-29 19:53:35 +0000481lldb::SBType
Johnny Chen4efffd92011-12-19 20:16:22 +0000482SBModule::FindFirstType (const char *name_cstr)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000483{
Greg Claytonfe42ac42011-08-03 22:57:10 +0000484 SBType sb_type;
Greg Claytonc2ff9312012-02-22 19:41:02 +0000485 ModuleSP module_sp (GetSP ());
486 if (name_cstr && module_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000487 {
Greg Claytonfe42ac42011-08-03 22:57:10 +0000488 SymbolContext sc;
Greg Clayton84db9102012-03-26 23:03:23 +0000489 const bool exact_match = false;
Greg Claytonfe42ac42011-08-03 22:57:10 +0000490 ConstString name(name_cstr);
491
Greg Claytonb43165b2012-12-05 21:24:42 +0000492 sb_type = SBType (module_sp->FindFirstType(sc, name, exact_match));
Greg Claytonfe42ac42011-08-03 22:57:10 +0000493
Greg Claytonb43165b2012-12-05 21:24:42 +0000494 if (!sb_type.IsValid())
495 sb_type = SBType (ClangASTType::GetBasicType (module_sp->GetClangASTContext().getASTContext(), name));
Enrico Granata6f3533f2011-07-29 19:53:35 +0000496 }
Greg Claytonfe42ac42011-08-03 22:57:10 +0000497 return sb_type;
Enrico Granata6f3533f2011-07-29 19:53:35 +0000498}
499
Greg Claytonb43165b2012-12-05 21:24:42 +0000500lldb::SBType
501SBModule::GetBasicType(lldb::BasicType type)
502{
503 ModuleSP module_sp (GetSP ());
504 if (module_sp)
505 return SBType (ClangASTType::GetBasicType (module_sp->GetClangASTContext().getASTContext(), type));
506 return SBType();
507}
508
Enrico Granata6f3533f2011-07-29 19:53:35 +0000509lldb::SBTypeList
Johnny Chen4efffd92011-12-19 20:16:22 +0000510SBModule::FindTypes (const char *type)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000511{
Enrico Granata6f3533f2011-07-29 19:53:35 +0000512 SBTypeList retval;
513
Greg Claytonc2ff9312012-02-22 19:41:02 +0000514 ModuleSP module_sp (GetSP ());
515 if (type && module_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000516 {
Greg Claytonfe42ac42011-08-03 22:57:10 +0000517 SymbolContext sc;
518 TypeList type_list;
Greg Clayton84db9102012-03-26 23:03:23 +0000519 const bool exact_match = false;
Greg Claytonfe42ac42011-08-03 22:57:10 +0000520 ConstString name(type);
Greg Claytonb43165b2012-12-05 21:24:42 +0000521 const uint32_t num_matches = module_sp->FindTypes (sc,
522 name,
523 exact_match,
524 UINT32_MAX,
525 type_list);
Enrico Granata6f3533f2011-07-29 19:53:35 +0000526
Greg Claytonb43165b2012-12-05 21:24:42 +0000527 if (num_matches > 0)
Greg Claytonfe42ac42011-08-03 22:57:10 +0000528 {
Greg Claytonb43165b2012-12-05 21:24:42 +0000529 for (size_t idx = 0; idx < num_matches; idx++)
530 {
531 TypeSP type_sp (type_list.GetTypeAtIndex(idx));
532 if (type_sp)
533 retval.Append(SBType(type_sp));
534 }
535 }
536 else
537 {
538 SBType sb_type(ClangASTType::GetBasicType (module_sp->GetClangASTContext().getASTContext(), name));
539 if (sb_type.IsValid())
540 retval.Append(sb_type);
Greg Claytonfe42ac42011-08-03 22:57:10 +0000541 }
Enrico Granata6f3533f2011-07-29 19:53:35 +0000542 }
543
544 return retval;
Greg Clayton3418c852011-08-10 02:10:13 +0000545}
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000546
Greg Claytonf02500c2013-06-18 22:51:05 +0000547lldb::SBTypeList
548SBModule::GetTypes (uint32_t type_mask)
549{
550 SBTypeList sb_type_list;
551
552 ModuleSP module_sp (GetSP ());
553 if (module_sp)
554 {
555 SymbolVendor* vendor = module_sp->GetSymbolVendor();
556 if (vendor)
557 {
558 TypeList type_list;
559 vendor->GetTypes (NULL, type_mask, type_list);
560 sb_type_list.m_opaque_ap->Append(type_list);
561 }
562 }
563 return sb_type_list;
564}
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000565
566SBSection
567SBModule::FindSection (const char *sect_name)
568{
569 SBSection sb_section;
570
Greg Claytonc2ff9312012-02-22 19:41:02 +0000571 ModuleSP module_sp (GetSP ());
572 if (sect_name && module_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000573 {
Michael Sartaina7499c92013-07-01 19:45:50 +0000574 // Give the symbol vendor a chance to add to the unified section list.
575 module_sp->GetSymbolVendor();
576 SectionList *section_list = module_sp->GetUnifiedSectionList();
577 if (section_list)
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000578 {
Michael Sartaina7499c92013-07-01 19:45:50 +0000579 ConstString const_sect_name(sect_name);
580 SectionSP section_sp (section_list->FindSectionByName(const_sect_name));
581 if (section_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000582 {
Michael Sartaina7499c92013-07-01 19:45:50 +0000583 sb_section.SetSP (section_sp);
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000584 }
585 }
586 }
587 return sb_section;
588}
589
Greg Clayton13d19502012-01-29 06:07:39 +0000590lldb::ByteOrder
591SBModule::GetByteOrder ()
592{
Greg Claytonc2ff9312012-02-22 19:41:02 +0000593 ModuleSP module_sp (GetSP ());
594 if (module_sp)
595 return module_sp->GetArchitecture().GetByteOrder();
Greg Clayton13d19502012-01-29 06:07:39 +0000596 return eByteOrderInvalid;
597}
598
599const char *
600SBModule::GetTriple ()
601{
Greg Claytonc2ff9312012-02-22 19:41:02 +0000602 ModuleSP module_sp (GetSP ());
603 if (module_sp)
Greg Clayton13d19502012-01-29 06:07:39 +0000604 {
Greg Claytonc2ff9312012-02-22 19:41:02 +0000605 std::string triple (module_sp->GetArchitecture().GetTriple().str());
Greg Clayton13d19502012-01-29 06:07:39 +0000606 // Unique the string so we don't run into ownership issues since
607 // the const strings put the string into the string pool once and
608 // the strings never comes out
609 ConstString const_triple (triple.c_str());
610 return const_triple.GetCString();
611 }
612 return NULL;
613}
614
615uint32_t
616SBModule::GetAddressByteSize()
617{
Greg Claytonc2ff9312012-02-22 19:41:02 +0000618 ModuleSP module_sp (GetSP ());
619 if (module_sp)
620 return module_sp->GetArchitecture().GetAddressByteSize();
Greg Clayton13d19502012-01-29 06:07:39 +0000621 return sizeof(void*);
622}
623
Greg Claytonc2ff9312012-02-22 19:41:02 +0000624
625uint32_t
626SBModule::GetVersion (uint32_t *versions, uint32_t num_versions)
627{
628 ModuleSP module_sp (GetSP ());
629 if (module_sp)
Enrico Granata3467d802012-09-04 18:47:54 +0000630 return module_sp->GetVersion(versions, num_versions);
631 else
Greg Claytonc2ff9312012-02-22 19:41:02 +0000632 {
Enrico Granata3467d802012-09-04 18:47:54 +0000633 if (versions && num_versions)
634 {
635 for (uint32_t i=0; i<num_versions; ++i)
636 versions[i] = UINT32_MAX;
637 }
638 return 0;
Greg Claytonc2ff9312012-02-22 19:41:02 +0000639 }
Greg Claytonc2ff9312012-02-22 19:41:02 +0000640}
641