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/Debugger.h"
13 #include "lldb/Core/Scalar.h"
14 #include "lldb/Core/StreamFile.h"
15 #include "lldb/Symbol/ClangASTContext.h"
16 #include "lldb/Symbol/ClangExternalASTSourceCommon.h"
17 #include "lldb/Symbol/Type.h"
18 #include "lldb/Target/ExecutionContext.h"
19 #include "lldb/Target/Process.h"
20 #include "lldb/Utility/ConstString.h"
21 #include "lldb/Utility/DataBufferHeap.h"
22 #include "lldb/Utility/DataExtractor.h"
23 #include "lldb/Utility/Stream.h"
24 #include "lldb/Utility/StreamString.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
642 // "clang_type" 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
665 // with: { 1, 1 } The first index 1 is the child index for "class A" within
666 // class C The second index 1 is the child index for "m_b" within class A
668 // With omit_empty_base_classes == true we would get an integer array back
669 // with: { 0, 1 } The first index 0 is the child index for "class A" within
670 // class C (since class B doesn't have any members it doesn't count) The second
671 // index 1 is the child index for "m_b" within class A
673 size_t CompilerType::GetIndexOfChildMemberWithName(
674 const char *name, bool omit_empty_base_classes,
675 std::vector<uint32_t> &child_indexes) const {
676 if (IsValid() && name && name[0]) {
677 return m_type_system->GetIndexOfChildMemberWithName(
678 m_type, name, omit_empty_base_classes, child_indexes);
683 size_t CompilerType::GetNumTemplateArguments() const {
685 return m_type_system->GetNumTemplateArguments(m_type);
690 TemplateArgumentKind CompilerType::GetTemplateArgumentKind(size_t idx) const {
692 return m_type_system->GetTemplateArgumentKind(m_type, idx);
693 return eTemplateArgumentKindNull;
696 CompilerType CompilerType::GetTypeTemplateArgument(size_t idx) const {
698 return m_type_system->GetTypeTemplateArgument(m_type, idx);
700 return CompilerType();
703 llvm::Optional<CompilerType::IntegralTemplateArgument>
704 CompilerType::GetIntegralTemplateArgument(size_t idx) const {
706 return m_type_system->GetIntegralTemplateArgument(m_type, idx);
710 CompilerType CompilerType::GetTypeForFormatters() const {
712 return m_type_system->GetTypeForFormatters(m_type);
713 return CompilerType();
716 LazyBool CompilerType::ShouldPrintAsOneLiner(ValueObject *valobj) const {
718 return m_type_system->ShouldPrintAsOneLiner(m_type, valobj);
719 return eLazyBoolCalculate;
722 bool CompilerType::IsMeaninglessWithoutDynamicResolution() const {
724 return m_type_system->IsMeaninglessWithoutDynamicResolution(m_type);
728 // Get the index of the child of "clang_type" whose name matches. This function
729 // doesn't descend into the children, but only looks one level deep and name
730 // matches can include base class names.
733 CompilerType::GetIndexOfChildWithName(const char *name,
734 bool omit_empty_base_classes) const {
735 if (IsValid() && name && name[0]) {
736 return m_type_system->GetIndexOfChildWithName(m_type, name,
737 omit_empty_base_classes);
742 size_t CompilerType::ConvertStringToFloatValue(const char *s, uint8_t *dst,
743 size_t dst_size) const {
745 return m_type_system->ConvertStringToFloatValue(m_type, s, dst, dst_size);
749 //----------------------------------------------------------------------
751 //----------------------------------------------------------------------
752 #define DEPTH_INCREMENT 2
754 void CompilerType::DumpValue(ExecutionContext *exe_ctx, Stream *s,
755 lldb::Format format, const DataExtractor &data,
756 lldb::offset_t data_byte_offset,
757 size_t data_byte_size, uint32_t bitfield_bit_size,
758 uint32_t bitfield_bit_offset, bool show_types,
759 bool show_summary, bool verbose, uint32_t depth) {
762 m_type_system->DumpValue(m_type, exe_ctx, s, format, data, data_byte_offset,
763 data_byte_size, bitfield_bit_size,
764 bitfield_bit_offset, show_types, show_summary,
768 bool CompilerType::DumpTypeValue(Stream *s, lldb::Format format,
769 const DataExtractor &data,
770 lldb::offset_t byte_offset, size_t byte_size,
771 uint32_t bitfield_bit_size,
772 uint32_t bitfield_bit_offset,
773 ExecutionContextScope *exe_scope) {
776 return m_type_system->DumpTypeValue(m_type, s, format, data, byte_offset,
777 byte_size, bitfield_bit_size,
778 bitfield_bit_offset, exe_scope);
781 void CompilerType::DumpSummary(ExecutionContext *exe_ctx, Stream *s,
782 const DataExtractor &data,
783 lldb::offset_t data_byte_offset,
784 size_t data_byte_size) {
786 m_type_system->DumpSummary(m_type, exe_ctx, s, data, data_byte_offset,
790 void CompilerType::DumpTypeDescription() const {
792 m_type_system->DumpTypeDescription(m_type);
795 void CompilerType::DumpTypeDescription(Stream *s) const {
797 m_type_system->DumpTypeDescription(m_type, s);
801 bool CompilerType::GetValueAsScalar(const lldb_private::DataExtractor &data,
802 lldb::offset_t data_byte_offset,
803 size_t data_byte_size,
804 Scalar &value) const {
808 if (IsAggregateType()) {
809 return false; // Aggregate types don't have scalar values
812 lldb::Encoding encoding = GetEncoding(count);
814 if (encoding == lldb::eEncodingInvalid || count != 1)
817 const uint64_t byte_size = GetByteSize(nullptr);
818 lldb::offset_t offset = data_byte_offset;
820 case lldb::eEncodingInvalid:
822 case lldb::eEncodingVector:
824 case lldb::eEncodingUint:
825 if (byte_size <= sizeof(unsigned long long)) {
826 uint64_t uval64 = data.GetMaxU64(&offset, byte_size);
827 if (byte_size <= sizeof(unsigned int)) {
828 value = (unsigned int)uval64;
830 } else if (byte_size <= sizeof(unsigned long)) {
831 value = (unsigned long)uval64;
833 } else if (byte_size <= sizeof(unsigned long long)) {
834 value = (unsigned long long)uval64;
841 case lldb::eEncodingSint:
842 if (byte_size <= sizeof(long long)) {
843 int64_t sval64 = data.GetMaxS64(&offset, byte_size);
844 if (byte_size <= sizeof(int)) {
847 } else if (byte_size <= sizeof(long)) {
848 value = (long)sval64;
850 } else if (byte_size <= sizeof(long long)) {
851 value = (long long)sval64;
858 case lldb::eEncodingIEEE754:
859 if (byte_size <= sizeof(long double)) {
862 if (byte_size == sizeof(float)) {
863 if (sizeof(float) == sizeof(uint32_t)) {
864 u32 = data.GetU32(&offset);
865 value = *((float *)&u32);
867 } else if (sizeof(float) == sizeof(uint64_t)) {
868 u64 = data.GetU64(&offset);
869 value = *((float *)&u64);
872 } else if (byte_size == sizeof(double)) {
873 if (sizeof(double) == sizeof(uint32_t)) {
874 u32 = data.GetU32(&offset);
875 value = *((double *)&u32);
877 } else if (sizeof(double) == sizeof(uint64_t)) {
878 u64 = data.GetU64(&offset);
879 value = *((double *)&u64);
882 } else if (byte_size == sizeof(long double)) {
883 if (sizeof(long double) == sizeof(uint32_t)) {
884 u32 = data.GetU32(&offset);
885 value = *((long double *)&u32);
887 } else if (sizeof(long double) == sizeof(uint64_t)) {
888 u64 = data.GetU64(&offset);
889 value = *((long double *)&u64);
900 bool CompilerType::SetValueFromScalar(const Scalar &value, Stream &strm) {
904 // Aggregate types don't have scalar values
905 if (!IsAggregateType()) {
906 strm.GetFlags().Set(Stream::eBinary);
908 lldb::Encoding encoding = GetEncoding(count);
910 if (encoding == lldb::eEncodingInvalid || count != 1)
913 const uint64_t bit_width = GetBitSize(nullptr);
914 // This function doesn't currently handle non-byte aligned assignments
915 if ((bit_width % 8) != 0)
918 const uint64_t byte_size = (bit_width + 7) / 8;
920 case lldb::eEncodingInvalid:
922 case lldb::eEncodingVector:
924 case lldb::eEncodingUint:
927 strm.PutHex8(value.UInt());
930 strm.PutHex16(value.UInt());
933 strm.PutHex32(value.UInt());
936 strm.PutHex64(value.ULongLong());
943 case lldb::eEncodingSint:
946 strm.PutHex8(value.SInt());
949 strm.PutHex16(value.SInt());
952 strm.PutHex32(value.SInt());
955 strm.PutHex64(value.SLongLong());
962 case lldb::eEncodingIEEE754:
963 if (byte_size <= sizeof(long double)) {
964 if (byte_size == sizeof(float)) {
965 strm.PutFloat(value.Float());
967 } else if (byte_size == sizeof(double)) {
968 strm.PutDouble(value.Double());
970 } else if (byte_size == sizeof(long double)) {
971 strm.PutDouble(value.LongDouble());
981 bool CompilerType::ReadFromMemory(lldb_private::ExecutionContext *exe_ctx,
982 lldb::addr_t addr, AddressType address_type,
983 lldb_private::DataExtractor &data) {
987 // Can't convert a file address to anything valid without more context (which
988 // Module it came from)
989 if (address_type == eAddressTypeFile)
992 if (!GetCompleteType())
995 const uint64_t byte_size =
996 GetByteSize(exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL);
997 if (data.GetByteSize() < byte_size) {
998 lldb::DataBufferSP data_sp(new DataBufferHeap(byte_size, '\0'));
999 data.SetData(data_sp);
1002 uint8_t *dst = const_cast<uint8_t *>(data.PeekData(0, byte_size));
1003 if (dst != nullptr) {
1004 if (address_type == eAddressTypeHost) {
1007 // The address is an address in this process, so just copy it
1008 memcpy(dst, reinterpret_cast<uint8_t *>(addr), byte_size);
1011 Process *process = nullptr;
1013 process = exe_ctx->GetProcessPtr();
1016 return process->ReadMemory(addr, dst, byte_size, error) == byte_size;
1023 bool CompilerType::WriteToMemory(lldb_private::ExecutionContext *exe_ctx,
1024 lldb::addr_t addr, AddressType address_type,
1025 StreamString &new_value) {
1029 // Can't convert a file address to anything valid without more context (which
1030 // Module it came from)
1031 if (address_type == eAddressTypeFile)
1034 if (!GetCompleteType())
1037 const uint64_t byte_size =
1038 GetByteSize(exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL);
1040 if (byte_size > 0) {
1041 if (address_type == eAddressTypeHost) {
1042 // The address is an address in this process, so just copy it
1043 memcpy((void *)addr, new_value.GetData(), byte_size);
1046 Process *process = nullptr;
1048 process = exe_ctx->GetProcessPtr();
1051 return process->WriteMemory(addr, new_value.GetData(), byte_size,
1052 error) == byte_size;
1059 // clang::CXXRecordDecl *
1060 // CompilerType::GetAsCXXRecordDecl (lldb::opaque_compiler_type_t
1061 // opaque_compiler_qual_type)
1063 // if (opaque_compiler_qual_type)
1065 // clang::QualType::getFromOpaquePtr(opaque_compiler_qual_type)->getAsCXXRecordDecl();
1069 bool lldb_private::operator==(const lldb_private::CompilerType &lhs,
1070 const lldb_private::CompilerType &rhs) {
1071 return lhs.GetTypeSystem() == rhs.GetTypeSystem() &&
1072 lhs.GetOpaqueQualType() == rhs.GetOpaqueQualType();
1075 bool lldb_private::operator!=(const lldb_private::CompilerType &lhs,
1076 const lldb_private::CompilerType &rhs) {
1077 return lhs.GetTypeSystem() != rhs.GetTypeSystem() ||
1078 lhs.GetOpaqueQualType() != rhs.GetOpaqueQualType();