Skip to content

Commit 39be0f5

Browse files
authored
Merge branch 'main' into cir_upstream_vec_binary_ops
2 parents 4d82633 + 5fa985e commit 39be0f5

File tree

10 files changed

+362
-179
lines changed

10 files changed

+362
-179
lines changed

lldb/tools/lldb-dap/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ add_lldb_library(lldbDAP
2323
RunInTerminal.cpp
2424
SourceBreakpoint.cpp
2525
Transport.cpp
26+
Variables.cpp
2627
Watchpoint.cpp
2728

2829
Handler/ResponseHandler.cpp

lldb/tools/lldb-dap/DAP.cpp

Lines changed: 1 addition & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,9 @@ llvm::StringRef DAP::debug_adapter_path = "";
118118
DAP::DAP(Log *log, const ReplMode default_repl_mode,
119119
std::vector<std::string> pre_init_commands, Transport &transport)
120120
: log(log), transport(transport), broadcaster("lldb-dap"),
121-
exception_breakpoints(), focus_tid(LLDB_INVALID_THREAD_ID),
122-
stop_at_entry(false), is_attach(false),
123-
restarting_process_id(LLDB_INVALID_PROCESS_ID), configuration_done(false),
124-
waiting_for_run_in_terminal(false),
125121
progress_event_reporter(
126122
[&](const ProgressEvent &event) { SendJSON(event.ToJSON()); }),
127-
reverse_request_seq(0), repl_mode(default_repl_mode) {
123+
repl_mode(default_repl_mode) {
128124
configuration.preInitCommands = std::move(pre_init_commands);
129125
RegisterRequests();
130126
}
@@ -1021,45 +1017,6 @@ lldb::SBError DAP::WaitForProcessToStop(std::chrono::seconds seconds) {
10211017
return error;
10221018
}
10231019

1024-
void Variables::Clear() {
1025-
locals.Clear();
1026-
globals.Clear();
1027-
registers.Clear();
1028-
referenced_variables.clear();
1029-
}
1030-
1031-
int64_t Variables::GetNewVariableReference(bool is_permanent) {
1032-
if (is_permanent)
1033-
return next_permanent_var_ref++;
1034-
return next_temporary_var_ref++;
1035-
}
1036-
1037-
bool Variables::IsPermanentVariableReference(int64_t var_ref) {
1038-
return var_ref >= PermanentVariableStartIndex;
1039-
}
1040-
1041-
lldb::SBValue Variables::GetVariable(int64_t var_ref) const {
1042-
if (IsPermanentVariableReference(var_ref)) {
1043-
auto pos = referenced_permanent_variables.find(var_ref);
1044-
if (pos != referenced_permanent_variables.end())
1045-
return pos->second;
1046-
} else {
1047-
auto pos = referenced_variables.find(var_ref);
1048-
if (pos != referenced_variables.end())
1049-
return pos->second;
1050-
}
1051-
return lldb::SBValue();
1052-
}
1053-
1054-
int64_t Variables::InsertVariable(lldb::SBValue variable, bool is_permanent) {
1055-
int64_t var_ref = GetNewVariableReference(is_permanent);
1056-
if (is_permanent)
1057-
referenced_permanent_variables.insert(std::make_pair(var_ref, variable));
1058-
else
1059-
referenced_variables.insert(std::make_pair(var_ref, variable));
1060-
return var_ref;
1061-
}
1062-
10631020
bool StartDebuggingRequestHandler::DoExecute(
10641021
lldb::SBDebugger debugger, char **command,
10651022
lldb::SBCommandReturnObject &result) {
@@ -1296,60 +1253,6 @@ DAP::GetInstructionBPFromStopReason(lldb::SBThread &thread) {
12961253
return inst_bp;
12971254
}
12981255

1299-
lldb::SBValueList *Variables::GetTopLevelScope(int64_t variablesReference) {
1300-
switch (variablesReference) {
1301-
case VARREF_LOCALS:
1302-
return &locals;
1303-
case VARREF_GLOBALS:
1304-
return &globals;
1305-
case VARREF_REGS:
1306-
return &registers;
1307-
default:
1308-
return nullptr;
1309-
}
1310-
}
1311-
1312-
lldb::SBValue Variables::FindVariable(uint64_t variablesReference,
1313-
llvm::StringRef name) {
1314-
lldb::SBValue variable;
1315-
if (lldb::SBValueList *top_scope = GetTopLevelScope(variablesReference)) {
1316-
bool is_duplicated_variable_name = name.contains(" @");
1317-
// variablesReference is one of our scopes, not an actual variable it is
1318-
// asking for a variable in locals or globals or registers
1319-
int64_t end_idx = top_scope->GetSize();
1320-
// Searching backward so that we choose the variable in closest scope
1321-
// among variables of the same name.
1322-
for (int64_t i = end_idx - 1; i >= 0; --i) {
1323-
lldb::SBValue curr_variable = top_scope->GetValueAtIndex(i);
1324-
std::string variable_name = CreateUniqueVariableNameForDisplay(
1325-
curr_variable, is_duplicated_variable_name);
1326-
if (variable_name == name) {
1327-
variable = curr_variable;
1328-
break;
1329-
}
1330-
}
1331-
} else {
1332-
// This is not under the globals or locals scope, so there are no
1333-
// duplicated names.
1334-
1335-
// We have a named item within an actual variable so we need to find it
1336-
// withing the container variable by name.
1337-
lldb::SBValue container = GetVariable(variablesReference);
1338-
variable = container.GetChildMemberWithName(name.data());
1339-
if (!variable.IsValid()) {
1340-
if (name.starts_with("[")) {
1341-
llvm::StringRef index_str(name.drop_front(1));
1342-
uint64_t index = 0;
1343-
if (!index_str.consumeInteger(0, index)) {
1344-
if (index_str == "]")
1345-
variable = container.GetChildAtIndex(index);
1346-
}
1347-
}
1348-
}
1349-
}
1350-
return variable;
1351-
}
1352-
13531256
protocol::Capabilities DAP::GetCapabilities() {
13541257
protocol::Capabilities capabilities;
13551258

lldb/tools/lldb-dap/DAP.h

Lines changed: 40 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "Protocol/ProtocolTypes.h"
2121
#include "SourceBreakpoint.h"
2222
#include "Transport.h"
23+
#include "Variables.h"
2324
#include "lldb/API/SBBroadcaster.h"
2425
#include "lldb/API/SBCommandInterpreter.h"
2526
#include "lldb/API/SBDebugger.h"
@@ -30,8 +31,6 @@
3031
#include "lldb/API/SBMutex.h"
3132
#include "lldb/API/SBTarget.h"
3233
#include "lldb/API/SBThread.h"
33-
#include "lldb/API/SBValue.h"
34-
#include "lldb/API/SBValueList.h"
3534
#include "lldb/lldb-types.h"
3635
#include "llvm/ADT/DenseMap.h"
3736
#include "llvm/ADT/DenseSet.h"
@@ -52,10 +51,6 @@
5251
#include <thread>
5352
#include <vector>
5453

55-
#define VARREF_LOCALS (int64_t)1
56-
#define VARREF_GLOBALS (int64_t)2
57-
#define VARREF_REGS (int64_t)3
58-
#define VARREF_FIRST_VAR_IDX (int64_t)4
5954
#define NO_TYPENAME "<no-type>"
6055

6156
namespace lldb_dap {
@@ -88,50 +83,6 @@ enum class PacketStatus {
8883

8984
enum class ReplMode { Variable = 0, Command, Auto };
9085

91-
struct Variables {
92-
/// Variable_reference start index of permanent expandable variable.
93-
static constexpr int64_t PermanentVariableStartIndex = (1ll << 32);
94-
95-
lldb::SBValueList locals;
96-
lldb::SBValueList globals;
97-
lldb::SBValueList registers;
98-
99-
int64_t next_temporary_var_ref{VARREF_FIRST_VAR_IDX};
100-
int64_t next_permanent_var_ref{PermanentVariableStartIndex};
101-
102-
/// Variables that are alive in this stop state.
103-
/// Will be cleared when debuggee resumes.
104-
llvm::DenseMap<int64_t, lldb::SBValue> referenced_variables;
105-
/// Variables that persist across entire debug session.
106-
/// These are the variables evaluated from debug console REPL.
107-
llvm::DenseMap<int64_t, lldb::SBValue> referenced_permanent_variables;
108-
109-
/// Check if \p var_ref points to a variable that should persist for the
110-
/// entire duration of the debug session, e.g. repl expandable variables
111-
static bool IsPermanentVariableReference(int64_t var_ref);
112-
113-
/// \return a new variableReference.
114-
/// Specify is_permanent as true for variable that should persist entire
115-
/// debug session.
116-
int64_t GetNewVariableReference(bool is_permanent);
117-
118-
/// \return the expandable variable corresponding with variableReference
119-
/// value of \p value.
120-
/// If \p var_ref is invalid an empty SBValue is returned.
121-
lldb::SBValue GetVariable(int64_t var_ref) const;
122-
123-
/// Insert a new \p variable.
124-
/// \return variableReference assigned to this expandable variable.
125-
int64_t InsertVariable(lldb::SBValue variable, bool is_permanent);
126-
127-
lldb::SBValueList *GetTopLevelScope(int64_t variablesReference);
128-
129-
lldb::SBValue FindVariable(uint64_t variablesReference, llvm::StringRef name);
130-
131-
/// Clear all scope variables and non-permanent expandable variables.
132-
void Clear();
133-
};
134-
13586
struct StartDebuggingRequestHandler : public lldb::SBCommandPluginInterface {
13687
DAP &dap;
13788
explicit StartDebuggingRequestHandler(DAP &d) : dap(d) {};
@@ -162,50 +113,70 @@ struct DAP {
162113
lldb::SBFile in;
163114
OutputRedirector out;
164115
OutputRedirector err;
116+
165117
/// Configuration specified by the launch or attach commands.
166118
protocol::Configuration configuration;
119+
120+
/// The debugger instance for this DAP session.
167121
lldb::SBDebugger debugger;
122+
123+
/// The target instance for this DAP session.
168124
lldb::SBTarget target;
125+
169126
Variables variables;
170127
lldb::SBBroadcaster broadcaster;
171128
llvm::StringMap<SourceBreakpointMap> source_breakpoints;
172129
FunctionBreakpointMap function_breakpoints;
173130
InstructionBreakpointMap instruction_breakpoints;
174131
std::optional<std::vector<ExceptionBreakpoint>> exception_breakpoints;
175132
llvm::once_flag init_exception_breakpoints_flag;
176-
// Map step in target id to list of function targets that user can choose.
133+
134+
/// Map step in target id to list of function targets that user can choose.
177135
llvm::DenseMap<lldb::addr_t, std::string> step_in_targets;
178-
// A copy of the last LaunchRequest so we can reuse its arguments if we get a
179-
// RestartRequest. Restarting an AttachRequest is not supported.
136+
137+
/// A copy of the last LaunchRequest so we can reuse its arguments if we get a
138+
/// RestartRequest. Restarting an AttachRequest is not supported.
180139
std::optional<protocol::LaunchRequestArguments> last_launch_request;
181-
lldb::tid_t focus_tid;
140+
141+
/// The focused thread for this DAP session.
142+
lldb::tid_t focus_tid = LLDB_INVALID_THREAD_ID;
143+
182144
bool disconnecting = false;
183145
llvm::once_flag terminated_event_flag;
184-
bool stop_at_entry;
185-
bool is_attach;
186-
// The process event thread normally responds to process exited events by
187-
// shutting down the entire adapter. When we're restarting, we keep the id of
188-
// the old process here so we can detect this case and keep running.
189-
lldb::pid_t restarting_process_id;
146+
bool stop_at_entry = false;
147+
bool is_attach = false;
148+
149+
/// The process event thread normally responds to process exited events by
150+
/// shutting down the entire adapter. When we're restarting, we keep the id of
151+
/// the old process here so we can detect this case and keep running.
152+
lldb::pid_t restarting_process_id = LLDB_INVALID_PROCESS_ID;
153+
154+
/// Whether we have received the ConfigurationDone request, indicating that
155+
/// the client has finished initialization of the debug adapter.
190156
bool configuration_done;
191-
bool waiting_for_run_in_terminal;
157+
158+
bool waiting_for_run_in_terminal = false;
192159
ProgressEventReporter progress_event_reporter;
193-
// Keep track of the last stop thread index IDs as threads won't go away
194-
// unless we send a "thread" event to indicate the thread exited.
160+
161+
/// Keep track of the last stop thread index IDs as threads won't go away
162+
/// unless we send a "thread" event to indicate the thread exited.
195163
llvm::DenseSet<lldb::tid_t> thread_ids;
196-
uint32_t reverse_request_seq;
164+
165+
uint32_t reverse_request_seq = 0;
197166
std::mutex call_mutex;
198167
llvm::SmallDenseMap<int64_t, std::unique_ptr<ResponseHandler>>
199168
inflight_reverse_requests;
200169
ReplMode repl_mode;
201170
lldb::SBFormat frame_format;
202171
lldb::SBFormat thread_format;
203-
// This is used to allow request_evaluate to handle empty expressions
204-
// (ie the user pressed 'return' and expects the previous expression to
205-
// repeat). If the previous expression was a command, this string will be
206-
// empty; if the previous expression was a variable expression, this string
207-
// will contain that expression.
172+
173+
/// This is used to allow request_evaluate to handle empty expressions
174+
/// (ie the user pressed 'return' and expects the previous expression to
175+
/// repeat). If the previous expression was a command, this string will be
176+
/// empty; if the previous expression was a variable expression, this string
177+
/// will contain that expression.
208178
std::string last_nonempty_var_expression;
179+
209180
/// The set of features supported by the connected client.
210181
llvm::DenseSet<ClientFeature> clientFeatures;
211182

@@ -257,8 +228,6 @@ struct DAP {
257228
/// Configures the debug adapter for launching/attaching.
258229
void SetConfiguration(const protocol::Configuration &confing, bool is_attach);
259230

260-
void SetConfigurationDone();
261-
262231
/// Configure source maps based on the current `DAPConfiguration`.
263232
void ConfigureSourceMaps();
264233

0 commit comments

Comments
 (0)