use of org.eclipse.che.api.debugger.server.exceptions.DebuggerException in project che by eclipse.
the class Gdb method suspend.
public Location suspend(final String file, boolean isRemoteConnection) throws IOException, InterruptedException, DebuggerException {
if (pid < 0) {
throw new DebuggerException("Gdb process not found.");
}
if (isRemoteConnection) {
Runtime.getRuntime().exec("kill -SIGINT " + pid).waitFor();
sendCommand("signal SIGSTOP ");
} else {
final List<String> outputs = new ArrayList<>();
final ProcessBuilder processBuilder = new ProcessBuilder().command("ps", "-o", "pid,cmd", "--ppid", String.valueOf(pid));
final Process process = processBuilder.start();
LineConsumer stdout = new AbstractLineConsumer() {
@Override
public void writeLine(String line) throws IOException {
outputs.add(line);
}
};
ProcessUtil.process(process, stdout);
int processId = -1;
for (String output : outputs) {
try {
final ProcessInfo processInfo = ProcessInfo.parse(output);
if (file.equals(processInfo.getProcessName())) {
processId = processInfo.getProcessId();
}
} catch (Exception e) {
//we can't get info about current process, but we are trying to get info about another processes
}
}
if (processId == -1) {
throw new DebuggerException(format("Process %s not found.", file));
}
Runtime.getRuntime().exec("kill -SIGINT " + processId).waitFor();
}
final GdbOutput gdbOutput = sendCommand("backtrace");
final GdbBacktrace backtrace = GdbBacktrace.parse(gdbOutput);
final Map<Integer, Location> frames = backtrace.getFrames();
if (frames.containsKey(0)) {
return frames.get(0);
}
throw new DebuggerException("Unable recognize current location for debugger session. ");
}
use of org.eclipse.che.api.debugger.server.exceptions.DebuggerException in project che by eclipse.
the class GdbDebugger method init.
private static GdbDebugger init(String host, int port, String file, String srcDirectory, DebuggerCallback debuggerCallback) throws DebuggerException {
Gdb gdb;
try {
gdb = Gdb.start();
} catch (IOException e) {
throw new DebuggerException("Can't start GDB: " + e.getMessage(), e);
}
try {
GdbDirectory directory = gdb.directory(srcDirectory);
LOG.debug("Source directories: " + directory.getDirectories());
gdb.file(file);
if (port > 0) {
gdb.targetRemote(host, port);
}
} catch (DebuggerException | IOException | InterruptedException e) {
gdb.stop();
throw new DebuggerException("Can't initialize GDB: " + e.getMessage(), e);
}
GdbVersion gdbVersion = gdb.getGdbVersion();
return new GdbDebugger(host, port, gdbVersion.getVersion(), gdbVersion.getName(), file, gdb, debuggerCallback);
}
use of org.eclipse.che.api.debugger.server.exceptions.DebuggerException in project che by eclipse.
the class GdbDebugger method resume.
@Override
public void resume(ResumeAction action) throws DebuggerException {
try {
GdbContinue gdbContinue = gdb.cont();
Breakpoint breakpoint = gdbContinue.getBreakpoint();
if (breakpoint != null) {
currentLocation = breakpoint.getLocation();
debuggerCallback.onEvent(new SuspendEventImpl(breakpoint.getLocation()));
} else {
GdbInfoProgram gdbInfoProgram = gdb.infoProgram();
if (gdbInfoProgram.getStoppedAddress() == null) {
disconnect();
}
}
} catch (GdbTerminatedException e) {
disconnect();
throw e;
} catch (IOException | GdbParseException | InterruptedException e) {
throw new DebuggerException("Resume error. " + e.getMessage(), e);
}
}
use of org.eclipse.che.api.debugger.server.exceptions.DebuggerException in project che by eclipse.
the class GdbDebugger method dumpStackFrame.
/**
* Dump frame.
*/
@Override
public StackFrameDump dumpStackFrame() throws DebuggerException {
try {
Map<String, String> locals = gdb.infoLocals().getVariables();
locals.putAll(gdb.infoArgs().getVariables());
List<Variable> variables = new ArrayList<>(locals.size());
for (Map.Entry<String, String> e : locals.entrySet()) {
String varName = e.getKey();
String varValue = e.getValue();
String varType;
try {
varType = gdb.ptype(varName).getType();
} catch (GdbParseException pe) {
LOG.warn(pe.getMessage(), pe);
varType = "";
}
VariablePath variablePath = new VariablePathImpl(singletonList(varName));
VariableImpl variable = new VariableImpl(varType, varName, varValue, true, variablePath, Collections.emptyList(), true);
variables.add(variable);
}
return new StackFrameDumpImpl(Collections.emptyList(), variables);
} catch (GdbTerminatedException e) {
disconnect();
throw e;
} catch (IOException | GdbParseException | InterruptedException e) {
throw new DebuggerException("Can't dump stack frame. " + e.getMessage(), e);
}
}
use of org.eclipse.che.api.debugger.server.exceptions.DebuggerException in project che by eclipse.
the class GdbDebugger method setValue.
@Override
public void setValue(Variable variable) throws DebuggerException {
try {
List<String> path = variable.getVariablePath().getPath();
if (path.isEmpty()) {
throw new DebuggerException("Variable path is empty");
}
gdb.setVar(path.get(0), variable.getValue());
} catch (GdbTerminatedException e) {
disconnect();
throw e;
} catch (IOException | GdbParseException | InterruptedException e) {
throw new DebuggerException("Can't set value for " + variable.getName() + ". " + e.getMessage(), e);
}
}
Aggregations