use of org.jkiss.dbeaver.debug.DBGException in project dbeaver by dbeaver.
the class Debugger method chooseBreakpoint.
public static DBGBreakpointDescriptor chooseBreakpoint(Scanner sc, DBGController controller, DBGSession session) throws DBGException {
DBGBreakpointDescriptor bp = null;
List<? extends DBGBreakpointDescriptor> bps = session.getBreakpoints();
Scanner scArg;
if (bps.size() == 1) {
bp = bps.get(0);
} else {
System.out.println("Choose breakpoint (0 for quit) :");
int bpNo = 1;
for (DBGBreakpointDescriptor b : bps) {
System.out.println(String.format(" (%d) %s", bpNo++, b.toString()));
}
int bpId = -1;
while (bpId < 0) {
String argc = sc.nextLine();
String strBpid = "";
scArg = new Scanner(argc);
if (scArg.hasNext()) {
strBpid = scArg.next();
if (strBpid.trim().length() > 0) {
try {
bpId = Integer.valueOf(strBpid);
} catch (Exception e) {
System.out.println(String.format("Incorrect session ID %s", strBpid));
bpId = -1;
}
if (bpId == 0) {
break;
}
if (bpId > bps.size()) {
System.out.println(String.format("Incorrect breakpoint ID %s", strBpid));
bpId = -1;
} else {
bp = bps.get(bpId - 1);
break;
}
}
}
scArg.close();
}
}
return bp;
}
use of org.jkiss.dbeaver.debug.DBGException in project dbeaver by dbeaver.
the class Debugger method chooseSession.
public static DBGSession chooseSession(Scanner sc, DBGBaseController controller) throws DBGException {
DBGSession debugSession = null;
List<DBGSession> sessions = controller.getSessions();
Scanner scArg;
if (sessions.size() == 1) {
debugSession = sessions.get(0);
} else {
System.out.println("Choose debug session (0 for quit) :");
int sessNo = 1;
for (DBGSession s : sessions) {
System.out.println(String.format(" (%d) %s", sessNo++, s.toString()));
}
int sessionId = -1;
while (sessionId < 0) {
String argc = sc.nextLine();
String strSessionid = "";
scArg = new Scanner(argc);
if (scArg.hasNext()) {
strSessionid = scArg.next();
if (strSessionid.trim().length() > 0) {
try {
sessionId = Integer.valueOf(strSessionid);
} catch (Exception e) {
System.out.println(String.format("Incorrect session ID %s", strSessionid));
sessionId = -1;
}
if (sessionId == 0) {
break;
}
if (sessionId > sessions.size()) {
System.out.println(String.format("Incorrect session ID %s", strSessionid));
sessionId = -1;
} else {
debugSession = sessions.get(sessionId - 1);
break;
}
}
}
scArg.close();
}
}
return debugSession;
}
use of org.jkiss.dbeaver.debug.DBGException in project dbeaver by dbeaver.
the class PostgreDebugController method getObjects.
@Override
public List<PostgreDebugObjectDescriptor> getObjects(String ownerCtx, String nameCtx) throws DBGException {
DBCExecutionContext executionContext = getExecutionContext();
String sql = SQL_OBJECT.replaceAll("\\?nameCtx", nameCtx).replaceAll("\\?userCtx", ownerCtx).toLowerCase();
try (Statement stmt = getConnection(executionContext).createStatement();
ResultSet rs = stmt.executeQuery(sql)) {
List<PostgreDebugObjectDescriptor> res = new ArrayList<PostgreDebugObjectDescriptor>();
while (rs.next()) {
int oid = rs.getInt("oid");
String proname = rs.getString("proname");
String owner = rs.getString("owner");
String nspname = rs.getString("nspname");
String lang = rs.getString("lang");
PostgreDebugObjectDescriptor object = new PostgreDebugObjectDescriptor(oid, proname, owner, nspname, lang);
res.add(object);
}
return res;
} catch (SQLException e) {
throw new DBGException("SQL error", e);
}
}
use of org.jkiss.dbeaver.debug.DBGException in project dbeaver by dbeaver.
the class PostgreDebugController method getSessionDescriptor.
@Override
public PostgreDebugSessionInfo getSessionDescriptor(DBCExecutionContext connectionTarget) throws DBGException {
try (Statement stmt = getConnection(connectionTarget).createStatement();
ResultSet rs = stmt.executeQuery(SQL_CURRENT_SESSION)) {
if (rs.next()) {
int pid = rs.getInt("pid");
String usename = rs.getString("usename");
String applicationName = rs.getString("application_name");
String state = rs.getString("state");
String query = rs.getString("query");
PostgreDebugSessionInfo res = new PostgreDebugSessionInfo(pid, usename, applicationName, state, query);
return res;
}
throw new DBGException("Error getting session");
} catch (SQLException e) {
throw new DBGException("SQL error", e);
}
}
use of org.jkiss.dbeaver.debug.DBGException in project dbeaver by dbeaver.
the class PostgreDebugSession method selectFrame.
/**
* This function changes the debugger focus to the indicated frame (in the
* call stack). Whenever the target stops (at a breakpoint or as the result
* of a step/into or step/over), the debugger changes focus to most deeply
* nested function in the call stack (because that's the function that's
* executing).
*
* You can change the debugger focus to other stack frames - once you do
* that, you can examine the source code for that frame, the variable values
* in that frame, and the breakpoints in that target.
*
* The debugger focus remains on the selected frame until you change it or
* the target stops at another breakpoint.
*
* @return DBGStackFrame
*/
public void selectFrame(int frameNumber) throws DBGException {
acquireReadLock();
String pattern = SQL_SELECT_FRAME;
pattern = "select * from pldbg_select_frame(?sessionid,?frameno)";
String sql = pattern.replaceAll("\\?sessionid", String.valueOf(sessionId)).replaceAll("\\?frameno", String.valueOf(frameNumber));
try (Statement stmt = getConnection().createStatement();
ResultSet rs = stmt.executeQuery(sql)) {
if (!rs.next()) {
throw new DBGException("Unable to select frame");
}
} catch (SQLException e) {
throw new DBGException("SQL error", e);
} finally {
lock.readLock().unlock();
}
}
Aggregations