|
20 | 20 | #include "Protocol/ProtocolTypes.h" |
21 | 21 | #include "SourceBreakpoint.h" |
22 | 22 | #include "Transport.h" |
| 23 | +#include "Variables.h" |
23 | 24 | #include "lldb/API/SBBroadcaster.h" |
24 | 25 | #include "lldb/API/SBCommandInterpreter.h" |
25 | 26 | #include "lldb/API/SBDebugger.h" |
|
30 | 31 | #include "lldb/API/SBMutex.h" |
31 | 32 | #include "lldb/API/SBTarget.h" |
32 | 33 | #include "lldb/API/SBThread.h" |
33 | | -#include "lldb/API/SBValue.h" |
34 | | -#include "lldb/API/SBValueList.h" |
35 | 34 | #include "lldb/lldb-types.h" |
36 | 35 | #include "llvm/ADT/DenseMap.h" |
37 | 36 | #include "llvm/ADT/DenseSet.h" |
|
52 | 51 | #include <thread> |
53 | 52 | #include <vector> |
54 | 53 |
|
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 |
59 | 54 | #define NO_TYPENAME "<no-type>" |
60 | 55 |
|
61 | 56 | namespace lldb_dap { |
@@ -88,50 +83,6 @@ enum class PacketStatus { |
88 | 83 |
|
89 | 84 | enum class ReplMode { Variable = 0, Command, Auto }; |
90 | 85 |
|
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 | | - |
135 | 86 | struct StartDebuggingRequestHandler : public lldb::SBCommandPluginInterface { |
136 | 87 | DAP &dap; |
137 | 88 | explicit StartDebuggingRequestHandler(DAP &d) : dap(d) {}; |
@@ -162,50 +113,70 @@ struct DAP { |
162 | 113 | lldb::SBFile in; |
163 | 114 | OutputRedirector out; |
164 | 115 | OutputRedirector err; |
| 116 | + |
165 | 117 | /// Configuration specified by the launch or attach commands. |
166 | 118 | protocol::Configuration configuration; |
| 119 | + |
| 120 | + /// The debugger instance for this DAP session. |
167 | 121 | lldb::SBDebugger debugger; |
| 122 | + |
| 123 | + /// The target instance for this DAP session. |
168 | 124 | lldb::SBTarget target; |
| 125 | + |
169 | 126 | Variables variables; |
170 | 127 | lldb::SBBroadcaster broadcaster; |
171 | 128 | llvm::StringMap<SourceBreakpointMap> source_breakpoints; |
172 | 129 | FunctionBreakpointMap function_breakpoints; |
173 | 130 | InstructionBreakpointMap instruction_breakpoints; |
174 | 131 | std::optional<std::vector<ExceptionBreakpoint>> exception_breakpoints; |
175 | 132 | 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. |
177 | 135 | 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. |
180 | 139 | 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 | + |
182 | 144 | bool disconnecting = false; |
183 | 145 | 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. |
190 | 156 | bool configuration_done; |
191 | | - bool waiting_for_run_in_terminal; |
| 157 | + |
| 158 | + bool waiting_for_run_in_terminal = false; |
192 | 159 | 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. |
195 | 163 | llvm::DenseSet<lldb::tid_t> thread_ids; |
196 | | - uint32_t reverse_request_seq; |
| 164 | + |
| 165 | + uint32_t reverse_request_seq = 0; |
197 | 166 | std::mutex call_mutex; |
198 | 167 | llvm::SmallDenseMap<int64_t, std::unique_ptr<ResponseHandler>> |
199 | 168 | inflight_reverse_requests; |
200 | 169 | ReplMode repl_mode; |
201 | 170 | lldb::SBFormat frame_format; |
202 | 171 | 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. |
208 | 178 | std::string last_nonempty_var_expression; |
| 179 | + |
209 | 180 | /// The set of features supported by the connected client. |
210 | 181 | llvm::DenseSet<ClientFeature> clientFeatures; |
211 | 182 |
|
@@ -257,8 +228,6 @@ struct DAP { |
257 | 228 | /// Configures the debug adapter for launching/attaching. |
258 | 229 | void SetConfiguration(const protocol::Configuration &confing, bool is_attach); |
259 | 230 |
|
260 | | - void SetConfigurationDone(); |
261 | | - |
262 | 231 | /// Configure source maps based on the current `DAPConfiguration`. |
263 | 232 | void ConfigureSourceMaps(); |
264 | 233 |
|
|
0 commit comments