Search in sources :

Example 1 with GdbOutput

use of org.eclipse.che.plugin.gdb.server.parser.GdbOutput in project che by eclipse.

the class Gdb method clear.

/**
     * `clear` command.
     */
public void clear(@NotNull String file, int lineNumber) throws IOException, InterruptedException, DebuggerException {
    String command = "clear " + file + ":" + lineNumber;
    GdbOutput gdbOutput = sendCommand(command);
    GdbClear.parse(gdbOutput);
}
Also used : GdbOutput(org.eclipse.che.plugin.gdb.server.parser.GdbOutput)

Example 2 with GdbOutput

use of org.eclipse.che.plugin.gdb.server.parser.GdbOutput in project che by eclipse.

the class Gdb method clear.

/**
     * `clear` command.
     */
public void clear(int lineNumber) throws IOException, InterruptedException, DebuggerException {
    String command = "clear " + lineNumber;
    GdbOutput gdbOutput = sendCommand(command);
    GdbClear.parse(gdbOutput);
}
Also used : GdbOutput(org.eclipse.che.plugin.gdb.server.parser.GdbOutput)

Example 3 with GdbOutput

use of org.eclipse.che.plugin.gdb.server.parser.GdbOutput 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. ");
}
Also used : AbstractLineConsumer(org.eclipse.che.api.core.util.AbstractLineConsumer) DebuggerException(org.eclipse.che.api.debugger.server.exceptions.DebuggerException) ArrayList(java.util.ArrayList) ProcessInfo(org.eclipse.che.plugin.gdb.server.parser.ProcessInfo) GdbPrint(org.eclipse.che.plugin.gdb.server.parser.GdbPrint) DebuggerException(org.eclipse.che.api.debugger.server.exceptions.DebuggerException) IOException(java.io.IOException) GdbException(org.eclipse.che.plugin.gdb.server.exception.GdbException) GdbTerminatedException(org.eclipse.che.plugin.gdb.server.exception.GdbTerminatedException) GdbOutput(org.eclipse.che.plugin.gdb.server.parser.GdbOutput) LineConsumer(org.eclipse.che.api.core.util.LineConsumer) AbstractLineConsumer(org.eclipse.che.api.core.util.AbstractLineConsumer) GdbBacktrace(org.eclipse.che.plugin.gdb.server.parser.GdbBacktrace) Location(org.eclipse.che.api.debug.shared.model.Location)

Example 4 with GdbOutput

use of org.eclipse.che.plugin.gdb.server.parser.GdbOutput in project che by eclipse.

the class Gdb method breakpoint.

/**
     * `break` command
     */
public void breakpoint(@NotNull String file, int lineNumber) throws IOException, InterruptedException, DebuggerException {
    String command = "break " + file + ":" + lineNumber;
    GdbOutput gdbOutput = sendCommand(command);
    GdbBreak.parse(gdbOutput);
}
Also used : GdbOutput(org.eclipse.che.plugin.gdb.server.parser.GdbOutput)

Example 5 with GdbOutput

use of org.eclipse.che.plugin.gdb.server.parser.GdbOutput in project che by eclipse.

the class Gdb method delete.

/**
     * `delete` command.
     */
public void delete() throws IOException, InterruptedException, DebuggerException {
    GdbOutput gdbOutput = sendCommand("delete");
    GdbDelete.parse(gdbOutput);
}
Also used : GdbOutput(org.eclipse.che.plugin.gdb.server.parser.GdbOutput)

Aggregations

GdbOutput (org.eclipse.che.plugin.gdb.server.parser.GdbOutput)9 GdbTerminatedException (org.eclipse.che.plugin.gdb.server.exception.GdbTerminatedException)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 AbstractLineConsumer (org.eclipse.che.api.core.util.AbstractLineConsumer)1 LineConsumer (org.eclipse.che.api.core.util.LineConsumer)1 Location (org.eclipse.che.api.debug.shared.model.Location)1 DebuggerException (org.eclipse.che.api.debugger.server.exceptions.DebuggerException)1 GdbException (org.eclipse.che.plugin.gdb.server.exception.GdbException)1 GdbBacktrace (org.eclipse.che.plugin.gdb.server.parser.GdbBacktrace)1 GdbPrint (org.eclipse.che.plugin.gdb.server.parser.GdbPrint)1 ProcessInfo (org.eclipse.che.plugin.gdb.server.parser.ProcessInfo)1