gopls/internal/lsp/cache: in tests, show all stacks during analyzer crash

We recently started using bug.Errorf to report analyzer crashes,
causing tests to fail sporadically. Unfortunately the log included
only the "panicked" message but not the relevant stack of the panic
or of the other goroutines, giving limited evidence on which to
investigate the underlying cause, suspected to be in package loading,
not the analyzer itself.

This change causes such crashes to display all stacks so that we
can gather more evidence over the next few days before we suppress
the crashes again.

Updates golang/go#54762
Updates golang/go#56035

Change-Id: I2d29e05b5910540918816e695b458463a05f94d9
Reviewed-on: https://go-review.googlesource.com/c/tools/+/439116
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Alan Donovan <adonovan@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
diff --git a/gopls/internal/lsp/cache/analysis.go b/gopls/internal/lsp/cache/analysis.go
index e7f2d41..ffd1405 100644
--- a/gopls/internal/lsp/cache/analysis.go
+++ b/gopls/internal/lsp/cache/analysis.go
@@ -361,19 +361,20 @@
 	var result interface{}
 	var err error
 	func() {
-		// Set this flag temporarily when debugging crashes.
-		// See https://github.com/golang/go/issues/54762.
-		const norecover = false
-		if norecover {
-			debug.SetTraceback("all") // show all goroutines
-		} else {
-			defer func() {
-				if r := recover(); r != nil {
-					// Use bug.Errorf so that we detect panics during testing.
-					err = bug.Errorf("analysis %s for package %s panicked: %v", analyzer.Name, pkg.PkgPath(), r)
+		defer func() {
+			if r := recover(); r != nil {
+				// An Analyzer crashed. This is often merely a symptom
+				// of a problem in package loading.
+				if bug.PanicOnBugs {
+					// During testing, crash. See issues 54762, 56035.
+					debug.SetTraceback("all") // show all goroutines
+					panic(r)
+				} else {
+					// In production, suppress the panic and press on.
+					err = fmt.Errorf("analysis %s for package %s panicked: %v", analyzer.Name, pkg.PkgPath(), r)
 				}
-			}()
-		}
+			}
+		}()
 		result, err = pass.Analyzer.Run(pass)
 	}()
 	if err != nil {