1.解决变量设置失败问题;

2.解决命中次数断点bug;
This commit is contained in:
xuhong 2023-09-15 15:28:01 +08:00
parent 6f350c632e
commit 29d4b36587
5 changed files with 49 additions and 5 deletions

View File

@ -1,3 +1,7 @@
# 0.1.7
- fix set variable fail issue;
- fix hitCount breakpoint does work bugs;
# 0.1.6
- modify readme;

View File

@ -9,6 +9,7 @@ export interface Breakpoint {
raw?: string;
condition: string;
countCondition?: string;
logMessage?: string;
}
export interface OurInstructionBreakpoint extends DebugProtocol.InstructionBreakpoint {

View File

@ -18,6 +18,11 @@ const nonOutput = /^(?:\d*|undefined)[\*\+\=]|[\~\@\&\^]/;
const gdbMatch = /(?:\d*|undefined)\(gdb\)/;
const numRegex = /\d+/;
function isPositiveInteger(str: string): boolean {
const regex = /^[1-9]\d*$/;
return regex.test(str);
}
export interface ReadMemResults {
startAddress: string;
endAddress: string;
@ -606,6 +611,13 @@ export class MI2 extends EventEmitter implements IBackend {
return this.sendCommand("break-condition " + bkptNum + " " + condition);
}
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);
}
setEntryBreakPoint(entryPoint: string): Thenable<any> {
return this.sendCommand("break-insert -t -f " + entryPoint);
}
@ -621,18 +633,31 @@ export class MI2 extends EventEmitter implements IBackend {
if (breakpoint.countCondition[0] == ">")
location += "-i " + numRegex.exec(breakpoint.countCondition.substr(1))[0] + " ";
else {
if(!isPositiveInteger(breakpoint.countCondition)) {
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");
resolve([false, undefined]);
return;
}
const match = numRegex.exec(breakpoint.countCondition)[0];
if (match.length != breakpoint.countCondition.length) {
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");
location += "-t ";
} else if (parseInt(match) != 0)
location += "-t -i " + parseInt(match) + " ";
} else if (parseInt(match) != 0) {
location += "-t -i " + (parseInt(match) - 1) + " ";
}
}
}
if (breakpoint.raw)
location += '"' + escape(breakpoint.raw) + '"';
else
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.sendCommand("break-insert -f " + location).then((result) => {
if (result.resultRecords.resultClass == "done") {
const bkptNum = parseInt(result.result("bkpt.number"));
@ -651,7 +676,18 @@ export class MI2 extends EventEmitter implements IBackend {
resolve([false, undefined]);
}
}, reject);
}
else if(breakpoint.logMessage) {
this.setLogPoint(bkptNum, breakpoint.logMessage).then((result) => {
if (result.resultRecords.resultClass == "done") {
this.breakpoints.set(newBrk, bkptNum);
resolve([true, newBrk]);
} else {
resolve([false, undefined]);
}
}, reject);
}
else {
this.breakpoints.set(newBrk, bkptNum);
resolve([true, newBrk]);
}

View File

@ -53,6 +53,8 @@ export class GDBDebugSession extends MI2DebugSession {
response.body.supportsFunctionBreakpoints = true;
response.body.supportsEvaluateForHovers = true;
response.body.supportsSetVariable = true;
response.body.supportsLogPoints = true;
if(process.arch=="arm64")
{
response.body.supportsStepBack = true;

View File

@ -199,7 +199,7 @@ export class MI2DebugSession extends DebugSession {
this.sendErrorResponse(response, 20, "Could not modify string variable");
return;
}
let name;
let name=args.name;
let id;
if (args.variablesReference >= VAR_HANDLES_START) {
const pointerCombineChar = ".";
@ -260,8 +260,9 @@ export class MI2DebugSession extends DebugSession {
}
}
}
const all = args.breakpoints.map(brk => {
return this.miDebugger.addBreakPoint({ file: path, line: brk.line, condition: brk.condition, countCondition: brk.hitCondition });
return this.miDebugger.addBreakPoint({ file: path, line: brk.line, condition: brk.condition, countCondition: brk.hitCondition, logMessage: brk.logMessage });
});
Promise.all(all).then(brkpoints => {
const finalBrks = [];