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

isRunning unreliable #325

Open
colin-grant-work opened this issue Mar 13, 2024 · 0 comments
Open

isRunning unreliable #325

colin-grant-work opened this issue Mar 13, 2024 · 0 comments

Comments

@colin-grant-work
Copy link
Contributor

colin-grant-work commented Mar 13, 2024

The GDBDebugSession maintains a state isRunning and guards various actions depending on that value. However, a synchronous check of that value isn't guaranteed to accurately reflect GDB's state by the time it tries to process an MI command: some other part of the adapter code could have issued a continue command without GDB having yet emitted the event indicating that it has continued.

I'd suggest that we implement something like a tryIfNotRunning method along the following lines:

    protected async tryIfNotRunning<T, U>(
        action: () => Promise<T>,
        defaultValue: U
    ): Promise<T | U> {
        if (this.isRunning) {
            return defaultValue;
        }
        try {
            return await action();
        } catch (err) {
            if (
                err instanceof Error &&
                err.message.includes('target is running')
            ) {
                return defaultValue;
            }
            throw err;
        }
    }

That would centralize the handling of the error that such and such a command can't be handled while the target is running. I bet we could clean up the types a bit, too, for ergonomics.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant