Search in sources :

Example 1 with Location

use of org.eclipse.che.api.debug.shared.model.Location 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 2 with Location

use of org.eclipse.che.api.debug.shared.model.Location in project che by eclipse.

the class GdbBacktraceTest method testParseFileLocation.

@Test
public void testParseFileLocation() throws Exception {
    GdbOutput gdbOutput = GdbOutput.of(BACKTRACE_OUTPUT);
    GdbBacktrace backtrace = GdbBacktrace.parse(gdbOutput);
    Map<Integer, Location> frames = backtrace.getFrames();
    Location frame0 = frames.get(0);
    Location frame3 = frames.get(3);
    assertEquals(frame0.getTarget(), "../sysdeps/unix/syscall-template.S");
    assertEquals(frame0.getLineNumber(), 81);
    assertEquals(frame3.getTarget(), "hello.cc");
    assertEquals(frame3.getLineNumber(), 16);
}
Also used : Location(org.eclipse.che.api.debug.shared.model.Location) Test(org.testng.annotations.Test)

Example 3 with Location

use of org.eclipse.che.api.debug.shared.model.Location in project che by eclipse.

the class GdbInfoLineTest method testParse2.

@Test
public void testParse2() throws Exception {
    GdbOutput gdbOutput = GdbOutput.of("Line 530 of \"/usr/src/debug/gcc-4.8.3-20140911/obj-x86_64-redhat-linux/x86_64-redhat-linux/libstdc++-v3/include/ostream\"\n" + "   starts at address 0x3e8ba94e60 <std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)>\n" + "   and ends at 0x3e8ba94e6c <std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)+12>.\n");
    GdbInfoLine gdbInfoLine = GdbInfoLine.parse(gdbOutput);
    Location location = gdbInfoLine.getLocation();
    assertEquals(location.getTarget(), "/usr/src/debug/gcc-4.8.3-20140911/obj-x86_64-redhat-linux/x86_64-redhat-linux/libstdc++-v3/include/ostream");
    assertEquals(location.getLineNumber(), 530);
}
Also used : Location(org.eclipse.che.api.debug.shared.model.Location) Test(org.testng.annotations.Test)

Example 4 with Location

use of org.eclipse.che.api.debug.shared.model.Location in project che by eclipse.

the class GdbInfoLineTest method testParse3.

@Test
public void testParse3() throws Exception {
    GdbOutput gdbOutput = GdbOutput.of("Line number 34 is out of range for \"artic_adc.c\"");
    GdbInfoLine gdbInfoLine = GdbInfoLine.parse(gdbOutput);
    Location location = gdbInfoLine.getLocation();
    assertEquals(location.getTarget(), "artic_adc.c");
    assertEquals(location.getLineNumber(), 34);
}
Also used : Location(org.eclipse.che.api.debug.shared.model.Location) Test(org.testng.annotations.Test)

Example 5 with Location

use of org.eclipse.che.api.debug.shared.model.Location in project che by eclipse.

the class GdbInfoBreak method parse.

/**
     * Factory method.
     */
public static GdbInfoBreak parse(GdbOutput gdbOutput) throws GdbParseException {
    String output = gdbOutput.getOutput();
    List<Breakpoint> breakpoints = new ArrayList<>();
    for (String line : output.split("\n")) {
        Matcher matcher = GDB_INFO_B.matcher(line);
        if (matcher.find()) {
            String file = matcher.group(2);
            String lineNumber = matcher.group(3);
            Location location = new LocationImpl(file, Integer.parseInt(lineNumber));
            breakpoints.add(new BreakpointImpl(location));
        }
    }
    return new GdbInfoBreak(breakpoints);
}
Also used : Breakpoint(org.eclipse.che.api.debug.shared.model.Breakpoint) BreakpointImpl(org.eclipse.che.api.debug.shared.model.impl.BreakpointImpl) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) LocationImpl(org.eclipse.che.api.debug.shared.model.impl.LocationImpl) Location(org.eclipse.che.api.debug.shared.model.Location)

Aggregations

Location (org.eclipse.che.api.debug.shared.model.Location)26 LocationImpl (org.eclipse.che.api.debug.shared.model.impl.LocationImpl)11 BreakpointImpl (org.eclipse.che.api.debug.shared.model.impl.BreakpointImpl)9 Test (org.testng.annotations.Test)9 Breakpoint (org.eclipse.che.api.debug.shared.model.Breakpoint)8 DebuggerException (org.eclipse.che.api.debugger.server.exceptions.DebuggerException)6 Matcher (java.util.regex.Matcher)4 BreakpointActivatedEventImpl (org.eclipse.che.api.debug.shared.model.impl.event.BreakpointActivatedEventImpl)4 ArrayList (java.util.ArrayList)3 BreakpointActivatedEvent (org.eclipse.che.api.debug.shared.model.event.BreakpointActivatedEvent)3 DebuggerEvent (org.eclipse.che.api.debug.shared.model.event.DebuggerEvent)3 SuspendEventImpl (org.eclipse.che.api.debug.shared.model.impl.event.SuspendEventImpl)3 IOException (java.io.IOException)2 SuspendEvent (org.eclipse.che.api.debug.shared.model.event.SuspendEvent)2 GdbParseException (org.eclipse.che.plugin.gdb.server.exception.GdbParseException)2 GdbTerminatedException (org.eclipse.che.plugin.gdb.server.exception.GdbTerminatedException)2 ExpressionParser (org.eclipse.che.plugin.jdb.server.expression.ExpressionParser)2 NodeJsOutput (org.eclipse.che.plugin.nodejsdbg.server.NodeJsOutput)2 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1