eppleton commented on code in PR #9732:
URL: https://github.com/apache/netbeans/pull/9732#discussion_r4377438129


##########
java/debugger.jpda.ui/src/org/netbeans/modules/debugger/jpda/ui/actions/AddLogpointAction.java:
##########
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.debugger.jpda.ui.actions;
+
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import javax.swing.AbstractAction;
+import javax.swing.Action;
+import org.netbeans.api.debugger.DebuggerManager;
+import org.netbeans.api.debugger.jpda.JPDABreakpoint;
+import org.netbeans.api.debugger.jpda.LineBreakpoint;
+import org.netbeans.modules.debugger.jpda.ui.EditorContextBridge;
+import org.openide.awt.ActionID;
+import org.openide.awt.ActionReference;
+import org.openide.awt.ActionReferences;
+import org.openide.awt.ActionRegistration;
+import org.openide.awt.ActionState;
+import org.openide.loaders.DataObject;
+import org.openide.util.NbBundle.Messages;
+
+@ActionID(
+        category = "Debug",
+        id = "org.netbeans.modules.debugger.jpda.ui.actions.AddLogpointAction"
+)
+@ActionRegistration(
+        displayName = "#CTL_AddLogpointAction",
+        enabledOn = @ActionState( property = "hasJavaSource", type = 
Action.class )
+)
+@ActionReferences({
+    @ActionReference(path = "Editors/text/x-java/Popup", position = 1900),
+    @ActionReference(path = 
"Editors/AnnotationTypes/BreakpointActionsWithToggleNew", position = 400)

Review Comment:
   `BreakpointActionsWithToggleNew` is the popup of the existing *Breakpoint* 
annotation (`Breakpoint.xml` in spi.debugger.ui), so the entry only appears on 
a line that already has a breakpoint. "Add Logpoint" there adds a second 
breakpoint on the same line, so the line both stops and logs. Is that intended? 
On an existing breakpoint, I think users would expect "turn this into a 
logpoint" (set suspend to none and fill in the print text). The same applies to 
the editor popup on a line that already has a breakpoint.



##########
java/api.debugger.jpda/src/org/netbeans/api/debugger/jpda/Variable.java:
##########
@@ -61,5 +61,17 @@ public interface Variable {
      * @since 2.44
      */
     Object createMirrorObject();
-    
+
+    /** Creates an<em>immutable snapshot</em> of the variable.

Review Comment:
   The javadoc promises an *immutable snapshot* of the current state, but for 
objects the copy only keeps pointing at the same object. Its state is still 
live.
   
   I checked this locally on the PR head. A local held an object whose int 
field the program changed from 100 to 101 between two hits of the logpoint. At 
the second hit, the variable held by the first hit's hyperlink reported 101 
(same unique ID in both hits). That fits the code: 
`AbstractObjectVariable.clone()` reuses the same JDI `ObjectReference`, and 
`DebuggetStateListener` marks the fields for re-reading as soon as the debuggee 
resumes. Garbage collection isn't disabled either, so the object can also 
disappear later.
   
   So for a logpoint, clicking the link from iteration 1 shows the object as it 
is now, not as it was when the line was printed. Since this becomes public API, 
I'd describe what it actually guarantees: the copy keeps referring to the 
current value/object, regardless of what the original variable is reassigned to 
later. Two minor things: "an<em>immutable" is missing a space, and `toFixed` 
might remind people of JavaScript's `Number.toFixed`.



##########
java/debugger.jpda.ui/src/org/netbeans/modules/debugger/jpda/ui/BreakpointOutput.java:
##########
@@ -462,12 +456,53 @@ final void printExpressions(
             printText = printText + "\n***\n"+ 
thr.getLocalizedMessage()+"\n***\n";
         }
         // remaining of the text with a new line
-        println.accept(printText);
+        io.print(printText, null, true);
         for (var errors : dumpErrors) {
             errors.run();
         }
     }
 
+    final void printLocals(JPDABreakpointEvent event, BreakpointOutputWriter 
io) {
+        CallStackFrame csf = findTopFrame(event);
+        if (csf != null) {
+            try {
+                for (var refValue : csf.getLocalVariables()) {
+                    io.print("  ", null, false);
+                    io.print(refValue.getName(), null, false);
+                    io.print(" = ", null, false);
+                    if (refValue instanceof ObjectVariable ov && !isNull(ov) 
&& ov.toFixed() instanceof ObjectVariable obj) {

Review Comment:
   Something to keep in mind about memory (I haven't measured it): every hit 
creates a copy of each object local, and the console hyperlink keeps it alive. 
Each copy also registers a (weak) state listener on the debugger in the 
`AbstractObjectVariable` constructor. `{=expr}` already works this way, but 
`{locals}` multiplies it by the number of locals, and logpoints are meant to 
sit in loops. A logpoint in a hot loop would keep adding up for the whole 
session. Maybe this is acceptable, but it might be worth limiting how many 
linked hits are kept.



##########
java/debugger.jpda.ui/test/unit/src/org/netbeans/modules/debugger/jpda/ui/LogpointReviewTest.java:
##########
@@ -0,0 +1,117 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.debugger.jpda.ui;
+
+import java.io.File;
+import java.lang.reflect.Field;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicReference;
+import junit.framework.Test;
+import org.netbeans.api.debugger.DebuggerManager;
+import org.netbeans.api.debugger.jpda.ExceptionBreakpoint;
+import org.netbeans.api.debugger.jpda.JPDADebugger;
+import org.netbeans.api.debugger.jpda.JPDASupport;
+import org.netbeans.api.debugger.jpda.ObjectVariable;
+import org.netbeans.junit.NbTestCase;
+import org.openide.util.Utilities;
+
+public class LogpointReviewTest extends NbTestCase {

Review Comment:
   Good to have a regression test for the identity problem. Some suggestions 
for keeping it maintainable:
   - The names `LogpointReviewTest`/`LogpointReviewMain` describe how the test 
came about rather than what it checks.
   - It reads private console internals by reflection (`output`, `ioManager`, 
`buffer`, `text`, `action`) plus the lambda's captured fields, so any 
refactoring of the console IO will break it.
   - It sets the global `test.dir.src` property.
   
   Could it go into `BreakpointOutputTest`, driving `printLocals` through the 
new `BreakpointOutputWriter`? That would at least avoid depending on the 
console internals.



##########
java/debugger.jpda.ui/src/org/netbeans/modules/debugger/jpda/ui/BreakpointOutput.java:
##########
@@ -375,13 +375,18 @@ private void printOutEvent(DebuggerConsoleIO io, String 
format, JPDABreakpointEv
                 printText = selectCondition(printText, threadStartedCondition, 
false);
             }
         }
+
+        int printLocals = printText.indexOf(localsPattern);

Review Comment:
   Minor points about `{locals}`:
   - It is removed from wherever it appears, and the locals are always printed 
after the message.
   - Only the first occurrence is removed; a second `{locals}` is printed 
literally.
   
   Both are fine if documented, but I couldn't find `{locals}` mentioned 
anywhere a user would see it, e.g. near the print text field in the breakpoint 
customizer.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to