Skip to content

Commit a246c69

Browse files
committed
Utilizing --xml-debug introduced in ruby-debug-ide 0.4.0
- do not mess up debugger debug output with the debuggee output - more robustness - more info during failures
1 parent 0c5e6b2 commit a246c69

File tree

7 files changed

+62
-6
lines changed

7 files changed

+62
-6
lines changed

CHANGES

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
* relaxing addBreakpoint, to emit warning instead of exception (debuggee
99
could die)
1010
* ReadersSupport does not throw redundant RubyDebuggerException anymore
11+
* Utilizing --xml-debug introduced in ruby-debug-ide 0.4.0
12+
* do not mess up debugger debug output with the debuggee output
13+
* more robustness
14+
* more info during failures
1115

1216
0.9.0 - 0.9.1
1317
-------------

src/org/rubyforge/debugcommons/ReadersSupport.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ private void startXPPLoop(final XmlPullParser xpp) throws XmlPullParserException
110110
break;
111111
}
112112
eventType = xpp.next();
113+
Util.logEvent(xpp);
113114
} while (eventType != XmlPullParser.END_DOCUMENT);
114115
}
115116

@@ -130,9 +131,8 @@ private void processElement(final XmlPullParser xpp) throws IOException, XmlPull
130131
LOGGER.warning(ErrorReader.readMessage(xpp));
131132
} else if (MESSAGE_ELEMENT.equals(element)) {
132133
String text = ErrorReader.readMessage(xpp);
133-
LOGGER.info(text);
134134
if (text.equals(FINISHED)) {
135-
LOGGER.fine("Got <message>, text == finished");
135+
LOGGER.fine("Got 'finished' <message>, text == finished");
136136
finished = true;
137137
}
138138
} else if (THREADS_ELEMENT.equals(element)) {
@@ -230,7 +230,7 @@ private static XmlPullParser getXpp(final InputStream is) throws XmlPullParserE
230230
xpp.setInput(new BufferedReader(new InputStreamReader(is)));
231231
return xpp;
232232
}
233-
233+
234234
private class XPPLoop extends Thread {
235235

236236
private final XmlPullParser xpp;

src/org/rubyforge/debugcommons/RubyDebuggerFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public static RubyDebuggerProxy startRubyDebug(
127127
args.add("-p");
128128
args.add(String.valueOf(descriptor.getPort()));
129129
if (descriptor.isVerbose()) {
130-
args.add("-d");
130+
args.add("--xml-debug");
131131
}
132132
args.add("--");
133133
args.add(descriptor.getScriptPath());

src/org/rubyforge/debugcommons/RubyDebuggerProxy.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,9 @@ public void resume(final RubyThread thread) {
308308
private void sendCommand(final String s) throws RubyDebuggerException {
309309
LOGGER.fine("Sending command debugger: " + s);
310310
if (isFinished()) {
311-
throw new RubyDebuggerException("Trying to send a command [" + s + "] to terminated process (debuggee: " + getDebugTarged() + ')');
311+
throw new RubyDebuggerException("Trying to send a command [" + s +
312+
"] to terminated process (debuggee: " + getDebugTarged() + ", output: \n\n" +
313+
dumpProcess(debugTarged.getProcess()));
312314
}
313315
getCommandWriter().println(s);
314316
}

src/org/rubyforge/debugcommons/Util.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import java.util.logging.Logger;
77
import java.util.regex.Matcher;
88
import java.util.regex.Pattern;
9+
import org.xmlpull.v1.XmlPullParser;
10+
import org.xmlpull.v1.XmlPullParserException;
911

1012
public final class Util {
1113

@@ -95,4 +97,44 @@ public static int compareVersions(String version1, String version2) {
9597
// Just do silly alphabetical comparison
9698
return version1.compareTo(version2);
9799
}
100+
101+
public static void logEvent(final XmlPullParser xpp) {
102+
if (LOGGER.isLoggable(Level.FINEST)) {
103+
if ("message".equals(xpp.getName())) { // message is handled specially
104+
return;
105+
}
106+
StringBuilder toXml = new StringBuilder();
107+
toXml.append("<");
108+
try {
109+
if (xpp.getEventType() == XmlPullParser.END_TAG) {
110+
toXml.append('/');
111+
}
112+
} catch (XmlPullParserException ex) {
113+
LOGGER.log(Level.SEVERE, ex.getLocalizedMessage(), ex);
114+
}
115+
toXml.append(xpp.getName());
116+
for (int i = 0; i < xpp.getAttributeCount(); i++) {
117+
toXml.append(' ').
118+
append(xpp.getAttributeName(i)).
119+
append("='").
120+
append(xpp.getAttributeValue(i)).
121+
append("'");
122+
}
123+
toXml.append('>');
124+
LOGGER.finest("Received: " + toXml.toString());
125+
}
126+
}
127+
128+
public static void logMessage(final String message, final boolean debug) {
129+
if (LOGGER.isLoggable(Level.FINEST)) {
130+
StringBuilder messageXml = new StringBuilder("<message");
131+
if (debug) {
132+
messageXml.append(" debug='true'");
133+
}
134+
messageXml.append('>');
135+
messageXml.append(message);
136+
messageXml.append("</message>");
137+
LOGGER.finest("Received: " + messageXml.toString());
138+
}
139+
}
98140
}

src/org/rubyforge/debugcommons/reader/ErrorReader.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.rubyforge.debugcommons.reader;
22

33
import java.io.IOException;
4+
import org.rubyforge.debugcommons.Util;
45
import org.xmlpull.v1.XmlPullParser;
56
import org.xmlpull.v1.XmlPullParserException;
67

@@ -14,7 +15,9 @@ public ErrorReader(XmlPullParser xpp) {
1415

1516
private void parse() throws XmlPullParserException, IOException {
1617
assert xpp.getName().equals("error") || xpp.getName().equals("message");
18+
boolean debug = getAttributeBoolValue("debug");
1719
message = xpp.nextText();
20+
Util.logMessage(message, debug);
1821
}
1922

2023
public static String readMessage(final XmlPullParser xpp)

src/org/rubyforge/debugcommons/reader/XmlStreamReader.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
package org.rubyforge.debugcommons.reader;
22

33
import java.io.IOException;
4+
import java.util.logging.Logger;
5+
import org.rubyforge.debugcommons.Util;
46
import org.xmlpull.v1.XmlPullParser;
57
import org.xmlpull.v1.XmlPullParserException;
68

79
public abstract class XmlStreamReader {
810

11+
private static final Logger LOGGER = Logger.getLogger(XmlStreamReader.class.getName());
12+
913
protected final XmlPullParser xpp;
1014

1115
public XmlStreamReader(XmlPullParser xpp) {
@@ -30,6 +34,7 @@ protected int nextEvent() throws XmlPullParserException, IOException {
3034
// skip
3135
// LOGGER.finest("Skipping text event");
3236
}
37+
Util.logEvent(xpp);
3338
return eventType;
3439
}
3540

@@ -42,7 +47,7 @@ protected int getAttributeIntValue(final String attrName) {
4247
}
4348

4449
protected boolean getAttributeBoolValue(final String attrName) {
45-
return getAttributeValue(attrName).equals("true");
50+
return "true".equals(getAttributeValue(attrName));
4651
}
4752

4853
}

0 commit comments

Comments
 (0)