Skip to content

Commit 8f69156

Browse files
Yuyupoyichoi
authored andcommitted
Breakpoints (#20)
IoT.js-Debug-DCO-1.0-Signed-off-by: Daniella Barsony [email protected]
1 parent ea0ea93 commit 8f69156

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed

src/IotjsDebugger.ts

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
import {
2020
LoggingDebugSession, DebugSession, Logger, logger, InitializedEvent, OutputEvent, Thread, Source,
21-
StoppedEvent, ContinuedEvent, StackFrame, TerminatedEvent
21+
StoppedEvent, ContinuedEvent, StackFrame, TerminatedEvent, Breakpoint as AdapterBreakpoint
2222
} from 'vscode-debugadapter';
2323
import { DebugProtocol } from 'vscode-debugprotocol';
2424
import * as Fs from 'fs';
@@ -230,8 +230,55 @@ class IotjsDebugSession extends LoggingDebugSession {
230230
protected setBreakPointsRequest(
231231
response: DebugProtocol.SetBreakpointsResponse, args: DebugProtocol.SetBreakpointsArguments
232232
): void {
233-
this.log('setBreakPointsRequest: Not implemented yet');
233+
this.log('setBreakPointsRequest');
234+
235+
const filename = args.source.name;
236+
const clientLines = args.lines || [];
237+
238+
try {
239+
const scriptId = this._protocolhandler.getScriptIdByName(filename);
240+
241+
const activeBp = this._protocolhandler.getActiveBreakpointsByScriptId(scriptId);
242+
const activeBpLines = activeBp.map(b => b.line);
243+
const newBp = clientLines.filter(b => activeBpLines.indexOf(b) === -1);
244+
const removeBp = activeBpLines.filter(b => clientLines.indexOf(b) === -1);
245+
const persistingBp = clientLines.filter(b => newBp.indexOf(b) === -1);
246+
247+
let newBreakpoints = [];
248+
try {
249+
newBreakpoints = newBp.map(b => {
250+
const breakpoint = this._protocolhandler.findBreakpoint(scriptId, b);
251+
this._protocolhandler.updateBreakpoint(breakpoint, true);
252+
return <DebugProtocol.Breakpoint> new AdapterBreakpoint(true, b);
253+
});
254+
} catch (error) {
255+
this.log(error.message);
256+
}
257+
258+
try {
259+
removeBp.forEach(b => {
260+
const breakpoint = this._protocolhandler.findBreakpoint(scriptId, b);
261+
this._protocolhandler.updateBreakpoint(breakpoint, false);
262+
});
263+
} catch (error) {
264+
this.log(error.message);
265+
}
234266

267+
let persistingBreakpoints = [];
268+
try {
269+
persistingBreakpoints = persistingBp.map(b => {
270+
return <DebugProtocol.Breakpoint> new AdapterBreakpoint(true, b);
271+
});
272+
} catch (error) {
273+
this.log(error.message);
274+
}
275+
276+
response.body = {
277+
breakpoints: [...persistingBreakpoints, ...newBreakpoints]
278+
};
279+
} catch (error) {
280+
this.log(error.message);
281+
}
235282
this.sendResponse(response);
236283
}
237284

src/JerryProtocolHandler.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,10 @@ export class JerryDebugProtocolHandler {
545545
return this.activeBreakpoints[breakpointId];
546546
}
547547

548+
getActiveBreakpointsByScriptId(scriptId: number) {
549+
return this.activeBreakpoints.filter(b => b.scriptId === scriptId);
550+
}
551+
548552
evaluate(expression: string) {
549553
if (!this.lastBreakpointHit) {
550554
throw new Error('attempted eval while not at breakpoint');

0 commit comments

Comments
 (0)