Skip to content

Commit

Permalink
save runtime and don't query gdb for stack depth
Browse files Browse the repository at this point in the history
  • Loading branch information
haneefdm committed Aug 31, 2023
1 parent 400e6d5 commit d4e6ee1
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.12.1-pre4",
"version": "1.12.1-pre5",
"preview": false,
"activationEvents": [
"onDebugResolve:cortex-debug",
Expand Down
4 changes: 2 additions & 2 deletions src/backend/mi2/mi2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -809,12 +809,12 @@ export class MI2 extends EventEmitter implements IBackend {
});
}

public getStackDepth(threadId: number): Thenable<number> {
public getStackDepth(threadId: number, maxDepth: number = 1000): Thenable<number> {
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);
Expand Down
19 changes: 14 additions & 5 deletions src/gdb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}

Expand Down Expand Up @@ -2464,7 +2468,11 @@ export class GDBDebugSession extends LoggingDebugSession {
}
return new Promise<void>(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[] = [];
Expand All @@ -2478,7 +2486,7 @@ export class GDBDebugSession extends LoggingDebugSession {
}
response.body = {
stackFrames: ret,
totalFrames: maxDepth
totalFrames: useMaxDepth ? maxDepth : undefined
};
this.sendResponse(response);
resolve();
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit d4e6ee1

Please sign in to comment.