@@ -45,6 +45,7 @@ public static enum DebuggerType { CLASSIC_DEBUGGER, RUBY_DEBUG }
4545 private final DebuggerType debuggerType ;
4646 private RubyDebugTarget debugTarged ;
4747 private Socket commandSocket ;
48+ private boolean started ;
4849 private boolean finished ;
4950
5051 private PrintWriter commandWriter ;
@@ -112,16 +113,17 @@ public void startDebugging(final IRubyBreakpoint[] initialBreakpoints) throws Ru
112113 startSuspensionReaderLoop ();
113114 }
114115
116+
115117 /**
116- * Whether client might send command to the proxy. When the debuggee
117- * finished (in a standard manner or unexpectedly, e.g. was killed) this
118- * returns false.
118+ * Whether client might send command to the proxy. When the debuggee has
119+ * finished (in a standard manner or unexpectedly, e.g. was killed) or the
120+ * proxy did not start yet, false is returned .
119121 */
120- public synchronized boolean isFinished () {
121- return finished || ! getDebugTarged ().isRunning ();
122+ public synchronized boolean isReady () {
123+ return ! finished && commandWriter != null && getDebugTarged ().isRunning ();
122124 }
123125
124- private void startClassicDebugger (final IRubyBreakpoint [] initialBreakpoints ) throws RubyDebuggerException {
126+ private synchronized void startClassicDebugger (final IRubyBreakpoint [] initialBreakpoints ) throws RubyDebuggerException {
125127 try {
126128 commandFactory = new ClassicDebuggerCommandFactory ();
127129 readersSupport .startCommandLoop (getCommandSocket ().getInputStream ());
@@ -133,7 +135,7 @@ private void startClassicDebugger(final IRubyBreakpoint[] initialBreakpoints) th
133135 }
134136 }
135137
136- private void startRubyDebug (final IRubyBreakpoint [] initialBreakpoints ) throws RubyDebuggerException {
138+ private synchronized void startRubyDebug (final IRubyBreakpoint [] initialBreakpoints ) throws RubyDebuggerException {
137139 try {
138140 commandFactory = new RubyDebugCommandFactory ();
139141 readersSupport .startCommandLoop (getCommandSocket ().getInputStream ());
@@ -172,8 +174,8 @@ protected void setBreakpoints(final IRubyBreakpoint[] breakpoints) throws RubyDe
172174
173175 public synchronized void addBreakpoint (final IRubyBreakpoint breakpoint ) {
174176 LOGGER .fine ("Adding breakpoint: " + breakpoint );
175- if (isFinished ()) {
176- LOGGER .fine ("Session and/or debuggee has already finished , skipping addition of breakpoint: " + breakpoint );
177+ if (! isReady ()) {
178+ LOGGER .fine ("Session and/or debuggee is not ready , skipping addition of breakpoint: " + breakpoint );
177179 return ;
178180 }
179181 assert breakpoint != null : "breakpoint cannot be null" ;
@@ -226,8 +228,8 @@ public synchronized void removeBreakpoint(final IRubyBreakpoint breakpoint) {
226228 */
227229 public synchronized void removeBreakpoint (final IRubyBreakpoint breakpoint , boolean silent ) {
228230 LOGGER .fine ("Removing breakpoint: " + breakpoint );
229- if (isFinished ()) {
230- LOGGER .fine ("Session and/or debuggee has already finished , skipping removing of breakpoint: " + breakpoint );
231+ if (! isReady ()) {
232+ LOGGER .fine ("Session and/or debuggee is not ready , skipping removing of breakpoint: " + breakpoint );
231233 return ;
232234 }
233235 if (breakpoint instanceof IRubyLineBreakpoint ) {
@@ -307,9 +309,9 @@ public void resume(final RubyThread thread) {
307309
308310 private void sendCommand (final String s ) throws RubyDebuggerException {
309311 LOGGER .fine ("Sending command debugger: " + s );
310- if (isFinished ()) {
312+ if (! isReady ()) {
311313 throw new RubyDebuggerException ("Trying to send a command [" + s +
312- "] to terminated process (debuggee: " + getDebugTarged () + ", output: \n \n " +
314+ "] to non-started or finished proxy (debuggee: " + getDebugTarged () + ", output: \n \n " +
313315 dumpProcess (debugTarged .getProcess ()));
314316 }
315317 getCommandWriter ().println (s );
@@ -358,7 +360,7 @@ public RubyFrame[] readFrames(RubyThread thread) throws RubyDebuggerException {
358360 sendCommand (commandFactory .createReadFrames (thread ));
359361 infos = getReadersSupport ().readFrames ();
360362 } catch (RubyDebuggerException e ) {
361- if (isFinished ()) {
363+ if (! isReady ()) {
362364 throw e ;
363365 }
364366 infos = new RubyFrameInfo [0 ];
0 commit comments