Skip to content

Log points to easily dump content of local variables - #9732

Open
jtulach wants to merge 5 commits into
apache:masterfrom
jtulach:jtulach/LogPoints
Open

jtulach wants to merge 5 commits into
apache:masterfrom
jtulach:jtulach/LogPoints

Conversation

@jtulach

@jtulach jtulach commented Oct 19, 2026

Copy link
Copy Markdown
Contributor
  • NetBeans IDE already supports log points
    • yet configuring them isn't easy (especially for debugging newbies)
  • this PR proposes an extra action "Add Logpoint"
log point action
  • the log point is just properly configured breakpoint
    • doesn't stop any thread when hit
    • asks to dump all local variables into "debugger console" everytime it is hit
  • e.g. prints multiple times when put into a for loop
log points
  • to make the configuratin easy a new {locals} directive in setPrintText message is recognized
    • to simplify the most common case
    • e.g. when one dumps all local variables of a method

@jtulach jtulach self-assigned this Oct 19, 2026
@jtulach jtulach added Java [ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form) debugger labels Oct 19, 2026
@jtulach jtulach added this to the NB33 milestone Oct 19, 2026
io.printWithAction(" = ", null, false);
if (refValue instanceof ObjectVariable obj && !isNull(obj)) {
var sessionRef = new WeakReference<>(session);
io.printWithAction(obj.getValue(), () -> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hyperlink captures an ObjectLocalVariable wrapper that NetBeans reuses and updates. When a loop assigns another object to the same local, earlier links retain their original text but target the newer object. A temporary native test reproduced this: the first hyperlink’s object ID changed from 89 to 97. Capture a stable object reference when creating the link.

@jtulach jtulach Oct 19, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

..temporary native test reporduced this ...

I don't understand. What is the test doing? True tests were missing, but I've just added one in 15eb8c4. It passes. What's the problem with the ObjectLocalVariable? Following code seems to be logging value of fac array properly:

fac array

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for editing your comment, newly using GH PR extension in VS Code and it has some editing specialities....
LogpointReviewTests.zip this is quick and dirty review regression test.

cp LogpointReviewTest.java to java/debugger.jpda.ui/test/unit/src/org/netbeans/modules/debugger/jpda/ui/

cp LogpointReviewMain.java to java/debugger.jpda.ui/test/unit/src/test/
Set: review_jvm_flags="$(cat nbbuild/jms-config/{base,desktop,compiler}.flags | tr '\n' ' ')"
Run then:

ANT_OPTS=-Djava.awt.headless=true \
ant -f java/debugger.jpda.ui/build.xml test-unit \
  -Dtest.includes='**/LogpointReviewTest.class' \
  -Dtest.qa-functional.src.dir=/tmp/pr9732-no-tests \
  "-Dtest.run.args=-ea -Djava.awt.headless=true -XX:+IgnoreUnrecognizedVMOptions $review_jvm_flags"

Should fail with something like: Earlier hyperlink should still target the first object expected:<89> but was:<97>
ID/numbers can differ for your run. Hope this helps

@MartinBalin MartinBalin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left 2 comments

)
@ActionReferences({
@ActionReference(path = "Editors/text/x-java/Popup", position = 1900),
@ActionReference(path = "Editors/AnnotationTypes/BreakpointActionsWithToggleNew", position = 400)

@jtulach jtulach Oct 19, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this Editors/AnnotationTypes/BreakpointActionsWithToggleNew registration we now see the action in the editor gutter of the Java files:

Image

Non-Java editors like PHP don't show this action. It wouldn't work as it is using JPDABreakpoint functionality.

@jtulach
jtulach requested a review from MartinBalin October 19, 2026 18:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

debugger Java [ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants