Skip to content

Show GDB server stderr/stdout output when startup times out #634

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,8 @@ public int waitFor() throws InterruptedException {

// Start/stop the GDB server.
protected class GdbServerStep extends InitializationShutdownStep {
private StringBuffer fStartupErrBuffer = new StringBuffer();
private StringBuffer fStartupOutBuffer = new StringBuffer();

public GdbServerStep(Direction direction) {
super(direction);
Expand Down Expand Up @@ -718,17 +720,15 @@ protected IStatus run(IProgressMonitor monitor) {

boolean success = false;

StringBuffer outBuffer = new StringBuffer();
StringBuffer errBuffer = new StringBuffer();

// Check if the server started properly

success = checkServer(serverLaunchRequestMonitor, monitor, outBuffer, errBuffer);
success = checkServer(serverLaunchRequestMonitor, monitor, fStartupOutBuffer, fStartupErrBuffer);
if (success || serverLaunchRequestMonitor.isSuccess())
// Create a wrapper for the original process, to have
// some
// control over the I/O stream.
fServerPipedProcess = new PushBackProcess(fServerProcess, outBuffer, errBuffer);
fServerPipedProcess = new PushBackProcess(fServerProcess, fStartupOutBuffer, fStartupErrBuffer);

// This monitor will further complete the initialise().
if (!serverLaunchRequestMonitor.isCanceled()) {
Expand Down Expand Up @@ -792,7 +792,7 @@ public void run() {
// Notify initialise(rm) directly.
rm.setStatus(
new Status(IStatus.ERROR, Activator.PLUGIN_ID, DebugException.TARGET_REQUEST_FAILED,
getStartingServerJobName() + " timed out.", null)); //$NON-NLS-1$
getStartingServerJobName() + " timed out." + getStartupOutput(), null)); //$NON-NLS-1$
rm.done();
}
}
Expand Down Expand Up @@ -904,6 +904,34 @@ public void run() {
System.out.println("GdbServerStep.shutdown() return");
}
}

/**
* Gets the standard output and error output of the GDB Server during the startup phase (e.g., CheckServer phase).
* @return A string containing the stdout and stderr content, or an empty string if there is none.
*/
private String getStartupOutput() {
String stderrSnapshot;
String stdoutSnapshot;
synchronized (fStartupErrBuffer) {
stderrSnapshot = fStartupErrBuffer.toString();
}

synchronized (fStartupOutBuffer) {
stdoutSnapshot = fStartupOutBuffer.toString();
}

StringBuilder result = new StringBuilder();
if (stderrSnapshot != null && !stderrSnapshot.isEmpty()) {
result.append("\n[stderr]\n").append(stderrSnapshot);
}

if (stdoutSnapshot != null && !stdoutSnapshot.isEmpty()) {
result.append("\n[stdout]\n").append(stdoutSnapshot);
}

return result.toString();
}

}

// ========================================================================
Expand Down