Skip to content

Commit 5b85f1d

Browse files
committed
del breakpoint
1 parent 5e0d458 commit 5b85f1d

File tree

2 files changed

+49
-14
lines changed

2 files changed

+49
-14
lines changed

src/debugger/AttachDebugSession.ts

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import * as sb from "smart-buffer";
99
import {
1010
LuaAttachMessage, DMReqInitialize, DebugMessageId, DMMessage, DMLoadScript,
1111
DMAddBreakpoint, DMBreak, StackNodeContainer, StackRootNode, IStackNode,
12-
DMReqEvaluate, DMRespEvaluate, ExprEvaluator, LoadedScript, LoadedScriptManager
12+
DMReqEvaluate, DMRespEvaluate, ExprEvaluator, LoadedScript, LoadedScriptManager,
13+
DMDelBreakpoint
1314
} from './AttachProtol';
1415
import { ByteArray } from './ByteArray';
1516
import * as path from 'path';
@@ -37,6 +38,7 @@ interface EmmyLaunchRequesetArguments extends DebugProtocol.LaunchRequestArgumen
3738

3839
interface EmmyBreakpoint {
3940
id: number;
41+
scriptIndex: number;
4042
line: number;
4143
}
4244

@@ -215,8 +217,9 @@ export class AttachDebugSession extends LoggingDebugSession implements ExprEvalu
215217
const bpList = this.breakpoints.get(filePath);
216218
if (bpList) {
217219
for (let index = 0; index < bpList.length; index++) {
218-
const bp = bpList[index];
219-
this.send(new DMAddBreakpoint(script.index, this.convertClientLineToDebugger(bp.line)));
220+
const ebp = bpList[index];
221+
ebp.scriptIndex = script.index;
222+
this.send(new DMAddBreakpoint(script.index, this.convertClientLineToDebugger(ebp.line)));
220223
}
221224
}
222225
} else {
@@ -272,30 +275,45 @@ export class AttachDebugSession extends LoggingDebugSession implements ExprEvalu
272275
let lines = args.breakpoints || [];
273276
const path = this.normalize(<string> args.source.path);
274277

275-
let bpList = this.breakpoints.get(path);
276-
if (!bpList) {
277-
bpList = new Array<EmmyBreakpoint>();
278-
this.breakpoints.set(path, bpList);
278+
let existBps = this.breakpoints.get(path);
279+
const existMap = new Map<number, EmmyBreakpoint>();
280+
if (existBps) {
281+
existBps.forEach(bp => existMap.set(bp.line, bp));
279282
}
280-
const bps = bpList;
283+
const bps = <EmmyBreakpoint[]>[];
281284

282285
const breakpoints = new Array<DebugProtocol.Breakpoint>();
283286
lines.forEach(bp => {
284287
const bpk = <DebugProtocol.Breakpoint> new Breakpoint(true, bp.line);
285288
bpk.id = ++breakpointId;
286289
breakpoints.push(bpk);
287-
288-
bps.push({ id: breakpointId, line: bp.line });
289290

290-
//send
291-
const script = this.findScript(path);
292-
if (script) {
293-
this.send(new DMAddBreakpoint(script.index, this.convertClientLineToDebugger(bp.line)));
291+
const exist = existMap.get(bp.line);
292+
if (exist) {
293+
bps.push(exist);
294+
existMap.delete(bp.line);
295+
} else {
296+
const ebp: EmmyBreakpoint = { id: breakpointId, line: bp.line, scriptIndex: -1 };
297+
298+
//send
299+
const script = this.findScript(path);
300+
if (script) {
301+
this.send(new DMAddBreakpoint(script.index, this.convertClientLineToDebugger(bp.line)));
302+
ebp.scriptIndex = script.index;
303+
}
304+
bps.push(ebp);
294305
}
295306
});
296307
response.body = {
297308
breakpoints: breakpoints
298309
};
310+
311+
this.breakpoints.set(path, bps);
312+
existMap.forEach((v, k) => {
313+
if (v.scriptIndex > 0) {
314+
this.send(new DMDelBreakpoint(v.scriptIndex, this.convertClientLineToDebugger(v.line)));
315+
}
316+
});
299317
this.sendResponse(response);
300318
}
301319

src/debugger/AttachProtol.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,23 @@ export class DMAddBreakpoint extends LuaAttachMessage {
116116
}
117117
}
118118

119+
export class DMDelBreakpoint extends LuaAttachMessage {
120+
scriptIndex: number;
121+
line: number;
122+
123+
constructor(si: number, l: number) {
124+
super(DebugMessageId.DelBreakpoint);
125+
this.scriptIndex = si;
126+
this.line = l;
127+
}
128+
129+
write(buf: ByteArray) {
130+
super.write(buf);
131+
buf.writeUint32(this.scriptIndex);
132+
buf.writeUint32(this.line);
133+
}
134+
}
135+
119136
export class DMLoadScript extends LuaAttachMessage {
120137
fileName?:string;
121138
source?:string;

0 commit comments

Comments
 (0)