mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
more debug tweaks
This commit is contained in:
@@ -49,36 +49,36 @@ public class Runner implements MessageConsumer {
|
||||
private boolean presenting;
|
||||
|
||||
// Object that listens for error messages or exceptions.
|
||||
private RunnerListener listener;
|
||||
protected RunnerListener listener;
|
||||
|
||||
// Running remote VM
|
||||
private VirtualMachine vm;
|
||||
protected VirtualMachine vm;
|
||||
|
||||
// Thread transferring remote error stream to our error stream
|
||||
private Thread errThread = null;
|
||||
protected Thread errThread = null;
|
||||
|
||||
// Thread transferring remote output stream to our output stream
|
||||
private Thread outThread = null;
|
||||
protected Thread outThread = null;
|
||||
|
||||
// Mode for tracing the Trace program (default= 0 off)
|
||||
private int debugTraceMode = 0;
|
||||
protected int debugTraceMode = 0;
|
||||
|
||||
// Do we want to watch assignments to fields
|
||||
private boolean watchFields = false;
|
||||
protected boolean watchFields = false;
|
||||
|
||||
// Class patterns for which we don't want events
|
||||
private String[] excludes = {
|
||||
protected String[] excludes = {
|
||||
"java.*", "javax.*", "sun.*", "com.sun.*",
|
||||
"apple.*",
|
||||
"processing.*"
|
||||
};
|
||||
|
||||
private RunnerException exception;
|
||||
protected RunnerException exception;
|
||||
//private PrintStream leechErr;
|
||||
|
||||
private Editor editor;
|
||||
private Sketch sketch;
|
||||
private String appletClassName;
|
||||
protected Editor editor;
|
||||
protected Sketch sketch;
|
||||
protected String appletClassName;
|
||||
|
||||
|
||||
public Runner(RunnerListener listener) {
|
||||
@@ -86,6 +86,8 @@ public class Runner implements MessageConsumer {
|
||||
|
||||
if (listener instanceof Editor) {
|
||||
this.editor = (Editor) listener;
|
||||
// } else {
|
||||
// System.out.println("actually it's a " + listener.getClass().getName());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -61,6 +61,8 @@ public class Android implements Tool {
|
||||
static final String ANDROID_SDK_URL =
|
||||
"http://developer.android.com/sdk/";
|
||||
|
||||
static final String ADB_SOCKET_PORT = "29892";
|
||||
|
||||
|
||||
public String getMenuTitle() {
|
||||
return "Android Mode";
|
||||
@@ -410,12 +412,20 @@ public class Android implements Tool {
|
||||
|
||||
if (result == 0) {
|
||||
String[] lines = p.getOutputLines();
|
||||
String last = lines[lines.length - 1];
|
||||
if (last.trim().length() == 0) {
|
||||
last = lines[lines.length - 2];
|
||||
PApplet.println(lines);
|
||||
// String last = lines[lines.length - 1];
|
||||
// if (last.trim().length() == 0) {
|
||||
// last = lines[lines.length - 2];
|
||||
// }
|
||||
// //System.out.println("last is " + last);
|
||||
// return last.trim();
|
||||
for (int i = lines.length-1; i >= 0; --i) {
|
||||
String s = lines[i].trim();
|
||||
if (s.length() != 0) {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
//System.out.println("last is " + last);
|
||||
return last.trim();
|
||||
return null;
|
||||
|
||||
} else {
|
||||
for (String err : p.getErrorLines()) {
|
||||
@@ -560,11 +570,12 @@ public class Android implements Tool {
|
||||
}
|
||||
port = getJdwpPort(device);
|
||||
if (!port.equals(prevPort)) {
|
||||
System.out.println("I'm digging port " + port +
|
||||
" instead of " + prevPort + ".");
|
||||
// System.out.println("I'm digging port " + port +
|
||||
// " instead of " + prevPort + ".");
|
||||
break;
|
||||
}
|
||||
}
|
||||
System.out.println("Found application on port " + port + ".");
|
||||
|
||||
// Originally based on helpful notes by Agus Santoso (http://j.mp/7zV69M)
|
||||
|
||||
@@ -580,27 +591,29 @@ public class Android implements Tool {
|
||||
"adb",
|
||||
"-s", device,
|
||||
"forward",
|
||||
"tcp:29892",
|
||||
"tcp:" + ADB_SOCKET_PORT,
|
||||
"jdwp:" + port
|
||||
};
|
||||
PApplet.println(cmd);
|
||||
// PApplet.println(cmd);
|
||||
Pavarotti fwd = new Pavarotti(cmd);
|
||||
// StringRedirectThread error = new StringRedirectThread(p.getErrorStream());
|
||||
// StringRedirectThread output = new StringRedirectThread(p.getInputStream());
|
||||
|
||||
System.out.println("waiting for forward");
|
||||
//System.out.println("waiting for forward");
|
||||
int result = fwd.waitFor();
|
||||
fwd.printLines();
|
||||
System.out.println("done with forward");
|
||||
//System.out.println("done with forward");
|
||||
|
||||
if (result != 0) {
|
||||
editor.statusError("Could not connect for debugging.");
|
||||
return false;
|
||||
}
|
||||
|
||||
System.out.println("launching vm");
|
||||
System.out.println("creating runner");
|
||||
//System.out.println("editor from Android is " + editor);
|
||||
AndroidRunner ar = new AndroidRunner(editor);
|
||||
return ar.launch("29892");
|
||||
System.out.println("launching vm");
|
||||
return ar.launch(ADB_SOCKET_PORT);
|
||||
//System.out.println("vm launched");
|
||||
|
||||
} catch (IOException e) {
|
||||
|
||||
@@ -41,10 +41,10 @@ public class AndroidRunner extends Runner {
|
||||
// private boolean presenting;
|
||||
|
||||
// Object that listens for error messages or exceptions.
|
||||
private RunnerListener listener;
|
||||
// private RunnerListener listener;
|
||||
|
||||
// Running remote VM
|
||||
private VirtualMachine vm;
|
||||
// private VirtualMachine vm;
|
||||
|
||||
// Thread transferring remote error stream to our error stream
|
||||
// private Thread errThread = null;
|
||||
@@ -65,26 +65,28 @@ public class AndroidRunner extends Runner {
|
||||
// "processing.*"
|
||||
// };
|
||||
|
||||
private RunnerException exception;
|
||||
// private RunnerException exception;
|
||||
|
||||
private Editor editor;
|
||||
private Sketch sketch;
|
||||
private String appletClassName;
|
||||
// private Editor editor;
|
||||
// private Sketch sketch;
|
||||
// private String appletClassName;
|
||||
|
||||
|
||||
public AndroidRunner(RunnerListener listener) {
|
||||
super(listener);
|
||||
|
||||
System.out.println("editor is " + editor);
|
||||
}
|
||||
|
||||
|
||||
public boolean launch(String port) {
|
||||
vm = launchVirtualMachine(port);
|
||||
System.out.println("vm launched");
|
||||
if (vm != null) {
|
||||
System.out.println("starting trace");
|
||||
generateTrace(null);
|
||||
System.out.println("done starting trace");
|
||||
return true;
|
||||
}
|
||||
System.out.println("no trace for you");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -257,14 +259,19 @@ public class AndroidRunner extends Runner {
|
||||
(Connector.Argument)arguments.get("port");
|
||||
portArg.setValue(port);
|
||||
|
||||
((Connector.Argument) arguments.get("hostname")).setValue("localhost");
|
||||
((Connector.Argument) arguments.get("timeout")).setValue("5000");
|
||||
((Connector.Argument) arguments.get("hostname")).setValue("127.0.0.1");
|
||||
// ((Connector.Argument) arguments.get("hostname")).setValue("localhost");
|
||||
// ((Connector.Argument) arguments.get("timeout")).setValue("5000");
|
||||
|
||||
try {
|
||||
PApplet.println(connector);
|
||||
PApplet.println(arguments);
|
||||
|
||||
return connector.attach(arguments);
|
||||
PApplet.println("attaching now...");
|
||||
//return connector.attach(arguments);
|
||||
VirtualMachine machine = connector.attach(arguments);
|
||||
PApplet.println("attached");
|
||||
return machine;
|
||||
|
||||
} catch (IOException ioe) {
|
||||
//throw new Error("Unable to launch target VM: " + exc);
|
||||
@@ -285,8 +292,7 @@ public class AndroidRunner extends Runner {
|
||||
* start threads to forward remote error and output streams,
|
||||
* resume the remote VM, wait for the final event, and shutdown.
|
||||
*/
|
||||
/*
|
||||
void generateTrace(PrintWriter writer) {
|
||||
protected void generateTrace(PrintWriter writer) {
|
||||
vm.setDebugTraceMode(debugTraceMode);
|
||||
|
||||
EventThread eventThread = null;
|
||||
@@ -300,36 +306,28 @@ public class AndroidRunner extends Runner {
|
||||
|
||||
Process process = vm.process();
|
||||
|
||||
// processInput = new SystemOutSiphon(process.getInputStream());
|
||||
// processError = new MessageSiphon(process.getErrorStream(), this);
|
||||
if (process != null) {
|
||||
MessageSiphon ms = new MessageSiphon(process.getErrorStream(), this);
|
||||
errThread = ms.getThread();
|
||||
|
||||
// Copy target's output and error to our output and error.
|
||||
// errThread = new StreamRedirectThread("error reader",
|
||||
// process.getErrorStream(),
|
||||
// System.err);
|
||||
MessageSiphon ms = new MessageSiphon(process.getErrorStream(), this);
|
||||
errThread = ms.getThread();
|
||||
outThread = new StreamRedirectThread("output reader",
|
||||
process.getInputStream(),
|
||||
System.out);
|
||||
|
||||
outThread = new StreamRedirectThread("output reader",
|
||||
process.getInputStream(),
|
||||
System.out);
|
||||
|
||||
errThread.start();
|
||||
outThread.start();
|
||||
errThread.start();
|
||||
outThread.start();
|
||||
} else {
|
||||
System.out.println("process is null, so no streams...");
|
||||
}
|
||||
|
||||
vm.resume();
|
||||
//System.out.println("done with resume");
|
||||
System.out.println("done with resume");
|
||||
|
||||
// Shutdown begins when event thread terminates
|
||||
try {
|
||||
if (eventThread != null) eventThread.join();
|
||||
// System.out.println("in here");
|
||||
// Bug #852 tracked to this next line in the code.
|
||||
// http://dev.processing.org/bugs/show_bug.cgi?id=852
|
||||
errThread.join(); // Make sure output is forwarded
|
||||
// System.out.println("and then");
|
||||
outThread.join(); // before we exit
|
||||
// System.out.println("out of it");
|
||||
// errThread.join(); // Make sure output is forwarded
|
||||
// outThread.join(); // before we exit
|
||||
|
||||
// At this point, disable the run button.
|
||||
// This happens when the sketch is exited by hitting ESC,
|
||||
@@ -345,7 +343,6 @@ public class AndroidRunner extends Runner {
|
||||
//System.out.println("and leaving");
|
||||
if (writer != null) writer.close();
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
@@ -457,7 +454,7 @@ public class AndroidRunner extends Runner {
|
||||
// message to the console.
|
||||
List<StackFrame> frames = thread.frames();
|
||||
for (StackFrame frame : frames) {
|
||||
// System.out.println("frame: " + frame);
|
||||
System.out.println("frame: " + frame);
|
||||
Location location = frame.location();
|
||||
String filename = null;
|
||||
filename = location.sourceName();
|
||||
|
||||
@@ -59,13 +59,13 @@ public class Pavarotti {
|
||||
public void printLines() {
|
||||
for (String err : getErrorLines()) {
|
||||
//if (err.length() > 0) System.err.println("err: " + err);
|
||||
//if (err.length() > 0) System.err.println(err);
|
||||
System.err.println(err);
|
||||
if (err.length() > 0) System.err.println(err);
|
||||
// System.err.println(err);
|
||||
}
|
||||
for (String out : getOutputLines()) {
|
||||
//if (out.length() > 0) System.out.println("out: " + out);
|
||||
//if (out.length() > 0) System.out.println(out);
|
||||
System.out.println(out);
|
||||
if (out.length() > 0) System.out.println(out);
|
||||
// System.out.println(out);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user