1 //===-- ValueObjectConstResult.h --------------------------------*- C++ -*-===// 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 #ifndef LLDB_CORE_VALUEOBJECTCONSTRESULT_H 10 #define LLDB_CORE_VALUEOBJECTCONSTRESULT_H 11 12 #include "lldb/Core/Value.h" 13 #include "lldb/Core/ValueObject.h" 14 #include "lldb/Core/ValueObjectConstResultImpl.h" 15 #include "lldb/Symbol/CompilerType.h" 16 #include "lldb/Utility/ConstString.h" 17 #include "lldb/Utility/Status.h" 18 #include "lldb/lldb-defines.h" 19 #include "lldb/lldb-enumerations.h" 20 #include "lldb/lldb-forward.h" 21 #include "lldb/lldb-private-enumerations.h" 22 #include "lldb/lldb-types.h" 23 24 #include <cstddef> 25 #include <cstdint> 26 #include <optional> 27 28 namespace lldb_private { 29 class DataExtractor; 30 class ExecutionContextScope; 31 class Module; 32 33 /// A frozen ValueObject copied into host memory. 34 class ValueObjectConstResult : public ValueObject { 35 public: 36 ~ValueObjectConstResult() override; 37 38 static lldb::ValueObjectSP 39 Create(ExecutionContextScope *exe_scope, lldb::ByteOrder byte_order, 40 uint32_t addr_byte_size, lldb::addr_t address = LLDB_INVALID_ADDRESS); 41 42 static lldb::ValueObjectSP 43 Create(ExecutionContextScope *exe_scope, const CompilerType &compiler_type, 44 ConstString name, const DataExtractor &data, 45 lldb::addr_t address = LLDB_INVALID_ADDRESS); 46 47 static lldb::ValueObjectSP 48 Create(ExecutionContextScope *exe_scope, const CompilerType &compiler_type, 49 ConstString name, const lldb::DataBufferSP &result_data_sp, 50 lldb::ByteOrder byte_order, uint32_t addr_size, 51 lldb::addr_t address = LLDB_INVALID_ADDRESS); 52 53 static lldb::ValueObjectSP 54 Create(ExecutionContextScope *exe_scope, const CompilerType &compiler_type, 55 ConstString name, lldb::addr_t address, 56 AddressType address_type, uint32_t addr_byte_size); 57 58 static lldb::ValueObjectSP Create(ExecutionContextScope *exe_scope, 59 Value &value, ConstString name, 60 Module *module = nullptr); 61 62 // When an expression fails to evaluate, we return an error 63 static lldb::ValueObjectSP Create(ExecutionContextScope *exe_scope, 64 const Status &error); 65 66 std::optional<uint64_t> GetByteSize() override; 67 68 lldb::ValueType GetValueType() const override; 69 70 llvm::Expected<uint32_t> CalculateNumChildren(uint32_t max) override; 71 72 ConstString GetTypeName() override; 73 74 ConstString GetDisplayTypeName() override; 75 76 bool IsInScope() override; 77 78 void SetByteSize(size_t size); 79 80 lldb::ValueObjectSP Dereference(Status &error) override; 81 82 lldb::ValueObjectSP GetSyntheticChildAtOffset( 83 uint32_t offset, const CompilerType &type, bool can_create, 84 ConstString name_const_str = ConstString()) override; 85 86 lldb::ValueObjectSP AddressOf(Status &error) override; 87 88 lldb::addr_t GetAddressOf(bool scalar_is_load_address = true, 89 AddressType *address_type = nullptr) override; 90 91 size_t GetPointeeData(DataExtractor &data, uint32_t item_idx = 0, 92 uint32_t item_count = 1) override; 93 94 lldb::addr_t GetLiveAddress() override { return m_impl.GetLiveAddress(); } 95 96 void SetLiveAddress(lldb::addr_t addr = LLDB_INVALID_ADDRESS, 97 AddressType address_type = eAddressTypeLoad) override { 98 m_impl.SetLiveAddress(addr, address_type); 99 } 100 101 lldb::ValueObjectSP 102 GetDynamicValue(lldb::DynamicValueType valueType) override; 103 104 lldb::LanguageType GetPreferredDisplayLanguage() override; 105 106 lldb::ValueObjectSP DoCast(const CompilerType &compiler_type) override; 107 108 protected: 109 bool UpdateValue() override; 110 111 CompilerType GetCompilerTypeImpl() override; 112 113 ConstString m_type_name; 114 std::optional<uint64_t> m_byte_size; 115 116 ValueObjectConstResultImpl m_impl; 117 118 private: 119 friend class ValueObjectConstResultImpl; 120 121 ValueObjectConstResult(ExecutionContextScope *exe_scope, 122 ValueObjectManager &manager, 123 lldb::ByteOrder byte_order, uint32_t addr_byte_size, 124 lldb::addr_t address); 125 126 ValueObjectConstResult(ExecutionContextScope *exe_scope, 127 ValueObjectManager &manager, 128 const CompilerType &compiler_type, ConstString name, 129 const DataExtractor &data, lldb::addr_t address); 130 131 ValueObjectConstResult(ExecutionContextScope *exe_scope, 132 ValueObjectManager &manager, 133 const CompilerType &compiler_type, ConstString name, 134 const lldb::DataBufferSP &result_data_sp, 135 lldb::ByteOrder byte_order, uint32_t addr_size, 136 lldb::addr_t address); 137 138 ValueObjectConstResult(ExecutionContextScope *exe_scope, 139 ValueObjectManager &manager, 140 const CompilerType &compiler_type, ConstString name, 141 lldb::addr_t address, AddressType address_type, 142 uint32_t addr_byte_size); 143 144 ValueObjectConstResult(ExecutionContextScope *exe_scope, 145 ValueObjectManager &manager, const Value &value, 146 ConstString name, Module *module = nullptr); 147 148 ValueObjectConstResult(ExecutionContextScope *exe_scope, 149 ValueObjectManager &manager, const Status &error); 150 151 ValueObject *CreateChildAtIndex(size_t idx) override { 152 return m_impl.CreateChildAtIndex(idx); 153 } 154 ValueObject *CreateSyntheticArrayMember(size_t idx) override { 155 return m_impl.CreateSyntheticArrayMember(idx); 156 } 157 158 ValueObjectConstResult(const ValueObjectConstResult &) = delete; 159 const ValueObjectConstResult & 160 operator=(const ValueObjectConstResult &) = delete; 161 }; 162 163 } // namespace lldb_private 164 165 #endif // LLDB_CORE_VALUEOBJECTCONSTRESULT_H 166