From d7bb29e18e414c1e2c70774c3ae5f97345f86ea4 Mon Sep 17 00:00:00 2001 From: Jonah Graham Date: Tue, 31 Jan 2023 17:59:17 -0500 Subject: [PATCH] Deliver gdb and inferior error messages to the client Fixes #239 --- src/GDBBackend.ts | 6 ++ src/integration-tests/stdouterr.spec.ts | 62 +++++++++++++++++++ .../test-programs/.gitignore | 1 + src/integration-tests/test-programs/Makefile | 5 +- .../test-programs/stdouterr.c | 9 +++ 5 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 src/integration-tests/stdouterr.spec.ts create mode 100644 src/integration-tests/test-programs/stdouterr.c diff --git a/src/GDBBackend.ts b/src/GDBBackend.ts index ca706519..f4a9b78b 100644 --- a/src/GDBBackend.ts +++ b/src/GDBBackend.ts @@ -85,6 +85,12 @@ export class GDBBackend extends events.EventEmitter { this.out = this.proc.stdin; this.hardwareBreakpoint = requestArgs.hardwareBreakpoint ? true : false; await this.parser.parse(this.proc.stdout); + if (this.proc.stderr) { + this.proc.stderr.on('data', (chunk) => { + const newChunk = chunk.toString(); + this.emit('consoleStreamOutput', newChunk, 'stderr'); + }); + } await this.setNonStopMode(requestArgs.gdbNonStop); await this.setAsyncMode(requestArgs.gdbAsync); } diff --git a/src/integration-tests/stdouterr.spec.ts b/src/integration-tests/stdouterr.spec.ts new file mode 100644 index 00000000..cbe13a77 --- /dev/null +++ b/src/integration-tests/stdouterr.spec.ts @@ -0,0 +1,62 @@ +/********************************************************************* + * Copyright (c) 2023 Kichwa Coders Canada Inc. + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + *********************************************************************/ + +import * as path from 'path'; +import { LaunchRequestArguments } from '../GDBDebugSession'; +import { CdtDebugClient } from './debugClient'; +import { + fillDefaults, + getScopes, + isRemoteTest, + standardBeforeEach, + testProgramsDir, +} from './utils'; + +describe('stdouterr', function () { + let dc: CdtDebugClient; + const program = path.join(testProgramsDir, 'stdouterr'); + const source = path.join(testProgramsDir, 'stdouterr.c'); + + beforeEach(async function () { + dc = await standardBeforeEach(); + }); + + afterEach(async function () { + await dc.stop(); + }); + + it('receives stdout and stderr from inferior as output events', async function () { + if (isRemoteTest) { + // remote tests the inferior stdout/err comes out the remote end, so + // no output events from the adapter + this.skip(); + } + + await dc.hitBreakpoint( + fillDefaults(this.test, { + program: program, + } as LaunchRequestArguments), + { + path: source, + line: 4, + } + ); + + const stdout = dc.waitForOutputEvent('stdout', 'STDOUT Here I am\n'); + const stderr = dc.waitForOutputEvent('stderr', 'STDERR Here I am\n'); + + const scope = await getScopes(dc); + await Promise.all([ + dc.continueRequest({ threadId: scope.thread.id }), + stdout, + stderr, + ]); + }); +}); diff --git a/src/integration-tests/test-programs/.gitignore b/src/integration-tests/test-programs/.gitignore index ac7ac021..94b6e0ab 100644 --- a/src/integration-tests/test-programs/.gitignore +++ b/src/integration-tests/test-programs/.gitignore @@ -18,3 +18,4 @@ MultiThreadRunControl .settings/ /vars_cpp /log +stdouterr diff --git a/src/integration-tests/test-programs/Makefile b/src/integration-tests/test-programs/Makefile index 8ee279ff..3319c587 100644 --- a/src/integration-tests/test-programs/Makefile +++ b/src/integration-tests/test-programs/Makefile @@ -1,4 +1,4 @@ -BINS = empty empty\ space evaluate vars vars_cpp mem segv count disassemble functions loopforever MultiThread MultiThreadRunControl +BINS = empty empty\ space evaluate vars vars_cpp mem segv count disassemble functions loopforever MultiThread MultiThreadRunControl stdouterr .PHONY: all all: $(BINS) @@ -56,6 +56,9 @@ MultiThread: MultiThread.o MultiThreadRunControl: MultiThreadRunControl.o $(LINK_CXX) +stdouterr: stdouterr.o + $(LINK) + %.o: %.c $(CC) -c $< -g3 -O0 diff --git a/src/integration-tests/test-programs/stdouterr.c b/src/integration-tests/test-programs/stdouterr.c new file mode 100644 index 00000000..1c3c0639 --- /dev/null +++ b/src/integration-tests/test-programs/stdouterr.c @@ -0,0 +1,9 @@ +#include +int main() +{ + fprintf(stdout, "STDOUT Here I am\n"); + fflush(stdout); + fprintf(stderr, "STDERR Here I am\n"); + fflush(stderr); + return 0; +}