Skip to content

Commit c7370d8

Browse files
author
WebFreak001
committed
support breakpoint hit count
1 parent 2f2d029 commit c7370d8

7 files changed

Lines changed: 27 additions & 10 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"publisher": "webfreak",
1414
"icon": "images/icon-plain.svg",
1515
"engines": {
16-
"vscode": "^0.10.10"
16+
"vscode": "^1.7.2"
1717
},
1818
"main": "./out/src/frontend/extension",
1919
"activationEvents": [

src/backend/backend.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export interface Breakpoint {
33
line?: number;
44
raw?: string;
55
condition: string;
6+
countCondition?: string;
67
}
78

89
export interface Stack {

src/backend/mi2/mi2.ts

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export function escape(str: string) {
1616

1717
const nonOutput = /^(?:\d*|undefined)[\*\+\=]|[\~\@\&\^]/;
1818
const gdbMatch = /(?:\d*|undefined)\(gdb\)/;
19+
const numRegex = /\d+/;
1920

2021
function couldBeOutput(line: string) {
2122
if (nonOutput.exec(line))
@@ -232,8 +233,7 @@ export class MI2 extends EventEmitter implements IBackend {
232233
this.buffer = this.buffer.substr(end + 1);
233234
}
234235
if (this.buffer.length) {
235-
if (this.onOutputPartial(this.buffer))
236-
{
236+
if (this.onOutputPartial(this.buffer)) {
237237
this.buffer = "";
238238
}
239239
}
@@ -358,7 +358,7 @@ export class MI2 extends EventEmitter implements IBackend {
358358
let to = setTimeout(() => {
359359
proc.signal("KILL");
360360
}, 1000);
361-
this.stream.on("exit", function(code) {
361+
this.stream.on("exit", function (code) {
362362
clearTimeout(to);
363363
})
364364
this.sendRaw("-gdb-exit");
@@ -368,7 +368,7 @@ export class MI2 extends EventEmitter implements IBackend {
368368
let to = setTimeout(() => {
369369
process.kill(-proc.pid);
370370
}, 1000);
371-
this.process.on("exit", function(code) {
371+
this.process.on("exit", function (code) {
372372
clearTimeout(to);
373373
});
374374
this.sendRaw("-gdb-exit");
@@ -380,7 +380,7 @@ export class MI2 extends EventEmitter implements IBackend {
380380
let to = setTimeout(() => {
381381
process.kill(-proc.pid);
382382
}, 1000);
383-
this.process.on("exit", function(code) {
383+
this.process.on("exit", function (code) {
384384
clearTimeout(to);
385385
});
386386
this.sendRaw("-target-detach");
@@ -465,10 +465,23 @@ export class MI2 extends EventEmitter implements IBackend {
465465
if (this.breakpoints.has(breakpoint))
466466
return resolve(false);
467467
let location = "";
468+
if (breakpoint.countCondition) {
469+
if (breakpoint.countCondition[0] == ">")
470+
location += "-i " + numRegex.exec(breakpoint.countCondition.substr(1))[0] + " ";
471+
else {
472+
let match = numRegex.exec(breakpoint.countCondition)[0];
473+
if (match.length != breakpoint.countCondition.length) {
474+
this.log("stderr", "Unsupported break count expression: '" + breakpoint.countCondition + "'. Only supports 'X' for breaking once after X times or '>X' for ignoring the first X breaks");
475+
location += "-t ";
476+
}
477+
else if (parseInt(match) != 0)
478+
location += "-t -i " + parseInt(match) + " ";
479+
}
480+
}
468481
if (breakpoint.raw)
469-
location = '"' + escape(breakpoint.raw) + '"';
482+
location += '"' + escape(breakpoint.raw) + '"';
470483
else
471-
location = '"' + escape(breakpoint.file) + ":" + breakpoint.line + '"';
484+
location += '"' + escape(breakpoint.file) + ":" + breakpoint.line + '"';
472485
this.sendCommand("break-insert -f " + location).then((result) => {
473486
if (result.resultRecords.resultClass == "done") {
474487
let bkptNum = parseInt(result.result("bkpt.number"));

src/gdb.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export interface AttachRequestArguments {
2929

3030
class GDBDebugSession extends MI2DebugSession {
3131
protected initializeRequest(response: DebugProtocol.InitializeResponse, args: DebugProtocol.InitializeRequestArguments): void {
32+
response.body.supportsHitConditionalBreakpoints = true;
3233
response.body.supportsConfigurationDoneRequest = true;
3334
response.body.supportsConditionalBreakpoints = true;
3435
response.body.supportsFunctionBreakpoints = true;

src/lldb.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export interface AttachRequestArguments {
2727

2828
class LLDBDebugSession extends MI2DebugSession {
2929
protected initializeRequest(response: DebugProtocol.InitializeResponse, args: DebugProtocol.InitializeRequestArguments): void {
30+
response.body.supportsHitConditionalBreakpoints = true;
3031
response.body.supportsConfigurationDoneRequest = true;
3132
response.body.supportsConditionalBreakpoints = true;
3233
response.body.supportsFunctionBreakpoints = true;

src/mago.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class MagoDebugSession extends MI2DebugSession {
3030
}
3131

3232
protected initializeRequest(response: DebugProtocol.InitializeResponse, args: DebugProtocol.InitializeRequestArguments): void {
33+
response.body.supportsHitConditionalBreakpoints = true;
3334
response.body.supportsConfigurationDoneRequest = true;
3435
response.body.supportsConditionalBreakpoints = true;
3536
response.body.supportsFunctionBreakpoints = true;

src/mibase.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ export class MI2DebugSession extends DebugSession {
135135
this.debugReady = true;
136136
let all = [];
137137
args.breakpoints.forEach(brk => {
138-
all.push(this.miDebugger.addBreakPoint({ raw: brk.name, condition: brk.condition }));
138+
all.push(this.miDebugger.addBreakPoint({ raw: brk.name, condition: brk.condition, countCondition: brk.hitCondition }));
139139
});
140140
Promise.all(all).then(brkpoints => {
141141
let finalBrks = [];
@@ -168,7 +168,7 @@ export class MI2DebugSession extends DebugSession {
168168
}
169169
let all = [];
170170
args.breakpoints.forEach(brk => {
171-
all.push(this.miDebugger.addBreakPoint({ file: path, line: brk.line, condition: brk.condition }));
171+
all.push(this.miDebugger.addBreakPoint({ file: path, line: brk.line, condition: brk.condition, countCondition: brk.hitCondition }));
172172
});
173173
Promise.all(all).then(brkpoints => {
174174
let finalBrks = [];

0 commit comments

Comments
 (0)