diff --git a/CHANGELOG.md b/CHANGELOG.md index dcc61bb..943eee9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.1.7 +- fix set variable fail issue; +- fix hitCount breakpoint does work bugs; + # 0.1.6 - modify readme; diff --git a/src/backend/backend.ts b/src/backend/backend.ts index ebb579a..5e88937 100644 --- a/src/backend/backend.ts +++ b/src/backend/backend.ts @@ -9,6 +9,7 @@ export interface Breakpoint { raw?: string; condition: string; countCondition?: string; + logMessage?: string; } export interface OurInstructionBreakpoint extends DebugProtocol.InstructionBreakpoint { diff --git a/src/backend/mi2/mi2.ts b/src/backend/mi2/mi2.ts index 66eff15..9f98685 100644 --- a/src/backend/mi2/mi2.ts +++ b/src/backend/mi2/mi2.ts @@ -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 { + if (trace) + this.log("stderr", "setLogoPoint"); + command = "printf \"log msg:%d\\n\", i" ; + return this.sendCommand("break-commands " + bkptNum + " " + command); + } + setEntryBreakPoint(entryPoint: string): Thenable { 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 { + } + 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]); } diff --git a/src/gdb.ts b/src/gdb.ts index 40cc0c7..a1ecdfa 100644 --- a/src/gdb.ts +++ b/src/gdb.ts @@ -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; diff --git a/src/mibase.ts b/src/mibase.ts index bc66a9e..3449eaa 100644 --- a/src/mibase.ts +++ b/src/mibase.ts @@ -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 = [];