1 //===-- CompilerType.cpp ----------------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #include "lldb/Symbol/CompilerType.h"
11 #include "lldb/Core/Debugger.h"
12 #include "lldb/Core/StreamFile.h"
13 #include "lldb/Symbol/ClangASTContext.h"
14 #include "lldb/Symbol/ClangExternalASTSourceCommon.h"
15 #include "lldb/Symbol/Type.h"
16 #include "lldb/Target/ExecutionContext.h"
17 #include "lldb/Target/Process.h"
18 #include "lldb/Utility/ConstString.h"
19 #include "lldb/Utility/DataBufferHeap.h"
20 #include "lldb/Utility/DataExtractor.h"
21 #include "lldb/Utility/Scalar.h"
22 #include "lldb/Utility/Stream.h"
23 #include "lldb/Utility/StreamString.h"
29 using namespace lldb_private;
31 CompilerType::CompilerType(TypeSystem *type_system,
32 lldb::opaque_compiler_type_t type)
33 : m_type(type), m_type_system(type_system) {}
35 CompilerType::CompilerType(clang::ASTContext *ast, clang::QualType qual_type)
36 : m_type(qual_type.getAsOpaquePtr()),
37 m_type_system(ClangASTContext::GetASTContext(ast)) {
39 assert(m_type_system != nullptr);
42 CompilerType::~CompilerType() {}
46 bool CompilerType::IsAggregateType() const {
48 return m_type_system->IsAggregateType(m_type);
52 bool CompilerType::IsAnonymousType() const {
54 return m_type_system->IsAnonymousType(m_type);
58 bool CompilerType::IsArrayType(CompilerType *element_type_ptr, uint64_t *size,
59 bool *is_incomplete) const {
61 return m_type_system->IsArrayType(m_type, element_type_ptr, size,
65 element_type_ptr->Clear();
69 *is_incomplete = false;
73 bool CompilerType::IsVectorType(CompilerType *element_type,
74 uint64_t *size) const {
76 return m_type_system->IsVectorType(m_type, element_type, size);
80 bool CompilerType::IsRuntimeGeneratedType() const {
82 return m_type_system->IsRuntimeGeneratedType(m_type);
86 bool CompilerType::IsCharType() const {
88 return m_type_system->IsCharType(m_type);
92 bool CompilerType::IsCompleteType() const {
94 return m_type_system->IsCompleteType(m_type);
98 bool CompilerType::IsConst() const {
100 return m_type_system->IsConst(m_type);
104 bool CompilerType::IsCStringType(uint32_t &length) const {
106 return m_type_system->IsCStringType(m_type, length);
110 bool CompilerType::IsFunctionType(bool *is_variadic_ptr) const {
112 return m_type_system->IsFunctionType(m_type, is_variadic_ptr);
116 // Used to detect "Homogeneous Floating-point Aggregates"
118 CompilerType::IsHomogeneousAggregate(CompilerType *base_type_ptr) const {
120 return m_type_system->IsHomogeneousAggregate(m_type, base_type_ptr);
124 size_t CompilerType::GetNumberOfFunctionArguments() const {
126 return m_type_system->GetNumberOfFunctionArguments(m_type);
131 CompilerType::GetFunctionArgumentAtIndex(const size_t index) const {
133 return m_type_system->GetFunctionArgumentAtIndex(m_type, index);
134 return CompilerType();
137 bool CompilerType::IsFunctionPointerType() const {
139 return m_type_system->IsFunctionPointerType(m_type);
143 bool CompilerType::IsBlockPointerType(
144 CompilerType *function_pointer_type_ptr) const {
146 return m_type_system->IsBlockPointerType(m_type, function_pointer_type_ptr);
150 bool CompilerType::IsIntegerType(bool &is_signed) const {
152 return m_type_system->IsIntegerType(m_type, is_signed);
156 bool CompilerType::IsEnumerationType(bool &is_signed) const {
158 return m_type_system->IsEnumerationType(m_type, is_signed);
162 bool CompilerType::IsIntegerOrEnumerationType(bool &is_signed) const {
163 return IsIntegerType(is_signed) || IsEnumerationType(is_signed);
166 bool CompilerType::IsPointerType(CompilerType *pointee_type) const {
168 return m_type_system->IsPointerType(m_type, pointee_type);
171 pointee_type->Clear();
175 bool CompilerType::IsPointerOrReferenceType(CompilerType *pointee_type) const {
177 return m_type_system->IsPointerOrReferenceType(m_type, pointee_type);
180 pointee_type->Clear();
184 bool CompilerType::IsReferenceType(CompilerType *pointee_type,
185 bool *is_rvalue) const {
187 return m_type_system->IsReferenceType(m_type, pointee_type, is_rvalue);
190 pointee_type->Clear();
194 bool CompilerType::ShouldTreatScalarValueAsAddress() const {
196 return m_type_system->ShouldTreatScalarValueAsAddress(m_type);
200 bool CompilerType::IsFloatingPointType(uint32_t &count,
201 bool &is_complex) const {
203 return m_type_system->IsFloatingPointType(m_type, count, is_complex);
210 bool CompilerType::IsDefined() const {
212 return m_type_system->IsDefined(m_type);
216 bool CompilerType::IsPolymorphicClass() const {
218 return m_type_system->IsPolymorphicClass(m_type);
223 bool CompilerType::IsPossibleDynamicType(CompilerType *dynamic_pointee_type,
224 bool check_cplusplus,
225 bool check_objc) const {
227 return m_type_system->IsPossibleDynamicType(m_type, dynamic_pointee_type,
228 check_cplusplus, check_objc);
232 bool CompilerType::IsScalarType() const {
236 return m_type_system->IsScalarType(m_type);
239 bool CompilerType::IsTypedefType() const {
242 return m_type_system->IsTypedefType(m_type);
245 bool CompilerType::IsVoidType() const {
248 return m_type_system->IsVoidType(m_type);
251 bool CompilerType::IsPointerToScalarType() const {
255 return IsPointerType() && GetPointeeType().IsScalarType();
258 bool CompilerType::IsArrayOfScalarType() const {
259 CompilerType element_type;
260 if (IsArrayType(&element_type, nullptr, nullptr))
261 return element_type.IsScalarType();
265 bool CompilerType::IsBeingDefined() const {
268 return m_type_system->IsBeingDefined(m_type);
273 bool CompilerType::GetCompleteType() const {
276 return m_type_system->GetCompleteType(m_type);
279 // AST related queries
280 size_t CompilerType::GetPointerByteSize() const {
282 return m_type_system->GetPointerByteSize();
286 ConstString CompilerType::GetConstQualifiedTypeName() const {
287 return GetConstTypeName();
290 ConstString CompilerType::GetConstTypeName() const {
292 ConstString type_name(GetTypeName());
296 return ConstString("<invalid>");
299 ConstString CompilerType::GetTypeName() const {
301 return m_type_system->GetTypeName(m_type);
303 return ConstString("<invalid>");
306 ConstString CompilerType::GetDisplayTypeName() const { return GetTypeName(); }
308 uint32_t CompilerType::GetTypeInfo(
309 CompilerType *pointee_or_element_compiler_type) const {
313 return m_type_system->GetTypeInfo(m_type, pointee_or_element_compiler_type);
316 lldb::LanguageType CompilerType::GetMinimumLanguage() {
318 return lldb::eLanguageTypeC;
320 return m_type_system->GetMinimumLanguage(m_type);
323 lldb::TypeClass CompilerType::GetTypeClass() const {
325 return lldb::eTypeClassInvalid;
327 return m_type_system->GetTypeClass(m_type);
330 void CompilerType::SetCompilerType(TypeSystem *type_system,
331 lldb::opaque_compiler_type_t type) {
332 m_type_system = type_system;
336 void CompilerType::SetCompilerType(clang::ASTContext *ast,
337 clang::QualType qual_type) {
338 m_type_system = ClangASTContext::GetASTContext(ast);
339 m_type = qual_type.getAsOpaquePtr();
342 unsigned CompilerType::GetTypeQualifiers() const {
344 return m_type_system->GetTypeQualifiers(m_type);
348 // Creating related types
350 CompilerType CompilerType::GetArrayElementType(uint64_t *stride) const {
352 return m_type_system->GetArrayElementType(m_type, stride);
354 return CompilerType();
357 CompilerType CompilerType::GetArrayType(uint64_t size) const {
359 return m_type_system->GetArrayType(m_type, size);
361 return CompilerType();
364 CompilerType CompilerType::GetCanonicalType() const {
366 return m_type_system->GetCanonicalType(m_type);
367 return CompilerType();
370 CompilerType CompilerType::GetFullyUnqualifiedType() const {
372 return m_type_system->GetFullyUnqualifiedType(m_type);
373 return CompilerType();
376 int CompilerType::GetFunctionArgumentCount() const {
378 return m_type_system->GetFunctionArgumentCount(m_type);
383 CompilerType CompilerType::GetFunctionArgumentTypeAtIndex(size_t idx) const {
385 return m_type_system->GetFunctionArgumentTypeAtIndex(m_type, idx);
387 return CompilerType();
390 CompilerType CompilerType::GetFunctionReturnType() const {
392 return m_type_system->GetFunctionReturnType(m_type);
394 return CompilerType();
397 size_t CompilerType::GetNumMemberFunctions() const {
399 return m_type_system->GetNumMemberFunctions(m_type);
404 TypeMemberFunctionImpl CompilerType::GetMemberFunctionAtIndex(size_t idx) {
406 return m_type_system->GetMemberFunctionAtIndex(m_type, idx);
408 return TypeMemberFunctionImpl();
411 CompilerType CompilerType::GetNonReferenceType() const {
413 return m_type_system->GetNonReferenceType(m_type);
414 return CompilerType();
417 CompilerType CompilerType::GetPointeeType() const {
419 return m_type_system->GetPointeeType(m_type);
421 return CompilerType();
424 CompilerType CompilerType::GetPointerType() const {
426 return m_type_system->GetPointerType(m_type);
428 return CompilerType();
431 CompilerType CompilerType::GetLValueReferenceType() const {
433 return m_type_system->GetLValueReferenceType(m_type);
435 return CompilerType();
438 CompilerType CompilerType::GetRValueReferenceType() const {
440 return m_type_system->GetRValueReferenceType(m_type);
442 return CompilerType();
445 CompilerType CompilerType::AddConstModifier() const {
447 return m_type_system->AddConstModifier(m_type);
449 return CompilerType();
452 CompilerType CompilerType::AddVolatileModifier() const {
454 return m_type_system->AddVolatileModifier(m_type);
456 return CompilerType();
459 CompilerType CompilerType::AddRestrictModifier() const {
461 return m_type_system->AddRestrictModifier(m_type);
463 return CompilerType();
467 CompilerType::CreateTypedef(const char *name,
468 const CompilerDeclContext &decl_ctx) const {
470 return m_type_system->CreateTypedef(m_type, name, decl_ctx);
472 return CompilerType();
475 CompilerType CompilerType::GetTypedefedType() const {
477 return m_type_system->GetTypedefedType(m_type);
479 return CompilerType();
482 // Create related types using the current type's AST
485 CompilerType::GetBasicTypeFromAST(lldb::BasicType basic_type) const {
487 return m_type_system->GetBasicTypeFromAST(basic_type);
488 return CompilerType();
490 // Exploring the type
492 llvm::Optional<uint64_t>
493 CompilerType::GetBitSize(ExecutionContextScope *exe_scope) const {
495 return m_type_system->GetBitSize(m_type, exe_scope);
499 llvm::Optional<uint64_t>
500 CompilerType::GetByteSize(ExecutionContextScope *exe_scope) const {
501 if (llvm::Optional<uint64_t> bit_size = GetBitSize(exe_scope))
502 return (*bit_size + 7) / 8;
506 size_t CompilerType::GetTypeBitAlign() const {
508 return m_type_system->GetTypeBitAlign(m_type);
512 lldb::Encoding CompilerType::GetEncoding(uint64_t &count) const {
514 return lldb::eEncodingInvalid;
516 return m_type_system->GetEncoding(m_type, count);
519 lldb::Format CompilerType::GetFormat() const {
521 return lldb::eFormatDefault;
523 return m_type_system->GetFormat(m_type);
526 uint32_t CompilerType::GetNumChildren(bool omit_empty_base_classes,
527 const ExecutionContext *exe_ctx) const {
530 return m_type_system->GetNumChildren(m_type, omit_empty_base_classes,
534 lldb::BasicType CompilerType::GetBasicTypeEnumeration() const {
536 return m_type_system->GetBasicTypeEnumeration(m_type);
537 return eBasicTypeInvalid;
540 void CompilerType::ForEachEnumerator(
541 std::function<bool(const CompilerType &integer_type,
543 const llvm::APSInt &value)> const &callback) const {
545 return m_type_system->ForEachEnumerator(m_type, callback);
548 uint32_t CompilerType::GetNumFields() const {
551 return m_type_system->GetNumFields(m_type);
554 CompilerType CompilerType::GetFieldAtIndex(size_t idx, std::string &name,
555 uint64_t *bit_offset_ptr,
556 uint32_t *bitfield_bit_size_ptr,
557 bool *is_bitfield_ptr) const {
559 return CompilerType();
560 return m_type_system->GetFieldAtIndex(m_type, idx, name, bit_offset_ptr,
561 bitfield_bit_size_ptr, is_bitfield_ptr);
564 uint32_t CompilerType::GetNumDirectBaseClasses() const {
566 return m_type_system->GetNumDirectBaseClasses(m_type);
570 uint32_t CompilerType::GetNumVirtualBaseClasses() const {
572 return m_type_system->GetNumVirtualBaseClasses(m_type);
577 CompilerType::GetDirectBaseClassAtIndex(size_t idx,
578 uint32_t *bit_offset_ptr) const {
580 return m_type_system->GetDirectBaseClassAtIndex(m_type, idx,
582 return CompilerType();
586 CompilerType::GetVirtualBaseClassAtIndex(size_t idx,
587 uint32_t *bit_offset_ptr) const {
589 return m_type_system->GetVirtualBaseClassAtIndex(m_type, idx,
591 return CompilerType();
594 uint32_t CompilerType::GetIndexOfFieldWithName(
595 const char *name, CompilerType *field_compiler_type_ptr,
596 uint64_t *bit_offset_ptr, uint32_t *bitfield_bit_size_ptr,
597 bool *is_bitfield_ptr) const {
598 unsigned count = GetNumFields();
599 std::string field_name;
600 for (unsigned index = 0; index < count; index++) {
601 CompilerType field_compiler_type(
602 GetFieldAtIndex(index, field_name, bit_offset_ptr,
603 bitfield_bit_size_ptr, is_bitfield_ptr));
604 if (strcmp(field_name.c_str(), name) == 0) {
605 if (field_compiler_type_ptr)
606 *field_compiler_type_ptr = field_compiler_type;
613 CompilerType CompilerType::GetChildCompilerTypeAtIndex(
614 ExecutionContext *exe_ctx, size_t idx, bool transparent_pointers,
615 bool omit_empty_base_classes, bool ignore_array_bounds,
616 std::string &child_name, uint32_t &child_byte_size,
617 int32_t &child_byte_offset, uint32_t &child_bitfield_bit_size,
618 uint32_t &child_bitfield_bit_offset, bool &child_is_base_class,
619 bool &child_is_deref_of_parent, ValueObject *valobj,
620 uint64_t &language_flags) const {
622 return CompilerType();
623 return m_type_system->GetChildCompilerTypeAtIndex(
624 m_type, exe_ctx, idx, transparent_pointers, omit_empty_base_classes,
625 ignore_array_bounds, child_name, child_byte_size, child_byte_offset,
626 child_bitfield_bit_size, child_bitfield_bit_offset, child_is_base_class,
627 child_is_deref_of_parent, valobj, language_flags);
630 // Look for a child member (doesn't include base classes, but it does include
631 // their members) in the type hierarchy. Returns an index path into
632 // "clang_type" on how to reach the appropriate member.
651 // If we have a clang type that describes "class C", and we wanted to looked
654 // With omit_empty_base_classes == false we would get an integer array back
655 // with: { 1, 1 } The first index 1 is the child index for "class A" within
656 // class C The second index 1 is the child index for "m_b" within class A
658 // With omit_empty_base_classes == true we would get an integer array back
659 // with: { 0, 1 } The first index 0 is the child index for "class A" within
660 // class C (since class B doesn't have any members it doesn't count) The second
661 // index 1 is the child index for "m_b" within class A
663 size_t CompilerType::GetIndexOfChildMemberWithName(
664 const char *name, bool omit_empty_base_classes,
665 std::vector<uint32_t> &child_indexes) const {
666 if (IsValid() && name && name[0]) {
667 return m_type_system->GetIndexOfChildMemberWithName(
668 m_type, name, omit_empty_base_classes, child_indexes);
673 size_t CompilerType::GetNumTemplateArguments() const {
675 return m_type_system->GetNumTemplateArguments(m_type);
680 TemplateArgumentKind CompilerType::GetTemplateArgumentKind(size_t idx) const {
682 return m_type_system->GetTemplateArgumentKind(m_type, idx);
683 return eTemplateArgumentKindNull;
686 CompilerType CompilerType::GetTypeTemplateArgument(size_t idx) const {
688 return m_type_system->GetTypeTemplateArgument(m_type, idx);
690 return CompilerType();
693 llvm::Optional<CompilerType::IntegralTemplateArgument>
694 CompilerType::GetIntegralTemplateArgument(size_t idx) const {
696 return m_type_system->GetIntegralTemplateArgument(m_type, idx);
700 CompilerType CompilerType::GetTypeForFormatters() const {
702 return m_type_system->GetTypeForFormatters(m_type);
703 return CompilerType();
706 LazyBool CompilerType::ShouldPrintAsOneLiner(ValueObject *valobj) const {
708 return m_type_system->ShouldPrintAsOneLiner(m_type, valobj);
709 return eLazyBoolCalculate;
712 bool CompilerType::IsMeaninglessWithoutDynamicResolution() const {
714 return m_type_system->IsMeaninglessWithoutDynamicResolution(m_type);
718 // Get the index of the child of "clang_type" whose name matches. This function
719 // doesn't descend into the children, but only looks one level deep and name
720 // matches can include base class names.
723 CompilerType::GetIndexOfChildWithName(const char *name,
724 bool omit_empty_base_classes) const {
725 if (IsValid() && name && name[0]) {
726 return m_type_system->GetIndexOfChildWithName(m_type, name,
727 omit_empty_base_classes);
732 size_t CompilerType::ConvertStringToFloatValue(const char *s, uint8_t *dst,
733 size_t dst_size) const {
735 return m_type_system->ConvertStringToFloatValue(m_type, s, dst, dst_size);
740 #define DEPTH_INCREMENT 2
742 void CompilerType::DumpValue(ExecutionContext *exe_ctx, Stream *s,
743 lldb::Format format, const DataExtractor &data,
744 lldb::offset_t data_byte_offset,
745 size_t data_byte_size, uint32_t bitfield_bit_size,
746 uint32_t bitfield_bit_offset, bool show_types,
747 bool show_summary, bool verbose, uint32_t depth) {
750 m_type_system->DumpValue(m_type, exe_ctx, s, format, data, data_byte_offset,
751 data_byte_size, bitfield_bit_size,
752 bitfield_bit_offset, show_types, show_summary,
756 bool CompilerType::DumpTypeValue(Stream *s, lldb::Format format,
757 const DataExtractor &data,
758 lldb::offset_t byte_offset, size_t byte_size,
759 uint32_t bitfield_bit_size,
760 uint32_t bitfield_bit_offset,
761 ExecutionContextScope *exe_scope) {
764 return m_type_system->DumpTypeValue(m_type, s, format, data, byte_offset,
765 byte_size, bitfield_bit_size,
766 bitfield_bit_offset, exe_scope);
769 void CompilerType::DumpSummary(ExecutionContext *exe_ctx, Stream *s,
770 const DataExtractor &data,
771 lldb::offset_t data_byte_offset,
772 size_t data_byte_size) {
774 m_type_system->DumpSummary(m_type, exe_ctx, s, data, data_byte_offset,
778 void CompilerType::DumpTypeDescription() const {
780 m_type_system->DumpTypeDescription(m_type);
783 void CompilerType::DumpTypeDescription(Stream *s) const {
785 m_type_system->DumpTypeDescription(m_type, s);
790 LLVM_DUMP_METHOD void CompilerType::dump() const {
792 m_type_system->dump(m_type);
794 llvm::errs() << "<invalid>\n";
798 bool CompilerType::GetValueAsScalar(const lldb_private::DataExtractor &data,
799 lldb::offset_t data_byte_offset,
800 size_t data_byte_size,
801 Scalar &value) const {
805 if (IsAggregateType()) {
806 return false; // Aggregate types don't have scalar values
809 lldb::Encoding encoding = GetEncoding(count);
811 if (encoding == lldb::eEncodingInvalid || count != 1)
814 llvm::Optional<uint64_t> byte_size = GetByteSize(nullptr);
817 lldb::offset_t offset = data_byte_offset;
819 case lldb::eEncodingInvalid:
821 case lldb::eEncodingVector:
823 case lldb::eEncodingUint:
824 if (*byte_size <= sizeof(unsigned long long)) {
825 uint64_t uval64 = data.GetMaxU64(&offset, *byte_size);
826 if (*byte_size <= sizeof(unsigned int)) {
827 value = (unsigned int)uval64;
829 } else if (*byte_size <= sizeof(unsigned long)) {
830 value = (unsigned long)uval64;
832 } else if (*byte_size <= sizeof(unsigned long long)) {
833 value = (unsigned long long)uval64;
840 case lldb::eEncodingSint:
841 if (*byte_size <= sizeof(long long)) {
842 int64_t sval64 = data.GetMaxS64(&offset, *byte_size);
843 if (*byte_size <= sizeof(int)) {
846 } else if (*byte_size <= sizeof(long)) {
847 value = (long)sval64;
849 } else if (*byte_size <= sizeof(long long)) {
850 value = (long long)sval64;
857 case lldb::eEncodingIEEE754:
858 if (*byte_size <= sizeof(long double)) {
861 if (*byte_size == sizeof(float)) {
862 if (sizeof(float) == sizeof(uint32_t)) {
863 u32 = data.GetU32(&offset);
864 value = *((float *)&u32);
866 } else if (sizeof(float) == sizeof(uint64_t)) {
867 u64 = data.GetU64(&offset);
868 value = *((float *)&u64);
871 } else if (*byte_size == sizeof(double)) {
872 if (sizeof(double) == sizeof(uint32_t)) {
873 u32 = data.GetU32(&offset);
874 value = *((double *)&u32);
876 } else if (sizeof(double) == sizeof(uint64_t)) {
877 u64 = data.GetU64(&offset);
878 value = *((double *)&u64);
881 } else if (*byte_size == sizeof(long double)) {
882 if (sizeof(long double) == sizeof(uint32_t)) {
883 u32 = data.GetU32(&offset);
884 value = *((long double *)&u32);
886 } else if (sizeof(long double) == sizeof(uint64_t)) {
887 u64 = data.GetU64(&offset);
888 value = *((long double *)&u64);
899 bool CompilerType::SetValueFromScalar(const Scalar &value, Stream &strm) {
903 // Aggregate types don't have scalar values
904 if (!IsAggregateType()) {
905 strm.GetFlags().Set(Stream::eBinary);
907 lldb::Encoding encoding = GetEncoding(count);
909 if (encoding == lldb::eEncodingInvalid || count != 1)
912 llvm::Optional<uint64_t> bit_width = GetBitSize(nullptr);
916 // This function doesn't currently handle non-byte aligned assignments
917 if ((*bit_width % 8) != 0)
920 const uint64_t byte_size = (*bit_width + 7) / 8;
922 case lldb::eEncodingInvalid:
924 case lldb::eEncodingVector:
926 case lldb::eEncodingUint:
929 strm.PutHex8(value.UInt());
932 strm.PutHex16(value.UInt());
935 strm.PutHex32(value.UInt());
938 strm.PutHex64(value.ULongLong());
945 case lldb::eEncodingSint:
948 strm.PutHex8(value.SInt());
951 strm.PutHex16(value.SInt());
954 strm.PutHex32(value.SInt());
957 strm.PutHex64(value.SLongLong());
964 case lldb::eEncodingIEEE754:
965 if (byte_size <= sizeof(long double)) {
966 if (byte_size == sizeof(float)) {
967 strm.PutFloat(value.Float());
969 } else if (byte_size == sizeof(double)) {
970 strm.PutDouble(value.Double());
972 } else if (byte_size == sizeof(long double)) {
973 strm.PutDouble(value.LongDouble());
983 bool CompilerType::ReadFromMemory(lldb_private::ExecutionContext *exe_ctx,
984 lldb::addr_t addr, AddressType address_type,
985 lldb_private::DataExtractor &data) {
989 // Can't convert a file address to anything valid without more context (which
990 // Module it came from)
991 if (address_type == eAddressTypeFile)
994 if (!GetCompleteType())
998 GetByteSize(exe_ctx ? exe_ctx->GetBestExecutionContextScope() : nullptr);
1002 if (data.GetByteSize() < *byte_size) {
1003 lldb::DataBufferSP data_sp(new DataBufferHeap(*byte_size, '\0'));
1004 data.SetData(data_sp);
1007 uint8_t *dst = const_cast<uint8_t *>(data.PeekData(0, *byte_size));
1008 if (dst != nullptr) {
1009 if (address_type == eAddressTypeHost) {
1012 // The address is an address in this process, so just copy it
1013 memcpy(dst, reinterpret_cast<uint8_t *>(addr), *byte_size);
1016 Process *process = nullptr;
1018 process = exe_ctx->GetProcessPtr();
1021 return process->ReadMemory(addr, dst, *byte_size, error) == *byte_size;
1028 bool CompilerType::WriteToMemory(lldb_private::ExecutionContext *exe_ctx,
1029 lldb::addr_t addr, AddressType address_type,
1030 StreamString &new_value) {
1034 // Can't convert a file address to anything valid without more context (which
1035 // Module it came from)
1036 if (address_type == eAddressTypeFile)
1039 if (!GetCompleteType())
1043 GetByteSize(exe_ctx ? exe_ctx->GetBestExecutionContextScope() : nullptr);
1047 if (*byte_size > 0) {
1048 if (address_type == eAddressTypeHost) {
1049 // The address is an address in this process, so just copy it
1050 memcpy((void *)addr, new_value.GetData(), *byte_size);
1053 Process *process = nullptr;
1055 process = exe_ctx->GetProcessPtr();
1058 return process->WriteMemory(addr, new_value.GetData(), *byte_size,
1059 error) == *byte_size;
1066 bool lldb_private::operator==(const lldb_private::CompilerType &lhs,
1067 const lldb_private::CompilerType &rhs) {
1068 return lhs.GetTypeSystem() == rhs.GetTypeSystem() &&
1069 lhs.GetOpaqueQualType() == rhs.GetOpaqueQualType();
1072 bool lldb_private::operator!=(const lldb_private::CompilerType &lhs,
1073 const lldb_private::CompilerType &rhs) {
1074 return !(lhs == rhs);