Skip to content

Commit aef7585

Browse files
strongly typed breakPointIDs
1 parent daa819d commit aef7585

File tree

5 files changed

+48
-21
lines changed

5 files changed

+48
-21
lines changed

luceedebug/src/main/java/luceedebug/DapServer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,12 @@ private DapServer(ILuceeVm luceeVm, Config config) {
7777
clientProxy_.stopped(event);
7878
});
7979

80-
this.luceeVm_.registerBreakpointEventCallback((jdwpThreadID, i32_bpID) -> {
80+
this.luceeVm_.registerBreakpointEventCallback((jdwpThreadID, bpID) -> {
8181
final int i32_threadID = (int)(long)jdwpThreadID.v;
8282
var event = new StoppedEventArguments();
8383
event.setReason("breakpoint");
8484
event.setThreadId(i32_threadID);
85-
event.setHitBreakpointIds(new Integer[] { i32_bpID });
85+
event.setHitBreakpointIds(new Integer[] { bpID.v });
8686
clientProxy_.stopped(event);
8787
});
8888

luceedebug/src/main/java/luceedebug/ILuceeVm.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55

66
import com.sun.jdi.*;
77

8+
import luceedebug.StrongInt.DapBreakpointID;
89
import luceedebug.StrongLong.JdwpThreadID;
910
import luceedebug.StrongString.CanonicalServerAbsPath;
1011
import luceedebug.StrongString.RawIdePath;
1112

1213
public interface ILuceeVm {
1314
public void registerStepEventCallback(Consumer<JdwpThreadID> cb);
14-
public void registerBreakpointEventCallback(BiConsumer<JdwpThreadID, /*bpID*/Integer> cb);
15+
public void registerBreakpointEventCallback(BiConsumer<JdwpThreadID, DapBreakpointID> cb);
1516

1617
public static class BreakpointsChangedEvent {
1718
IBreakpoint[] newBreakpoints = new IBreakpoint[0];
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package luceedebug;
2+
3+
public class StrongInt {
4+
public final Integer v;
5+
private StrongInt(Integer v) {
6+
this.v = v;
7+
}
8+
9+
@Override
10+
public int hashCode() {
11+
return v.hashCode();
12+
}
13+
14+
@Override
15+
public boolean equals(Object other) {
16+
return (other instanceof StrongInt) && v.equals(((StrongInt)other).v);
17+
}
18+
19+
public static class DapBreakpointID extends StrongInt {
20+
public DapBreakpointID(Integer v) {
21+
super(v);
22+
}
23+
}
24+
}
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
11
package luceedebug.coreinject;
22

33
import luceedebug.*;
4+
import luceedebug.StrongInt.DapBreakpointID;
45

56
class Breakpoint implements IBreakpoint {
67
final int line;
7-
final int ID;
8+
final DapBreakpointID ID;
89
final boolean isBound;
910

10-
private Breakpoint(int line, int ID, boolean isBound) {
11+
private Breakpoint(int line, DapBreakpointID ID, boolean isBound) {
1112
this.line = line;
1213
this.ID = ID;
1314
this.isBound = isBound;
1415
}
1516

16-
public static Breakpoint Bound(int line, int ID) {
17+
public static Breakpoint Bound(int line, DapBreakpointID ID) {
1718
return new Breakpoint(line, ID, true);
1819
}
1920

20-
public static Breakpoint Unbound(int line, int ID) {
21+
public static Breakpoint Unbound(int line, DapBreakpointID ID) {
2122
return new Breakpoint(line, ID, false);
2223
}
2324

2425
public int getLine() { return line; }
25-
public int getID() { return ID; }
26+
public int getID() { return ID.v; }
2627
public boolean getIsBound() { return isBound; }
2728
}

luceedebug/src/main/java/luceedebug/coreinject/LuceeVm.java

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import static luceedebug.coreinject.Iife.iife;
2929

3030
import luceedebug.*;
31+
import luceedebug.StrongInt.DapBreakpointID;
3132
import luceedebug.StrongLong.JdwpThreadID;
3233
import luceedebug.StrongString.CanonicalServerAbsPath;
3334
import luceedebug.StrongString.RawIdePath;
@@ -116,7 +117,7 @@ private static class ReplayableCfBreakpointRequest {
116117
final RawIdePath ideAbsPath;
117118
final CanonicalServerAbsPath serverAbsPath;
118119
final int line;
119-
final int id;
120+
final DapBreakpointID id;
120121
/**
121122
* expression for conditional breakpoints
122123
* can be null for "not a conditional breakpoint"
@@ -144,7 +145,7 @@ public boolean equals(Object vv) {
144145
&& expr.equals(v.expr);
145146
}
146147

147-
ReplayableCfBreakpointRequest(RawIdePath ideAbsPath, CanonicalServerAbsPath serverAbsPath, int line, int id, String expr) {
148+
ReplayableCfBreakpointRequest(RawIdePath ideAbsPath, CanonicalServerAbsPath serverAbsPath, int line, DapBreakpointID id, String expr) {
148149
this.ideAbsPath = ideAbsPath;
149150
this.serverAbsPath = serverAbsPath;
150151
this.line = line;
@@ -153,7 +154,7 @@ public boolean equals(Object vv) {
153154
this.maybeNull_jdwpBreakpointRequest = null;
154155
}
155156

156-
ReplayableCfBreakpointRequest(RawIdePath ideAbsPath, CanonicalServerAbsPath serverAbsPath, int line, int id, String expr, BreakpointRequest jdwpBreakpointRequest) {
157+
ReplayableCfBreakpointRequest(RawIdePath ideAbsPath, CanonicalServerAbsPath serverAbsPath, int line, DapBreakpointID id, String expr, BreakpointRequest jdwpBreakpointRequest) {
157158
this.ideAbsPath = ideAbsPath;
158159
this.serverAbsPath = serverAbsPath;
159160
this.line = line;
@@ -471,14 +472,14 @@ public LuceeVm(Config config, VirtualMachine vm) {
471472
private static enum SteppingState { stepping, finalizingViaAwaitedBreakpoint }
472473
private ConcurrentMap<JdwpThreadID, SteppingState> steppingStatesByThread = new ConcurrentHashMap<>();
473474
private Consumer<JdwpThreadID> stepEventCallback = null;
474-
private BiConsumer<JdwpThreadID, /*breakpoint ID*/ Integer> breakpointEventCallback = null;
475+
private BiConsumer<JdwpThreadID, DapBreakpointID> breakpointEventCallback = null;
475476
private Consumer<BreakpointsChangedEvent> breakpointsChangedCallback = null;
476477

477478
public void registerStepEventCallback(Consumer<JdwpThreadID> cb) {
478479
stepEventCallback = cb;
479480
}
480481

481-
public void registerBreakpointEventCallback(BiConsumer<JdwpThreadID, Integer> cb) {
482+
public void registerBreakpointEventCallback(BiConsumer<JdwpThreadID, DapBreakpointID> cb) {
482483
breakpointEventCallback = cb;
483484
}
484485

@@ -690,7 +691,7 @@ private void handleBreakpointEvent(BreakpointEvent event) {
690691
}
691692

692693
if (breakpointEventCallback != null) {
693-
final var bpID = (Integer) request.getProperty(LUCEEDEBUG_BREAKPOINT_ID);
694+
final var bpID = (DapBreakpointID) request.getProperty(LUCEEDEBUG_BREAKPOINT_ID);
694695
breakpointEventCallback.accept(threadID, bpID);
695696
}
696697
}
@@ -727,8 +728,8 @@ public IDebugEntity[] getIndexedVariables(long ID) {
727728
}
728729

729730
private AtomicInteger breakpointID = new AtomicInteger();
730-
private int nextBreakpointID() {
731-
return breakpointID.incrementAndGet();
731+
private DapBreakpointID nextDapBreakpointID() {
732+
return new DapBreakpointID(breakpointID.incrementAndGet());
732733
}
733734

734735
public void rebindBreakpoints(CanonicalServerAbsPath serverAbsPath, Collection<ReplayableCfBreakpointRequest> cfBpRequests) {
@@ -743,10 +744,10 @@ static class BpLineAndId {
743744
final RawIdePath ideAbsPath;
744745
final CanonicalServerAbsPath serverAbsPath;
745746
final int line;
746-
final int id;
747+
final DapBreakpointID id;
747748
final String expr;
748749

749-
public BpLineAndId(RawIdePath ideAbsPath, CanonicalServerAbsPath serverAbsPath, int line, int id, String expr) {
750+
public BpLineAndId(RawIdePath ideAbsPath, CanonicalServerAbsPath serverAbsPath, int line, DapBreakpointID id, String expr) {
750751
this.ideAbsPath = ideAbsPath;
751752
this.serverAbsPath = serverAbsPath;
752753
this.line = line;
@@ -767,16 +768,16 @@ private BpLineAndId[] freshBpLineAndIdRecordsFromLines(RawIdePath idePath, Canon
767768
for (var i = 0; i < lines.length; ++i) {
768769
final int line = lines[i];
769770

770-
int id = iife(() -> {
771+
DapBreakpointID id = iife(() -> {
771772
if (bpInfo == null) {
772-
return nextBreakpointID();
773+
return nextDapBreakpointID();
773774
}
774775
for (var z : bpInfo) {
775776
if (z.line == line) {
776777
return z.id;
777778
}
778779
}
779-
return nextBreakpointID();
780+
return nextDapBreakpointID();
780781
});
781782

782783
result[i] = new BpLineAndId(idePath, serverPath, line, id, exprs[i]);

0 commit comments

Comments
 (0)