1 //===-- CompilerType.cpp ----------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/Symbol/CompilerType.h"
12 #include "lldb/Core/ConstString.h"
13 #include "lldb/Core/DataBufferHeap.h"
14 #include "lldb/Core/DataExtractor.h"
15 #include "lldb/Core/Debugger.h"
16 #include "lldb/Core/Scalar.h"
17 #include "lldb/Core/Stream.h"
18 #include "lldb/Core/StreamFile.h"
19 #include "lldb/Core/StreamString.h"
20 #include "lldb/Symbol/ClangASTContext.h"
21 #include "lldb/Symbol/ClangExternalASTSourceCommon.h"
22 #include "lldb/Symbol/Type.h"
23 #include "lldb/Target/ExecutionContext.h"
24 #include "lldb/Target/Process.h"
30 using namespace lldb_private;
32 CompilerType::CompilerType(TypeSystem *type_system,
33 lldb::opaque_compiler_type_t type)
34 : m_type(type), m_type_system(type_system) {}
36 CompilerType::CompilerType(clang::ASTContext *ast, clang::QualType qual_type)
37 : m_type(qual_type.getAsOpaquePtr()),
38 m_type_system(ClangASTContext::GetASTContext(ast)) {
39 #ifdef LLDB_CONFIGURATION_DEBUG
41 assert(m_type_system != nullptr);
45 CompilerType::~CompilerType() {}
47 //----------------------------------------------------------------------
49 //----------------------------------------------------------------------
51 bool CompilerType::IsAggregateType() const {
53 return m_type_system->IsAggregateType(m_type);
57 bool CompilerType::IsAnonymousType() const {
59 return m_type_system->IsAnonymousType(m_type);
63 bool CompilerType::IsArrayType(CompilerType *element_type_ptr, uint64_t *size,
64 bool *is_incomplete) const {
66 return m_type_system->IsArrayType(m_type, element_type_ptr, size,
70 element_type_ptr->Clear();
74 *is_incomplete = false;
78 bool CompilerType::IsVectorType(CompilerType *element_type,
79 uint64_t *size) const {
81 return m_type_system->IsVectorType(m_type, element_type, size);
85 bool CompilerType::IsRuntimeGeneratedType() const {
87 return m_type_system->IsRuntimeGeneratedType(m_type);
91 bool CompilerType::IsCharType() const {
93 return m_type_system->IsCharType(m_type);
97 bool CompilerType::IsCompleteType() const {
99 return m_type_system->IsCompleteType(m_type);
103 bool CompilerType::IsConst() const {
105 return m_type_system->IsConst(m_type);
109 bool CompilerType::IsCStringType(uint32_t &length) const {
111 return m_type_system->IsCStringType(m_type, length);
115 bool CompilerType::IsFunctionType(bool *is_variadic_ptr) const {
117 return m_type_system->IsFunctionType(m_type, is_variadic_ptr);
121 // Used to detect "Homogeneous Floating-point Aggregates"
123 CompilerType::IsHomogeneousAggregate(CompilerType *base_type_ptr) const {
125 return m_type_system->IsHomogeneousAggregate(m_type, base_type_ptr);
129 size_t CompilerType::GetNumberOfFunctionArguments() const {
131 return m_type_system->GetNumberOfFunctionArguments(m_type);
136 CompilerType::GetFunctionArgumentAtIndex(const size_t index) const {
138 return m_type_system->GetFunctionArgumentAtIndex(m_type, index);
139 return CompilerType();
142 bool CompilerType::IsFunctionPointerType() const {
144 return m_type_system->IsFunctionPointerType(m_type);
148 bool CompilerType::IsBlockPointerType(
149 CompilerType *function_pointer_type_ptr) const {
151 return m_type_system->IsBlockPointerType(m_type, function_pointer_type_ptr);
155 bool CompilerType::IsIntegerType(bool &is_signed) const {
157 return m_type_system->IsIntegerType(m_type, is_signed);
161 bool CompilerType::IsEnumerationType(bool &is_signed) const {
163 return m_type_system->IsEnumerationType(m_type, is_signed);
167 bool CompilerType::IsIntegerOrEnumerationType(bool &is_signed) const {
168 return IsIntegerType(is_signed) || IsEnumerationType(is_signed);
171 bool CompilerType::IsPointerType(CompilerType *pointee_type) const {
173 return m_type_system->IsPointerType(m_type, pointee_type);
176 pointee_type->Clear();
180 bool CompilerType::IsPointerOrReferenceType(CompilerType *pointee_type) const {
182 return m_type_system->IsPointerOrReferenceType(m_type, pointee_type);
185 pointee_type->Clear();
189 bool CompilerType::IsReferenceType(CompilerType *pointee_type,
190 bool *is_rvalue) const {
192 return m_type_system->IsReferenceType(m_type, pointee_type, is_rvalue);
195 pointee_type->Clear();
199 bool CompilerType::ShouldTreatScalarValueAsAddress() const {
201 return m_type_system->ShouldTreatScalarValueAsAddress(m_type);
205 bool CompilerType::IsFloatingPointType(uint32_t &count,
206 bool &is_complex) const {
208 return m_type_system->IsFloatingPointType(m_type, count, is_complex);
215 bool CompilerType::IsDefined() const {
217 return m_type_system->IsDefined(m_type);
221 bool CompilerType::IsPolymorphicClass() const {
223 return m_type_system->IsPolymorphicClass(m_type);
228 bool CompilerType::IsPossibleDynamicType(CompilerType *dynamic_pointee_type,
229 bool check_cplusplus,
230 bool check_objc) const {
232 return m_type_system->IsPossibleDynamicType(m_type, dynamic_pointee_type,
233 check_cplusplus, check_objc);
237 bool CompilerType::IsScalarType() const {
241 return m_type_system->IsScalarType(m_type);
244 bool CompilerType::IsTypedefType() const {
247 return m_type_system->IsTypedefType(m_type);
250 bool CompilerType::IsVoidType() const {
253 return m_type_system->IsVoidType(m_type);
256 bool CompilerType::IsPointerToScalarType() const {
260 return IsPointerType() && GetPointeeType().IsScalarType();
263 bool CompilerType::IsArrayOfScalarType() const {
264 CompilerType element_type;
265 if (IsArrayType(&element_type, nullptr, nullptr))
266 return element_type.IsScalarType();
270 bool CompilerType::IsBeingDefined() const {
273 return m_type_system->IsBeingDefined(m_type);
276 //----------------------------------------------------------------------
278 //----------------------------------------------------------------------
280 bool CompilerType::GetCompleteType() const {
283 return m_type_system->GetCompleteType(m_type);
286 //----------------------------------------------------------------------
287 // AST related queries
288 //----------------------------------------------------------------------
289 size_t CompilerType::GetPointerByteSize() const {
291 return m_type_system->GetPointerByteSize();
295 ConstString CompilerType::GetConstQualifiedTypeName() const {
296 return GetConstTypeName();
299 ConstString CompilerType::GetConstTypeName() const {
301 ConstString type_name(GetTypeName());
305 return ConstString("<invalid>");
308 ConstString CompilerType::GetTypeName() const {
310 return m_type_system->GetTypeName(m_type);
312 return ConstString("<invalid>");
315 ConstString CompilerType::GetDisplayTypeName() const { return GetTypeName(); }
317 uint32_t CompilerType::GetTypeInfo(
318 CompilerType *pointee_or_element_compiler_type) const {
322 return m_type_system->GetTypeInfo(m_type, pointee_or_element_compiler_type);
325 lldb::LanguageType CompilerType::GetMinimumLanguage() {
327 return lldb::eLanguageTypeC;
329 return m_type_system->GetMinimumLanguage(m_type);
332 lldb::TypeClass CompilerType::GetTypeClass() const {
334 return lldb::eTypeClassInvalid;
336 return m_type_system->GetTypeClass(m_type);
339 void CompilerType::SetCompilerType(TypeSystem *type_system,
340 lldb::opaque_compiler_type_t type) {
341 m_type_system = type_system;
345 void CompilerType::SetCompilerType(clang::ASTContext *ast,
346 clang::QualType qual_type) {
347 m_type_system = ClangASTContext::GetASTContext(ast);
348 m_type = qual_type.getAsOpaquePtr();
351 unsigned CompilerType::GetTypeQualifiers() const {
353 return m_type_system->GetTypeQualifiers(m_type);
357 //----------------------------------------------------------------------
358 // Creating related types
359 //----------------------------------------------------------------------
361 CompilerType CompilerType::GetArrayElementType(uint64_t *stride) const {
363 return m_type_system->GetArrayElementType(m_type, stride);
365 return CompilerType();
368 CompilerType CompilerType::GetArrayType(uint64_t size) const {
370 return m_type_system->GetArrayType(m_type, size);
372 return CompilerType();
375 CompilerType CompilerType::GetCanonicalType() const {
377 return m_type_system->GetCanonicalType(m_type);
378 return CompilerType();
381 CompilerType CompilerType::GetFullyUnqualifiedType() const {
383 return m_type_system->GetFullyUnqualifiedType(m_type);
384 return CompilerType();
387 int CompilerType::GetFunctionArgumentCount() const {
389 return m_type_system->GetFunctionArgumentCount(m_type);
394 CompilerType CompilerType::GetFunctionArgumentTypeAtIndex(size_t idx) const {
396 return m_type_system->GetFunctionArgumentTypeAtIndex(m_type, idx);
398 return CompilerType();
401 CompilerType CompilerType::GetFunctionReturnType() const {
403 return m_type_system->GetFunctionReturnType(m_type);
405 return CompilerType();
408 size_t CompilerType::GetNumMemberFunctions() const {
410 return m_type_system->GetNumMemberFunctions(m_type);
415 TypeMemberFunctionImpl CompilerType::GetMemberFunctionAtIndex(size_t idx) {
417 return m_type_system->GetMemberFunctionAtIndex(m_type, idx);
419 return TypeMemberFunctionImpl();
422 CompilerType CompilerType::GetNonReferenceType() const {
424 return m_type_system->GetNonReferenceType(m_type);
425 return CompilerType();
428 CompilerType CompilerType::GetPointeeType() const {
430 return m_type_system->GetPointeeType(m_type);
432 return CompilerType();
435 CompilerType CompilerType::GetPointerType() const {
437 return m_type_system->GetPointerType(m_type);
439 return CompilerType();
442 CompilerType CompilerType::GetLValueReferenceType() const {
444 return m_type_system->GetLValueReferenceType(m_type);
446 return CompilerType();
449 CompilerType CompilerType::GetRValueReferenceType() const {
451 return m_type_system->GetRValueReferenceType(m_type);
453 return CompilerType();
456 CompilerType CompilerType::AddConstModifier() const {
458 return m_type_system->AddConstModifier(m_type);
460 return CompilerType();
463 CompilerType CompilerType::AddVolatileModifier() const {
465 return m_type_system->AddVolatileModifier(m_type);
467 return CompilerType();
470 CompilerType CompilerType::AddRestrictModifier() const {
472 return m_type_system->AddRestrictModifier(m_type);
474 return CompilerType();
478 CompilerType::CreateTypedef(const char *name,
479 const CompilerDeclContext &decl_ctx) const {
481 return m_type_system->CreateTypedef(m_type, name, decl_ctx);
483 return CompilerType();
486 CompilerType CompilerType::GetTypedefedType() const {
488 return m_type_system->GetTypedefedType(m_type);
490 return CompilerType();
493 //----------------------------------------------------------------------
494 // Create related types using the current type's AST
495 //----------------------------------------------------------------------
498 CompilerType::GetBasicTypeFromAST(lldb::BasicType basic_type) const {
500 return m_type_system->GetBasicTypeFromAST(basic_type);
501 return CompilerType();
503 //----------------------------------------------------------------------
504 // Exploring the type
505 //----------------------------------------------------------------------
507 uint64_t CompilerType::GetBitSize(ExecutionContextScope *exe_scope) const {
509 return m_type_system->GetBitSize(m_type, exe_scope);
514 uint64_t CompilerType::GetByteSize(ExecutionContextScope *exe_scope) const {
515 return (GetBitSize(exe_scope) + 7) / 8;
518 size_t CompilerType::GetTypeBitAlign() const {
520 return m_type_system->GetTypeBitAlign(m_type);
524 lldb::Encoding CompilerType::GetEncoding(uint64_t &count) const {
526 return lldb::eEncodingInvalid;
528 return m_type_system->GetEncoding(m_type, count);
531 lldb::Format CompilerType::GetFormat() const {
533 return lldb::eFormatDefault;
535 return m_type_system->GetFormat(m_type);
538 uint32_t CompilerType::GetNumChildren(bool omit_empty_base_classes) const {
541 return m_type_system->GetNumChildren(m_type, omit_empty_base_classes);
544 lldb::BasicType CompilerType::GetBasicTypeEnumeration() const {
546 return m_type_system->GetBasicTypeEnumeration(m_type);
547 return eBasicTypeInvalid;
550 void CompilerType::ForEachEnumerator(
551 std::function<bool(const CompilerType &integer_type,
552 const ConstString &name,
553 const llvm::APSInt &value)> const &callback) const {
555 return m_type_system->ForEachEnumerator(m_type, callback);
558 uint32_t CompilerType::GetNumFields() const {
561 return m_type_system->GetNumFields(m_type);
564 CompilerType CompilerType::GetFieldAtIndex(size_t idx, std::string &name,
565 uint64_t *bit_offset_ptr,
566 uint32_t *bitfield_bit_size_ptr,
567 bool *is_bitfield_ptr) const {
569 return CompilerType();
570 return m_type_system->GetFieldAtIndex(m_type, idx, name, bit_offset_ptr,
571 bitfield_bit_size_ptr, is_bitfield_ptr);
574 uint32_t CompilerType::GetNumDirectBaseClasses() const {
576 return m_type_system->GetNumDirectBaseClasses(m_type);
580 uint32_t CompilerType::GetNumVirtualBaseClasses() const {
582 return m_type_system->GetNumVirtualBaseClasses(m_type);
587 CompilerType::GetDirectBaseClassAtIndex(size_t idx,
588 uint32_t *bit_offset_ptr) const {
590 return m_type_system->GetDirectBaseClassAtIndex(m_type, idx,
592 return CompilerType();
596 CompilerType::GetVirtualBaseClassAtIndex(size_t idx,
597 uint32_t *bit_offset_ptr) const {
599 return m_type_system->GetVirtualBaseClassAtIndex(m_type, idx,
601 return CompilerType();
604 uint32_t CompilerType::GetIndexOfFieldWithName(
605 const char *name, CompilerType *field_compiler_type_ptr,
606 uint64_t *bit_offset_ptr, uint32_t *bitfield_bit_size_ptr,
607 bool *is_bitfield_ptr) const {
608 unsigned count = GetNumFields();
609 std::string field_name;
610 for (unsigned index = 0; index < count; index++) {
611 CompilerType field_compiler_type(
612 GetFieldAtIndex(index, field_name, bit_offset_ptr,
613 bitfield_bit_size_ptr, is_bitfield_ptr));
614 if (strcmp(field_name.c_str(), name) == 0) {
615 if (field_compiler_type_ptr)
616 *field_compiler_type_ptr = field_compiler_type;
623 CompilerType CompilerType::GetChildCompilerTypeAtIndex(
624 ExecutionContext *exe_ctx, size_t idx, bool transparent_pointers,
625 bool omit_empty_base_classes, bool ignore_array_bounds,
626 std::string &child_name, uint32_t &child_byte_size,
627 int32_t &child_byte_offset, uint32_t &child_bitfield_bit_size,
628 uint32_t &child_bitfield_bit_offset, bool &child_is_base_class,
629 bool &child_is_deref_of_parent, ValueObject *valobj,
630 uint64_t &language_flags) const {
632 return CompilerType();
633 return m_type_system->GetChildCompilerTypeAtIndex(
634 m_type, exe_ctx, idx, transparent_pointers, omit_empty_base_classes,
635 ignore_array_bounds, child_name, child_byte_size, child_byte_offset,
636 child_bitfield_bit_size, child_bitfield_bit_offset, child_is_base_class,
637 child_is_deref_of_parent, valobj, language_flags);
640 // Look for a child member (doesn't include base classes, but it does include
641 // their members) in the type hierarchy. Returns an index path into "clang_type"
642 // on how to reach the appropriate member.
661 // If we have a clang type that describes "class C", and we wanted to looked
664 // With omit_empty_base_classes == false we would get an integer array back
667 // The first index 1 is the child index for "class A" within class C
668 // The second index 1 is the child index for "m_b" within class A
670 // With omit_empty_base_classes == true we would get an integer array back with:
672 // The first index 0 is the child index for "class A" within class C (since
673 // class B doesn't have any members it doesn't count)
674 // The second index 1 is the child index for "m_b" within class A
676 size_t CompilerType::GetIndexOfChildMemberWithName(
677 const char *name, bool omit_empty_base_classes,
678 std::vector<uint32_t> &child_indexes) const {
679 if (IsValid() && name && name[0]) {
680 return m_type_system->GetIndexOfChildMemberWithName(
681 m_type, name, omit_empty_base_classes, child_indexes);
686 size_t CompilerType::GetNumTemplateArguments() const {
688 return m_type_system->GetNumTemplateArguments(m_type);
694 CompilerType::GetTemplateArgument(size_t idx,
695 lldb::TemplateArgumentKind &kind) const {
697 return m_type_system->GetTemplateArgument(m_type, idx, kind);
699 return CompilerType();
702 CompilerType CompilerType::GetTypeForFormatters() const {
704 return m_type_system->GetTypeForFormatters(m_type);
705 return CompilerType();
708 LazyBool CompilerType::ShouldPrintAsOneLiner(ValueObject *valobj) const {
710 return m_type_system->ShouldPrintAsOneLiner(m_type, valobj);
711 return eLazyBoolCalculate;
714 bool CompilerType::IsMeaninglessWithoutDynamicResolution() const {
716 return m_type_system->IsMeaninglessWithoutDynamicResolution(m_type);
720 // Get the index of the child of "clang_type" whose name matches. This function
721 // doesn't descend into the children, but only looks one level deep and name
722 // matches can include base class names.
725 CompilerType::GetIndexOfChildWithName(const char *name,
726 bool omit_empty_base_classes) const {
727 if (IsValid() && name && name[0]) {
728 return m_type_system->GetIndexOfChildWithName(m_type, name,
729 omit_empty_base_classes);
734 size_t CompilerType::ConvertStringToFloatValue(const char *s, uint8_t *dst,
735 size_t dst_size) const {
737 return m_type_system->ConvertStringToFloatValue(m_type, s, dst, dst_size);
741 //----------------------------------------------------------------------
743 //----------------------------------------------------------------------
744 #define DEPTH_INCREMENT 2
746 void CompilerType::DumpValue(ExecutionContext *exe_ctx, Stream *s,
748 const lldb_private::DataExtractor &data,
749 lldb::offset_t data_byte_offset,
750 size_t data_byte_size, uint32_t bitfield_bit_size,
751 uint32_t bitfield_bit_offset, bool show_types,
752 bool show_summary, bool verbose, uint32_t depth) {
755 m_type_system->DumpValue(m_type, exe_ctx, s, format, data, data_byte_offset,
756 data_byte_size, bitfield_bit_size,
757 bitfield_bit_offset, show_types, show_summary,
761 bool CompilerType::DumpTypeValue(Stream *s, lldb::Format format,
762 const lldb_private::DataExtractor &data,
763 lldb::offset_t byte_offset, size_t byte_size,
764 uint32_t bitfield_bit_size,
765 uint32_t bitfield_bit_offset,
766 ExecutionContextScope *exe_scope) {
769 return m_type_system->DumpTypeValue(m_type, s, format, data, byte_offset,
770 byte_size, bitfield_bit_size,
771 bitfield_bit_offset, exe_scope);
774 void CompilerType::DumpSummary(ExecutionContext *exe_ctx, Stream *s,
775 const lldb_private::DataExtractor &data,
776 lldb::offset_t data_byte_offset,
777 size_t data_byte_size) {
779 m_type_system->DumpSummary(m_type, exe_ctx, s, data, data_byte_offset,
783 void CompilerType::DumpTypeDescription() const {
785 m_type_system->DumpTypeDescription(m_type);
788 void CompilerType::DumpTypeDescription(Stream *s) const {
790 m_type_system->DumpTypeDescription(m_type, s);
794 bool CompilerType::GetValueAsScalar(const lldb_private::DataExtractor &data,
795 lldb::offset_t data_byte_offset,
796 size_t data_byte_size,
797 Scalar &value) const {
801 if (IsAggregateType()) {
802 return false; // Aggregate types don't have scalar values
805 lldb::Encoding encoding = GetEncoding(count);
807 if (encoding == lldb::eEncodingInvalid || count != 1)
810 const uint64_t byte_size = GetByteSize(nullptr);
811 lldb::offset_t offset = data_byte_offset;
813 case lldb::eEncodingInvalid:
815 case lldb::eEncodingVector:
817 case lldb::eEncodingUint:
818 if (byte_size <= sizeof(unsigned long long)) {
819 uint64_t uval64 = data.GetMaxU64(&offset, byte_size);
820 if (byte_size <= sizeof(unsigned int)) {
821 value = (unsigned int)uval64;
823 } else if (byte_size <= sizeof(unsigned long)) {
824 value = (unsigned long)uval64;
826 } else if (byte_size <= sizeof(unsigned long long)) {
827 value = (unsigned long long)uval64;
834 case lldb::eEncodingSint:
835 if (byte_size <= sizeof(long long)) {
836 int64_t sval64 = data.GetMaxS64(&offset, byte_size);
837 if (byte_size <= sizeof(int)) {
840 } else if (byte_size <= sizeof(long)) {
841 value = (long)sval64;
843 } else if (byte_size <= sizeof(long long)) {
844 value = (long long)sval64;
851 case lldb::eEncodingIEEE754:
852 if (byte_size <= sizeof(long double)) {
855 if (byte_size == sizeof(float)) {
856 if (sizeof(float) == sizeof(uint32_t)) {
857 u32 = data.GetU32(&offset);
858 value = *((float *)&u32);
860 } else if (sizeof(float) == sizeof(uint64_t)) {
861 u64 = data.GetU64(&offset);
862 value = *((float *)&u64);
865 } else if (byte_size == sizeof(double)) {
866 if (sizeof(double) == sizeof(uint32_t)) {
867 u32 = data.GetU32(&offset);
868 value = *((double *)&u32);
870 } else if (sizeof(double) == sizeof(uint64_t)) {
871 u64 = data.GetU64(&offset);
872 value = *((double *)&u64);
875 } else if (byte_size == sizeof(long double)) {
876 if (sizeof(long double) == sizeof(uint32_t)) {
877 u32 = data.GetU32(&offset);
878 value = *((long double *)&u32);
880 } else if (sizeof(long double) == sizeof(uint64_t)) {
881 u64 = data.GetU64(&offset);
882 value = *((long double *)&u64);
893 bool CompilerType::SetValueFromScalar(const Scalar &value, Stream &strm) {
897 // Aggregate types don't have scalar values
898 if (!IsAggregateType()) {
899 strm.GetFlags().Set(Stream::eBinary);
901 lldb::Encoding encoding = GetEncoding(count);
903 if (encoding == lldb::eEncodingInvalid || count != 1)
906 const uint64_t bit_width = GetBitSize(nullptr);
907 // This function doesn't currently handle non-byte aligned assignments
908 if ((bit_width % 8) != 0)
911 const uint64_t byte_size = (bit_width + 7) / 8;
913 case lldb::eEncodingInvalid:
915 case lldb::eEncodingVector:
917 case lldb::eEncodingUint:
920 strm.PutHex8(value.UInt());
923 strm.PutHex16(value.UInt());
926 strm.PutHex32(value.UInt());
929 strm.PutHex64(value.ULongLong());
936 case lldb::eEncodingSint:
939 strm.PutHex8(value.SInt());
942 strm.PutHex16(value.SInt());
945 strm.PutHex32(value.SInt());
948 strm.PutHex64(value.SLongLong());
955 case lldb::eEncodingIEEE754:
956 if (byte_size <= sizeof(long double)) {
957 if (byte_size == sizeof(float)) {
958 strm.PutFloat(value.Float());
960 } else if (byte_size == sizeof(double)) {
961 strm.PutDouble(value.Double());
963 } else if (byte_size == sizeof(long double)) {
964 strm.PutDouble(value.LongDouble());
974 bool CompilerType::ReadFromMemory(lldb_private::ExecutionContext *exe_ctx,
975 lldb::addr_t addr, AddressType address_type,
976 lldb_private::DataExtractor &data) {
980 // Can't convert a file address to anything valid without more
981 // context (which Module it came from)
982 if (address_type == eAddressTypeFile)
985 if (!GetCompleteType())
988 const uint64_t byte_size =
989 GetByteSize(exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL);
990 if (data.GetByteSize() < byte_size) {
991 lldb::DataBufferSP data_sp(new DataBufferHeap(byte_size, '\0'));
992 data.SetData(data_sp);
995 uint8_t *dst = const_cast<uint8_t *>(data.PeekData(0, byte_size));
996 if (dst != nullptr) {
997 if (address_type == eAddressTypeHost) {
1000 // The address is an address in this process, so just copy it
1001 memcpy(dst, (uint8_t *)nullptr + addr, byte_size);
1004 Process *process = nullptr;
1006 process = exe_ctx->GetProcessPtr();
1009 return process->ReadMemory(addr, dst, byte_size, error) == byte_size;
1016 bool CompilerType::WriteToMemory(lldb_private::ExecutionContext *exe_ctx,
1017 lldb::addr_t addr, AddressType address_type,
1018 StreamString &new_value) {
1022 // Can't convert a file address to anything valid without more
1023 // context (which Module it came from)
1024 if (address_type == eAddressTypeFile)
1027 if (!GetCompleteType())
1030 const uint64_t byte_size =
1031 GetByteSize(exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL);
1033 if (byte_size > 0) {
1034 if (address_type == eAddressTypeHost) {
1035 // The address is an address in this process, so just copy it
1036 memcpy((void *)addr, new_value.GetData(), byte_size);
1039 Process *process = nullptr;
1041 process = exe_ctx->GetProcessPtr();
1044 return process->WriteMemory(addr, new_value.GetData(), byte_size,
1045 error) == byte_size;
1052 // clang::CXXRecordDecl *
1053 // CompilerType::GetAsCXXRecordDecl (lldb::opaque_compiler_type_t
1054 // opaque_compiler_qual_type)
1056 // if (opaque_compiler_qual_type)
1058 // clang::QualType::getFromOpaquePtr(opaque_compiler_qual_type)->getAsCXXRecordDecl();
1062 bool lldb_private::operator==(const lldb_private::CompilerType &lhs,
1063 const lldb_private::CompilerType &rhs) {
1064 return lhs.GetTypeSystem() == rhs.GetTypeSystem() &&
1065 lhs.GetOpaqueQualType() == rhs.GetOpaqueQualType();
1068 bool lldb_private::operator!=(const lldb_private::CompilerType &lhs,
1069 const lldb_private::CompilerType &rhs) {
1070 return lhs.GetTypeSystem() != rhs.GetTypeSystem() ||
1071 lhs.GetOpaqueQualType() != rhs.GetOpaqueQualType();