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