blob: b9d75cc1dd180e38f2867c1b0cd737d5087fba53 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
/*******************************************************************************
* Copyright (c) 2000, 2005 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* QNX Software Systems - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.debug.mi.core;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import org.eclipse.cdt.debug.mi.core.command.CLICommand;
import org.eclipse.cdt.debug.mi.core.command.Command;
import org.eclipse.cdt.debug.mi.core.command.CommandFactory;
import org.eclipse.cdt.debug.mi.core.command.RawCommand;
/**
*/
public class SessionProcess extends Process {
MISession session;
OutputStream out;
public SessionProcess(MISession s) {
session = s;
}
/**
* @see java.lang.Process#destroy()
*/
public void destroy() {
session.terminate();
}
/**
* @see java.lang.Process#exitValue()
*/
public int exitValue() {
return session.getGDBProcess().exitValue();
}
/**
* @see java.lang.Process#getErrorStream()
*/
public InputStream getErrorStream() {
return session.getMILogStream();
}
/**
* @see java.lang.Process#getInputStream()
*/
public InputStream getInputStream() {
return session.getMIConsoleStream();
}
/**
* @see java.lang.Process#getOutputStream()
*/
public OutputStream getOutputStream() {
if (out == null) {
out = new OutputStream() {
StringBuffer buf = new StringBuffer();
public void write(int b) throws IOException {
buf.append((char)b);
if (b == '\n') {
post();
}
}
// Encapsulate the string sent to gdb in a fake
// command and post it to the TxThread.
public void post() throws IOException {
// Throw away the newline.
String str = buf.toString().trim();
buf.setLength(0);
Command cmd = null;
// 1-
// if We have the secondary prompt it means
// that GDB is waiting for more feedback, use a RawCommand
// 2-
// Do not use the interpreterexec for stepping operation
// the UI will fall out of step.
// 3-
// Normal Command Line Interface.
boolean secondary = session.inSecondaryPrompt();
if (secondary) {
cmd = new RawCommand(str);
} else if (session.useExecConsole() && str.length() > 0
&& !CLIProcessor.isSteppingOperation(str)) {
CommandFactory factory = session.getCommandFactory();
cmd = factory.createMIInterpreterExecConsole(str);
} else {
cmd = new CLICommand(str);
}
try {
// Do not wait around for the answer.
session.postCommand(cmd, -1);
} catch (MIException e) {
//e.printStackTrace();
throw new IOException(e.getMessage());
}
}
};
}
return out;
}
/**
* @see java.lang.Process#waitFor()
*/
public int waitFor() throws InterruptedException {
return session.getGDBProcess().waitFor();
}
}
|