Skip to content

Commit 21ac981

Browse files
committed
Updating live watch on stop and on initiation of debug session
1 parent 55c55a7 commit 21ac981

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

src/debug-session/gdbtarget-debug-session.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,12 @@ describe('GDBTargetDebugSession', () => {
7676
(vscode.debug.activeStackItem as unknown) = undefined;
7777
});
7878

79-
it('returns undefined if evaluating a global expression fails', async () => {
79+
it('returns a string if evaluating a global expression fails', async () => {
8080
// Only mock relevant properties, return value is body of EvaluateResponse
8181
const logDebugSpy = jest.spyOn(logger, 'debug');
8282
(debugSession.customRequest as jest.Mock).mockRejectedValueOnce(new Error('myError'));
8383
const result = await gdbTargetSession.evaluateGlobalExpression('myGlobalVariable');
84-
expect(result).toBeUndefined();
84+
expect(result).toBe('Error: could not evaluate expression');
8585
expect(debugSession.customRequest as jest.Mock).toHaveBeenCalledWith('evaluate', { expression: 'myGlobalVariable', frameId: 0, context: 'hover' });
8686
expect(logDebugSpy).toHaveBeenCalledWith('Session \'session-name\': Failed to evaluate global expression \'myGlobalVariable\' - \'myError\'');
8787
});

src/debug-session/gdbtarget-debug-session.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export class GDBTargetDebugSession {
5454
this._cbuildRunParsePromise = undefined;
5555
}
5656

57-
public async evaluateGlobalExpression(expression: string): Promise<string|undefined> {
57+
public async evaluateGlobalExpression(expression: string): Promise<string> {
5858
try {
5959
const frameId = (vscode.debug.activeStackItem as vscode.DebugStackFrame)?.frameId ?? 0;
6060
const args: DebugProtocol.EvaluateArguments = {
@@ -63,12 +63,12 @@ export class GDBTargetDebugSession {
6363
context: 'hover'
6464
};
6565
const response = await this.session.customRequest('evaluate', args) as DebugProtocol.EvaluateResponse['body'];
66-
return response.result.match(/\d+/) ? response.result : undefined;
66+
return response.result;
6767
} catch (error: unknown) {
6868
const errorMessage = (error as Error)?.message;
6969
logger.debug(`Session '${this.session.name}': Failed to evaluate global expression '${expression}' - '${errorMessage}'`);
70+
return errorMessage;
7071
}
71-
return undefined;
7272
}
7373

7474
public async readMemory(address: number, length = 4): Promise<ArrayBuffer|undefined> {

src/live-watch/live-watch.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,18 @@ export class LiveWatchTreeDataProvider implements vscode.TreeDataProvider<LiveWa
4747
this.addVSCodeCommands();
4848
const onDidChangeActiveDebugSession = tracker.onDidChangeActiveDebugSession((session) => {
4949
this.activeSession = session;
50+
this.refresh();
5051
this.continueEvaluate = false;
5152
});
5253
const onWillStartSession = tracker.onWillStartSession(session => this.handleOnWillStartSession(session));
54+
// Doing a refresh on stop to ensure we have the latest data
55+
const onStopped = tracker.onStopped(() => this.refresh());
56+
// Using this event because this is when the threadId is available for evaluations
57+
const onStackTrace = tracker.onDidChangeActiveStackItem(() => this.refresh());
5358
this._context.subscriptions.push(onDidChangeActiveDebugSession);
5459
this._context.subscriptions.push(onWillStartSession);
60+
this._context.subscriptions.push(onStopped);
61+
this._context.subscriptions.push(onStackTrace);
5562
}
5663

5764
handleOnWillStartSession(session: GDBTargetDebugSession): void {

0 commit comments

Comments
 (0)