forked from WebFreak001/code-debug
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmibase.ts
750 lines (698 loc) · 25.6 KB
/
mibase.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
import * as DebugAdapter from 'vscode-debugadapter';
import { DebugSession, InitializedEvent, TerminatedEvent, StoppedEvent, ThreadEvent, OutputEvent, ContinuedEvent, Thread, StackFrame, Scope, Source, Handles } from 'vscode-debugadapter';
import { DebugProtocol } from 'vscode-debugprotocol';
import { Breakpoint, IBackend, Variable, VariableObject, ValuesFormattingMode, MIError } from './backend/backend';
import { MINode } from './backend/mi_parse';
import { expandValue, isExpandable } from './backend/gdb_expansion';
import { MI2 } from './backend/mi2/mi2';
import * as systemPath from "path";
import * as net from "net";
import * as os from "os";
import * as fs from "fs";
import { SourceFileMap } from "./source_file_map";
class ExtendedVariable {
constructor(public name, public options) {
}
}
class VariableScope {
constructor (public readonly name: string, public readonly threadId: number, public readonly level: number) {
}
public static variableName (handle: number, name: string): string {
return `var_${handle}_${name}`;
}
}
export enum RunCommand { CONTINUE, RUN, NONE }
export class MI2DebugSession extends DebugSession {
protected variableHandles = new Handles<VariableScope | string | VariableObject | ExtendedVariable>();
protected variableHandlesReverse: { [id: string]: number } = {};
protected scopeHandlesReverse: { [key: string]: number } = {};
protected useVarObjects: boolean;
protected quit: boolean;
protected attached: boolean;
protected initialRunCommand: RunCommand;
protected stopAtEntry: boolean | string;
protected isSSH: boolean;
protected sourceFileMap: SourceFileMap;
protected started: boolean;
protected crashed: boolean;
protected miDebugger: MI2;
protected commandServer: net.Server;
protected serverPath: string;
public constructor(debuggerLinesStartAt1: boolean, isServer: boolean = false) {
super(debuggerLinesStartAt1, isServer);
}
protected initDebugger() {
this.miDebugger.on("launcherror", this.launchError.bind(this));
this.miDebugger.on("quit", this.quitEvent.bind(this));
this.miDebugger.on("exited-normally", this.quitEvent.bind(this));
this.miDebugger.on("stopped", this.stopEvent.bind(this));
this.miDebugger.on("msg", this.handleMsg.bind(this));
this.miDebugger.on("breakpoint", this.handleBreakpoint.bind(this));
this.miDebugger.on("watchpoint", this.handleBreak.bind(this)); // consider to parse old/new, too (otherwise it is in the console only)
this.miDebugger.on("step-end", this.handleBreak.bind(this));
//this.miDebugger.on("step-out-end", this.handleBreak.bind(this)); // was combined into step-end
this.miDebugger.on("step-other", this.handleBreak.bind(this));
this.miDebugger.on("signal-stop", this.handlePause.bind(this));
this.miDebugger.on("thread-created", this.threadCreatedEvent.bind(this));
this.miDebugger.on("thread-exited", this.threadExitedEvent.bind(this));
this.miDebugger.once("debug-ready", (() => this.sendEvent(new InitializedEvent())));
try {
this.commandServer = net.createServer(c => {
c.on("data", data => {
const rawCmd = data.toString();
const spaceIndex = rawCmd.indexOf(" ");
let func = rawCmd;
let args = [];
if (spaceIndex != -1) {
func = rawCmd.substring(0, spaceIndex);
args = JSON.parse(rawCmd.substring(spaceIndex + 1));
}
Promise.resolve(this.miDebugger[func].apply(this.miDebugger, args)).then(data => {
c.write(data.toString());
});
});
});
this.commandServer.on("error", err => {
if (process.platform != "win32")
this.handleMsg("stderr", "Code-Debug WARNING: Utility Command Server: Error in command socket " + err.toString() + "\nCode-Debug WARNING: The examine memory location command won't work");
});
if (!fs.existsSync(systemPath.join(os.tmpdir(), "code-debug-sockets")))
fs.mkdirSync(systemPath.join(os.tmpdir(), "code-debug-sockets"));
this.commandServer.listen(this.serverPath = systemPath.join(os.tmpdir(), "code-debug-sockets", ("Debug-Instance-" + Math.floor(Math.random() * 36 * 36 * 36 * 36).toString(36)).toLowerCase()));
} catch (e) {
if (process.platform != "win32")
this.handleMsg("stderr", "Code-Debug WARNING: Utility Command Server: Failed to start " + e.toString() + "\nCode-Debug WARNING: The examine memory location command won't work");
}
}
protected setValuesFormattingMode(mode: ValuesFormattingMode) {
switch (mode) {
case "disabled":
this.useVarObjects = true;
this.miDebugger.prettyPrint = false;
break;
case "prettyPrinters":
this.useVarObjects = true;
this.miDebugger.prettyPrint = true;
break;
case "parseText":
default:
this.useVarObjects = false;
this.miDebugger.prettyPrint = false;
}
}
protected handleMsg(type: string, msg: string) {
if (type == "target")
type = "stdout";
if (type == "log")
type = "stderr";
this.sendEvent(new OutputEvent(msg, type));
}
protected handleBreakpoint(info: MINode) {
const event = new StoppedEvent("breakpoint", parseInt(info.record("thread-id")));
(event as DebugProtocol.StoppedEvent).body.allThreadsStopped = info.record("stopped-threads") == "all";
this.sendEvent(event);
}
protected handleBreak(info?: MINode) {
const event = new StoppedEvent("step", info ? parseInt(info.record("thread-id")) : 1);
(event as DebugProtocol.StoppedEvent).body.allThreadsStopped = info ? info.record("stopped-threads") == "all" : true;
this.sendEvent(event);
}
protected handlePause(info: MINode) {
const event = new StoppedEvent("user request", parseInt(info.record("thread-id")));
(event as DebugProtocol.StoppedEvent).body.allThreadsStopped = info.record("stopped-threads") == "all";
this.sendEvent(event);
}
protected stopEvent(info: MINode) {
if (!this.started)
this.crashed = true;
if (!this.quit) {
const event = new StoppedEvent("exception", parseInt(info.record("thread-id")));
(event as DebugProtocol.StoppedEvent).body.allThreadsStopped = info.record("stopped-threads") == "all";
this.sendEvent(event);
}
}
protected threadCreatedEvent(info: MINode) {
this.sendEvent(new ThreadEvent("started", info.record("id")));
}
protected threadExitedEvent(info: MINode) {
this.sendEvent(new ThreadEvent("exited", info.record("id")));
}
protected quitEvent() {
this.quit = true;
this.sendEvent(new TerminatedEvent());
if (this.serverPath)
fs.unlink(this.serverPath, (err) => {
// eslint-disable-next-line no-console
console.error("Failed to unlink debug server");
});
}
protected launchError(err: any) {
this.handleMsg("stderr", "Could not start debugger process, does the program exist in filesystem?\n");
this.handleMsg("stderr", err.toString() + "\n");
this.quitEvent();
}
protected disconnectRequest(response: DebugProtocol.DisconnectResponse, args: DebugProtocol.DisconnectArguments): void {
if (this.attached)
this.miDebugger.detach();
else
this.miDebugger.stop();
this.commandServer.close();
this.commandServer = undefined;
this.sendResponse(response);
}
protected async setVariableRequest(response: DebugProtocol.SetVariableResponse, args: DebugProtocol.SetVariableArguments): Promise<void> {
try {
if (this.useVarObjects) {
let name = args.name;
const parent = this.variableHandles.get(args.variablesReference);
if (parent instanceof VariableScope) {
name = VariableScope.variableName(args.variablesReference, name);
} else if (parent instanceof VariableObject) {
name = `${parent.name}.${name}`;
}
const res = await this.miDebugger.varAssign(name, args.value);
response.body = {
value: res.result("value")
};
} else {
await this.miDebugger.changeVariable(args.name, args.value);
response.body = {
value: args.value
};
}
this.sendResponse(response);
} catch (err) {
this.sendErrorResponse(response, 11, `Could not continue: ${err}`);
}
}
protected setFunctionBreakPointsRequest(response: DebugProtocol.SetFunctionBreakpointsResponse, args: DebugProtocol.SetFunctionBreakpointsArguments): void {
const all = [];
args.breakpoints.forEach(brk => {
all.push(this.miDebugger.addBreakPoint({ raw: brk.name, condition: brk.condition, countCondition: brk.hitCondition }));
});
Promise.all(all).then(brkpoints => {
const finalBrks = [];
brkpoints.forEach(brkp => {
if (brkp[0])
finalBrks.push({ line: brkp[1].line });
});
response.body = {
breakpoints: finalBrks
};
this.sendResponse(response);
}, msg => {
this.sendErrorResponse(response, 10, msg.toString());
});
}
protected setBreakPointsRequest(response: DebugProtocol.SetBreakpointsResponse, args: DebugProtocol.SetBreakpointsArguments): void {
let path = args.source.path;
if (this.isSSH) {
// convert local path to ssh path
path = this.sourceFileMap.toRemotePath(path);
}
this.miDebugger.clearBreakPoints(path).then(() => {
const all = args.breakpoints.map(brk => {
return this.miDebugger.addBreakPoint({ file: path, line: brk.line, condition: brk.condition, countCondition: brk.hitCondition });
});
Promise.all(all).then(brkpoints => {
const finalBrks = [];
brkpoints.forEach(brkp => {
// TODO: Currently all breakpoints returned are marked as verified,
// which leads to verified breakpoints on a broken lldb.
if (brkp[0])
finalBrks.push(new DebugAdapter.Breakpoint(true, brkp[1].line));
});
response.body = {
breakpoints: finalBrks
};
this.sendResponse(response);
}, msg => {
this.sendErrorResponse(response, 9, msg.toString());
});
}, msg => {
this.sendErrorResponse(response, 9, msg.toString());
});
}
protected threadsRequest(response: DebugProtocol.ThreadsResponse): void {
if (!this.miDebugger) {
this.sendResponse(response);
return;
}
this.miDebugger.getThreads().then(threads => {
response.body = {
threads: []
};
for (const thread of threads) {
const threadName = thread.name || thread.targetId || "<unnamed>";
response.body.threads.push(new Thread(thread.id, thread.id + ":" + threadName));
}
this.sendResponse(response);
}).catch(error => {
this.sendErrorResponse(response, 17, `Could not get threads: ${error}`);
});
}
// Supports 65535 threads.
protected threadAndLevelToFrameId(threadId: number, level: number) {
return level << 16 | threadId;
}
protected frameIdToThreadAndLevel(frameId: number) {
return [frameId & 0xffff, frameId >> 16];
}
protected stackTraceRequest(response: DebugProtocol.StackTraceResponse, args: DebugProtocol.StackTraceArguments): void {
this.miDebugger.getStack(args.startFrame, args.levels, args.threadId).then(stack => {
const ret: StackFrame[] = [];
stack.forEach(element => {
let source = undefined;
let path = element.file;
if (path) {
if (this.isSSH) {
// convert ssh path to local path
path = this.sourceFileMap.toLocalPath(path);
} else if (process.platform === "win32") {
if (path.startsWith("\\cygdrive\\") || path.startsWith("/cygdrive/")) {
path = path[10] + ":" + path.substring(11); // replaces /cygdrive/c/foo/bar.txt with c:/foo/bar.txt
}
}
source = new Source(element.fileName, path);
}
ret.push(new StackFrame(
this.threadAndLevelToFrameId(args.threadId, element.level),
element.function + "@" + element.address,
source,
element.line,
0));
});
response.body = {
stackFrames: ret
};
this.sendResponse(response);
}, err => {
this.sendErrorResponse(response, 12, `Failed to get Stack Trace: ${err.toString()}`);
});
}
protected configurationDoneRequest(response: DebugProtocol.ConfigurationDoneResponse, args: DebugProtocol.ConfigurationDoneArguments): void {
const promises: Thenable<any>[] = [];
let entryPoint: string | undefined = undefined;
let runToStart: boolean = false;
// Setup temporary breakpoint for the entry point if needed.
switch (this.initialRunCommand) {
case RunCommand.CONTINUE:
case RunCommand.NONE:
if (typeof this.stopAtEntry == 'boolean' && this.stopAtEntry)
entryPoint = "main"; // sensible default
else if (typeof this.stopAtEntry == 'string')
entryPoint = this.stopAtEntry;
break;
case RunCommand.RUN:
if (typeof this.stopAtEntry == 'boolean' && this.stopAtEntry) {
if (this.miDebugger.features.includes("exec-run-start-option"))
runToStart = true;
else
entryPoint = "main"; // sensible fallback
} else if (typeof this.stopAtEntry == 'string')
entryPoint = this.stopAtEntry;
break;
default:
throw new Error('Unhandled run command: ' + RunCommand[this.initialRunCommand]);
}
if (entryPoint)
promises.push(this.miDebugger.setEntryBreakPoint(entryPoint));
switch (this.initialRunCommand) {
case RunCommand.CONTINUE:
promises.push(this.miDebugger.continue().then(() => {
// Some debuggers will provide an out-of-band status that they are stopped
// when attaching (e.g., gdb), so the client assumes we are stopped and gets
// confused if we start running again on our own.
//
// If we don't send this event, the client may start requesting data (such as
// stack frames, local variables, etc.) since they believe the target is
// stopped. Furthermore, the client may not be indicating the proper status
// to the user (may indicate stopped when the target is actually running).
this.sendEvent(new ContinuedEvent(1, true));
}));
break;
case RunCommand.RUN:
promises.push(this.miDebugger.start(runToStart).then(() => {
this.started = true;
if (this.crashed)
this.handlePause(undefined);
}));
break;
case RunCommand.NONE: {
// Not all debuggers seem to provide an out-of-band status that they are stopped
// when attaching (e.g., lldb), so the client assumes we are running and gets
// confused when we don't actually run or continue. Therefore, we'll force a
// stopped event to be sent to the client (just in case) to synchronize the state.
const event: DebugProtocol.StoppedEvent = new StoppedEvent("pause", 1);
event.body.description = "paused on attach";
event.body.allThreadsStopped = true;
this.sendEvent(event);
break;
}
default:
throw new Error('Unhandled run command: ' + RunCommand[this.initialRunCommand]);
}
Promise.all(promises).then(() => {
this.sendResponse(response);
}).catch(err => {
this.sendErrorResponse(response, 18, `Could not run/continue: ${err.toString()}`);
});
}
protected scopesRequest(response: DebugProtocol.ScopesResponse, args: DebugProtocol.ScopesArguments): void {
const scopes = new Array<Scope>();
const [threadId, level] = this.frameIdToThreadAndLevel(args.frameId);
const createScope = (scopeName: string, expensive: boolean): Scope => {
const key: string = scopeName + ":" + threadId + ":" + level;
let handle: number;
if (this.scopeHandlesReverse.hasOwnProperty(key)) {
handle = this.scopeHandlesReverse[key];
} else {
handle = this.variableHandles.create(new VariableScope(scopeName, threadId, level));
this.scopeHandlesReverse[key] = handle;
}
return new Scope(scopeName, handle, expensive);
};
scopes.push(createScope("Local", false));
response.body = {
scopes: scopes
};
this.sendResponse(response);
}
protected async variablesRequest(response: DebugProtocol.VariablesResponse, args: DebugProtocol.VariablesArguments): Promise<void> {
const variables: DebugProtocol.Variable[] = [];
const id: VariableScope | string | VariableObject | ExtendedVariable = this.variableHandles.get(args.variablesReference);
const createVariable = (arg, options?) => {
if (options)
return this.variableHandles.create(new ExtendedVariable(arg, options));
else
return this.variableHandles.create(arg);
};
const findOrCreateVariable = (varObj: VariableObject): number => {
let id: number;
if (this.variableHandlesReverse.hasOwnProperty(varObj.name)) {
id = this.variableHandlesReverse[varObj.name];
} else {
id = createVariable(varObj);
this.variableHandlesReverse[varObj.name] = id;
}
return varObj.isCompound() ? id : 0;
};
if (id instanceof VariableScope) {
let stack: Variable[];
try {
stack = await this.miDebugger.getStackVariables(id.threadId, id.level);
for (const variable of stack) {
if (this.useVarObjects) {
try {
const varObjName = VariableScope.variableName(args.variablesReference, variable.name);
let varObj: VariableObject;
try {
const changes = await this.miDebugger.varUpdate(varObjName);
const changelist = changes.result("changelist");
changelist.forEach((change) => {
const name = MINode.valueOf(change, "name");
const vId = this.variableHandlesReverse[name];
const v = this.variableHandles.get(vId) as any;
v.applyChanges(change);
});
const varId = this.variableHandlesReverse[varObjName];
varObj = this.variableHandles.get(varId) as any;
} catch (err) {
if (err instanceof MIError && err.message == "Variable object not found") {
varObj = await this.miDebugger.varCreate(variable.name, varObjName);
const varId = findOrCreateVariable(varObj);
varObj.exp = variable.name;
varObj.id = varId;
} else {
throw err;
}
}
variables.push(varObj.toProtocolVariable());
} catch (err) {
variables.push({
name: variable.name,
value: `<${err}>`,
variablesReference: 0
});
}
} else {
if (variable.valueStr !== undefined) {
let expanded = expandValue(createVariable, `{${variable.name}=${variable.valueStr})`, "", variable.raw);
if (expanded) {
if (typeof expanded[0] == "string")
expanded = [
{
name: "<value>",
value: prettyStringArray(expanded),
variablesReference: 0
}
];
variables.push(expanded[0]);
}
} else
variables.push({
name: variable.name,
type: variable.type,
value: "<unknown>",
variablesReference: createVariable(variable.name)
});
}
}
response.body = {
variables: variables
};
this.sendResponse(response);
} catch (err) {
this.sendErrorResponse(response, 1, `Could not expand variable: ${err}`);
}
} else if (typeof id == "string") {
// Variable members
let variable;
try {
// TODO: this evaluates on an (effectively) unknown thread for multithreaded programs.
variable = await this.miDebugger.evalExpression(JSON.stringify(id), 0, 0);
try {
let expanded = expandValue(createVariable, variable.result("value"), id, variable);
if (!expanded) {
this.sendErrorResponse(response, 2, `Could not expand variable`);
} else {
if (typeof expanded[0] == "string")
expanded = [
{
name: "<value>",
value: prettyStringArray(expanded),
variablesReference: 0
}
];
response.body = {
variables: expanded
};
this.sendResponse(response);
}
} catch (e) {
this.sendErrorResponse(response, 2, `Could not expand variable: ${e}`);
}
} catch (err) {
this.sendErrorResponse(response, 1, `Could not expand variable: ${err}`);
}
} else if (typeof id == "object") {
if (id instanceof VariableObject) {
// Variable members
let children: VariableObject[];
try {
children = await this.miDebugger.varListChildren(id.name);
const vars = children.map(child => {
const varId = findOrCreateVariable(child);
child.id = varId;
return child.toProtocolVariable();
});
response.body = {
variables: vars
};
this.sendResponse(response);
} catch (err) {
this.sendErrorResponse(response, 1, `Could not expand variable: ${err}`);
}
} else if (id instanceof ExtendedVariable) {
const varReq = id;
if (varReq.options.arg) {
const strArr = [];
let argsPart = true;
let arrIndex = 0;
const submit = () => {
response.body = {
variables: strArr
};
this.sendResponse(response);
};
const addOne = async () => {
// TODO: this evaluates on an (effectively) unknown thread for multithreaded programs.
const variable = await this.miDebugger.evalExpression(JSON.stringify(`${varReq.name}+${arrIndex})`), 0, 0);
try {
const expanded = expandValue(createVariable, variable.result("value"), varReq.name, variable);
if (!expanded) {
this.sendErrorResponse(response, 15, `Could not expand variable`);
} else {
if (typeof expanded == "string") {
if (expanded == "<nullptr>") {
if (argsPart)
argsPart = false;
else
return submit();
} else if (expanded[0] != '"') {
strArr.push({
name: "[err]",
value: expanded,
variablesReference: 0
});
return submit();
}
strArr.push({
name: `[${(arrIndex++)}]`,
value: expanded,
variablesReference: 0
});
addOne();
} else {
strArr.push({
name: "[err]",
value: expanded,
variablesReference: 0
});
submit();
}
}
} catch (e) {
this.sendErrorResponse(response, 14, `Could not expand variable: ${e}`);
}
};
addOne();
} else
this.sendErrorResponse(response, 13, `Unimplemented variable request options: ${JSON.stringify(varReq.options)}`);
} else {
response.body = {
variables: id
};
this.sendResponse(response);
}
} else {
response.body = {
variables: variables
};
this.sendResponse(response);
}
}
protected pauseRequest(response: DebugProtocol.ContinueResponse, args: DebugProtocol.ContinueArguments): void {
this.miDebugger.interrupt().then(done => {
this.sendResponse(response);
}, msg => {
this.sendErrorResponse(response, 3, `Could not pause: ${msg}`);
});
}
protected reverseContinueRequest(response: DebugProtocol.ReverseContinueResponse, args: DebugProtocol.ReverseContinueArguments): void {
this.miDebugger.continue(true).then(done => {
this.sendResponse(response);
}, msg => {
this.sendErrorResponse(response, 2, `Could not continue: ${msg}`);
});
}
protected continueRequest(response: DebugProtocol.ContinueResponse, args: DebugProtocol.ContinueArguments): void {
this.miDebugger.continue().then(done => {
this.sendResponse(response);
}, msg => {
this.sendErrorResponse(response, 2, `Could not continue: ${msg}`);
});
}
protected stepBackRequest(response: DebugProtocol.StepBackResponse, args: DebugProtocol.StepBackArguments): void {
this.miDebugger.step(true).then(done => {
this.sendResponse(response);
}, msg => {
this.sendErrorResponse(response, 4, `Could not step back: ${msg} - Try running 'target record-full' before stepping back`);
});
}
protected stepInRequest(response: DebugProtocol.NextResponse, args: DebugProtocol.NextArguments): void {
this.miDebugger.step().then(done => {
this.sendResponse(response);
}, msg => {
this.sendErrorResponse(response, 4, `Could not step in: ${msg}`);
});
}
protected stepOutRequest(response: DebugProtocol.NextResponse, args: DebugProtocol.NextArguments): void {
this.miDebugger.stepOut().then(done => {
this.sendResponse(response);
}, msg => {
this.sendErrorResponse(response, 5, `Could not step out: ${msg}`);
});
}
protected nextRequest(response: DebugProtocol.NextResponse, args: DebugProtocol.NextArguments): void {
this.miDebugger.next().then(done => {
this.sendResponse(response);
}, msg => {
this.sendErrorResponse(response, 6, `Could not step over: ${msg}`);
});
}
protected evaluateRequest(response: DebugProtocol.EvaluateResponse, args: DebugProtocol.EvaluateArguments): void {
const [threadId, level] = this.frameIdToThreadAndLevel(args.frameId);
if (args.context == "watch" || args.context == "hover") {
this.miDebugger.evalExpression(args.expression, threadId, level).then((res) => {
response.body = {
variablesReference: 0,
result: res.result("value")
};
this.sendResponse(response);
}, msg => {
this.sendErrorResponse(response, 7, msg.toString());
});
} else {
this.miDebugger.sendUserInput(args.expression, threadId, level).then(output => {
if (typeof output == "undefined")
response.body = {
result: "",
variablesReference: 0
};
else
response.body = {
result: JSON.stringify(output),
variablesReference: 0
};
this.sendResponse(response);
}, msg => {
this.sendErrorResponse(response, 8, msg.toString());
});
}
}
protected gotoTargetsRequest(response: DebugProtocol.GotoTargetsResponse, args: DebugProtocol.GotoTargetsArguments): void {
const path: string = this.isSSH ? this.sourceFileMap.toRemotePath(args.source.path) : args.source.path;
this.miDebugger.goto(path, args.line).then(done => {
response.body = {
targets: [{
id: 1,
label: args.source.name,
column: args.column,
line : args.line
}]
};
this.sendResponse(response);
}, msg => {
this.sendErrorResponse(response, 16, `Could not jump: ${msg}`);
});
}
protected gotoRequest(response: DebugProtocol.GotoResponse, args: DebugProtocol.GotoArguments): void {
this.sendResponse(response);
}
protected setSourceFileMap(configMap: { [index: string]: string }, fallbackGDB: string, fallbackIDE: string): void {
if (configMap === undefined) {
this.sourceFileMap = new SourceFileMap({[fallbackGDB]: fallbackIDE});
} else {
this.sourceFileMap = new SourceFileMap(configMap, fallbackGDB);
}
}
}
function prettyStringArray(strings) {
if (typeof strings == "object") {
if (strings.length !== undefined)
return strings.join(", ");
else
return JSON.stringify(strings);
} else return strings;
}