Skip to content

Commit 1c0472c

Browse files
authored
Merge branch 'master' into andy_user_error
2 parents 4d2191e + 909ab61 commit 1c0472c

29 files changed

Lines changed: 909 additions & 408 deletions

com.microsoft.java.debug.core/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>com.microsoft.java</groupId>
77
<artifactId>java-debug-parent</artifactId>
8-
<version>0.4.0</version>
8+
<version>0.5.0</version>
99
</parent>
1010
<artifactId>com.microsoft.java.debug.core</artifactId>
1111
<packaging>jar</packaging>

com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/DebugSettings.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public final class DebugSettings {
2424
public boolean showStaticVariables = true;
2525
public boolean showQualifiedNames = false;
2626
public boolean showHex = false;
27+
public boolean enableHotCodeReplace = false;
2728
public String logLevel;
2829

2930
public static DebugSettings getCurrent() {

com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/StackFrameUtility.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
import com.sun.jdi.AbsentInformationException;
1515
import com.sun.jdi.IncompatibleThreadStateException;
16+
import com.sun.jdi.InvalidStackFrameException;
1617
import com.sun.jdi.ReferenceType;
1718
import com.sun.jdi.StackFrame;
1819

@@ -27,15 +28,13 @@ public static boolean isNative(StackFrame frame) {
2728
*
2829
* @param frame
2930
* the StackFrame will be popped
30-
* @return true if succeeded
3131
*/
32-
public static boolean pop(StackFrame frame) {
32+
public static void pop(StackFrame frame) throws DebugException {
3333
try {
3434
frame.thread().popFrames(frame);
35-
} catch (IncompatibleThreadStateException e) {
36-
return false;
35+
} catch (IncompatibleThreadStateException | InvalidStackFrameException e) {
36+
throw new DebugException(e.getMessage(), e);
3737
}
38-
return true;
3938
}
4039

4140
public static String getName(StackFrame frame) {

com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/DebugAdapterContext.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ public class DebugAdapterContext implements IDebugAdapterContext {
4545
private RecyclableObjectPool<Long, Object> recyclableIdPool = new RecyclableObjectPool<>();
4646
private IVariableFormatter variableFormatter = VariableFormatterFactory.createVariableFormatter();
4747

48+
private IStackFrameManager stackFrameManager = new StackFrameManager();
49+
4850
public DebugAdapterContext(IProtocolServer server, IProviderContext providerContext) {
4951
this.providerContext = providerContext;
5052
this.server = server;
@@ -224,4 +226,9 @@ public void setStepFilters(StepFilters stepFilters) {
224226
public StepFilters getStepFilters() {
225227
return stepFilters;
226228
}
229+
230+
@Override
231+
public IStackFrameManager getStackFrameManager() {
232+
return stackFrameManager;
233+
}
227234
}

com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/IDebugAdapterContext.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,6 @@ public interface IDebugAdapterContext {
9999
void setStepFilters(StepFilters stepFilters);
100100

101101
StepFilters getStepFilters();
102+
103+
IStackFrameManager getStackFrameManager();
102104
}

com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/IEvaluationProvider.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
import java.util.concurrent.CompletableFuture;
1515

16-
import com.sun.jdi.StackFrame;
1716
import com.sun.jdi.ThreadReference;
1817
import com.sun.jdi.Value;
1918

@@ -34,18 +33,20 @@ public interface IEvaluationProvider extends IProvider {
3433
* Evaluate the expression at the given project and thread and stack frame depth, the promise is to be resolved/rejected when
3534
* the evaluation finishes.
3635
*
37-
* @param projectName The java project which provides resolve class used in the expression
3836
* @param expression The expression to be evaluated
39-
* @param sf The stack frame of the evaluation task
40-
* @return the evaluation result
37+
* @param thread The jdi thread to the expression will be executed at
38+
* @param depth The depth of stackframe of the stopped thread
39+
* @return the evaluation result future
4140
*/
42-
CompletableFuture<Value> evaluate(String projectName, String expression, StackFrame sf);
41+
CompletableFuture<Value> evaluate(String expression, ThreadReference thread, int depth);
4342

4443

4544
/**
46-
* Cancel ongoing evaluation tasks on specified thread.
45+
* Call this method when the thread is to be resumed by user, it will first cancel ongoing evaluation tasks on specified thread and
46+
* ensure the inner states is cleaned.
47+
*
4748
* @param thread the JDI thread reference where the evaluation task is executing at
4849
*/
49-
void cancelEvaluation(ThreadReference thread);
50+
void clearState(ThreadReference thread);
5051

5152
}

com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/IHotCodeReplaceProvider.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
package com.microsoft.java.debug.core.adapter;
1313

1414
import java.util.List;
15-
import java.util.concurrent.CompletableFuture;
15+
import java.util.function.Consumer;
1616

1717
public interface IHotCodeReplaceProvider extends IProvider {
18-
CompletableFuture<List<String>> redefineClasses();
18+
void onClassRedefined(Consumer<List<String>> consumer);
1919
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2017 Microsoft Corporation and others.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.eclipse.org/legal/epl-v10.html
7+
*
8+
* Contributors:
9+
* Microsoft Corporation - initial API and implementation
10+
*******************************************************************************/
11+
12+
package com.microsoft.java.debug.core.adapter;
13+
14+
import com.microsoft.java.debug.core.adapter.variables.StackFrameReference;
15+
import com.sun.jdi.StackFrame;
16+
import com.sun.jdi.ThreadReference;
17+
18+
public interface IStackFrameManager {
19+
/**
20+
* Get a jdi stack frame from stack frame reference.
21+
*
22+
* @param ref the stackframe reference
23+
* @return the jdi stackframe
24+
*/
25+
StackFrame getStackFrame(StackFrameReference ref);
26+
27+
/**
28+
* Refresh all stackframes from jdi thread.
29+
*
30+
* @param thread the jdi thread
31+
* @return all the stackframes in the specified thread
32+
*/
33+
StackFrame[] reloadStackFrames(ThreadReference thread);
34+
}

com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/ProtocolServer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,6 @@ protected void dispatchRequest(Messages.Request request) {
108108
ex.getMessage() != null ? ex.getMessage() : ex.toString()));
109109
}
110110
return null;
111-
});
111+
}).join();
112112
}
113113
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2017 Microsoft Corporation and others.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.eclipse.org/legal/epl-v10.html
7+
*
8+
* Contributors:
9+
* Microsoft Corporation - initial API and implementation
10+
*******************************************************************************/
11+
12+
package com.microsoft.java.debug.core.adapter;
13+
14+
import java.util.Collections;
15+
import java.util.HashMap;
16+
import java.util.Map;
17+
18+
import com.microsoft.java.debug.core.adapter.variables.StackFrameReference;
19+
import com.sun.jdi.IncompatibleThreadStateException;
20+
import com.sun.jdi.StackFrame;
21+
import com.sun.jdi.ThreadReference;
22+
23+
public class StackFrameManager implements IStackFrameManager {
24+
private Map<Long, StackFrame[]> threadStackFrameMap = Collections.synchronizedMap(new HashMap<>());
25+
26+
@Override
27+
public StackFrame getStackFrame(StackFrameReference ref) {
28+
ThreadReference thread = ref.getThread();
29+
int depth = ref.getDepth();
30+
StackFrame[] frames = threadStackFrameMap.get(thread.uniqueID());
31+
return frames == null || frames.length < depth ? null : frames[depth];
32+
}
33+
34+
@Override
35+
public StackFrame[] reloadStackFrames(ThreadReference thread) {
36+
return threadStackFrameMap.compute(thread.uniqueID(), (key, old) -> {
37+
try {
38+
return thread.frames().toArray(new StackFrame[0]);
39+
} catch (IncompatibleThreadStateException e) {
40+
return new StackFrame[0];
41+
}
42+
});
43+
}
44+
}

0 commit comments

Comments
 (0)