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) {
400349cc55cSDimitry Andric 
401349cc55cSDimitry Andric     ModuleFunctionSearchOptions function_options;
402349cc55cSDimitry Andric     function_options.include_symbols = true;
403349cc55cSDimitry Andric     function_options.include_inlines = true;
404*0b57cec5SDimitry Andric     FunctionNameType type = static_cast<FunctionNameType>(name_type_mask);
4055ffd83dbSDimitry Andric     module_sp->FindFunctions(ConstString(name), CompilerDeclContext(), type,
406349cc55cSDimitry Andric                              function_options, *sb_sc_list);
407*0b57cec5SDimitry Andric   }
408*0b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(sb_sc_list);
409*0b57cec5SDimitry Andric }
410*0b57cec5SDimitry Andric 
411*0b57cec5SDimitry Andric SBValueList SBModule::FindGlobalVariables(SBTarget &target, const char *name,
412*0b57cec5SDimitry Andric                                           uint32_t max_matches) {
413*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD(lldb::SBValueList, SBModule, FindGlobalVariables,
414*0b57cec5SDimitry Andric                      (lldb::SBTarget &, const char *, uint32_t), target, name,
415*0b57cec5SDimitry Andric                      max_matches);
416*0b57cec5SDimitry Andric 
417*0b57cec5SDimitry Andric   SBValueList sb_value_list;
418*0b57cec5SDimitry Andric   ModuleSP module_sp(GetSP());
419*0b57cec5SDimitry Andric   if (name && module_sp) {
420*0b57cec5SDimitry Andric     VariableList variable_list;
4215ffd83dbSDimitry Andric     module_sp->FindGlobalVariables(ConstString(name), CompilerDeclContext(),
4225ffd83dbSDimitry Andric                                    max_matches, variable_list);
423480093f4SDimitry Andric     for (const VariableSP &var_sp : variable_list) {
424*0b57cec5SDimitry Andric       lldb::ValueObjectSP valobj_sp;
425*0b57cec5SDimitry Andric       TargetSP target_sp(target.GetSP());
426480093f4SDimitry Andric       valobj_sp = ValueObjectVariable::Create(target_sp.get(), var_sp);
427*0b57cec5SDimitry Andric       if (valobj_sp)
428*0b57cec5SDimitry Andric         sb_value_list.Append(SBValue(valobj_sp));
429*0b57cec5SDimitry Andric     }
430*0b57cec5SDimitry Andric   }
431*0b57cec5SDimitry Andric 
432*0b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(sb_value_list);
433*0b57cec5SDimitry Andric }
434*0b57cec5SDimitry Andric 
435*0b57cec5SDimitry Andric lldb::SBValue SBModule::FindFirstGlobalVariable(lldb::SBTarget &target,
436*0b57cec5SDimitry Andric                                                 const char *name) {
437*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD(lldb::SBValue, SBModule, FindFirstGlobalVariable,
438*0b57cec5SDimitry Andric                      (lldb::SBTarget &, const char *), target, name);
439*0b57cec5SDimitry Andric 
440*0b57cec5SDimitry Andric   SBValueList sb_value_list(FindGlobalVariables(target, name, 1));
441*0b57cec5SDimitry Andric   if (sb_value_list.IsValid() && sb_value_list.GetSize() > 0)
442*0b57cec5SDimitry Andric     return LLDB_RECORD_RESULT(sb_value_list.GetValueAtIndex(0));
443*0b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(SBValue());
444*0b57cec5SDimitry Andric }
445*0b57cec5SDimitry Andric 
446*0b57cec5SDimitry Andric lldb::SBType SBModule::FindFirstType(const char *name_cstr) {
447*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD(lldb::SBType, SBModule, FindFirstType, (const char *),
448*0b57cec5SDimitry Andric                      name_cstr);
449*0b57cec5SDimitry Andric 
450*0b57cec5SDimitry Andric   SBType sb_type;
451*0b57cec5SDimitry Andric   ModuleSP module_sp(GetSP());
452*0b57cec5SDimitry Andric   if (name_cstr && module_sp) {
453*0b57cec5SDimitry Andric     SymbolContext sc;
454*0b57cec5SDimitry Andric     const bool exact_match = false;
455*0b57cec5SDimitry Andric     ConstString name(name_cstr);
456*0b57cec5SDimitry Andric 
457*0b57cec5SDimitry Andric     sb_type = SBType(module_sp->FindFirstType(sc, name, exact_match));
458*0b57cec5SDimitry Andric 
459*0b57cec5SDimitry Andric     if (!sb_type.IsValid()) {
4609dba64beSDimitry Andric       auto type_system_or_err =
461*0b57cec5SDimitry Andric           module_sp->GetTypeSystemForLanguage(eLanguageTypeC);
4629dba64beSDimitry Andric       if (auto err = type_system_or_err.takeError()) {
4639dba64beSDimitry Andric         llvm::consumeError(std::move(err));
4649dba64beSDimitry Andric         return LLDB_RECORD_RESULT(SBType());
4659dba64beSDimitry Andric       }
4669dba64beSDimitry Andric       sb_type = SBType(type_system_or_err->GetBuiltinTypeByName(name));
467*0b57cec5SDimitry Andric     }
468*0b57cec5SDimitry Andric   }
469*0b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(sb_type);
470*0b57cec5SDimitry Andric }
471*0b57cec5SDimitry Andric 
472*0b57cec5SDimitry Andric lldb::SBType SBModule::GetBasicType(lldb::BasicType type) {
473*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD(lldb::SBType, SBModule, GetBasicType, (lldb::BasicType),
474*0b57cec5SDimitry Andric                      type);
475*0b57cec5SDimitry Andric 
476*0b57cec5SDimitry Andric   ModuleSP module_sp(GetSP());
477*0b57cec5SDimitry Andric   if (module_sp) {
4789dba64beSDimitry Andric     auto type_system_or_err =
479*0b57cec5SDimitry Andric         module_sp->GetTypeSystemForLanguage(eLanguageTypeC);
4809dba64beSDimitry Andric     if (auto err = type_system_or_err.takeError()) {
4819dba64beSDimitry Andric       llvm::consumeError(std::move(err));
4829dba64beSDimitry Andric     } else {
4839dba64beSDimitry Andric       return LLDB_RECORD_RESULT(
4849dba64beSDimitry Andric           SBType(type_system_or_err->GetBasicTypeFromAST(type)));
4859dba64beSDimitry Andric     }
486*0b57cec5SDimitry Andric   }
487*0b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(SBType());
488*0b57cec5SDimitry Andric }
489*0b57cec5SDimitry Andric 
490*0b57cec5SDimitry Andric lldb::SBTypeList SBModule::FindTypes(const char *type) {
491*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD(lldb::SBTypeList, SBModule, FindTypes, (const char *),
492*0b57cec5SDimitry Andric                      type);
493*0b57cec5SDimitry Andric 
494*0b57cec5SDimitry Andric   SBTypeList retval;
495*0b57cec5SDimitry Andric 
496*0b57cec5SDimitry Andric   ModuleSP module_sp(GetSP());
497*0b57cec5SDimitry Andric   if (type && module_sp) {
498*0b57cec5SDimitry Andric     TypeList type_list;
499*0b57cec5SDimitry Andric     const bool exact_match = false;
500*0b57cec5SDimitry Andric     ConstString name(type);
501*0b57cec5SDimitry Andric     llvm::DenseSet<SymbolFile *> searched_symbol_files;
5029dba64beSDimitry Andric     module_sp->FindTypes(name, exact_match, UINT32_MAX, searched_symbol_files,
5039dba64beSDimitry Andric                          type_list);
504*0b57cec5SDimitry Andric 
5059dba64beSDimitry Andric     if (type_list.Empty()) {
5069dba64beSDimitry Andric       auto type_system_or_err =
5079dba64beSDimitry Andric           module_sp->GetTypeSystemForLanguage(eLanguageTypeC);
5089dba64beSDimitry Andric       if (auto err = type_system_or_err.takeError()) {
5099dba64beSDimitry Andric         llvm::consumeError(std::move(err));
5109dba64beSDimitry Andric       } else {
5119dba64beSDimitry Andric         CompilerType compiler_type =
5129dba64beSDimitry Andric             type_system_or_err->GetBuiltinTypeByName(name);
5139dba64beSDimitry Andric         if (compiler_type)
5149dba64beSDimitry Andric           retval.Append(SBType(compiler_type));
5159dba64beSDimitry Andric       }
5169dba64beSDimitry Andric     } else {
5179dba64beSDimitry Andric       for (size_t idx = 0; idx < type_list.GetSize(); idx++) {
518*0b57cec5SDimitry Andric         TypeSP type_sp(type_list.GetTypeAtIndex(idx));
519*0b57cec5SDimitry Andric         if (type_sp)
520*0b57cec5SDimitry Andric           retval.Append(SBType(type_sp));
521*0b57cec5SDimitry Andric       }
522*0b57cec5SDimitry Andric     }
523*0b57cec5SDimitry Andric   }
524*0b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(retval);
525*0b57cec5SDimitry Andric }
526*0b57cec5SDimitry Andric 
527*0b57cec5SDimitry Andric lldb::SBType SBModule::GetTypeByID(lldb::user_id_t uid) {
528*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD(lldb::SBType, SBModule, GetTypeByID, (lldb::user_id_t),
529*0b57cec5SDimitry Andric                      uid);
530*0b57cec5SDimitry Andric 
531*0b57cec5SDimitry Andric   ModuleSP module_sp(GetSP());
532*0b57cec5SDimitry Andric   if (module_sp) {
5339dba64beSDimitry Andric     if (SymbolFile *symfile = module_sp->GetSymbolFile()) {
5349dba64beSDimitry Andric       Type *type_ptr = symfile->ResolveTypeUID(uid);
535*0b57cec5SDimitry Andric       if (type_ptr)
536*0b57cec5SDimitry Andric         return LLDB_RECORD_RESULT(SBType(type_ptr->shared_from_this()));
537*0b57cec5SDimitry Andric     }
538*0b57cec5SDimitry Andric   }
539*0b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(SBType());
540*0b57cec5SDimitry Andric }
541*0b57cec5SDimitry Andric 
542*0b57cec5SDimitry Andric lldb::SBTypeList SBModule::GetTypes(uint32_t type_mask) {
543*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD(lldb::SBTypeList, SBModule, GetTypes, (uint32_t),
544*0b57cec5SDimitry Andric                      type_mask);
545*0b57cec5SDimitry Andric 
546*0b57cec5SDimitry Andric   SBTypeList sb_type_list;
547*0b57cec5SDimitry Andric 
548*0b57cec5SDimitry Andric   ModuleSP module_sp(GetSP());
549*0b57cec5SDimitry Andric   if (!module_sp)
550*0b57cec5SDimitry Andric     return LLDB_RECORD_RESULT(sb_type_list);
5519dba64beSDimitry Andric   SymbolFile *symfile = module_sp->GetSymbolFile();
5529dba64beSDimitry Andric   if (!symfile)
553*0b57cec5SDimitry Andric     return LLDB_RECORD_RESULT(sb_type_list);
554*0b57cec5SDimitry Andric 
555*0b57cec5SDimitry Andric   TypeClass type_class = static_cast<TypeClass>(type_mask);
556*0b57cec5SDimitry Andric   TypeList type_list;
5579dba64beSDimitry Andric   symfile->GetTypes(nullptr, type_class, type_list);
558*0b57cec5SDimitry Andric   sb_type_list.m_opaque_up->Append(type_list);
559*0b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(sb_type_list);
560*0b57cec5SDimitry Andric }
561*0b57cec5SDimitry Andric 
562*0b57cec5SDimitry Andric SBSection SBModule::FindSection(const char *sect_name) {
563*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD(lldb::SBSection, SBModule, FindSection, (const char *),
564*0b57cec5SDimitry Andric                      sect_name);
565*0b57cec5SDimitry Andric 
566*0b57cec5SDimitry Andric   SBSection sb_section;
567*0b57cec5SDimitry Andric 
568*0b57cec5SDimitry Andric   ModuleSP module_sp(GetSP());
569*0b57cec5SDimitry Andric   if (sect_name && module_sp) {
570*0b57cec5SDimitry Andric     // Give the symbol vendor a chance to add to the unified section list.
5719dba64beSDimitry Andric     module_sp->GetSymbolFile();
572*0b57cec5SDimitry Andric     SectionList *section_list = module_sp->GetSectionList();
573*0b57cec5SDimitry Andric     if (section_list) {
574*0b57cec5SDimitry Andric       ConstString const_sect_name(sect_name);
575*0b57cec5SDimitry Andric       SectionSP section_sp(section_list->FindSectionByName(const_sect_name));
576*0b57cec5SDimitry Andric       if (section_sp) {
577*0b57cec5SDimitry Andric         sb_section.SetSP(section_sp);
578*0b57cec5SDimitry Andric       }
579*0b57cec5SDimitry Andric     }
580*0b57cec5SDimitry Andric   }
581*0b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(sb_section);
582*0b57cec5SDimitry Andric }
583*0b57cec5SDimitry Andric 
584*0b57cec5SDimitry Andric lldb::ByteOrder SBModule::GetByteOrder() {
585*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD_NO_ARGS(lldb::ByteOrder, SBModule, GetByteOrder);
586*0b57cec5SDimitry Andric 
587*0b57cec5SDimitry Andric   ModuleSP module_sp(GetSP());
588*0b57cec5SDimitry Andric   if (module_sp)
589*0b57cec5SDimitry Andric     return module_sp->GetArchitecture().GetByteOrder();
590*0b57cec5SDimitry Andric   return eByteOrderInvalid;
591*0b57cec5SDimitry Andric }
592*0b57cec5SDimitry Andric 
593*0b57cec5SDimitry Andric const char *SBModule::GetTriple() {
594*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD_NO_ARGS(const char *, SBModule, GetTriple);
595*0b57cec5SDimitry Andric 
596*0b57cec5SDimitry Andric   ModuleSP module_sp(GetSP());
597*0b57cec5SDimitry Andric   if (module_sp) {
598*0b57cec5SDimitry Andric     std::string triple(module_sp->GetArchitecture().GetTriple().str());
599*0b57cec5SDimitry Andric     // Unique the string so we don't run into ownership issues since the const
600*0b57cec5SDimitry Andric     // strings put the string into the string pool once and the strings never
601*0b57cec5SDimitry Andric     // comes out
602*0b57cec5SDimitry Andric     ConstString const_triple(triple.c_str());
603*0b57cec5SDimitry Andric     return const_triple.GetCString();
604*0b57cec5SDimitry Andric   }
605*0b57cec5SDimitry Andric   return nullptr;
606*0b57cec5SDimitry Andric }
607*0b57cec5SDimitry Andric 
608*0b57cec5SDimitry Andric uint32_t SBModule::GetAddressByteSize() {
609*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBModule, GetAddressByteSize);
610*0b57cec5SDimitry Andric 
611*0b57cec5SDimitry Andric   ModuleSP module_sp(GetSP());
612*0b57cec5SDimitry Andric   if (module_sp)
613*0b57cec5SDimitry Andric     return module_sp->GetArchitecture().GetAddressByteSize();
614*0b57cec5SDimitry Andric   return sizeof(void *);
615*0b57cec5SDimitry Andric }
616*0b57cec5SDimitry Andric 
617*0b57cec5SDimitry Andric uint32_t SBModule::GetVersion(uint32_t *versions, uint32_t num_versions) {
618*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD(uint32_t, SBModule, GetVersion, (uint32_t *, uint32_t),
619*0b57cec5SDimitry Andric                      versions, num_versions);
620*0b57cec5SDimitry Andric 
621*0b57cec5SDimitry Andric   llvm::VersionTuple version;
622*0b57cec5SDimitry Andric   if (ModuleSP module_sp = GetSP())
623*0b57cec5SDimitry Andric     version = module_sp->GetVersion();
624*0b57cec5SDimitry Andric   uint32_t result = 0;
625*0b57cec5SDimitry Andric   if (!version.empty())
626*0b57cec5SDimitry Andric     ++result;
627*0b57cec5SDimitry Andric   if (version.getMinor())
628*0b57cec5SDimitry Andric     ++result;
629*0b57cec5SDimitry Andric   if (version.getSubminor())
630*0b57cec5SDimitry Andric     ++result;
631*0b57cec5SDimitry Andric 
632*0b57cec5SDimitry Andric   if (!versions)
633*0b57cec5SDimitry Andric     return result;
634*0b57cec5SDimitry Andric 
635*0b57cec5SDimitry Andric   if (num_versions > 0)
636*0b57cec5SDimitry Andric     versions[0] = version.empty() ? UINT32_MAX : version.getMajor();
637*0b57cec5SDimitry Andric   if (num_versions > 1)
638*0b57cec5SDimitry Andric     versions[1] = version.getMinor().getValueOr(UINT32_MAX);
639*0b57cec5SDimitry Andric   if (num_versions > 2)
640*0b57cec5SDimitry Andric     versions[2] = version.getSubminor().getValueOr(UINT32_MAX);
641*0b57cec5SDimitry Andric   for (uint32_t i = 3; i < num_versions; ++i)
642*0b57cec5SDimitry Andric     versions[i] = UINT32_MAX;
643*0b57cec5SDimitry Andric   return result;
644*0b57cec5SDimitry Andric }
645*0b57cec5SDimitry Andric 
646*0b57cec5SDimitry Andric lldb::SBFileSpec SBModule::GetSymbolFileSpec() const {
647*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBFileSpec, SBModule,
648*0b57cec5SDimitry Andric                                    GetSymbolFileSpec);
649*0b57cec5SDimitry Andric 
650*0b57cec5SDimitry Andric   lldb::SBFileSpec sb_file_spec;
651*0b57cec5SDimitry Andric   ModuleSP module_sp(GetSP());
652*0b57cec5SDimitry Andric   if (module_sp) {
6539dba64beSDimitry Andric     if (SymbolFile *symfile = module_sp->GetSymbolFile())
6549dba64beSDimitry Andric       sb_file_spec.SetFileSpec(symfile->GetObjectFile()->GetFileSpec());
655*0b57cec5SDimitry Andric   }
656*0b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(sb_file_spec);
657*0b57cec5SDimitry Andric }
658*0b57cec5SDimitry Andric 
659*0b57cec5SDimitry Andric lldb::SBAddress SBModule::GetObjectFileHeaderAddress() const {
660*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBAddress, SBModule,
661*0b57cec5SDimitry Andric                                    GetObjectFileHeaderAddress);
662*0b57cec5SDimitry Andric 
663*0b57cec5SDimitry Andric   lldb::SBAddress sb_addr;
664*0b57cec5SDimitry Andric   ModuleSP module_sp(GetSP());
665*0b57cec5SDimitry Andric   if (module_sp) {
666*0b57cec5SDimitry Andric     ObjectFile *objfile_ptr = module_sp->GetObjectFile();
667*0b57cec5SDimitry Andric     if (objfile_ptr)
668*0b57cec5SDimitry Andric       sb_addr.ref() = objfile_ptr->GetBaseAddress();
669*0b57cec5SDimitry Andric   }
670*0b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(sb_addr);
671*0b57cec5SDimitry Andric }
672*0b57cec5SDimitry Andric 
673*0b57cec5SDimitry Andric lldb::SBAddress SBModule::GetObjectFileEntryPointAddress() const {
674*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBAddress, SBModule,
675*0b57cec5SDimitry Andric                                    GetObjectFileEntryPointAddress);
676*0b57cec5SDimitry Andric 
677*0b57cec5SDimitry Andric   lldb::SBAddress sb_addr;
678*0b57cec5SDimitry Andric   ModuleSP module_sp(GetSP());
679*0b57cec5SDimitry Andric   if (module_sp) {
680*0b57cec5SDimitry Andric     ObjectFile *objfile_ptr = module_sp->GetObjectFile();
681*0b57cec5SDimitry Andric     if (objfile_ptr)
682*0b57cec5SDimitry Andric       sb_addr.ref() = objfile_ptr->GetEntryPointAddress();
683*0b57cec5SDimitry Andric   }
684*0b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(sb_addr);
685*0b57cec5SDimitry Andric }
686*0b57cec5SDimitry Andric 
6875ffd83dbSDimitry Andric uint32_t SBModule::GetNumberAllocatedModules() {
6885ffd83dbSDimitry Andric   LLDB_RECORD_STATIC_METHOD_NO_ARGS(uint32_t, SBModule,
6895ffd83dbSDimitry Andric                                     GetNumberAllocatedModules);
6905ffd83dbSDimitry Andric 
6915ffd83dbSDimitry Andric   return Module::GetNumberAllocatedModules();
6925ffd83dbSDimitry Andric }
6935ffd83dbSDimitry Andric 
694e8d8bef9SDimitry Andric void SBModule::GarbageCollectAllocatedModules() {
695e8d8bef9SDimitry Andric   LLDB_RECORD_STATIC_METHOD_NO_ARGS(void, SBModule,
696e8d8bef9SDimitry Andric                                     GarbageCollectAllocatedModules);
697e8d8bef9SDimitry Andric 
698e8d8bef9SDimitry Andric   const bool mandatory = false;
699e8d8bef9SDimitry Andric   ModuleList::RemoveOrphanSharedModules(mandatory);
700e8d8bef9SDimitry Andric }
701e8d8bef9SDimitry Andric 
702*0b57cec5SDimitry Andric namespace lldb_private {
703*0b57cec5SDimitry Andric namespace repro {
704*0b57cec5SDimitry Andric 
705e8d8bef9SDimitry Andric template <> void RegisterMethods<SBModule>(Registry &R) {
706*0b57cec5SDimitry Andric   LLDB_REGISTER_CONSTRUCTOR(SBModule, ());
707*0b57cec5SDimitry Andric   LLDB_REGISTER_CONSTRUCTOR(SBModule, (const lldb::SBModuleSpec &));
708*0b57cec5SDimitry Andric   LLDB_REGISTER_CONSTRUCTOR(SBModule, (const lldb::SBModule &));
709*0b57cec5SDimitry Andric   LLDB_REGISTER_CONSTRUCTOR(SBModule, (lldb::SBProcess &, lldb::addr_t));
710e8d8bef9SDimitry Andric   LLDB_REGISTER_METHOD(const lldb::SBModule &, SBModule, operator=,
711e8d8bef9SDimitry Andric                        (const lldb::SBModule &));
712*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD_CONST(bool, SBModule, IsValid, ());
713*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD_CONST(bool, SBModule, operator bool, ());
714*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(void, SBModule, Clear, ());
715*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD_CONST(lldb::SBFileSpec, SBModule, GetFileSpec, ());
716*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD_CONST(lldb::SBFileSpec, SBModule, GetPlatformFileSpec,
717*0b57cec5SDimitry Andric                              ());
718*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(bool, SBModule, SetPlatformFileSpec,
719*0b57cec5SDimitry Andric                        (const lldb::SBFileSpec &));
720*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBFileSpec, SBModule, GetRemoteInstallFileSpec,
721*0b57cec5SDimitry Andric                        ());
722*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(bool, SBModule, SetRemoteInstallFileSpec,
723*0b57cec5SDimitry Andric                        (lldb::SBFileSpec &));
724*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD_CONST(const char *, SBModule, GetUUIDString, ());
725e8d8bef9SDimitry Andric   LLDB_REGISTER_METHOD_CONST(bool, SBModule, operator==,
726e8d8bef9SDimitry Andric                              (const lldb::SBModule &));
727e8d8bef9SDimitry Andric   LLDB_REGISTER_METHOD_CONST(bool, SBModule, operator!=,
728e8d8bef9SDimitry Andric                              (const lldb::SBModule &));
729*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBAddress, SBModule, ResolveFileAddress,
730*0b57cec5SDimitry Andric                        (lldb::addr_t));
731*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBSymbolContext, SBModule,
732*0b57cec5SDimitry Andric                        ResolveSymbolContextForAddress,
733*0b57cec5SDimitry Andric                        (const lldb::SBAddress &, uint32_t));
734*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(bool, SBModule, GetDescription, (lldb::SBStream &));
735*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(uint32_t, SBModule, GetNumCompileUnits, ());
736*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBCompileUnit, SBModule, GetCompileUnitAtIndex,
737*0b57cec5SDimitry Andric                        (uint32_t));
738*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBSymbolContextList, SBModule, FindCompileUnits,
739*0b57cec5SDimitry Andric                        (const lldb::SBFileSpec &));
740*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(size_t, SBModule, GetNumSymbols, ());
741*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBSymbol, SBModule, GetSymbolAtIndex, (size_t));
742*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBSymbol, SBModule, FindSymbol,
743*0b57cec5SDimitry Andric                        (const char *, lldb::SymbolType));
744*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBSymbolContextList, SBModule, FindSymbols,
745*0b57cec5SDimitry Andric                        (const char *, lldb::SymbolType));
746*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(size_t, SBModule, GetNumSections, ());
747e8d8bef9SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBSection, SBModule, GetSectionAtIndex, (size_t));
748*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBSymbolContextList, SBModule, FindFunctions,
749*0b57cec5SDimitry Andric                        (const char *, uint32_t));
750*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBValueList, SBModule, FindGlobalVariables,
751*0b57cec5SDimitry Andric                        (lldb::SBTarget &, const char *, uint32_t));
752*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBValue, SBModule, FindFirstGlobalVariable,
753*0b57cec5SDimitry Andric                        (lldb::SBTarget &, const char *));
754*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBType, SBModule, FindFirstType, (const char *));
755e8d8bef9SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBType, SBModule, GetBasicType, (lldb::BasicType));
756*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBTypeList, SBModule, FindTypes, (const char *));
757e8d8bef9SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBType, SBModule, GetTypeByID, (lldb::user_id_t));
758*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBTypeList, SBModule, GetTypes, (uint32_t));
759e8d8bef9SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBSection, SBModule, FindSection, (const char *));
760*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::ByteOrder, SBModule, GetByteOrder, ());
761*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(const char *, SBModule, GetTriple, ());
762*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(uint32_t, SBModule, GetAddressByteSize, ());
763e8d8bef9SDimitry Andric   LLDB_REGISTER_METHOD(uint32_t, SBModule, GetVersion, (uint32_t *, uint32_t));
764e8d8bef9SDimitry Andric   LLDB_REGISTER_METHOD_CONST(lldb::SBFileSpec, SBModule, GetSymbolFileSpec, ());
765*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD_CONST(lldb::SBAddress, SBModule,
766*0b57cec5SDimitry Andric                              GetObjectFileHeaderAddress, ());
767*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD_CONST(lldb::SBAddress, SBModule,
768*0b57cec5SDimitry Andric                              GetObjectFileEntryPointAddress, ());
7695ffd83dbSDimitry Andric   LLDB_REGISTER_STATIC_METHOD(uint32_t, SBModule, GetNumberAllocatedModules,
7705ffd83dbSDimitry Andric                               ());
771e8d8bef9SDimitry Andric   LLDB_REGISTER_STATIC_METHOD(void, SBModule, GarbageCollectAllocatedModules,
772e8d8bef9SDimitry Andric                               ());
773*0b57cec5SDimitry Andric }
774*0b57cec5SDimitry Andric 
775e8d8bef9SDimitry Andric } // namespace repro
776e8d8bef9SDimitry Andric } // namespace lldb_private
777