mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 16:14:10 -08:00
Further work on IDEA debugger
This commit is contained in:
parent
98efadc6fd
commit
0dbe437266
|
@ -44,12 +44,12 @@ public class TeaVMDebugProcess extends XDebugProcess {
|
||||||
innerDebugger.addListener(new DebuggerListener() {
|
innerDebugger.addListener(new DebuggerListener() {
|
||||||
@Override
|
@Override
|
||||||
public void resumed() {
|
public void resumed() {
|
||||||
session.resume();
|
getSession().resume();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void paused() {
|
public void paused() {
|
||||||
session.pause();
|
handlePaused();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -115,6 +115,10 @@ public class TeaVMDebugProcess extends XDebugProcess {
|
||||||
innerDebugger.continueToLocation(position.getFile().getPath(), position.getLine());
|
innerDebugger.continueToLocation(position.getFile().getPath(), position.getLine());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void handlePaused() {
|
||||||
|
getSession().positionReached(new TeaVMSuspendContext(innerDebugger, getSession().getProject()));
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public XBreakpointHandler<?>[] getBreakpointHandlers() {
|
public XBreakpointHandler<?>[] getBreakpointHandlers() {
|
||||||
|
|
|
@ -0,0 +1,75 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2016 Alexey Andreev.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.teavm.idea.debug;
|
||||||
|
|
||||||
|
import com.intellij.openapi.project.Project;
|
||||||
|
import com.intellij.openapi.roots.ProjectRootManager;
|
||||||
|
import com.intellij.openapi.vfs.VirtualFile;
|
||||||
|
import com.intellij.xdebugger.frame.XExecutionStack;
|
||||||
|
import com.intellij.xdebugger.frame.XStackFrame;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Objects;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.teavm.debugging.CallFrame;
|
||||||
|
import org.teavm.debugging.Debugger;
|
||||||
|
|
||||||
|
public class TeaVMExecutionStack extends XExecutionStack {
|
||||||
|
private Debugger innerDebugger;
|
||||||
|
private TeaVMStackFrame[] frames;
|
||||||
|
private ProjectRootManager rootManager;
|
||||||
|
|
||||||
|
public TeaVMExecutionStack(@NotNull Debugger innerDebugger, @NotNull Project project) {
|
||||||
|
super("TeaVM");
|
||||||
|
this.innerDebugger = innerDebugger;
|
||||||
|
rootManager = ProjectRootManager.getInstance(project);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public XStackFrame getTopFrame() {
|
||||||
|
TeaVMStackFrame[] frames = calculateFrames();
|
||||||
|
return frames.length > 0 ? frames[0] : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private TeaVMStackFrame[] calculateFrames() {
|
||||||
|
if (frames == null) {
|
||||||
|
CallFrame[] innerCallStack = innerDebugger.getCallStack();
|
||||||
|
frames = new TeaVMStackFrame[innerCallStack.length];
|
||||||
|
for (int i = 0; i < innerCallStack.length; ++i) {
|
||||||
|
frames[i] = new TeaVMStackFrame(this, innerCallStack[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return frames;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void computeStackFrames(int firstFrameIndex, XStackFrameContainer container) {
|
||||||
|
TeaVMStackFrame[] frames = calculateFrames();
|
||||||
|
int index = Math.min(firstFrameIndex, frames.length);
|
||||||
|
container.addStackFrames(Arrays.asList(frames).subList(index, frames.length), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
VirtualFile findVirtualFile(@NotNull String partialPath) {
|
||||||
|
return Arrays.stream(rootManager.getContentSourceRoots())
|
||||||
|
.map(sourceRoot -> sourceRoot.findFileByRelativePath(partialPath))
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.findFirst()
|
||||||
|
.orElse(null);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,54 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2016 Alexey Andreev.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.teavm.idea.debug;
|
||||||
|
|
||||||
|
import com.intellij.openapi.vfs.VirtualFile;
|
||||||
|
import com.intellij.xdebugger.XDebuggerUtil;
|
||||||
|
import com.intellij.xdebugger.XSourcePosition;
|
||||||
|
import com.intellij.xdebugger.frame.XStackFrame;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.teavm.debugging.CallFrame;
|
||||||
|
import org.teavm.debugging.information.SourceLocation;
|
||||||
|
|
||||||
|
class TeaVMStackFrame extends XStackFrame {
|
||||||
|
private TeaVMExecutionStack stack;
|
||||||
|
private CallFrame innerFrame;
|
||||||
|
private XSourcePosition position;
|
||||||
|
|
||||||
|
TeaVMStackFrame(@NotNull TeaVMExecutionStack stack, @NotNull CallFrame innerFrame) {
|
||||||
|
this.stack = stack;
|
||||||
|
this.innerFrame = innerFrame;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public XSourcePosition getSourcePosition() {
|
||||||
|
if (position == null) {
|
||||||
|
VirtualFile virtualFile = null;
|
||||||
|
int line = -1;
|
||||||
|
SourceLocation innerLocation = innerFrame.getLocation();
|
||||||
|
if (innerLocation != null) {
|
||||||
|
if (innerLocation.getFileName() != null) {
|
||||||
|
virtualFile = stack.findVirtualFile(innerLocation.getFileName());
|
||||||
|
}
|
||||||
|
line = innerLocation.getLine();
|
||||||
|
}
|
||||||
|
position = XDebuggerUtil.getInstance().createPosition(virtualFile, line);
|
||||||
|
}
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,36 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2016 Alexey Andreev.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.teavm.idea.debug;
|
||||||
|
|
||||||
|
import com.intellij.openapi.project.Project;
|
||||||
|
import com.intellij.xdebugger.frame.XExecutionStack;
|
||||||
|
import com.intellij.xdebugger.frame.XSuspendContext;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.teavm.debugging.Debugger;
|
||||||
|
|
||||||
|
class TeaVMSuspendContext extends XSuspendContext {
|
||||||
|
private XExecutionStack executionStack;
|
||||||
|
|
||||||
|
TeaVMSuspendContext(Debugger innerDebugger, Project project) {
|
||||||
|
executionStack = new TeaVMExecutionStack(innerDebugger, project);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public XExecutionStack getActiveExecutionStack() {
|
||||||
|
return executionStack;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user