Skip to content

Commit 0156e64

Browse files
authored
add condition field for conditional bp (microsoft#151)
* add condition field for conditional bp * remove two useless helper functions. * refine the code style for get/set
1 parent 700637c commit 0156e64

File tree

8 files changed

+33
-25
lines changed

8 files changed

+33
-25
lines changed

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,24 @@ public class Breakpoint implements IBreakpoint {
3535
private String className = null;
3636
private int lineNumber = 0;
3737
private int hitCount = 0;
38+
private String condition = null;
3839
private HashMap<Object, Object> propertyMap = new HashMap<>();
3940

4041
Breakpoint(VirtualMachine vm, IEventHub eventHub, String className, int lineNumber) {
41-
this(vm, eventHub, className, lineNumber, 0);
42+
this(vm, eventHub, className, lineNumber, 0, null);
4243
}
4344

4445
Breakpoint(VirtualMachine vm, IEventHub eventHub, String className, int lineNumber, int hitCount) {
46+
this(vm, eventHub, className, lineNumber, hitCount, null);
47+
}
48+
49+
Breakpoint(VirtualMachine vm, IEventHub eventHub, String className, int lineNumber, int hitCount, String condition) {
4550
this.vm = vm;
4651
this.eventHub = eventHub;
4752
this.className = className;
4853
this.lineNumber = lineNumber;
4954
this.hitCount = hitCount;
55+
this.condition = condition;
5056
}
5157

5258
// IDebugResource
@@ -85,22 +91,27 @@ public String className() {
8591
}
8692

8793
@Override
88-
public int lineNumber() {
94+
public int getLineNumber() {
8995
return lineNumber;
9096
}
9197

98+
@Override
99+
public String getCondition() {
100+
return condition;
101+
}
102+
92103
@Override
93104
public boolean equals(Object obj) {
94105
if (!(obj instanceof IBreakpoint)) {
95106
return super.equals(obj);
96107
}
97108

98109
IBreakpoint breakpoint = (IBreakpoint) obj;
99-
return Objects.equals(this.className(), breakpoint.className()) && this.lineNumber() == breakpoint.lineNumber();
110+
return Objects.equals(this.className(), breakpoint.className()) && this.getLineNumber() == breakpoint.getLineNumber();
100111
}
101112

102113
@Override
103-
public int hitCount() {
114+
public int getHitCount() {
104115
return hitCount;
105116
}
106117

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,10 @@ public void terminate() {
7777
}
7878

7979
@Override
80-
public IBreakpoint createBreakpoint(String className, int lineNumber) {
81-
return new Breakpoint(vm, this.getEventHub(), className, lineNumber);
80+
public IBreakpoint createBreakpoint(String className, int lineNumber, int hitCount, String condition) {
81+
return new Breakpoint(vm, this.getEventHub(), className, lineNumber, hitCount, condition);
8282
}
8383

84-
@Override
85-
public IBreakpoint createBreakpoint(String className, int lineNumber, int hitCount) {
86-
return new Breakpoint(vm, this.getEventHub(), className, lineNumber, hitCount);
87-
}
8884

8985
@Override
9086
public void setExceptionBreakpoints(boolean notifyCaught, boolean notifyUncaught) {

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
public interface IBreakpoint extends IDebugResource {
1717
String className();
1818

19-
int lineNumber();
19+
int getLineNumber();
2020

21-
int hitCount();
21+
int getHitCount();
2222

2323
void setHitCount(int hitCount);
2424

@@ -27,4 +27,6 @@ public interface IBreakpoint extends IDebugResource {
2727
void putProperty(Object key, Object value);
2828

2929
Object getProperty(Object key);
30+
31+
String getCondition();
3032
}

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ public interface IDebugSession {
2828
void terminate();
2929

3030
// breakpoints
31-
IBreakpoint createBreakpoint(String className, int lineNumber);
32-
33-
IBreakpoint createBreakpoint(String className, int lineNumber, int hitCount);
31+
IBreakpoint createBreakpoint(String className, int lineNumber, int hitCount, String condition);
3432

3533
void setExceptionBreakpoints(boolean notifyCaught, boolean notifyUncaught);
3634

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,10 @@ public IBreakpoint[] setBreakpoints(String source, IBreakpoint[] breakpoints, bo
9191
List<IBreakpoint> toAdd = new ArrayList<>();
9292
List<Integer> visitedLineNumbers = new ArrayList<>();
9393
for (IBreakpoint breakpoint : breakpoints) {
94-
IBreakpoint existed = breakpointMap.get(String.valueOf(breakpoint.lineNumber()));
94+
IBreakpoint existed = breakpointMap.get(String.valueOf(breakpoint.getLineNumber()));
9595
if (existed != null) {
9696
result.add(existed);
97-
visitedLineNumbers.add(existed.lineNumber());
97+
visitedLineNumbers.add(existed.getLineNumber());
9898
continue;
9999
} else {
100100
result.add(breakpoint);
@@ -105,7 +105,7 @@ public IBreakpoint[] setBreakpoints(String source, IBreakpoint[] breakpoints, bo
105105
// Compute the breakpoints that are no longer listed.
106106
List<IBreakpoint> toRemove = new ArrayList<>();
107107
for (IBreakpoint breakpoint : breakpointMap.values()) {
108-
if (!visitedLineNumbers.contains(breakpoint.lineNumber())) {
108+
if (!visitedLineNumbers.contains(breakpoint.getLineNumber())) {
109109
toRemove.add(breakpoint);
110110
}
111111
}
@@ -123,7 +123,7 @@ private void addBreakpointsInternally(String source, IBreakpoint[] breakpoints)
123123
for (IBreakpoint breakpoint : breakpoints) {
124124
breakpoint.putProperty("id", this.nextBreakpointId.getAndIncrement());
125125
this.breakpoints.add(breakpoint);
126-
breakpointMap.put(String.valueOf(breakpoint.lineNumber()), breakpoint);
126+
breakpointMap.put(String.valueOf(breakpoint.getLineNumber()), breakpoint);
127127
}
128128
}
129129
}
@@ -143,7 +143,7 @@ private void removeBreakpointsInternally(String source, IBreakpoint[] breakpoint
143143
// Destroy the breakpoint on the debugee VM.
144144
breakpoint.close();
145145
this.breakpoints.remove(breakpoint);
146-
breakpointMap.remove(String.valueOf(breakpoint.lineNumber()));
146+
breakpointMap.remove(String.valueOf(breakpoint.getLineNumber()));
147147
} catch (Exception e) {
148148
logger.log(Level.SEVERE, String.format("Remove breakpoint exception: %s", e.toString()), e);
149149
}

com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/handler/SetBreakpointsRequestHandler.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,9 @@ public CompletableFuture<Response> handle(Command command, Arguments arguments,
115115
Events.BreakpointEvent bpEvent = new Events.BreakpointEvent("new", this.convertDebuggerBreakpointToClient(bp, context));
116116
context.getProtocolServer().sendEvent(bpEvent);
117117
});
118-
} else if (toAdds[i].hitCount() != added[i].hitCount() && added[i].className() != null) {
118+
} else if (toAdds[i].getHitCount() != added[i].getHitCount() && added[i].className() != null) {
119119
// Update hitCount condition.
120-
added[i].setHitCount(toAdds[i].hitCount());
120+
added[i].setHitCount(toAdds[i].getHitCount());
121121
}
122122
res.add(this.convertDebuggerBreakpointToClient(added[i], context));
123123
}
@@ -133,7 +133,7 @@ public CompletableFuture<Response> handle(Command command, Arguments arguments,
133133
private Types.Breakpoint convertDebuggerBreakpointToClient(IBreakpoint breakpoint, IDebugAdapterContext context) {
134134
int id = (int) breakpoint.getProperty("id");
135135
boolean verified = breakpoint.getProperty("verified") != null && (boolean) breakpoint.getProperty("verified");
136-
int lineNumber = AdapterUtils.convertLineNumber(breakpoint.lineNumber(), context.isDebuggerLinesStartAt1(), context.isClientLinesStartAt1());
136+
int lineNumber = AdapterUtils.convertLineNumber(breakpoint.getLineNumber(), context.isDebuggerLinesStartAt1(), context.isClientLinesStartAt1());
137137
return new Types.Breakpoint(id, verified, lineNumber, "");
138138
}
139139

@@ -152,7 +152,7 @@ private IBreakpoint[] convertClientBreakpointsToDebugger(String sourceFile, Type
152152
} catch (NumberFormatException e) {
153153
hitCount = 0; // If hitCount is an illegal number, ignore hitCount condition.
154154
}
155-
breakpoints[i] = context.getDebugSession().createBreakpoint(fqns[i], lines[i], hitCount);
155+
breakpoints[i] = context.getDebugSession().createBreakpoint(fqns[i], lines[i], hitCount, sourceBreakpoints[i].condition);
156156
if (sourceProvider.supportsRealtimeBreakpointVerification() && StringUtils.isNotBlank(fqns[i])) {
157157
breakpoints[i].putProperty("verified", true);
158158
}

com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/protocol/Types.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ public ExceptionBreakpointFilter(String value, String label) {
213213
public static class Capabilities {
214214
public boolean supportsConfigurationDoneRequest;
215215
public boolean supportsHitConditionalBreakpoints;
216+
public boolean supportsConditionalBreakpoints;
216217
public boolean supportsEvaluateForHovers;
217218
public boolean supportsSetVariable;
218219
public boolean supportsRestartRequest;

com.microsoft.java.debug.core/src/test/java/com/microsoft/java/debug/core/AbstractJdiTestCase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ protected BreakpointEvent waitForBreakPointEvent(String breakpointAtClass, int l
3838
}
3939
IDebugSession debugSession = getCurrentDebugSession();
4040

41-
IBreakpoint breakpointToAdd = debugSession.createBreakpoint(breakpointAtClass, line);
41+
IBreakpoint breakpointToAdd = debugSession.createBreakpoint(breakpointAtClass, line, 0, null);
4242
breakpointToAdd.install().thenAccept(t -> {
4343
System.out.println("Breakpoint is accepted.");
4444
});

0 commit comments

Comments
 (0)