Skip to content

Commit

Permalink
Deliver gdb and inferior error messages to the client
Browse files Browse the repository at this point in the history
  • Loading branch information
jonahgraham committed Feb 1, 2023
1 parent f148157 commit d7bb29e
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/GDBBackend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
62 changes: 62 additions & 0 deletions src/integration-tests/stdouterr.spec.ts
Original file line number Diff line number Diff line change
@@ -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,
]);
});
});
1 change: 1 addition & 0 deletions src/integration-tests/test-programs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ MultiThreadRunControl
.settings/
/vars_cpp
/log
stdouterr
5 changes: 4 additions & 1 deletion src/integration-tests/test-programs/Makefile
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -56,6 +56,9 @@ MultiThread: MultiThread.o
MultiThreadRunControl: MultiThreadRunControl.o
$(LINK_CXX)

stdouterr: stdouterr.o
$(LINK)

%.o: %.c
$(CC) -c $< -g3 -O0

Expand Down
9 changes: 9 additions & 0 deletions src/integration-tests/test-programs/stdouterr.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include <stdio.h>
int main()
{
fprintf(stdout, "STDOUT Here I am\n");
fflush(stdout);
fprintf(stderr, "STDERR Here I am\n");
fflush(stderr);
return 0;
}

0 comments on commit d7bb29e

Please sign in to comment.