Skip to content
Navigation Menu
{{ message }}
-
Notifications
You must be signed in to change notification settings - Fork 119
Expand file tree
/
Copy pathDebugSession.cs
More file actions
502 lines (402 loc) · 11.9 KB
/
Copy pathDebugSession.cs
File metadata and controls
502 lines (402 loc) · 11.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using VSCode.DebugAdapter;
namespace VSCodeDebug
{
// ---- Types -------------------------------------------------------------------------
public class Message {
public int id { get; }
public string format { get; }
public dynamic variables { get; }
public dynamic showUser { get; }
public dynamic sendTelemetry { get; }
public Message(int id, string format, dynamic variables = null, bool user = true, bool telemetry = false) {
this.id = id;
this.format = format;
this.variables = variables;
this.showUser = user;
this.sendTelemetry = telemetry;
}
}
public class StackFrame
{
public int id { get; }
public Source source { get; }
public int line { get; }
public int column { get; }
public string name { get; }
public StackFrame(int id, string name, Source source, int line, int column) {
this.id = id;
this.name = name;
this.source = source;
this.line = line;
this.column = column;
}
}
public class Scope
{
public string name { get; }
public int variablesReference { get; }
public bool expensive { get; }
public Scope(string name, int variablesReference, bool expensive = false) {
this.name = name;
this.variablesReference = variablesReference;
this.expensive = expensive;
}
}
public class Variable
{
public string name { get; }
public string value { get; }
public string type { get; }
public int variablesReference { get; }
public Variable(string name, string value, string type, int variablesReference = 0) {
this.name = name;
this.value = value;
this.type = type;
this.variablesReference = variablesReference;
}
}
public class Thread
{
public int id { get; }
public string name { get; }
public Thread(int id, string name) {
this.id = id;
if (name == null || name.Length == 0) {
this.name = string.Format("Thread #{0}", id);
}
else {
this.name = name;
}
}
}
public class Source
{
public string name { get; }
public string path { get; }
public int sourceReference { get; }
public string origin { get; set; }
public string presentationHint { get; set; }
public Source(string name, string path, int sourceReference = 0) {
this.name = name;
this.path = path;
this.sourceReference = sourceReference;
}
public Source(string path, int sourceReference = 0) {
this.name = Path.GetFileName(path);
this.path = path;
this.sourceReference = sourceReference;
}
}
public class Breakpoint
{
public bool verified { get; }
public int line { get; }
public Breakpoint(bool verified)
{
this.verified = verified;
line = 0;
}
public Breakpoint(bool verified, int line) {
this.verified = verified;
this.line = line;
}
}
// ---- Events -------------------------------------------------------------------------
public class InitializedEvent : Event
{
public InitializedEvent()
: base("initialized") { }
}
public class StoppedEvent : Event
{
public StoppedEvent(int tid, string reasn, string txt = null)
: base("stopped", new {
threadId = tid,
reason = reasn,
text = txt
}) { }
}
public class ExitedEvent : Event
{
public ExitedEvent(int exCode)
: base("exited", new { exitCode = exCode } ) { }
}
public class TerminatedEvent : Event
{
public TerminatedEvent()
: base("terminated") { }
}
public class ThreadEvent : Event
{
public ThreadEvent(string reasn, int tid)
: base("thread", new {
reason = reasn,
threadId = tid
}) { }
}
public class OutputEvent : Event
{
public OutputEvent(string cat, string outpt)
: base("output", new {
category = cat,
output = outpt
}) { }
}
// ---- Response -------------------------------------------------------------------------
public class Capabilities : ResponseBody {
public bool supportsConfigurationDoneRequest;
public bool supportsFunctionBreakpoints;
public bool supportsConditionalBreakpoints;
public bool supportsEvaluateForHovers;
public bool supportsExceptionFilterOptions;
public dynamic[] exceptionBreakpointFilters;
public bool supportTerminateDebuggee;
}
public class ErrorResponseBody : ResponseBody {
public Message error { get; }
public ErrorResponseBody(Message error) {
this.error = error;
}
}
public class StackTraceResponseBody : ResponseBody
{
public StackFrame[] stackFrames { get; }
public StackTraceResponseBody(IEnumerable<StackFrame> frames = null) {
if (frames == null)
stackFrames = new StackFrame[0];
else
stackFrames = frames.ToArray<StackFrame>();
}
}
public class ScopesResponseBody : ResponseBody
{
public Scope[] scopes { get; }
public ScopesResponseBody(IList<Scope> scps = null) {
if (scps == null)
scopes = new Scope[0];
else
scopes = scps.ToArray<Scope>();
}
}
public class VariablesResponseBody : ResponseBody
{
public Variable[] variables { get; }
public VariablesResponseBody(IList<Variable> vars = null) {
if (vars == null)
variables = new Variable[0];
else
variables = vars.ToArray<Variable>();
}
}
public class ThreadsResponseBody : ResponseBody
{
public Thread[] threads { get; }
public ThreadsResponseBody(List<Thread> vars = null) {
if (vars == null)
threads = new Thread[0];
else
threads = vars.ToArray<Thread>();
}
}
public class EvaluateResponseBody : ResponseBody
{
public string result { get; }
public string type { get; set; }
public int variablesReference { get; }
public EvaluateResponseBody(string value, int reff = 0) {
result = value;
variablesReference = reff;
}
}
public class SetBreakpointsResponseBody : ResponseBody
{
public Breakpoint[] breakpoints { get; }
public SetBreakpointsResponseBody(List<Breakpoint> bpts = null) {
if (bpts == null)
breakpoints = Array.Empty<Breakpoint>();
else
breakpoints = bpts.ToArray<Breakpoint>();
}
}
public class SetExceptionBreakpointsResponseBody : ResponseBody
{
public Breakpoint[] breakpoints { get; }
public SetExceptionBreakpointsResponseBody(List<Breakpoint> bpts = null)
{
if (bpts == null)
breakpoints = Array.Empty<Breakpoint>();
else
breakpoints = bpts.ToArray<Breakpoint>();
}
}
// ---- The Session --------------------------------------------------------
public abstract class DebugSession : ProtocolServer
{
private bool _clientLinesStartAt1 = true;
private bool _clientPathsAreUri = true;
public PathHandlingStrategy PathStrategy { get; }
public DebugSession(bool debuggerLinesStartAt1, bool debuggerPathsAreURI = false)
{
PathStrategy = new PathHandlingStrategy
{
DebuggerLinesStartAt1 = debuggerLinesStartAt1,
DebuggerPathsAreUri = debuggerPathsAreURI
};
}
public void SendResponse(Response response, dynamic body = null)
{
if (body != null) {
response.SetBody(body);
}
SendMessage(response);
}
public void SendErrorResponse(Response response, int id, string format, dynamic arguments = null, bool user = true, bool telemetry = false)
{
var msg = new Message(id, format, arguments, user, telemetry);
var message = Utilities.ExpandVariables(msg.format, msg.variables);
response.SetErrorBody(message, new ErrorResponseBody(msg));
SendMessage(response);
}
protected override void DispatchRequest(string command, dynamic args, Response response)
{
if (args == null) {
args = new { };
}
try {
switch (command) {
case "initialize":
if (args.linesStartAt1 != null) {
_clientLinesStartAt1 = (bool)args.linesStartAt1;
}
var pathFormat = (string)args.pathFormat;
if (pathFormat != null) {
switch (pathFormat) {
case "uri":
_clientPathsAreUri = true;
break;
case "path":
_clientPathsAreUri = false;
break;
default:
SendErrorResponse(response, 1015, "initialize: bad value '{_format}' for pathFormat", new { _format = pathFormat });
return;
}
}
SetPathStrategy();
Initialize(response, args);
break;
case "launch":
Launch(response, args);
break;
case "attach":
Attach(response, args);
break;
case "disconnect":
Disconnect(response, args);
break;
case "next":
Next(response, args);
break;
case "continue":
Continue(response, args);
break;
case "stepIn":
StepIn(response, args);
break;
case "stepOut":
StepOut(response, args);
break;
case "pause":
Pause(response, args);
break;
case "stackTrace":
StackTrace(response, args);
break;
case "scopes":
Scopes(response, args);
break;
case "variables":
Variables(response, args);
break;
case "source":
Source(response, args);
break;
case "threads":
Threads(response, args);
break;
case "setBreakpoints":
SetBreakpoints(response, args);
break;
case "setFunctionBreakpoints":
SetFunctionBreakpoints(response, args);
break;
case "setExceptionBreakpoints":
SetExceptionBreakpoints(response, args);
break;
case "evaluate":
Evaluate(response, args);
break;
case "configurationDone":
ConfigurationDone(response, args);
break;
default:
SendErrorResponse(response, 1014, "unrecognized request: {_request}", new { _request = command });
break;
}
}
catch (Exception e) {
OnRequestError(e);
SendErrorResponse(response, 1104, "error while processing request '{_request}' (exception: {_exception})", new { _request = command, _exception = e.Message });
}
if (command == "disconnect") {
Stop();
}
}
private void SetPathStrategy()
{
PathStrategy.ClientLinesStartAt1 = _clientLinesStartAt1;
PathStrategy.ClientPathsAreUri = _clientPathsAreUri;
}
protected string ConvertClientPathToDebugger(string path)
{
return PathStrategy.ConvertClientPathToDebugger(path);
}
public abstract void ConfigurationDone(Response response, dynamic args);
public abstract void Initialize(Response response, dynamic args);
public abstract void Launch(Response response, dynamic arguments);
public abstract void Attach(Response response, dynamic arguments);
public abstract void Disconnect(Response response, dynamic arguments);
public virtual void SetFunctionBreakpoints(Response response, dynamic arguments)
{
}
public virtual void SetExceptionBreakpoints(Response response, dynamic arguments)
{
}
protected virtual void OnRequestError(Exception e)
{
}
public abstract void SetBreakpoints(Response response, dynamic arguments);
public abstract void Continue(Response response, dynamic arguments);
public abstract void Next(Response response, dynamic arguments);
public abstract void StepIn(Response response, dynamic arguments);
public abstract void StepOut(Response response, dynamic arguments);
public abstract void Pause(Response response, dynamic arguments);
public abstract void StackTrace(Response response, dynamic arguments);
public abstract void Scopes(Response response, dynamic arguments);
public abstract void Variables(Response response, dynamic arguments);
public virtual void Source(Response response, dynamic arguments)
{
SendErrorResponse(response, 1020, "Source not supported");
}
public abstract void Threads(Response response, dynamic arguments);
public abstract void Evaluate(Response response, dynamic arguments);
}
}
You can’t perform that action at this time.
