Skip to content

Commit

Permalink
Lazily update frames of all threads in all-stop mode
Browse files Browse the repository at this point in the history
When a breakpoint occurs in a thread in all-stop mode, all other
threads have outdated/missing stackframes which means no variables
show up and can be inspected. This fixes the issue by marking each
thread as potentially having "dirty" frames: frames that need to be
re-fetched when the user selects them.

Signed-off-by: Samuel Frylmark <samuel.frylmark@ericsson.com>
  • Loading branch information
sfrylmark committed Jan 9, 2020
1 parent c8b8854 commit 1ae1e10
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
25 changes: 18 additions & 7 deletions packages/debug/src/browser/debug-session.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export class DebugSession implements CompositeTreeElement {
}),
this.on('stopped', async ({ body }) => {
await this.updateThreads(body);
await this.updateFrames();
await this.updateFrames(body);
}),
this.on('thread', ({ body: { reason, threadId } }) => {
if (reason === 'started') {
Expand Down Expand Up @@ -221,6 +221,9 @@ export class DebugSession implements CompositeTreeElement {
this.fireDidChange();
if (thread) {
this.toDisposeOnCurrentThread.push(thread.onDidChanged(() => this.fireDidChange()));
if (thread.framesDirty) {
thread.fetchFrames();
}
}
}

Expand Down Expand Up @@ -456,16 +459,24 @@ export class DebugSession implements CompositeTreeElement {
|| this._threads.values().next().value;
}

protected async updateFrames(): Promise<void> {
const thread = this._currentThread;
if (!thread || thread.frameCount) {
protected async updateFrames(stoppedDetails?: StoppedDetails): Promise<void> {
if (stoppedDetails && stoppedDetails.allThreadsStopped) {
for (const thread of this.threads) {
// Mark all thread as needing a frame reload whenever the user opens it.
thread.framesDirty = true;
}
}

// Load current thread immediately.
const currentThread = this._currentThread;
if (!currentThread || currentThread.frameCount) {
return;
}
if (this.capabilities.supportsDelayedStackTraceLoading) {
await thread.fetchFrames(1);
await thread.fetchFrames(19);
await currentThread.fetchFrames(1);
await currentThread.fetchFrames(19);
} else {
await thread.fetchFrames();
await currentThread.fetchFrames();
}
}

Expand Down
11 changes: 11 additions & 0 deletions packages/debug/src/browser/model/debug-thread.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export class DebugThread extends DebugThreadData implements TreeElement {
}

protected _currentFrame: DebugStackFrame | undefined;

get currentFrame(): DebugStackFrame | undefined {
return this._currentFrame;
}
Expand All @@ -61,6 +62,15 @@ export class DebugThread extends DebugThreadData implements TreeElement {
this.onDidChangedEmitter.fire(undefined);
}

protected _framesDirty: boolean = false;

get framesDirty(): boolean {
return this._framesDirty;
}
set framesDirty(framesDirty: boolean) {
this._framesDirty = framesDirty;
}

get stopped(): boolean {
return !!this.stoppedDetails;
}
Expand Down Expand Up @@ -141,6 +151,7 @@ export class DebugThread extends DebugThreadData implements TreeElement {

protected pendingFetch = Promise.resolve<DebugStackFrame[]>([]);
async fetchFrames(levels: number = 20): Promise<DebugStackFrame[]> {
this.framesDirty = false;
return this.pendingFetch = this.pendingFetch.then(async () => {
try {
const start = this.frameCount;
Expand Down

0 comments on commit 1ae1e10

Please sign in to comment.