Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added resume and suspend actions #1971

Merged

Conversation

JPinkney
Copy link
Contributor

Signed-off-by: jpinkney josh.pinkney@mail.utoronto.ca

This PR adds the resume and suspend actions for DAP.


export namespace DebugSessionContextMenu {
export const STOP = [...DEBUG_SESSION_CONTEXT_MENU, '1_stop'];
export const RESUME_ALL_THREADS = [...DEBUG_SESSION_CONTEXT_MENU, '3_resume_all_threads'];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These actions should be represented by buttons.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where should the buttons be displayed? Still here? Or just registered to the top debug menu? I figured the context menu should be a good place to have these because it covers the entire session.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Top debug menu will be ok for now.


export const SUSPEND_ALL_THREADS = {
id: 'debug.thread.suspend.all',
label: 'Suspend all threads'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just Suspend


export const RESUME_ALL_THREADS = {
id: 'debug.thread.resume.all',
label: 'Resume all threads'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just Resume

@@ -60,6 +90,8 @@ export class DebugCommandHandlers implements MenuContribution, CommandContributi
protected readonly debugSessionManager: DebugSessionManager;
@inject(DebugConfigurationManager)
protected readonly debugConfigurationManager: DebugConfigurationManager;
@inject(DebugThreadSelectionService)
protected readonly selectionService: DebugThreadSelectionService;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have to get rid of DebugThreadSelectionService

execute: () => {
const debugSession = this.debugSessionManager.getActiveDebugSession();
if (debugSession) {
debugSession.threads().then(response => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would move these code to DebugSession in function suspend(threadId?: number)
The same for resume command.;

debugSession.threads().then(response => {
const threads: DebugProtocol.Thread[] = response.body.threads;
// tslint:disable-next-line:forin
for (const thread in threads) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is better to use
for (const thread of threads)

return Promise.all(requests);
});
}
this.emit('changeStatus', threadId, false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

StoppedEvent is fired when thread is stopped. You don't have emit changeStatus event.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean I should resolve the promise and then emit the changeStatus event or that I should emit changeStatus event here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't emit any events here.
Just rely on DebugState https://github.com/theia-ide/theia/blob/vscode-debug-protocol/packages/debug/src/browser/debug-session.ts#L27

Let me know if you need something else.

@tolusha tolusha force-pushed the vscode-debug-protocol branch from faf8a36 to 0eff22d Compare June 4, 2018 11:56
@JPinkney JPinkney force-pushed the resume_and_suspend branch from 3734923 to 33fa65d Compare June 4, 2018 19:39
const requests = [];
for (const thread of threads) {
const currentThreadID = thread.id;
const pauseResponse = this.proceedRequest("pause", { currentThreadID });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currentThreadID -> threadId: thread.id

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happened if thread already stopped?

const requests = [];
for (const thread of threads) {
const currentThreadID = thread.id;
const continueResponse = this.proceedRequest("continue", { currentThreadID }) as Promise<DebugProtocol.ContinueResponse>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currentThreadID -> threadId: thread.id

@@ -23,10 +24,13 @@ import { injectable, inject } from "inversify";
export class DebugThreadsWidget extends VirtualWidget {
private _threads: DebugProtocol.Thread[] = [];
private _threadId?: number;
private _threadStatus: Map<number, boolean> = new Map();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Get rid of _threadStatus field. Rely on debugSession.debugSessionState

Copy link
Contributor Author

@JPinkney JPinkney Jun 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My only problems is that inside of the onContinuedEvent it assumes that to remove the thread you need to have the event but the debug adapter protocol suggests that the continued event is optional after a continue:

 /** Event message for 'continued' event type.
        The event indicates that the execution of the debuggee has continued.
        Please note: a debug adapter is not expected to send this event in response to a request that implies that execution continues, e.g. 'launch' or 'continue'.
        It is only necessary to send a ContinuedEvent if there was no previous request that implied this.
    */

If the onContinuedEvent state is not triggered then we won't accurately know the state of all the threads

Copy link
Contributor

@tolusha tolusha Jun 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see.
Let's emit continued event ourselves after continue response. In this case DebugSessionState will be consistent.

             const event: DebugProtocol.ContinuedEvent = {
                    type: 'event',
                    seq: -1,
                    event: 'continued',
                    body: {
                        threadId,
                        allThreadsContinued: false
                    }
                };
                this.proceedEvent(event);

}
}
},
isEnabled: () => !this.debugSession.debugSessionState.allThreadsContinued,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be enabled if at least one thread is stopped

}
}
},
isEnabled: () => !this.debugSession.debugSessionState.allThreadsStopped,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be enabled if at least one thread is run

@tolusha tolusha added the dap debug adapter protocol label Jun 5, 2018
return this.proceedRequest("pause", { threadId });
}

resume(threadId?: number): Promise<DebugProtocol.ContinueResponse> | Promise<DebugProtocol.ContinueResponse[]> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is better not to duplicate the code.
Let's do it in a simpler way:

    resume(threadId?: number): Promise<DebugProtocol.ContinueResponse | DebugProtocol.ContinueResponse[]> {
        if (threadId) {
            return this.doResume(threadId);
        } else {
            return this.threads().then(response => Promise.all(response.body.threads.map(thread => this.doResume(thread.id))));
        }
    }

    private doResume(threadId: number): Promise<DebugProtocol.ContinueResponse> {
        return this.proceedRequest("continue", { threadId: threadId }).then(response => {
            const event: DebugProtocol.ContinuedEvent = {
                type: 'event',
                seq: -1,
                event: 'continued',
                body: {
                    threadId: threadId,
                    allThreadsContinued: false
                }
            };
            this.proceedEvent(event);
            return response as DebugProtocol.ContinueResponse;
        });
    }

@@ -124,10 +125,56 @@ export class DebugSessionImpl extends EventEmitter implements DebugSession {
return this.proceedRequest("threads");
}

pause(threadId: number): Promise<DebugProtocol.PauseResponse> {
pause(threadId?: number): Promise<DebugProtocol.PauseResponse> | Promise<DebugProtocol.PauseResponse[]> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's do it in a simple way

  pause(threadId?: number): Promise<DebugProtocol.PauseResponse> | Promise<DebugProtocol.PauseResponse[]> {
        if (threadId) {
            return this.doPause(threadId);
        } else {
            return this.threads().then(response => Promise.all(response.body.threads.map(thread => this.doPause(thread.id))));
        }
    }

    doPause(threadId: number): Promise<DebugProtocol.PauseResponse> {
        return this.proceedRequest("pause", { threadId });
    }

@JPinkney JPinkney force-pushed the resume_and_suspend branch from 4d0d992 to 9e02925 Compare June 6, 2018 13:48
Signed-off-by: jpinkney <josh.pinkney@mail.utoronto.ca>
@JPinkney JPinkney force-pushed the resume_and_suspend branch from 9e02925 to 606b052 Compare June 6, 2018 13:51
@tolusha tolusha merged commit 2c8f5d3 into eclipse-theia:vscode-debug-protocol Jun 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dap debug adapter protocol
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants