blob: 446a69331d99bc00f6afd28ab2a9fc04a245c413 [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 Clayton3e8c25f2011-09-24 00:52:29 +0000331size_t
332SBModule::GetNumSections ()
333{
Greg Clayton49f4bf22012-02-22 19:41:02 +0000334 ModuleSP module_sp (GetSP ());
335 if (module_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000336 {
Greg Clayton49f4bf22012-02-22 19:41:02 +0000337 ObjectFile *obj_file = module_sp->GetObjectFile();
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000338 if (obj_file)
339 {
340 SectionList *section_list = obj_file->GetSectionList ();
341 if (section_list)
342 return section_list->GetSize();
343 }
344 }
345 return 0;
346}
347
348SBSection
349SBModule::GetSectionAtIndex (size_t idx)
350{
351 SBSection sb_section;
Greg Clayton49f4bf22012-02-22 19:41:02 +0000352 ModuleSP module_sp (GetSP ());
353 if (module_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000354 {
Greg Clayton49f4bf22012-02-22 19:41:02 +0000355 ObjectFile *obj_file = module_sp->GetObjectFile();
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000356 if (obj_file)
357 {
358 SectionList *section_list = obj_file->GetSectionList ();
359
360 if (section_list)
Greg Clayton3508c382012-02-24 01:59:29 +0000361 sb_section.SetSP(section_list->GetSectionAtIndex (idx));
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000362 }
363 }
364 return sb_section;
365}
366
Greg Clayton7dd5c512012-02-06 01:44:54 +0000367lldb::SBSymbolContextList
Greg Clayton4ed315f2011-06-21 01:34:41 +0000368SBModule::FindFunctions (const char *name,
Greg Clayton7dd5c512012-02-06 01:44:54 +0000369 uint32_t name_type_mask)
Greg Clayton4ed315f2011-06-21 01:34:41 +0000370{
Greg Clayton7dd5c512012-02-06 01:44:54 +0000371 lldb::SBSymbolContextList sb_sc_list;
Greg Clayton49f4bf22012-02-22 19:41:02 +0000372 ModuleSP module_sp (GetSP ());
373 if (name && module_sp)
Greg Clayton4ed315f2011-06-21 01:34:41 +0000374 {
Greg Clayton7dd5c512012-02-06 01:44:54 +0000375 const bool append = true;
Greg Clayton4ed315f2011-06-21 01:34:41 +0000376 const bool symbols_ok = true;
Sean Callanan302d78c2012-02-10 22:52:19 +0000377 const bool inlines_ok = true;
Greg Clayton49f4bf22012-02-22 19:41:02 +0000378 module_sp->FindFunctions (ConstString(name),
379 NULL,
380 name_type_mask,
381 symbols_ok,
382 inlines_ok,
383 append,
384 *sb_sc_list);
Greg Clayton4ed315f2011-06-21 01:34:41 +0000385 }
Greg Clayton7dd5c512012-02-06 01:44:54 +0000386 return sb_sc_list;
Greg Clayton4ed315f2011-06-21 01:34:41 +0000387}
388
Greg Clayton917c0002011-06-29 22:09:02 +0000389
390SBValueList
391SBModule::FindGlobalVariables (SBTarget &target, const char *name, uint32_t max_matches)
392{
393 SBValueList sb_value_list;
Greg Clayton49f4bf22012-02-22 19:41:02 +0000394 ModuleSP module_sp (GetSP ());
395 if (name && module_sp)
Greg Clayton917c0002011-06-29 22:09:02 +0000396 {
397 VariableList variable_list;
Greg Clayton49f4bf22012-02-22 19:41:02 +0000398 const uint32_t match_count = module_sp->FindGlobalVariables (ConstString (name),
399 NULL,
400 false,
401 max_matches,
402 variable_list);
Greg Clayton917c0002011-06-29 22:09:02 +0000403
404 if (match_count > 0)
405 {
406 ValueObjectList &value_object_list = sb_value_list.ref();
407 for (uint32_t i=0; i<match_count; ++i)
408 {
409 lldb::ValueObjectSP valobj_sp;
Greg Clayton334d33a2012-01-30 07:41:31 +0000410 TargetSP target_sp (target.GetSP());
411 valobj_sp = ValueObjectVariable::Create (target_sp.get(), variable_list.GetVariableAtIndex(i));
Greg Clayton917c0002011-06-29 22:09:02 +0000412 if (valobj_sp)
413 value_object_list.Append(valobj_sp);
414 }
415 }
416 }
417
418 return sb_value_list;
419}
Enrico Granata979e20d2011-07-29 19:53:35 +0000420
421lldb::SBType
Johnny Chen87b8c4c2011-12-19 20:16:22 +0000422SBModule::FindFirstType (const char *name_cstr)
Enrico Granata979e20d2011-07-29 19:53:35 +0000423{
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000424 SBType sb_type;
Greg Clayton49f4bf22012-02-22 19:41:02 +0000425 ModuleSP module_sp (GetSP ());
426 if (name_cstr && module_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +0000427 {
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000428 SymbolContext sc;
429 TypeList type_list;
430 uint32_t num_matches = 0;
Greg Claytondc0a38c2012-03-26 23:03:23 +0000431 const bool exact_match = false;
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000432 ConstString name(name_cstr);
433
Greg Clayton49f4bf22012-02-22 19:41:02 +0000434 num_matches = module_sp->FindTypes (sc,
435 name,
Greg Claytondc0a38c2012-03-26 23:03:23 +0000436 exact_match,
Greg Clayton49f4bf22012-02-22 19:41:02 +0000437 1,
438 type_list);
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000439
440 if (num_matches)
441 sb_type = lldb::SBType(type_list.GetTypeAtIndex(0));
Enrico Granata979e20d2011-07-29 19:53:35 +0000442 }
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000443 return sb_type;
Enrico Granata979e20d2011-07-29 19:53:35 +0000444}
445
446lldb::SBTypeList
Johnny Chen87b8c4c2011-12-19 20:16:22 +0000447SBModule::FindTypes (const char *type)
Enrico Granata979e20d2011-07-29 19:53:35 +0000448{
449
450 SBTypeList retval;
451
Greg Clayton49f4bf22012-02-22 19:41:02 +0000452 ModuleSP module_sp (GetSP ());
453 if (type && module_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +0000454 {
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000455 SymbolContext sc;
456 TypeList type_list;
Greg Claytondc0a38c2012-03-26 23:03:23 +0000457 const bool exact_match = false;
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000458 uint32_t num_matches = 0;
459 ConstString name(type);
Enrico Granata979e20d2011-07-29 19:53:35 +0000460
Greg Clayton49f4bf22012-02-22 19:41:02 +0000461 num_matches = module_sp->FindTypes (sc,
462 name,
Greg Claytondc0a38c2012-03-26 23:03:23 +0000463 exact_match,
Greg Clayton49f4bf22012-02-22 19:41:02 +0000464 UINT32_MAX,
465 type_list);
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000466
467 for (size_t idx = 0; idx < num_matches; idx++)
468 {
469 TypeSP type_sp (type_list.GetTypeAtIndex(idx));
470 if (type_sp)
471 retval.Append(SBType(type_sp));
472 }
Enrico Granata979e20d2011-07-29 19:53:35 +0000473 }
474
475 return retval;
Greg Clayton153ccd72011-08-10 02:10:13 +0000476}
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000477
478
479SBSection
480SBModule::FindSection (const char *sect_name)
481{
482 SBSection sb_section;
483
Greg Clayton49f4bf22012-02-22 19:41:02 +0000484 ModuleSP module_sp (GetSP ());
485 if (sect_name && module_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000486 {
Greg Clayton49f4bf22012-02-22 19:41:02 +0000487 ObjectFile *objfile = module_sp->GetObjectFile();
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000488 if (objfile)
489 {
490 SectionList *section_list = objfile->GetSectionList();
491 if (section_list)
492 {
493 ConstString const_sect_name(sect_name);
494 SectionSP section_sp (section_list->FindSectionByName(const_sect_name));
495 if (section_sp)
496 {
Greg Clayton3508c382012-02-24 01:59:29 +0000497 sb_section.SetSP (section_sp);
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000498 }
499 }
500 }
501 }
502 return sb_section;
503}
504
Greg Clayton1b925202012-01-29 06:07:39 +0000505lldb::ByteOrder
506SBModule::GetByteOrder ()
507{
Greg Clayton49f4bf22012-02-22 19:41:02 +0000508 ModuleSP module_sp (GetSP ());
509 if (module_sp)
510 return module_sp->GetArchitecture().GetByteOrder();
Greg Clayton1b925202012-01-29 06:07:39 +0000511 return eByteOrderInvalid;
512}
513
514const char *
515SBModule::GetTriple ()
516{
Greg Clayton49f4bf22012-02-22 19:41:02 +0000517 ModuleSP module_sp (GetSP ());
518 if (module_sp)
Greg Clayton1b925202012-01-29 06:07:39 +0000519 {
Greg Clayton49f4bf22012-02-22 19:41:02 +0000520 std::string triple (module_sp->GetArchitecture().GetTriple().str());
Greg Clayton1b925202012-01-29 06:07:39 +0000521 // Unique the string so we don't run into ownership issues since
522 // the const strings put the string into the string pool once and
523 // the strings never comes out
524 ConstString const_triple (triple.c_str());
525 return const_triple.GetCString();
526 }
527 return NULL;
528}
529
530uint32_t
531SBModule::GetAddressByteSize()
532{
Greg Clayton49f4bf22012-02-22 19:41:02 +0000533 ModuleSP module_sp (GetSP ());
534 if (module_sp)
535 return module_sp->GetArchitecture().GetAddressByteSize();
Greg Clayton1b925202012-01-29 06:07:39 +0000536 return sizeof(void*);
537}
538
Greg Clayton49f4bf22012-02-22 19:41:02 +0000539
540uint32_t
541SBModule::GetVersion (uint32_t *versions, uint32_t num_versions)
542{
543 ModuleSP module_sp (GetSP ());
544 if (module_sp)
Enrico Granataae2ae942012-09-04 18:47:54 +0000545 return module_sp->GetVersion(versions, num_versions);
546 else
Greg Clayton49f4bf22012-02-22 19:41:02 +0000547 {
Enrico Granataae2ae942012-09-04 18:47:54 +0000548 if (versions && num_versions)
549 {
550 for (uint32_t i=0; i<num_versions; ++i)
551 versions[i] = UINT32_MAX;
552 }
553 return 0;
Greg Clayton49f4bf22012-02-22 19:41:02 +0000554 }
Greg Clayton49f4bf22012-02-22 19:41:02 +0000555}
556