Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Add stacktrace dump and better error messages on EXC_BAD_ACCESS panics #2904

Merged
merged 6 commits into from
Mar 20, 2020

Conversation

lggomez
Copy link
Contributor

@lggomez lggomez commented Nov 14, 2019

Fixes #1903

@lggomez
Copy link
Contributor Author

lggomez commented Nov 14, 2019

@ramya-rao-a PTAL

@lggomez
Copy link
Contributor Author

lggomez commented Nov 14, 2019

cc @jhendrixMSFT

@ramya-rao-a
Copy link
Contributor

@jhendrixMSFT Can you take another look here?

// Get current goroutine
// Debugger may be stopped at this point but we still can (and need) to obtain state and stacktrace
let goroutineId = 0;
this.delve.call<DebuggerState | CommandOut>('State', [{ NonBlocking: true }], (err, out) => {
Copy link
Member

Choose a reason for hiding this comment

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

I tested this out on macOS, unfortunately dlv doesn't report the correct go routine in this case (I see the same behavior using vscode and dlv) so I think we can remove this. What it means though is if the panic is on a go routine other than zero you won't get the correct stack trace. If we still want to include the stack trace then I think we should add a message indicating that it might not be correct. :(

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 would leave it just for diagnose purposes with a warning message saying that the stacktrace might differ from the expected goroutine

I tested this out on macOS, unfortunately dlv doesn't report the correct go routine in this case (I see the same behavior using vscode and dlv)

This is probably related to the original dlv issue, or maybe it is a different issue that might be actionable, nevertheless, that is still something that should be discussed upstream, unfortunately

@lggomez lggomez force-pushed the fix_1903 branch 3 times, most recently from cbcfa9c to cd6485b Compare December 16, 2019 23:54
logError(message + ' - ' + errorMessage);

if (err.toString() === 'bad access') {
logError('WARNING: this stack might not be from the expected active goroutine');
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 think this might suffice for now, what do you think @jhendrixMSFT?

Copy link
Member

Choose a reason for hiding this comment

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

I would reword this to "...the faulting goroutine".
I also wonder if it would just be better to omit the stack trace entirely given that it might not be accurate (we could add it later if there's sufficient feedback). @ramya-rao-a do you have an opinion about this?


logError(message + ' - ' + errorMessage);

if (err.toString() === 'bad access') {
Copy link
Contributor

Choose a reason for hiding this comment

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

The same if check exists a few lines above, so consider moving this log statement to the previous if block

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 like the duplicate if either but I did it so the warning comes right before the stacktrace and not before the errorMessage:

Current:
Screen Shot 2019-12-17 at 11 51 25

Simplified:
Screen Shot 2019-12-17 at 11 49 13

I don't think it is that much of an issue so if you're fine with that I can go on with the single if version

Copy link
Contributor

Choose a reason for hiding this comment

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

Understood, in that case let's keep the current order

});

// Get goroutine stacktrace
const stackTraceIn = { id: goroutineId, depth: this.delve.stackTraceDepth };
Copy link
Contributor

Choose a reason for hiding this comment

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

The goroutineId here will always be 0 as this code path is not inside the callback provided to the delve call a few lines above.

Copy link
Contributor

@ramya-rao-a ramya-rao-a Dec 19, 2019

Choose a reason for hiding this comment

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

You can try

try {
  const stateCallResult: DebuggerState | CommandOut = await this.delve.callPromise('State', [{ NonBlocking: true }]);
  goroutineId = this.delve.isApiV1 ? (<CommandOut>stateCallResult).State.currentGoroutine.id : (<DebuggerState>stateCallResult).currentGoroutine.id;
} catch (error) {
	// log error?
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jhendrixMSFT @ramya-rao-a I think I solved the issue of state returning always (?) zero. The gist of the debugger state is that there seems to be no currentGoroutine in this scenario so we have to default to the currentThread goroutineId:

This is the apicall response:

{
	"Running": false,
	"currentThread": {
		"id": 5142829,
		"pc": 17138024,
		"file": "/Users/lgomez/DEV/go/test_1903/main.go",
		"line": 5,
		"function": {
			"name": "main.oops",
			"value": 17138000,
			"type": 0,
			"goType": 0,
			"optimized": false
		},
		"goroutineID": 1,
		"ReturnValues": null
	},
	"Threads": [
		{
			"id": 5142829,
			"pc": 17138024,
			"file": "/Users/lgomez/DEV/go/test_1903/main.go",
			"line": 5,
			"function": {
				"name": "main.oops",
				"value": 17138000,
				"type": 0,
				"goType": 0,
				"optimized": false
			},
			"goroutineID": 1,
			"ReturnValues": null
		},
		{
			"id": 5142873,
			"pc": 140734907268914,
			"file": "",
			"line": 0,
			"goroutineID": 0,
			"ReturnValues": null
		},
		{
			"id": 5142874,
			"pc": 140734907267178,
			"file": "",
			"line": 0,
			"goroutineID": 0,
			"ReturnValues": null
		},
		{
			"id": 5142875,
			"pc": 140734907267178,
			"file": "",
			"line": 0,
			"goroutineID": 0,
			"ReturnValues": null
		},
		{
			"id": 5142876,
			"pc": 140734907267178,
			"file": "",
			"line": 0,
			"goroutineID": 0,
			"ReturnValues": null
		}
	],
	"NextInProgress": false,
	"exited": false,
	"exitStatus": 0,
	"When": ""
}

And this is the handled panic with the updated behavior:
Screen Shot 2019-12-19 at 17 59 35

This is on mac, I´ll try this at home later to see if the response is different on linux

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'm not getting the currentGoroutine on linux either, i'm trying other goroutine examples and i'm even reproducing #2563 while at it so I'm willing to say this is our best bet for now. We're supposed to be getting this field but we can follow up on that issue since it is better suited for its root cause

@ramya-rao-a
Copy link
Contributor

cc @quoctruong to try out the changes here

@jhendrixMSFT
Copy link
Member

@ramya-rao-a any other concerns?

@lggomez lggomez force-pushed the fix_1903 branch 2 times, most recently from c74b73d to 46fe64c Compare February 17, 2020 03:32
@lggomezml
Copy link

@andrewchoi5 I decided to reset and rebase my changes to current master since there were many merge conflicts to solve (the branch was a bit stale and several changes entered into the debug adapter), would you care to check again please?

@ramya-rao-a ramya-rao-a merged commit 00c318b into microsoft:master Mar 20, 2020
hyangah added a commit to hyangah/vscode-go-old that referenced this pull request Mar 20, 2020
* master:
  goLanguageServer: set completion follow up command from middleware (microsoft#3084)
  Add stacktrace dump and better error messages on EXC_BAD_ACCESS panics (microsoft#2904)
  Address mismatch on path separators in debug config (microsoft#2010) (microsoft#3108)
  Include the link to release note/package overview in the update prompt, and update gopls default version (microsoft#3041)
  bug_report.md: Fix "architecture" typo. (microsoft#3095)
  telemetry.ts: send telemetry only if aiKey is not an empty  string(microsoft#3091)
hyangah added a commit to hyangah/vscode-go-old that referenced this pull request Mar 20, 2020
…sync

microsoft/vscode-go@d53b1b3

* 'master' of https://github.com/microsoft/vscode-go:
  goLanguageServer: set completion follow up command from middleware (microsoft#3084)
  Add stacktrace dump and better error messages on EXC_BAD_ACCESS panics (microsoft#2904)
  Address mismatch on path separators in debug config (microsoft#2010) (microsoft#3108)
gopherbot referenced this pull request in golang/vscode-go Mar 20, 2020
Merge branch 'master' of https://github.com/microsoft/vscode-go@d53b1b3

* 'master' of https://github.com/microsoft/vscode-go:
  goLanguageServer: set completion follow up command from middleware (microsoft#3084)
  Add stacktrace dump and better error messages on EXC_BAD_ACCESS panics (microsoft#2904)
  Address mismatch on path separators in debug config (microsoft#2010) (microsoft#3108)

Created by

`git pull --no-ff --log upstream master`

Change-Id: Id38768f3ec1bd01fa81325978f51f314fc1c08cb
GitHub-Last-Rev: 3a8de3f
GitHub-Pull-Request: #17
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/224240
Reviewed-by: Rebecca Stambler <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Replace "Failed to continue - bad access" with more informative error message and stack trace.
5 participants