-
Notifications
You must be signed in to change notification settings - Fork 80
/
Copy pathdebugSession.ts
971 lines (772 loc) · 32.8 KB
/
debugSession.ts
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
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import {DebugProtocol} from 'vscode-debugprotocol';
import {ProtocolServer} from './protocol';
import {Response, Event} from './messages';
import * as Net from 'net';
import {URL} from 'url';
export class Source implements DebugProtocol.Source {
name: string;
path: string;
sourceReference: number;
public constructor(name: string, path?: string, id: number = 0, origin?: string, data?: any) {
this.name = name;
this.path = path;
this.sourceReference = id;
if (origin) {
(<any>this).origin = origin;
}
if (data) {
(<any>this).adapterData = data;
}
}
}
export class Scope implements DebugProtocol.Scope {
name: string;
variablesReference: number;
expensive: boolean;
public constructor(name: string, reference: number, expensive: boolean = false) {
this.name = name;
this.variablesReference = reference;
this.expensive = expensive;
}
}
export class StackFrame implements DebugProtocol.StackFrame {
id: number;
source: Source;
line: number;
column: number;
name: string;
public constructor(i: number, nm: string, src?: Source, ln: number = 0, col: number = 0) {
this.id = i;
this.source = src;
this.line = ln;
this.column = col;
this.name = nm;
}
}
export class Thread implements DebugProtocol.Thread {
id: number;
name: string;
public constructor(id: number, name: string) {
this.id = id;
if (name) {
this.name = name;
} else {
this.name = 'Thread #' + id;
}
}
}
export class Variable implements DebugProtocol.Variable {
name: string;
value: string;
variablesReference: number;
public constructor(name: string, value: string, ref: number = 0, indexedVariables?: number, namedVariables?: number) {
this.name = name;
this.value = value;
this.variablesReference = ref;
if (typeof namedVariables === 'number') {
(<DebugProtocol.Variable>this).namedVariables = namedVariables;
}
if (typeof indexedVariables === 'number') {
(<DebugProtocol.Variable>this).indexedVariables = indexedVariables;
}
}
}
export class Breakpoint implements DebugProtocol.Breakpoint {
verified: boolean;
public constructor(verified: boolean, line?: number, column?: number, source?: Source) {
this.verified = verified;
const e: DebugProtocol.Breakpoint = this;
if (typeof line === 'number') {
e.line = line;
}
if (typeof column === 'number') {
e.column = column;
}
if (source) {
e.source = source;
}
}
}
export class Module implements DebugProtocol.Module {
id: number | string;
name: string;
public constructor(id: number | string, name: string) {
this.id = id;
this.name = name;
}
}
export class CompletionItem implements DebugProtocol.CompletionItem {
label: string;
start: number;
length: number;
public constructor(label: string, start: number, length: number = 0) {
this.label = label;
this.start = start;
this.length = length;
}
}
export class StoppedEvent extends Event implements DebugProtocol.StoppedEvent {
body: {
reason: string;
};
public constructor(reason: string, threadId?: number, exceptionText?: string) {
super('stopped');
this.body = {
reason: reason
};
if (typeof threadId === 'number') {
(this as DebugProtocol.StoppedEvent).body.threadId = threadId;
}
if (typeof exceptionText === 'string') {
(this as DebugProtocol.StoppedEvent).body.text = exceptionText;
}
}
}
export class ContinuedEvent extends Event implements DebugProtocol.ContinuedEvent {
body: {
threadId: number;
};
public constructor(threadId: number, allThreadsContinued?: boolean) {
super('continued');
this.body = {
threadId: threadId
};
if (typeof allThreadsContinued === 'boolean') {
(<DebugProtocol.ContinuedEvent>this).body.allThreadsContinued = allThreadsContinued;
}
}
}
export class InitializedEvent extends Event implements DebugProtocol.InitializedEvent {
public constructor() {
super('initialized');
}
}
export class TerminatedEvent extends Event implements DebugProtocol.TerminatedEvent {
public constructor(restart?: any) {
super('terminated');
if (typeof restart === 'boolean' || restart) {
const e: DebugProtocol.TerminatedEvent = this;
e.body = {
restart: restart
};
}
}
}
export class OutputEvent extends Event implements DebugProtocol.OutputEvent {
body: {
category: string,
output: string,
data?: any
};
public constructor(output: string, category: string = 'console', data?: any) {
super('output');
this.body = {
category: category,
output: output
};
if (data !== undefined) {
this.body.data = data;
}
}
}
export class ThreadEvent extends Event implements DebugProtocol.ThreadEvent {
body: {
reason: string,
threadId: number
};
public constructor(reason: string, threadId: number) {
super('thread');
this.body = {
reason: reason,
threadId: threadId
};
}
}
export class BreakpointEvent extends Event implements DebugProtocol.BreakpointEvent {
body: {
reason: string,
breakpoint: Breakpoint
};
public constructor(reason: string, breakpoint: Breakpoint) {
super('breakpoint');
this.body = {
reason: reason,
breakpoint: breakpoint
};
}
}
export class ModuleEvent extends Event implements DebugProtocol.ModuleEvent {
body: {
reason: 'new' | 'changed' | 'removed',
module: Module
};
public constructor(reason: 'new' | 'changed' | 'removed', module: Module) {
super('module');
this.body = {
reason: reason,
module: module
};
}
}
export class LoadedSourceEvent extends Event implements DebugProtocol.LoadedSourceEvent {
body: {
reason: 'new' | 'changed' | 'removed',
source: Source
};
public constructor(reason: 'new' | 'changed' | 'removed', source: Source) {
super('loadedSource');
this.body = {
reason: reason,
source: source
};
}
}
export class CapabilitiesEvent extends Event implements DebugProtocol.CapabilitiesEvent {
body: {
capabilities: DebugProtocol.Capabilities
};
public constructor(capabilities: DebugProtocol.Capabilities) {
super('capabilities');
this.body = {
capabilities: capabilities
};
}
}
export class ProgressStartEvent extends Event implements DebugProtocol.ProgressStartEvent {
body: {
progressId: string,
title: string
};
public constructor(progressId: string, title: string, message?: string) {
super('progressStart');
this.body = {
progressId: progressId,
title: title
};
if (typeof message === 'string') {
(this as DebugProtocol.ProgressStartEvent).body.message = message;
}
}
}
export class ProgressUpdateEvent extends Event implements DebugProtocol.ProgressUpdateEvent {
body: {
progressId: string
};
public constructor(progressId: string, message?: string) {
super('progressUpdate');
this.body = {
progressId: progressId
};
if (typeof message === 'string') {
(this as DebugProtocol.ProgressUpdateEvent).body.message = message;
}
}
}
export class ProgressEndEvent extends Event implements DebugProtocol.ProgressEndEvent {
body: {
progressId: string
};
public constructor(progressId: string, message?: string) {
super('progressEnd');
this.body = {
progressId: progressId
};
if (typeof message === 'string') {
(this as DebugProtocol.ProgressEndEvent).body.message = message;
}
}
}
export enum ErrorDestination {
User = 1,
Telemetry = 2
};
export class DebugSession extends ProtocolServer {
private _debuggerLinesStartAt1: boolean;
private _debuggerColumnsStartAt1: boolean;
private _debuggerPathsAreURIs: boolean;
private _clientLinesStartAt1: boolean;
private _clientColumnsStartAt1: boolean;
private _clientPathsAreURIs: boolean;
protected _isServer: boolean;
public constructor(obsolete_debuggerLinesAndColumnsStartAt1?: boolean, obsolete_isServer?: boolean) {
super();
const linesAndColumnsStartAt1 = typeof obsolete_debuggerLinesAndColumnsStartAt1 === 'boolean' ? obsolete_debuggerLinesAndColumnsStartAt1 : false;
this._debuggerLinesStartAt1 = linesAndColumnsStartAt1;
this._debuggerColumnsStartAt1 = linesAndColumnsStartAt1;
this._debuggerPathsAreURIs = false;
this._clientLinesStartAt1 = true;
this._clientColumnsStartAt1 = true;
this._clientPathsAreURIs = false;
this._isServer = typeof obsolete_isServer === 'boolean' ? obsolete_isServer : false;
this.on('close', () => {
this.shutdown();
});
this.on('error', (error) => {
this.shutdown();
});
}
public setDebuggerPathFormat(format: string) {
this._debuggerPathsAreURIs = format !== 'path';
}
public setDebuggerLinesStartAt1(enable: boolean) {
this._debuggerLinesStartAt1 = enable;
}
public setDebuggerColumnsStartAt1(enable: boolean) {
this._debuggerColumnsStartAt1 = enable;
}
public setRunAsServer(enable: boolean) {
this._isServer = enable;
}
/**
* A virtual constructor...
*/
public static run(debugSession: typeof DebugSession) {
// parse arguments
let port = 0;
const args = process.argv.slice(2);
args.forEach(function (val, index, array) {
const portMatch = /^--server=(\d{4,5})$/.exec(val);
if (portMatch) {
port = parseInt(portMatch[1], 10);
}
});
if (port > 0) {
// start as a server
console.error(`waiting for debug protocol on port ${port}`);
Net.createServer((socket) => {
console.error('>> accepted connection from client');
socket.on('end', () => {
console.error('>> client connection closed\n');
});
const session = new debugSession(false, true);
session.setRunAsServer(true);
session.start(socket, socket);
}).listen(port);
} else {
// start a session
//console.error('waiting for debug protocol on stdin/stdout');
const session = new debugSession(false);
process.on('SIGTERM', () => {
session.shutdown();
});
session.start(process.stdin, process.stdout);
}
}
public shutdown(): void {
if (this._isServer || this._isRunningInline()) {
// shutdown ignored in server mode
} else {
// wait a bit before shutting down
setTimeout(() => {
process.exit(0);
}, 100);
}
}
protected sendErrorResponse(response: DebugProtocol.Response, codeOrMessage: number | DebugProtocol.Message, format?: string, variables?: any, dest: ErrorDestination = ErrorDestination.User): void {
let msg : DebugProtocol.Message;
if (typeof codeOrMessage === 'number') {
msg = <DebugProtocol.Message> {
id: <number> codeOrMessage,
format: format
};
if (variables) {
msg.variables = variables;
}
if (dest & ErrorDestination.User) {
msg.showUser = true;
}
if (dest & ErrorDestination.Telemetry) {
msg.sendTelemetry = true;
}
} else {
msg = codeOrMessage;
}
response.success = false;
response.message = DebugSession.formatPII(msg.format, true, msg.variables);
if (!response.body) {
response.body = { };
}
response.body.error = msg;
this.sendResponse(response);
}
public runInTerminalRequest(args: DebugProtocol.RunInTerminalRequestArguments, timeout: number, cb: (response: DebugProtocol.RunInTerminalResponse) => void) {
this.sendRequest('runInTerminal', args, timeout, cb);
}
protected dispatchRequest(request: DebugProtocol.Request): void {
const response = new Response(request);
try {
if (request.command === 'initialize') {
var args = <DebugProtocol.InitializeRequestArguments> request.arguments;
if (typeof args.linesStartAt1 === 'boolean') {
this._clientLinesStartAt1 = args.linesStartAt1;
}
if (typeof args.columnsStartAt1 === 'boolean') {
this._clientColumnsStartAt1 = args.columnsStartAt1;
}
if (args.pathFormat !== 'path') {
this.sendErrorResponse(response, 2018, 'debug adapter only supports native paths', null, ErrorDestination.Telemetry);
} else {
const initializeResponse = <DebugProtocol.InitializeResponse> response;
initializeResponse.body = {};
this.initializeRequest(initializeResponse, args);
}
} else if (request.command === 'launch') {
this.launchRequest(<DebugProtocol.LaunchResponse> response, request.arguments, request);
} else if (request.command === 'attach') {
this.attachRequest(<DebugProtocol.AttachResponse> response, request.arguments, request);
} else if (request.command === 'disconnect') {
this.disconnectRequest(<DebugProtocol.DisconnectResponse> response, request.arguments, request);
} else if (request.command === 'terminate') {
this.terminateRequest(<DebugProtocol.TerminateResponse> response, request.arguments, request);
} else if (request.command === 'restart') {
this.restartRequest(<DebugProtocol.RestartResponse> response, request.arguments, request);
} else if (request.command === 'setBreakpoints') {
this.setBreakPointsRequest(<DebugProtocol.SetBreakpointsResponse> response, request.arguments, request);
} else if (request.command === 'setFunctionBreakpoints') {
this.setFunctionBreakPointsRequest(<DebugProtocol.SetFunctionBreakpointsResponse> response, request.arguments, request);
} else if (request.command === 'setExceptionBreakpoints') {
this.setExceptionBreakPointsRequest(<DebugProtocol.SetExceptionBreakpointsResponse> response, request.arguments, request);
} else if (request.command === 'configurationDone') {
this.configurationDoneRequest(<DebugProtocol.ConfigurationDoneResponse> response, request.arguments, request);
} else if (request.command === 'continue') {
this.continueRequest(<DebugProtocol.ContinueResponse> response, request.arguments, request);
} else if (request.command === 'next') {
this.nextRequest(<DebugProtocol.NextResponse> response, request.arguments, request);
} else if (request.command === 'stepIn') {
this.stepInRequest(<DebugProtocol.StepInResponse> response, request.arguments, request);
} else if (request.command === 'stepOut') {
this.stepOutRequest(<DebugProtocol.StepOutResponse> response, request.arguments, request);
} else if (request.command === 'stepBack') {
this.stepBackRequest(<DebugProtocol.StepBackResponse> response, request.arguments, request);
} else if (request.command === 'reverseContinue') {
this.reverseContinueRequest(<DebugProtocol.ReverseContinueResponse> response, request.arguments, request);
} else if (request.command === 'restartFrame') {
this.restartFrameRequest(<DebugProtocol.RestartFrameResponse> response, request.arguments, request);
} else if (request.command === 'goto') {
this.gotoRequest(<DebugProtocol.GotoResponse> response, request.arguments, request);
} else if (request.command === 'pause') {
this.pauseRequest(<DebugProtocol.PauseResponse> response, request.arguments, request);
} else if (request.command === 'stackTrace') {
this.stackTraceRequest(<DebugProtocol.StackTraceResponse> response, request.arguments, request);
} else if (request.command === 'scopes') {
this.scopesRequest(<DebugProtocol.ScopesResponse> response, request.arguments, request);
} else if (request.command === 'variables') {
this.variablesRequest(<DebugProtocol.VariablesResponse> response, request.arguments, request);
} else if (request.command === 'setVariable') {
this.setVariableRequest(<DebugProtocol.SetVariableResponse> response, request.arguments, request);
} else if (request.command === 'setExpression') {
this.setExpressionRequest(<DebugProtocol.SetExpressionResponse> response, request.arguments, request);
} else if (request.command === 'source') {
this.sourceRequest(<DebugProtocol.SourceResponse> response, request.arguments, request);
} else if (request.command === 'threads') {
this.threadsRequest(<DebugProtocol.ThreadsResponse> response, request);
} else if (request.command === 'terminateThreads') {
this.terminateThreadsRequest(<DebugProtocol.TerminateThreadsResponse> response, request.arguments, request);
} else if (request.command === 'evaluate') {
this.evaluateRequest(<DebugProtocol.EvaluateResponse> response, request.arguments, request);
} else if (request.command === 'stepInTargets') {
this.stepInTargetsRequest(<DebugProtocol.StepInTargetsResponse> response, request.arguments, request);
} else if (request.command === 'gotoTargets') {
this.gotoTargetsRequest(<DebugProtocol.GotoTargetsResponse> response, request.arguments, request);
} else if (request.command === 'completions') {
this.completionsRequest(<DebugProtocol.CompletionsResponse> response, request.arguments, request);
} else if (request.command === 'exceptionInfo') {
this.exceptionInfoRequest(<DebugProtocol.ExceptionInfoResponse> response, request.arguments, request);
} else if (request.command === 'loadedSources') {
this.loadedSourcesRequest(<DebugProtocol.LoadedSourcesResponse> response, request.arguments, request);
} else if (request.command === 'dataBreakpointInfo') {
this.dataBreakpointInfoRequest(<DebugProtocol.DataBreakpointInfoResponse> response, request.arguments, request);
} else if (request.command === 'setDataBreakpoints') {
this.setDataBreakpointsRequest(<DebugProtocol.SetDataBreakpointsResponse> response, request.arguments, request);
} else if (request.command === 'readMemory') {
this.readMemoryRequest(<DebugProtocol.ReadMemoryResponse> response, request.arguments, request);
} else if (request.command === 'disassemble') {
this.disassembleRequest(<DebugProtocol.DisassembleResponse> response, request.arguments, request);
} else if (request.command === 'cancel') {
this.cancelRequest(<DebugProtocol.CancelResponse> response, request.arguments, request);
} else if (request.command === 'breakpointLocations') {
this.breakpointLocationsRequest(<DebugProtocol.BreakpointLocationsResponse> response, request.arguments, request);
} else if (request.command === 'setInstructionBreakpoints') {
this.setInstructionBreakpointsRequest(<DebugProtocol.SetInstructionBreakpointsResponse> response, request.arguments, request);
} else {
this.customRequest(request.command, <DebugProtocol.Response> response, request.arguments, request);
}
} catch (e) {
this.sendErrorResponse(response, 1104, '{_stack}', { _exception: e.message, _stack: e.stack }, ErrorDestination.Telemetry);
}
}
protected initializeRequest(response: DebugProtocol.InitializeResponse, args: DebugProtocol.InitializeRequestArguments): void {
// This default debug adapter does not support conditional breakpoints.
response.body.supportsConditionalBreakpoints = false;
// This default debug adapter does not support hit conditional breakpoints.
response.body.supportsHitConditionalBreakpoints = false;
// This default debug adapter does not support function breakpoints.
response.body.supportsFunctionBreakpoints = false;
// This default debug adapter implements the 'configurationDone' request.
response.body.supportsConfigurationDoneRequest = true;
// This default debug adapter does not support hovers based on the 'evaluate' request.
response.body.supportsEvaluateForHovers = false;
// This default debug adapter does not support the 'stepBack' request.
response.body.supportsStepBack = false;
// This default debug adapter does not support the 'setVariable' request.
response.body.supportsSetVariable = false;
// This default debug adapter does not support the 'restartFrame' request.
response.body.supportsRestartFrame = false;
// This default debug adapter does not support the 'stepInTargets' request.
response.body.supportsStepInTargetsRequest = false;
// This default debug adapter does not support the 'gotoTargets' request.
response.body.supportsGotoTargetsRequest = false;
// This default debug adapter does not support the 'completions' request.
response.body.supportsCompletionsRequest = false;
// This default debug adapter does not support the 'restart' request.
response.body.supportsRestartRequest = false;
// This default debug adapter does not support the 'exceptionOptions' attribute on the 'setExceptionBreakpoints' request.
response.body.supportsExceptionOptions = false;
// This default debug adapter does not support the 'format' attribute on the 'variables', 'evaluate', and 'stackTrace' request.
response.body.supportsValueFormattingOptions = false;
// This debug adapter does not support the 'exceptionInfo' request.
response.body.supportsExceptionInfoRequest = false;
// This debug adapter does not support the 'TerminateDebuggee' attribute on the 'disconnect' request.
response.body.supportTerminateDebuggee = false;
// This debug adapter does not support delayed loading of stack frames.
response.body.supportsDelayedStackTraceLoading = false;
// This debug adapter does not support the 'loadedSources' request.
response.body.supportsLoadedSourcesRequest = false;
// This debug adapter does not support the 'logMessage' attribute of the SourceBreakpoint.
response.body.supportsLogPoints = false;
// This debug adapter does not support the 'terminateThreads' request.
response.body.supportsTerminateThreadsRequest = false;
// This debug adapter does not support the 'setExpression' request.
response.body.supportsSetExpression = false;
// This debug adapter does not support the 'terminate' request.
response.body.supportsTerminateRequest = false;
// This debug adapter does not support data breakpoints.
response.body.supportsDataBreakpoints = false;
/** This debug adapter does not support the 'readMemory' request. */
response.body.supportsReadMemoryRequest = false;
/** The debug adapter does not support the 'disassemble' request. */
response.body.supportsDisassembleRequest = false;
/** The debug adapter does not support the 'cancel' request. */
response.body.supportsCancelRequest = false;
/** The debug adapter does not support the 'breakpointLocations' request. */
response.body.supportsBreakpointLocationsRequest = false;
/** The debug adapter does not support the 'clipboard' context value in the 'evaluate' request. */
response.body.supportsClipboardContext = false;
/** The debug adapter does not support stepping granularities for the stepping requests. */
response.body.supportsSteppingGranularity = false;
/** The debug adapter does not support the 'setInstructionBreakpoints' request. */
response.body.supportsInstructionBreakpoints = false;
this.sendResponse(response);
}
protected disconnectRequest(response: DebugProtocol.DisconnectResponse, args: DebugProtocol.DisconnectArguments, request?: DebugProtocol.Request): void {
this.sendResponse(response);
this.shutdown();
}
protected launchRequest(response: DebugProtocol.LaunchResponse, args: DebugProtocol.LaunchRequestArguments, request?: DebugProtocol.Request): void {
this.sendResponse(response);
}
protected attachRequest(response: DebugProtocol.AttachResponse, args: DebugProtocol.AttachRequestArguments, request?: DebugProtocol.Request): void {
this.sendResponse(response);
}
protected terminateRequest(response: DebugProtocol.TerminateResponse, args: DebugProtocol.TerminateArguments, request?: DebugProtocol.Request): void {
this.sendResponse(response);
}
protected restartRequest(response: DebugProtocol.RestartResponse, args: DebugProtocol.RestartArguments, request?: DebugProtocol.Request): void {
this.sendResponse(response);
}
protected setBreakPointsRequest(response: DebugProtocol.SetBreakpointsResponse, args: DebugProtocol.SetBreakpointsArguments, request?: DebugProtocol.Request): void {
this.sendResponse(response);
}
protected setFunctionBreakPointsRequest(response: DebugProtocol.SetFunctionBreakpointsResponse, args: DebugProtocol.SetFunctionBreakpointsArguments, request?: DebugProtocol.Request): void {
this.sendResponse(response);
}
protected setExceptionBreakPointsRequest(response: DebugProtocol.SetExceptionBreakpointsResponse, args: DebugProtocol.SetExceptionBreakpointsArguments, request?: DebugProtocol.Request): void {
this.sendResponse(response);
}
protected configurationDoneRequest(response: DebugProtocol.ConfigurationDoneResponse, args: DebugProtocol.ConfigurationDoneArguments, request?: DebugProtocol.Request): void {
this.sendResponse(response);
}
protected continueRequest(response: DebugProtocol.ContinueResponse, args: DebugProtocol.ContinueArguments, request?: DebugProtocol.Request) : void {
this.sendResponse(response);
}
protected nextRequest(response: DebugProtocol.NextResponse, args: DebugProtocol.NextArguments, request?: DebugProtocol.Request) : void {
this.sendResponse(response);
}
protected stepInRequest(response: DebugProtocol.StepInResponse, args: DebugProtocol.StepInArguments, request?: DebugProtocol.Request) : void {
this.sendResponse(response);
}
protected stepOutRequest(response: DebugProtocol.StepOutResponse, args: DebugProtocol.StepOutArguments, request?: DebugProtocol.Request) : void {
this.sendResponse(response);
}
protected stepBackRequest(response: DebugProtocol.StepBackResponse, args: DebugProtocol.StepBackArguments, request?: DebugProtocol.Request) : void {
this.sendResponse(response);
}
protected reverseContinueRequest(response: DebugProtocol.ReverseContinueResponse, args: DebugProtocol.ReverseContinueArguments, request?: DebugProtocol.Request) : void {
this.sendResponse(response);
}
protected restartFrameRequest(response: DebugProtocol.RestartFrameResponse, args: DebugProtocol.RestartFrameArguments, request?: DebugProtocol.Request) : void {
this.sendResponse(response);
}
protected gotoRequest(response: DebugProtocol.GotoResponse, args: DebugProtocol.GotoArguments, request?: DebugProtocol.Request) : void {
this.sendResponse(response);
}
protected pauseRequest(response: DebugProtocol.PauseResponse, args: DebugProtocol.PauseArguments, request?: DebugProtocol.Request) : void {
this.sendResponse(response);
}
protected sourceRequest(response: DebugProtocol.SourceResponse, args: DebugProtocol.SourceArguments, request?: DebugProtocol.Request) : void {
this.sendResponse(response);
}
protected threadsRequest(response: DebugProtocol.ThreadsResponse, request?: DebugProtocol.Request): void {
this.sendResponse(response);
}
protected terminateThreadsRequest(response: DebugProtocol.TerminateThreadsResponse, args: DebugProtocol.TerminateThreadsArguments, request?: DebugProtocol.Request): void {
this.sendResponse(response);
}
protected stackTraceRequest(response: DebugProtocol.StackTraceResponse, args: DebugProtocol.StackTraceArguments, request?: DebugProtocol.Request): void {
this.sendResponse(response);
}
protected scopesRequest(response: DebugProtocol.ScopesResponse, args: DebugProtocol.ScopesArguments, request?: DebugProtocol.Request): void {
this.sendResponse(response);
}
protected variablesRequest(response: DebugProtocol.VariablesResponse, args: DebugProtocol.VariablesArguments, request?: DebugProtocol.Request): void {
this.sendResponse(response);
}
protected setVariableRequest(response: DebugProtocol.SetVariableResponse, args: DebugProtocol.SetVariableArguments, request?: DebugProtocol.Request): void {
this.sendResponse(response);
}
protected setExpressionRequest(response: DebugProtocol.SetExpressionResponse, args: DebugProtocol.SetExpressionArguments, request?: DebugProtocol.Request): void {
this.sendResponse(response);
}
protected evaluateRequest(response: DebugProtocol.EvaluateResponse, args: DebugProtocol.EvaluateArguments, request?: DebugProtocol.Request): void {
this.sendResponse(response);
}
protected stepInTargetsRequest(response: DebugProtocol.StepInTargetsResponse, args: DebugProtocol.StepInTargetsArguments, request?: DebugProtocol.Request): void {
this.sendResponse(response);
}
protected gotoTargetsRequest(response: DebugProtocol.GotoTargetsResponse, args: DebugProtocol.GotoTargetsArguments, request?: DebugProtocol.Request): void {
this.sendResponse(response);
}
protected completionsRequest(response: DebugProtocol.CompletionsResponse, args: DebugProtocol.CompletionsArguments, request?: DebugProtocol.Request): void {
this.sendResponse(response);
}
protected exceptionInfoRequest(response: DebugProtocol.ExceptionInfoResponse, args: DebugProtocol.ExceptionInfoArguments, request?: DebugProtocol.Request): void {
this.sendResponse(response);
}
protected loadedSourcesRequest(response: DebugProtocol.LoadedSourcesResponse, args: DebugProtocol.LoadedSourcesArguments, request?: DebugProtocol.Request): void {
this.sendResponse(response);
}
protected dataBreakpointInfoRequest(response: DebugProtocol.DataBreakpointInfoResponse, args: DebugProtocol.DataBreakpointInfoArguments, request?: DebugProtocol.Request): void {
this.sendResponse(response);
}
protected setDataBreakpointsRequest(response: DebugProtocol.SetDataBreakpointsResponse, args: DebugProtocol.SetDataBreakpointsArguments, request?: DebugProtocol.Request): void {
this.sendResponse(response);
}
protected readMemoryRequest(response: DebugProtocol.ReadMemoryResponse, args: DebugProtocol.ReadMemoryArguments, request?: DebugProtocol.Request): void {
this.sendResponse(response);
}
protected disassembleRequest(response: DebugProtocol.DisassembleResponse, args: DebugProtocol.DisassembleArguments, request?: DebugProtocol.Request): void {
this.sendResponse(response);
}
protected cancelRequest(response: DebugProtocol.CancelResponse, args: DebugProtocol.CancelArguments, request?: DebugProtocol.Request): void {
this.sendResponse(response);
}
protected breakpointLocationsRequest(response: DebugProtocol.BreakpointLocationsResponse, args: DebugProtocol.BreakpointLocationsArguments, request?: DebugProtocol.Request): void {
this.sendResponse(response);
}
protected setInstructionBreakpointsRequest(response: DebugProtocol.SetInstructionBreakpointsResponse, args: DebugProtocol.SetInstructionBreakpointsArguments, request?: DebugProtocol.Request): void {
this.sendResponse(response);
}
/**
* Override this hook to implement custom requests.
*/
protected customRequest(command: string, response: DebugProtocol.Response, args: any, request?: DebugProtocol.Request): void {
this.sendErrorResponse(response, 1014, 'unrecognized request', null, ErrorDestination.Telemetry);
}
//---- protected -------------------------------------------------------------------------------------------------
protected convertClientLineToDebugger(line: number): number {
if (this._debuggerLinesStartAt1) {
return this._clientLinesStartAt1 ? line : line + 1;
}
return this._clientLinesStartAt1 ? line - 1 : line;
}
protected convertDebuggerLineToClient(line: number): number {
if (this._debuggerLinesStartAt1) {
return this._clientLinesStartAt1 ? line : line - 1;
}
return this._clientLinesStartAt1 ? line + 1 : line;
}
protected convertClientColumnToDebugger(column: number): number {
if (this._debuggerColumnsStartAt1) {
return this._clientColumnsStartAt1 ? column : column + 1;
}
return this._clientColumnsStartAt1 ? column - 1 : column;
}
protected convertDebuggerColumnToClient(column: number): number {
if (this._debuggerColumnsStartAt1) {
return this._clientColumnsStartAt1 ? column : column - 1;
}
return this._clientColumnsStartAt1 ? column + 1 : column;
}
protected convertClientPathToDebugger(clientPath: string): string {
if (this._clientPathsAreURIs !== this._debuggerPathsAreURIs) {
if (this._clientPathsAreURIs) {
return DebugSession.uri2path(clientPath);
} else {
return DebugSession.path2uri(clientPath);
}
}
return clientPath;
}
protected convertDebuggerPathToClient(debuggerPath: string): string {
if (this._debuggerPathsAreURIs !== this._clientPathsAreURIs) {
if (this._debuggerPathsAreURIs) {
return DebugSession.uri2path(debuggerPath);
} else {
return DebugSession.path2uri(debuggerPath);
}
}
return debuggerPath;
}
//---- private -------------------------------------------------------------------------------
private static path2uri(path: string): string {
if (process.platform === 'win32') {
if (/^[A-Z]:/.test(path)) {
path = path[0].toLowerCase() + path.substr(1);
}
path = path.replace(/\\/g, '/');
}
path = encodeURI(path);
let uri = new URL(`file:`); // ignore 'path' for now
uri.pathname = path; // now use 'path' to get the correct percent encoding (see https://url.spec.whatwg.org)
return uri.toString();
}
private static uri2path(sourceUri: string): string {
let uri = new URL(sourceUri);
let s = decodeURIComponent(uri.pathname);
if (process.platform === 'win32') {
if (/^\/[a-zA-Z]:/.test(s)) {
s = s[1].toLowerCase() + s.substr(2);
}
s = s.replace(/\//g, '\\');
}
return s;
}
private static _formatPIIRegexp = /{([^}]+)}/g;
/*
* If argument starts with '_' it is OK to send its value to telemetry.
*/
private static formatPII(format:string, excludePII: boolean, args: {[key: string]: string}): string {
return format.replace(DebugSession._formatPIIRegexp, function(match, paramName) {
if (excludePII && paramName.length > 0 && paramName[0] !== '_') {
return match;
}
return args[paramName] && args.hasOwnProperty(paramName) ?
args[paramName] :
match;
})
}
}