Fixes positioning on native JavaScript stack frame. Fixes logging of

Google Chrome debugger backend.
This commit is contained in:
konsoletyper 2014-09-02 00:07:25 +04:00
parent 491f7ab962
commit b63a6d203f
2 changed files with 23 additions and 9 deletions

View File

@ -19,12 +19,17 @@ import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.concurrent.*; import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.LinkedTransferQueue;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock; import java.util.concurrent.locks.ReentrantLock;
import org.codehaus.jackson.JsonNode; import org.codehaus.jackson.JsonNode;
import org.codehaus.jackson.map.ObjectMapper; import org.codehaus.jackson.map.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.teavm.chromerdp.data.*; import org.teavm.chromerdp.data.*;
import org.teavm.chromerdp.messages.*; import org.teavm.chromerdp.messages.*;
import org.teavm.debugging.javascript.*; import org.teavm.debugging.javascript.*;
@ -34,6 +39,7 @@ import org.teavm.debugging.javascript.*;
* @author Alexey Andreev <konsoletyper@gmail.com> * @author Alexey Andreev <konsoletyper@gmail.com>
*/ */
public class ChromeRDPDebugger implements JavaScriptDebugger, ChromeRDPExchangeConsumer { public class ChromeRDPDebugger implements JavaScriptDebugger, ChromeRDPExchangeConsumer {
private static final Logger logger = LoggerFactory.getLogger(ChromeRDPDebugger.class);
private static final Object dummy = new Object(); private static final Object dummy = new Object();
private ChromeRDPExchange exchange; private ChromeRDPExchange exchange;
private ConcurrentMap<JavaScriptDebuggerListener, Object> listeners = new ConcurrentHashMap<>(); private ConcurrentMap<JavaScriptDebuggerListener, Object> listeners = new ConcurrentHashMap<>();
@ -114,8 +120,9 @@ public class ChromeRDPDebugger implements JavaScriptDebugger, ChromeRDPExchangeC
} }
} }
} catch (Exception e) { } catch (Exception e) {
// TODO: logging if (logger.isErrorEnabled()) {
e.printStackTrace(); logger.error("Error receiving message from Google Chrome", e);
}
} }
} }
}.start(); }.start();
@ -285,7 +292,9 @@ public class ChromeRDPDebugger implements JavaScriptDebugger, ChromeRDPExchangeC
breakpointLocationMap.remove(breakpoint.getLocation()); breakpointLocationMap.remove(breakpoint.getLocation());
breakpoints.remove(breakpoint); breakpoints.remove(breakpoint);
if (breakpoint.chromeId != null) { if (breakpoint.chromeId != null) {
System.out.println("Removing breakpoint at " + breakpoint.getLocation()); if (logger.isInfoEnabled()) {
logger.info("Removing breakpoint at {}", breakpoint.getLocation());
}
Message message = new Message(); Message message = new Message();
message.setMethod("Debugger.removeBreakpoint"); message.setMethod("Debugger.removeBreakpoint");
RemoveBreakpointCommand params = new RemoveBreakpointCommand(); RemoveBreakpointCommand params = new RemoveBreakpointCommand();
@ -316,15 +325,20 @@ public class ChromeRDPDebugger implements JavaScriptDebugger, ChromeRDPExchangeC
SetBreakpointCommand params = new SetBreakpointCommand(); SetBreakpointCommand params = new SetBreakpointCommand();
params.setLocation(unmap(breakpoint.getLocation())); params.setLocation(unmap(breakpoint.getLocation()));
message.setParams(mapper.valueToTree(params)); message.setParams(mapper.valueToTree(params));
System.out.println("Setting breakpoint at: " + breakpoint.getLocation()); if (logger.isInfoEnabled()) {
logger.info("Setting breakpoint at {}, message id is ", breakpoint.getLocation(), message.getId());
}
ResponseHandler handler = new ResponseHandler() { ResponseHandler handler = new ResponseHandler() {
@Override public void received(JsonNode node) throws IOException { @Override public void received(JsonNode node) throws IOException {
if (node != null) { if (node != null) {
SetBreakpointResponse response = mapper.reader(SetBreakpointResponse.class).readValue(node); SetBreakpointResponse response = mapper.reader(SetBreakpointResponse.class).readValue(node);
breakpoint.chromeId = response.getBreakpointId(); breakpoint.chromeId = response.getBreakpointId();
} else { } else {
System.err.println("Error setting breakpoint at " + breakpoint.getLocation() + if (logger.isWarnEnabled()) {
", message id is " + message.getId()); logger.warn("Error setting breakpoint at {}, message id is {}",
breakpoint.getLocation(), message.getId());
}
System.err.println();
breakpoint.chromeId = null; breakpoint.chromeId = null;
} }
for (JavaScriptDebuggerListener listener : getListeners()) { for (JavaScriptDebuggerListener listener : getListeners()) {

View File

@ -146,8 +146,8 @@ public class TeaVMStackFrame implements IStackFrame {
@Override @Override
public int getLineNumber() throws DebugException { public int getLineNumber() throws DebugException {
return callFrame.getLocation() != null ? callFrame.getLocation().getLine() : return callFrame.getLocation() != null && callFrame.getLocation().getLine() >= 0 ?
callFrame.getOriginalLocation().getLine(); callFrame.getLocation().getLine() : callFrame.getOriginalLocation().getLine() + 1;
} }
@Override @Override