Skip to content

Commit

Permalink
Merge pull request #313 from brownts/bugfix/breakpoint_race_condition
Browse files Browse the repository at this point in the history
Implement well defined window for breakpoint configuration.
  • Loading branch information
GitMensch committed Mar 3, 2022
2 parents d2c56d0 + 12f9a7a commit e2831d9
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 57 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* New `stopAtConnect` configuration #299, #302 (@brownts)
* New `stopAtEntry` configuration to run debugger to application's entry point #306 (@brownts)
* fix for race conditions on startup where breakpoints were not hit #304 (@brownts)
* fix additional race conditions with setting breakpoints #313 (@brownts)

# 0.25.1

Expand Down
2 changes: 0 additions & 2 deletions src/gdb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ class GDBDebugSession extends MI2DebugSession {
this.isSSH = false;
this.started = false;
this.crashed = false;
this.debugReady = false;
this.setValuesFormattingMode(args.valuesFormatting);
this.miDebugger.printCalls = !!args.printCalls;
this.miDebugger.debugOutput = !!args.showDevDebugOutput;
Expand Down Expand Up @@ -111,7 +110,6 @@ class GDBDebugSession extends MI2DebugSession {
this.attached = !args.remote;
this.initialRunCommand = !!args.stopAtConnect ? RunCommand.NONE : RunCommand.CONTINUE;
this.isSSH = false;
this.debugReady = false;
this.setValuesFormattingMode(args.valuesFormatting);
this.miDebugger.printCalls = !!args.printCalls;
this.miDebugger.debugOutput = !!args.showDevDebugOutput;
Expand Down
2 changes: 0 additions & 2 deletions src/lldb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ class LLDBDebugSession extends MI2DebugSession {
this.isSSH = false;
this.started = false;
this.crashed = false;
this.debugReady = false;
this.setValuesFormattingMode(args.valuesFormatting);
this.miDebugger.printCalls = !!args.printCalls;
this.miDebugger.debugOutput = !!args.showDevDebugOutput;
Expand Down Expand Up @@ -102,7 +101,6 @@ class LLDBDebugSession extends MI2DebugSession {
this.attached = true;
this.initialRunCommand = !!args.stopAtConnect ? RunCommand.NONE : RunCommand.CONTINUE;
this.isSSH = false;
this.debugReady = false;
this.setValuesFormattingMode(args.valuesFormatting);
this.miDebugger.printCalls = !!args.printCalls;
this.miDebugger.debugOutput = !!args.showDevDebugOutput;
Expand Down
2 changes: 0 additions & 2 deletions src/mago.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ class MagoDebugSession extends MI2DebugSession {
this.isSSH = false;
this.started = false;
this.crashed = false;
this.debugReady = false;
this.setValuesFormattingMode(args.valuesFormatting);
this.miDebugger.printCalls = !!args.printCalls;
this.miDebugger.debugOutput = !!args.showDevDebugOutput;
Expand All @@ -78,7 +77,6 @@ class MagoDebugSession extends MI2DebugSession {
this.attached = true;
this.initialRunCommand = !!args.stopAtConnect ? RunCommand.NONE : RunCommand.CONTINUE;
this.isSSH = false;
this.debugReady = false;
this.setValuesFormattingMode(args.valuesFormatting);
this.miDebugger.printCalls = !!args.printCalls;
this.miDebugger.debugOutput = !!args.showDevDebugOutput;
Expand Down
87 changes: 36 additions & 51 deletions src/mibase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ export class MI2DebugSession extends DebugSession {
protected switchCWD: string;
protected started: boolean;
protected crashed: boolean;
protected debugReady: boolean;
protected miDebugger: MI2;
protected commandServer: net.Server;
protected serverPath: string;
Expand All @@ -59,7 +58,7 @@ export class MI2DebugSession extends DebugSession {
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.sendEvent(new InitializedEvent());
this.miDebugger.once("debug-ready", (() => this.sendEvent(new InitializedEvent())));
try {
this.commandServer = net.createServer(c => {
c.on("data", data => {
Expand Down Expand Up @@ -202,68 +201,54 @@ export class MI2DebugSession extends DebugSession {
}

protected setFunctionBreakPointsRequest(response: DebugProtocol.SetFunctionBreakpointsResponse, args: DebugProtocol.SetFunctionBreakpointsArguments): void {
const cb = (() => {
this.debugReady = true;
const all = [];
args.breakpoints.forEach(brk => {
all.push(this.miDebugger.addBreakPoint({ raw: brk.name, condition: brk.condition, countCondition: brk.hitCondition }));
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 {
this.miDebugger.clearBreakPoints(args.source.path).then(() => {
let path = args.source.path;
if (this.isSSH) {
// trimCWD is the local path, switchCWD is the ssh path
path = systemPath.relative(this.trimCWD.replace(/\\/g, "/"), path.replace(/\\/g, "/"));
path = resolve(this.switchCWD.replace(/\\/g, "/"), path.replace(/\\/g, "/"));
}
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({ line: brkp[1].line });
finalBrks.push(new DebugAdapter.Breakpoint(true, brkp[1].line));
});
response.body = {
breakpoints: finalBrks
};
this.sendResponse(response);
}, msg => {
this.sendErrorResponse(response, 10, msg.toString());
});
}).bind(this);
if (this.debugReady)
cb();
else
this.miDebugger.once("debug-ready", cb);
}

protected setBreakPointsRequest(response: DebugProtocol.SetBreakpointsResponse, args: DebugProtocol.SetBreakpointsArguments): void {
const cb = (() => {
this.debugReady = true;
this.miDebugger.clearBreakPoints(args.source.path).then(() => {
let path = args.source.path;
if (this.isSSH) {
// trimCWD is the local path, switchCWD is the ssh path
path = systemPath.relative(this.trimCWD.replace(/\\/g, "/"), path.replace(/\\/g, "/"));
path = resolve(this.switchCWD.replace(/\\/g, "/"), path.replace(/\\/g, "/"));
}
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());
});
}).bind(this);
if (this.debugReady)
cb();
else
this.miDebugger.once("debug-ready", cb);
}, msg => {
this.sendErrorResponse(response, 9, msg.toString());
});
}

protected threadsRequest(response: DebugProtocol.ThreadsResponse): void {
Expand Down

0 comments on commit e2831d9

Please sign in to comment.