Skip to content

Commit 1695116

Browse files
HenryRiley0WebFreak001
authored andcommitted
add support to Log Message breakpoint
1 parent 1b9f13e commit 1695116

File tree

4 files changed

+86
-2
lines changed

4 files changed

+86
-2
lines changed

src/backend/backend.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ import { DebugProtocol } from "vscode-debugprotocol/lib/debugProtocol";
44
export type ValuesFormattingMode = "disabled" | "parseText" | "prettyPrinters";
55

66
export interface Breakpoint {
7+
id?:number;
78
file?: string;
89
line?: number;
910
raw?: string;
1011
condition: string;
1112
countCondition?: string;
13+
logMessage?: string;
1214
}
1315

1416
export interface Thread {

src/backend/mi2/mi2.ts

Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,50 @@ function couldBeOutput(line: string) {
2424

2525
const trace = false;
2626

27+
class LogMessage {
28+
protected logMsgVar = "";
29+
protected logMsgVarProcess = "";
30+
protected logMsgRplNum = 0;
31+
protected logMsgRplItem: string[] = [];
32+
protected logMsgMatch = /(^\$[0-9]*[\ ]*=[\ ]*)(.*)/;
33+
protected logReplaceTest = /{([^}]*)}/g;
34+
public logMsgBrkList: Breakpoint[] = [];
35+
36+
logMsgOutput(record){
37+
if ((record.type === 'console')) {
38+
if(record.content.startsWith("$")){
39+
const content = record.content;
40+
const variableMatch = this.logMsgMatch.exec(content);
41+
if (variableMatch) {
42+
const value = content.substr(variableMatch[1].length).trim();
43+
this.logMsgRplItem.push(value);
44+
this.logMsgRplNum--;
45+
if(this.logMsgRplNum == 0){
46+
for(let i = 0; i < this.logMsgRplItem.length; i++){
47+
this.logMsgVarProcess = this.logMsgVarProcess.replace("placeHolderForVariable", this.logMsgRplItem[i]);
48+
}
49+
return "Log Message:" + this.logMsgVarProcess;
50+
}
51+
}
52+
}
53+
return null
54+
}
55+
}
56+
57+
logMsgProcess(parsed){
58+
this.logMsgBrkList.forEach((brk)=>{
59+
if(parsed.outOfBandRecord[0].output[0][1] == "breakpoint-hit" && parsed.outOfBandRecord[0].output[2][1] == brk.id){
60+
this.logMsgVar = brk?.logMessage;
61+
const matches = this.logMsgVar.match(this.logReplaceTest);
62+
const count = matches ? matches.length : 0;
63+
this.logMsgRplNum = count;
64+
this.logMsgVarProcess = this.logMsgVar.replace(this.logReplaceTest, "placeHolderForVariable");
65+
this.logMsgRplItem = [];
66+
}
67+
});
68+
}
69+
}
70+
2771
export class MI2 extends EventEmitter implements IBackend {
2872
constructor(public application: string, public preargs: string[], public extraargs: string[], procEnv: any, public extraCommands: string[] = []) {
2973
super();
@@ -47,6 +91,7 @@ export class MI2 extends EventEmitter implements IBackend {
4791
this.procEnv = env;
4892
}
4993
}
94+
protected logMessage:LogMessage = new LogMessage;
5095

5196
load(cwd: string, target: string, procArgs: string, separateConsole: string, autorun: string[]): Thenable<any> {
5297
if (!path.isAbsolute(target))
@@ -354,6 +399,10 @@ export class MI2 extends EventEmitter implements IBackend {
354399
parsed.outOfBandRecord.forEach(record => {
355400
if (record.isStream) {
356401
this.log(record.type, record.content);
402+
const logOutput = this.logMessage.logMsgOutput(record);
403+
if(logOutput){
404+
this.log("console", logOutput);
405+
}
357406
} else {
358407
if (record.type == "exec") {
359408
this.emit("exec-async-output", parsed);
@@ -373,6 +422,7 @@ export class MI2 extends EventEmitter implements IBackend {
373422
switch (reason) {
374423
case "breakpoint-hit":
375424
this.emit("breakpoint", parsed);
425+
this.logMessage.logMsgProcess(parsed);
376426
break;
377427
case "watchpoint-trigger":
378428
case "read-watchpoint-trigger":
@@ -576,6 +626,23 @@ export class MI2 extends EventEmitter implements IBackend {
576626
return this.sendCommand("break-condition " + bkptNum + " " + condition);
577627
}
578628

629+
setLogPoint(bkptNum, command): Thenable<any> {
630+
const regex = /{([a-z0-9A-Z-_\.\>\&\*\[\]]*)}/gm;
631+
let m:RegExpExecArray;
632+
let commands:string = "";
633+
634+
while ((m = regex.exec(command))) {
635+
if (m.index === regex.lastIndex) {
636+
regex.lastIndex++;
637+
}
638+
if (m[1]) {
639+
commands += `\"print ${m[1]}\" `;
640+
}
641+
}
642+
commands += "\"continue\"";
643+
return this.sendCommand("break-commands " + bkptNum + " " + commands);
644+
}
645+
579646
setEntryBreakPoint(entryPoint: string): Thenable<any> {
580647
return this.sendCommand("break-insert -t -f " + entryPoint);
581648
}
@@ -607,15 +674,29 @@ export class MI2 extends EventEmitter implements IBackend {
607674
if (result.resultRecords.resultClass == "done") {
608675
const bkptNum = parseInt(result.result("bkpt.number"));
609676
const newBrk = {
677+
id: bkptNum,
610678
file: breakpoint.file ? breakpoint.file : result.result("bkpt.file"),
611679
raw: breakpoint.raw,
612680
line: parseInt(result.result("bkpt.line")),
613-
condition: breakpoint.condition
681+
condition: breakpoint.condition,
682+
logMessage: breakpoint?.logMessage,
614683
};
615684
if (breakpoint.condition) {
616685
this.setBreakPointCondition(bkptNum, breakpoint.condition).then((result) => {
617686
if (result.resultRecords.resultClass == "done") {
618687
this.breakpoints.set(newBrk, bkptNum);
688+
resolve([true, newBrk]);
689+
} else {
690+
resolve([false, undefined]);
691+
}
692+
}, reject);
693+
} else if (breakpoint.logMessage) {
694+
this.setLogPoint(bkptNum, breakpoint.logMessage).then((result) => {
695+
if (result.resultRecords.resultClass == "done") {
696+
breakpoint.id = newBrk.id;
697+
this.breakpoints.set(newBrk, bkptNum);
698+
this.logMessage.logMsgBrkList.push(breakpoint);
699+
619700
resolve([true, newBrk]);
620701
} else {
621702
resolve([false, undefined]);

src/gdb.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class GDBDebugSession extends MI2DebugSession {
4949
response.body.supportsEvaluateForHovers = true;
5050
response.body.supportsSetVariable = true;
5151
response.body.supportsStepBack = true;
52+
response.body.supportsLogPoints = true;
5253
this.sendResponse(response);
5354
}
5455

src/mibase.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ export class MI2DebugSession extends DebugSession {
247247
}
248248
this.miDebugger.clearBreakPoints(path).then(() => {
249249
const all = args.breakpoints.map(brk => {
250-
return this.miDebugger.addBreakPoint({ file: path, line: brk.line, condition: brk.condition, countCondition: brk.hitCondition });
250+
return this.miDebugger.addBreakPoint({ file: path, line: brk.line, condition: brk.condition, countCondition: brk.hitCondition, logMessage: brk.logMessage });
251251
});
252252
Promise.all(all).then(brkpoints => {
253253
const finalBrks: DebugProtocol.Breakpoint[] = [];

0 commit comments

Comments
 (0)