Skip to content

Inspect all stratas to find a source file - #9433

Open
jtulach wants to merge 5 commits into
apache:masterfrom
jtulach:DebugKotlin
Open

jtulach wants to merge 5 commits into
apache:masterfrom
jtulach:DebugKotlin

Conversation

@jtulach

@jtulach jtulach commented Jun 8, 2026 •

Copy link
Copy Markdown
Contributor
  • this PR improves debugging of Kotlin source files
  • there is a test and a fix to handle multiple strata and pick them up ...
  • ... when no other means of locating right source worked out:
strata
  • to reproduce the problem locally please create a Hi.kt file:
    fun main() {
      throw java.lang.AssertionError("Hi from Kotlin")
    }
  • compile it by a Kotlin compiler. A HiKt.class gets generated
  • execute as
$ java -agentlib:jdwp=transport=dt_socket,address=5005,server=y HiKt
Listening for transport dt_socket at address: 5005
  • and attach NetBeans JPDA debugger to the process while having a breakpoint on AssertionError
  • with this fix the Hi.kt file is shown and highlights the right location
Hi.kit breakpoint

@jtulach jtulach self-assigned this Jun 8, 2026
@jtulach jtulach added Java [ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form) Kotlin debugger labels Jun 8, 2026
convertSlash (csf.getSourcePath (stratumn)), true
convertSlash (csf.getSourcePath (csf.getDefaultStratum())), true
);
for (var anyStratum : csf.getAvailableStrata()) {

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.

This fallback is only applied if url is still null after all previous attempts. E.g. this fallback shall not have any impact on cases where the URL was found previously.

In Kotlin sources, it seems to work OKeish - the line is selected according to Java strata (that good). However the debugger strata remains Kotlin. As such the current PC line isn't highlighted, just selected. Not ideal, but I am afraid to switch the strata behind the scene - who knows how that would work in JSPs, etc.?

@jtulach
jtulach requested a review from lahodaj June 9, 2026 09:41
private static final Pattern PACKAGE = Pattern.compile("package *([\\p{Alnum}+\\.$]+) *");
private void createNewBreakpoint(String url, int line, final DebuggerManager m) {
try {
var b = LineBreakpoint.create(url, line);

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.

This is a tedious piece of code that every JVM language needs to write to allow LineBreakpoint. I am convinced that LineBreakpoint should be a core debugger feature and should be applicable to any line in any file automatically.

That's why I'd like to introduce LineBreakpoint next to ide/api.debugger/src/org/netbeans/api/debugger/Breakpoint.java and automatically handle placing it everywhere (in .txt files, or .md files, etc.). It would then be up to various debuggers (like JPDA debugger) to pick all such generic LineBreakpoints up and use them.

Of course, that would be for a separate PR and review...

//

var sourcePath = new SourcePath(dm.getCurrentSession());
sourcePath.showSource(stack[0], null);

@jtulach jtulach Sep 24, 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.

  • unit testing debugging of Kotlin source
    -reproduces the scenario captured on this screenshot:
Hi.kit breakpoint

@jtulach

jtulach commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor Author

@eppleton

Copy link
Copy Markdown
Contributor

I built the PR and tested SourcePath.showSource with a Kotlin class compiled with an inline function, so it has an SMAP: strata [Java, Kotlin, KotlinDebug], default Kotlin. At the breakpoint the Java line is 9 and the Kotlin line is 2.

The PR removes stratumn = csf.getDefaultStratum() before the default-stratum lookup. When the requested stratum has no source but the default one does, like with JSP servlet situation, the editor now opens the default stratum's file at the requested stratum's line. In my test, requesting Java when only the Kotlin-stratum file exists opens it at line 9 on the PR, while master opens line 2. So the change also affects cases that worked before, not only those where no URL was found.

For Kotlin itself, the lookup fails because the SMAP's source path is HiKt (a class name). The PR finds the file through the Java stratum and keeps the Kotlin line, which works only because both strata point to the same file.

Also: BreakpointInKotlinTest uses a class without an SMAP, so only the Java stratum exists and the test passes on master too. And getURL(CallStackFrame, …), which the current-line annotation uses, still returns null for the Kotlin stratum.

@eppleton

eppleton commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

KotlinSmapDiagTest.java

@jtulach's note: Thanks, integrated as 20e867b

/**
* Content of a class file to test. File named {@code Hi.kt} with content {@link #KOTLIN_HI_SRC}
* Compiles into following bytes.
*/

@jtulach jtulach Sep 27, 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.

I've noticed @eppleton using Base64 in his sample test. Switching to it in 6e383fc as well. Thanks Toni!

@eppleton

Copy link
Copy Markdown
Contributor

The Kotlin case regressed: with diag.source=Hi.kt, showSource(frame, null) and showSource(frame, "Kotlin") now open Hi.kt:9 (previous PR version: line 2). The loop finds Hi.kt via the Java stratum and now sets stratumn = anyStratum, so the line comes from Java. For inline code, that is a synthetic line past the end of the file. The Kotlin stratum's line (2) is the correct one; the stratum just fails to resolve because its SMAP source path is HiKt (a class name), even though its source name is Hi.kt.

KotlinSmapDiagTest only prints its results and has no assertions, so it passes either way. It would be good to turn the SUMMARY into asserts: null/Kotlin → line 2 in Hi.kt; with only HiKt present, Java → line 2. Also getURL(frame, "Kotlin") should be non-null.

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) Kotlin

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants