Closes #119784 Probably closes #147105 as well, but I couldn't test due to #156473: This PR fixes two bugs: 1. It generates unique variable reference IDs per suspended debuggee state. 2. It stores all created variables in a stopped state instead of dropping variables in unselected scopes. So it can properly handle all scope/variable requests It does this by storing all variables in their respective scopes and using that mapping in request handlers that relied on the old mapping. It dynamically creates new variable/scope IDs instead of resetting IDs whenever a new scope is created. I also removed some unused code as well. --------- Co-authored-by: Med Ismail Bennani <ismail@bennani.ma> Co-authored-by: Jonas Devlieghere <jonas@devlieghere.com> Co-authored-by: Ebuka Ezike <yerimyah1@gmail.com>
46 lines
2.0 KiB
C++
46 lines
2.0 KiB
C++
//===-- ScopesRequestHandler.cpp ------------------------------------------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "DAP.h"
|
|
#include "RequestHandler.h"
|
|
#include "Variables.h"
|
|
|
|
using namespace lldb_dap::protocol;
|
|
namespace lldb_dap {
|
|
|
|
llvm::Expected<ScopesResponseBody>
|
|
ScopesRequestHandler::Run(const ScopesArguments &args) const {
|
|
lldb::SBFrame frame = dap.GetLLDBFrame(args.frameId);
|
|
|
|
// As the user selects different stack frames in the GUI, a "scopes" request
|
|
// will be sent to the DAP. This is the only way we know that the user has
|
|
// selected a frame in a thread. There are no other notifications that are
|
|
// sent and VS code doesn't allow multiple frames to show variables
|
|
// concurrently. If we select the thread and frame as the "scopes" requests
|
|
// are sent, this allows users to type commands in the debugger console
|
|
// with a backtick character to run lldb commands and these lldb commands
|
|
// will now have the right context selected as they are run. If the user
|
|
// types "`bt" into the debugger console, and we had another thread selected
|
|
// in the LLDB library, we would show the wrong thing to the user. If the
|
|
// users switch threads with a lldb command like "`thread select 14", the
|
|
// GUI will not update as there are no "event" notification packets that
|
|
// allow us to change the currently selected thread or frame in the GUI that
|
|
// I am aware of.
|
|
if (frame.IsValid()) {
|
|
frame.GetThread().GetProcess().SetSelectedThread(frame.GetThread());
|
|
frame.GetThread().SetSelectedFrame(frame.GetFrameID());
|
|
}
|
|
|
|
std::vector<protocol::Scope> scopes =
|
|
dap.variables.CreateScopes(args.frameId, frame);
|
|
|
|
return ScopesResponseBody{std::move(scopes)};
|
|
}
|
|
|
|
} // namespace lldb_dap
|