1、实现消息日志功能
This commit is contained in:
parent
caa5512a25
commit
1408545364
|
@ -17,6 +17,9 @@ export function escape(str: string) {
|
|||
const nonOutput = /^(?:\d*|undefined)[\*\+\=]|[\~\@\&\^]/;
|
||||
const gdbMatch = /(?:\d*|undefined)\(gdb\)/;
|
||||
const numRegex = /\d+/;
|
||||
const logMsgMatch = /(^\$[0-9]*[\ ]*=[\ ]*)(.*)/;
|
||||
const logReplace = /{([^}]*)}/;
|
||||
const logReplaceTest = /{([^}]*)}/g;
|
||||
|
||||
function isPositiveInteger(str: string): boolean {
|
||||
const regex = /^[1-9]\d*$/;
|
||||
|
@ -75,7 +78,10 @@ export class MI2 extends EventEmitter implements IBackend {
|
|||
}
|
||||
this.cpuArch = os.arch();
|
||||
}
|
||||
|
||||
protected logMsg: Breakpoint[] = [];
|
||||
protected logMsgNum = 0;
|
||||
protected logMsgVar = "";
|
||||
protected logMsgRplNum = 0;
|
||||
load(cwd: string, target: string, procArgs: string, separateConsole: string): Thenable<any> {
|
||||
if (!path.isAbsolute(target))
|
||||
target = path.join(cwd, target);
|
||||
|
@ -381,10 +387,27 @@ export class MI2 extends EventEmitter implements IBackend {
|
|||
if (parsed.outOfBandRecord) {
|
||||
parsed.outOfBandRecord.forEach(record => {
|
||||
if (record.isStream) {
|
||||
if ((record.type === 'console') && (this.needOutput[this.nextTokenComing] !== undefined)) {
|
||||
// if ((record.type === 'console') && (this.needOutput[this.nextTokenComing] !== undefined)) { //判断undefined有什么用?
|
||||
if ((record.type === 'console')) {
|
||||
this.needOutput[this.nextTokenComing] += record.content;
|
||||
if(record.content.startsWith("$")){
|
||||
let content = record.content;
|
||||
const variableMatch = logMsgMatch.exec(content)
|
||||
let value = content.substr(variableMatch[1].length).trim();
|
||||
|
||||
const result = this.logMsgVar.replace(logReplace, value);
|
||||
this.logMsgRplNum--;
|
||||
this.logMsgVar = result;
|
||||
if(this.logMsgRplNum == 0){
|
||||
this.log("console", "Log Message:" + this.logMsgVar);
|
||||
}
|
||||
}else if(record.content.startsWith("No symbol")){
|
||||
// this.log("log", "GDB -> App6: +++++++++:" + this.logMsgNum + ":" + record.content + ":" + this.logMsgVar);
|
||||
}
|
||||
} else {
|
||||
this.log(record.type, record.content);
|
||||
if(record.content.startsWith("No symbol")){
|
||||
this.log(record.type, record.content);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (record.type == "exec") {
|
||||
|
@ -418,6 +441,18 @@ export class MI2 extends EventEmitter implements IBackend {
|
|||
case "breakpoint-hit,function-finished":
|
||||
case "breakpoint-hit":
|
||||
this.emit("breakpoint", parsed);
|
||||
// this.log("log", "GDB -> App1: " + JSON.stringify(parsed));
|
||||
this.logMsg.forEach((brk, index)=>{
|
||||
if(parsed.outOfBandRecord[0].output[0][1]=="breakpoint-hit" && parsed.outOfBandRecord[0].output[2][1] == brk.id){
|
||||
// this.log("log", "GDB -> App11: " + parsed.outOfBandRecord[0].output[2][1] + ":" + brk?.logMessage);
|
||||
this.logMsgNum = brk.id;
|
||||
this.logMsgVar = brk?.logMessage;
|
||||
|
||||
const matches = this.logMsgVar.match(logReplaceTest);
|
||||
const count = matches ? matches.length : 0;
|
||||
this.logMsgRplNum = count;
|
||||
}
|
||||
});
|
||||
break;
|
||||
case "watchpoint-trigger":
|
||||
case "read-watchpoint-trigger":
|
||||
|
@ -635,10 +670,30 @@ export class MI2 extends EventEmitter implements IBackend {
|
|||
}
|
||||
|
||||
setLogPoint(bkptNum, command): Thenable<any> {
|
||||
if (trace)
|
||||
this.log("stderr", "setLogoPoint");
|
||||
command = "printf \"log msg:%d\\n\", i";
|
||||
return this.sendCommand("break-commands " + bkptNum + " " + command);
|
||||
this.log("stderr", `setLogoPoint : ` + command);
|
||||
const regex = /{([a-z0-9A-Z-_\.\>\&\*]*)}/gm;
|
||||
|
||||
// Alternative syntax using RegExp constructor
|
||||
// const regex = new RegExp('{([a-z0-9A-Z-_\\*]*)}', 'gm')
|
||||
|
||||
let m;
|
||||
let commands = "";
|
||||
|
||||
while ((m = regex.exec(command)) !== null) {
|
||||
// This is necessary to avoid infinite loops with zero-width matches
|
||||
if (m.index === regex.lastIndex) {
|
||||
regex.lastIndex++;
|
||||
}
|
||||
|
||||
// The result can be accessed through the `m`-variable.
|
||||
m.forEach((match, groupIndex) => {
|
||||
if(groupIndex==1){
|
||||
commands += "\"print " + match + "\" ";
|
||||
}
|
||||
});
|
||||
}
|
||||
commands += "\"continue\""
|
||||
return this.sendCommand("break-commands " + bkptNum + " " + commands);
|
||||
}
|
||||
|
||||
setEntryBreakPoint(entryPoint: string): Thenable<any> {
|
||||
|
@ -676,9 +731,7 @@ export class MI2 extends EventEmitter implements IBackend {
|
|||
location += '"' + escape(breakpoint.file) + ":" + breakpoint.line + '"';
|
||||
if (breakpoint.logMessage) {
|
||||
//do send logmsg command;
|
||||
this.log("stderr", "logmsg:" + breakpoint.logMessage);
|
||||
// -break-commands 1 "printf \"log msg:%d\\n\", i" "continue"
|
||||
//this.sendCommand(" -break-commands 1 "printf \"log msg:%d\\n\", i" "continue" ")
|
||||
// this.log("info", "logmsg:" + breakpoint.logMessage);
|
||||
}
|
||||
|
||||
this.sendCommand("break-insert -f " + location).then((result) => {
|
||||
|
@ -690,10 +743,12 @@ export class MI2 extends EventEmitter implements IBackend {
|
|||
raw: breakpoint.raw,
|
||||
line: parseInt(result.result("bkpt.line")),
|
||||
condition: breakpoint.condition,
|
||||
logMessage: breakpoint?.logMessage,
|
||||
message: undefined,
|
||||
verified: undefined
|
||||
};
|
||||
if (breakpoint.condition) {
|
||||
this.log("stderr", "setBreakPointCondition:" + breakpoint.condition);
|
||||
this.setBreakPointCondition(bkptNum, breakpoint.condition).then((result) => {
|
||||
if (result.resultRecords.resultClass == "done") {
|
||||
this.breakpoints.set(newBrk, bkptNum);
|
||||
|
@ -709,7 +764,11 @@ export class MI2 extends EventEmitter implements IBackend {
|
|||
else if (breakpoint.logMessage) {
|
||||
this.setLogPoint(bkptNum, breakpoint.logMessage).then((result) => {
|
||||
if (result.resultRecords.resultClass == "done") {
|
||||
breakpoint.id = newBrk.id;
|
||||
// this.log("stderr", "setLogPoint+:" + breakpoint.id+ ":" +breakpoint?.file + ":" + breakpoint?.line +":" + breakpoint.logMessage);
|
||||
this.breakpoints.set(newBrk, bkptNum);
|
||||
this.logMsg.push(breakpoint);
|
||||
|
||||
resolve([true, newBrk]);
|
||||
} else {
|
||||
resolve([false, undefined]);
|
||||
|
|
Loading…
Reference in New Issue