src/debugAdapter: send terminated event when program exits

The change to only send stopped events for breakpoints (cl/253578)
had the side effect of not sending a terminated event when the program
stopped. This adds that event back in so the session can terminate
correctly.

Change-Id: I3e07b82b0b2edc774747e584f1bbab77141b46b6
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/259218
Trust: Suzy Mueller <suzmue@golang.org>
Trust: Hyang-Ah Hana Kim <hyangah@gmail.com>
Reviewed-by: Polina Sokolova <polina@google.com>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
diff --git a/src/debugAdapter/goDebug.ts b/src/debugAdapter/goDebug.ts
index 6dbe0c0..0054a12 100644
--- a/src/debugAdapter/goDebug.ts
+++ b/src/debugAdapter/goDebug.ts
@@ -2210,7 +2210,7 @@
 			// Check if the current thread was stopped on a breakpoint.
 			// Other stopping events (eg pause) create their own StoppedEvents,
 			// if necessary.
-			if (!!state.currentThread.breakPoint) {
+			if (!!state.currentThread && !!state.currentThread.breakPoint) {
 				const bp = state.currentThread.breakPoint;
 				if (bp.id === unrecoveredPanicID) {
 					// If the breakpoint is actually caused by a panic,
@@ -2223,6 +2223,9 @@
 				} else {
 					this.handleReenterDebug('breakpoint');
 				}
+			} else if (state.exited) {
+				// Notify the client if the program has exited.
+				this.handleReenterDebug('');
 			}
 		};