Skip to content

Commit

Permalink
strongly typed breakPointIDs
Browse files Browse the repository at this point in the history
  • Loading branch information
softwareCobbler committed Dec 17, 2024
1 parent daa819d commit aef7585
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 21 deletions.
4 changes: 2 additions & 2 deletions luceedebug/src/main/java/luceedebug/DapServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ private DapServer(ILuceeVm luceeVm, Config config) {
clientProxy_.stopped(event);
});

this.luceeVm_.registerBreakpointEventCallback((jdwpThreadID, i32_bpID) -> {
this.luceeVm_.registerBreakpointEventCallback((jdwpThreadID, bpID) -> {
final int i32_threadID = (int)(long)jdwpThreadID.v;
var event = new StoppedEventArguments();
event.setReason("breakpoint");
event.setThreadId(i32_threadID);
event.setHitBreakpointIds(new Integer[] { i32_bpID });
event.setHitBreakpointIds(new Integer[] { bpID.v });
clientProxy_.stopped(event);
});

Expand Down
3 changes: 2 additions & 1 deletion luceedebug/src/main/java/luceedebug/ILuceeVm.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@

import com.sun.jdi.*;

import luceedebug.StrongInt.DapBreakpointID;
import luceedebug.StrongLong.JdwpThreadID;
import luceedebug.StrongString.CanonicalServerAbsPath;
import luceedebug.StrongString.RawIdePath;

public interface ILuceeVm {
public void registerStepEventCallback(Consumer<JdwpThreadID> cb);
public void registerBreakpointEventCallback(BiConsumer<JdwpThreadID, /*bpID*/Integer> cb);
public void registerBreakpointEventCallback(BiConsumer<JdwpThreadID, DapBreakpointID> cb);

public static class BreakpointsChangedEvent {
IBreakpoint[] newBreakpoints = new IBreakpoint[0];
Expand Down
24 changes: 24 additions & 0 deletions luceedebug/src/main/java/luceedebug/StrongInt.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package luceedebug;

public class StrongInt {
public final Integer v;
private StrongInt(Integer v) {
this.v = v;
}

@Override
public int hashCode() {
return v.hashCode();
}

@Override
public boolean equals(Object other) {
return (other instanceof StrongInt) && v.equals(((StrongInt)other).v);
}

public static class DapBreakpointID extends StrongInt {
public DapBreakpointID(Integer v) {
super(v);
}
}
}
11 changes: 6 additions & 5 deletions luceedebug/src/main/java/luceedebug/coreinject/Breakpoint.java
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
package luceedebug.coreinject;

import luceedebug.*;
import luceedebug.StrongInt.DapBreakpointID;

class Breakpoint implements IBreakpoint {
final int line;
final int ID;
final DapBreakpointID ID;
final boolean isBound;

private Breakpoint(int line, int ID, boolean isBound) {
private Breakpoint(int line, DapBreakpointID ID, boolean isBound) {
this.line = line;
this.ID = ID;
this.isBound = isBound;
}

public static Breakpoint Bound(int line, int ID) {
public static Breakpoint Bound(int line, DapBreakpointID ID) {
return new Breakpoint(line, ID, true);
}

public static Breakpoint Unbound(int line, int ID) {
public static Breakpoint Unbound(int line, DapBreakpointID ID) {
return new Breakpoint(line, ID, false);
}

public int getLine() { return line; }
public int getID() { return ID; }
public int getID() { return ID.v; }
public boolean getIsBound() { return isBound; }
}
27 changes: 14 additions & 13 deletions luceedebug/src/main/java/luceedebug/coreinject/LuceeVm.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import static luceedebug.coreinject.Iife.iife;

import luceedebug.*;
import luceedebug.StrongInt.DapBreakpointID;
import luceedebug.StrongLong.JdwpThreadID;
import luceedebug.StrongString.CanonicalServerAbsPath;
import luceedebug.StrongString.RawIdePath;
Expand Down Expand Up @@ -116,7 +117,7 @@ private static class ReplayableCfBreakpointRequest {
final RawIdePath ideAbsPath;
final CanonicalServerAbsPath serverAbsPath;
final int line;
final int id;
final DapBreakpointID id;
/**
* expression for conditional breakpoints
* can be null for "not a conditional breakpoint"
Expand Down Expand Up @@ -144,7 +145,7 @@ public boolean equals(Object vv) {
&& expr.equals(v.expr);
}

ReplayableCfBreakpointRequest(RawIdePath ideAbsPath, CanonicalServerAbsPath serverAbsPath, int line, int id, String expr) {
ReplayableCfBreakpointRequest(RawIdePath ideAbsPath, CanonicalServerAbsPath serverAbsPath, int line, DapBreakpointID id, String expr) {
this.ideAbsPath = ideAbsPath;
this.serverAbsPath = serverAbsPath;
this.line = line;
Expand All @@ -153,7 +154,7 @@ public boolean equals(Object vv) {
this.maybeNull_jdwpBreakpointRequest = null;
}

ReplayableCfBreakpointRequest(RawIdePath ideAbsPath, CanonicalServerAbsPath serverAbsPath, int line, int id, String expr, BreakpointRequest jdwpBreakpointRequest) {
ReplayableCfBreakpointRequest(RawIdePath ideAbsPath, CanonicalServerAbsPath serverAbsPath, int line, DapBreakpointID id, String expr, BreakpointRequest jdwpBreakpointRequest) {
this.ideAbsPath = ideAbsPath;
this.serverAbsPath = serverAbsPath;
this.line = line;
Expand Down Expand Up @@ -471,14 +472,14 @@ public LuceeVm(Config config, VirtualMachine vm) {
private static enum SteppingState { stepping, finalizingViaAwaitedBreakpoint }
private ConcurrentMap<JdwpThreadID, SteppingState> steppingStatesByThread = new ConcurrentHashMap<>();
private Consumer<JdwpThreadID> stepEventCallback = null;
private BiConsumer<JdwpThreadID, /*breakpoint ID*/ Integer> breakpointEventCallback = null;
private BiConsumer<JdwpThreadID, DapBreakpointID> breakpointEventCallback = null;
private Consumer<BreakpointsChangedEvent> breakpointsChangedCallback = null;

public void registerStepEventCallback(Consumer<JdwpThreadID> cb) {
stepEventCallback = cb;
}

public void registerBreakpointEventCallback(BiConsumer<JdwpThreadID, Integer> cb) {
public void registerBreakpointEventCallback(BiConsumer<JdwpThreadID, DapBreakpointID> cb) {
breakpointEventCallback = cb;
}

Expand Down Expand Up @@ -690,7 +691,7 @@ private void handleBreakpointEvent(BreakpointEvent event) {
}

if (breakpointEventCallback != null) {
final var bpID = (Integer) request.getProperty(LUCEEDEBUG_BREAKPOINT_ID);
final var bpID = (DapBreakpointID) request.getProperty(LUCEEDEBUG_BREAKPOINT_ID);
breakpointEventCallback.accept(threadID, bpID);
}
}
Expand Down Expand Up @@ -727,8 +728,8 @@ public IDebugEntity[] getIndexedVariables(long ID) {
}

private AtomicInteger breakpointID = new AtomicInteger();
private int nextBreakpointID() {
return breakpointID.incrementAndGet();
private DapBreakpointID nextDapBreakpointID() {
return new DapBreakpointID(breakpointID.incrementAndGet());
}

public void rebindBreakpoints(CanonicalServerAbsPath serverAbsPath, Collection<ReplayableCfBreakpointRequest> cfBpRequests) {
Expand All @@ -743,10 +744,10 @@ static class BpLineAndId {
final RawIdePath ideAbsPath;
final CanonicalServerAbsPath serverAbsPath;
final int line;
final int id;
final DapBreakpointID id;
final String expr;

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

int id = iife(() -> {
DapBreakpointID id = iife(() -> {
if (bpInfo == null) {
return nextBreakpointID();
return nextDapBreakpointID();
}
for (var z : bpInfo) {
if (z.line == line) {
return z.id;
}
}
return nextBreakpointID();
return nextDapBreakpointID();
});

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

0 comments on commit aef7585

Please sign in to comment.