Coverage Report

Created: 2023-09-30 09:22

/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/include/lldb/Core/Value.h
Line
Count
Source
1
//===-- Value.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_VALUE_H
10
#define LLDB_CORE_VALUE_H
11
12
#include "lldb/Symbol/CompilerType.h"
13
#include "lldb/Utility/DataBufferHeap.h"
14
#include "lldb/Utility/Scalar.h"
15
#include "lldb/Utility/Status.h"
16
#include "lldb/lldb-enumerations.h"
17
#include "lldb/lldb-private-enumerations.h"
18
#include "lldb/lldb-private-types.h"
19
20
#include "llvm/ADT/APInt.h"
21
22
#include <vector>
23
24
#include <cstdint>
25
#include <cstring>
26
27
namespace lldb_private {
28
class DataExtractor;
29
class ExecutionContext;
30
class Module;
31
class Stream;
32
class Type;
33
class Variable;
34
}
35
36
namespace lldb_private {
37
38
class Value {
39
public:
40
  /// Type that describes Value::m_value.
41
  enum class ValueType {
42
    Invalid = -1,
43
    // m_value contains:
44
    /// A raw scalar value.
45
    Scalar = 0,
46
    /// A file address value.
47
    FileAddress,
48
    /// A load address value.
49
    LoadAddress,
50
    /// A host address value (for memory in the process that < A is
51
    /// using liblldb).
52
    HostAddress
53
  };
54
55
  /// Type that describes Value::m_context.
56
  enum class ContextType {
57
    // m_context contains:
58
    /// Undefined.
59
    Invalid = -1,
60
    /// RegisterInfo * (can be a scalar or a vector register).
61
    RegisterInfo = 0,
62
    /// lldb_private::Type *.
63
    LLDBType,
64
    /// lldb_private::Variable *.
65
    Variable
66
  };
67
68
  Value();
69
  Value(const Scalar &scalar);
70
  Value(const void *bytes, int len);
71
  Value(const Value &rhs);
72
73
  void SetBytes(const void *bytes, int len);
74
75
  void AppendBytes(const void *bytes, int len);
76
77
  Value &operator=(const Value &rhs);
78
79
  const CompilerType &GetCompilerType();
80
81
  void SetCompilerType(const CompilerType &compiler_type);
82
83
  ValueType GetValueType() const;
84
85
  AddressType GetValueAddressType() const;
86
87
109k
  ContextType GetContextType() const { return m_context_type; }
88
89
127k
  void SetValueType(ValueType value_type) { m_value_type = value_type; }
90
91
1.57k
  void ClearContext() {
92
1.57k
    m_context = nullptr;
93
1.57k
    m_context_type = ContextType::Invalid;
94
1.57k
  }
95
96
29.8k
  void SetContext(ContextType context_type, void *p) {
97
29.8k
    m_context_type = context_type;
98
29.8k
    m_context = p;
99
29.8k
    if (m_context_type == ContextType::RegisterInfo) {
100
5.33k
      RegisterInfo *reg_info = GetRegisterInfo();
101
5.33k
      if (reg_info->encoding == lldb::eEncodingVector)
102
505
        SetValueType(ValueType::Scalar);
103
5.33k
    }
104
29.8k
  }
105
106
  RegisterInfo *GetRegisterInfo() const;
107
108
  Type *GetType();
109
110
  Scalar &ResolveValue(ExecutionContext *exe_ctx, Module *module = nullptr);
111
112
202
  const Scalar &GetScalar() const { return m_value; }
113
114
280k
  Scalar &GetScalar() { return m_value; }
115
116
  size_t ResizeData(size_t len);
117
118
  size_t AppendDataToHostBuffer(const Value &rhs);
119
120
47
  DataBufferHeap &GetBuffer() { return m_data_buffer; }
121
122
18
  const DataBufferHeap &GetBuffer() const { return m_data_buffer; }
123
124
  bool ValueOf(ExecutionContext *exe_ctx);
125
126
  Variable *GetVariable();
127
128
  void Dump(Stream *strm);
129
130
  lldb::Format GetValueDefaultFormat();
131
132
  uint64_t GetValueByteSize(Status *error_ptr, ExecutionContext *exe_ctx);
133
134
  Status GetValueAsData(ExecutionContext *exe_ctx, DataExtractor &data,
135
                        Module *module); // Can be nullptr
136
137
  static const char *GetValueTypeAsCString(ValueType context_type);
138
139
  static const char *GetContextTypeAsCString(ContextType context_type);
140
141
  /// Convert this value's file address to a load address, if possible.
142
  void ConvertToLoadAddress(Module *module, Target *target);
143
144
  bool GetData(DataExtractor &data);
145
146
  void Clear();
147
148
  static ValueType GetValueTypeFromAddressType(AddressType address_type);
149
150
protected:
151
  Scalar m_value;
152
  CompilerType m_compiler_type;
153
  void *m_context = nullptr;
154
  ValueType m_value_type = ValueType::Scalar;
155
  ContextType m_context_type = ContextType::Invalid;
156
  DataBufferHeap m_data_buffer;
157
};
158
159
class ValueList {
160
public:
161
4.35k
  ValueList() = default;
162
8.30k
  ~ValueList() = default;
163
164
3.98k
  ValueList(const ValueList &rhs) = default;
165
11
  ValueList &operator=(const ValueList &rhs) = default;
166
167
  // void InsertValue (Value *value, size_t idx);
168
  void PushValue(const Value &value);
169
170
  size_t GetSize();
171
  Value *GetValueAtIndex(size_t idx);
172
  void Clear();
173
174
private:
175
  typedef std::vector<Value> collection;
176
177
  collection m_values;
178
};
179
180
} // namespace lldb_private
181
182
#endif // LLDB_CORE_VALUE_H