================
@@ -103,3 +146,89 @@ lldb::SBValue Variables::FindVariable(uint64_t 
variablesReference,
   }
   return variable;
 }
+
+std::optional<ScopeData>
+Variables::GetScopeKind(const int64_t variablesReference) {
+  auto scope_kind_iter = m_scope_kinds.find(variablesReference);
+  if (scope_kind_iter == m_scope_kinds.end()) {
+    return std::nullopt;
+  }
+
+  auto scope_iter = m_frames.find(scope_kind_iter->second.second);
+  if (scope_iter == m_frames.end()) {
+    return std::nullopt;
+  }
+
+  ScopeData scope_data = ScopeData();
+  scope_data.kind = scope_kind_iter->second.first;
+  lldb::SBValueList *scope = scope_iter->second.GetScope(scope_data.kind);
+
+  if (scope == nullptr) {
+    return std::nullopt;
+  }
+
+  scope_data.scope = *scope;
+  return scope_data;
+}
+
+lldb::SBValueList *Variables::GetScope(const uint64_t dap_frame_id,
+                                       const eScopeKind kind) {
+
+  auto frame = m_frames.find(dap_frame_id);
+  if (frame == m_frames.end()) {
+    return nullptr;
+  }
+
+  return frame->second.GetScope(kind);
+}
+
+std::vector<protocol::Scope> Variables::ReadyFrame(const uint64_t dap_frame_id,
+                                                   lldb::SBFrame &frame) {
+
+  if (m_frames.find(dap_frame_id) == m_frames.end()) {
+
+    auto locals = frame.GetVariables(/*arguments=*/true,
+                                     /*locals=*/true,
+                                     /*statics=*/false,
+                                     /*in_scope_only=*/true);
+
+    auto globals = frame.GetVariables(/*arguments=*/false,
+                                      /*locals=*/false,
+                                      /*statics=*/true,
+                                      /*in_scope_only=*/true);
+
+    auto registers = frame.GetRegisters();
+
+    m_frames.insert(
+        std::make_pair(dap_frame_id, FrameScopes{locals, globals, registers}));
+  }
+
+  std::vector<protocol::Scope> scopes = {};
+
+  int64_t locals_ref = GetNewVariableReference(false);
+
+  scopes.push_back(CreateScope(
+      eScopeKind::Locals, locals_ref,
+      GetScope(dap_frame_id, eScopeKind::Locals)->GetSize(), false));
+
+  m_scope_kinds[locals_ref] = std::make_pair(eScopeKind::Locals, dap_frame_id);
+
+  int64_t globals_ref = GetNewVariableReference(false);
+  scopes.push_back(CreateScope(
+      eScopeKind::Globals, globals_ref,
+      GetScope(dap_frame_id, eScopeKind::Globals)->GetSize(), false));
+  m_scope_kinds[globals_ref] =
+      std::make_pair(eScopeKind::Globals, dap_frame_id);
----------------
da-viper wrote:

```suggestion
  m_scope_kinds.try_emplace(globals_ref, eScopeKind::Globals, dap_frame_id);
```
apply to other scope types

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

Reply via email to