Search in sources :

Example 21 with Location

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

the class GdbBacktraceTest method testParseLibraryLocation.

@Test
public void testParseLibraryLocation() throws Exception {
    GdbOutput gdbOutput = GdbOutput.of(BACKTRACE_OUTPUT);
    GdbBacktrace backtrace = GdbBacktrace.parse(gdbOutput);
    Map<Integer, Location> frames = backtrace.getFrames();
    Location frame1 = frames.get(1);
    Location frame2 = frames.get(2);
    assertEquals(frame1.getTarget(), "/usr/lib/x86_64-linux-gnu/libstdc++.so.6");
    assertEquals(frame2.getTarget(), "/usr/lib/x86_64-linux-gnu/libstdc++.so.6");
}
Also used : Location(org.eclipse.che.api.debug.shared.model.Location) Test(org.testng.annotations.Test)

Example 22 with Location

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

the class GdbInfoLineTest method testParse1.

@Test
public void testParse1() throws Exception {
    GdbOutput gdbOutput = GdbOutput.of("Line 6 of \"h.cpp\" starts at address 0x4008ae <main()+17> and ends at 0x4008ca <main()+45>.\n");
    GdbInfoLine gdbInfoLine = GdbInfoLine.parse(gdbOutput);
    Location location = gdbInfoLine.getLocation();
    assertEquals(location.getTarget(), "h.cpp");
    assertEquals(location.getLineNumber(), 6);
}
Also used : Location(org.eclipse.che.api.debug.shared.model.Location) Test(org.testng.annotations.Test)

Example 23 with Location

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

the class JavaDebugger method processBreakPointEvent.

private boolean processBreakPointEvent(com.sun.jdi.event.BreakpointEvent event) throws DebuggerException {
    setCurrentThread(event.thread());
    boolean hitBreakpoint;
    ExpressionParser parser = (ExpressionParser) event.request().getProperty("org.eclipse.che.ide.java.debug.condition.expression.parser");
    if (parser != null) {
        com.sun.jdi.Value result = evaluate(parser);
        hitBreakpoint = result instanceof com.sun.jdi.BooleanValue && ((com.sun.jdi.BooleanValue) result).value();
    } else {
        // If there is no expression.
        hitBreakpoint = true;
    }
    if (hitBreakpoint) {
        com.sun.jdi.Location jdiLocation = event.location();
        Location location;
        try {
            location = debuggerUtil.getLocation(jdiLocation);
        } catch (DebuggerException e) {
            location = new LocationImpl(jdiLocation.declaringType().name(), jdiLocation.lineNumber());
        }
        debuggerCallback.onEvent(new SuspendEventImpl(location));
    }
    // or if condition expression is not set.
    return !hitBreakpoint;
}
Also used : SuspendEventImpl(org.eclipse.che.api.debug.shared.model.impl.event.SuspendEventImpl) DebuggerException(org.eclipse.che.api.debugger.server.exceptions.DebuggerException) LocationImpl(org.eclipse.che.api.debug.shared.model.impl.LocationImpl) ExpressionParser(org.eclipse.che.plugin.jdb.server.expression.ExpressionParser) Location(org.eclipse.che.api.debug.shared.model.Location)

Example 24 with Location

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

the class GdbDebugger method addBreakpoint.

@Override
public void addBreakpoint(Breakpoint breakpoint) throws DebuggerException {
    try {
        Location location = breakpoint.getLocation();
        if (location.getTarget() == null) {
            gdb.breakpoint(location.getLineNumber());
        } else {
            gdb.breakpoint(location.getTarget(), location.getLineNumber());
        }
        debuggerCallback.onEvent(new BreakpointActivatedEventImpl(breakpoint));
    } catch (GdbTerminatedException e) {
        disconnect();
        throw e;
    } catch (IOException | GdbParseException | InterruptedException e) {
        throw new DebuggerException("Can't add breakpoint: " + breakpoint + ". " + e.getMessage(), e);
    }
}
Also used : DebuggerException(org.eclipse.che.api.debugger.server.exceptions.DebuggerException) BreakpointActivatedEventImpl(org.eclipse.che.api.debug.shared.model.impl.event.BreakpointActivatedEventImpl) GdbTerminatedException(org.eclipse.che.plugin.gdb.server.exception.GdbTerminatedException) IOException(java.io.IOException) GdbParseException(org.eclipse.che.plugin.gdb.server.exception.GdbParseException) Location(org.eclipse.che.api.debug.shared.model.Location)

Example 25 with Location

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

the class GdbBacktrace method parse.

/**
     * Factory method.
     */
public static GdbBacktrace parse(GdbOutput gdbOutput) throws GdbParseException {
    Matcher matcher;
    final String output = gdbOutput.getOutput();
    final String[] framesInfo = output.split("#");
    final Map<Integer, Location> frames = new HashMap<>(framesInfo.length);
    for (String frame : framesInfo) {
        try {
            matcher = GDB_FILE_LOCATION.matcher(frame);
            if (matcher.find()) {
                final String fileLocation = matcher.group(2);
                final int lineNumber = Integer.parseInt(matcher.group(3));
                final int frameNumber = Integer.parseInt(matcher.group(1));
                final Location location = new LocationImpl(fileLocation, lineNumber);
                frames.put(frameNumber, location);
                continue;
            }
            matcher = GDB_LIBRARY_LOCATION.matcher(frame);
            if (matcher.find()) {
                final int frameNumber = Integer.parseInt(matcher.group(1));
                final String libraryLocation = matcher.group(2);
                final Location location = new LocationImpl(libraryLocation);
                frames.put(frameNumber, location);
            }
        } catch (NumberFormatException e) {
        //we can't get info about current frame, but we are trying to get info about another frames
        }
    }
    if (!frames.isEmpty()) {
        return new GdbBacktrace(frames);
    }
    throw new GdbParseException(GdbBacktrace.class, output);
}
Also used : Matcher(java.util.regex.Matcher) HashMap(java.util.HashMap) LocationImpl(org.eclipse.che.api.debug.shared.model.impl.LocationImpl) GdbParseException(org.eclipse.che.plugin.gdb.server.exception.GdbParseException) 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