eppleton commented on code in PR #9691:
URL: https://github.com/apache/netbeans/pull/9691#discussion_r4246121033
##########
java/debugger.jpda.ui/src/org/netbeans/modules/debugger/jpda/ui/BreakpointOutput.java:
##########
@@ -397,43 +400,44 @@ private String substitute (String printText,
JPDABreakpointEvent event) {
}
} catch (AbsentInformationException aiex) {}
}
- try {
- value = ((Variable)
theDebugger.getClass().getMethod("evaluate", String.class,
CallStackFrame.class).
- invoke(theDebugger, expression, csf)).getValue();
- } catch (InvocationTargetException itex) {
- if (itex.getTargetException() instanceof
InvalidExpressionException) {
- throw (InvalidExpressionException)
itex.getTargetException();
- }
- } catch (Exception ex) {
- Exceptions.printStackTrace(ex);
+ Variable refValue = theDebugger.evaluate(expression, csf);
+ if (refValue instanceof ObjectVariable obj) {
+ io.printWithAction(" " + obj.getType() + " " + expression
+ " = ", null, false);
+ var sessionRef = new WeakReference<>(session);
+ io.printWithAction("#" + obj.getUniqueID(), () -> {
Review Comment:
The `WeakReference` to the session helps, but javap shows the lambda as
`lambda$printOutEvent$0(WeakReference, ObjectVariable, DebuggerConsoleIO)`, so
it still captures `obj` and `io` strongly. Both reach the debugger:
- `obj` is an `AbstractVariable`, which has `private JPDADebuggerImpl
debugger`, plus the JDI `Value`.
- `io` is `DebuggerConsoleIO`, which has `private final JPDADebuggerImpl
debugger`.
The output window keeps the listener:
`NbIOProvider.hyperlinkToOutputListener` wraps the `Hyperlink`, and
`AbstractLines` stores it per line. `DebuggerOutput` closes the old tab only
when a new session starts as the only session. A heap dump taken after starting
the next session therefore wouldn't show it. I traced this in the code and
haven't taken a heap dump myself, so it may be worth checking with the console
tab still open after the session ends.
Maybe hold `obj` weakly too, as `ShowObjectVariableInHeap` already does? The
"Cannot display details" fallback is the only reason to capture `io`.
##########
java/debugger.jpda.ui/src/org/netbeans/modules/debugger/jpda/ui/BreakpointOutput.java:
##########
@@ -397,43 +400,44 @@ private String substitute (String printText,
JPDABreakpointEvent event) {
}
} catch (AbsentInformationException aiex) {}
}
- try {
- value = ((Variable)
theDebugger.getClass().getMethod("evaluate", String.class,
CallStackFrame.class).
- invoke(theDebugger, expression, csf)).getValue();
- } catch (InvocationTargetException itex) {
- if (itex.getTargetException() instanceof
InvalidExpressionException) {
- throw (InvalidExpressionException)
itex.getTargetException();
- }
- } catch (Exception ex) {
- Exceptions.printStackTrace(ex);
+ Variable refValue = theDebugger.evaluate(expression, csf);
+ if (refValue instanceof ObjectVariable obj) {
+ io.printWithAction(" " + obj.getType() + " " + expression
+ " = ", null, false);
Review Comment:
Two questions about when this line is printed:
- `getUniqueID()` returns `0` for a `null` value and when the object was
collected or the VM disconnected. `HeapActionsFilter` returns early on `0`, but
here `#0` is printed as a link.
- Every object-valued `{=expr}`, including plain `String`s, now adds an
extra line before the log message itself, so existing log points get more
verbose output. Is that intended, or should the extra line be limited to the
cases where the Instances view adds something?
##########
java/debugger.jpda/src/org/netbeans/modules/debugger/jpda/console/DebuggerOutput.java:
##########
@@ -510,11 +507,23 @@ private void print (
return ;
}
}
+ findProvider();
Review Comment:
This looks like leftover debugging code. `findProvider()` runs on every
Debugger Console message: it does a `Class.forName` and a `LocalsView` lookup,
then prints `all: ...` to `System.err`.
##########
java/debugger.jpda/src/org/netbeans/modules/debugger/jpda/DebuggerConsoleIO.java:
##########
@@ -53,7 +54,18 @@ public void println(String text, Line line) {
public void println(String text, Line line, boolean important) {
output.getIOManager().println(text, line, important);
}
-
+
+ /** Prints a hyperlinked text and associates it with an action.
+ *
+ * @param text the text to print
+ * @param run action or {@code null} to invoke when the hyperlink is
clicked
+ * @param newLine add a new line after the text
+ * @since 1.144
+ */
+ public void printWithAction(@NonNull String text, Runnable run, boolean
newLine) {
Review Comment:
`debugger.jpda.ui` now calls this method (`@since 1.144`), but its
`project.xml` still declares
`<specification-version>1.81</specification-version>` for
`org.netbeans.modules.debugger.jpda`.
##########
java/debugger.jpda.ui/src/org/netbeans/modules/debugger/jpda/ui/BreakpointOutputDetails.java:
##########
@@ -0,0 +1,41 @@
+/*
+ * 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 org.netbeans.api.debugger.Session;
+import org.netbeans.api.debugger.jpda.ObjectVariable;
+
+
+/**
+ *
+ * @since 1.89
+ */
+public interface BreakpointOutputDetails {
+ public abstract boolean display(Session debugger, ObjectVariable v);
Review Comment:
Nits on this new (friend) interface:
- `public abstract` is redundant on an interface method.
- The `Session` parameter is still named `debugger`.
- The static `showObjectVariable` is now implicitly `public`, so it becomes
part of the interface's API.
- A line of javadoc saying when `display` is called and what `false` means
would help implementors.
--
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