From 870254b168e73b277d7eee1efde135066ac2c088 Mon Sep 17 00:00:00 2001 From: Ricardo Subtil Date: Mon, 30 Sep 2024 14:15:09 +0100 Subject: [PATCH] Support object inspection through DAP `evaluate` request --- editor/debugger/debug_adapter/debug_adapter_parser.cpp | 7 +++++-- editor/debugger/debug_adapter/debug_adapter_protocol.cpp | 4 ++++ editor/debugger/debug_adapter/debug_adapter_protocol.h | 1 + 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/editor/debugger/debug_adapter/debug_adapter_parser.cpp b/editor/debugger/debug_adapter/debug_adapter_parser.cpp index 8e2f037a1c3..02c414f13d1 100644 --- a/editor/debugger/debug_adapter/debug_adapter_parser.cpp +++ b/editor/debugger/debug_adapter/debug_adapter_parser.cpp @@ -492,9 +492,12 @@ Dictionary DebugAdapterParser::req_evaluate(const Dictionary &p_params) const { Dictionary args = p_params["arguments"]; - String value = EditorDebuggerNode::get_singleton()->get_var_value(args["expression"]); + String eval = args["expression"]; + String value = EditorDebuggerNode::get_singleton()->get_var_value(eval); + HashMap::ConstIterator variableID = DebugAdapterProtocol::get_singleton()->variable_eval_list.find(eval); + body["result"] = value; - body["variablesReference"] = 0; + body["variablesReference"] = variableID ? variableID->value : 0; return response; } diff --git a/editor/debugger/debug_adapter/debug_adapter_protocol.cpp b/editor/debugger/debug_adapter/debug_adapter_protocol.cpp index f8f5584ba6d..51516effa5d 100644 --- a/editor/debugger/debug_adapter/debug_adapter_protocol.cpp +++ b/editor/debugger/debug_adapter/debug_adapter_protocol.cpp @@ -186,6 +186,7 @@ void DebugAdapterProtocol::reset_stack_info() { stackframe_list.clear(); variable_list.clear(); + variable_eval_list.clear(); object_list.clear(); object_pending_set.clear(); } @@ -1131,6 +1132,9 @@ void DebugAdapterProtocol::on_debug_stack_frame_var(const Array &p_data) { variable.value = stack_var.value; variable.type = Variant::get_type_name(stack_var.value.get_type()); variable.variablesReference = parse_variant(stack_var.value); + if (variable.variablesReference != 0) { + variable_eval_list.insert(variable.name, variable.variablesReference); + } variable_list.find(var_id)->value.push_back(variable.to_json()); _remaining_vars--; diff --git a/editor/debugger/debug_adapter/debug_adapter_protocol.h b/editor/debugger/debug_adapter/debug_adapter_protocol.h index 29d7457ee76..2a2591bea1b 100644 --- a/editor/debugger/debug_adapter/debug_adapter_protocol.h +++ b/editor/debugger/debug_adapter/debug_adapter_protocol.h @@ -125,6 +125,7 @@ private: List breakpoint_list; HashMap, DAP::StackFrame> stackframe_list; HashMap variable_list; + HashMap variable_eval_list; HashMap object_list; HashSet object_pending_set;