From d4e6ee1e224bd6b7fb95e9017f56821418051bef Mon Sep 17 00:00:00 2001 From: Haneef Mohammed Date: Thu, 31 Aug 2023 08:08:53 -0700 Subject: [PATCH] save runtime and don't query gdb for stack depth --- CHANGELOG.md | 2 +- package.json | 2 +- src/backend/mi2/mi2.ts | 4 ++-- src/gdb.ts | 19 ++++++++++++++----- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ceb50aed..5d058390 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ # V1.12.1 * Fix for [#923: Local variables with same name between functions not tracking or updating context](https://github.com/Marus/cortex-debug/issues/923) * Fix for [#740: Missing RTT Timestamp in logfile](https://github.com/Marus/cortex-debug/issues/740) -* Tag VSCode generated debug lines with a timestamp when `showDevDebugTimestamps` is set to true +* Tag VSCode generated debug lines with a timestamp when `showDevDebugTimestamps` is set to true. Also, the timestamp has a delta from the previous message * For `symbolFIles`, you can simply specify a elf file or specify an object that has other options like offsets. If you do not need any special options, `symbolFiles` is now a simple array of elf-file-names # V1.12.0 diff --git a/package.json b/package.json index 1ebb8bdc..233daeed 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "version": "1.12.1-pre4", + "version": "1.12.1-pre5", "preview": false, "activationEvents": [ "onDebugResolve:cortex-debug", diff --git a/src/backend/mi2/mi2.ts b/src/backend/mi2/mi2.ts index 614105df..addfdfe6 100644 --- a/src/backend/mi2/mi2.ts +++ b/src/backend/mi2/mi2.ts @@ -809,12 +809,12 @@ export class MI2 extends EventEmitter implements IBackend { }); } - public getStackDepth(threadId: number): Thenable { + public getStackDepth(threadId: number, maxDepth: number = 1000): Thenable { if (trace) { this.log('stderr', 'getStackDepth'); } return new Promise((resolve, reject) => { - this.sendCommand(`stack-info-depth --thread ${threadId} 1000`).then((result) => { + this.sendCommand(`stack-info-depth --thread ${threadId} ${maxDepth}`).then((result) => { const depth = result.result('depth'); const ret = parseInt(depth); resolve(ret); diff --git a/src/gdb.ts b/src/gdb.ts index ee90e96b..e0d24f95 100755 --- a/src/gdb.ts +++ b/src/gdb.ts @@ -1626,6 +1626,7 @@ export class GDBDebugSession extends LoggingDebugSession { } protected timeStart = Date.now(); + protected timeLast = this.timeStart; protected wrapTimeStamp(str: string): string { if (this.args.showDevDebugOutput && this.args.showDevDebugTimestamps) { return this.wrapTimeStampRaw(str); @@ -1635,8 +1636,11 @@ export class GDBDebugSession extends LoggingDebugSession { } private wrapTimeStampRaw(str: string) { - const elapsed = Date.now() - this.timeStart; - const elapsedStr = elapsed.toString().padStart(10, '0'); + const now = Date.now(); + const elapsed = now - this.timeStart; + const delta = now - this.timeLast; + this.timeLast = now; + const elapsedStr = elapsed.toString().padStart(10, '0') + '+' + delta.toString().padStart(5, '0'); return elapsedStr + ': ' + str; } @@ -2464,7 +2468,11 @@ export class GDBDebugSession extends LoggingDebugSession { } return new Promise(async (resolve) => { try { - const maxDepth = await this.miDebugger.getStackDepth(args.threadId); + // GDB can take a long time if the stack is malformed to report depth. Instead, we just keep asking + // for chunks of stack trace until GDB runs out of them + const useMaxDepth = false; + const defMaxDepth = 1000; + const maxDepth = useMaxDepth ? await this.miDebugger.getStackDepth(args.threadId, defMaxDepth) : defMaxDepth; const highFrame = Math.min(maxDepth, args.startFrame + args.levels) - 1; const stack = await this.miDebugger.getStack(args.threadId, args.startFrame, highFrame); const ret: StackFrame[] = []; @@ -2478,7 +2486,7 @@ export class GDBDebugSession extends LoggingDebugSession { } response.body = { stackFrames: ret, - totalFrames: maxDepth + totalFrames: useMaxDepth ? maxDepth : undefined }; this.sendResponse(response); resolve(); @@ -2824,7 +2832,8 @@ export class GDBDebugSession extends LoggingDebugSession { const variables: DebugProtocol.Variable[] = []; let stack: Variable[]; try { - await this.miDebugger.sendCommand(`stack-select-frame --thread ${threadId} ${frameId}`); + // Don't think we need the following anymore after gdb 9.x + // await this.miDebugger.sendCommand(`stack-select-frame --thread ${threadId} ${frameId}`); stack = await this.miDebugger.getStackVariables(threadId, frameId); for (const variable of stack) { const varObjName = this.createStackVarName(variable.name, args.variablesReference);