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