blob: 681d416c2aeaebd003c78b5cf0696caafa4341d2 [file] [log] [blame]
Chris Lattner24943d22010-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 Clayton466f6c42010-09-10 18:31:35 +000011#include "lldb/API/SBAddress.h"
12#include "lldb/API/SBFileSpec.h"
Greg Claytonb5a8f142012-02-05 02:38:54 +000013#include "lldb/API/SBProcess.h"
Caroline Tice98f930f2010-09-20 05:20:02 +000014#include "lldb/API/SBStream.h"
Greg Clayton4ed315f2011-06-21 01:34:41 +000015#include "lldb/API/SBSymbolContextList.h"
Chris Lattner24943d22010-06-08 16:52:24 +000016#include "lldb/Core/Module.h"
Caroline Tice7826c882010-10-26 03:11:13 +000017#include "lldb/Core/Log.h"
Greg Clayton49ce8962012-08-29 21:13:06 +000018#include "lldb/Core/Section.h"
Greg Clayton135adf22010-10-31 19:57:43 +000019#include "lldb/Core/StreamString.h"
Greg Clayton917c0002011-06-29 22:09:02 +000020#include "lldb/Core/ValueObjectList.h"
21#include "lldb/Core/ValueObjectVariable.h"
Greg Clayton49ce8962012-08-29 21:13:06 +000022#include "lldb/Symbol/ObjectFile.h"
Enrico Granata979e20d2011-07-29 19:53:35 +000023#include "lldb/Symbol/SymbolVendor.h"
Greg Clayton49ce8962012-08-29 21:13:06 +000024#include "lldb/Symbol/Symtab.h"
Greg Clayton917c0002011-06-29 22:09:02 +000025#include "lldb/Symbol/VariableList.h"
26#include "lldb/Target/Target.h"
Chris Lattner24943d22010-06-08 16:52:24 +000027
28using namespace lldb;
Caroline Tice7826c882010-10-26 03:11:13 +000029using namespace lldb_private;
Chris Lattner24943d22010-06-08 16:52:24 +000030
31
32SBModule::SBModule () :
Greg Clayton63094e02010-06-23 01:19:29 +000033 m_opaque_sp ()
Chris Lattner24943d22010-06-08 16:52:24 +000034{
35}
36
37SBModule::SBModule (const lldb::ModuleSP& module_sp) :
Greg Clayton63094e02010-06-23 01:19:29 +000038 m_opaque_sp (module_sp)
Chris Lattner24943d22010-06-08 16:52:24 +000039{
40}
41
Greg Clayton538eb822010-11-05 23:17:00 +000042SBModule::SBModule(const SBModule &rhs) :
43 m_opaque_sp (rhs.m_opaque_sp)
44{
45}
46
Greg Claytonb5a8f142012-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 Clayton9ce95382012-02-13 23:10:39 +000052 {
Greg Clayton2ddb2b82013-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 Clayton9ce95382012-02-13 23:10:39 +000061 }
Greg Claytonb5a8f142012-02-05 02:38:54 +000062}
63
Greg Clayton538eb822010-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 Lattner24943d22010-06-08 16:52:24 +000072SBModule::~SBModule ()
73{
74}
75
76bool
77SBModule::IsValid () const
78{
Greg Clayton63094e02010-06-23 01:19:29 +000079 return m_opaque_sp.get() != NULL;
Chris Lattner24943d22010-06-08 16:52:24 +000080}
81
Jim Inghame0bd5712011-12-19 20:39:44 +000082void
83SBModule::Clear()
84{
85 m_opaque_sp.reset();
86}
87
Chris Lattner24943d22010-06-08 16:52:24 +000088SBFileSpec
89SBModule::GetFileSpec () const
90{
Greg Claytone005f2c2010-11-06 01:53:30 +000091 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +000092
Chris Lattner24943d22010-06-08 16:52:24 +000093 SBFileSpec file_spec;
Greg Clayton49f4bf22012-02-22 19:41:02 +000094 ModuleSP module_sp (GetSP ());
95 if (module_sp)
96 file_spec.SetFileSpec(module_sp->GetFileSpec());
Caroline Tice7826c882010-10-26 03:11:13 +000097
98 if (log)
99 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000100 log->Printf ("SBModule(%p)::GetFileSpec () => SBFileSpec(%p)",
Greg Clayton49f4bf22012-02-22 19:41:02 +0000101 module_sp.get(), file_spec.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000102 }
103
Chris Lattner24943d22010-06-08 16:52:24 +0000104 return file_spec;
105}
106
Greg Clayton180546b2011-04-30 01:09:13 +0000107lldb::SBFileSpec
108SBModule::GetPlatformFileSpec () const
109{
110 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
111
112 SBFileSpec file_spec;
Greg Clayton49f4bf22012-02-22 19:41:02 +0000113 ModuleSP module_sp (GetSP ());
114 if (module_sp)
115 file_spec.SetFileSpec(module_sp->GetPlatformFileSpec());
Greg Clayton180546b2011-04-30 01:09:13 +0000116
117 if (log)
118 {
119 log->Printf ("SBModule(%p)::GetPlatformFileSpec () => SBFileSpec(%p)",
Greg Clayton49f4bf22012-02-22 19:41:02 +0000120 module_sp.get(), file_spec.get());
Greg Clayton180546b2011-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;
131 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
132
Greg Clayton49f4bf22012-02-22 19:41:02 +0000133 ModuleSP module_sp (GetSP ());
134 if (module_sp)
Greg Clayton180546b2011-04-30 01:09:13 +0000135 {
Greg Clayton49f4bf22012-02-22 19:41:02 +0000136 module_sp->SetPlatformFileSpec(*platform_file);
Greg Clayton180546b2011-04-30 01:09:13 +0000137 result = true;
138 }
139
140 if (log)
141 {
142 log->Printf ("SBModule(%p)::SetPlatformFileSpec (SBFileSpec(%p (%s%s%s)) => %i",
Greg Clayton49f4bf22012-02-22 19:41:02 +0000143 module_sp.get(),
Greg Clayton180546b2011-04-30 01:09:13 +0000144 platform_file.get(),
145 platform_file->GetDirectory().GetCString(),
146 platform_file->GetDirectory() ? "/" : "",
147 platform_file->GetFilename().GetCString(),
148 result);
149 }
150 return result;
151}
152
153
154
Chris Lattner24943d22010-06-08 16:52:24 +0000155const uint8_t *
156SBModule::GetUUIDBytes () const
157{
Greg Claytone005f2c2010-11-06 01:53:30 +0000158 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000159
Greg Claytona66ba462010-10-30 04:51:46 +0000160 const uint8_t *uuid_bytes = NULL;
Greg Clayton49f4bf22012-02-22 19:41:02 +0000161 ModuleSP module_sp (GetSP ());
162 if (module_sp)
163 uuid_bytes = (const uint8_t *)module_sp->GetUUID().GetBytes();
Caroline Tice7826c882010-10-26 03:11:13 +0000164
165 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000166 {
167 if (uuid_bytes)
168 {
169 StreamString s;
Greg Clayton49f4bf22012-02-22 19:41:02 +0000170 module_sp->GetUUID().Dump (&s);
171 log->Printf ("SBModule(%p)::GetUUIDBytes () => %s", module_sp.get(), s.GetData());
Greg Claytona66ba462010-10-30 04:51:46 +0000172 }
173 else
Greg Clayton49f4bf22012-02-22 19:41:02 +0000174 log->Printf ("SBModule(%p)::GetUUIDBytes () => NULL", module_sp.get());
Greg Claytona66ba462010-10-30 04:51:46 +0000175 }
176 return uuid_bytes;
Chris Lattner24943d22010-06-08 16:52:24 +0000177}
178
179
Johnny Chen919ee602011-04-01 00:35:55 +0000180const char *
181SBModule::GetUUIDString () const
182{
183 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
184
185 static char uuid_string[80];
186 const char * uuid_c_string = NULL;
Greg Clayton49f4bf22012-02-22 19:41:02 +0000187 ModuleSP module_sp (GetSP ());
188 if (module_sp)
189 uuid_c_string = (const char *)module_sp->GetUUID().GetAsCString(uuid_string, sizeof(uuid_string));
Johnny Chen919ee602011-04-01 00:35:55 +0000190
191 if (log)
192 {
193 if (uuid_c_string)
194 {
195 StreamString s;
Greg Clayton49f4bf22012-02-22 19:41:02 +0000196 module_sp->GetUUID().Dump (&s);
197 log->Printf ("SBModule(%p)::GetUUIDString () => %s", module_sp.get(), s.GetData());
Johnny Chen919ee602011-04-01 00:35:55 +0000198 }
199 else
Greg Clayton49f4bf22012-02-22 19:41:02 +0000200 log->Printf ("SBModule(%p)::GetUUIDString () => NULL", module_sp.get());
Johnny Chen919ee602011-04-01 00:35:55 +0000201 }
202 return uuid_c_string;
203}
204
205
Chris Lattner24943d22010-06-08 16:52:24 +0000206bool
207SBModule::operator == (const SBModule &rhs) const
208{
Greg Clayton63094e02010-06-23 01:19:29 +0000209 if (m_opaque_sp)
210 return m_opaque_sp.get() == rhs.m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000211 return false;
212}
213
214bool
215SBModule::operator != (const SBModule &rhs) const
216{
Greg Clayton63094e02010-06-23 01:19:29 +0000217 if (m_opaque_sp)
218 return m_opaque_sp.get() != rhs.m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000219 return false;
220}
221
Greg Clayton0416bdf2012-01-30 09:04:36 +0000222ModuleSP
223SBModule::GetSP () const
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000224{
225 return m_opaque_sp;
226}
Chris Lattner24943d22010-06-08 16:52:24 +0000227
228void
Greg Clayton0416bdf2012-01-30 09:04:36 +0000229SBModule::SetSP (const ModuleSP &module_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000230{
Greg Clayton63094e02010-06-23 01:19:29 +0000231 m_opaque_sp = module_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000232}
233
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000234SBAddress
235SBModule::ResolveFileAddress (lldb::addr_t vm_addr)
Greg Clayton466f6c42010-09-10 18:31:35 +0000236{
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000237 lldb::SBAddress sb_addr;
Greg Clayton49f4bf22012-02-22 19:41:02 +0000238 ModuleSP module_sp (GetSP ());
239 if (module_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000240 {
241 Address addr;
Greg Clayton49f4bf22012-02-22 19:41:02 +0000242 if (module_sp->ResolveFileAddress (vm_addr, addr))
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000243 sb_addr.ref() = addr;
244 }
245 return sb_addr;
Greg Clayton466f6c42010-09-10 18:31:35 +0000246}
247
248SBSymbolContext
249SBModule::ResolveSymbolContextForAddress (const SBAddress& addr, uint32_t resolve_scope)
250{
251 SBSymbolContext sb_sc;
Greg Clayton49f4bf22012-02-22 19:41:02 +0000252 ModuleSP module_sp (GetSP ());
253 if (module_sp && addr.IsValid())
254 module_sp->ResolveSymbolContextForAddress (addr.ref(), resolve_scope, *sb_sc);
Greg Clayton466f6c42010-09-10 18:31:35 +0000255 return sb_sc;
256}
257
Caroline Tice98f930f2010-09-20 05:20:02 +0000258bool
259SBModule::GetDescription (SBStream &description)
260{
Greg Clayton96154be2011-11-13 06:57:31 +0000261 Stream &strm = description.ref();
262
Greg Clayton49f4bf22012-02-22 19:41:02 +0000263 ModuleSP module_sp (GetSP ());
264 if (module_sp)
Caroline Tice98f930f2010-09-20 05:20:02 +0000265 {
Greg Clayton49f4bf22012-02-22 19:41:02 +0000266 module_sp->GetDescription (&strm);
Caroline Tice98f930f2010-09-20 05:20:02 +0000267 }
268 else
Greg Clayton96154be2011-11-13 06:57:31 +0000269 strm.PutCString ("No value");
Caroline Tice98f930f2010-09-20 05:20:02 +0000270
271 return true;
272}
Greg Clayton43edca32010-12-07 05:40:31 +0000273
Johnny Chenb451f5f2012-03-16 20:46:10 +0000274uint32_t
275SBModule::GetNumCompileUnits()
276{
277 ModuleSP module_sp (GetSP ());
278 if (module_sp)
279 {
280 return module_sp->GetNumCompileUnits ();
281 }
282 return 0;
283}
284
285SBCompileUnit
286SBModule::GetCompileUnitAtIndex (uint32_t index)
287{
288 SBCompileUnit sb_cu;
289 ModuleSP module_sp (GetSP ());
290 if (module_sp)
291 {
292 CompUnitSP cu_sp = module_sp->GetCompileUnitAtIndex (index);
293 sb_cu.reset(cu_sp.get());
294 }
295 return sb_cu;
296}
297
Greg Clayton43edca32010-12-07 05:40:31 +0000298size_t
299SBModule::GetNumSymbols ()
300{
Greg Clayton49f4bf22012-02-22 19:41:02 +0000301 ModuleSP module_sp (GetSP ());
302 if (module_sp)
Greg Clayton43edca32010-12-07 05:40:31 +0000303 {
Greg Clayton49f4bf22012-02-22 19:41:02 +0000304 ObjectFile *obj_file = module_sp->GetObjectFile();
Greg Clayton43edca32010-12-07 05:40:31 +0000305 if (obj_file)
306 {
307 Symtab *symtab = obj_file->GetSymtab();
308 if (symtab)
309 return symtab->GetNumSymbols();
310 }
311 }
312 return 0;
313}
314
315SBSymbol
316SBModule::GetSymbolAtIndex (size_t idx)
317{
318 SBSymbol sb_symbol;
Greg Clayton49f4bf22012-02-22 19:41:02 +0000319 ModuleSP module_sp (GetSP ());
320 if (module_sp)
Greg Clayton43edca32010-12-07 05:40:31 +0000321 {
Greg Clayton49f4bf22012-02-22 19:41:02 +0000322 ObjectFile *obj_file = module_sp->GetObjectFile();
Greg Clayton43edca32010-12-07 05:40:31 +0000323 if (obj_file)
324 {
325 Symtab *symtab = obj_file->GetSymtab();
326 if (symtab)
327 sb_symbol.SetSymbol(symtab->SymbolAtIndex (idx));
328 }
329 }
330 return sb_symbol;
331}
Greg Clayton4ed315f2011-06-21 01:34:41 +0000332
Greg Claytonb3dafc62012-12-04 02:22:16 +0000333lldb::SBSymbol
334SBModule::FindSymbol (const char *name,
335 lldb::SymbolType symbol_type)
336{
337 SBSymbol sb_symbol;
338 if (name && name[0])
339 {
340 ModuleSP module_sp (GetSP ());
341 if (module_sp)
342 {
343 ObjectFile *obj_file = module_sp->GetObjectFile();
344 if (obj_file)
345 {
346 Symtab *symtab = obj_file->GetSymtab();
347 if (symtab)
348 sb_symbol.SetSymbol(symtab->FindFirstSymbolWithNameAndType(ConstString(name), symbol_type, Symtab::eDebugAny, Symtab::eVisibilityAny));
349 }
350 }
351 }
352 return sb_symbol;
353}
354
355
356lldb::SBSymbolContextList
357SBModule::FindSymbols (const char *name, lldb::SymbolType symbol_type)
358{
359 SBSymbolContextList sb_sc_list;
360 if (name && name[0])
361 {
362 ModuleSP module_sp (GetSP ());
363 if (module_sp)
364 {
365 ObjectFile *obj_file = module_sp->GetObjectFile();
366 if (obj_file)
367 {
368 Symtab *symtab = obj_file->GetSymtab();
369 if (symtab)
370 {
371 std::vector<uint32_t> matching_symbol_indexes;
372 const size_t num_matches = symtab->FindAllSymbolsWithNameAndType(ConstString(name), symbol_type, matching_symbol_indexes);
373 if (num_matches)
374 {
375 SymbolContext sc;
376 sc.module_sp = module_sp;
377 SymbolContextList &sc_list = *sb_sc_list;
378 for (size_t i=0; i<num_matches; ++i)
379 {
380 sc.symbol = symtab->SymbolAtIndex (matching_symbol_indexes[i]);
381 if (sc.symbol)
382 sc_list.Append(sc);
383 }
384 }
385 }
386 }
387 }
388 }
389 return sb_sc_list;
390
391}
392
393
394
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000395size_t
396SBModule::GetNumSections ()
397{
Greg Clayton49f4bf22012-02-22 19:41:02 +0000398 ModuleSP module_sp (GetSP ());
399 if (module_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000400 {
Greg Clayton49f4bf22012-02-22 19:41:02 +0000401 ObjectFile *obj_file = module_sp->GetObjectFile();
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000402 if (obj_file)
403 {
404 SectionList *section_list = obj_file->GetSectionList ();
405 if (section_list)
406 return section_list->GetSize();
407 }
408 }
409 return 0;
410}
411
412SBSection
413SBModule::GetSectionAtIndex (size_t idx)
414{
415 SBSection sb_section;
Greg Clayton49f4bf22012-02-22 19:41:02 +0000416 ModuleSP module_sp (GetSP ());
417 if (module_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000418 {
Greg Clayton49f4bf22012-02-22 19:41:02 +0000419 ObjectFile *obj_file = module_sp->GetObjectFile();
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000420 if (obj_file)
421 {
422 SectionList *section_list = obj_file->GetSectionList ();
423
424 if (section_list)
Greg Clayton3508c382012-02-24 01:59:29 +0000425 sb_section.SetSP(section_list->GetSectionAtIndex (idx));
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000426 }
427 }
428 return sb_section;
429}
430
Greg Clayton7dd5c512012-02-06 01:44:54 +0000431lldb::SBSymbolContextList
Greg Clayton4ed315f2011-06-21 01:34:41 +0000432SBModule::FindFunctions (const char *name,
Greg Clayton7dd5c512012-02-06 01:44:54 +0000433 uint32_t name_type_mask)
Greg Clayton4ed315f2011-06-21 01:34:41 +0000434{
Greg Clayton7dd5c512012-02-06 01:44:54 +0000435 lldb::SBSymbolContextList sb_sc_list;
Greg Clayton49f4bf22012-02-22 19:41:02 +0000436 ModuleSP module_sp (GetSP ());
437 if (name && module_sp)
Greg Clayton4ed315f2011-06-21 01:34:41 +0000438 {
Greg Clayton7dd5c512012-02-06 01:44:54 +0000439 const bool append = true;
Greg Clayton4ed315f2011-06-21 01:34:41 +0000440 const bool symbols_ok = true;
Sean Callanan302d78c2012-02-10 22:52:19 +0000441 const bool inlines_ok = true;
Greg Clayton49f4bf22012-02-22 19:41:02 +0000442 module_sp->FindFunctions (ConstString(name),
443 NULL,
444 name_type_mask,
445 symbols_ok,
446 inlines_ok,
447 append,
448 *sb_sc_list);
Greg Clayton4ed315f2011-06-21 01:34:41 +0000449 }
Greg Clayton7dd5c512012-02-06 01:44:54 +0000450 return sb_sc_list;
Greg Clayton4ed315f2011-06-21 01:34:41 +0000451}
452
Greg Clayton917c0002011-06-29 22:09:02 +0000453
454SBValueList
455SBModule::FindGlobalVariables (SBTarget &target, const char *name, uint32_t max_matches)
456{
457 SBValueList sb_value_list;
Greg Clayton49f4bf22012-02-22 19:41:02 +0000458 ModuleSP module_sp (GetSP ());
459 if (name && module_sp)
Greg Clayton917c0002011-06-29 22:09:02 +0000460 {
461 VariableList variable_list;
Greg Clayton49f4bf22012-02-22 19:41:02 +0000462 const uint32_t match_count = module_sp->FindGlobalVariables (ConstString (name),
463 NULL,
464 false,
465 max_matches,
466 variable_list);
Greg Clayton917c0002011-06-29 22:09:02 +0000467
468 if (match_count > 0)
469 {
470 ValueObjectList &value_object_list = sb_value_list.ref();
471 for (uint32_t i=0; i<match_count; ++i)
472 {
473 lldb::ValueObjectSP valobj_sp;
Greg Clayton334d33a2012-01-30 07:41:31 +0000474 TargetSP target_sp (target.GetSP());
475 valobj_sp = ValueObjectVariable::Create (target_sp.get(), variable_list.GetVariableAtIndex(i));
Greg Clayton917c0002011-06-29 22:09:02 +0000476 if (valobj_sp)
477 value_object_list.Append(valobj_sp);
478 }
479 }
480 }
481
482 return sb_value_list;
483}
Enrico Granata979e20d2011-07-29 19:53:35 +0000484
Enrico Granata392bd8d2013-01-16 18:53:52 +0000485lldb::SBValue
486SBModule::FindFirstGlobalVariable (lldb::SBTarget &target, const char *name)
487{
488 SBValueList sb_value_list(FindGlobalVariables(target, name, 1));
489 if (sb_value_list.IsValid() && sb_value_list.GetSize() > 0)
490 return sb_value_list.GetValueAtIndex(0);
491 return SBValue();
492}
493
Enrico Granata979e20d2011-07-29 19:53:35 +0000494lldb::SBType
Johnny Chen87b8c4c2011-12-19 20:16:22 +0000495SBModule::FindFirstType (const char *name_cstr)
Enrico Granata979e20d2011-07-29 19:53:35 +0000496{
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000497 SBType sb_type;
Greg Clayton49f4bf22012-02-22 19:41:02 +0000498 ModuleSP module_sp (GetSP ());
499 if (name_cstr && module_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +0000500 {
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000501 SymbolContext sc;
Greg Claytondc0a38c2012-03-26 23:03:23 +0000502 const bool exact_match = false;
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000503 ConstString name(name_cstr);
504
Greg Clayton0b93a752012-12-05 21:24:42 +0000505 sb_type = SBType (module_sp->FindFirstType(sc, name, exact_match));
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000506
Greg Clayton0b93a752012-12-05 21:24:42 +0000507 if (!sb_type.IsValid())
508 sb_type = SBType (ClangASTType::GetBasicType (module_sp->GetClangASTContext().getASTContext(), name));
Enrico Granata979e20d2011-07-29 19:53:35 +0000509 }
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000510 return sb_type;
Enrico Granata979e20d2011-07-29 19:53:35 +0000511}
512
Greg Clayton0b93a752012-12-05 21:24:42 +0000513lldb::SBType
514SBModule::GetBasicType(lldb::BasicType type)
515{
516 ModuleSP module_sp (GetSP ());
517 if (module_sp)
518 return SBType (ClangASTType::GetBasicType (module_sp->GetClangASTContext().getASTContext(), type));
519 return SBType();
520}
521
Enrico Granata979e20d2011-07-29 19:53:35 +0000522lldb::SBTypeList
Johnny Chen87b8c4c2011-12-19 20:16:22 +0000523SBModule::FindTypes (const char *type)
Enrico Granata979e20d2011-07-29 19:53:35 +0000524{
Enrico Granata979e20d2011-07-29 19:53:35 +0000525 SBTypeList retval;
526
Greg Clayton49f4bf22012-02-22 19:41:02 +0000527 ModuleSP module_sp (GetSP ());
528 if (type && module_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +0000529 {
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000530 SymbolContext sc;
531 TypeList type_list;
Greg Claytondc0a38c2012-03-26 23:03:23 +0000532 const bool exact_match = false;
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000533 ConstString name(type);
Greg Clayton0b93a752012-12-05 21:24:42 +0000534 const uint32_t num_matches = module_sp->FindTypes (sc,
535 name,
536 exact_match,
537 UINT32_MAX,
538 type_list);
Enrico Granata979e20d2011-07-29 19:53:35 +0000539
Greg Clayton0b93a752012-12-05 21:24:42 +0000540 if (num_matches > 0)
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000541 {
Greg Clayton0b93a752012-12-05 21:24:42 +0000542 for (size_t idx = 0; idx < num_matches; idx++)
543 {
544 TypeSP type_sp (type_list.GetTypeAtIndex(idx));
545 if (type_sp)
546 retval.Append(SBType(type_sp));
547 }
548 }
549 else
550 {
551 SBType sb_type(ClangASTType::GetBasicType (module_sp->GetClangASTContext().getASTContext(), name));
552 if (sb_type.IsValid())
553 retval.Append(sb_type);
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000554 }
Enrico Granata979e20d2011-07-29 19:53:35 +0000555 }
556
557 return retval;
Greg Clayton153ccd72011-08-10 02:10:13 +0000558}
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000559
560
561SBSection
562SBModule::FindSection (const char *sect_name)
563{
564 SBSection sb_section;
565
Greg Clayton49f4bf22012-02-22 19:41:02 +0000566 ModuleSP module_sp (GetSP ());
567 if (sect_name && module_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000568 {
Greg Clayton49f4bf22012-02-22 19:41:02 +0000569 ObjectFile *objfile = module_sp->GetObjectFile();
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000570 if (objfile)
571 {
572 SectionList *section_list = objfile->GetSectionList();
573 if (section_list)
574 {
575 ConstString const_sect_name(sect_name);
576 SectionSP section_sp (section_list->FindSectionByName(const_sect_name));
577 if (section_sp)
578 {
Greg Clayton3508c382012-02-24 01:59:29 +0000579 sb_section.SetSP (section_sp);
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000580 }
581 }
582 }
583 }
584 return sb_section;
585}
586
Greg Clayton1b925202012-01-29 06:07:39 +0000587lldb::ByteOrder
588SBModule::GetByteOrder ()
589{
Greg Clayton49f4bf22012-02-22 19:41:02 +0000590 ModuleSP module_sp (GetSP ());
591 if (module_sp)
592 return module_sp->GetArchitecture().GetByteOrder();
Greg Clayton1b925202012-01-29 06:07:39 +0000593 return eByteOrderInvalid;
594}
595
596const char *
597SBModule::GetTriple ()
598{
Greg Clayton49f4bf22012-02-22 19:41:02 +0000599 ModuleSP module_sp (GetSP ());
600 if (module_sp)
Greg Clayton1b925202012-01-29 06:07:39 +0000601 {
Greg Clayton49f4bf22012-02-22 19:41:02 +0000602 std::string triple (module_sp->GetArchitecture().GetTriple().str());
Greg Clayton1b925202012-01-29 06:07:39 +0000603 // Unique the string so we don't run into ownership issues since
604 // the const strings put the string into the string pool once and
605 // the strings never comes out
606 ConstString const_triple (triple.c_str());
607 return const_triple.GetCString();
608 }
609 return NULL;
610}
611
612uint32_t
613SBModule::GetAddressByteSize()
614{
Greg Clayton49f4bf22012-02-22 19:41:02 +0000615 ModuleSP module_sp (GetSP ());
616 if (module_sp)
617 return module_sp->GetArchitecture().GetAddressByteSize();
Greg Clayton1b925202012-01-29 06:07:39 +0000618 return sizeof(void*);
619}
620
Greg Clayton49f4bf22012-02-22 19:41:02 +0000621
622uint32_t
623SBModule::GetVersion (uint32_t *versions, uint32_t num_versions)
624{
625 ModuleSP module_sp (GetSP ());
626 if (module_sp)
Enrico Granataae2ae942012-09-04 18:47:54 +0000627 return module_sp->GetVersion(versions, num_versions);
628 else
Greg Clayton49f4bf22012-02-22 19:41:02 +0000629 {
Enrico Granataae2ae942012-09-04 18:47:54 +0000630 if (versions && num_versions)
631 {
632 for (uint32_t i=0; i<num_versions; ++i)
633 versions[i] = UINT32_MAX;
634 }
635 return 0;
Greg Clayton49f4bf22012-02-22 19:41:02 +0000636 }
Greg Clayton49f4bf22012-02-22 19:41:02 +0000637}
638