1 | //===-- SBType.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/SBType.h" |
10 | #include "Utils.h" |
11 | #include "lldb/API/SBDefines.h" |
12 | #include "lldb/API/SBModule.h" |
13 | #include "lldb/API/SBStream.h" |
14 | #include "lldb/API/SBTypeEnumMember.h" |
15 | #include "lldb/Core/Mangled.h" |
16 | #include "lldb/Symbol/CompilerDecl.h" |
17 | #include "lldb/Symbol/CompilerType.h" |
18 | #include "lldb/Symbol/Type.h" |
19 | #include "lldb/Symbol/TypeSystem.h" |
20 | #include "lldb/Utility/ConstString.h" |
21 | #include "lldb/Utility/DataExtractor.h" |
22 | #include "lldb/Utility/Instrumentation.h" |
23 | #include "lldb/Utility/Scalar.h" |
24 | #include "lldb/Utility/Stream.h" |
25 | #include "lldb/ValueObject/ValueObjectConstResult.h" |
26 | |
27 | #include "llvm/ADT/APSInt.h" |
28 | #include "llvm/Support/MathExtras.h" |
29 | |
30 | #include <memory> |
31 | #include <optional> |
32 | |
33 | using namespace lldb; |
34 | using namespace lldb_private; |
35 | |
36 | SBType::SBType() { LLDB_INSTRUMENT_VA(this); } |
37 | |
38 | SBType::SBType(const CompilerType &type) : m_opaque_sp(new TypeImpl(type)) {} |
39 | |
40 | SBType::SBType(const lldb::TypeSP &type_sp) |
41 | : m_opaque_sp(new TypeImpl(type_sp)) {} |
42 | |
43 | SBType::SBType(const lldb::TypeImplSP &type_impl_sp) |
44 | : m_opaque_sp(type_impl_sp) {} |
45 | |
46 | SBType::SBType(const SBType &rhs) { |
47 | LLDB_INSTRUMENT_VA(this, rhs); |
48 | |
49 | if (this != &rhs) { |
50 | m_opaque_sp = rhs.m_opaque_sp; |
51 | } |
52 | } |
53 | |
54 | // SBType::SBType (TypeImpl* impl) : |
55 | // m_opaque_up(impl) |
56 | //{} |
57 | // |
58 | bool SBType::operator==(SBType &rhs) { |
59 | LLDB_INSTRUMENT_VA(this, rhs); |
60 | |
61 | if (!IsValid()) |
62 | return !rhs.IsValid(); |
63 | |
64 | if (!rhs.IsValid()) |
65 | return false; |
66 | |
67 | return *m_opaque_sp.get() == *rhs.m_opaque_sp.get(); |
68 | } |
69 | |
70 | bool SBType::operator!=(SBType &rhs) { |
71 | LLDB_INSTRUMENT_VA(this, rhs); |
72 | |
73 | if (!IsValid()) |
74 | return rhs.IsValid(); |
75 | |
76 | if (!rhs.IsValid()) |
77 | return true; |
78 | |
79 | return *m_opaque_sp.get() != *rhs.m_opaque_sp.get(); |
80 | } |
81 | |
82 | lldb::TypeImplSP SBType::GetSP() { return m_opaque_sp; } |
83 | |
84 | void SBType::SetSP(const lldb::TypeImplSP &type_impl_sp) { |
85 | m_opaque_sp = type_impl_sp; |
86 | } |
87 | |
88 | SBType &SBType::operator=(const SBType &rhs) { |
89 | LLDB_INSTRUMENT_VA(this, rhs); |
90 | |
91 | if (this != &rhs) { |
92 | m_opaque_sp = rhs.m_opaque_sp; |
93 | } |
94 | return *this; |
95 | } |
96 | |
97 | SBType::~SBType() = default; |
98 | |
99 | TypeImpl &SBType::ref() { |
100 | if (m_opaque_sp.get() == nullptr) |
101 | m_opaque_sp = std::make_shared<TypeImpl>(); |
102 | return *m_opaque_sp; |
103 | } |
104 | |
105 | const TypeImpl &SBType::ref() const { |
106 | // "const SBAddress &addr" should already have checked "addr.IsValid()" prior |
107 | // to calling this function. In case you didn't we will assert and die to let |
108 | // you know. |
109 | assert(m_opaque_sp.get()); |
110 | return *m_opaque_sp; |
111 | } |
112 | |
113 | bool SBType::IsValid() const { |
114 | LLDB_INSTRUMENT_VA(this); |
115 | return this->operator bool(); |
116 | } |
117 | SBType::operator bool() const { |
118 | LLDB_INSTRUMENT_VA(this); |
119 | |
120 | if (m_opaque_sp.get() == nullptr) |
121 | return false; |
122 | |
123 | return m_opaque_sp->IsValid(); |
124 | } |
125 | |
126 | uint64_t SBType::GetByteSize() { |
127 | LLDB_INSTRUMENT_VA(this); |
128 | |
129 | if (IsValid()) |
130 | if (std::optional<uint64_t> size = llvm::expectedToOptional( |
131 | E: m_opaque_sp->GetCompilerType(prefer_dynamic: false).GetByteSize(exe_scope: nullptr))) |
132 | return *size; |
133 | return 0; |
134 | } |
135 | |
136 | uint64_t SBType::GetByteAlign() { |
137 | LLDB_INSTRUMENT_VA(this); |
138 | |
139 | if (!IsValid()) |
140 | return 0; |
141 | |
142 | std::optional<uint64_t> bit_align = |
143 | m_opaque_sp->GetCompilerType(/*prefer_dynamic=*/false) |
144 | .GetTypeBitAlign(exe_scope: nullptr); |
145 | return llvm::divideCeil(Numerator: bit_align.value_or(u: 0), Denominator: 8); |
146 | } |
147 | |
148 | bool SBType::IsPointerType() { |
149 | LLDB_INSTRUMENT_VA(this); |
150 | |
151 | if (!IsValid()) |
152 | return false; |
153 | return m_opaque_sp->GetCompilerType(prefer_dynamic: true).IsPointerType(); |
154 | } |
155 | |
156 | bool SBType::IsArrayType() { |
157 | LLDB_INSTRUMENT_VA(this); |
158 | |
159 | if (!IsValid()) |
160 | return false; |
161 | return m_opaque_sp->GetCompilerType(prefer_dynamic: true).IsArrayType(element_type: nullptr, size: nullptr, |
162 | is_incomplete: nullptr); |
163 | } |
164 | |
165 | bool SBType::IsVectorType() { |
166 | LLDB_INSTRUMENT_VA(this); |
167 | |
168 | if (!IsValid()) |
169 | return false; |
170 | return m_opaque_sp->GetCompilerType(prefer_dynamic: true).IsVectorType(element_type: nullptr, size: nullptr); |
171 | } |
172 | |
173 | bool SBType::IsReferenceType() { |
174 | LLDB_INSTRUMENT_VA(this); |
175 | |
176 | if (!IsValid()) |
177 | return false; |
178 | return m_opaque_sp->GetCompilerType(prefer_dynamic: true).IsReferenceType(); |
179 | } |
180 | |
181 | SBType SBType::GetPointerType() { |
182 | LLDB_INSTRUMENT_VA(this); |
183 | |
184 | if (!IsValid()) |
185 | return SBType(); |
186 | |
187 | return SBType(TypeImplSP(new TypeImpl(m_opaque_sp->GetPointerType()))); |
188 | } |
189 | |
190 | SBType SBType::GetPointeeType() { |
191 | LLDB_INSTRUMENT_VA(this); |
192 | |
193 | if (!IsValid()) |
194 | return SBType(); |
195 | return SBType(TypeImplSP(new TypeImpl(m_opaque_sp->GetPointeeType()))); |
196 | } |
197 | |
198 | SBType SBType::GetReferenceType() { |
199 | LLDB_INSTRUMENT_VA(this); |
200 | |
201 | if (!IsValid()) |
202 | return SBType(); |
203 | return SBType(TypeImplSP(new TypeImpl(m_opaque_sp->GetReferenceType()))); |
204 | } |
205 | |
206 | SBType SBType::GetTypedefedType() { |
207 | LLDB_INSTRUMENT_VA(this); |
208 | |
209 | if (!IsValid()) |
210 | return SBType(); |
211 | return SBType(TypeImplSP(new TypeImpl(m_opaque_sp->GetTypedefedType()))); |
212 | } |
213 | |
214 | SBType SBType::GetDereferencedType() { |
215 | LLDB_INSTRUMENT_VA(this); |
216 | |
217 | if (!IsValid()) |
218 | return SBType(); |
219 | return SBType(TypeImplSP(new TypeImpl(m_opaque_sp->GetDereferencedType()))); |
220 | } |
221 | |
222 | SBType SBType::GetArrayElementType() { |
223 | LLDB_INSTRUMENT_VA(this); |
224 | |
225 | if (!IsValid()) |
226 | return SBType(); |
227 | return SBType(TypeImplSP(new TypeImpl( |
228 | m_opaque_sp->GetCompilerType(prefer_dynamic: true).GetArrayElementType(exe_scope: nullptr)))); |
229 | } |
230 | |
231 | SBType SBType::GetArrayType(uint64_t size) { |
232 | LLDB_INSTRUMENT_VA(this, size); |
233 | |
234 | if (!IsValid()) |
235 | return SBType(); |
236 | return SBType(TypeImplSP( |
237 | new TypeImpl(m_opaque_sp->GetCompilerType(prefer_dynamic: true).GetArrayType(size)))); |
238 | } |
239 | |
240 | SBType SBType::GetVectorElementType() { |
241 | LLDB_INSTRUMENT_VA(this); |
242 | |
243 | SBType type_sb; |
244 | if (IsValid()) { |
245 | CompilerType vector_element_type; |
246 | if (m_opaque_sp->GetCompilerType(prefer_dynamic: true).IsVectorType(element_type: &vector_element_type, |
247 | size: nullptr)) |
248 | type_sb.SetSP(TypeImplSP(new TypeImpl(vector_element_type))); |
249 | } |
250 | return type_sb; |
251 | } |
252 | |
253 | bool SBType::IsFunctionType() { |
254 | LLDB_INSTRUMENT_VA(this); |
255 | |
256 | if (!IsValid()) |
257 | return false; |
258 | return m_opaque_sp->GetCompilerType(prefer_dynamic: true).IsFunctionType(); |
259 | } |
260 | |
261 | bool SBType::IsPolymorphicClass() { |
262 | LLDB_INSTRUMENT_VA(this); |
263 | |
264 | if (!IsValid()) |
265 | return false; |
266 | return m_opaque_sp->GetCompilerType(prefer_dynamic: true).IsPolymorphicClass(); |
267 | } |
268 | |
269 | bool SBType::IsTypedefType() { |
270 | LLDB_INSTRUMENT_VA(this); |
271 | |
272 | if (!IsValid()) |
273 | return false; |
274 | return m_opaque_sp->GetCompilerType(prefer_dynamic: true).IsTypedefType(); |
275 | } |
276 | |
277 | bool SBType::IsAnonymousType() { |
278 | LLDB_INSTRUMENT_VA(this); |
279 | |
280 | if (!IsValid()) |
281 | return false; |
282 | return m_opaque_sp->GetCompilerType(prefer_dynamic: true).IsAnonymousType(); |
283 | } |
284 | |
285 | bool SBType::IsScopedEnumerationType() { |
286 | LLDB_INSTRUMENT_VA(this); |
287 | |
288 | if (!IsValid()) |
289 | return false; |
290 | return m_opaque_sp->GetCompilerType(prefer_dynamic: true).IsScopedEnumerationType(); |
291 | } |
292 | |
293 | bool SBType::IsAggregateType() { |
294 | LLDB_INSTRUMENT_VA(this); |
295 | |
296 | if (!IsValid()) |
297 | return false; |
298 | return m_opaque_sp->GetCompilerType(prefer_dynamic: true).IsAggregateType(); |
299 | } |
300 | |
301 | lldb::SBType SBType::GetFunctionReturnType() { |
302 | LLDB_INSTRUMENT_VA(this); |
303 | |
304 | if (IsValid()) { |
305 | CompilerType return_type( |
306 | m_opaque_sp->GetCompilerType(prefer_dynamic: true).GetFunctionReturnType()); |
307 | if (return_type.IsValid()) |
308 | return SBType(return_type); |
309 | } |
310 | return lldb::SBType(); |
311 | } |
312 | |
313 | lldb::SBTypeList SBType::GetFunctionArgumentTypes() { |
314 | LLDB_INSTRUMENT_VA(this); |
315 | |
316 | SBTypeList sb_type_list; |
317 | if (IsValid()) { |
318 | CompilerType func_type(m_opaque_sp->GetCompilerType(prefer_dynamic: true)); |
319 | size_t count = func_type.GetNumberOfFunctionArguments(); |
320 | for (size_t i = 0; i < count; i++) { |
321 | sb_type_list.Append(type: SBType(func_type.GetFunctionArgumentAtIndex(index: i))); |
322 | } |
323 | } |
324 | return sb_type_list; |
325 | } |
326 | |
327 | uint32_t SBType::GetNumberOfMemberFunctions() { |
328 | LLDB_INSTRUMENT_VA(this); |
329 | |
330 | if (IsValid()) { |
331 | return m_opaque_sp->GetCompilerType(prefer_dynamic: true).GetNumMemberFunctions(); |
332 | } |
333 | return 0; |
334 | } |
335 | |
336 | lldb::SBTypeMemberFunction SBType::GetMemberFunctionAtIndex(uint32_t idx) { |
337 | LLDB_INSTRUMENT_VA(this, idx); |
338 | |
339 | SBTypeMemberFunction sb_func_type; |
340 | if (IsValid()) |
341 | sb_func_type.reset(new TypeMemberFunctionImpl( |
342 | m_opaque_sp->GetCompilerType(prefer_dynamic: true).GetMemberFunctionAtIndex(idx))); |
343 | return sb_func_type; |
344 | } |
345 | |
346 | SBTypeStaticField::SBTypeStaticField() { LLDB_INSTRUMENT_VA(this); } |
347 | |
348 | SBTypeStaticField::SBTypeStaticField(lldb_private::CompilerDecl decl) |
349 | : m_opaque_up(decl ? std::make_unique<CompilerDecl>(args&: decl) : nullptr) {} |
350 | |
351 | SBTypeStaticField::SBTypeStaticField(const SBTypeStaticField &rhs) { |
352 | LLDB_INSTRUMENT_VA(this, rhs); |
353 | |
354 | m_opaque_up = clone(src: rhs.m_opaque_up); |
355 | } |
356 | |
357 | SBTypeStaticField &SBTypeStaticField::operator=(const SBTypeStaticField &rhs) { |
358 | LLDB_INSTRUMENT_VA(this, rhs); |
359 | |
360 | m_opaque_up = clone(src: rhs.m_opaque_up); |
361 | return *this; |
362 | } |
363 | |
364 | SBTypeStaticField::~SBTypeStaticField() { LLDB_INSTRUMENT_VA(this); } |
365 | |
366 | SBTypeStaticField::operator bool() const { |
367 | LLDB_INSTRUMENT_VA(this); |
368 | |
369 | return IsValid(); |
370 | } |
371 | |
372 | bool SBTypeStaticField::IsValid() const { |
373 | LLDB_INSTRUMENT_VA(this); |
374 | |
375 | return m_opaque_up != nullptr; |
376 | } |
377 | |
378 | const char *SBTypeStaticField::GetName() { |
379 | LLDB_INSTRUMENT_VA(this); |
380 | |
381 | if (!IsValid()) |
382 | return ""; |
383 | return m_opaque_up->GetName().GetCString(); |
384 | } |
385 | |
386 | const char *SBTypeStaticField::GetMangledName() { |
387 | LLDB_INSTRUMENT_VA(this); |
388 | |
389 | if (!IsValid()) |
390 | return ""; |
391 | return m_opaque_up->GetMangledName().GetCString(); |
392 | } |
393 | |
394 | SBType SBTypeStaticField::GetType() { |
395 | LLDB_INSTRUMENT_VA(this); |
396 | |
397 | if (!IsValid()) |
398 | return SBType(); |
399 | return SBType(m_opaque_up->GetType()); |
400 | } |
401 | |
402 | SBValue SBTypeStaticField::GetConstantValue(lldb::SBTarget target) { |
403 | LLDB_INSTRUMENT_VA(this, target); |
404 | |
405 | if (!IsValid()) |
406 | return SBValue(); |
407 | |
408 | Scalar value = m_opaque_up->GetConstantValue(); |
409 | if (!value.IsValid()) |
410 | return SBValue(); |
411 | DataExtractor data; |
412 | value.GetData(data); |
413 | auto value_obj_sp = ValueObjectConstResult::Create( |
414 | exe_scope: target.GetSP().get(), compiler_type: m_opaque_up->GetType(), name: m_opaque_up->GetName(), |
415 | data); |
416 | return SBValue(std::move(value_obj_sp)); |
417 | } |
418 | |
419 | lldb::SBType SBType::GetUnqualifiedType() { |
420 | LLDB_INSTRUMENT_VA(this); |
421 | |
422 | if (!IsValid()) |
423 | return SBType(); |
424 | return SBType(TypeImplSP(new TypeImpl(m_opaque_sp->GetUnqualifiedType()))); |
425 | } |
426 | |
427 | lldb::SBType SBType::GetCanonicalType() { |
428 | LLDB_INSTRUMENT_VA(this); |
429 | |
430 | if (IsValid()) |
431 | return SBType(TypeImplSP(new TypeImpl(m_opaque_sp->GetCanonicalType()))); |
432 | return SBType(); |
433 | } |
434 | |
435 | SBType SBType::GetEnumerationIntegerType() { |
436 | LLDB_INSTRUMENT_VA(this); |
437 | |
438 | if (IsValid()) { |
439 | return SBType( |
440 | m_opaque_sp->GetCompilerType(prefer_dynamic: true).GetEnumerationIntegerType()); |
441 | } |
442 | return SBType(); |
443 | } |
444 | |
445 | lldb::BasicType SBType::GetBasicType() { |
446 | LLDB_INSTRUMENT_VA(this); |
447 | |
448 | if (IsValid()) |
449 | return m_opaque_sp->GetCompilerType(prefer_dynamic: false).GetBasicTypeEnumeration(); |
450 | return eBasicTypeInvalid; |
451 | } |
452 | |
453 | SBType SBType::GetBasicType(lldb::BasicType basic_type) { |
454 | LLDB_INSTRUMENT_VA(this, basic_type); |
455 | |
456 | if (IsValid() && m_opaque_sp->IsValid()) |
457 | if (auto ts = m_opaque_sp->GetTypeSystem(prefer_dynamic: false)) |
458 | return SBType(ts->GetBasicTypeFromAST(basic_type)); |
459 | return SBType(); |
460 | } |
461 | |
462 | uint32_t SBType::GetNumberOfDirectBaseClasses() { |
463 | LLDB_INSTRUMENT_VA(this); |
464 | |
465 | if (IsValid()) |
466 | return m_opaque_sp->GetCompilerType(prefer_dynamic: true).GetNumDirectBaseClasses(); |
467 | return 0; |
468 | } |
469 | |
470 | uint32_t SBType::GetNumberOfVirtualBaseClasses() { |
471 | LLDB_INSTRUMENT_VA(this); |
472 | |
473 | if (IsValid()) |
474 | return m_opaque_sp->GetCompilerType(prefer_dynamic: true).GetNumVirtualBaseClasses(); |
475 | return 0; |
476 | } |
477 | |
478 | uint32_t SBType::GetNumberOfFields() { |
479 | LLDB_INSTRUMENT_VA(this); |
480 | |
481 | if (IsValid()) |
482 | return m_opaque_sp->GetCompilerType(prefer_dynamic: true).GetNumFields(); |
483 | return 0; |
484 | } |
485 | |
486 | bool SBType::GetDescription(SBStream &description, |
487 | lldb::DescriptionLevel description_level) { |
488 | LLDB_INSTRUMENT_VA(this, description, description_level); |
489 | |
490 | Stream &strm = description.ref(); |
491 | |
492 | if (m_opaque_sp) { |
493 | m_opaque_sp->GetDescription(strm, description_level); |
494 | } else |
495 | strm.PutCString(cstr: "No value"); |
496 | |
497 | return true; |
498 | } |
499 | |
500 | SBTypeMember SBType::GetDirectBaseClassAtIndex(uint32_t idx) { |
501 | LLDB_INSTRUMENT_VA(this, idx); |
502 | |
503 | SBTypeMember sb_type_member; |
504 | if (IsValid()) { |
505 | uint32_t bit_offset = 0; |
506 | CompilerType base_class_type = |
507 | m_opaque_sp->GetCompilerType(prefer_dynamic: true).GetDirectBaseClassAtIndex( |
508 | idx, bit_offset_ptr: &bit_offset); |
509 | if (base_class_type.IsValid()) |
510 | sb_type_member.reset(new TypeMemberImpl( |
511 | TypeImplSP(new TypeImpl(base_class_type)), bit_offset)); |
512 | } |
513 | return sb_type_member; |
514 | } |
515 | |
516 | SBTypeMember SBType::GetVirtualBaseClassAtIndex(uint32_t idx) { |
517 | LLDB_INSTRUMENT_VA(this, idx); |
518 | |
519 | SBTypeMember sb_type_member; |
520 | if (IsValid()) { |
521 | uint32_t bit_offset = 0; |
522 | CompilerType base_class_type = |
523 | m_opaque_sp->GetCompilerType(prefer_dynamic: true).GetVirtualBaseClassAtIndex( |
524 | idx, bit_offset_ptr: &bit_offset); |
525 | if (base_class_type.IsValid()) |
526 | sb_type_member.reset(new TypeMemberImpl( |
527 | TypeImplSP(new TypeImpl(base_class_type)), bit_offset)); |
528 | } |
529 | return sb_type_member; |
530 | } |
531 | |
532 | SBTypeStaticField SBType::GetStaticFieldWithName(const char *name) { |
533 | LLDB_INSTRUMENT_VA(this, name); |
534 | |
535 | if (!IsValid() || !name) |
536 | return SBTypeStaticField(); |
537 | |
538 | return SBTypeStaticField(m_opaque_sp->GetCompilerType(/*prefer_dynamic=*/true) |
539 | .GetStaticFieldWithName(name)); |
540 | } |
541 | |
542 | SBTypeEnumMemberList SBType::GetEnumMembers() { |
543 | LLDB_INSTRUMENT_VA(this); |
544 | |
545 | SBTypeEnumMemberList sb_enum_member_list; |
546 | if (IsValid()) { |
547 | CompilerType this_type(m_opaque_sp->GetCompilerType(prefer_dynamic: true)); |
548 | if (this_type.IsValid()) { |
549 | this_type.ForEachEnumerator(callback: [&sb_enum_member_list]( |
550 | const CompilerType &integer_type, |
551 | ConstString name, |
552 | const llvm::APSInt &value) -> bool { |
553 | SBTypeEnumMember enum_member( |
554 | lldb::TypeEnumMemberImplSP(new TypeEnumMemberImpl( |
555 | lldb::TypeImplSP(new TypeImpl(integer_type)), name, value))); |
556 | sb_enum_member_list.Append(entry: enum_member); |
557 | return true; // Keep iterating |
558 | }); |
559 | } |
560 | } |
561 | return sb_enum_member_list; |
562 | } |
563 | |
564 | SBTypeMember SBType::GetFieldAtIndex(uint32_t idx) { |
565 | LLDB_INSTRUMENT_VA(this, idx); |
566 | |
567 | SBTypeMember sb_type_member; |
568 | if (IsValid()) { |
569 | CompilerType this_type(m_opaque_sp->GetCompilerType(prefer_dynamic: false)); |
570 | if (this_type.IsValid()) { |
571 | uint64_t bit_offset = 0; |
572 | uint32_t bitfield_bit_size = 0; |
573 | bool is_bitfield = false; |
574 | std::string name_sstr; |
575 | CompilerType field_type(this_type.GetFieldAtIndex( |
576 | idx, name&: name_sstr, bit_offset_ptr: &bit_offset, bitfield_bit_size_ptr: &bitfield_bit_size, is_bitfield_ptr: &is_bitfield)); |
577 | if (field_type.IsValid()) { |
578 | ConstString name; |
579 | if (!name_sstr.empty()) |
580 | name.SetCString(name_sstr.c_str()); |
581 | sb_type_member.reset( |
582 | new TypeMemberImpl(TypeImplSP(new TypeImpl(field_type)), bit_offset, |
583 | name, bitfield_bit_size, is_bitfield)); |
584 | } |
585 | } |
586 | } |
587 | return sb_type_member; |
588 | } |
589 | |
590 | bool SBType::IsTypeComplete() { |
591 | LLDB_INSTRUMENT_VA(this); |
592 | |
593 | if (!IsValid()) |
594 | return false; |
595 | CompilerType compiler_type = m_opaque_sp->GetCompilerType(prefer_dynamic: false); |
596 | // Only return true if we have a complete type and it wasn't forcefully |
597 | // completed. |
598 | if (compiler_type.IsCompleteType()) |
599 | return !compiler_type.IsForcefullyCompleted(); |
600 | return false; |
601 | } |
602 | |
603 | uint32_t SBType::GetTypeFlags() { |
604 | LLDB_INSTRUMENT_VA(this); |
605 | |
606 | if (!IsValid()) |
607 | return 0; |
608 | return m_opaque_sp->GetCompilerType(prefer_dynamic: true).GetTypeInfo(); |
609 | } |
610 | |
611 | lldb::SBModule SBType::GetModule() { |
612 | LLDB_INSTRUMENT_VA(this); |
613 | |
614 | lldb::SBModule sb_module; |
615 | if (!IsValid()) |
616 | return sb_module; |
617 | |
618 | sb_module.SetSP(m_opaque_sp->GetModule()); |
619 | return sb_module; |
620 | } |
621 | |
622 | const char *SBType::GetName() { |
623 | LLDB_INSTRUMENT_VA(this); |
624 | |
625 | if (!IsValid()) |
626 | return ""; |
627 | return m_opaque_sp->GetName().GetCString(); |
628 | } |
629 | |
630 | const char *SBType::GetDisplayTypeName() { |
631 | LLDB_INSTRUMENT_VA(this); |
632 | |
633 | if (!IsValid()) |
634 | return ""; |
635 | return m_opaque_sp->GetDisplayTypeName().GetCString(); |
636 | } |
637 | |
638 | lldb::TypeClass SBType::GetTypeClass() { |
639 | LLDB_INSTRUMENT_VA(this); |
640 | |
641 | if (IsValid()) |
642 | return m_opaque_sp->GetCompilerType(prefer_dynamic: true).GetTypeClass(); |
643 | return lldb::eTypeClassInvalid; |
644 | } |
645 | |
646 | uint32_t SBType::GetNumberOfTemplateArguments() { |
647 | LLDB_INSTRUMENT_VA(this); |
648 | |
649 | if (IsValid()) |
650 | return m_opaque_sp->GetCompilerType(prefer_dynamic: false).GetNumTemplateArguments( |
651 | /*expand_pack=*/true); |
652 | return 0; |
653 | } |
654 | |
655 | lldb::SBType SBType::GetTemplateArgumentType(uint32_t idx) { |
656 | LLDB_INSTRUMENT_VA(this, idx); |
657 | |
658 | if (!IsValid()) |
659 | return SBType(); |
660 | |
661 | CompilerType type; |
662 | const bool expand_pack = true; |
663 | switch(GetTemplateArgumentKind(idx)) { |
664 | case eTemplateArgumentKindType: |
665 | type = m_opaque_sp->GetCompilerType(prefer_dynamic: false).GetTypeTemplateArgument( |
666 | idx, expand_pack); |
667 | break; |
668 | case eTemplateArgumentKindIntegral: |
669 | type = m_opaque_sp->GetCompilerType(prefer_dynamic: false) |
670 | .GetIntegralTemplateArgument(idx, expand_pack) |
671 | ->type; |
672 | break; |
673 | default: |
674 | break; |
675 | } |
676 | if (type.IsValid()) |
677 | return SBType(type); |
678 | return SBType(); |
679 | } |
680 | |
681 | lldb::TemplateArgumentKind SBType::GetTemplateArgumentKind(uint32_t idx) { |
682 | LLDB_INSTRUMENT_VA(this, idx); |
683 | |
684 | if (IsValid()) |
685 | return m_opaque_sp->GetCompilerType(prefer_dynamic: false).GetTemplateArgumentKind( |
686 | idx, /*expand_pack=*/true); |
687 | return eTemplateArgumentKindNull; |
688 | } |
689 | |
690 | lldb::SBValue SBType::GetTemplateArgumentValue(lldb::SBTarget target, |
691 | uint32_t idx) { |
692 | LLDB_INSTRUMENT_VA(this, target, idx); |
693 | |
694 | if (!IsValid()) |
695 | return {}; |
696 | |
697 | std::optional<CompilerType::IntegralTemplateArgument> arg; |
698 | const bool expand_pack = true; |
699 | switch (GetTemplateArgumentKind(idx)) { |
700 | case eTemplateArgumentKindStructuralValue: |
701 | case eTemplateArgumentKindIntegral: |
702 | arg = m_opaque_sp->GetCompilerType(prefer_dynamic: false).GetIntegralTemplateArgument( |
703 | idx, expand_pack); |
704 | break; |
705 | default: |
706 | break; |
707 | } |
708 | |
709 | if (!arg) |
710 | return {}; |
711 | |
712 | DataExtractor data; |
713 | arg->value.GetData(data); |
714 | |
715 | ExecutionContext exe_ctx; |
716 | auto target_sp = target.GetSP(); |
717 | if (!target_sp) |
718 | return {}; |
719 | |
720 | target_sp->CalculateExecutionContext(exe_ctx); |
721 | |
722 | return ValueObject::CreateValueObjectFromData(name: "value", data, exe_ctx, |
723 | type: arg->type); |
724 | } |
725 | |
726 | SBType SBType::FindDirectNestedType(const char *name) { |
727 | LLDB_INSTRUMENT_VA(this, name); |
728 | |
729 | if (!IsValid()) |
730 | return SBType(); |
731 | return SBType(m_opaque_sp->FindDirectNestedType(name)); |
732 | } |
733 | |
734 | SBTypeList::SBTypeList() : m_opaque_up(new TypeListImpl()) { |
735 | LLDB_INSTRUMENT_VA(this); |
736 | } |
737 | |
738 | SBTypeList::SBTypeList(const SBTypeList &rhs) |
739 | : m_opaque_up(new TypeListImpl()) { |
740 | LLDB_INSTRUMENT_VA(this, rhs); |
741 | |
742 | for (uint32_t i = 0, rhs_size = const_cast<SBTypeList &>(rhs).GetSize(); |
743 | i < rhs_size; i++) |
744 | Append(type: const_cast<SBTypeList &>(rhs).GetTypeAtIndex(index: i)); |
745 | } |
746 | |
747 | bool SBTypeList::IsValid() { |
748 | LLDB_INSTRUMENT_VA(this); |
749 | return this->operator bool(); |
750 | } |
751 | SBTypeList::operator bool() const { |
752 | LLDB_INSTRUMENT_VA(this); |
753 | |
754 | return (m_opaque_up != nullptr); |
755 | } |
756 | |
757 | SBTypeList &SBTypeList::operator=(const SBTypeList &rhs) { |
758 | LLDB_INSTRUMENT_VA(this, rhs); |
759 | |
760 | if (this != &rhs) { |
761 | m_opaque_up = std::make_unique<TypeListImpl>(); |
762 | for (uint32_t i = 0, rhs_size = const_cast<SBTypeList &>(rhs).GetSize(); |
763 | i < rhs_size; i++) |
764 | Append(type: const_cast<SBTypeList &>(rhs).GetTypeAtIndex(index: i)); |
765 | } |
766 | return *this; |
767 | } |
768 | |
769 | void SBTypeList::Append(SBType type) { |
770 | LLDB_INSTRUMENT_VA(this, type); |
771 | |
772 | if (type.IsValid()) |
773 | m_opaque_up->Append(type: type.m_opaque_sp); |
774 | } |
775 | |
776 | SBType SBTypeList::GetTypeAtIndex(uint32_t index) { |
777 | LLDB_INSTRUMENT_VA(this, index); |
778 | |
779 | if (m_opaque_up) |
780 | return SBType(m_opaque_up->GetTypeAtIndex(idx: index)); |
781 | return SBType(); |
782 | } |
783 | |
784 | uint32_t SBTypeList::GetSize() { |
785 | LLDB_INSTRUMENT_VA(this); |
786 | |
787 | return m_opaque_up->GetSize(); |
788 | } |
789 | |
790 | SBTypeList::~SBTypeList() = default; |
791 | |
792 | SBTypeMember::SBTypeMember() { LLDB_INSTRUMENT_VA(this); } |
793 | |
794 | SBTypeMember::~SBTypeMember() = default; |
795 | |
796 | SBTypeMember::SBTypeMember(const SBTypeMember &rhs) { |
797 | LLDB_INSTRUMENT_VA(this, rhs); |
798 | |
799 | if (this != &rhs) { |
800 | if (rhs.IsValid()) |
801 | m_opaque_up = std::make_unique<TypeMemberImpl>(args: rhs.ref()); |
802 | } |
803 | } |
804 | |
805 | lldb::SBTypeMember &SBTypeMember::operator=(const lldb::SBTypeMember &rhs) { |
806 | LLDB_INSTRUMENT_VA(this, rhs); |
807 | |
808 | if (this != &rhs) { |
809 | if (rhs.IsValid()) |
810 | m_opaque_up = std::make_unique<TypeMemberImpl>(args: rhs.ref()); |
811 | } |
812 | return *this; |
813 | } |
814 | |
815 | bool SBTypeMember::IsValid() const { |
816 | LLDB_INSTRUMENT_VA(this); |
817 | return this->operator bool(); |
818 | } |
819 | SBTypeMember::operator bool() const { |
820 | LLDB_INSTRUMENT_VA(this); |
821 | |
822 | return m_opaque_up.get(); |
823 | } |
824 | |
825 | const char *SBTypeMember::GetName() { |
826 | LLDB_INSTRUMENT_VA(this); |
827 | |
828 | if (m_opaque_up) |
829 | return m_opaque_up->GetName().GetCString(); |
830 | return nullptr; |
831 | } |
832 | |
833 | SBType SBTypeMember::GetType() { |
834 | LLDB_INSTRUMENT_VA(this); |
835 | |
836 | SBType sb_type; |
837 | if (m_opaque_up) { |
838 | sb_type.SetSP(m_opaque_up->GetTypeImpl()); |
839 | } |
840 | return sb_type; |
841 | } |
842 | |
843 | uint64_t SBTypeMember::GetOffsetInBytes() { |
844 | LLDB_INSTRUMENT_VA(this); |
845 | |
846 | if (m_opaque_up) |
847 | return m_opaque_up->GetBitOffset() / 8u; |
848 | return 0; |
849 | } |
850 | |
851 | uint64_t SBTypeMember::GetOffsetInBits() { |
852 | LLDB_INSTRUMENT_VA(this); |
853 | |
854 | if (m_opaque_up) |
855 | return m_opaque_up->GetBitOffset(); |
856 | return 0; |
857 | } |
858 | |
859 | bool SBTypeMember::IsBitfield() { |
860 | LLDB_INSTRUMENT_VA(this); |
861 | |
862 | if (m_opaque_up) |
863 | return m_opaque_up->GetIsBitfield(); |
864 | return false; |
865 | } |
866 | |
867 | uint32_t SBTypeMember::GetBitfieldSizeInBits() { |
868 | LLDB_INSTRUMENT_VA(this); |
869 | |
870 | if (m_opaque_up) |
871 | return m_opaque_up->GetBitfieldBitSize(); |
872 | return 0; |
873 | } |
874 | |
875 | bool SBTypeMember::GetDescription(lldb::SBStream &description, |
876 | lldb::DescriptionLevel description_level) { |
877 | LLDB_INSTRUMENT_VA(this, description, description_level); |
878 | |
879 | Stream &strm = description.ref(); |
880 | |
881 | if (m_opaque_up) { |
882 | const uint32_t bit_offset = m_opaque_up->GetBitOffset(); |
883 | const uint32_t byte_offset = bit_offset / 8u; |
884 | const uint32_t byte_bit_offset = bit_offset % 8u; |
885 | const char *name = m_opaque_up->GetName().GetCString(); |
886 | if (byte_bit_offset) |
887 | strm.Printf(format: "+%u + %u bits: (", byte_offset, byte_bit_offset); |
888 | else |
889 | strm.Printf(format: "+%u: (", byte_offset); |
890 | |
891 | TypeImplSP type_impl_sp(m_opaque_up->GetTypeImpl()); |
892 | if (type_impl_sp) |
893 | type_impl_sp->GetDescription(strm, description_level); |
894 | |
895 | strm.Printf(format: ") %s", name); |
896 | if (m_opaque_up->GetIsBitfield()) { |
897 | const uint32_t bitfield_bit_size = m_opaque_up->GetBitfieldBitSize(); |
898 | strm.Printf(format: " : %u", bitfield_bit_size); |
899 | } |
900 | } else { |
901 | strm.PutCString(cstr: "No value"); |
902 | } |
903 | return true; |
904 | } |
905 | |
906 | void SBTypeMember::reset(TypeMemberImpl *type_member_impl) { |
907 | m_opaque_up.reset(p: type_member_impl); |
908 | } |
909 | |
910 | TypeMemberImpl &SBTypeMember::ref() { |
911 | if (m_opaque_up == nullptr) |
912 | m_opaque_up = std::make_unique<TypeMemberImpl>(); |
913 | return *m_opaque_up; |
914 | } |
915 | |
916 | const TypeMemberImpl &SBTypeMember::ref() const { return *m_opaque_up; } |
917 | |
918 | SBTypeMemberFunction::SBTypeMemberFunction() { LLDB_INSTRUMENT_VA(this); } |
919 | |
920 | SBTypeMemberFunction::~SBTypeMemberFunction() = default; |
921 | |
922 | SBTypeMemberFunction::SBTypeMemberFunction(const SBTypeMemberFunction &rhs) |
923 | : m_opaque_sp(rhs.m_opaque_sp) { |
924 | LLDB_INSTRUMENT_VA(this, rhs); |
925 | } |
926 | |
927 | lldb::SBTypeMemberFunction &SBTypeMemberFunction:: |
928 | operator=(const lldb::SBTypeMemberFunction &rhs) { |
929 | LLDB_INSTRUMENT_VA(this, rhs); |
930 | |
931 | if (this != &rhs) |
932 | m_opaque_sp = rhs.m_opaque_sp; |
933 | return *this; |
934 | } |
935 | |
936 | bool SBTypeMemberFunction::IsValid() const { |
937 | LLDB_INSTRUMENT_VA(this); |
938 | return this->operator bool(); |
939 | } |
940 | SBTypeMemberFunction::operator bool() const { |
941 | LLDB_INSTRUMENT_VA(this); |
942 | |
943 | return m_opaque_sp.get(); |
944 | } |
945 | |
946 | const char *SBTypeMemberFunction::GetName() { |
947 | LLDB_INSTRUMENT_VA(this); |
948 | |
949 | if (m_opaque_sp) |
950 | return m_opaque_sp->GetName().GetCString(); |
951 | return nullptr; |
952 | } |
953 | |
954 | const char *SBTypeMemberFunction::GetDemangledName() { |
955 | LLDB_INSTRUMENT_VA(this); |
956 | |
957 | if (!m_opaque_sp) |
958 | return nullptr; |
959 | |
960 | ConstString mangled_str = m_opaque_sp->GetMangledName(); |
961 | if (!mangled_str) |
962 | return nullptr; |
963 | |
964 | Mangled mangled(mangled_str); |
965 | return mangled.GetDemangledName().GetCString(); |
966 | } |
967 | |
968 | const char *SBTypeMemberFunction::GetMangledName() { |
969 | LLDB_INSTRUMENT_VA(this); |
970 | |
971 | if (m_opaque_sp) |
972 | return m_opaque_sp->GetMangledName().GetCString(); |
973 | return nullptr; |
974 | } |
975 | |
976 | SBType SBTypeMemberFunction::GetType() { |
977 | LLDB_INSTRUMENT_VA(this); |
978 | |
979 | SBType sb_type; |
980 | if (m_opaque_sp) { |
981 | sb_type.SetSP(lldb::TypeImplSP(new TypeImpl(m_opaque_sp->GetType()))); |
982 | } |
983 | return sb_type; |
984 | } |
985 | |
986 | lldb::SBType SBTypeMemberFunction::GetReturnType() { |
987 | LLDB_INSTRUMENT_VA(this); |
988 | |
989 | SBType sb_type; |
990 | if (m_opaque_sp) { |
991 | sb_type.SetSP(lldb::TypeImplSP(new TypeImpl(m_opaque_sp->GetReturnType()))); |
992 | } |
993 | return sb_type; |
994 | } |
995 | |
996 | uint32_t SBTypeMemberFunction::GetNumberOfArguments() { |
997 | LLDB_INSTRUMENT_VA(this); |
998 | |
999 | if (m_opaque_sp) |
1000 | return m_opaque_sp->GetNumArguments(); |
1001 | return 0; |
1002 | } |
1003 | |
1004 | lldb::SBType SBTypeMemberFunction::GetArgumentTypeAtIndex(uint32_t i) { |
1005 | LLDB_INSTRUMENT_VA(this, i); |
1006 | |
1007 | SBType sb_type; |
1008 | if (m_opaque_sp) { |
1009 | sb_type.SetSP( |
1010 | lldb::TypeImplSP(new TypeImpl(m_opaque_sp->GetArgumentAtIndex(idx: i)))); |
1011 | } |
1012 | return sb_type; |
1013 | } |
1014 | |
1015 | lldb::MemberFunctionKind SBTypeMemberFunction::GetKind() { |
1016 | LLDB_INSTRUMENT_VA(this); |
1017 | |
1018 | if (m_opaque_sp) |
1019 | return m_opaque_sp->GetKind(); |
1020 | return lldb::eMemberFunctionKindUnknown; |
1021 | } |
1022 | |
1023 | bool SBTypeMemberFunction::GetDescription( |
1024 | lldb::SBStream &description, lldb::DescriptionLevel description_level) { |
1025 | LLDB_INSTRUMENT_VA(this, description, description_level); |
1026 | |
1027 | Stream &strm = description.ref(); |
1028 | |
1029 | if (m_opaque_sp) |
1030 | return m_opaque_sp->GetDescription(stream&: strm); |
1031 | |
1032 | return false; |
1033 | } |
1034 | |
1035 | void SBTypeMemberFunction::reset(TypeMemberFunctionImpl *type_member_impl) { |
1036 | m_opaque_sp.reset(p: type_member_impl); |
1037 | } |
1038 | |
1039 | TypeMemberFunctionImpl &SBTypeMemberFunction::ref() { |
1040 | if (!m_opaque_sp) |
1041 | m_opaque_sp = std::make_shared<TypeMemberFunctionImpl>(); |
1042 | return *m_opaque_sp.get(); |
1043 | } |
1044 | |
1045 | const TypeMemberFunctionImpl &SBTypeMemberFunction::ref() const { |
1046 | return *m_opaque_sp.get(); |
1047 | } |
1048 |
Definitions
- SBType
- SBType
- SBType
- SBType
- SBType
- operator==
- operator!=
- GetSP
- SetSP
- operator=
- ~SBType
- ref
- ref
- IsValid
- operator bool
- GetByteSize
- GetByteAlign
- IsPointerType
- IsArrayType
- IsVectorType
- IsReferenceType
- GetPointerType
- GetPointeeType
- GetReferenceType
- GetTypedefedType
- GetDereferencedType
- GetArrayElementType
- GetArrayType
- GetVectorElementType
- IsFunctionType
- IsPolymorphicClass
- IsTypedefType
- IsAnonymousType
- IsScopedEnumerationType
- IsAggregateType
- GetFunctionReturnType
- GetFunctionArgumentTypes
- GetNumberOfMemberFunctions
- GetMemberFunctionAtIndex
- SBTypeStaticField
- SBTypeStaticField
- SBTypeStaticField
- operator=
- ~SBTypeStaticField
- operator bool
- IsValid
- GetName
- GetMangledName
- GetType
- GetConstantValue
- GetUnqualifiedType
- GetCanonicalType
- GetEnumerationIntegerType
- GetBasicType
- GetBasicType
- GetNumberOfDirectBaseClasses
- GetNumberOfVirtualBaseClasses
- GetNumberOfFields
- GetDescription
- GetDirectBaseClassAtIndex
- GetVirtualBaseClassAtIndex
- GetStaticFieldWithName
- GetEnumMembers
- GetFieldAtIndex
- IsTypeComplete
- GetTypeFlags
- GetModule
- GetName
- GetDisplayTypeName
- GetTypeClass
- GetNumberOfTemplateArguments
- GetTemplateArgumentType
- GetTemplateArgumentKind
- GetTemplateArgumentValue
- FindDirectNestedType
- SBTypeList
- SBTypeList
- IsValid
- operator bool
- operator=
- Append
- GetTypeAtIndex
- GetSize
- ~SBTypeList
- SBTypeMember
- ~SBTypeMember
- SBTypeMember
- operator=
- IsValid
- operator bool
- GetName
- GetType
- GetOffsetInBytes
- GetOffsetInBits
- IsBitfield
- GetBitfieldSizeInBits
- GetDescription
- reset
- ref
- ref
- SBTypeMemberFunction
- ~SBTypeMemberFunction
- SBTypeMemberFunction
- operator=
- IsValid
- operator bool
- GetName
- GetDemangledName
- GetMangledName
- GetType
- GetReturnType
- GetNumberOfArguments
- GetArgumentTypeAtIndex
- GetKind
- GetDescription
- reset
- ref
Learn to use CMake with our Intro Training
Find out more