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

service/dap: add throw reason to exception info #2524

Merged
merged 9 commits into from
Jun 28, 2021

Conversation

suzmue
Copy link
Contributor

@suzmue suzmue commented Jun 2, 2021

We can get the throw reason by looking at the argument "s" in runtime.throw. This is not currently working in Go 1.16 or Go 1.17 (see golang/go#46425), but does work in Go 1.15 and Go 1.14

@suzmue
Copy link
Contributor Author

suzmue commented Jun 2, 2021

Screen shot of fatal throw reason:
Screen Shot 2021-06-02 at 5 57 55 PM

service/dap/server.go Outdated Show resolved Hide resolved
@@ -3335,6 +3334,9 @@ func TestFatalThrowBreakpoint(t *testing.T) {
if se.Body.Reason != "exception" || se.Body.Description != "Paused on fatal error" {
t.Errorf("\ngot %#v\nwant Reason=\"exception\" Description=\"Paused on fatal error\"", se)
}

// TODO(suzmue): Get the exception info for the thread and check the description
// includes "all goroutines are asleep - deadlock!".
Copy link
Member

Choose a reason for hiding this comment

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

You should be able to test this, just gate the assertion on the Go compiler being version 1.14 or 1.15 (which we still test via CI).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The actual issue that is breaking this test is that the deadlock is not associated with a goroutine ID, so we can't request the exception info. This needs to be fixed too, but makes sense to do separately because we will likely want to add the thread that is running to display the stack trace etc.

Copy link
Collaborator

Choose a reason for hiding this comment

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

What about _fixtures/fatalerror.go? Does that one result in a selected goroutine, so you have an id linked to a description that you can check?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't see that fixture. I could add a fixture to do a concurrent map read / write and I could test it that way.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Huh! That's because it was in my local client. I was going to add it at some point, but never did. This is easier than concurrent map operations:

func main() {
    var f func()
    go f()
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added the fixture and the test

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sorry again for pointing to something that only I had :) Thank you for adding the test.

About the deadlock case with no thread id. I filed an issue against vscode a while back for displaying stopped reason even with no thread id: microsoft/vscode#124532. They seem to be taking it seriously. Can we think of a related way to associate exception info with a stop that has no thread id?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The exception info is shown in the source code, so if its not associated with a thread with a stack trace, I think there would need to be a separate UI for it.

service/dap/server.go Show resolved Hide resolved
@@ -3335,6 +3334,9 @@ func TestFatalThrowBreakpoint(t *testing.T) {
if se.Body.Reason != "exception" || se.Body.Description != "Paused on fatal error" {
t.Errorf("\ngot %#v\nwant Reason=\"exception\" Description=\"Paused on fatal error\"", se)
}

// TODO(suzmue): Get the exception info for the thread and check the description
// includes "all goroutines are asleep - deadlock!".
Copy link
Collaborator

Choose a reason for hiding this comment

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

What about _fixtures/fatalerror.go? Does that one result in a selected goroutine, so you have an id linked to a description that you can check?

service/dap/server.go Outdated Show resolved Hide resolved
@aarzilli
Copy link
Member

See test failures.

@@ -3335,6 +3334,9 @@ func TestFatalThrowBreakpoint(t *testing.T) {
if se.Body.Reason != "exception" || se.Body.Description != "Paused on fatal error" {
t.Errorf("\ngot %#v\nwant Reason=\"exception\" Description=\"Paused on fatal error\"", se)
}

// TODO(suzmue): Get the exception info for the thread and check the description
// includes "all goroutines are asleep - deadlock!".
Copy link
Collaborator

Choose a reason for hiding this comment

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

Sorry again for pointing to something that only I had :) Thank you for adding the test.

About the deadlock case with no thread id. I filed an issue against vscode a while back for displaying stopped reason even with no thread id: microsoft/vscode#124532. They seem to be taking it seriously. Can we think of a related way to associate exception info with a stop that has no thread id?

@polinasok
Copy link
Collaborator

@suzmue Is this PR ready for @derekparker to take another look for final approval?

@polinasok
Copy link
Collaborator

DeepSource nag sounds reasonable. Probably a good idea to fix it.

@suzmue
Copy link
Contributor Author

suzmue commented Jun 23, 2021

@suzmue Is this PR ready for @derekparker to take another look for final approval?

Yes I think its ready.

DeepSource nag sounds reasonable. Probably a good idea to fix it.

This is unrelated to this change, so I will just send a quick follow up PR to fix it.

Copy link
Member

@derekparker derekparker left a comment

Choose a reason for hiding this comment

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

LGTM

@derekparker derekparker merged commit 1ebfc5c into go-delve:master Jun 28, 2021
@suzmue suzmue deleted the throw branch June 30, 2021 15:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants