blob: 463669fe22c11ba41a372b0e8a35dadcd2e9582e [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
Johnny Chenb451f5f2012-03-16 20:46:10 +0000269uint32_t
270SBModule::GetNumCompileUnits()
271{
272 ModuleSP module_sp (GetSP ());
273 if (module_sp)
274 {
275 return module_sp->GetNumCompileUnits ();
276 }
277 return 0;
278}
279
280SBCompileUnit
281SBModule::GetCompileUnitAtIndex (uint32_t index)
282{
283 SBCompileUnit sb_cu;
284 ModuleSP module_sp (GetSP ());
285 if (module_sp)
286 {
287 CompUnitSP cu_sp = module_sp->GetCompileUnitAtIndex (index);
288 sb_cu.reset(cu_sp.get());
289 }
290 return sb_cu;
291}
292
Greg Clayton43edca32010-12-07 05:40:31 +0000293size_t
294SBModule::GetNumSymbols ()
295{
Greg Clayton49f4bf22012-02-22 19:41:02 +0000296 ModuleSP module_sp (GetSP ());
297 if (module_sp)
Greg Clayton43edca32010-12-07 05:40:31 +0000298 {
Greg Clayton49f4bf22012-02-22 19:41:02 +0000299 ObjectFile *obj_file = module_sp->GetObjectFile();
Greg Clayton43edca32010-12-07 05:40:31 +0000300 if (obj_file)
301 {
302 Symtab *symtab = obj_file->GetSymtab();
303 if (symtab)
304 return symtab->GetNumSymbols();
305 }
306 }
307 return 0;
308}
309
310SBSymbol
311SBModule::GetSymbolAtIndex (size_t idx)
312{
313 SBSymbol sb_symbol;
Greg Clayton49f4bf22012-02-22 19:41:02 +0000314 ModuleSP module_sp (GetSP ());
315 if (module_sp)
Greg Clayton43edca32010-12-07 05:40:31 +0000316 {
Greg Clayton49f4bf22012-02-22 19:41:02 +0000317 ObjectFile *obj_file = module_sp->GetObjectFile();
Greg Clayton43edca32010-12-07 05:40:31 +0000318 if (obj_file)
319 {
320 Symtab *symtab = obj_file->GetSymtab();
321 if (symtab)
322 sb_symbol.SetSymbol(symtab->SymbolAtIndex (idx));
323 }
324 }
325 return sb_symbol;
326}
Greg Clayton4ed315f2011-06-21 01:34:41 +0000327
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000328size_t
329SBModule::GetNumSections ()
330{
Greg Clayton49f4bf22012-02-22 19:41:02 +0000331 ModuleSP module_sp (GetSP ());
332 if (module_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000333 {
Greg Clayton49f4bf22012-02-22 19:41:02 +0000334 ObjectFile *obj_file = module_sp->GetObjectFile();
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000335 if (obj_file)
336 {
337 SectionList *section_list = obj_file->GetSectionList ();
338 if (section_list)
339 return section_list->GetSize();
340 }
341 }
342 return 0;
343}
344
345SBSection
346SBModule::GetSectionAtIndex (size_t idx)
347{
348 SBSection sb_section;
Greg Clayton49f4bf22012-02-22 19:41:02 +0000349 ModuleSP module_sp (GetSP ());
350 if (module_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000351 {
Greg Clayton49f4bf22012-02-22 19:41:02 +0000352 ObjectFile *obj_file = module_sp->GetObjectFile();
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000353 if (obj_file)
354 {
355 SectionList *section_list = obj_file->GetSectionList ();
356
357 if (section_list)
Greg Clayton3508c382012-02-24 01:59:29 +0000358 sb_section.SetSP(section_list->GetSectionAtIndex (idx));
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000359 }
360 }
361 return sb_section;
362}
363
Greg Clayton7dd5c512012-02-06 01:44:54 +0000364lldb::SBSymbolContextList
Greg Clayton4ed315f2011-06-21 01:34:41 +0000365SBModule::FindFunctions (const char *name,
Greg Clayton7dd5c512012-02-06 01:44:54 +0000366 uint32_t name_type_mask)
Greg Clayton4ed315f2011-06-21 01:34:41 +0000367{
Greg Clayton7dd5c512012-02-06 01:44:54 +0000368 lldb::SBSymbolContextList sb_sc_list;
Greg Clayton49f4bf22012-02-22 19:41:02 +0000369 ModuleSP module_sp (GetSP ());
370 if (name && module_sp)
Greg Clayton4ed315f2011-06-21 01:34:41 +0000371 {
Greg Clayton7dd5c512012-02-06 01:44:54 +0000372 const bool append = true;
Greg Clayton4ed315f2011-06-21 01:34:41 +0000373 const bool symbols_ok = true;
Sean Callanan302d78c2012-02-10 22:52:19 +0000374 const bool inlines_ok = true;
Greg Clayton49f4bf22012-02-22 19:41:02 +0000375 module_sp->FindFunctions (ConstString(name),
376 NULL,
377 name_type_mask,
378 symbols_ok,
379 inlines_ok,
380 append,
381 *sb_sc_list);
Greg Clayton4ed315f2011-06-21 01:34:41 +0000382 }
Greg Clayton7dd5c512012-02-06 01:44:54 +0000383 return sb_sc_list;
Greg Clayton4ed315f2011-06-21 01:34:41 +0000384}
385
Greg Clayton917c0002011-06-29 22:09:02 +0000386
387SBValueList
388SBModule::FindGlobalVariables (SBTarget &target, const char *name, uint32_t max_matches)
389{
390 SBValueList sb_value_list;
Greg Clayton49f4bf22012-02-22 19:41:02 +0000391 ModuleSP module_sp (GetSP ());
392 if (name && module_sp)
Greg Clayton917c0002011-06-29 22:09:02 +0000393 {
394 VariableList variable_list;
Greg Clayton49f4bf22012-02-22 19:41:02 +0000395 const uint32_t match_count = module_sp->FindGlobalVariables (ConstString (name),
396 NULL,
397 false,
398 max_matches,
399 variable_list);
Greg Clayton917c0002011-06-29 22:09:02 +0000400
401 if (match_count > 0)
402 {
403 ValueObjectList &value_object_list = sb_value_list.ref();
404 for (uint32_t i=0; i<match_count; ++i)
405 {
406 lldb::ValueObjectSP valobj_sp;
Greg Clayton334d33a2012-01-30 07:41:31 +0000407 TargetSP target_sp (target.GetSP());
408 valobj_sp = ValueObjectVariable::Create (target_sp.get(), variable_list.GetVariableAtIndex(i));
Greg Clayton917c0002011-06-29 22:09:02 +0000409 if (valobj_sp)
410 value_object_list.Append(valobj_sp);
411 }
412 }
413 }
414
415 return sb_value_list;
416}
Enrico Granata979e20d2011-07-29 19:53:35 +0000417
418lldb::SBType
Johnny Chen87b8c4c2011-12-19 20:16:22 +0000419SBModule::FindFirstType (const char *name_cstr)
Enrico Granata979e20d2011-07-29 19:53:35 +0000420{
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000421 SBType sb_type;
Greg Clayton49f4bf22012-02-22 19:41:02 +0000422 ModuleSP module_sp (GetSP ());
423 if (name_cstr && module_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +0000424 {
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000425 SymbolContext sc;
426 TypeList type_list;
427 uint32_t num_matches = 0;
Greg Claytondc0a38c2012-03-26 23:03:23 +0000428 const bool exact_match = false;
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000429 ConstString name(name_cstr);
430
Greg Clayton49f4bf22012-02-22 19:41:02 +0000431 num_matches = module_sp->FindTypes (sc,
432 name,
Greg Claytondc0a38c2012-03-26 23:03:23 +0000433 exact_match,
Greg Clayton49f4bf22012-02-22 19:41:02 +0000434 1,
435 type_list);
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000436
437 if (num_matches)
438 sb_type = lldb::SBType(type_list.GetTypeAtIndex(0));
Enrico Granata979e20d2011-07-29 19:53:35 +0000439 }
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000440 return sb_type;
Enrico Granata979e20d2011-07-29 19:53:35 +0000441}
442
443lldb::SBTypeList
Johnny Chen87b8c4c2011-12-19 20:16:22 +0000444SBModule::FindTypes (const char *type)
Enrico Granata979e20d2011-07-29 19:53:35 +0000445{
446
447 SBTypeList retval;
448
Greg Clayton49f4bf22012-02-22 19:41:02 +0000449 ModuleSP module_sp (GetSP ());
450 if (type && module_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +0000451 {
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000452 SymbolContext sc;
453 TypeList type_list;
Greg Claytondc0a38c2012-03-26 23:03:23 +0000454 const bool exact_match = false;
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000455 uint32_t num_matches = 0;
456 ConstString name(type);
Enrico Granata979e20d2011-07-29 19:53:35 +0000457
Greg Clayton49f4bf22012-02-22 19:41:02 +0000458 num_matches = module_sp->FindTypes (sc,
459 name,
Greg Claytondc0a38c2012-03-26 23:03:23 +0000460 exact_match,
Greg Clayton49f4bf22012-02-22 19:41:02 +0000461 UINT32_MAX,
462 type_list);
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000463
464 for (size_t idx = 0; idx < num_matches; idx++)
465 {
466 TypeSP type_sp (type_list.GetTypeAtIndex(idx));
467 if (type_sp)
468 retval.Append(SBType(type_sp));
469 }
Enrico Granata979e20d2011-07-29 19:53:35 +0000470 }
471
472 return retval;
Greg Clayton153ccd72011-08-10 02:10:13 +0000473}
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000474
475
476SBSection
477SBModule::FindSection (const char *sect_name)
478{
479 SBSection sb_section;
480
Greg Clayton49f4bf22012-02-22 19:41:02 +0000481 ModuleSP module_sp (GetSP ());
482 if (sect_name && module_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000483 {
Greg Clayton49f4bf22012-02-22 19:41:02 +0000484 ObjectFile *objfile = module_sp->GetObjectFile();
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000485 if (objfile)
486 {
487 SectionList *section_list = objfile->GetSectionList();
488 if (section_list)
489 {
490 ConstString const_sect_name(sect_name);
491 SectionSP section_sp (section_list->FindSectionByName(const_sect_name));
492 if (section_sp)
493 {
Greg Clayton3508c382012-02-24 01:59:29 +0000494 sb_section.SetSP (section_sp);
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000495 }
496 }
497 }
498 }
499 return sb_section;
500}
501
Greg Clayton1b925202012-01-29 06:07:39 +0000502lldb::ByteOrder
503SBModule::GetByteOrder ()
504{
Greg Clayton49f4bf22012-02-22 19:41:02 +0000505 ModuleSP module_sp (GetSP ());
506 if (module_sp)
507 return module_sp->GetArchitecture().GetByteOrder();
Greg Clayton1b925202012-01-29 06:07:39 +0000508 return eByteOrderInvalid;
509}
510
511const char *
512SBModule::GetTriple ()
513{
Greg Clayton49f4bf22012-02-22 19:41:02 +0000514 ModuleSP module_sp (GetSP ());
515 if (module_sp)
Greg Clayton1b925202012-01-29 06:07:39 +0000516 {
Greg Clayton49f4bf22012-02-22 19:41:02 +0000517 std::string triple (module_sp->GetArchitecture().GetTriple().str());
Greg Clayton1b925202012-01-29 06:07:39 +0000518 // Unique the string so we don't run into ownership issues since
519 // the const strings put the string into the string pool once and
520 // the strings never comes out
521 ConstString const_triple (triple.c_str());
522 return const_triple.GetCString();
523 }
524 return NULL;
525}
526
527uint32_t
528SBModule::GetAddressByteSize()
529{
Greg Clayton49f4bf22012-02-22 19:41:02 +0000530 ModuleSP module_sp (GetSP ());
531 if (module_sp)
532 return module_sp->GetArchitecture().GetAddressByteSize();
Greg Clayton1b925202012-01-29 06:07:39 +0000533 return sizeof(void*);
534}
535
Greg Clayton49f4bf22012-02-22 19:41:02 +0000536
537uint32_t
538SBModule::GetVersion (uint32_t *versions, uint32_t num_versions)
539{
540 ModuleSP module_sp (GetSP ());
541 if (module_sp)
542 {
543 ObjectFile *obj_file = module_sp->GetObjectFile();
544 if (obj_file)
545 return obj_file->GetVersion (versions, num_versions);
546 }
547
548 if (versions && num_versions)
549 {
550 for (uint32_t i=0; i<num_versions; ++i)
551 versions[i] = UINT32_MAX;
552 }
553 return 0;
554}
555