1 //===-- SBModule.cpp --------------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "lldb/API/SBModule.h"
10 #include "SBReproducerPrivate.h"
11 #include "lldb/API/SBAddress.h"
12 #include "lldb/API/SBFileSpec.h"
13 #include "lldb/API/SBModuleSpec.h"
14 #include "lldb/API/SBProcess.h"
15 #include "lldb/API/SBStream.h"
16 #include "lldb/API/SBSymbolContextList.h"
17 #include "lldb/Core/Module.h"
18 #include "lldb/Core/Section.h"
19 #include "lldb/Core/ValueObjectList.h"
20 #include "lldb/Core/ValueObjectVariable.h"
21 #include "lldb/Symbol/ObjectFile.h"
22 #include "lldb/Symbol/SymbolFile.h"
23 #include "lldb/Symbol/SymbolVendor.h"
24 #include "lldb/Symbol/Symtab.h"
25 #include "lldb/Symbol/TypeSystem.h"
26 #include "lldb/Symbol/VariableList.h"
27 #include "lldb/Target/Target.h"
28 #include "lldb/Utility/Log.h"
29 #include "lldb/Utility/StreamString.h"
30 
31 using namespace lldb;
32 using namespace lldb_private;
33 
34 SBModule::SBModule() : m_opaque_sp() {
35   LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBModule);
36 }
37 
38 SBModule::SBModule(const lldb::ModuleSP &module_sp) : m_opaque_sp(module_sp) {}
39 
40 SBModule::SBModule(const SBModuleSpec &module_spec) : m_opaque_sp() {
41   LLDB_RECORD_CONSTRUCTOR(SBModule, (const lldb::SBModuleSpec &), module_spec);
42 
43   ModuleSP module_sp;
44   Status error = ModuleList::GetSharedModule(*module_spec.m_opaque_up,
45                                              module_sp, NULL, NULL, NULL);
46   if (module_sp)
47     SetSP(module_sp);
48 }
49 
50 SBModule::SBModule(const SBModule &rhs) : m_opaque_sp(rhs.m_opaque_sp) {
51   LLDB_RECORD_CONSTRUCTOR(SBModule, (const lldb::SBModule &), rhs);
52 }
53 
54 SBModule::SBModule(lldb::SBProcess &process, lldb::addr_t header_addr)
55     : m_opaque_sp() {
56   LLDB_RECORD_CONSTRUCTOR(SBModule, (lldb::SBProcess &, lldb::addr_t), process,
57                           header_addr);
58 
59   ProcessSP process_sp(process.GetSP());
60   if (process_sp) {
61     m_opaque_sp = process_sp->ReadModuleFromMemory(FileSpec(), header_addr);
62     if (m_opaque_sp) {
63       Target &target = process_sp->GetTarget();
64       bool changed = false;
65       m_opaque_sp->SetLoadAddress(target, 0, true, changed);
66       target.GetImages().Append(m_opaque_sp);
67     }
68   }
69 }
70 
71 const SBModule &SBModule::operator=(const SBModule &rhs) {
72   LLDB_RECORD_METHOD(const lldb::SBModule &,
73                      SBModule, operator=,(const lldb::SBModule &), rhs);
74 
75   if (this != &rhs)
76     m_opaque_sp = rhs.m_opaque_sp;
77   return *this;
78 }
79 
80 SBModule::~SBModule() {}
81 
82 bool SBModule::IsValid() const {
83   LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBModule, IsValid);
84 
85   return m_opaque_sp.get() != NULL;
86 }
87 
88 void SBModule::Clear() {
89   LLDB_RECORD_METHOD_NO_ARGS(void, SBModule, Clear);
90 
91   m_opaque_sp.reset();
92 }
93 
94 SBFileSpec SBModule::GetFileSpec() const {
95   LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBFileSpec, SBModule, GetFileSpec);
96 
97   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
98 
99   SBFileSpec file_spec;
100   ModuleSP module_sp(GetSP());
101   if (module_sp)
102     file_spec.SetFileSpec(module_sp->GetFileSpec());
103 
104   if (log)
105     log->Printf("SBModule(%p)::GetFileSpec () => SBFileSpec(%p)",
106                 static_cast<void *>(module_sp.get()),
107                 static_cast<const void *>(file_spec.get()));
108 
109   return LLDB_RECORD_RESULT(file_spec);
110 }
111 
112 lldb::SBFileSpec SBModule::GetPlatformFileSpec() const {
113   LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBFileSpec, SBModule,
114                                    GetPlatformFileSpec);
115 
116   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
117 
118   SBFileSpec file_spec;
119   ModuleSP module_sp(GetSP());
120   if (module_sp)
121     file_spec.SetFileSpec(module_sp->GetPlatformFileSpec());
122 
123   if (log)
124     log->Printf("SBModule(%p)::GetPlatformFileSpec () => SBFileSpec(%p)",
125                 static_cast<void *>(module_sp.get()),
126                 static_cast<const void *>(file_spec.get()));
127 
128   return LLDB_RECORD_RESULT(file_spec);
129 }
130 
131 bool SBModule::SetPlatformFileSpec(const lldb::SBFileSpec &platform_file) {
132   LLDB_RECORD_METHOD(bool, SBModule, SetPlatformFileSpec,
133                      (const lldb::SBFileSpec &), platform_file);
134 
135   bool result = false;
136   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
137 
138   ModuleSP module_sp(GetSP());
139   if (module_sp) {
140     module_sp->SetPlatformFileSpec(*platform_file);
141     result = true;
142   }
143 
144   if (log)
145     log->Printf("SBModule(%p)::SetPlatformFileSpec (SBFileSpec(%p (%s)) => %i",
146                 static_cast<void *>(module_sp.get()),
147                 static_cast<const void *>(platform_file.get()),
148                 platform_file->GetPath().c_str(), result);
149   return result;
150 }
151 
152 lldb::SBFileSpec SBModule::GetRemoteInstallFileSpec() {
153   LLDB_RECORD_METHOD_NO_ARGS(lldb::SBFileSpec, SBModule,
154                              GetRemoteInstallFileSpec);
155 
156   SBFileSpec sb_file_spec;
157   ModuleSP module_sp(GetSP());
158   if (module_sp)
159     sb_file_spec.SetFileSpec(module_sp->GetRemoteInstallFileSpec());
160   return LLDB_RECORD_RESULT(sb_file_spec);
161 }
162 
163 bool SBModule::SetRemoteInstallFileSpec(lldb::SBFileSpec &file) {
164   LLDB_RECORD_METHOD(bool, SBModule, SetRemoteInstallFileSpec,
165                      (lldb::SBFileSpec &), file);
166 
167   ModuleSP module_sp(GetSP());
168   if (module_sp) {
169     module_sp->SetRemoteInstallFileSpec(file.ref());
170     return true;
171   }
172   return false;
173 }
174 
175 const uint8_t *SBModule::GetUUIDBytes() const {
176   LLDB_RECORD_METHOD_CONST_NO_ARGS(const uint8_t *, SBModule, GetUUIDBytes);
177 
178   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
179 
180   const uint8_t *uuid_bytes = NULL;
181   ModuleSP module_sp(GetSP());
182   if (module_sp)
183     uuid_bytes = module_sp->GetUUID().GetBytes().data();
184 
185   if (log) {
186     if (uuid_bytes) {
187       StreamString s;
188       module_sp->GetUUID().Dump(&s);
189       log->Printf("SBModule(%p)::GetUUIDBytes () => %s",
190                   static_cast<void *>(module_sp.get()), s.GetData());
191     } else
192       log->Printf("SBModule(%p)::GetUUIDBytes () => NULL",
193                   static_cast<void *>(module_sp.get()));
194   }
195   return uuid_bytes;
196 }
197 
198 const char *SBModule::GetUUIDString() const {
199   LLDB_RECORD_METHOD_CONST_NO_ARGS(const char *, SBModule, GetUUIDString);
200 
201   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
202 
203   const char *uuid_cstr = NULL;
204   ModuleSP module_sp(GetSP());
205   if (module_sp) {
206     // We are going to return a "const char *" value through the public API, so
207     // we need to constify it so it gets added permanently the string pool and
208     // then we don't need to worry about the lifetime of the string as it will
209     // never go away once it has been put into the ConstString string pool
210     uuid_cstr = ConstString(module_sp->GetUUID().GetAsString()).GetCString();
211   }
212 
213   if (uuid_cstr && uuid_cstr[0]) {
214     if (log)
215       log->Printf("SBModule(%p)::GetUUIDString () => %s",
216                   static_cast<void *>(module_sp.get()), uuid_cstr);
217     return uuid_cstr;
218   }
219 
220   if (log)
221     log->Printf("SBModule(%p)::GetUUIDString () => NULL",
222                 static_cast<void *>(module_sp.get()));
223   return NULL;
224 }
225 
226 bool SBModule::operator==(const SBModule &rhs) const {
227   LLDB_RECORD_METHOD_CONST(bool, SBModule, operator==,(const lldb::SBModule &),
228                            rhs);
229 
230   if (m_opaque_sp)
231     return m_opaque_sp.get() == rhs.m_opaque_sp.get();
232   return false;
233 }
234 
235 bool SBModule::operator!=(const SBModule &rhs) const {
236   LLDB_RECORD_METHOD_CONST(bool, SBModule, operator!=,(const lldb::SBModule &),
237                            rhs);
238 
239   if (m_opaque_sp)
240     return m_opaque_sp.get() != rhs.m_opaque_sp.get();
241   return false;
242 }
243 
244 ModuleSP SBModule::GetSP() const { return m_opaque_sp; }
245 
246 void SBModule::SetSP(const ModuleSP &module_sp) { m_opaque_sp = module_sp; }
247 
248 SBAddress SBModule::ResolveFileAddress(lldb::addr_t vm_addr) {
249   LLDB_RECORD_METHOD(lldb::SBAddress, SBModule, ResolveFileAddress,
250                      (lldb::addr_t), vm_addr);
251 
252   lldb::SBAddress sb_addr;
253   ModuleSP module_sp(GetSP());
254   if (module_sp) {
255     Address addr;
256     if (module_sp->ResolveFileAddress(vm_addr, addr))
257       sb_addr.ref() = addr;
258   }
259   return LLDB_RECORD_RESULT(sb_addr);
260 }
261 
262 SBSymbolContext
263 SBModule::ResolveSymbolContextForAddress(const SBAddress &addr,
264                                          uint32_t resolve_scope) {
265   LLDB_RECORD_METHOD(lldb::SBSymbolContext, SBModule,
266                      ResolveSymbolContextForAddress,
267                      (const lldb::SBAddress &, uint32_t), addr, resolve_scope);
268 
269   SBSymbolContext sb_sc;
270   ModuleSP module_sp(GetSP());
271   SymbolContextItem scope = static_cast<SymbolContextItem>(resolve_scope);
272   if (module_sp && addr.IsValid())
273     module_sp->ResolveSymbolContextForAddress(addr.ref(), scope, *sb_sc);
274   return LLDB_RECORD_RESULT(sb_sc);
275 }
276 
277 bool SBModule::GetDescription(SBStream &description) {
278   LLDB_RECORD_METHOD(bool, SBModule, GetDescription, (lldb::SBStream &),
279                      description);
280 
281   Stream &strm = description.ref();
282 
283   ModuleSP module_sp(GetSP());
284   if (module_sp) {
285     module_sp->GetDescription(&strm);
286   } else
287     strm.PutCString("No value");
288 
289   return true;
290 }
291 
292 uint32_t SBModule::GetNumCompileUnits() {
293   LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBModule, GetNumCompileUnits);
294 
295   ModuleSP module_sp(GetSP());
296   if (module_sp) {
297     return module_sp->GetNumCompileUnits();
298   }
299   return 0;
300 }
301 
302 SBCompileUnit SBModule::GetCompileUnitAtIndex(uint32_t index) {
303   LLDB_RECORD_METHOD(lldb::SBCompileUnit, SBModule, GetCompileUnitAtIndex,
304                      (uint32_t), index);
305 
306   SBCompileUnit sb_cu;
307   ModuleSP module_sp(GetSP());
308   if (module_sp) {
309     CompUnitSP cu_sp = module_sp->GetCompileUnitAtIndex(index);
310     sb_cu.reset(cu_sp.get());
311   }
312   return LLDB_RECORD_RESULT(sb_cu);
313 }
314 
315 SBSymbolContextList SBModule::FindCompileUnits(const SBFileSpec &sb_file_spec) {
316   LLDB_RECORD_METHOD(lldb::SBSymbolContextList, SBModule, FindCompileUnits,
317                      (const lldb::SBFileSpec &), sb_file_spec);
318 
319   SBSymbolContextList sb_sc_list;
320   const ModuleSP module_sp(GetSP());
321   if (sb_file_spec.IsValid() && module_sp) {
322     const bool append = true;
323     module_sp->FindCompileUnits(*sb_file_spec, append, *sb_sc_list);
324   }
325   return LLDB_RECORD_RESULT(sb_sc_list);
326 }
327 
328 static Symtab *GetUnifiedSymbolTable(const lldb::ModuleSP &module_sp) {
329   if (module_sp) {
330     SymbolVendor *symbols = module_sp->GetSymbolVendor();
331     if (symbols)
332       return symbols->GetSymtab();
333   }
334   return NULL;
335 }
336 
337 size_t SBModule::GetNumSymbols() {
338   LLDB_RECORD_METHOD_NO_ARGS(size_t, SBModule, GetNumSymbols);
339 
340   ModuleSP module_sp(GetSP());
341   if (module_sp) {
342     Symtab *symtab = GetUnifiedSymbolTable(module_sp);
343     if (symtab)
344       return symtab->GetNumSymbols();
345   }
346   return 0;
347 }
348 
349 SBSymbol SBModule::GetSymbolAtIndex(size_t idx) {
350   LLDB_RECORD_METHOD(lldb::SBSymbol, SBModule, GetSymbolAtIndex, (size_t), idx);
351 
352   SBSymbol sb_symbol;
353   ModuleSP module_sp(GetSP());
354   Symtab *symtab = GetUnifiedSymbolTable(module_sp);
355   if (symtab)
356     sb_symbol.SetSymbol(symtab->SymbolAtIndex(idx));
357   return LLDB_RECORD_RESULT(sb_symbol);
358 }
359 
360 lldb::SBSymbol SBModule::FindSymbol(const char *name,
361                                     lldb::SymbolType symbol_type) {
362   LLDB_RECORD_METHOD(lldb::SBSymbol, SBModule, FindSymbol,
363                      (const char *, lldb::SymbolType), name, symbol_type);
364 
365   SBSymbol sb_symbol;
366   if (name && name[0]) {
367     ModuleSP module_sp(GetSP());
368     Symtab *symtab = GetUnifiedSymbolTable(module_sp);
369     if (symtab)
370       sb_symbol.SetSymbol(symtab->FindFirstSymbolWithNameAndType(
371           ConstString(name), symbol_type, Symtab::eDebugAny,
372           Symtab::eVisibilityAny));
373   }
374   return LLDB_RECORD_RESULT(sb_symbol);
375 }
376 
377 lldb::SBSymbolContextList SBModule::FindSymbols(const char *name,
378                                                 lldb::SymbolType symbol_type) {
379   LLDB_RECORD_METHOD(lldb::SBSymbolContextList, SBModule, FindSymbols,
380                      (const char *, lldb::SymbolType), name, symbol_type);
381 
382   SBSymbolContextList sb_sc_list;
383   if (name && name[0]) {
384     ModuleSP module_sp(GetSP());
385     Symtab *symtab = GetUnifiedSymbolTable(module_sp);
386     if (symtab) {
387       std::vector<uint32_t> matching_symbol_indexes;
388       const size_t num_matches = symtab->FindAllSymbolsWithNameAndType(
389           ConstString(name), symbol_type, matching_symbol_indexes);
390       if (num_matches) {
391         SymbolContext sc;
392         sc.module_sp = module_sp;
393         SymbolContextList &sc_list = *sb_sc_list;
394         for (size_t i = 0; i < num_matches; ++i) {
395           sc.symbol = symtab->SymbolAtIndex(matching_symbol_indexes[i]);
396           if (sc.symbol)
397             sc_list.Append(sc);
398         }
399       }
400     }
401   }
402   return LLDB_RECORD_RESULT(sb_sc_list);
403 }
404 
405 size_t SBModule::GetNumSections() {
406   LLDB_RECORD_METHOD_NO_ARGS(size_t, SBModule, GetNumSections);
407 
408   ModuleSP module_sp(GetSP());
409   if (module_sp) {
410     // Give the symbol vendor a chance to add to the unified section list.
411     module_sp->GetSymbolVendor();
412     SectionList *section_list = module_sp->GetSectionList();
413     if (section_list)
414       return section_list->GetSize();
415   }
416   return 0;
417 }
418 
419 SBSection SBModule::GetSectionAtIndex(size_t idx) {
420   LLDB_RECORD_METHOD(lldb::SBSection, SBModule, GetSectionAtIndex, (size_t),
421                      idx);
422 
423   SBSection sb_section;
424   ModuleSP module_sp(GetSP());
425   if (module_sp) {
426     // Give the symbol vendor a chance to add to the unified section list.
427     module_sp->GetSymbolVendor();
428     SectionList *section_list = module_sp->GetSectionList();
429 
430     if (section_list)
431       sb_section.SetSP(section_list->GetSectionAtIndex(idx));
432   }
433   return LLDB_RECORD_RESULT(sb_section);
434 }
435 
436 lldb::SBSymbolContextList SBModule::FindFunctions(const char *name,
437                                                   uint32_t name_type_mask) {
438   LLDB_RECORD_METHOD(lldb::SBSymbolContextList, SBModule, FindFunctions,
439                      (const char *, uint32_t), name, name_type_mask);
440 
441   lldb::SBSymbolContextList sb_sc_list;
442   ModuleSP module_sp(GetSP());
443   if (name && module_sp) {
444     const bool append = true;
445     const bool symbols_ok = true;
446     const bool inlines_ok = true;
447     FunctionNameType type = static_cast<FunctionNameType>(name_type_mask);
448     module_sp->FindFunctions(ConstString(name), NULL, type, symbols_ok,
449                              inlines_ok, append, *sb_sc_list);
450   }
451   return LLDB_RECORD_RESULT(sb_sc_list);
452 }
453 
454 SBValueList SBModule::FindGlobalVariables(SBTarget &target, const char *name,
455                                           uint32_t max_matches) {
456   LLDB_RECORD_METHOD(lldb::SBValueList, SBModule, FindGlobalVariables,
457                      (lldb::SBTarget &, const char *, uint32_t), target, name,
458                      max_matches);
459 
460   SBValueList sb_value_list;
461   ModuleSP module_sp(GetSP());
462   if (name && module_sp) {
463     VariableList variable_list;
464     const uint32_t match_count = module_sp->FindGlobalVariables(
465         ConstString(name), NULL, max_matches, variable_list);
466 
467     if (match_count > 0) {
468       for (uint32_t i = 0; i < match_count; ++i) {
469         lldb::ValueObjectSP valobj_sp;
470         TargetSP target_sp(target.GetSP());
471         valobj_sp = ValueObjectVariable::Create(
472             target_sp.get(), variable_list.GetVariableAtIndex(i));
473         if (valobj_sp)
474           sb_value_list.Append(SBValue(valobj_sp));
475       }
476     }
477   }
478 
479   return LLDB_RECORD_RESULT(sb_value_list);
480 }
481 
482 lldb::SBValue SBModule::FindFirstGlobalVariable(lldb::SBTarget &target,
483                                                 const char *name) {
484   LLDB_RECORD_METHOD(lldb::SBValue, SBModule, FindFirstGlobalVariable,
485                      (lldb::SBTarget &, const char *), target, name);
486 
487   SBValueList sb_value_list(FindGlobalVariables(target, name, 1));
488   if (sb_value_list.IsValid() && sb_value_list.GetSize() > 0)
489     return LLDB_RECORD_RESULT(sb_value_list.GetValueAtIndex(0));
490   return LLDB_RECORD_RESULT(SBValue());
491 }
492 
493 lldb::SBType SBModule::FindFirstType(const char *name_cstr) {
494   LLDB_RECORD_METHOD(lldb::SBType, SBModule, FindFirstType, (const char *),
495                      name_cstr);
496 
497   SBType sb_type;
498   ModuleSP module_sp(GetSP());
499   if (name_cstr && module_sp) {
500     SymbolContext sc;
501     const bool exact_match = false;
502     ConstString name(name_cstr);
503 
504     sb_type = SBType(module_sp->FindFirstType(sc, name, exact_match));
505 
506     if (!sb_type.IsValid()) {
507       TypeSystem *type_system =
508           module_sp->GetTypeSystemForLanguage(eLanguageTypeC);
509       if (type_system)
510         sb_type = SBType(type_system->GetBuiltinTypeByName(name));
511     }
512   }
513   return LLDB_RECORD_RESULT(sb_type);
514 }
515 
516 lldb::SBType SBModule::GetBasicType(lldb::BasicType type) {
517   LLDB_RECORD_METHOD(lldb::SBType, SBModule, GetBasicType, (lldb::BasicType),
518                      type);
519 
520   ModuleSP module_sp(GetSP());
521   if (module_sp) {
522     TypeSystem *type_system =
523         module_sp->GetTypeSystemForLanguage(eLanguageTypeC);
524     if (type_system)
525       return LLDB_RECORD_RESULT(SBType(type_system->GetBasicTypeFromAST(type)));
526   }
527   return LLDB_RECORD_RESULT(SBType());
528 }
529 
530 lldb::SBTypeList SBModule::FindTypes(const char *type) {
531   LLDB_RECORD_METHOD(lldb::SBTypeList, SBModule, FindTypes, (const char *),
532                      type);
533 
534   SBTypeList retval;
535 
536   ModuleSP module_sp(GetSP());
537   if (type && module_sp) {
538     TypeList type_list;
539     const bool exact_match = false;
540     ConstString name(type);
541     llvm::DenseSet<SymbolFile *> searched_symbol_files;
542     const uint32_t num_matches = module_sp->FindTypes(
543         name, exact_match, UINT32_MAX, searched_symbol_files, type_list);
544 
545     if (num_matches > 0) {
546       for (size_t idx = 0; idx < num_matches; idx++) {
547         TypeSP type_sp(type_list.GetTypeAtIndex(idx));
548         if (type_sp)
549           retval.Append(SBType(type_sp));
550       }
551     } else {
552       TypeSystem *type_system =
553           module_sp->GetTypeSystemForLanguage(eLanguageTypeC);
554       if (type_system) {
555         CompilerType compiler_type = type_system->GetBuiltinTypeByName(name);
556         if (compiler_type)
557           retval.Append(SBType(compiler_type));
558       }
559     }
560   }
561 
562   return LLDB_RECORD_RESULT(retval);
563 }
564 
565 lldb::SBType SBModule::GetTypeByID(lldb::user_id_t uid) {
566   LLDB_RECORD_METHOD(lldb::SBType, SBModule, GetTypeByID, (lldb::user_id_t),
567                      uid);
568 
569   ModuleSP module_sp(GetSP());
570   if (module_sp) {
571     SymbolVendor *vendor = module_sp->GetSymbolVendor();
572     if (vendor) {
573       Type *type_ptr = vendor->ResolveTypeUID(uid);
574       if (type_ptr)
575         return LLDB_RECORD_RESULT(SBType(type_ptr->shared_from_this()));
576     }
577   }
578   return LLDB_RECORD_RESULT(SBType());
579 }
580 
581 lldb::SBTypeList SBModule::GetTypes(uint32_t type_mask) {
582   LLDB_RECORD_METHOD(lldb::SBTypeList, SBModule, GetTypes, (uint32_t),
583                      type_mask);
584 
585   SBTypeList sb_type_list;
586 
587   ModuleSP module_sp(GetSP());
588   if (!module_sp)
589     return LLDB_RECORD_RESULT(sb_type_list);
590   SymbolVendor *vendor = module_sp->GetSymbolVendor();
591   if (!vendor)
592     return LLDB_RECORD_RESULT(sb_type_list);
593 
594   TypeClass type_class = static_cast<TypeClass>(type_mask);
595   TypeList type_list;
596   vendor->GetTypes(NULL, type_class, type_list);
597   sb_type_list.m_opaque_up->Append(type_list);
598   return LLDB_RECORD_RESULT(sb_type_list);
599 }
600 
601 SBSection SBModule::FindSection(const char *sect_name) {
602   LLDB_RECORD_METHOD(lldb::SBSection, SBModule, FindSection, (const char *),
603                      sect_name);
604 
605   SBSection sb_section;
606 
607   ModuleSP module_sp(GetSP());
608   if (sect_name && module_sp) {
609     // Give the symbol vendor a chance to add to the unified section list.
610     module_sp->GetSymbolVendor();
611     SectionList *section_list = module_sp->GetSectionList();
612     if (section_list) {
613       ConstString const_sect_name(sect_name);
614       SectionSP section_sp(section_list->FindSectionByName(const_sect_name));
615       if (section_sp) {
616         sb_section.SetSP(section_sp);
617       }
618     }
619   }
620   return LLDB_RECORD_RESULT(sb_section);
621 }
622 
623 lldb::ByteOrder SBModule::GetByteOrder() {
624   LLDB_RECORD_METHOD_NO_ARGS(lldb::ByteOrder, SBModule, GetByteOrder);
625 
626   ModuleSP module_sp(GetSP());
627   if (module_sp)
628     return module_sp->GetArchitecture().GetByteOrder();
629   return eByteOrderInvalid;
630 }
631 
632 const char *SBModule::GetTriple() {
633   LLDB_RECORD_METHOD_NO_ARGS(const char *, SBModule, GetTriple);
634 
635   ModuleSP module_sp(GetSP());
636   if (module_sp) {
637     std::string triple(module_sp->GetArchitecture().GetTriple().str());
638     // Unique the string so we don't run into ownership issues since the const
639     // strings put the string into the string pool once and the strings never
640     // comes out
641     ConstString const_triple(triple.c_str());
642     return const_triple.GetCString();
643   }
644   return NULL;
645 }
646 
647 uint32_t SBModule::GetAddressByteSize() {
648   LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBModule, GetAddressByteSize);
649 
650   ModuleSP module_sp(GetSP());
651   if (module_sp)
652     return module_sp->GetArchitecture().GetAddressByteSize();
653   return sizeof(void *);
654 }
655 
656 uint32_t SBModule::GetVersion(uint32_t *versions, uint32_t num_versions) {
657   LLDB_RECORD_METHOD(uint32_t, SBModule, GetVersion, (uint32_t *, uint32_t),
658                      versions, num_versions);
659 
660   llvm::VersionTuple version;
661   if (ModuleSP module_sp = GetSP())
662     version = module_sp->GetVersion();
663   uint32_t result = 0;
664   if (!version.empty())
665     ++result;
666   if (version.getMinor())
667     ++result;
668   if(version.getSubminor())
669     ++result;
670 
671   if (!versions)
672     return result;
673 
674   if (num_versions > 0)
675     versions[0] = version.empty() ? UINT32_MAX : version.getMajor();
676   if (num_versions > 1)
677     versions[1] = version.getMinor().getValueOr(UINT32_MAX);
678   if (num_versions > 2)
679     versions[2] = version.getSubminor().getValueOr(UINT32_MAX);
680   for (uint32_t i = 3; i < num_versions; ++i)
681     versions[i] = UINT32_MAX;
682   return result;
683 }
684 
685 lldb::SBFileSpec SBModule::GetSymbolFileSpec() const {
686   LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBFileSpec, SBModule,
687                                    GetSymbolFileSpec);
688 
689   lldb::SBFileSpec sb_file_spec;
690   ModuleSP module_sp(GetSP());
691   if (module_sp) {
692     SymbolVendor *symbol_vendor_ptr = module_sp->GetSymbolVendor();
693     if (symbol_vendor_ptr)
694       sb_file_spec.SetFileSpec(symbol_vendor_ptr->GetMainFileSpec());
695   }
696   return LLDB_RECORD_RESULT(sb_file_spec);
697 }
698 
699 lldb::SBAddress SBModule::GetObjectFileHeaderAddress() const {
700   LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBAddress, SBModule,
701                                    GetObjectFileHeaderAddress);
702 
703   lldb::SBAddress sb_addr;
704   ModuleSP module_sp(GetSP());
705   if (module_sp) {
706     ObjectFile *objfile_ptr = module_sp->GetObjectFile();
707     if (objfile_ptr)
708       sb_addr.ref() = objfile_ptr->GetBaseAddress();
709   }
710   return LLDB_RECORD_RESULT(sb_addr);
711 }
712 
713 lldb::SBAddress SBModule::GetObjectFileEntryPointAddress() const {
714   LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBAddress, SBModule,
715                                    GetObjectFileEntryPointAddress);
716 
717   lldb::SBAddress sb_addr;
718   ModuleSP module_sp(GetSP());
719   if (module_sp) {
720     ObjectFile *objfile_ptr = module_sp->GetObjectFile();
721     if (objfile_ptr)
722       sb_addr.ref() = objfile_ptr->GetEntryPointAddress();
723   }
724   return LLDB_RECORD_RESULT(sb_addr);
725 }
726