未验证 提交 fc2b6725 编写于 作者: S Serge Rider 提交者: GitHub

Merge pull request #2831 from dbeaver/2556-debug-view

2556 debug view
...@@ -135,25 +135,26 @@ public abstract class DBGBaseController implements DBGController { ...@@ -135,25 +135,26 @@ public abstract class DBGBaseController implements DBGController {
@Override @Override
public List<? extends DBGStackFrame> getStack(Object id) throws DBGException { public List<? extends DBGStackFrame> getStack(Object id) throws DBGException {
DBGSession session = findSession(id); DBGSession session = findAccessibleSession(id);
if (session == null) {
String message = NLS.bind("Session for {0} is not available", id);
throw new DBGException(message);
}
return session.getStack(); return session.getStack();
} }
@Override @Override
public List<? extends DBGVariable<?>> getVariables(Object id) throws DBGException {
DBGSession session = findAccessibleSession(id);
return session.getVariables();
}
public abstract DBGSession createSession(DBGSessionInfo targetInfo, DBCExecutionContext connection) throws DBGException;
public DBGSession findSession(Object id) throws DBGException { public DBGSession findSession(Object id) throws DBGException {
return sessions.get(id); return sessions.get(id);
} }
@Override
public boolean isSessionExists(Object id) { public boolean isSessionExists(Object id) {
return sessions.containsKey(id); return sessions.containsKey(id);
} }
@Override
public List<DBGSession> getSessions() throws DBGException { public List<DBGSession> getSessions() throws DBGException {
return new ArrayList<DBGSession>(sessions.values()); return new ArrayList<DBGSession>(sessions.values());
} }
...@@ -176,21 +177,13 @@ public abstract class DBGBaseController implements DBGController { ...@@ -176,21 +177,13 @@ public abstract class DBGBaseController implements DBGController {
@Override @Override
public void stepInto(Object sessionKey) throws DBGException { public void stepInto(Object sessionKey) throws DBGException {
DBGSession session = findSession(sessionKey); DBGSession session = findAccessibleSession(sessionKey);
if (session == null) {
String message = NLS.bind("Session for {0} is not available", sessionKey);
throw new DBGException(message);
}
session.execStepInto(); session.execStepInto();
} }
@Override @Override
public void stepOver(Object sessionKey) throws DBGException { public void stepOver(Object sessionKey) throws DBGException {
DBGSession session = findSession(sessionKey); DBGSession session = findAccessibleSession(sessionKey);
if (session == null) {
String message = NLS.bind("Session for {0} is not available", sessionKey);
throw new DBGException(message);
}
session.execStepOver(); session.execStepOver();
} }
...@@ -198,7 +191,17 @@ public abstract class DBGBaseController implements DBGController { ...@@ -198,7 +191,17 @@ public abstract class DBGBaseController implements DBGController {
public void stepReturn(Object sessionKey) throws DBGException { public void stepReturn(Object sessionKey) throws DBGException {
//throw DBGException? //throw DBGException?
} }
protected DBGSession findAccessibleSession(Object sessionKey) throws DBGException {
DBGSession session = findSession(sessionKey);
if (session == null) {
String message = NLS.bind("Session for {0} is not available", sessionKey);
throw new DBGException(message);
}
//FIXME:AF: check for accessible state here
return session;
}
@Override @Override
public void registerEventHandler(DBGEventHandler eventHandler) { public void registerEventHandler(DBGEventHandler eventHandler) {
eventHandlers.add(eventHandler); eventHandlers.add(eventHandler);
......
...@@ -39,7 +39,7 @@ public abstract class DBGBaseSession implements DBGSession { ...@@ -39,7 +39,7 @@ public abstract class DBGBaseSession implements DBGSession {
private final DBGBaseController controller; private final DBGBaseController controller;
private FutureTask<DBGEvent> task; private FutureTask<Void> task;
private Thread workerThread = null; private Thread workerThread = null;
...@@ -47,7 +47,7 @@ public abstract class DBGBaseSession implements DBGSession { ...@@ -47,7 +47,7 @@ public abstract class DBGBaseSession implements DBGSession {
private final List<DBGBreakpointDescriptor> breakpoints = new ArrayList<>(1); private final List<DBGBreakpointDescriptor> breakpoints = new ArrayList<>(1);
public DBGBaseSession(DBGBaseController controller) { protected DBGBaseSession(DBGBaseController controller) {
this.controller = controller; this.controller = controller;
} }
...@@ -71,7 +71,7 @@ public abstract class DBGBaseSession implements DBGSession { ...@@ -71,7 +71,7 @@ public abstract class DBGBaseSession implements DBGSession {
this.connection = connection; this.connection = connection;
} }
public DBGBaseController getController() { protected DBGBaseController getController() {
return controller; return controller;
} }
...@@ -105,8 +105,7 @@ public abstract class DBGBaseSession implements DBGSession { ...@@ -105,8 +105,7 @@ public abstract class DBGBaseSession implements DBGSession {
} }
if (task.isDone()) { if (task.isDone()) {
try { try {
DBGEvent dbgEvent = task.get(); task.get();
getController().fireEvent(dbgEvent);
} catch (InterruptedException e) { } catch (InterruptedException e) {
log.error("DEBUG INTERRUPT ERROR ", e); log.error("DEBUG INTERRUPT ERROR ", e);
return false; return false;
...@@ -126,18 +125,18 @@ public abstract class DBGBaseSession implements DBGSession { ...@@ -126,18 +125,18 @@ public abstract class DBGBaseSession implements DBGSession {
* @param name * @param name
* @throws DBGException * @throws DBGException
*/ */
protected void runAsync(String commandSQL, String name, DBGEvent event) throws DBGException { protected void runAsync(String commandSQL, String name, DBGEvent begin, DBGEvent end) throws DBGException {
Connection connection = getConnection(); Connection connection = getConnection();
try (Statement stmt = connection.createStatement()) { try (Statement stmt = connection.createStatement()) {
connection.setAutoCommit(false); connection.setAutoCommit(false);
DBGWorker worker = new DBGWorker(connection, commandSQL, event);
task = new FutureTask<DBGEvent>(worker);
workerThread = new Thread(task);
workerThread.setName(name);
workerThread.start();
} catch (SQLException e) { } catch (SQLException e) {
throw new DBGException("SQL error", e); throw new DBGException("SQL error", e);
} }
DBGWorker worker = new DBGWorker(this, commandSQL, begin, end);
task = new FutureTask<Void>(worker);
workerThread = new Thread(task);
workerThread.setName(name);
workerThread.start();
} }
public void close() { public void close() {
...@@ -235,7 +234,7 @@ public abstract class DBGBaseSession implements DBGSession { ...@@ -235,7 +234,7 @@ public abstract class DBGBaseSession implements DBGSession {
} }
} }
/** /**
* Try to acquire exclusive lock * Try to acquire exclusive lock
* *
...@@ -261,4 +260,8 @@ public abstract class DBGBaseSession implements DBGSession { ...@@ -261,4 +260,8 @@ public abstract class DBGBaseSession implements DBGSession {
} }
} }
protected void fireEvent(DBGEvent event) {
controller.fireEvent(event);
}
} }
...@@ -71,12 +71,8 @@ public interface DBGController { ...@@ -71,12 +71,8 @@ public interface DBGController {
DBGSessionInfo getSessionDescriptor(DBCExecutionContext connection) throws DBGException; DBGSessionInfo getSessionDescriptor(DBCExecutionContext connection) throws DBGException;
List<? extends DBGSessionInfo> getSessionDescriptors() throws DBGException; List<? extends DBGSessionInfo> getSessionDescriptors() throws DBGException;
DBGSession findSession(Object id) throws DBGException;
List<DBGSession> getSessions() throws DBGException;
DBGSession createSession(DBGSessionInfo targetInfo, DBCExecutionContext connection) throws DBGException;
boolean isSessionExists(Object id);
List<? extends DBGStackFrame> getStack(Object id) throws DBGException; List<? extends DBGStackFrame> getStack(Object id) throws DBGException;
List<? extends DBGVariable<?>> getVariables(Object id) throws DBGException;
List<? extends DBGObjectDescriptor> getObjects(String ownerCtx, String nameCtx) throws DBGException; List<? extends DBGObjectDescriptor> getObjects(String ownerCtx, String nameCtx) throws DBGException;
/* /*
......
...@@ -24,16 +24,25 @@ public class DBGEvent extends EventObject { ...@@ -24,16 +24,25 @@ public class DBGEvent extends EventObject {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
public static final int ATTACH = 0x0001; /*
public static final int SUSPEND = 0x0002; * The event kind constants
public static final int RESUME = 0x0004; */
public static final int DETACH = 0x0008; public static final int RESUME= 0x0001;
public static final int SUSPEND= 0x0002;
public static final int CREATE= 0x0004;
public static final int TERMINATE= 0x0008;
public static final int CHANGE= 0x0010;
public static final int MODEL_SPECIFIC= 0x0020;
/*
* The event detail constants
*/
public static final int UNSPECIFIED = 0; public static final int UNSPECIFIED = 0;
public static final int STEP_INTO = 0x0001; public static final int STEP_INTO = 0x0001;
public static final int STEP_OVER = 0x0002; public static final int STEP_OVER = 0x0002;
public static final int STEP_RETURN = 0x0004; public static final int STEP_RETURN = 0x0004;
public static final int STEP_END = 0x0008; public static final int STEP_END = 0x0008;
public static final int BREAKPOINT= 0x0010;
private int kind; private int kind;
......
...@@ -19,31 +19,34 @@ ...@@ -19,31 +19,34 @@
package org.jkiss.dbeaver.debug; package org.jkiss.dbeaver.debug;
import java.sql.Connection;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Statement; import java.sql.Statement;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
public class DBGWorker implements Callable<DBGEvent> { public class DBGWorker implements Callable<Void> {
private final Connection conn; private final DBGBaseSession session;
private final String sql; private final String sql;
private final DBGEvent event; private final DBGEvent before;
private final DBGEvent after;
public DBGWorker(Connection conn, String sqlCommand, DBGEvent event) public DBGWorker(DBGBaseSession session, String sqlCommand, DBGEvent begin, DBGEvent end)
{ {
this.conn = conn; this.session = session;
this.sql = sqlCommand; this.sql = sqlCommand;
this.event = event; this.before = begin;
this.after = end;
} }
@Override @Override
public DBGEvent call() throws Exception public Void call() throws Exception
{ {
try (Statement stmt = conn.createStatement()) { try (Statement stmt = session.getConnection().createStatement()) {
session.fireEvent(before);
stmt.executeQuery(sql); stmt.executeQuery(sql);
return event; session.fireEvent(after);
return null;
} catch (SQLException e) { } catch (SQLException e) {
String message = String.format("Failed to execute %s", sql); String message = String.format("Failed to execute %s", sql);
throw new Exception(message, e); throw new Exception(message, e);
......
...@@ -26,8 +26,8 @@ public class DatabaseDebugElement extends DebugElement { ...@@ -26,8 +26,8 @@ public class DatabaseDebugElement extends DebugElement {
super(target); super(target);
} }
public IDatabaseDebugTarget getDatabaseDebugTarget() { public DatabaseDebugTarget getDatabaseDebugTarget() {
return (IDatabaseDebugTarget) getDebugTarget(); return (DatabaseDebugTarget) getDebugTarget();
} }
public DBGController getController() { public DBGController getController() {
......
...@@ -38,8 +38,9 @@ import org.jkiss.dbeaver.debug.DBGController; ...@@ -38,8 +38,9 @@ import org.jkiss.dbeaver.debug.DBGController;
import org.jkiss.dbeaver.debug.DBGEvent; import org.jkiss.dbeaver.debug.DBGEvent;
import org.jkiss.dbeaver.debug.DBGEventHandler; import org.jkiss.dbeaver.debug.DBGEventHandler;
import org.jkiss.dbeaver.debug.DBGException; import org.jkiss.dbeaver.debug.DBGException;
import org.jkiss.dbeaver.debug.DBGStackFrame;
import org.jkiss.dbeaver.debug.DBGVariable;
import org.jkiss.dbeaver.debug.core.DebugCore; import org.jkiss.dbeaver.debug.core.DebugCore;
import org.jkiss.dbeaver.debug.core.DebugEvents;
import org.jkiss.dbeaver.model.runtime.DefaultProgressMonitor; import org.jkiss.dbeaver.model.runtime.DefaultProgressMonitor;
import org.jkiss.dbeaver.model.runtime.VoidProgressMonitor; import org.jkiss.dbeaver.model.runtime.VoidProgressMonitor;
...@@ -287,11 +288,6 @@ public abstract class DatabaseDebugTarget extends DatabaseDebugElement implement ...@@ -287,11 +288,6 @@ public abstract class DatabaseDebugTarget extends DatabaseDebugElement implement
return false; return false;
} }
@Override
public DebugEvent toDebugEvent(DBGEvent event) {
return new DebugEvent(event.getSource(), event.getKind(), event.getDetails());
}
@Override @Override
public boolean supportsStorageRetrieval() { public boolean supportsStorageRetrieval() {
return false; return false;
...@@ -304,9 +300,67 @@ public abstract class DatabaseDebugTarget extends DatabaseDebugElement implement ...@@ -304,9 +300,67 @@ public abstract class DatabaseDebugTarget extends DatabaseDebugElement implement
@Override @Override
public void handleDebugEvent(DBGEvent event) { public void handleDebugEvent(DBGEvent event) {
DebugEvent debugEvent = toDebugEvent(event); int kind = event.getKind();
DebugEvents.fireEvent(debugEvent); if (DBGEvent.SUSPEND == kind) {
// DebugEvents.fireEvent(new DebugEvent(this, DebugEvent.SUSPEND, DebugEvent.BREAKPOINT)); suspended(event.getDetails());
}
}
public boolean canStepInto() {
return controller.canStepInto(sessionKey);
}
public boolean canStepOver() {
return controller.canStepOver(sessionKey);
}
public boolean canStepReturn() {
return controller.canStepReturn(sessionKey);
}
public void stepInto() throws DebugException {
DBGController controller = getController();
try {
controller.stepInto(sessionKey);
} catch (DBGException e) {
String message = NLS.bind("Step into failed for session {0}", sessionKey);
IStatus status = DebugCore.newErrorStatus(message, e);
throw new DebugException(status);
}
}
public void stepOver() throws DebugException {
DBGController controller = getController();
try {
controller.stepOver(sessionKey);
} catch (DBGException e) {
String message = NLS.bind("Step over failed for session {0}", sessionKey);
IStatus status = DebugCore.newErrorStatus(message, e);
throw new DebugException(status);
}
}
public void stepReturn() throws DebugException {
DBGController controller = getController();
try {
controller.stepReturn(sessionKey);
} catch (DBGException e) {
String message = NLS.bind("Step return failed for session {0}", sessionKey);
IStatus status = DebugCore.newErrorStatus(message, e);
throw new DebugException(status);
}
}
protected List<? extends DBGStackFrame> requestStackFrames() throws DBGException {
DBGController controller = getController();
List<? extends DBGStackFrame> stack = controller.getStack(sessionKey);
return stack;
}
protected List<? extends DBGVariable<?>> requestVariables() throws DBGException {
DBGController controller = getController();
List<? extends DBGVariable<?>> variables = controller.getVariables(sessionKey);
return variables;
} }
} }
...@@ -10,7 +10,6 @@ import org.eclipse.debug.core.model.IThread; ...@@ -10,7 +10,6 @@ import org.eclipse.debug.core.model.IThread;
import org.eclipse.debug.core.model.IVariable; import org.eclipse.debug.core.model.IVariable;
import org.eclipse.osgi.util.NLS; import org.eclipse.osgi.util.NLS;
import org.jkiss.dbeaver.debug.DBGException; import org.jkiss.dbeaver.debug.DBGException;
import org.jkiss.dbeaver.debug.DBGSession;
import org.jkiss.dbeaver.debug.DBGStackFrame; import org.jkiss.dbeaver.debug.DBGStackFrame;
import org.jkiss.dbeaver.debug.DBGVariable; import org.jkiss.dbeaver.debug.DBGVariable;
...@@ -18,90 +17,93 @@ public class DatabaseStackFrame extends DatabaseDebugElement implements IStackFr ...@@ -18,90 +17,93 @@ public class DatabaseStackFrame extends DatabaseDebugElement implements IStackFr
private static final IRegisterGroup[] NO_REGISTER_GROUPS = new IRegisterGroup[0]; private static final IRegisterGroup[] NO_REGISTER_GROUPS = new IRegisterGroup[0];
private static final IVariable[] NO_VARIABLES = new IVariable[0]; private static final IVariable[] NO_VARIABLES = new IVariable[0];
private final DBGStackFrame dbgStackFrame;
private final List<DatabaseVariable> variables = new ArrayList<DatabaseVariable>();
private final DatabaseThread thread; private final DatabaseThread thread;
private final Object sessionKey; private final DBGStackFrame dbgStackFrame;
public DatabaseStackFrame(DatabaseThread thread, DBGStackFrame dbgStackFrame, Object sessionKey) { private boolean refreshVariables = true;
public DatabaseStackFrame(DatabaseThread thread, DBGStackFrame dbgStackFrame) {
super(thread.getDatabaseDebugTarget()); super(thread.getDatabaseDebugTarget());
this.thread = thread; this.thread = thread;
this.dbgStackFrame = dbgStackFrame; this.dbgStackFrame = dbgStackFrame;
this.sessionKey = sessionKey;
} }
@Override @Override
public boolean canStepInto() { public boolean canStepInto() {
return thread.canStepInto(); return getThread().canStepInto();
} }
@Override @Override
public boolean canStepOver() { public boolean canStepOver() {
return thread.canStepOver(); return getThread().canStepOver();
} }
@Override @Override
public boolean canStepReturn() { public boolean canStepReturn() {
return thread.canStepReturn(); return getThread().canStepReturn();
} }
@Override @Override
public boolean isStepping() { public boolean isStepping() {
return thread.isStepping(); return getThread().isStepping();
} }
@Override @Override
public void stepInto() throws DebugException { public void stepInto() throws DebugException {
thread.stepInto(); getThread().stepInto();
} }
@Override @Override
public void stepOver() throws DebugException { public void stepOver() throws DebugException {
thread.stepOver(); getThread().stepOver();
} }
@Override @Override
public void stepReturn() throws DebugException { public void stepReturn() throws DebugException {
thread.canStepReturn(); getThread().canStepReturn();
} }
@Override @Override
public boolean canResume() { public boolean canResume() {
return thread.canResume(); return getThread().canResume();
} }
@Override @Override
public boolean canSuspend() { public boolean canSuspend() {
return thread.canSuspend(); return getThread().canSuspend();
} }
@Override @Override
public boolean isSuspended() { public boolean isSuspended() {
return thread.isSuspended(); return getThread().isSuspended();
} }
@Override @Override
public void resume() throws DebugException { public void resume() throws DebugException {
thread.resume(); getThread().resume();
} }
@Override @Override
public void suspend() throws DebugException { public void suspend() throws DebugException {
thread.suspend(); getThread().suspend();
} }
@Override @Override
public boolean canTerminate() { public boolean canTerminate() {
return thread.canTerminate(); return getThread().canTerminate();
} }
@Override @Override
public boolean isTerminated() { public boolean isTerminated() {
return thread.isTerminated(); return getThread().isTerminated();
} }
@Override @Override
public void terminate() throws DebugException { public void terminate() throws DebugException {
thread.terminate(); getThread().terminate();
} }
@Override @Override
...@@ -111,28 +113,40 @@ public class DatabaseStackFrame extends DatabaseDebugElement implements IStackFr ...@@ -111,28 +113,40 @@ public class DatabaseStackFrame extends DatabaseDebugElement implements IStackFr
@Override @Override
public IVariable[] getVariables() throws DebugException { public IVariable[] getVariables() throws DebugException {
try { if (refreshVariables) {
DBGSession debugSession = getController().findSession(sessionKey); try {
List<? extends DBGVariable<?>> dbgVariables = debugSession.getVariables(); List<? extends DBGVariable<?>> variables = getDatabaseDebugTarget().requestVariables();
if (dbgVariables.size() == 0) { rebuildVariables(variables);
return NO_VARIABLES; } catch (DBGException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} }
List<DatabaseVariable> variables = new ArrayList<DatabaseVariable>(); }
if (variables.isEmpty()) {
return NO_VARIABLES;
}
return (IVariable[]) variables.toArray(new IVariable[variables.size()]);
}
protected void invalidateVariables() {
refreshVariables = true;
}
protected void rebuildVariables(List<? extends DBGVariable<?>> dbgVariables) {
try {
variables.clear();
for (DBGVariable<?> dbgVariable : dbgVariables) { for (DBGVariable<?> dbgVariable : dbgVariables) {
DatabaseVariable e = new DatabaseVariable(getDatabaseDebugTarget(), dbgVariable); DatabaseVariable variable = new DatabaseVariable(getDatabaseDebugTarget(), dbgVariable);
variables.add(e); variables.add(variable);
} }
return (DatabaseVariable[]) variables.toArray(new DatabaseVariable[variables.size()]); } finally {
} catch (DBGException e) { refreshVariables = false;
// TODO Auto-generated catch block
e.printStackTrace();
} }
return NO_VARIABLES;
} }
@Override @Override
public boolean hasVariables() throws DebugException { public boolean hasVariables() throws DebugException {
return true; return isSuspended();
} }
@Override @Override
......
...@@ -21,6 +21,7 @@ import java.util.ArrayList; ...@@ -21,6 +21,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.IStatus;
import org.eclipse.debug.core.DebugEvent;
import org.eclipse.debug.core.DebugException; import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.model.IBreakpoint; import org.eclipse.debug.core.model.IBreakpoint;
import org.eclipse.debug.core.model.IStackFrame; import org.eclipse.debug.core.model.IStackFrame;
...@@ -29,6 +30,7 @@ import org.eclipse.osgi.util.NLS; ...@@ -29,6 +30,7 @@ import org.eclipse.osgi.util.NLS;
import org.jkiss.dbeaver.debug.DBGController; import org.jkiss.dbeaver.debug.DBGController;
import org.jkiss.dbeaver.debug.DBGException; import org.jkiss.dbeaver.debug.DBGException;
import org.jkiss.dbeaver.debug.DBGStackFrame; import org.jkiss.dbeaver.debug.DBGStackFrame;
import org.jkiss.dbeaver.debug.DBGVariable;
import org.jkiss.dbeaver.debug.core.DebugCore; import org.jkiss.dbeaver.debug.core.DebugCore;
/** /**
...@@ -39,7 +41,11 @@ public abstract class DatabaseThread extends DatabaseDebugElement implements ITh ...@@ -39,7 +41,11 @@ public abstract class DatabaseThread extends DatabaseDebugElement implements ITh
private final Object sessionKey; private final Object sessionKey;
public DatabaseThread(IDatabaseDebugTarget target, Object sessionKey) { private boolean stepping = false;
private List<DatabaseStackFrame> frames = new ArrayList<>(1);
public DatabaseThread(DatabaseDebugTarget target, Object sessionKey) {
super(target); super(target);
this.sessionKey = sessionKey; this.sessionKey = sessionKey;
} }
...@@ -61,14 +67,13 @@ public abstract class DatabaseThread extends DatabaseDebugElement implements ITh ...@@ -61,14 +67,13 @@ public abstract class DatabaseThread extends DatabaseDebugElement implements ITh
@Override @Override
public void resume() throws DebugException { public void resume() throws DebugException {
// TODO Auto-generated method stub aboutToResume(DebugEvent.CLIENT_REQUEST, false);
getDebugTarget().resume();
} }
@Override @Override
public void suspend() throws DebugException { public void suspend() throws DebugException {
// TODO Auto-generated method stub getDebugTarget().suspend();
} }
@Override @Override
...@@ -91,44 +96,32 @@ public abstract class DatabaseThread extends DatabaseDebugElement implements ITh ...@@ -91,44 +96,32 @@ public abstract class DatabaseThread extends DatabaseDebugElement implements ITh
@Override @Override
public boolean isStepping() { public boolean isStepping() {
// TODO Auto-generated method stub return stepping;
return false;
} }
@Override @Override
public void stepInto() throws DebugException { public void stepInto() throws DebugException {
DBGController controller = getController(); aboutToResume(DebugEvent.STEP_INTO, true);
try { getDatabaseDebugTarget().stepInto();
controller.stepInto(sessionKey);
} catch (DBGException e) {
String message = NLS.bind("Step into failed for session {0}", sessionKey);
IStatus status = DebugCore.newErrorStatus(message, e);
throw new DebugException(status);
}
} }
@Override @Override
public void stepOver() throws DebugException { public void stepOver() throws DebugException {
DBGController controller = getController(); aboutToResume(DebugEvent.STEP_OVER, true);
try { getDatabaseDebugTarget().stepOver();
controller.stepOver(sessionKey);
} catch (DBGException e) {
String message = NLS.bind("Step over failed for session {0}", sessionKey);
IStatus status = DebugCore.newErrorStatus(message, e);
throw new DebugException(status);
}
} }
@Override @Override
public void stepReturn() throws DebugException { public void stepReturn() throws DebugException {
DBGController controller = getController(); aboutToResume(DebugEvent.STEP_RETURN, true);
try { getDatabaseDebugTarget().stepReturn();
controller.stepReturn(sessionKey); }
} catch (DBGException e) {
String message = NLS.bind("Step return failed for session {0}", sessionKey); private void aboutToResume(int detail, boolean stepping) {
IStatus status = DebugCore.newErrorStatus(message, e); frames.clear();
throw new DebugException(status); setStepping(stepping);
} // setBreakpoints(null);
fireResumeEvent(detail);
} }
@Override @Override
...@@ -143,24 +136,30 @@ public abstract class DatabaseThread extends DatabaseDebugElement implements ITh ...@@ -143,24 +136,30 @@ public abstract class DatabaseThread extends DatabaseDebugElement implements ITh
@Override @Override
public void terminate() throws DebugException { public void terminate() throws DebugException {
frames.clear();
getDebugTarget().terminate(); getDebugTarget().terminate();
} }
@Override @Override
public IStackFrame[] getStackFrames() throws DebugException { public IStackFrame[] getStackFrames() throws DebugException {
List<DatabaseStackFrame> frames = new ArrayList<DatabaseStackFrame>(); if (isSuspended()) {
DBGController controller = getController(); if (frames.size() == 0) {
try { extractStackFrames();
List<? extends DBGStackFrame> stack = controller.getStack(sessionKey);
for (DBGStackFrame dbgStackFrame : stack) {
DatabaseStackFrame frame = new DatabaseStackFrame(this, dbgStackFrame, sessionKey);
frames.add(frame);
} }
}
return frames.toArray(new IStackFrame[frames.size()]);
}
protected void extractStackFrames() throws DebugException {
List<? extends DBGStackFrame> stackFrames;
try {
stackFrames = getDatabaseDebugTarget().requestStackFrames();
rebuildStack(stackFrames);
} catch (DBGException e) { } catch (DBGException e) {
// TODO Auto-generated catch block String message = NLS.bind("Error reading stack for {0}", getName());
e.printStackTrace(); IStatus status = DebugCore.newErrorStatus(message, e);
throw new DebugException(status);
} }
return (IStackFrame[]) frames.toArray(new IStackFrame[frames.size()]);
} }
@Override @Override
...@@ -168,6 +167,17 @@ public abstract class DatabaseThread extends DatabaseDebugElement implements ITh ...@@ -168,6 +167,17 @@ public abstract class DatabaseThread extends DatabaseDebugElement implements ITh
return true; return true;
} }
public void rebuildStack(List<? extends DBGStackFrame> stackFrames) {
for (DBGStackFrame dbgStackFrame : stackFrames) {
addFrame(dbgStackFrame, sessionKey);
}
}
private void addFrame(DBGStackFrame stackFrameId , Object sessionKey) {
DatabaseStackFrame frame = new DatabaseStackFrame(this, stackFrameId);
frames.add(frame);
}
@Override @Override
public int getPriority() throws DebugException { public int getPriority() throws DebugException {
// no idea for now // no idea for now
...@@ -176,7 +186,14 @@ public abstract class DatabaseThread extends DatabaseDebugElement implements ITh ...@@ -176,7 +186,14 @@ public abstract class DatabaseThread extends DatabaseDebugElement implements ITh
@Override @Override
public IStackFrame getTopStackFrame() throws DebugException { public IStackFrame getTopStackFrame() throws DebugException {
// TODO Auto-generated method stub if (isSuspended()) {
if (frames.size() == 0) {
extractStackFrames();
}
if (frames.size() > 0) {
return frames.get(0);
}
}
return null; return null;
} }
...@@ -187,13 +204,23 @@ public abstract class DatabaseThread extends DatabaseDebugElement implements ITh ...@@ -187,13 +204,23 @@ public abstract class DatabaseThread extends DatabaseDebugElement implements ITh
} }
public void resumedByTarget() { public void resumedByTarget() {
// TODO Auto-generated method stub aboutToResume(DebugEvent.CLIENT_REQUEST, false);
} }
public void setStepping(boolean b) { public void setStepping(boolean stepping) {
// TODO Auto-generated method stub this.stepping = stepping;
}
protected List<? extends DBGVariable<?>> requestVariables() throws DebugException {
List<DBGVariable<?>> variables = new ArrayList<DBGVariable<?>>();
try {
variables.addAll(getDatabaseDebugTarget().requestVariables());
} catch (DBGException e) {
String message = NLS.bind("Error reading variables for {0}", getName());
IStatus status = DebugCore.newErrorStatus(message, e);
throw new DebugException(status);
}
return variables;
} }
} }
...@@ -19,17 +19,13 @@ package org.jkiss.dbeaver.debug.core.model; ...@@ -19,17 +19,13 @@ package org.jkiss.dbeaver.debug.core.model;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.debug.core.DebugEvent;
import org.eclipse.debug.core.IBreakpointManagerListener; import org.eclipse.debug.core.IBreakpointManagerListener;
import org.eclipse.debug.core.IDebugEventSetListener; import org.eclipse.debug.core.IDebugEventSetListener;
import org.eclipse.debug.core.model.IDebugTarget; import org.eclipse.debug.core.model.IDebugTarget;
import org.jkiss.dbeaver.debug.DBGController; import org.jkiss.dbeaver.debug.DBGController;
import org.jkiss.dbeaver.debug.DBGEvent;
public interface IDatabaseDebugTarget extends IDebugTarget, IDebugEventSetListener, IBreakpointManagerListener { public interface IDatabaseDebugTarget extends IDebugTarget, IDebugEventSetListener, IBreakpointManagerListener {
DebugEvent toDebugEvent(DBGEvent event);
DBGController getController(); DBGController getController();
void connect(IProgressMonitor monitor) throws CoreException; void connect(IProgressMonitor monitor) throws CoreException;
......
...@@ -22,7 +22,7 @@ import org.jkiss.dbeaver.debug.internal.core.DebugCoreMessages; ...@@ -22,7 +22,7 @@ import org.jkiss.dbeaver.debug.internal.core.DebugCoreMessages;
public class ProcedureThread extends DatabaseThread { public class ProcedureThread extends DatabaseThread {
public ProcedureThread(IDatabaseDebugTarget target, Object sessionKey) { public ProcedureThread(DatabaseDebugTarget target, Object sessionKey) {
super(target, sessionKey); super(target, sessionKey);
} }
......
...@@ -23,6 +23,7 @@ import java.sql.SQLException; ...@@ -23,6 +23,7 @@ import java.sql.SQLException;
import java.util.List; import java.util.List;
import java.util.Scanner; import java.util.Scanner;
import org.jkiss.dbeaver.debug.DBGBaseController;
import org.jkiss.dbeaver.debug.DBGBreakpointDescriptor; import org.jkiss.dbeaver.debug.DBGBreakpointDescriptor;
import org.jkiss.dbeaver.debug.DBGController; import org.jkiss.dbeaver.debug.DBGController;
import org.jkiss.dbeaver.debug.DBGException; import org.jkiss.dbeaver.debug.DBGException;
...@@ -210,7 +211,7 @@ public class Debugger { ...@@ -210,7 +211,7 @@ public class Debugger {
} }
public static DBGSession chooseSession(Scanner sc, DBGController controller) public static DBGSession chooseSession(Scanner sc, DBGBaseController controller)
throws DBGException { throws DBGException {
DBGSession debugSession = null; DBGSession debugSession = null;
...@@ -288,7 +289,7 @@ public class Debugger { ...@@ -288,7 +289,7 @@ public class Debugger {
DBPDataSourceContainer dataSource = null; DBPDataSourceContainer dataSource = null;
Connection conn; Connection conn;
DBGController controller; DBGBaseController controller;
try { try {
conn = DriverManager.getConnection(url); conn = DriverManager.getConnection(url);
......
...@@ -89,7 +89,7 @@ public class PostgreDebugSession extends DBGBaseSession { ...@@ -89,7 +89,7 @@ public class PostgreDebugSession extends DBGBaseSession {
* @param sessionDebugInfo - session (debugger client connection) description * @param sessionDebugInfo - session (debugger client connection) description
* @throws DBGException * @throws DBGException
*/ */
public PostgreDebugSession(DBGBaseController controller, PostgreDebugSessionInfo sessionInfo, Object targetId) throws DBGException { PostgreDebugSession(DBGBaseController controller, PostgreDebugSessionInfo sessionInfo, Object targetId) throws DBGException {
super(controller); super(controller);
this.sessionInfo = sessionInfo; this.sessionInfo = sessionInfo;
this.targetId = targetId; this.targetId = targetId;
...@@ -133,7 +133,10 @@ public class PostgreDebugSession extends DBGBaseSession { ...@@ -133,7 +133,10 @@ public class PostgreDebugSession extends DBGBaseSession {
String sessionParam = String.valueOf(getSessionId()); String sessionParam = String.valueOf(getSessionId());
String taskName = sessionParam + " global attached to " + String.valueOf(targetId); String taskName = sessionParam + " global attached to " + String.valueOf(targetId);
runAsync(SQL_ATTACH.replaceAll("\\?sessionid", sessionParam), taskName, new DBGEvent(this, DBGEvent.ATTACH)); String sql = SQL_ATTACH.replaceAll("\\?sessionid", sessionParam);
DBGEvent begin = new DBGEvent(this, DBGEvent.RESUME, DBGEvent.MODEL_SPECIFIC);
DBGEvent end = new DBGEvent(this, DBGEvent.SUSPEND, DBGEvent.BREAKPOINT);
runAsync(sql, taskName, begin, end);
/*if (breakpoint) { /*if (breakpoint) {
runAsync(SQL_ATTACH_BREAKPOINT.replaceAll("\\?sessionid", String.valueOf(sessionId)), runAsync(SQL_ATTACH_BREAKPOINT.replaceAll("\\?sessionid", String.valueOf(sessionId)),
...@@ -198,20 +201,20 @@ public class PostgreDebugSession extends DBGBaseSession { ...@@ -198,20 +201,20 @@ public class PostgreDebugSession extends DBGBaseSession {
* Execute step SQL command asynchronously, set debug session name to * Execute step SQL command asynchronously, set debug session name to
* [sessionID] name [managerPID] * [sessionID] name [managerPID]
* *
* @param commandSQL - SQL command for execute step * @param commandPattern - SQL command for execute step
* @param name - session 'name' part * @param nameParameter - session 'name' part
* @throws DBGException * @throws DBGException
*/ */
public void execStep(String commandSQL, String name, int eventDetail) throws DBGException { public void execStep(String commandPattern, String nameParameter, int eventDetail) throws DBGException {
acquireWriteLock(); acquireWriteLock();
try { try {
DBGEvent event = new DBGEvent(this, DBGEvent.RESUME, eventDetail); String sql = commandPattern.replaceAll("\\?sessionid", String.valueOf(sessionId));
String taskName = String.valueOf(sessionId) + nameParameter + String.valueOf(targetId);
runAsync(commandSQL.replaceAll("\\?sessionid", String.valueOf(sessionId)), DBGEvent begin = new DBGEvent(this, DBGEvent.RESUME, eventDetail);
String.valueOf(sessionId) + name + String.valueOf(targetId), event); DBGEvent end = new DBGEvent(this, DBGEvent.SUSPEND, eventDetail);
runAsync(sql, taskName, begin, end);
} finally { } finally {
lock.writeLock().unlock(); lock.writeLock().unlock();
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册