Skip to content

Commit d4e6ee1

Browse files
committed
save runtime and don't query gdb for stack depth
1 parent 400e6d5 commit d4e6ee1

File tree

4 files changed

+18
-9
lines changed

4 files changed

+18
-9
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# V1.12.1
33
* Fix for [#923: Local variables with same name between functions not tracking or updating context](https://github.com/Marus/cortex-debug/issues/923)
44
* Fix for [#740: Missing RTT Timestamp in logfile](https://github.com/Marus/cortex-debug/issues/740)
5-
* Tag VSCode generated debug lines with a timestamp when `showDevDebugTimestamps` is set to true
5+
* Tag VSCode generated debug lines with a timestamp when `showDevDebugTimestamps` is set to true. Also, the timestamp has a delta from the previous message
66
* 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
77

88
# V1.12.0

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "1.12.1-pre4",
2+
"version": "1.12.1-pre5",
33
"preview": false,
44
"activationEvents": [
55
"onDebugResolve:cortex-debug",

src/backend/mi2/mi2.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -809,12 +809,12 @@ export class MI2 extends EventEmitter implements IBackend {
809809
});
810810
}
811811

812-
public getStackDepth(threadId: number): Thenable<number> {
812+
public getStackDepth(threadId: number, maxDepth: number = 1000): Thenable<number> {
813813
if (trace) {
814814
this.log('stderr', 'getStackDepth');
815815
}
816816
return new Promise((resolve, reject) => {
817-
this.sendCommand(`stack-info-depth --thread ${threadId} 1000`).then((result) => {
817+
this.sendCommand(`stack-info-depth --thread ${threadId} ${maxDepth}`).then((result) => {
818818
const depth = result.result('depth');
819819
const ret = parseInt(depth);
820820
resolve(ret);

src/gdb.ts

+14-5
Original file line numberDiff line numberDiff line change
@@ -1626,6 +1626,7 @@ export class GDBDebugSession extends LoggingDebugSession {
16261626
}
16271627

16281628
protected timeStart = Date.now();
1629+
protected timeLast = this.timeStart;
16291630
protected wrapTimeStamp(str: string): string {
16301631
if (this.args.showDevDebugOutput && this.args.showDevDebugTimestamps) {
16311632
return this.wrapTimeStampRaw(str);
@@ -1635,8 +1636,11 @@ export class GDBDebugSession extends LoggingDebugSession {
16351636
}
16361637

16371638
private wrapTimeStampRaw(str: string) {
1638-
const elapsed = Date.now() - this.timeStart;
1639-
const elapsedStr = elapsed.toString().padStart(10, '0');
1639+
const now = Date.now();
1640+
const elapsed = now - this.timeStart;
1641+
const delta = now - this.timeLast;
1642+
this.timeLast = now;
1643+
const elapsedStr = elapsed.toString().padStart(10, '0') + '+' + delta.toString().padStart(5, '0');
16401644
return elapsedStr + ': ' + str;
16411645
}
16421646

@@ -2464,7 +2468,11 @@ export class GDBDebugSession extends LoggingDebugSession {
24642468
}
24652469
return new Promise<void>(async (resolve) => {
24662470
try {
2467-
const maxDepth = await this.miDebugger.getStackDepth(args.threadId);
2471+
// GDB can take a long time if the stack is malformed to report depth. Instead, we just keep asking
2472+
// for chunks of stack trace until GDB runs out of them
2473+
const useMaxDepth = false;
2474+
const defMaxDepth = 1000;
2475+
const maxDepth = useMaxDepth ? await this.miDebugger.getStackDepth(args.threadId, defMaxDepth) : defMaxDepth;
24682476
const highFrame = Math.min(maxDepth, args.startFrame + args.levels) - 1;
24692477
const stack = await this.miDebugger.getStack(args.threadId, args.startFrame, highFrame);
24702478
const ret: StackFrame[] = [];
@@ -2478,7 +2486,7 @@ export class GDBDebugSession extends LoggingDebugSession {
24782486
}
24792487
response.body = {
24802488
stackFrames: ret,
2481-
totalFrames: maxDepth
2489+
totalFrames: useMaxDepth ? maxDepth : undefined
24822490
};
24832491
this.sendResponse(response);
24842492
resolve();
@@ -2824,7 +2832,8 @@ export class GDBDebugSession extends LoggingDebugSession {
28242832
const variables: DebugProtocol.Variable[] = [];
28252833
let stack: Variable[];
28262834
try {
2827-
await this.miDebugger.sendCommand(`stack-select-frame --thread ${threadId} ${frameId}`);
2835+
// Don't think we need the following anymore after gdb 9.x
2836+
// await this.miDebugger.sendCommand(`stack-select-frame --thread ${threadId} ${frameId}`);
28282837
stack = await this.miDebugger.getStackVariables(threadId, frameId);
28292838
for (const variable of stack) {
28302839
const varObjName = this.createStackVarName(variable.name, args.variablesReference);

0 commit comments

Comments
 (0)