Skip to content

Commit 84d5ba6

Browse files
don't push frames while pushing frames
1 parent 66a14bc commit 84d5ba6

File tree

7 files changed

+467
-411
lines changed

7 files changed

+467
-411
lines changed

luceedebug/src/main/java/luceedebug/Agent.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@ private static Map<String, Integer> linearizedCoreInjectClasses() {
155155
result.put("luceedebug.coreinject.DebugManager$1", 0);
156156
result.put("luceedebug.coreinject.ClosureScopeLocalScopeAccessorShim", 0);
157157
result.put("luceedebug.coreinject.ComponentScopeMarkerTraitShim", 0);
158-
result.put("luceedebug.coreinject.DebugFrame$FrameContext", 0);
159158
result.put("luceedebug.coreinject.LuceeVm$SteppingState", 0);
160159
result.put("luceedebug.coreinject.LuceeVm$KlassMap", 0);
161160
result.put("luceedebug.coreinject.LuceeVm$JdwpWorker", 0);
@@ -165,21 +164,25 @@ private static Map<String, Integer> linearizedCoreInjectClasses() {
165164
result.put("luceedebug.coreinject.CfValueDebuggerBridge$MarkerTrait", 0);
166165
result.put("luceedebug.coreinject.ValTracker", 0);
167166
result.put("luceedebug.coreinject.UnsafeUtils", 0);
168-
result.put("luceedebug.coreinject.DebugFrame", 0);
169167
result.put("luceedebug.coreinject.CfValueDebuggerBridge$MarkerTrait$Scope", 0);
170168
result.put("luceedebug.coreinject.DebugManager$PageContextAndOutputStream", 0);
171169
result.put("luceedebug.coreinject.LuceeVm$ThreadMap", 0);
172170
result.put("luceedebug.coreinject.DebugManager", 0);
173171
result.put("luceedebug.coreinject.LuceeVm$JdwpStaticCallable", 0);
174172
result.put("luceedebug.coreinject.CfValueDebuggerBridge", 0);
175-
result.put("luceedebug.coreinject.DebugFrame$FrameContext$SupplierOrNull", 0);
176173
result.put("luceedebug.coreinject.LuceeVm", 0);
177174
result.put("luceedebug.coreinject.ValTracker$CleanerRunner", 0);
178175
result.put("luceedebug.coreinject.ExprEvaluator", 0);
179176

180177
result.put("luceedebug.coreinject.ExprEvaluator$Evaluator", 0);
181178
result.put("luceedebug.coreinject.ExprEvaluator$Lucee6Evaluator", 1);
182179
result.put("luceedebug.coreinject.ExprEvaluator$Lucee5Evaluator", 1);
180+
181+
result.put("luceedebug.coreinject.frame.DebugFrame", 0);
182+
result.put("luceedebug.coreinject.frame.Frame", 1);
183+
result.put("luceedebug.coreinject.frame.Frame$FrameContext", 1);
184+
result.put("luceedebug.coreinject.frame.Frame$FrameContext$SupplierOrNull", 1);
185+
result.put("luceedebug.coreinject.frame.DummyFrame", 1);
183186

184187
return result;
185188
}

luceedebug/src/main/java/luceedebug/coreinject/CfValueDebuggerBridge.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import lucee.runtime.type.Array;
1616
import luceedebug.ICfValueDebuggerBridge;
1717
import luceedebug.IDebugEntity;
18-
import luceedebug.coreinject.frame.DebugFrame;
18+
import luceedebug.coreinject.frame.Frame;
1919

2020
public class CfValueDebuggerBridge implements ICfValueDebuggerBridge {
2121
// Pin some ephemeral evaluated things so they don't get GC'd immediately.
@@ -32,11 +32,11 @@ public static void pin(Object obj) {
3232
pinnedObjects.put(System.identityHashCode(obj), obj);
3333
}
3434

35-
private final DebugFrame frame;
35+
private final Frame frame;
3636
public final Object obj;
3737
public final long id;
3838

39-
public CfValueDebuggerBridge(DebugFrame frame, Object obj) {
39+
public CfValueDebuggerBridge(Frame frame, Object obj) {
4040
this.frame = Objects.requireNonNull(frame);
4141
this.obj = Objects.requireNonNull(obj);
4242
this.id = frame.valTracker.idempotentRegisterObject(obj).id;
@@ -58,7 +58,7 @@ public Scope(Map<?,?> scopelike) {
5858
/**
5959
* @maybeNull_which --> null means "any type"
6060
*/
61-
public static IDebugEntity[] getAsDebugEntity(DebugFrame frame, Object obj, IDebugEntity.DebugEntityType maybeNull_which) {
61+
public static IDebugEntity[] getAsDebugEntity(Frame frame, Object obj, IDebugEntity.DebugEntityType maybeNull_which) {
6262
return getAsDebugEntity(frame.valTracker, obj, maybeNull_which);
6363
}
6464

luceedebug/src/main/java/luceedebug/coreinject/DebugManager.java

Lines changed: 52 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import luceedebug.IDebugFrame;
3434
import luceedebug.IDebugManager;
3535
import luceedebug.coreinject.frame.DebugFrame;
36+
import luceedebug.coreinject.frame.Frame;
3637

3738
public class DebugManager implements IDebugManager {
3839

@@ -328,36 +329,37 @@ synchronized private String doDumpAsJSON(PageContext pageContext, Object someDum
328329
}
329330

330331
public Either</*err*/String, /*ok*/Either<ICfValueDebuggerBridge, String>> evaluate(Long frameID, String expr) {
331-
final var frame = frameByFrameID.get(frameID);
332-
if (frame != null) {
333-
return doEvaluate(frame, expr)
334-
.bimap(
335-
err -> err,
336-
ok -> {
337-
// what about bool, Long, etc. ?...
338-
if (ok == null) {
339-
return Either.Right("null");
340-
}
341-
else if (ok instanceof String) {
342-
return Either.Right("\"" + ((String)ok).replaceAll("\"", "\\\"") + "\"");
343-
}
344-
else if (ok instanceof Number || ok instanceof Boolean) {
345-
return Either.Right(ok.toString());
346-
}
347-
else {
348-
return Either.Left(frame.trackEvalResult(ok));
349-
}
350-
}
351-
);
352-
}
353-
else {
332+
final var zzzframe = frameByFrameID.get(frameID);
333+
if (!(zzzframe instanceof Frame)) {
354334
return Either.Left("<<no such frame>>");
355335
}
336+
337+
Frame frame = (Frame)zzzframe;
338+
339+
return doEvaluate(frame, expr)
340+
.bimap(
341+
err -> err,
342+
ok -> {
343+
// what about bool, Long, etc. ?...
344+
if (ok == null) {
345+
return Either.Right("null");
346+
}
347+
else if (ok instanceof String) {
348+
return Either.Right("\"" + ((String)ok).replaceAll("\"", "\\\"") + "\"");
349+
}
350+
else if (ok instanceof Number || ok instanceof Boolean) {
351+
return Either.Right(ok.toString());
352+
}
353+
else {
354+
return Either.Left(frame.trackEvalResult(ok));
355+
}
356+
}
357+
);
356358
}
357359

358360
// concurrency here needs to be at the level of the DAP server?
359361
// does the DAP server do multiple concurrent requests ... ? ... it's all one socket so probably not ? ... well many inbound messages can be being serviced ...
360-
private Either</*err*/String, /*ok*/Object> doEvaluate(DebugFrame frame, String expr) {
362+
private Either</*err*/String, /*ok*/Object> doEvaluate(Frame frame, String expr) {
361363
try {
362364
return CompletableFuture
363365
.supplyAsync(
@@ -392,10 +394,18 @@ public boolean evaluateAsBooleanForConditionalBreakpoint(Thread thread, String e
392394
if (stack.isEmpty()) {
393395
return false;
394396
}
395-
return doEvaluateAsBoolean(stack.get(stack.size() - 1), expr);
397+
398+
DebugFrame frame = stack.get(stack.size() - 1);
399+
400+
if (frame instanceof Frame) {
401+
return doEvaluateAsBoolean((Frame)frame, expr);
402+
}
403+
else {
404+
return false;
405+
}
396406
}
397407

398-
private boolean doEvaluateAsBoolean(DebugFrame frame, String expr) {
408+
private boolean doEvaluateAsBoolean(Frame frame, String expr) {
399409
try {
400410
return CompletableFuture
401411
.supplyAsync(
@@ -482,7 +492,7 @@ synchronized public IDebugFrame[] getCfStack(Thread thread) {
482492
if (stack == null) {
483493
System.out.println("getCfStack called, frames was null, frames is " + cfStackByThread + ", passed thread was " + thread);
484494
System.out.println(" thread=" + thread + " this=" + this);
485-
return new DebugFrame[0];
495+
return new Frame[0];
486496
}
487497

488498
ArrayList<DebugFrame> result = new ArrayList<>();
@@ -501,7 +511,7 @@ synchronized public IDebugFrame[] getCfStack(Thread thread) {
501511
}
502512
}
503513

504-
return result.toArray(new DebugFrame[result.size()]);
514+
return result.toArray(new Frame[result.size()]);
505515
}
506516

507517
static class CfStepRequest {
@@ -570,9 +580,12 @@ public void luceedebug_stepNotificationEntry_step(int lineNumber) {
570580
if (request == null) {
571581
return;
572582
}
573-
else {
583+
else if (frame instanceof Frame) {
574584
request.__debug__steps++;
575-
maybeNotifyOfStepCompletion(currentThread, frame, request, minDistanceToLuceedebugStepNotificationEntryFrame + 1, System.nanoTime());
585+
maybeNotifyOfStepCompletion(currentThread, (Frame) frame, request, minDistanceToLuceedebugStepNotificationEntryFrame + 1, System.nanoTime());
586+
}
587+
else {
588+
// no-op
576589
}
577590
}
578591

@@ -596,13 +609,16 @@ public void luceedebug_stepNotificationEntry_stepAfterCompletedUdfCall() {
596609
if (request == null) {
597610
return;
598611
}
599-
else {
612+
else if (frame instanceof Frame) {
600613
request.__debug__steps++;
601-
maybeNotifyOfStepCompletion(currentThread, frame, request, minDistanceToLuceedebugStepNotificationEntryFrame + 1, System.nanoTime());
614+
maybeNotifyOfStepCompletion(currentThread, (Frame)frame, request, minDistanceToLuceedebugStepNotificationEntryFrame + 1, System.nanoTime());
615+
}
616+
else {
617+
// no-op
602618
}
603619
}
604620

605-
private void maybeNotifyOfStepCompletion(Thread currentThread, DebugFrame frame, CfStepRequest request, int minDistanceToLuceedebugStepNotificationEntryFrame, long start) {
621+
private void maybeNotifyOfStepCompletion(Thread currentThread, Frame frame, CfStepRequest request, int minDistanceToLuceedebugStepNotificationEntryFrame, long start) {
606622
if (frame.isUdfDefaultValueInitFrame && !config_.getStepIntoUdfDefaultValueInitFrames()) {
607623
return;
608624
}
@@ -683,11 +699,7 @@ private DebugFrame maybe_pushCfFrame_worker(PageContext pageContext, String sour
683699

684700
final int depth = stack.size(); // first frame is frame 0, and prior to pushing the first frame the stack is length 0; next frame is frame 1, and prior to pushing it the stack is of length 1, ...
685701

686-
final DebugFrame frame = DebugFrame.maybeMakeFrame(sourceFilePath, depth, valTracker, pageContext);
687-
688-
if (frame == null) {
689-
return null;
690-
}
702+
final DebugFrame frame = DebugFrame.makeFrame(sourceFilePath, depth, valTracker, pageContext);
691703

692704
stack.add(frame);
693705

@@ -703,11 +715,9 @@ private DebugFrame maybe_pushCfFrame_worker(PageContext pageContext, String sour
703715

704716
public void pushCfFunctionDefaultValueInitializationFrame(lucee.runtime.PageContext pageContext, String sourceFilePath) {
705717
DebugFrame frame = maybe_pushCfFrame_worker(pageContext, sourceFilePath);
706-
if (frame == null) {
707-
return;
718+
if (frame instanceof Frame) {
719+
((Frame)frame).isUdfDefaultValueInitFrame = true;
708720
}
709-
710-
frame.isUdfDefaultValueInitFrame = true;
711721
}
712722

713723
public void popCfFrame() {

luceedebug/src/main/java/luceedebug/coreinject/ExprEvaluator.java

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

99
import lucee.runtime.PageContext;
1010
import luceedebug.Either;
11-
import luceedebug.coreinject.frame.DebugFrame;
11+
import luceedebug.coreinject.frame.Frame;
1212

1313
import static luceedebug.coreinject.Utils.terminate;
1414

@@ -27,7 +27,7 @@ class ExprEvaluator {
2727
}
2828
}
2929

30-
public static Either</*err*/String, /*ok*/Object> eval(DebugFrame frame, String expr) {
30+
public static Either</*err*/String, /*ok*/Object> eval(Frame frame, String expr) {
3131
return lucee5
3232
.map(v -> v.eval(frame, expr))
3333
.or(() -> lucee6.map(v -> v.eval(frame, expr)))
@@ -52,9 +52,9 @@ static protected String getEvaluatableSourceText(String expr) {
5252
+ "</cfscript>";
5353
}
5454

55-
protected abstract void evalIntoVariablesScope(DebugFrame frame, String expr) throws Throwable;
55+
protected abstract void evalIntoVariablesScope(Frame frame, String expr) throws Throwable;
5656

57-
public Either</*err*/String, /*ok*/Object> eval(DebugFrame frame, String expr) {
57+
public Either</*err*/String, /*ok*/Object> eval(Frame frame, String expr) {
5858
try {
5959
evalIntoVariablesScope(frame, expr);
6060
var obj = consumeResult(frame);
@@ -68,7 +68,7 @@ static protected String getEvaluatableSourceText(String expr) {
6868
/**
6969
* get the eval'd result out of the frame's variables scope and then delete it from the variables scope.
7070
*/
71-
private Object consumeResult(DebugFrame frame) throws Throwable {
71+
private Object consumeResult(Frame frame) throws Throwable {
7272
Object evalResult = UnsafeUtils.deprecatedScopeGet(frame.getFrameContext().variables, resultName);
7373
frame.getFrameContext().variables.remove(resultName);
7474
return evalResult;
@@ -108,7 +108,7 @@ private static class Lucee5Evaluator extends Evaluator {
108108
this.methodHandle = methodHandle;
109109
}
110110

111-
protected void evalIntoVariablesScope(DebugFrame frame, String expr) throws Throwable {
111+
protected void evalIntoVariablesScope(Frame frame, String expr) throws Throwable {
112112
methodHandle.invoke(
113113
/*PageContext pc*/ frame.getFrameContext().pageContext,
114114
/*String cfml*/ Evaluator.getEvaluatableSourceText(expr),
@@ -148,7 +148,7 @@ private static class Lucee6Evaluator extends Evaluator {
148148
this.methodHandle = methodHandle;
149149
}
150150

151-
protected void evalIntoVariablesScope(DebugFrame frame, String expr) throws Throwable {
151+
protected void evalIntoVariablesScope(Frame frame, String expr) throws Throwable {
152152
methodHandle.invoke(
153153
/*PageContext pc*/ frame.getFrameContext().pageContext,
154154
/*String cfml*/ Evaluator.getEvaluatableSourceText(expr),

0 commit comments

Comments
 (0)