Skip to content

Commit

Permalink
Support removing function breakpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
thegecko committed Nov 20, 2019
1 parent 5da76e8 commit 88fcd1f
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 10 deletions.
63 changes: 55 additions & 8 deletions src/GDBDebugSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export class GDBDebugSession extends LoggingDebugSession {

protected frameHandles = new Handles<FrameReference>();
protected variableHandles = new Handles<VariableReference>();
protected functionBreakpoints: string[] = [];
protected logPointMessages: { [ key: string ]: string } = {};

protected threads: Thread[] = [];
Expand Down Expand Up @@ -263,8 +264,8 @@ export class GDBDebugSession extends LoggingDebugSession {

let inserts = breakpoints.slice();
const deletes = new Array<string>();

const actual = new Array<DebugProtocol.Breakpoint>();

const createActual = (breakpoint: mi.MIBreakpointInfo) => {
return {
id: parseInt(breakpoint.number, 10),
Expand All @@ -274,7 +275,12 @@ export class GDBDebugSession extends LoggingDebugSession {
};

const result = await mi.sendBreakList(this.gdb);
result.BreakpointTable.body.forEach((gdbbp) => {
const gdbbps = result.BreakpointTable.body.filter((gdbbp) => {
// Ignore function breakpoints
return this.functionBreakpoints.indexOf(gdbbp.number) === -1;
});

gdbbps.forEach((gdbbp) => {
if (gdbbp.fullname === file && gdbbp.line) {
// TODO probably need more thorough checks than just line number
const line = parseInt(gdbbp.line, 10);
Expand Down Expand Up @@ -355,18 +361,59 @@ export class GDBDebugSession extends LoggingDebugSession {

protected async setFunctionBreakPointsRequest(response: DebugProtocol.SetFunctionBreakpointsResponse,
args: DebugProtocol.SetFunctionBreakpointsArguments) {

const neededPause = this.isRunning;
if (neededPause) {
// Need to pause first
const waitPromise = new Promise<void>((resolve) => {
this.waitPaused = resolve;
});
this.gdb.pause();
await waitPromise;
}

try {
for (const fn of args.breakpoints) {
try {
await mi.sendBreakFunctionInsert(this.gdb, fn.name);
} catch (error) {
this.sendEvent(new OutputEvent(`Unable to set function breakpoint: ${error.message}`));
}
const vsbps = args.breakpoints || [];
const actual = new Array<DebugProtocol.Breakpoint>();
const result = await mi.sendBreakList(this.gdb);
const gdbbps = result.BreakpointTable.body.filter((gdbbp) => {
// Only function breakpoints
return this.functionBreakpoints.indexOf(gdbbp.number) > -1;
});

const inserts = vsbps.filter((vsbp) => {
return !gdbbps.find((gdbbp) => gdbbp.originalLocation === `-function ${vsbp.name}`);
});
const deletes = gdbbps.filter((gdbbp) => {
return !vsbps.find((vsbp) => gdbbp.originalLocation === `-function ${vsbp.name}`);
}).map((gdbbp) => gdbbp.number);

for (const vsbp of inserts) {
const gdbbp = await mi.sendBreakFunctionInsert(this.gdb, vsbp.name);
this.functionBreakpoints.push(gdbbp.bkpt.number);
actual.push({
id: parseInt(gdbbp.bkpt.number, 10),
verified: true,
});
}

if (deletes.length > 0) {
await mi.sendBreakDelete(this.gdb, { breakpoints: deletes });
this.functionBreakpoints = this.functionBreakpoints.filter((fnbp) => deletes.indexOf(fnbp) === -1);
}

response.body = {
breakpoints: actual,
};

this.sendResponse(response);
} catch (err) {
this.sendErrorResponse(response, 1, err.message);
}

if (neededPause) {
mi.sendExecContinue(this.gdb);
}
}

protected async configurationDoneRequest(response: DebugProtocol.ConfigurationDoneResponse,
Expand Down
4 changes: 2 additions & 2 deletions src/mi/breakpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export function sendBreakList(gdb: GDBBackend): Promise<MIBreakListResponse> {
return gdb.sendCommand('-break-list');
}

export function sendBreakFunctionInsert(gdb: GDBBackend, fn: string) {
export function sendBreakFunctionInsert(gdb: GDBBackend, fn: string): Promise<MIBreakInsertResponse> {
const command = `-break-insert --function ${fn}`;
return gdb.sendCommand(command);
return gdb.sendCommand<MIBreakInsertResponse>(command);
}

0 comments on commit 88fcd1f

Please sign in to comment.