================
@@ -64,6 +64,71 @@ enum LocationDescriptionKind {
   /* Composite*/
 };
 
+/// Keeps the location description kind associated with each eagerly
+/// materialized value on the DWARF expression stack.
+class EvaluationStack {
+public:
+  bool empty() const { return m_values.empty(); }
+  size_t size() const { return m_values.size(); }
+
+  Value &back() { return m_values.back(); }
+  const Value &back() const { return m_values.back(); }
+
+  Value &operator[](size_t index) { return m_values[index]; }
+  const Value &operator[](size_t index) const { return m_values[index]; }
+
+  void push_back(Value value, LocationDescriptionKind loc_desc_kind = Memory) {
+    m_values.push_back(std::move(value));
+    m_loc_desc_kinds.push_back(loc_desc_kind);
+  }
+
+  void PushCopy(size_t index) {
+    push_back(m_values[index], m_loc_desc_kinds[index]);
+  }
+
+  void pop_back() {
+    m_values.pop_back();
+    m_loc_desc_kinds.pop_back();
+  }
+
+  LocationDescriptionKind GetLocationDescriptionKind() const {
+    return m_loc_desc_kinds.back();
+  }
+
+  void SetLocationDescriptionKind(LocationDescriptionKind loc_desc_kind) {
+    m_loc_desc_kinds.back() = loc_desc_kind;
+  }
+
+  void SwapTopTwo() {
+    const size_t last = size() - 1;
+    std::swap(m_values[last], m_values[last - 1]);
+    std::swap(m_loc_desc_kinds[last], m_loc_desc_kinds[last - 1]);
+  }
+
+  void RotateTopThree() {
+    const size_t last = size() - 1;
+    Value old_top = m_values[last];
+    m_values[last] = m_values[last - 1];
+    m_values[last - 1] = m_values[last - 2];
+    m_values[last - 2] = std::move(old_top);
+
+    LocationDescriptionKind old_top_kind = m_loc_desc_kinds[last];
+    m_loc_desc_kinds[last] = m_loc_desc_kinds[last - 1];
+    m_loc_desc_kinds[last - 1] = m_loc_desc_kinds[last - 2];
+    m_loc_desc_kinds[last - 2] = old_top_kind;
+  }
+
+  DWARFExpression::Stack &Values() { return m_values; }
+
+  void SyncLocationDescriptionKinds() {
+    m_loc_desc_kinds.resize(m_values.size(), Memory);
+  }
+
+private:
+  DWARFExpression::Stack m_values;
+  std::vector<LocationDescriptionKind> m_loc_desc_kinds;
----------------
MrEven132 wrote:

Thanks for pointing this out. I changed the stack to store a single vector of 
entries, with each entry containing both the value and its location-description 
kind. This removes the synchronization invariant between the two vectors.

https://github.com/llvm/llvm-project/pull/219372
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to