blob: 77a7af2c62e119e9cc0e935a0dbc60d913b41c47 [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 Clayton135adf22010-10-31 19:57:43 +000018#include "lldb/Core/StreamString.h"
Greg Clayton917c0002011-06-29 22:09:02 +000019#include "lldb/Core/ValueObjectList.h"
20#include "lldb/Core/ValueObjectVariable.h"
Enrico Granata979e20d2011-07-29 19:53:35 +000021#include "lldb/Symbol/SymbolVendor.h"
Greg Clayton917c0002011-06-29 22:09:02 +000022#include "lldb/Symbol/VariableList.h"
23#include "lldb/Target/Target.h"
Chris Lattner24943d22010-06-08 16:52:24 +000024
25using namespace lldb;
Caroline Tice7826c882010-10-26 03:11:13 +000026using namespace lldb_private;
Chris Lattner24943d22010-06-08 16:52:24 +000027
28
29SBModule::SBModule () :
Greg Clayton63094e02010-06-23 01:19:29 +000030 m_opaque_sp ()
Chris Lattner24943d22010-06-08 16:52:24 +000031{
32}
33
34SBModule::SBModule (const lldb::ModuleSP& module_sp) :
Greg Clayton63094e02010-06-23 01:19:29 +000035 m_opaque_sp (module_sp)
Chris Lattner24943d22010-06-08 16:52:24 +000036{
37}
38
Greg Clayton538eb822010-11-05 23:17:00 +000039SBModule::SBModule(const SBModule &rhs) :
40 m_opaque_sp (rhs.m_opaque_sp)
41{
42}
43
Greg Claytonb5a8f142012-02-05 02:38:54 +000044SBModule::SBModule (lldb::SBProcess &process, lldb::addr_t header_addr) :
45 m_opaque_sp ()
46{
47 ProcessSP process_sp (process.GetSP());
48 if (process_sp)
Greg Clayton9ce95382012-02-13 23:10:39 +000049 {
50 const bool add_image_to_target = true;
51 const bool load_image_sections_in_target = true;
52 m_opaque_sp = process_sp->ReadModuleFromMemory (FileSpec(),
53 header_addr,
54 add_image_to_target,
55 load_image_sections_in_target);
56 }
Greg Claytonb5a8f142012-02-05 02:38:54 +000057}
58
Greg Clayton538eb822010-11-05 23:17:00 +000059const SBModule &
60SBModule::operator = (const SBModule &rhs)
61{
62 if (this != &rhs)
63 m_opaque_sp = rhs.m_opaque_sp;
64 return *this;
65}
66
Chris Lattner24943d22010-06-08 16:52:24 +000067SBModule::~SBModule ()
68{
69}
70
71bool
72SBModule::IsValid () const
73{
Greg Clayton63094e02010-06-23 01:19:29 +000074 return m_opaque_sp.get() != NULL;
Chris Lattner24943d22010-06-08 16:52:24 +000075}
76
Jim Inghame0bd5712011-12-19 20:39:44 +000077void
78SBModule::Clear()
79{
80 m_opaque_sp.reset();
81}
82
Chris Lattner24943d22010-06-08 16:52:24 +000083SBFileSpec
84SBModule::GetFileSpec () const
85{
Greg Claytone005f2c2010-11-06 01:53:30 +000086 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +000087
Chris Lattner24943d22010-06-08 16:52:24 +000088 SBFileSpec file_spec;
Greg Clayton49f4bf22012-02-22 19:41:02 +000089 ModuleSP module_sp (GetSP ());
90 if (module_sp)
91 file_spec.SetFileSpec(module_sp->GetFileSpec());
Caroline Tice7826c882010-10-26 03:11:13 +000092
93 if (log)
94 {
Greg Clayton49ce6822010-10-31 03:01:06 +000095 log->Printf ("SBModule(%p)::GetFileSpec () => SBFileSpec(%p)",
Greg Clayton49f4bf22012-02-22 19:41:02 +000096 module_sp.get(), file_spec.get());
Caroline Tice7826c882010-10-26 03:11:13 +000097 }
98
Chris Lattner24943d22010-06-08 16:52:24 +000099 return file_spec;
100}
101
Greg Clayton180546b2011-04-30 01:09:13 +0000102lldb::SBFileSpec
103SBModule::GetPlatformFileSpec () const
104{
105 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
106
107 SBFileSpec file_spec;
Greg Clayton49f4bf22012-02-22 19:41:02 +0000108 ModuleSP module_sp (GetSP ());
109 if (module_sp)
110 file_spec.SetFileSpec(module_sp->GetPlatformFileSpec());
Greg Clayton180546b2011-04-30 01:09:13 +0000111
112 if (log)
113 {
114 log->Printf ("SBModule(%p)::GetPlatformFileSpec () => SBFileSpec(%p)",
Greg Clayton49f4bf22012-02-22 19:41:02 +0000115 module_sp.get(), file_spec.get());
Greg Clayton180546b2011-04-30 01:09:13 +0000116 }
117
118 return file_spec;
119
120}
121
122bool
123SBModule::SetPlatformFileSpec (const lldb::SBFileSpec &platform_file)
124{
125 bool result = false;
126 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
127
Greg Clayton49f4bf22012-02-22 19:41:02 +0000128 ModuleSP module_sp (GetSP ());
129 if (module_sp)
Greg Clayton180546b2011-04-30 01:09:13 +0000130 {
Greg Clayton49f4bf22012-02-22 19:41:02 +0000131 module_sp->SetPlatformFileSpec(*platform_file);
Greg Clayton180546b2011-04-30 01:09:13 +0000132 result = true;
133 }
134
135 if (log)
136 {
137 log->Printf ("SBModule(%p)::SetPlatformFileSpec (SBFileSpec(%p (%s%s%s)) => %i",
Greg Clayton49f4bf22012-02-22 19:41:02 +0000138 module_sp.get(),
Greg Clayton180546b2011-04-30 01:09:13 +0000139 platform_file.get(),
140 platform_file->GetDirectory().GetCString(),
141 platform_file->GetDirectory() ? "/" : "",
142 platform_file->GetFilename().GetCString(),
143 result);
144 }
145 return result;
146}
147
148
149
Chris Lattner24943d22010-06-08 16:52:24 +0000150const uint8_t *
151SBModule::GetUUIDBytes () const
152{
Greg Claytone005f2c2010-11-06 01:53:30 +0000153 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000154
Greg Claytona66ba462010-10-30 04:51:46 +0000155 const uint8_t *uuid_bytes = NULL;
Greg Clayton49f4bf22012-02-22 19:41:02 +0000156 ModuleSP module_sp (GetSP ());
157 if (module_sp)
158 uuid_bytes = (const uint8_t *)module_sp->GetUUID().GetBytes();
Caroline Tice7826c882010-10-26 03:11:13 +0000159
160 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000161 {
162 if (uuid_bytes)
163 {
164 StreamString s;
Greg Clayton49f4bf22012-02-22 19:41:02 +0000165 module_sp->GetUUID().Dump (&s);
166 log->Printf ("SBModule(%p)::GetUUIDBytes () => %s", module_sp.get(), s.GetData());
Greg Claytona66ba462010-10-30 04:51:46 +0000167 }
168 else
Greg Clayton49f4bf22012-02-22 19:41:02 +0000169 log->Printf ("SBModule(%p)::GetUUIDBytes () => NULL", module_sp.get());
Greg Claytona66ba462010-10-30 04:51:46 +0000170 }
171 return uuid_bytes;
Chris Lattner24943d22010-06-08 16:52:24 +0000172}
173
174
Johnny Chen919ee602011-04-01 00:35:55 +0000175const char *
176SBModule::GetUUIDString () const
177{
178 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
179
180 static char uuid_string[80];
181 const char * uuid_c_string = NULL;
Greg Clayton49f4bf22012-02-22 19:41:02 +0000182 ModuleSP module_sp (GetSP ());
183 if (module_sp)
184 uuid_c_string = (const char *)module_sp->GetUUID().GetAsCString(uuid_string, sizeof(uuid_string));
Johnny Chen919ee602011-04-01 00:35:55 +0000185
186 if (log)
187 {
188 if (uuid_c_string)
189 {
190 StreamString s;
Greg Clayton49f4bf22012-02-22 19:41:02 +0000191 module_sp->GetUUID().Dump (&s);
192 log->Printf ("SBModule(%p)::GetUUIDString () => %s", module_sp.get(), s.GetData());
Johnny Chen919ee602011-04-01 00:35:55 +0000193 }
194 else
Greg Clayton49f4bf22012-02-22 19:41:02 +0000195 log->Printf ("SBModule(%p)::GetUUIDString () => NULL", module_sp.get());
Johnny Chen919ee602011-04-01 00:35:55 +0000196 }
197 return uuid_c_string;
198}
199
200
Chris Lattner24943d22010-06-08 16:52:24 +0000201bool
202SBModule::operator == (const SBModule &rhs) const
203{
Greg Clayton63094e02010-06-23 01:19:29 +0000204 if (m_opaque_sp)
205 return m_opaque_sp.get() == rhs.m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000206 return false;
207}
208
209bool
210SBModule::operator != (const SBModule &rhs) const
211{
Greg Clayton63094e02010-06-23 01:19:29 +0000212 if (m_opaque_sp)
213 return m_opaque_sp.get() != rhs.m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000214 return false;
215}
216
Greg Clayton0416bdf2012-01-30 09:04:36 +0000217ModuleSP
218SBModule::GetSP () const
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000219{
220 return m_opaque_sp;
221}
Chris Lattner24943d22010-06-08 16:52:24 +0000222
223void
Greg Clayton0416bdf2012-01-30 09:04:36 +0000224SBModule::SetSP (const ModuleSP &module_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000225{
Greg Clayton63094e02010-06-23 01:19:29 +0000226 m_opaque_sp = module_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000227}
228
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000229SBAddress
230SBModule::ResolveFileAddress (lldb::addr_t vm_addr)
Greg Clayton466f6c42010-09-10 18:31:35 +0000231{
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000232 lldb::SBAddress sb_addr;
Greg Clayton49f4bf22012-02-22 19:41:02 +0000233 ModuleSP module_sp (GetSP ());
234 if (module_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000235 {
236 Address addr;
Greg Clayton49f4bf22012-02-22 19:41:02 +0000237 if (module_sp->ResolveFileAddress (vm_addr, addr))
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000238 sb_addr.ref() = addr;
239 }
240 return sb_addr;
Greg Clayton466f6c42010-09-10 18:31:35 +0000241}
242
243SBSymbolContext
244SBModule::ResolveSymbolContextForAddress (const SBAddress& addr, uint32_t resolve_scope)
245{
246 SBSymbolContext sb_sc;
Greg Clayton49f4bf22012-02-22 19:41:02 +0000247 ModuleSP module_sp (GetSP ());
248 if (module_sp && addr.IsValid())
249 module_sp->ResolveSymbolContextForAddress (addr.ref(), resolve_scope, *sb_sc);
Greg Clayton466f6c42010-09-10 18:31:35 +0000250 return sb_sc;
251}
252
Caroline Tice98f930f2010-09-20 05:20:02 +0000253bool
254SBModule::GetDescription (SBStream &description)
255{
Greg Clayton96154be2011-11-13 06:57:31 +0000256 Stream &strm = description.ref();
257
Greg Clayton49f4bf22012-02-22 19:41:02 +0000258 ModuleSP module_sp (GetSP ());
259 if (module_sp)
Caroline Tice98f930f2010-09-20 05:20:02 +0000260 {
Greg Clayton49f4bf22012-02-22 19:41:02 +0000261 module_sp->GetDescription (&strm);
Caroline Tice98f930f2010-09-20 05:20:02 +0000262 }
263 else
Greg Clayton96154be2011-11-13 06:57:31 +0000264 strm.PutCString ("No value");
Caroline Tice98f930f2010-09-20 05:20:02 +0000265
266 return true;
267}
Greg Clayton43edca32010-12-07 05:40:31 +0000268
269size_t
270SBModule::GetNumSymbols ()
271{
Greg Clayton49f4bf22012-02-22 19:41:02 +0000272 ModuleSP module_sp (GetSP ());
273 if (module_sp)
Greg Clayton43edca32010-12-07 05:40:31 +0000274 {
Greg Clayton49f4bf22012-02-22 19:41:02 +0000275 ObjectFile *obj_file = module_sp->GetObjectFile();
Greg Clayton43edca32010-12-07 05:40:31 +0000276 if (obj_file)
277 {
278 Symtab *symtab = obj_file->GetSymtab();
279 if (symtab)
280 return symtab->GetNumSymbols();
281 }
282 }
283 return 0;
284}
285
286SBSymbol
287SBModule::GetSymbolAtIndex (size_t idx)
288{
289 SBSymbol sb_symbol;
Greg Clayton49f4bf22012-02-22 19:41:02 +0000290 ModuleSP module_sp (GetSP ());
291 if (module_sp)
Greg Clayton43edca32010-12-07 05:40:31 +0000292 {
Greg Clayton49f4bf22012-02-22 19:41:02 +0000293 ObjectFile *obj_file = module_sp->GetObjectFile();
Greg Clayton43edca32010-12-07 05:40:31 +0000294 if (obj_file)
295 {
296 Symtab *symtab = obj_file->GetSymtab();
297 if (symtab)
298 sb_symbol.SetSymbol(symtab->SymbolAtIndex (idx));
299 }
300 }
301 return sb_symbol;
302}
Greg Clayton4ed315f2011-06-21 01:34:41 +0000303
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000304size_t
305SBModule::GetNumSections ()
306{
Greg Clayton49f4bf22012-02-22 19:41:02 +0000307 ModuleSP module_sp (GetSP ());
308 if (module_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000309 {
Greg Clayton49f4bf22012-02-22 19:41:02 +0000310 ObjectFile *obj_file = module_sp->GetObjectFile();
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000311 if (obj_file)
312 {
313 SectionList *section_list = obj_file->GetSectionList ();
314 if (section_list)
315 return section_list->GetSize();
316 }
317 }
318 return 0;
319}
320
321SBSection
322SBModule::GetSectionAtIndex (size_t idx)
323{
324 SBSection sb_section;
Greg Clayton49f4bf22012-02-22 19:41:02 +0000325 ModuleSP module_sp (GetSP ());
326 if (module_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000327 {
Greg Clayton49f4bf22012-02-22 19:41:02 +0000328 ObjectFile *obj_file = module_sp->GetObjectFile();
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000329 if (obj_file)
330 {
331 SectionList *section_list = obj_file->GetSectionList ();
332
333 if (section_list)
334 sb_section.SetSection(section_list->GetSectionAtIndex (idx).get());
335 }
336 }
337 return sb_section;
338}
339
Greg Clayton7dd5c512012-02-06 01:44:54 +0000340lldb::SBSymbolContextList
Greg Clayton4ed315f2011-06-21 01:34:41 +0000341SBModule::FindFunctions (const char *name,
Greg Clayton7dd5c512012-02-06 01:44:54 +0000342 uint32_t name_type_mask)
Greg Clayton4ed315f2011-06-21 01:34:41 +0000343{
Greg Clayton7dd5c512012-02-06 01:44:54 +0000344 lldb::SBSymbolContextList sb_sc_list;
Greg Clayton49f4bf22012-02-22 19:41:02 +0000345 ModuleSP module_sp (GetSP ());
346 if (name && module_sp)
Greg Clayton4ed315f2011-06-21 01:34:41 +0000347 {
Greg Clayton7dd5c512012-02-06 01:44:54 +0000348 const bool append = true;
Greg Clayton4ed315f2011-06-21 01:34:41 +0000349 const bool symbols_ok = true;
Sean Callanan302d78c2012-02-10 22:52:19 +0000350 const bool inlines_ok = true;
Greg Clayton49f4bf22012-02-22 19:41:02 +0000351 module_sp->FindFunctions (ConstString(name),
352 NULL,
353 name_type_mask,
354 symbols_ok,
355 inlines_ok,
356 append,
357 *sb_sc_list);
Greg Clayton4ed315f2011-06-21 01:34:41 +0000358 }
Greg Clayton7dd5c512012-02-06 01:44:54 +0000359 return sb_sc_list;
Greg Clayton4ed315f2011-06-21 01:34:41 +0000360}
361
Greg Clayton917c0002011-06-29 22:09:02 +0000362
363SBValueList
364SBModule::FindGlobalVariables (SBTarget &target, const char *name, uint32_t max_matches)
365{
366 SBValueList sb_value_list;
Greg Clayton49f4bf22012-02-22 19:41:02 +0000367 ModuleSP module_sp (GetSP ());
368 if (name && module_sp)
Greg Clayton917c0002011-06-29 22:09:02 +0000369 {
370 VariableList variable_list;
Greg Clayton49f4bf22012-02-22 19:41:02 +0000371 const uint32_t match_count = module_sp->FindGlobalVariables (ConstString (name),
372 NULL,
373 false,
374 max_matches,
375 variable_list);
Greg Clayton917c0002011-06-29 22:09:02 +0000376
377 if (match_count > 0)
378 {
379 ValueObjectList &value_object_list = sb_value_list.ref();
380 for (uint32_t i=0; i<match_count; ++i)
381 {
382 lldb::ValueObjectSP valobj_sp;
Greg Clayton334d33a2012-01-30 07:41:31 +0000383 TargetSP target_sp (target.GetSP());
384 valobj_sp = ValueObjectVariable::Create (target_sp.get(), variable_list.GetVariableAtIndex(i));
Greg Clayton917c0002011-06-29 22:09:02 +0000385 if (valobj_sp)
386 value_object_list.Append(valobj_sp);
387 }
388 }
389 }
390
391 return sb_value_list;
392}
Enrico Granata979e20d2011-07-29 19:53:35 +0000393
394lldb::SBType
Johnny Chen87b8c4c2011-12-19 20:16:22 +0000395SBModule::FindFirstType (const char *name_cstr)
Enrico Granata979e20d2011-07-29 19:53:35 +0000396{
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000397 SBType sb_type;
Greg Clayton49f4bf22012-02-22 19:41:02 +0000398 ModuleSP module_sp (GetSP ());
399 if (name_cstr && module_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +0000400 {
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000401 SymbolContext sc;
402 TypeList type_list;
403 uint32_t num_matches = 0;
404 ConstString name(name_cstr);
405
Greg Clayton49f4bf22012-02-22 19:41:02 +0000406 num_matches = module_sp->FindTypes (sc,
407 name,
408 NULL,
409 false,
410 1,
411 type_list);
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000412
413 if (num_matches)
414 sb_type = lldb::SBType(type_list.GetTypeAtIndex(0));
Enrico Granata979e20d2011-07-29 19:53:35 +0000415 }
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000416 return sb_type;
Enrico Granata979e20d2011-07-29 19:53:35 +0000417}
418
419lldb::SBTypeList
Johnny Chen87b8c4c2011-12-19 20:16:22 +0000420SBModule::FindTypes (const char *type)
Enrico Granata979e20d2011-07-29 19:53:35 +0000421{
422
423 SBTypeList retval;
424
Greg Clayton49f4bf22012-02-22 19:41:02 +0000425 ModuleSP module_sp (GetSP ());
426 if (type && 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;
431 ConstString name(type);
Enrico Granata979e20d2011-07-29 19:53:35 +0000432
Greg Clayton49f4bf22012-02-22 19:41:02 +0000433 num_matches = module_sp->FindTypes (sc,
434 name,
435 NULL,
436 false,
437 UINT32_MAX,
438 type_list);
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000439
440 for (size_t idx = 0; idx < num_matches; idx++)
441 {
442 TypeSP type_sp (type_list.GetTypeAtIndex(idx));
443 if (type_sp)
444 retval.Append(SBType(type_sp));
445 }
Enrico Granata979e20d2011-07-29 19:53:35 +0000446 }
447
448 return retval;
Greg Clayton153ccd72011-08-10 02:10:13 +0000449}
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000450
451
452SBSection
453SBModule::FindSection (const char *sect_name)
454{
455 SBSection sb_section;
456
Greg Clayton49f4bf22012-02-22 19:41:02 +0000457 ModuleSP module_sp (GetSP ());
458 if (sect_name && module_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000459 {
Greg Clayton49f4bf22012-02-22 19:41:02 +0000460 ObjectFile *objfile = module_sp->GetObjectFile();
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000461 if (objfile)
462 {
463 SectionList *section_list = objfile->GetSectionList();
464 if (section_list)
465 {
466 ConstString const_sect_name(sect_name);
467 SectionSP section_sp (section_list->FindSectionByName(const_sect_name));
468 if (section_sp)
469 {
470 sb_section.SetSection(section_sp.get());
471 }
472 }
473 }
474 }
475 return sb_section;
476}
477
Greg Clayton1b925202012-01-29 06:07:39 +0000478lldb::ByteOrder
479SBModule::GetByteOrder ()
480{
Greg Clayton49f4bf22012-02-22 19:41:02 +0000481 ModuleSP module_sp (GetSP ());
482 if (module_sp)
483 return module_sp->GetArchitecture().GetByteOrder();
Greg Clayton1b925202012-01-29 06:07:39 +0000484 return eByteOrderInvalid;
485}
486
487const char *
488SBModule::GetTriple ()
489{
Greg Clayton49f4bf22012-02-22 19:41:02 +0000490 ModuleSP module_sp (GetSP ());
491 if (module_sp)
Greg Clayton1b925202012-01-29 06:07:39 +0000492 {
Greg Clayton49f4bf22012-02-22 19:41:02 +0000493 std::string triple (module_sp->GetArchitecture().GetTriple().str());
Greg Clayton1b925202012-01-29 06:07:39 +0000494 // Unique the string so we don't run into ownership issues since
495 // the const strings put the string into the string pool once and
496 // the strings never comes out
497 ConstString const_triple (triple.c_str());
498 return const_triple.GetCString();
499 }
500 return NULL;
501}
502
503uint32_t
504SBModule::GetAddressByteSize()
505{
Greg Clayton49f4bf22012-02-22 19:41:02 +0000506 ModuleSP module_sp (GetSP ());
507 if (module_sp)
508 return module_sp->GetArchitecture().GetAddressByteSize();
Greg Clayton1b925202012-01-29 06:07:39 +0000509 return sizeof(void*);
510}
511
Greg Clayton49f4bf22012-02-22 19:41:02 +0000512
513uint32_t
514SBModule::GetVersion (uint32_t *versions, uint32_t num_versions)
515{
516 ModuleSP module_sp (GetSP ());
517 if (module_sp)
518 {
519 ObjectFile *obj_file = module_sp->GetObjectFile();
520 if (obj_file)
521 return obj_file->GetVersion (versions, num_versions);
522 }
523
524 if (versions && num_versions)
525 {
526 for (uint32_t i=0; i<num_versions; ++i)
527 versions[i] = UINT32_MAX;
528 }
529 return 0;
530}
531