================
@@ -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] =
----------------
da-viper wrote:
Could we change how the `readyFrame` function works as we are always checking
the map every time we need a `FrameScope` instead do it once and use that
value. something like.
```cpp
std::vector<protocol::Scope> Variables::ReadyFrame(const uint64_t dap_frame_id,
lldb::SBFrame &frame) {
auto iter = m_frames.find(dap_frame_id);
if (iter == 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();
iter = m_frames.emplace(dap_frame_id, FrameScopes{locals, globals,
registers})
.first;
}
const FrameScopes &frame_scopes = iter->second;
auto create_and_store_scope = [&](eScopeKind kind, uint32_t size) {
const int64_t ref = GetNewVariableReference(false);
m_scope_kinds.try_emplace(ref, kind, dap_frame_id);
return CreateScope(kind, ref, size, false);
};
return {
create_and_store_scope(eScopeKind::Locals, frame_scopes.locals.GetSize()),
create_and_store_scope(eScopeKind::Globals,
frame_scopes.globals.GetSize()),
create_and_store_scope(eScopeKind::Registers,
frame_scopes.registers.GetSize())};
}
```
https://github.com/llvm/llvm-project/pull/124232
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits