blob: 933e803c270fc5e80bed6aadc83819dcd666e0e6 [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 {
53 const bool add_image_to_target = true;
54 const bool load_image_sections_in_target = true;
55 m_opaque_sp = process_sp->ReadModuleFromMemory (FileSpec(),
56 header_addr,
57 add_image_to_target,
58 load_image_sections_in_target);
59 }
Greg Claytonb5a8f142012-02-05 02:38:54 +000060}
61
Greg Clayton538eb822010-11-05 23:17:00 +000062const SBModule &
63SBModule::operator = (const SBModule &rhs)
64{
65 if (this != &rhs)
66 m_opaque_sp = rhs.m_opaque_sp;
67 return *this;
68}
69
Chris Lattner24943d22010-06-08 16:52:24 +000070SBModule::~SBModule ()
71{
72}
73
74bool
75SBModule::IsValid () const
76{
Greg Clayton63094e02010-06-23 01:19:29 +000077 return m_opaque_sp.get() != NULL;
Chris Lattner24943d22010-06-08 16:52:24 +000078}
79
Jim Inghame0bd5712011-12-19 20:39:44 +000080void
81SBModule::Clear()
82{
83 m_opaque_sp.reset();
84}
85
Chris Lattner24943d22010-06-08 16:52:24 +000086SBFileSpec
87SBModule::GetFileSpec () const
88{
Greg Claytone005f2c2010-11-06 01:53:30 +000089 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +000090
Chris Lattner24943d22010-06-08 16:52:24 +000091 SBFileSpec file_spec;
Greg Clayton49f4bf22012-02-22 19:41:02 +000092 ModuleSP module_sp (GetSP ());
93 if (module_sp)
94 file_spec.SetFileSpec(module_sp->GetFileSpec());
Caroline Tice7826c882010-10-26 03:11:13 +000095
96 if (log)
97 {
Greg Clayton49ce6822010-10-31 03:01:06 +000098 log->Printf ("SBModule(%p)::GetFileSpec () => SBFileSpec(%p)",
Greg Clayton49f4bf22012-02-22 19:41:02 +000099 module_sp.get(), file_spec.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000100 }
101
Chris Lattner24943d22010-06-08 16:52:24 +0000102 return file_spec;
103}
104
Greg Clayton180546b2011-04-30 01:09:13 +0000105lldb::SBFileSpec
106SBModule::GetPlatformFileSpec () const
107{
108 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
109
110 SBFileSpec file_spec;
Greg Clayton49f4bf22012-02-22 19:41:02 +0000111 ModuleSP module_sp (GetSP ());
112 if (module_sp)
113 file_spec.SetFileSpec(module_sp->GetPlatformFileSpec());
Greg Clayton180546b2011-04-30 01:09:13 +0000114
115 if (log)
116 {
117 log->Printf ("SBModule(%p)::GetPlatformFileSpec () => SBFileSpec(%p)",
Greg Clayton49f4bf22012-02-22 19:41:02 +0000118 module_sp.get(), file_spec.get());
Greg Clayton180546b2011-04-30 01:09:13 +0000119 }
120
121 return file_spec;
122
123}
124
125bool
126SBModule::SetPlatformFileSpec (const lldb::SBFileSpec &platform_file)
127{
128 bool result = false;
129 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
130
Greg Clayton49f4bf22012-02-22 19:41:02 +0000131 ModuleSP module_sp (GetSP ());
132 if (module_sp)
Greg Clayton180546b2011-04-30 01:09:13 +0000133 {
Greg Clayton49f4bf22012-02-22 19:41:02 +0000134 module_sp->SetPlatformFileSpec(*platform_file);
Greg Clayton180546b2011-04-30 01:09:13 +0000135 result = true;
136 }
137
138 if (log)
139 {
140 log->Printf ("SBModule(%p)::SetPlatformFileSpec (SBFileSpec(%p (%s%s%s)) => %i",
Greg Clayton49f4bf22012-02-22 19:41:02 +0000141 module_sp.get(),
Greg Clayton180546b2011-04-30 01:09:13 +0000142 platform_file.get(),
143 platform_file->GetDirectory().GetCString(),
144 platform_file->GetDirectory() ? "/" : "",
145 platform_file->GetFilename().GetCString(),
146 result);
147 }
148 return result;
149}
150
151
152
Chris Lattner24943d22010-06-08 16:52:24 +0000153const uint8_t *
154SBModule::GetUUIDBytes () const
155{
Greg Claytone005f2c2010-11-06 01:53:30 +0000156 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000157
Greg Claytona66ba462010-10-30 04:51:46 +0000158 const uint8_t *uuid_bytes = NULL;
Greg Clayton49f4bf22012-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 Tice7826c882010-10-26 03:11:13 +0000162
163 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000164 {
165 if (uuid_bytes)
166 {
167 StreamString s;
Greg Clayton49f4bf22012-02-22 19:41:02 +0000168 module_sp->GetUUID().Dump (&s);
169 log->Printf ("SBModule(%p)::GetUUIDBytes () => %s", module_sp.get(), s.GetData());
Greg Claytona66ba462010-10-30 04:51:46 +0000170 }
171 else
Greg Clayton49f4bf22012-02-22 19:41:02 +0000172 log->Printf ("SBModule(%p)::GetUUIDBytes () => NULL", module_sp.get());
Greg Claytona66ba462010-10-30 04:51:46 +0000173 }
174 return uuid_bytes;
Chris Lattner24943d22010-06-08 16:52:24 +0000175}
176
177
Johnny Chen919ee602011-04-01 00:35:55 +0000178const char *
179SBModule::GetUUIDString () const
180{
181 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
182
183 static char uuid_string[80];
184 const char * uuid_c_string = NULL;
Greg Clayton49f4bf22012-02-22 19:41:02 +0000185 ModuleSP module_sp (GetSP ());
186 if (module_sp)
187 uuid_c_string = (const char *)module_sp->GetUUID().GetAsCString(uuid_string, sizeof(uuid_string));
Johnny Chen919ee602011-04-01 00:35:55 +0000188
189 if (log)
190 {
191 if (uuid_c_string)
192 {
193 StreamString s;
Greg Clayton49f4bf22012-02-22 19:41:02 +0000194 module_sp->GetUUID().Dump (&s);
195 log->Printf ("SBModule(%p)::GetUUIDString () => %s", module_sp.get(), s.GetData());
Johnny Chen919ee602011-04-01 00:35:55 +0000196 }
197 else
Greg Clayton49f4bf22012-02-22 19:41:02 +0000198 log->Printf ("SBModule(%p)::GetUUIDString () => NULL", module_sp.get());
Johnny Chen919ee602011-04-01 00:35:55 +0000199 }
200 return uuid_c_string;
201}
202
203
Chris Lattner24943d22010-06-08 16:52:24 +0000204bool
205SBModule::operator == (const SBModule &rhs) const
206{
Greg Clayton63094e02010-06-23 01:19:29 +0000207 if (m_opaque_sp)
208 return m_opaque_sp.get() == rhs.m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000209 return false;
210}
211
212bool
213SBModule::operator != (const SBModule &rhs) const
214{
Greg Clayton63094e02010-06-23 01:19:29 +0000215 if (m_opaque_sp)
216 return m_opaque_sp.get() != rhs.m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000217 return false;
218}
219
Greg Clayton0416bdf2012-01-30 09:04:36 +0000220ModuleSP
221SBModule::GetSP () const
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000222{
223 return m_opaque_sp;
224}
Chris Lattner24943d22010-06-08 16:52:24 +0000225
226void
Greg Clayton0416bdf2012-01-30 09:04:36 +0000227SBModule::SetSP (const ModuleSP &module_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000228{
Greg Clayton63094e02010-06-23 01:19:29 +0000229 m_opaque_sp = module_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000230}
231
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000232SBAddress
233SBModule::ResolveFileAddress (lldb::addr_t vm_addr)
Greg Clayton466f6c42010-09-10 18:31:35 +0000234{
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000235 lldb::SBAddress sb_addr;
Greg Clayton49f4bf22012-02-22 19:41:02 +0000236 ModuleSP module_sp (GetSP ());
237 if (module_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000238 {
239 Address addr;
Greg Clayton49f4bf22012-02-22 19:41:02 +0000240 if (module_sp->ResolveFileAddress (vm_addr, addr))
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000241 sb_addr.ref() = addr;
242 }
243 return sb_addr;
Greg Clayton466f6c42010-09-10 18:31:35 +0000244}
245
246SBSymbolContext
247SBModule::ResolveSymbolContextForAddress (const SBAddress& addr, uint32_t resolve_scope)
248{
249 SBSymbolContext sb_sc;
Greg Clayton49f4bf22012-02-22 19:41:02 +0000250 ModuleSP module_sp (GetSP ());
251 if (module_sp && addr.IsValid())
252 module_sp->ResolveSymbolContextForAddress (addr.ref(), resolve_scope, *sb_sc);
Greg Clayton466f6c42010-09-10 18:31:35 +0000253 return sb_sc;
254}
255
Caroline Tice98f930f2010-09-20 05:20:02 +0000256bool
257SBModule::GetDescription (SBStream &description)
258{
Greg Clayton96154be2011-11-13 06:57:31 +0000259 Stream &strm = description.ref();
260
Greg Clayton49f4bf22012-02-22 19:41:02 +0000261 ModuleSP module_sp (GetSP ());
262 if (module_sp)
Caroline Tice98f930f2010-09-20 05:20:02 +0000263 {
Greg Clayton49f4bf22012-02-22 19:41:02 +0000264 module_sp->GetDescription (&strm);
Caroline Tice98f930f2010-09-20 05:20:02 +0000265 }
266 else
Greg Clayton96154be2011-11-13 06:57:31 +0000267 strm.PutCString ("No value");
Caroline Tice98f930f2010-09-20 05:20:02 +0000268
269 return true;
270}
Greg Clayton43edca32010-12-07 05:40:31 +0000271
Johnny Chenb451f5f2012-03-16 20:46:10 +0000272uint32_t
273SBModule::GetNumCompileUnits()
274{
275 ModuleSP module_sp (GetSP ());
276 if (module_sp)
277 {
278 return module_sp->GetNumCompileUnits ();
279 }
280 return 0;
281}
282
283SBCompileUnit
284SBModule::GetCompileUnitAtIndex (uint32_t index)
285{
286 SBCompileUnit sb_cu;
287 ModuleSP module_sp (GetSP ());
288 if (module_sp)
289 {
290 CompUnitSP cu_sp = module_sp->GetCompileUnitAtIndex (index);
291 sb_cu.reset(cu_sp.get());
292 }
293 return sb_cu;
294}
295
Greg Clayton43edca32010-12-07 05:40:31 +0000296size_t
297SBModule::GetNumSymbols ()
298{
Greg Clayton49f4bf22012-02-22 19:41:02 +0000299 ModuleSP module_sp (GetSP ());
300 if (module_sp)
Greg Clayton43edca32010-12-07 05:40:31 +0000301 {
Greg Clayton49f4bf22012-02-22 19:41:02 +0000302 ObjectFile *obj_file = module_sp->GetObjectFile();
Greg Clayton43edca32010-12-07 05:40:31 +0000303 if (obj_file)
304 {
305 Symtab *symtab = obj_file->GetSymtab();
306 if (symtab)
307 return symtab->GetNumSymbols();
308 }
309 }
310 return 0;
311}
312
313SBSymbol
314SBModule::GetSymbolAtIndex (size_t idx)
315{
316 SBSymbol sb_symbol;
Greg Clayton49f4bf22012-02-22 19:41:02 +0000317 ModuleSP module_sp (GetSP ());
318 if (module_sp)
Greg Clayton43edca32010-12-07 05:40:31 +0000319 {
Greg Clayton49f4bf22012-02-22 19:41:02 +0000320 ObjectFile *obj_file = module_sp->GetObjectFile();
Greg Clayton43edca32010-12-07 05:40:31 +0000321 if (obj_file)
322 {
323 Symtab *symtab = obj_file->GetSymtab();
324 if (symtab)
325 sb_symbol.SetSymbol(symtab->SymbolAtIndex (idx));
326 }
327 }
328 return sb_symbol;
329}
Greg Clayton4ed315f2011-06-21 01:34:41 +0000330
Greg Claytonb3dafc62012-12-04 02:22:16 +0000331lldb::SBSymbol
332SBModule::FindSymbol (const char *name,
333 lldb::SymbolType symbol_type)
334{
335 SBSymbol sb_symbol;
336 if (name && name[0])
337 {
338 ModuleSP module_sp (GetSP ());
339 if (module_sp)
340 {
341 ObjectFile *obj_file = module_sp->GetObjectFile();
342 if (obj_file)
343 {
344 Symtab *symtab = obj_file->GetSymtab();
345 if (symtab)
346 sb_symbol.SetSymbol(symtab->FindFirstSymbolWithNameAndType(ConstString(name), symbol_type, Symtab::eDebugAny, Symtab::eVisibilityAny));
347 }
348 }
349 }
350 return sb_symbol;
351}
352
353
354lldb::SBSymbolContextList
355SBModule::FindSymbols (const char *name, lldb::SymbolType symbol_type)
356{
357 SBSymbolContextList sb_sc_list;
358 if (name && name[0])
359 {
360 ModuleSP module_sp (GetSP ());
361 if (module_sp)
362 {
363 ObjectFile *obj_file = module_sp->GetObjectFile();
364 if (obj_file)
365 {
366 Symtab *symtab = obj_file->GetSymtab();
367 if (symtab)
368 {
369 std::vector<uint32_t> matching_symbol_indexes;
370 const size_t num_matches = symtab->FindAllSymbolsWithNameAndType(ConstString(name), symbol_type, matching_symbol_indexes);
371 if (num_matches)
372 {
373 SymbolContext sc;
374 sc.module_sp = module_sp;
375 SymbolContextList &sc_list = *sb_sc_list;
376 for (size_t i=0; i<num_matches; ++i)
377 {
378 sc.symbol = symtab->SymbolAtIndex (matching_symbol_indexes[i]);
379 if (sc.symbol)
380 sc_list.Append(sc);
381 }
382 }
383 }
384 }
385 }
386 }
387 return sb_sc_list;
388
389}
390
391
392
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000393size_t
394SBModule::GetNumSections ()
395{
Greg Clayton49f4bf22012-02-22 19:41:02 +0000396 ModuleSP module_sp (GetSP ());
397 if (module_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000398 {
Greg Clayton49f4bf22012-02-22 19:41:02 +0000399 ObjectFile *obj_file = module_sp->GetObjectFile();
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000400 if (obj_file)
401 {
402 SectionList *section_list = obj_file->GetSectionList ();
403 if (section_list)
404 return section_list->GetSize();
405 }
406 }
407 return 0;
408}
409
410SBSection
411SBModule::GetSectionAtIndex (size_t idx)
412{
413 SBSection sb_section;
Greg Clayton49f4bf22012-02-22 19:41:02 +0000414 ModuleSP module_sp (GetSP ());
415 if (module_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000416 {
Greg Clayton49f4bf22012-02-22 19:41:02 +0000417 ObjectFile *obj_file = module_sp->GetObjectFile();
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000418 if (obj_file)
419 {
420 SectionList *section_list = obj_file->GetSectionList ();
421
422 if (section_list)
Greg Clayton3508c382012-02-24 01:59:29 +0000423 sb_section.SetSP(section_list->GetSectionAtIndex (idx));
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000424 }
425 }
426 return sb_section;
427}
428
Greg Clayton7dd5c512012-02-06 01:44:54 +0000429lldb::SBSymbolContextList
Greg Clayton4ed315f2011-06-21 01:34:41 +0000430SBModule::FindFunctions (const char *name,
Greg Clayton7dd5c512012-02-06 01:44:54 +0000431 uint32_t name_type_mask)
Greg Clayton4ed315f2011-06-21 01:34:41 +0000432{
Greg Clayton7dd5c512012-02-06 01:44:54 +0000433 lldb::SBSymbolContextList sb_sc_list;
Greg Clayton49f4bf22012-02-22 19:41:02 +0000434 ModuleSP module_sp (GetSP ());
435 if (name && module_sp)
Greg Clayton4ed315f2011-06-21 01:34:41 +0000436 {
Greg Clayton7dd5c512012-02-06 01:44:54 +0000437 const bool append = true;
Greg Clayton4ed315f2011-06-21 01:34:41 +0000438 const bool symbols_ok = true;
Sean Callanan302d78c2012-02-10 22:52:19 +0000439 const bool inlines_ok = true;
Greg Clayton49f4bf22012-02-22 19:41:02 +0000440 module_sp->FindFunctions (ConstString(name),
441 NULL,
442 name_type_mask,
443 symbols_ok,
444 inlines_ok,
445 append,
446 *sb_sc_list);
Greg Clayton4ed315f2011-06-21 01:34:41 +0000447 }
Greg Clayton7dd5c512012-02-06 01:44:54 +0000448 return sb_sc_list;
Greg Clayton4ed315f2011-06-21 01:34:41 +0000449}
450
Greg Clayton917c0002011-06-29 22:09:02 +0000451
452SBValueList
453SBModule::FindGlobalVariables (SBTarget &target, const char *name, uint32_t max_matches)
454{
455 SBValueList sb_value_list;
Greg Clayton49f4bf22012-02-22 19:41:02 +0000456 ModuleSP module_sp (GetSP ());
457 if (name && module_sp)
Greg Clayton917c0002011-06-29 22:09:02 +0000458 {
459 VariableList variable_list;
Greg Clayton49f4bf22012-02-22 19:41:02 +0000460 const uint32_t match_count = module_sp->FindGlobalVariables (ConstString (name),
461 NULL,
462 false,
463 max_matches,
464 variable_list);
Greg Clayton917c0002011-06-29 22:09:02 +0000465
466 if (match_count > 0)
467 {
468 ValueObjectList &value_object_list = sb_value_list.ref();
469 for (uint32_t i=0; i<match_count; ++i)
470 {
471 lldb::ValueObjectSP valobj_sp;
Greg Clayton334d33a2012-01-30 07:41:31 +0000472 TargetSP target_sp (target.GetSP());
473 valobj_sp = ValueObjectVariable::Create (target_sp.get(), variable_list.GetVariableAtIndex(i));
Greg Clayton917c0002011-06-29 22:09:02 +0000474 if (valobj_sp)
475 value_object_list.Append(valobj_sp);
476 }
477 }
478 }
479
480 return sb_value_list;
481}
Enrico Granata979e20d2011-07-29 19:53:35 +0000482
483lldb::SBType
Johnny Chen87b8c4c2011-12-19 20:16:22 +0000484SBModule::FindFirstType (const char *name_cstr)
Enrico Granata979e20d2011-07-29 19:53:35 +0000485{
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000486 SBType sb_type;
Greg Clayton49f4bf22012-02-22 19:41:02 +0000487 ModuleSP module_sp (GetSP ());
488 if (name_cstr && module_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +0000489 {
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000490 SymbolContext sc;
491 TypeList type_list;
492 uint32_t num_matches = 0;
Greg Claytondc0a38c2012-03-26 23:03:23 +0000493 const bool exact_match = false;
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000494 ConstString name(name_cstr);
495
Greg Clayton49f4bf22012-02-22 19:41:02 +0000496 num_matches = module_sp->FindTypes (sc,
497 name,
Greg Claytondc0a38c2012-03-26 23:03:23 +0000498 exact_match,
Greg Clayton49f4bf22012-02-22 19:41:02 +0000499 1,
500 type_list);
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000501
502 if (num_matches)
503 sb_type = lldb::SBType(type_list.GetTypeAtIndex(0));
Enrico Granata979e20d2011-07-29 19:53:35 +0000504 }
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000505 return sb_type;
Enrico Granata979e20d2011-07-29 19:53:35 +0000506}
507
508lldb::SBTypeList
Johnny Chen87b8c4c2011-12-19 20:16:22 +0000509SBModule::FindTypes (const char *type)
Enrico Granata979e20d2011-07-29 19:53:35 +0000510{
511
512 SBTypeList retval;
513
Greg Clayton49f4bf22012-02-22 19:41:02 +0000514 ModuleSP module_sp (GetSP ());
515 if (type && module_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +0000516 {
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000517 SymbolContext sc;
518 TypeList type_list;
Greg Claytondc0a38c2012-03-26 23:03:23 +0000519 const bool exact_match = false;
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000520 uint32_t num_matches = 0;
521 ConstString name(type);
Enrico Granata979e20d2011-07-29 19:53:35 +0000522
Greg Clayton49f4bf22012-02-22 19:41:02 +0000523 num_matches = module_sp->FindTypes (sc,
524 name,
Greg Claytondc0a38c2012-03-26 23:03:23 +0000525 exact_match,
Greg Clayton49f4bf22012-02-22 19:41:02 +0000526 UINT32_MAX,
527 type_list);
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000528
529 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 }
Enrico Granata979e20d2011-07-29 19:53:35 +0000535 }
536
537 return retval;
Greg Clayton153ccd72011-08-10 02:10:13 +0000538}
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000539
540
541SBSection
542SBModule::FindSection (const char *sect_name)
543{
544 SBSection sb_section;
545
Greg Clayton49f4bf22012-02-22 19:41:02 +0000546 ModuleSP module_sp (GetSP ());
547 if (sect_name && module_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000548 {
Greg Clayton49f4bf22012-02-22 19:41:02 +0000549 ObjectFile *objfile = module_sp->GetObjectFile();
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000550 if (objfile)
551 {
552 SectionList *section_list = objfile->GetSectionList();
553 if (section_list)
554 {
555 ConstString const_sect_name(sect_name);
556 SectionSP section_sp (section_list->FindSectionByName(const_sect_name));
557 if (section_sp)
558 {
Greg Clayton3508c382012-02-24 01:59:29 +0000559 sb_section.SetSP (section_sp);
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000560 }
561 }
562 }
563 }
564 return sb_section;
565}
566
Greg Clayton1b925202012-01-29 06:07:39 +0000567lldb::ByteOrder
568SBModule::GetByteOrder ()
569{
Greg Clayton49f4bf22012-02-22 19:41:02 +0000570 ModuleSP module_sp (GetSP ());
571 if (module_sp)
572 return module_sp->GetArchitecture().GetByteOrder();
Greg Clayton1b925202012-01-29 06:07:39 +0000573 return eByteOrderInvalid;
574}
575
576const char *
577SBModule::GetTriple ()
578{
Greg Clayton49f4bf22012-02-22 19:41:02 +0000579 ModuleSP module_sp (GetSP ());
580 if (module_sp)
Greg Clayton1b925202012-01-29 06:07:39 +0000581 {
Greg Clayton49f4bf22012-02-22 19:41:02 +0000582 std::string triple (module_sp->GetArchitecture().GetTriple().str());
Greg Clayton1b925202012-01-29 06:07:39 +0000583 // Unique the string so we don't run into ownership issues since
584 // the const strings put the string into the string pool once and
585 // the strings never comes out
586 ConstString const_triple (triple.c_str());
587 return const_triple.GetCString();
588 }
589 return NULL;
590}
591
592uint32_t
593SBModule::GetAddressByteSize()
594{
Greg Clayton49f4bf22012-02-22 19:41:02 +0000595 ModuleSP module_sp (GetSP ());
596 if (module_sp)
597 return module_sp->GetArchitecture().GetAddressByteSize();
Greg Clayton1b925202012-01-29 06:07:39 +0000598 return sizeof(void*);
599}
600
Greg Clayton49f4bf22012-02-22 19:41:02 +0000601
602uint32_t
603SBModule::GetVersion (uint32_t *versions, uint32_t num_versions)
604{
605 ModuleSP module_sp (GetSP ());
606 if (module_sp)
Enrico Granataae2ae942012-09-04 18:47:54 +0000607 return module_sp->GetVersion(versions, num_versions);
608 else
Greg Clayton49f4bf22012-02-22 19:41:02 +0000609 {
Enrico Granataae2ae942012-09-04 18:47:54 +0000610 if (versions && num_versions)
611 {
612 for (uint32_t i=0; i<num_versions; ++i)
613 versions[i] = UINT32_MAX;
614 }
615 return 0;
Greg Clayton49f4bf22012-02-22 19:41:02 +0000616 }
Greg Clayton49f4bf22012-02-22 19:41:02 +0000617}
618