LLDB mainline
Type.cpp
Go to the documentation of this file.
1//===-- Type.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 <cstdio>
10#include <optional>
11
12#include "lldb/Core/Module.h"
16#include "lldb/Utility/Log.h"
17#include "lldb/Utility/Scalar.h"
19
25#include "lldb/Symbol/Type.h"
28
30#include "lldb/Target/Process.h"
31#include "lldb/Target/Target.h"
32
33#include "llvm/ADT/StringRef.h"
34
35using namespace lldb;
36using namespace lldb_private;
37
38bool lldb_private::contextMatches(llvm::ArrayRef<CompilerContext> context_chain,
39 llvm::ArrayRef<CompilerContext> pattern) {
40 auto ctx = context_chain.begin();
41 auto ctx_end = context_chain.end();
42 for (const CompilerContext &pat : pattern) {
43 // Early exit if the pattern is too long.
44 if (ctx == ctx_end)
45 return false;
46 if (*ctx != pat) {
47 // Skip any number of module matches.
48 if (pat.kind == CompilerContextKind::AnyModule) {
49 // Greedily match 0..n modules.
50 ctx = std::find_if(ctx, ctx_end, [](const CompilerContext &ctx) {
51 return ctx.kind != CompilerContextKind::Module;
52 });
53 continue;
54 }
55 // See if there is a kind mismatch; they should have 1 bit in common.
56 if (((uint16_t)ctx->kind & (uint16_t)pat.kind) == 0)
57 return false;
58 // The name is ignored for AnyModule, but not for AnyType.
59 if (pat.kind != CompilerContextKind::AnyModule && ctx->name != pat.name)
60 return false;
61 }
62 ++ctx;
63 }
64 return true;
65}
66
68 switch (kind) {
69 default:
70 printf("Invalid");
71 break;
73 printf("TranslationUnit");
74 break;
76 printf("Module");
77 break;
79 printf("Namespace");
80 break;
82 printf("Class");
83 break;
85 printf("Structure");
86 break;
88 printf("Union");
89 break;
91 printf("Function");
92 break;
94 printf("Variable");
95 break;
97 printf("Enumeration");
98 break;
100 printf("Typedef");
101 break;
103 printf("AnyModule");
104 break;
106 printf("AnyType");
107 break;
108 }
109 printf("(\"%s\")\n", name.GetCString());
110}
111
113public:
114 TypeAppendVisitor(TypeListImpl &type_list) : m_type_list(type_list) {}
115
116 bool operator()(const lldb::TypeSP &type) {
117 m_type_list.Append(TypeImplSP(new TypeImpl(type)));
118 return true;
119 }
120
121private:
123};
124
126 TypeAppendVisitor cb(*this);
127 type_list.ForEach(cb);
128}
129
131 const lldb::TypeSP &type_sp)
132 : UserID(type_sp ? type_sp->GetID() : LLDB_INVALID_UID),
133 m_symbol_file(symbol_file), m_type_sp(type_sp) {}
134
136 if (!m_type_sp) {
137 Type *resolved_type = m_symbol_file.ResolveTypeUID(GetID());
138 if (resolved_type)
139 m_type_sp = resolved_type->shared_from_this();
140 }
141 return m_type_sp.get();
142}
143
145 std::optional<uint64_t> byte_size, SymbolContextScope *context,
146 user_id_t encoding_uid, EncodingDataType encoding_uid_type,
147 const Declaration &decl, const CompilerType &compiler_type,
148 ResolveState compiler_type_resolve_state, uint32_t opaque_payload)
149 : std::enable_shared_from_this<Type>(), UserID(uid), m_name(name),
150 m_symbol_file(symbol_file), m_context(context),
151 m_encoding_uid(encoding_uid), m_encoding_uid_type(encoding_uid_type),
152 m_decl(decl), m_compiler_type(compiler_type),
153 m_compiler_type_resolve_state(compiler_type ? compiler_type_resolve_state
154 : ResolveState::Unresolved),
155 m_payload(opaque_payload) {
156 if (byte_size) {
157 m_byte_size = *byte_size;
159 } else {
160 m_byte_size = 0;
161 m_byte_size_has_value = false;
162 }
163}
164
166 : std::enable_shared_from_this<Type>(), UserID(0), m_name("<INVALID TYPE>"),
167 m_payload(0) {
168 m_byte_size = 0;
169 m_byte_size_has_value = false;
170}
171
173 bool show_name, ExecutionContextScope *exe_scope) {
174 *s << "id = " << (const UserID &)*this;
175
176 // Call the name accessor to make sure we resolve the type name
177 if (show_name) {
178 ConstString type_name = GetName();
179 if (type_name) {
180 *s << ", name = \"" << type_name << '"';
181 ConstString qualified_type_name(GetQualifiedName());
182 if (qualified_type_name != type_name) {
183 *s << ", qualified = \"" << qualified_type_name << '"';
184 }
185 }
186 }
187
188 // Call the get byte size accessor so we resolve our byte size
189 if (GetByteSize(exe_scope))
190 s->Printf(", byte-size = %" PRIu64, m_byte_size);
191 bool show_fullpaths = (level == lldb::eDescriptionLevelVerbose);
192 m_decl.Dump(s, show_fullpaths);
193
194 if (m_compiler_type.IsValid()) {
195 *s << ", compiler_type = \"";
197 *s << '"';
198 } else if (m_encoding_uid != LLDB_INVALID_UID) {
199 s->Printf(", type_uid = 0x%8.8" PRIx64, m_encoding_uid);
200 switch (m_encoding_uid_type) {
201 case eEncodingInvalid:
202 break;
203 case eEncodingIsUID:
204 s->PutCString(" (unresolved type)");
205 break;
207 s->PutCString(" (unresolved const type)");
208 break;
210 s->PutCString(" (unresolved restrict type)");
211 break;
213 s->PutCString(" (unresolved volatile type)");
214 break;
216 s->PutCString(" (unresolved atomic type)");
217 break;
219 s->PutCString(" (unresolved typedef)");
220 break;
222 s->PutCString(" (unresolved pointer)");
223 break;
225 s->PutCString(" (unresolved L value reference)");
226 break;
228 s->PutCString(" (unresolved R value reference)");
229 break;
231 s->PutCString(" (synthetic type)");
232 break;
233 }
234 }
235}
236
237void Type::Dump(Stream *s, bool show_context, lldb::DescriptionLevel level) {
238 s->Printf("%p: ", static_cast<void *>(this));
239 s->Indent();
240 *s << "Type" << static_cast<const UserID &>(*this) << ' ';
241 if (m_name)
242 *s << ", name = \"" << m_name << "\"";
243
245 s->Printf(", size = %" PRIu64, m_byte_size);
246
247 if (show_context && m_context != nullptr) {
248 s->PutCString(", context = ( ");
250 s->PutCString(" )");
251 }
252
253 bool show_fullpaths = false;
254 m_decl.Dump(s, show_fullpaths);
255
256 if (m_compiler_type.IsValid()) {
257 *s << ", compiler_type = " << m_compiler_type.GetOpaqueQualType() << ' ';
259 } else if (m_encoding_uid != LLDB_INVALID_UID) {
260 s->Format(", type_data = {0:x-16}", m_encoding_uid);
261 switch (m_encoding_uid_type) {
262 case eEncodingInvalid:
263 break;
264 case eEncodingIsUID:
265 s->PutCString(" (unresolved type)");
266 break;
268 s->PutCString(" (unresolved const type)");
269 break;
271 s->PutCString(" (unresolved restrict type)");
272 break;
274 s->PutCString(" (unresolved volatile type)");
275 break;
277 s->PutCString(" (unresolved atomic type)");
278 break;
280 s->PutCString(" (unresolved typedef)");
281 break;
283 s->PutCString(" (unresolved pointer)");
284 break;
286 s->PutCString(" (unresolved L value reference)");
287 break;
289 s->PutCString(" (unresolved R value reference)");
290 break;
292 s->PutCString(" (synthetic type)");
293 break;
294 }
295 }
296
297 //
298 // if (m_access)
299 // s->Printf(", access = %u", m_access);
300 s->EOL();
301}
302
304 if (!m_name)
306 return m_name;
307}
308
310 return GetForwardCompilerType().GetTypeName(/*BaseOnly*/ true);
311}
312
313void Type::DumpTypeName(Stream *s) { GetName().Dump(s, "<invalid-type-name>"); }
314
316 const DataExtractor &data, uint32_t data_byte_offset,
317 bool show_types, bool show_summary, bool verbose,
318 lldb::Format format) {
320 if (show_types) {
321 s->PutChar('(');
322 if (verbose)
323 s->Printf("Type{0x%8.8" PRIx64 "} ", GetID());
324 DumpTypeName(s);
325 s->PutCString(") ");
326 }
327
329 exe_ctx, s, format == lldb::eFormatDefault ? GetFormat() : format, data,
330 data_byte_offset,
331 GetByteSize(exe_ctx ? exe_ctx->GetBestExecutionContextScope() : nullptr)
332 .value_or(0),
333 0, // Bitfield bit size
334 0, // Bitfield bit offset
335 show_types, show_summary, verbose, 0);
336 }
337}
338
342 return m_encoding_type;
343}
344
345std::optional<uint64_t> Type::GetByteSize(ExecutionContextScope *exe_scope) {
347 return static_cast<uint64_t>(m_byte_size);
348
349 switch (m_encoding_uid_type) {
350 case eEncodingInvalid:
352 break;
353 case eEncodingIsUID:
359 Type *encoding_type = GetEncodingType();
360 if (encoding_type)
361 if (std::optional<uint64_t> size =
362 encoding_type->GetByteSize(exe_scope)) {
363 m_byte_size = *size;
365 return static_cast<uint64_t>(m_byte_size);
366 }
367
368 if (std::optional<uint64_t> size =
369 GetLayoutCompilerType().GetByteSize(exe_scope)) {
370 m_byte_size = *size;
372 return static_cast<uint64_t>(m_byte_size);
373 }
374 } break;
375
376 // If we are a pointer or reference, then this is just a pointer size;
381 m_byte_size = arch.GetAddressByteSize();
383 return static_cast<uint64_t>(m_byte_size);
384 }
385 } break;
386 }
387 return {};
388}
389
390uint32_t Type::GetNumChildren(bool omit_empty_base_classes) {
391 return GetForwardCompilerType().GetNumChildren(omit_empty_base_classes, nullptr);
392}
393
396}
397
400}
401
402lldb::TypeSP Type::GetTypedefType() {
403 lldb::TypeSP type_sp;
404 if (IsTypedef()) {
406 if (typedef_type)
407 type_sp = typedef_type->shared_from_this();
408 }
409 return type_sp;
410}
411
413
415 // Make sure we resolve our type if it already hasn't been.
416 return GetForwardCompilerType().GetEncoding(count);
417}
418
420 lldb::addr_t address, AddressType address_type,
421 bool show_types, bool show_summary, bool verbose) {
422 if (address != LLDB_INVALID_ADDRESS) {
423 DataExtractor data;
424 Target *target = nullptr;
425 if (exe_ctx)
426 target = exe_ctx->GetTargetPtr();
427 if (target)
428 data.SetByteOrder(target->GetArchitecture().GetByteOrder());
429 if (ReadFromMemory(exe_ctx, address, address_type, data)) {
430 DumpValue(exe_ctx, s, data, 0, show_types, show_summary, verbose);
431 return true;
432 }
433 }
434 return false;
435}
436
438 AddressType address_type, DataExtractor &data) {
439 if (address_type == eAddressTypeFile) {
440 // Can't convert a file address to anything valid without more context
441 // (which Module it came from)
442 return false;
443 }
444
445 const uint64_t byte_size =
446 GetByteSize(exe_ctx ? exe_ctx->GetBestExecutionContextScope() : nullptr)
447 .value_or(0);
448 if (data.GetByteSize() < byte_size) {
449 lldb::DataBufferSP data_sp(new DataBufferHeap(byte_size, '\0'));
450 data.SetData(data_sp);
451 }
452
453 uint8_t *dst = const_cast<uint8_t *>(data.PeekData(0, byte_size));
454 if (dst != nullptr) {
455 if (address_type == eAddressTypeHost) {
456 // The address is an address in this process, so just copy it
457 if (addr == 0)
458 return false;
459 memcpy(dst, reinterpret_cast<uint8_t *>(addr), byte_size);
460 return true;
461 } else {
462 if (exe_ctx) {
463 Process *process = exe_ctx->GetProcessPtr();
464 if (process) {
466 return exe_ctx->GetProcessPtr()->ReadMemory(addr, dst, byte_size,
467 error) == byte_size;
468 }
469 }
470 }
471 }
472 return false;
473}
474
476 AddressType address_type, DataExtractor &data) {
477 return false;
478}
479
480const Declaration &Type::GetDeclaration() const { return m_decl; }
481
482bool Type::ResolveCompilerType(ResolveState compiler_type_resolve_state) {
483 // TODO: This needs to consider the correct type system to use.
484 Type *encoding_type = nullptr;
485 if (!m_compiler_type.IsValid()) {
486 encoding_type = GetEncodingType();
487 if (encoding_type) {
488 switch (m_encoding_uid_type) {
489 case eEncodingIsUID: {
490 CompilerType encoding_compiler_type =
491 encoding_type->GetForwardCompilerType();
492 if (encoding_compiler_type.IsValid()) {
493 m_compiler_type = encoding_compiler_type;
495 encoding_type->m_compiler_type_resolve_state;
496 }
497 } break;
498
501 encoding_type->GetForwardCompilerType().AddConstModifier();
502 break;
503
507 break;
508
512 break;
513
516 encoding_type->GetForwardCompilerType().GetAtomicType();
517 break;
518
521 m_name.AsCString("__lldb_invalid_typedef_name"),
522 GetSymbolFile()->GetDeclContextContainingUID(GetID()), m_payload);
523 m_name.Clear();
524 break;
525
528 encoding_type->GetForwardCompilerType().GetPointerType();
529 break;
530
534 break;
535
539 break;
540
541 default:
542 llvm_unreachable("Unhandled encoding_data_type.");
543 }
544 } else {
545 // We have no encoding type, return void?
546 auto type_system_or_err =
548 if (auto err = type_system_or_err.takeError()) {
549 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
550 "Unable to construct void type from TypeSystemClang");
551 } else {
552 CompilerType void_compiler_type;
553 auto ts = *type_system_or_err;
554 if (ts)
555 void_compiler_type = ts->GetBasicTypeFromAST(eBasicTypeVoid);
556 switch (m_encoding_uid_type) {
557 case eEncodingIsUID:
558 m_compiler_type = void_compiler_type;
559 break;
560
562 m_compiler_type = void_compiler_type.AddConstModifier();
563 break;
564
566 m_compiler_type = void_compiler_type.AddRestrictModifier();
567 break;
568
570 m_compiler_type = void_compiler_type.AddVolatileModifier();
571 break;
572
574 m_compiler_type = void_compiler_type.GetAtomicType();
575 break;
576
578 m_compiler_type = void_compiler_type.CreateTypedef(
579 m_name.AsCString("__lldb_invalid_typedef_name"),
580 GetSymbolFile()->GetDeclContextContainingUID(GetID()), m_payload);
581 break;
582
584 m_compiler_type = void_compiler_type.GetPointerType();
585 break;
586
588 m_compiler_type = void_compiler_type.GetLValueReferenceType();
589 break;
590
592 m_compiler_type = void_compiler_type.GetRValueReferenceType();
593 break;
594
595 default:
596 llvm_unreachable("Unhandled encoding_data_type.");
597 }
598 }
599 }
600
601 // When we have a EncodingUID, our "m_flags.compiler_type_resolve_state" is
602 // set to eResolveStateUnresolved so we need to update it to say that we
603 // now have a forward declaration since that is what we created above.
606 }
607
608 // Check if we have a forward reference to a class/struct/union/enum?
609 if (compiler_type_resolve_state == ResolveState::Layout ||
610 compiler_type_resolve_state == ResolveState::Full) {
611 // Check if we have a forward reference to a class/struct/union/enum?
612 if (m_compiler_type.IsValid() &&
613 m_compiler_type_resolve_state < compiler_type_resolve_state) {
615 if (!m_compiler_type.IsDefined()) {
616 // We have a forward declaration, we need to resolve it to a complete
617 // definition.
619 }
620 }
621 }
622
623 // If we have an encoding type, then we need to make sure it is resolved
624 // appropriately.
626 if (encoding_type == nullptr)
627 encoding_type = GetEncodingType();
628 if (encoding_type) {
629 ResolveState encoding_compiler_type_resolve_state =
630 compiler_type_resolve_state;
631
632 if (compiler_type_resolve_state == ResolveState::Layout) {
633 switch (m_encoding_uid_type) {
637 encoding_compiler_type_resolve_state = ResolveState::Forward;
638 break;
639 default:
640 break;
641 }
642 }
643 encoding_type->ResolveCompilerType(encoding_compiler_type_resolve_state);
644 }
645 }
646 return m_compiler_type.IsValid();
647}
649 uint32_t encoding_mask = 1u << m_encoding_uid_type;
650 Type *encoding_type = GetEncodingType();
651 assert(encoding_type != this);
652 if (encoding_type)
653 encoding_mask |= encoding_type->GetEncodingMask();
654 return encoding_mask;
655}
656
659 return m_compiler_type;
660}
661
664 return m_compiler_type;
665}
666
669 return m_compiler_type;
670}
671
674}
675
676bool Type::GetTypeScopeAndBasename(llvm::StringRef name,
677 llvm::StringRef &scope,
678 llvm::StringRef &basename,
679 TypeClass &type_class) {
680 type_class = eTypeClassAny;
681
682 if (name.empty())
683 return false;
684
685 basename = name;
686 if (basename.consume_front("struct "))
687 type_class = eTypeClassStruct;
688 else if (basename.consume_front("class "))
689 type_class = eTypeClassClass;
690 else if (basename.consume_front("union "))
691 type_class = eTypeClassUnion;
692 else if (basename.consume_front("enum "))
693 type_class = eTypeClassEnumeration;
694 else if (basename.consume_front("typedef "))
695 type_class = eTypeClassTypedef;
696
697 size_t namespace_separator = basename.find("::");
698 if (namespace_separator == llvm::StringRef::npos)
699 return false;
700
701 size_t template_begin = basename.find('<');
702 while (namespace_separator != llvm::StringRef::npos) {
703 if (template_begin != llvm::StringRef::npos &&
704 namespace_separator > template_begin) {
705 size_t template_depth = 1;
706 llvm::StringRef template_arg =
707 basename.drop_front(template_begin + 1);
708 while (template_depth > 0 && !template_arg.empty()) {
709 if (template_arg.front() == '<')
710 template_depth++;
711 else if (template_arg.front() == '>')
712 template_depth--;
713 template_arg = template_arg.drop_front(1);
714 }
715 if (template_depth != 0)
716 return false; // We have an invalid type name. Bail out.
717 if (template_arg.empty())
718 break; // The template ends at the end of the full name.
719 basename = template_arg;
720 } else {
721 basename = basename.drop_front(namespace_separator + 2);
722 }
723 template_begin = basename.find('<');
724 namespace_separator = basename.find("::");
725 }
726 if (basename.size() < name.size()) {
727 scope = name.take_front(name.size() - basename.size());
728 return true;
729 }
730 return false;
731}
732
733ModuleSP Type::GetModule() {
734 if (m_symbol_file)
736 return ModuleSP();
737}
738
740 if (m_compiler_type) {
741 auto ts = m_compiler_type.GetTypeSystem();
742 if (!ts)
743 return {};
744 SymbolFile *symbol_file = ts->GetSymbolFile();
745 if (symbol_file)
746 return symbol_file->GetObjectFile()->GetModule();
747 }
748 return {};
749}
750
751TypeAndOrName::TypeAndOrName(TypeSP &in_type_sp) {
752 if (in_type_sp) {
753 m_compiler_type = in_type_sp->GetForwardCompilerType();
754 m_type_name = in_type_sp->GetName();
755 }
756}
757
758TypeAndOrName::TypeAndOrName(const char *in_type_str)
759 : m_type_name(in_type_str) {}
760
762 : m_type_name(in_type_const_string) {}
763
764bool TypeAndOrName::operator==(const TypeAndOrName &other) const {
765 if (m_compiler_type != other.m_compiler_type)
766 return false;
767 if (m_type_name != other.m_type_name)
768 return false;
769 return true;
770}
771
772bool TypeAndOrName::operator!=(const TypeAndOrName &other) const {
773 return !(*this == other);
774}
775
777 if (m_type_name)
778 return m_type_name;
779 if (m_compiler_type)
781 return ConstString("<invalid>");
782}
783
785 m_type_name = type_name;
786}
787
788void TypeAndOrName::SetName(const char *type_name_cstr) {
789 m_type_name.SetCString(type_name_cstr);
790}
791
792void TypeAndOrName::SetTypeSP(lldb::TypeSP type_sp) {
793 if (type_sp) {
794 m_compiler_type = type_sp->GetForwardCompilerType();
795 m_type_name = type_sp->GetName();
796 } else
797 Clear();
798}
799
801 m_compiler_type = compiler_type;
802 if (m_compiler_type)
804}
805
807 return !((bool)m_type_name || (bool)m_compiler_type);
808}
809
813}
814
815bool TypeAndOrName::HasName() const { return (bool)m_type_name; }
816
818 return m_compiler_type.IsValid();
819}
820
821TypeImpl::TypeImpl(const lldb::TypeSP &type_sp)
822 : m_module_wp(), m_static_type(), m_dynamic_type() {
823 SetType(type_sp);
824}
825
826TypeImpl::TypeImpl(const CompilerType &compiler_type)
827 : m_module_wp(), m_static_type(), m_dynamic_type() {
828 SetType(compiler_type);
829}
830
831TypeImpl::TypeImpl(const lldb::TypeSP &type_sp, const CompilerType &dynamic)
832 : m_module_wp(), m_static_type(), m_dynamic_type(dynamic) {
833 SetType(type_sp, dynamic);
834}
835
837 const CompilerType &dynamic_type)
838 : m_module_wp(), m_static_type(), m_dynamic_type() {
839 SetType(static_type, dynamic_type);
840}
841
842void TypeImpl::SetType(const lldb::TypeSP &type_sp) {
843 if (type_sp) {
844 m_static_type = type_sp->GetForwardCompilerType();
845 m_exe_module_wp = type_sp->GetExeModule();
846 m_module_wp = type_sp->GetModule();
847 } else {
849 m_module_wp = lldb::ModuleWP();
850 }
851}
852
853void TypeImpl::SetType(const CompilerType &compiler_type) {
854 m_module_wp = lldb::ModuleWP();
855 m_static_type = compiler_type;
856}
857
858void TypeImpl::SetType(const lldb::TypeSP &type_sp,
859 const CompilerType &dynamic) {
860 SetType(type_sp);
861 m_dynamic_type = dynamic;
862}
863
864void TypeImpl::SetType(const CompilerType &compiler_type,
865 const CompilerType &dynamic) {
866 m_module_wp = lldb::ModuleWP();
867 m_static_type = compiler_type;
868 m_dynamic_type = dynamic;
869}
870
871bool TypeImpl::CheckModule(lldb::ModuleSP &module_sp) const {
872 return CheckModuleCommon(m_module_wp, module_sp);
873}
874
875bool TypeImpl::CheckExeModule(lldb::ModuleSP &module_sp) const {
876 return CheckModuleCommon(m_exe_module_wp, module_sp);
877}
878
879bool TypeImpl::CheckModuleCommon(const lldb::ModuleWP &input_module_wp,
880 lldb::ModuleSP &module_sp) const {
881 // Check if we have a module for this type. If we do and the shared pointer
882 // is can be successfully initialized with m_module_wp, return true. Else
883 // return false if we didn't have a module, or if we had a module and it has
884 // been deleted. Any functions doing anything with a TypeSP in this TypeImpl
885 // class should call this function and only do anything with the ivars if
886 // this function returns true. If we have a module, the "module_sp" will be
887 // filled in with a strong reference to the module so that the module will at
888 // least stay around long enough for the type query to succeed.
889 module_sp = input_module_wp.lock();
890 if (!module_sp) {
891 lldb::ModuleWP empty_module_wp;
892 // If either call to "std::weak_ptr::owner_before(...) value returns true,
893 // this indicates that m_module_wp once contained (possibly still does) a
894 // reference to a valid shared pointer. This helps us know if we had a
895 // valid reference to a section which is now invalid because the module it
896 // was in was deleted
897 if (empty_module_wp.owner_before(input_module_wp) ||
898 input_module_wp.owner_before(empty_module_wp)) {
899 // input_module_wp had a valid reference to a module, but all strong
900 // references have been released and the module has been deleted
901 return false;
902 }
903 }
904 // We either successfully locked the module, or didn't have one to begin with
905 return true;
906}
907
908bool TypeImpl::operator==(const TypeImpl &rhs) const {
909 return m_static_type == rhs.m_static_type &&
911}
912
913bool TypeImpl::operator!=(const TypeImpl &rhs) const {
914 return !(*this == rhs);
915}
916
917bool TypeImpl::IsValid() const {
918 // just a name is not valid
919 ModuleSP module_sp;
920 if (CheckModule(module_sp))
922 return false;
923}
924
925TypeImpl::operator bool() const { return IsValid(); }
926
928 m_module_wp = lldb::ModuleWP();
931}
932
933ModuleSP TypeImpl::GetModule() const {
934 lldb::ModuleSP module_sp;
935 if (CheckExeModule(module_sp))
936 return module_sp;
937 return nullptr;
938}
939
941 ModuleSP module_sp;
942 if (CheckModule(module_sp)) {
943 if (m_dynamic_type)
945 return m_static_type.GetTypeName();
946 }
947 return ConstString();
948}
949
951 ModuleSP module_sp;
952 if (CheckModule(module_sp)) {
953 if (m_dynamic_type)
956 }
957 return ConstString();
958}
959
961 ModuleSP module_sp;
962 if (CheckModule(module_sp)) {
963 if (m_dynamic_type.IsValid()) {
966 }
968 }
969 return TypeImpl();
970}
971
973 ModuleSP module_sp;
974 if (CheckModule(module_sp)) {
975 if (m_dynamic_type.IsValid()) {
978 }
980 }
981 return TypeImpl();
982}
983
985 ModuleSP module_sp;
986 if (CheckModule(module_sp)) {
987 if (m_dynamic_type.IsValid()) {
990 }
992 }
993 return TypeImpl();
994}
995
997 ModuleSP module_sp;
998 if (CheckModule(module_sp)) {
999 if (m_dynamic_type.IsValid()) {
1002 }
1004 }
1005 return TypeImpl();
1006}
1007
1009 ModuleSP module_sp;
1010 if (CheckModule(module_sp)) {
1011 if (m_dynamic_type.IsValid()) {
1014 }
1016 }
1017 return TypeImpl();
1018}
1019
1021 ModuleSP module_sp;
1022 if (CheckModule(module_sp)) {
1023 if (m_dynamic_type.IsValid()) {
1026 }
1028 }
1029 return TypeImpl();
1030}
1031
1033 ModuleSP module_sp;
1034 if (CheckModule(module_sp)) {
1035 if (m_dynamic_type.IsValid()) {
1038 }
1040 }
1041 return TypeImpl();
1042}
1043
1045 ModuleSP module_sp;
1046 if (CheckModule(module_sp)) {
1047 if (prefer_dynamic) {
1048 if (m_dynamic_type.IsValid())
1049 return m_dynamic_type;
1050 }
1051 return m_static_type;
1052 }
1053 return CompilerType();
1054}
1055
1057 ModuleSP module_sp;
1058 if (CheckModule(module_sp)) {
1059 if (prefer_dynamic) {
1060 if (m_dynamic_type.IsValid())
1062 }
1064 }
1065 return {};
1066}
1067
1069 lldb::DescriptionLevel description_level) {
1070 ModuleSP module_sp;
1071 if (CheckModule(module_sp)) {
1072 if (m_dynamic_type.IsValid()) {
1073 strm.Printf("Dynamic:\n");
1075 strm.Printf("\nStatic:\n");
1076 }
1078 } else {
1079 strm.PutCString("Invalid TypeImpl module for type has been deleted\n");
1080 }
1081 return true;
1082}
1083
1086}
1087
1089
1091 return m_decl.GetMangledName();
1092}
1093
1095
1097 return m_kind;
1098}
1099
1101 switch (m_kind) {
1103 return false;
1105 stream.Printf("constructor for %s",
1106 m_type.GetTypeName().AsCString("<unknown>"));
1107 break;
1109 stream.Printf("destructor for %s",
1110 m_type.GetTypeName().AsCString("<unknown>"));
1111 break;
1113 stream.Printf("instance method %s of type %s", m_name.AsCString(),
1115 break;
1117 stream.Printf("static method %s of type %s", m_name.AsCString(),
1119 break;
1120 }
1121 return true;
1122}
1123
1125 if (m_type)
1128}
1129
1131 if (m_type)
1133 else
1135}
1136
1138 if (m_type)
1140 else
1141 return m_decl.GetFunctionArgumentType(idx);
1142}
1143
1144TypeEnumMemberImpl::TypeEnumMemberImpl(const lldb::TypeImplSP &integer_type_sp,
1145 ConstString name,
1146 const llvm::APSInt &value)
1147 : m_integer_type_sp(integer_type_sp), m_name(name), m_value(value),
1148 m_valid((bool)name && (bool)integer_type_sp)
1149
1150{}
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_LOG_ERROR(log, error,...)
Definition: Log.h:365
bool operator()(const lldb::TypeSP &type)
Definition: Type.cpp:116
TypeListImpl & m_type_list
Definition: Type.cpp:122
TypeAppendVisitor(TypeListImpl &type_list)
Definition: Type.cpp:114
An architecture specification class.
Definition: ArchSpec.h:31
lldb::ByteOrder GetByteOrder() const
Returns the byte order for the architecture specification.
Definition: ArchSpec.cpp:738
ConstString GetMangledName() const
CompilerType GetFunctionArgumentType(size_t arg_idx) const
CompilerType GetFunctionReturnType() const
CompilerDeclContext GetDeclContext() const
size_t GetNumFunctionArguments() const
This is a minimal wrapper of a TypeSystem shared pointer as returned by CompilerType which conventien...
Definition: CompilerType.h:52
Generic representation of a type in a programming language.
Definition: CompilerType.h:36
TypeSystemSPWrapper GetTypeSystem() const
Accessors.
CompilerType GetBasicTypeFromAST(lldb::BasicType basic_type) const
Create related types using the current type's AST.
std::optional< uint64_t > GetByteSize(ExecutionContextScope *exe_scope) const
Return the size of the type in bytes.
CompilerType AddConstModifier() const
Return a new CompilerType adds a const modifier to this type if this type is valid and the type syste...
lldb::Encoding GetEncoding(uint64_t &count) const
ConstString GetDisplayTypeName() const
CompilerType GetRValueReferenceType() const
Return a new CompilerType that is a R value reference to this type if this type is valid and the type...
CompilerType GetPointerType() const
Return a new CompilerType that is a pointer to this type.
lldb::opaque_compiler_type_t GetOpaqueQualType() const
Definition: CompilerType.h:234
CompilerType AddVolatileModifier() const
Return a new CompilerType adds a volatile modifier to this type if this type is valid and the type sy...
CompilerType AddRestrictModifier() const
Return a new CompilerType adds a restrict modifier to this type if this type is valid and the type sy...
CompilerType GetFunctionArgumentAtIndex(const size_t index) const
void DumpValue(ExecutionContext *exe_ctx, Stream *s, lldb::Format format, const DataExtractor &data, lldb::offset_t data_offset, size_t data_byte_size, uint32_t bitfield_bit_size, uint32_t bitfield_bit_offset, bool show_types, bool show_summary, bool verbose, uint32_t depth)
CompilerType GetLValueReferenceType() const
Return a new CompilerType that is a L value reference to this type if this type is valid and the type...
size_t GetNumberOfFunctionArguments() const
CompilerType GetNonReferenceType() const
If this type is a reference to a type (L value or R value reference), return a new type with the refe...
uint32_t GetNumChildren(bool omit_empty_base_classes, const ExecutionContext *exe_ctx) const
ConstString GetTypeName(bool BaseOnly=false) const
CompilerType GetTypedefedType() const
If the current object represents a typedef type, get the underlying type.
lldb::Format GetFormat() const
CompilerType GetFullyUnqualifiedType() const
CompilerType GetPointeeType() const
If this type is a pointer type, return the type that the pointer points to, else return an invalid ty...
CompilerType CreateTypedef(const char *name, const CompilerDeclContext &decl_ctx, uint32_t payload) const
Create a typedef to this type using "name" as the name of the typedef this type is valid and the type...
CompilerType GetFunctionReturnType() const
CompilerType GetAtomicType() const
Return a new CompilerType that is the atomic type of this type.
CompilerType GetCanonicalType() const
void DumpTypeDescription(lldb::DescriptionLevel level=lldb::eDescriptionLevelFull) const
Dump to stdout.
A uniqued constant string class.
Definition: ConstString.h:40
void SetCString(const char *cstr)
Set the C string value.
const char * AsCString(const char *value_if_empty=nullptr) const
Get the string value as a C string.
Definition: ConstString.h:198
void Dump(Stream *s, const char *value_if_empty=nullptr) const
Dump the object description to a stream.
void Clear()
Clear this object's state.
Definition: ConstString.h:237
const char * GetCString() const
Get the string value as a C string.
Definition: ConstString.h:221
A subclass of DataBuffer that stores a data buffer on the heap.
An data extractor class.
Definition: DataExtractor.h:48
const uint8_t * PeekData(lldb::offset_t offset, lldb::offset_t length) const
Peek at a bytes at offset.
void SetByteOrder(lldb::ByteOrder byte_order)
Set the byte_order value.
uint64_t GetByteSize() const
Get the number of bytes contained in this object.
lldb::offset_t SetData(const void *bytes, lldb::offset_t length, lldb::ByteOrder byte_order)
Set data with a buffer that is caller owned.
A class that describes the declaration location of a lldb object.
Definition: Declaration.h:24
void Dump(Stream *s, bool show_fullpaths) const
Dump a description of this object to a Stream.
Definition: Declaration.cpp:14
"lldb/Target/ExecutionContextScope.h" Inherit from this if your object can reconstruct its execution ...
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
ExecutionContextScope * GetBestExecutionContextScope() const
Target * GetTargetPtr() const
Returns a pointer to the target object.
Process * GetProcessPtr() const
Returns a pointer to the process object.
lldb::ModuleSP GetModule() const
Get const accessor for the module pointer.
Definition: ModuleChild.cpp:24
virtual ArchSpec GetArchitecture()=0
Get the ArchSpec for this object file.
A plug-in interface definition class for debugging a process.
Definition: Process.h:335
virtual size_t ReadMemory(lldb::addr_t vm_addr, void *buf, size_t size, Status &error)
Read of memory from a process.
Definition: Process.cpp:1941
An error handling class.
Definition: Status.h:44
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
void Format(const char *format, Args &&... args)
Definition: Stream.h:309
size_t Indent(llvm::StringRef s="")
Indent the current line in the stream.
Definition: Stream.cpp:130
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition: Stream.cpp:107
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition: Stream.cpp:63
size_t PutChar(char ch)
Definition: Stream.cpp:104
size_t EOL()
Output and End of Line character to the stream.
Definition: Stream.cpp:128
"lldb/Symbol/SymbolContextScope.h" Inherit from this if your object is part of a symbol context and c...
virtual void DumpSymbolContext(Stream *s)=0
Dump the object's symbol context to the stream s.
SymbolFile & m_symbol_file
Definition: Type.h:64
SymbolFileType(SymbolFile &symbol_file, lldb::user_id_t uid)
Definition: Type.h:51
lldb::TypeSP m_type_sp
Definition: Type.h:65
Provides public interface for all SymbolFiles.
Definition: SymbolFile.h:49
virtual bool CompleteType(CompilerType &compiler_type)=0
virtual Type * ResolveTypeUID(lldb::user_id_t type_uid)=0
virtual llvm::Expected< lldb::TypeSystemSP > GetTypeSystemForLanguage(lldb::LanguageType language)=0
virtual ObjectFile * GetObjectFile()=0
const ArchSpec & GetArchitecture() const
Definition: Target.h:1007
Sometimes you can find the name of the type corresponding to an object, but we don't have debug infor...
Definition: Type.h:410
void SetName(ConstString type_name)
Definition: Type.cpp:784
bool operator!=(const TypeAndOrName &other) const
Definition: Type.cpp:772
bool operator==(const TypeAndOrName &other) const
Definition: Type.cpp:764
bool HasName() const
Definition: Type.cpp:815
ConstString GetName() const
Definition: Type.cpp:776
bool HasCompilerType() const
Definition: Type.cpp:817
void SetCompilerType(CompilerType compiler_type)
Definition: Type.cpp:800
ConstString m_type_name
Definition: Type.h:448
void SetTypeSP(lldb::TypeSP type_sp)
Definition: Type.cpp:792
CompilerType m_compiler_type
Definition: Type.h:447
bool IsEmpty() const
Definition: Type.cpp:806
CompilerType GetCompilerType(bool prefer_dynamic)
Definition: Type.cpp:1044
bool operator!=(const TypeImpl &rhs) const
Definition: Type.cpp:913
bool CheckExeModule(lldb::ModuleSP &module_sp) const
Definition: Type.cpp:875
bool GetDescription(lldb_private::Stream &strm, lldb::DescriptionLevel description_level)
Definition: Type.cpp:1068
bool operator==(const TypeImpl &rhs) const
Definition: Type.cpp:908
bool CheckModuleCommon(const lldb::ModuleWP &input_module_wp, lldb::ModuleSP &module_sp) const
Definition: Type.cpp:879
TypeImpl GetCanonicalType() const
Definition: Type.cpp:1032
void SetType(const lldb::TypeSP &type_sp)
Definition: Type.cpp:842
TypeImpl GetUnqualifiedType() const
Definition: Type.cpp:1020
TypeImpl GetPointeeType() const
Definition: Type.cpp:972
CompilerType m_dynamic_type
Definition: Type.h:325
CompilerType::TypeSystemSPWrapper GetTypeSystem(bool prefer_dynamic)
Definition: Type.cpp:1056
CompilerType m_static_type
Definition: Type.h:324
bool CheckModule(lldb::ModuleSP &module_sp) const
Definition: Type.cpp:871
lldb::ModuleSP GetModule() const
Definition: Type.cpp:933
TypeImpl GetDereferencedType() const
Definition: Type.cpp:1008
bool IsValid() const
Definition: Type.cpp:917
TypeImpl GetPointerType() const
Definition: Type.cpp:960
lldb::ModuleWP m_exe_module_wp
Definition: Type.h:323
TypeImpl GetReferenceType() const
Definition: Type.cpp:984
TypeImpl GetTypedefedType() const
Definition: Type.cpp:996
lldb::ModuleWP m_module_wp
Definition: Type.h:322
ConstString GetName() const
Definition: Type.cpp:940
ConstString GetDisplayTypeName() const
Definition: Type.cpp:950
void Append(const lldb::TypeImplSP &type)
Definition: Type.h:332
void ForEach(std::function< bool(const lldb::TypeSP &type_sp)> const &callback) const
Definition: TypeList.cpp:78
CompilerType GetReturnType() const
Definition: Type.cpp:1124
ConstString GetMangledName() const
Definition: Type.cpp:1090
CompilerType GetType() const
Definition: Type.cpp:1094
ConstString GetName() const
Definition: Type.cpp:1088
CompilerType GetArgumentAtIndex(size_t idx) const
Definition: Type.cpp:1137
bool GetDescription(Stream &stream)
Definition: Type.cpp:1100
lldb::MemberFunctionKind GetKind() const
Definition: Type.cpp:1096
lldb::MemberFunctionKind m_kind
Definition: Type.h:485
Type * m_encoding_type
Definition: Type.h:214
CompilerType m_compiler_type
Definition: Type.h:220
CompilerType GetForwardCompilerType()
Definition: Type.cpp:667
lldb::Format GetFormat()
Definition: Type.cpp:412
Declaration m_decl
Definition: Type.h:219
Type * GetEncodingType()
Definition: Type.cpp:339
ConstString GetName()
Definition: Type.cpp:303
static bool GetTypeScopeAndBasename(llvm::StringRef name, llvm::StringRef &scope, llvm::StringRef &basename, lldb::TypeClass &type_class)
Definition: Type.cpp:676
const lldb_private::Declaration & GetDeclaration() const
Definition: Type.cpp:480
uint64_t m_byte_size_has_value
Definition: Type.h:218
bool IsTemplateType()
Definition: Type.cpp:398
void DumpValue(ExecutionContext *exe_ctx, Stream *s, const DataExtractor &data, uint32_t data_offset, bool show_type, bool show_summary, bool verbose, lldb::Format format=lldb::eFormatDefault)
Definition: Type.cpp:315
ResolveState m_compiler_type_resolve_state
Definition: Type.h:221
ConstString m_name
Definition: Type.h:210
uint32_t GetEncodingMask()
Definition: Type.cpp:648
void GetDescription(Stream *s, lldb::DescriptionLevel level, bool show_name, ExecutionContextScope *exe_scope)
Definition: Type.cpp:172
uint32_t GetNumChildren(bool omit_empty_base_classes)
Definition: Type.cpp:390
SymbolContextScope * m_context
The symbol context in which this type is defined.
Definition: Type.h:213
lldb::user_id_t m_encoding_uid
Definition: Type.h:215
@ eEncodingIsRestrictUID
This type is the type whose UID is m_encoding_uid with the restrict qualifier added.
Definition: Type.h:80
@ eEncodingIsConstUID
This type is the type whose UID is m_encoding_uid with the const qualifier added.
Definition: Type.h:77
@ eEncodingIsVolatileUID
This type is the type whose UID is m_encoding_uid with the volatile qualifier added.
Definition: Type.h:83
@ eEncodingIsAtomicUID
This type is the type whose UID is m_encoding_uid as an atomic type.
Definition: Type.h:93
@ eEncodingIsSyntheticUID
This type is the synthetic type whose UID is m_encoding_uid.
Definition: Type.h:95
@ eEncodingInvalid
Invalid encoding.
Definition: Type.h:72
@ eEncodingIsTypedefUID
This type is alias to a type whose UID is m_encoding_uid.
Definition: Type.h:85
@ eEncodingIsPointerUID
This type is pointer to a type whose UID is m_encoding_uid.
Definition: Type.h:87
@ eEncodingIsLValueReferenceUID
This type is L value reference to a type whose UID is m_encoding_uid.
Definition: Type.h:89
@ eEncodingIsRValueReferenceUID
This type is R value reference to a type whose UID is m_encoding_uid.
Definition: Type.h:91
@ eEncodingIsUID
This type is the type whose UID is m_encoding_uid.
Definition: Type.h:74
Payload m_payload
Language-specific flags.
Definition: Type.h:223
SymbolFile * GetSymbolFile()
Definition: Type.h:125
void Dump(Stream *s, bool show_context, lldb::DescriptionLevel level=lldb::eDescriptionLevelFull)
Definition: Type.cpp:237
CompilerType GetLayoutCompilerType()
Definition: Type.cpp:662
lldb::Encoding GetEncoding(uint64_t &count)
Definition: Type.cpp:414
lldb::ModuleSP GetExeModule()
GetModule may return module for compile unit's object file.
Definition: Type.cpp:739
void DumpTypeName(Stream *s)
Definition: Type.cpp:313
lldb::TypeSP GetTypedefType()
Definition: Type.cpp:402
bool ResolveCompilerType(ResolveState compiler_type_resolve_state)
Definition: Type.cpp:482
SymbolFile * m_symbol_file
Definition: Type.h:211
bool IsAggregateType()
Definition: Type.cpp:394
EncodingDataType m_encoding_uid_type
Definition: Type.h:216
uint64_t m_byte_size
Definition: Type.h:217
std::optional< uint64_t > GetByteSize(ExecutionContextScope *exe_scope)
Definition: Type.cpp:345
bool ReadFromMemory(ExecutionContext *exe_ctx, lldb::addr_t address, AddressType address_type, DataExtractor &data)
Definition: Type.cpp:437
bool DumpValueInMemory(ExecutionContext *exe_ctx, Stream *s, lldb::addr_t address, AddressType address_type, bool show_types, bool show_summary, bool verbose)
Definition: Type.cpp:419
ConstString GetBaseName()
Definition: Type.cpp:309
ConstString GetQualifiedName()
Definition: Type.cpp:672
CompilerType GetFullCompilerType()
Definition: Type.cpp:657
lldb::ModuleSP GetModule()
Since Type instances only keep a "SymbolFile *" internally, other classes like TypeImpl need make sur...
Definition: Type.cpp:733
bool WriteToMemory(ExecutionContext *exe_ctx, lldb::addr_t address, AddressType address_type, DataExtractor &data)
Definition: Type.cpp:475
bool IsTypedef()
Definition: Type.h:143
#define LLDB_INVALID_UID
Definition: lldb-defines.h:80
#define LLDB_INVALID_ADDRESS
Definition: lldb-defines.h:74
A class that represents a running process on the host machine.
Definition: SBAttachInfo.h:14
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition: Log.h:314
@ AnyModule
Match 0..n nested modules.
bool contextMatches(llvm::ArrayRef< CompilerContext > context_chain, llvm::ArrayRef< CompilerContext > pattern)
Match context_chain against pattern, which may contain "Any" kinds.
Definition: Type.cpp:38
@ eAddressTypeFile
Address is an address as found in an object or symbol file.
@ eAddressTypeHost
Address is an address in the process that is running this code.
Definition: SBAddress.h:15
DescriptionLevel
Description levels for "void GetDescription(Stream *, DescriptionLevel)" calls.
@ eDescriptionLevelVerbose
Format
Display format definitions.
@ eLanguageTypeC
Non-standardized C, such as K&R.
Encoding
Register encoding definitions.
MemberFunctionKind
Kind of member function.
@ eMemberFunctionKindInstanceMethod
A function that applies to a specific instance.
@ eMemberFunctionKindConstructor
A function used to create instances.
@ eMemberFunctionKindUnknown
Not sure what the type of this is.
@ eMemberFunctionKindDestructor
A function used to tear down existing instances.
@ eMemberFunctionKindStaticMethod
A function that applies to a type rather than any instance.
uint64_t user_id_t
Definition: lldb-types.h:80
uint64_t addr_t
Definition: lldb-types.h:79
CompilerContext allows an array of these items to be passed to perform detailed lookups in SymbolVend...
Definition: Type.h:29
CompilerContextKind kind
Definition: Type.h:39
A mix in class that contains a generic user ID.
Definition: UserID.h:31
lldb::user_id_t GetID() const
Get accessor for the user ID.
Definition: UserID.h:47