test/integration: log DAP trace when legacy adapter test fails

Recently the legacy adapter's disconnect tests became flaky.
This change enables tracing and reads the trace file written by
the legacy adapter. For delve DAP adapter, we always enabled
logging, so no behavior change is expected.

Change-Id: I0d0c563247cc3dcf6c9bbb49506651cefa2f0e70
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/348370
Trust: Hyang-Ah Hana Kim <hyangah@gmail.com>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
diff --git a/test/integration/goDebug.test.ts b/test/integration/goDebug.test.ts
index 5b1e500..a130b01 100644
--- a/test/integration/goDebug.test.ts
+++ b/test/integration/goDebug.test.ts
@@ -315,8 +315,11 @@
 
 	let dc: DebugClient;
 	let dlvDapAdapter: DelveDAPDebugAdapterOnSocket;
+	let dapTraced = false;
 
 	setup(async () => {
+		dapTraced = false;
+
 		if (isDlvDap) {
 			dc = new DebugClient('dlv', 'dap', 'go');
 			// dc.start will be called in initializeDebugConfig call,
@@ -345,6 +348,15 @@
 			}
 			d.dispose();
 		} else {
+			if (ctx.currentTest?.state === 'failed' && dapTraced) {
+				console.log(`${ctx.currentTest?.title} FAILED: Debug Adapter Trace`);
+				try {
+					const buf = fs.readFileSync(path.join(tmpdir(), 'vscode-go-debug.txt'));
+					console.log(buf.toString());
+				} catch (e) {
+					console.log(`Failed to read trace: ${e}`);
+				}
+			}
 			dc?.stop();
 		}
 		sinon.restore();
@@ -2091,21 +2103,19 @@
 	});
 
 	let testNumber = 0;
-	async function initializeDebugConfig(config: DebugConfiguration, keepUserLog?: boolean) {
-		if (isDlvDap) {
-			config['debugAdapter'] = 'dlv-dap';
-			if (!keepUserLog) {
-				// Log the output for easier test debugging.
-				config['logOutput'] = 'dap,debugger';
-				config['showLog'] = true;
-				config['trace'] = 'verbose';
-			}
-		} else {
-			config['debugAdapter'] = 'legacy';
-			// be explicit and prevent resolveDebugConfiguration from picking
-			// a default debugAdapter for us.
-		}
+	async function initializeDebugConfig(config: DebugConfiguration, keepUserLogSettings?: boolean) {
+		// be explicit and prevent resolveDebugConfiguration from picking
+		// a default debugAdapter for us.
+		config['debugAdapter'] = isDlvDap ? 'dlv-dap' : 'legacy';
 
+		if (!keepUserLogSettings) {
+			dapTraced = true;
+
+			// Log the output for easier test debugging.
+			config['logOutput'] = isDlvDap ? 'dap,debugger' : 'rpc,debugger';
+			config['showLog'] = true;
+			config['trace'] = 'verbose';
+		}
 		// Give each test a distinct debug binary. If a previous test
 		// and a new test use the same binary location, it is possible
 		// that the second test could build the binary, and then the