Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions ide/spi.debugger.ui/apichanges.xml
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,21 @@
<class package="org.netbeans.spi.debugger.ui" name="DebuggingView"/>
</change>

<change id="DVFrameSourceMimeType">
<api name="DebuggerCoreSPI"/>
<summary>Source MIME type added to DVFrame.</summary>
<version major="2" minor="67"/>
<date day="30" month="11" year="2020"/>
<author login="mentlicher"/>
<compatibility binary="compatible" source="compatible" addition="yes" semantic="compatible"/>
<description>
<p>
<code>DebuggingView.DVFrame</code> provides source MIME type.
</p>
</description>
<class package="org.netbeans.spi.debugger.ui" name="DebuggingView"/>
</change>

</changes>

<!-- Now the surrounding HTML text and document structure: -->
Expand Down
2 changes: 1 addition & 1 deletion ide/spi.debugger.ui/manifest.mf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ Manifest-Version: 1.0
OpenIDE-Module: org.netbeans.spi.debugger.ui/1
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/debugger/ui/Bundle.properties
OpenIDE-Module-Layer: org/netbeans/modules/debugger/resources/mf-layer.xml
OpenIDE-Module-Specification-Version: 2.66
OpenIDE-Module-Specification-Version: 2.67
OpenIDE-Module-Provides: org.netbeans.spi.debugger.ui
OpenIDE-Module-Install: org/netbeans/modules/debugger/ui/DebuggerModule.class
Original file line number Diff line number Diff line change
Expand Up @@ -477,12 +477,22 @@ public static interface DVFrame {
void makeCurrent();

/**
* Gen URI of the source file associated with this frame, if any.
* Get URI of the source file associated with this frame, if any.
* @return a source URI, or <code>null</code> if the file is unknown.
* @since 2.65
*/
URI getSourceURI();

/**
* Get the source MIME type, if known.
* @return the source MIME type, or <code>null</code> if the source, or
* its MIME type is unknown.
* @since 2.67
*/
default String getSourceMimeType() {
return null;
}

/**
* Line location of the frame in the source code at {@link #getSourceURI()}.
*
Expand Down
2 changes: 1 addition & 1 deletion java/debugger.jpda.truffle/nbproject/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
<compile-dependency/>
<run-dependency>
<release-version>1</release-version>
<specification-version>2.65</specification-version>
<specification-version>2.67</specification-version>
</run-dependency>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public class TruffleAccess implements JPDABreakpointListener {
private static final String VAR_FRAME = "frame"; // NOI18N
private static final String VAR_SRC_ID = "id"; // NOI18N
private static final String VAR_SRC_URI = "uri"; // NOI18N
private static final String VAR_SRC_MIMETYPE = "mimeType"; // NOI18N
private static final String VAR_SRC_NAME = "name"; // NOI18N
private static final String VAR_SRC_PATH = "path"; // NOI18N
private static final String VAR_SRC_SOURCESECTION = "sourceSection"; // NOI18N
Expand Down Expand Up @@ -308,8 +309,9 @@ public static SourcePosition getSourcePosition(JPDADebugger debugger, ObjectVari
String name = (String) sourcePositionVar.getField(VAR_SRC_NAME).createMirrorObject();
String path = (String) sourcePositionVar.getField(VAR_SRC_PATH).createMirrorObject();
URI uri = (URI) sourcePositionVar.getField(VAR_SRC_URI).createMirrorObject();
String mimeType = (String) sourcePositionVar.getField(VAR_SRC_MIMETYPE).createMirrorObject();
StringReference codeRef = (StringReference) ((JDIVariable) sourcePositionVar.getField(VAR_SRC_CODE)).getJDIValue();
src = Source.getSource(debugger, id, name, path, uri, codeRef);
src = Source.getSource(debugger, id, name, path, uri, mimeType, codeRef);
}
return new SourcePosition(debugger, id, src, sourceSection);
}
Expand Down Expand Up @@ -408,6 +410,7 @@ private static SourcePosition parseSource(JPDADebugger debugger, String sourceDe
String sourceName;
String sourcePath;
URI sourceURI;
String mimeType;
String sourceSection;
try {
int i1 = 0;
Expand All @@ -428,14 +431,17 @@ private static SourcePosition parseSource(JPDADebugger debugger, String sourceDe
}
i1 = i2 + 1;
i2 = sourceDef.indexOf('\n', i1);
mimeType = sourceDef.substring(i1, i2);
i1 = i2 + 1;
i2 = sourceDef.indexOf('\n', i1);
if (i2 < 0) {
i2 = sourceDef.length();
}
sourceSection = sourceDef.substring(i1, i2);
} catch (IndexOutOfBoundsException ioob) {
throw new IllegalStateException("var source definition='"+sourceDef+"'", ioob);
}
Source src = Source.getSource(debugger, sourceId, sourceName, sourcePath, sourceURI, codeRef);
Source src = Source.getSource(debugger, sourceId, sourceName, sourcePath, sourceURI, mimeType, codeRef);
return new SourcePosition(debugger, sourceId, src, sourceSection);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import com.sun.jdi.AbsentInformationException;
import com.sun.jdi.ArrayReference;
import com.sun.jdi.BooleanValue;
import com.sun.jdi.ClassNotLoadedException;
import com.sun.jdi.ClassType;
import com.sun.jdi.IncompatibleThreadStateException;
Expand Down Expand Up @@ -192,6 +193,12 @@ public void submitBreakpoints(ClassType accessorClass, ObjectReference debugMana
if (bp.isEnabled()) {
bpImpl = setLineBreakpoint(debugManager, t, uri, bp.getLineNumber(),
getIgnoreCount(bp), bp.getCondition());
// Find out whether the breakpoint was resolved already during the submission:
try {
updateResolved(bp, bpImpl, t.getThreadReference());
} catch (Exception ex) {
Exceptions.printStackTrace(Exceptions.attachMessage(ex, "Testing resolved breakpoint at "+uri+":"+bp.getLineNumber()));
}
} else {
bpImpl = null;
}
Expand All @@ -210,6 +217,15 @@ public void submitBreakpoints(ClassType accessorClass, ObjectReference debugMana
}
}

private void updateResolved(JSLineBreakpoint breakpoint, ObjectReference bp, ThreadReference tr) throws InternalExceptionWrapper, VMDisconnectedExceptionWrapper, ClassNotPreparedExceptionWrapper, InvalidTypeException, ClassNotLoadedException, IncompatibleThreadStateException, InvocationException, ObjectCollectedExceptionWrapper {
ClassType breakpointClass = (ClassType) bp.referenceType();
Method isResolvedMethod = ClassTypeWrapper.concreteMethodByName(breakpointClass, "isResolved", "()Z");
BooleanValue isResolvedValue = (BooleanValue) ObjectReferenceWrapper.invokeMethod(bp, tr, isResolvedMethod, Collections.emptyList(), ObjectReference.INVOKE_SINGLE_THREADED);
if (isResolvedValue.value()) {
JSBreakpointStatus.setValid(breakpoint, "resolved");
}
}

private static int getIgnoreCount(JSLineBreakpoint bp) {
int ignoreCount = 0;
if (Breakpoint.HIT_COUNT_FILTERING_STYLE.GREATER.equals(bp.getHitCountFilteringStyle())) {
Expand Down Expand Up @@ -301,10 +317,16 @@ public void callMethods(JPDAThread thread) throws InvocationException {
ObjectReference.INVOKE_SINGLE_THREADED);
ret.disableCollection();
bpRef[0] = ret;
// Find out whether the breakpoint was resolved already during the submission:
for (Value v : ret.getValues()) {
if (v instanceof ObjectReference) {
updateResolved(bp, (ObjectReference) v, tr);
}
}
} catch (InvalidTypeException | ClassNotLoadedException |
IncompatibleThreadStateException | UnsupportedOperationExceptionWrapper |
InternalExceptionWrapper | VMDisconnectedExceptionWrapper |
ObjectCollectedExceptionWrapper ex) {
ObjectCollectedExceptionWrapper | ClassNotPreparedExceptionWrapper ex) {
Exceptions.printStackTrace(Exceptions.attachMessage(ex, "Setting breakpoint to "+uri+":"+line));
} finally {
persistents.collect();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public final class TruffleStackFrame {
private final String sourceName;
private final String sourcePath;
private final URI sourceURI;
private final String mimeType;
private final String sourceSection;
private final StringReference codeRef;
private TruffleScope[] scopes;
Expand Down Expand Up @@ -111,6 +112,9 @@ public TruffleStackFrame(JPDADebugger debugger, JPDAThread thread, int depth,
throw new IllegalStateException("Bad URI: "+frameDefinition.substring(i1, i2), usex);
}
i1 = i2 + 1;
i2 = frameDefinition.indexOf('\n', i1);
mimeType = frameDefinition.substring(i1, i2);
i1 = i2 + 1;
if (includeInternal) {
i2 = frameDefinition.indexOf('\n', i1);
sourceSection = frameDefinition.substring(i1, i2);
Expand Down Expand Up @@ -163,7 +167,7 @@ public String getDisplayName() {
public SourcePosition getSourcePosition() {
Source src = Source.getExistingSource(debugger, sourceId);
if (src == null) {
src = Source.getSource(debugger, sourceId, sourceName, sourcePath, sourceURI, codeRef);
src = Source.getSource(debugger, sourceId, sourceName, sourcePath, sourceURI, mimeType, codeRef);
}
SourcePosition sp = new SourcePosition(debugger, sourceId, src, sourceSection);
return sp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
package org.netbeans.modules.debugger.jpda.truffle.frames.models;

import java.net.URI;
import java.net.URISyntaxException;
import org.netbeans.modules.debugger.jpda.truffle.access.CurrentPCInfo;
import org.netbeans.modules.debugger.jpda.truffle.access.TruffleAccess;
import org.netbeans.modules.debugger.jpda.truffle.frames.TruffleStackFrame;
import org.netbeans.modules.debugger.jpda.truffle.source.Source;
import org.netbeans.spi.debugger.ui.DebuggingView.DVFrame;
import org.netbeans.spi.debugger.ui.DebuggingView.DVThread;

Expand Down Expand Up @@ -63,7 +65,22 @@ public void makeCurrent() {

@Override
public URI getSourceURI() {
return truffleFrame.getSourcePosition().getSource().getURI();
Source source = truffleFrame.getSourcePosition().getSource();
URI uri = source.getURI();
if (uri != null && "file".equalsIgnoreCase(uri.getScheme())) {
return uri;
}
try {
return source.getUrl().toURI();
} catch (URISyntaxException ex) {
return null;
}
}

@Override
public String getSourceMimeType() {
Source source = truffleFrame.getSourcePosition().getSource();
return source.getMimeType();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@ public final class Source {
private final String name;
private final URI uri; // The original source URI
private final URL url; // The source
private final String mimeType;
private final long hash;
private String content;

private Source(JPDADebugger jpda, String name, URI uri, long hash, StringReference codeRef) {
private Source(JPDADebugger jpda, String name, URI uri, String mimeType, long hash, StringReference codeRef) {
this.name = name;
this.codeRef = codeRef;
URL url = null;
Expand All @@ -76,6 +77,7 @@ private Source(JPDADebugger jpda, String name, URI uri, long hash, StringReferen
}
this.url = url;
this.uri = uri;
this.mimeType = mimeType;
this.hash = hash;
}

Expand Down Expand Up @@ -119,6 +121,15 @@ public static Source getSource(JPDADebugger debugger, long id,
String path,
URI uri,
StringReference codeRef) {
return getSource(debugger, id, name, path, uri, null, codeRef);
}

public static Source getSource(JPDADebugger debugger, long id,
String name,
String path,
URI uri,
String mimeType,
StringReference codeRef) {
synchronized (KNOWN_SOURCES) {
Map<Long, Source> dbgSources = KNOWN_SOURCES.get(debugger);
if (dbgSources != null) {
Expand All @@ -128,16 +139,17 @@ public static Source getSource(JPDADebugger debugger, long id,
}
}
}
return getTheSource(debugger, id, name, path, uri, codeRef);
return getTheSource(debugger, id, name, path, uri, mimeType, codeRef);
}

private static Source getTheSource(JPDADebugger debugger, long id,
String name,
String path,
URI uri,
String mimeType,
StringReference codeRef) {

Source src = new Source(debugger, name, uri, id, codeRef);
Source src = new Source(debugger, name, uri, mimeType, id, codeRef);
synchronized (KNOWN_SOURCES) {
Map<Long, Source> dbgSources = KNOWN_SOURCES.get(debugger);
if (dbgSources == null) {
Expand All @@ -161,6 +173,10 @@ public URI getURI() {
return uri;
}

public String getMimeType() {
return mimeType;
}

public long getHash() {
return hash;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ final class FrameInfo {

FrameInfo(DebugStackFrame topStackFrame, Iterable<DebugStackFrame> stackFrames) {
SourceSection topSS = topStackFrame.getSourceSection();
SourcePosition position = new SourcePosition(topSS);
SourcePosition position = new SourcePosition(topSS, topStackFrame.getLanguage());
ArrayList<DebugStackFrame> stackFramesArray = new ArrayList<>();
for (DebugStackFrame sf : stackFrames) {
if (sf == topStackFrame) {
Expand All @@ -61,7 +61,7 @@ final class FrameInfo {
((sfLang != null) ? sfLang.getId() + " " + sfLang.getName() : "") + "\n" +
DebuggerVisualizer.getSourceLocation(topSS) + "\n" +
position.id + "\n" + position.name + "\n" + position.path + "\n" +
position.uri.toString() + "\n" + position.sourceSection +/* "," + position.startColumn + "," +
position.uri.toString() + "\n" + position.mimeType + "\n" + position.sourceSection +/* "," + position.startColumn + "," +
position.endLine + "," + position.endColumn +*/ "\n" + isInternal(topStackFrame);
topVariables = JPDATruffleAccessor.getVariables(topStackFrame);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public final class GuestObject {
SourceSection sourceLocation = value.getSourceLocation();
//System.err.println("\nSOURCE of "+value.getName()+" is: "+sourceLocation);
if (sourceLocation != null && sourceLocation.isAvailable()) {
sp = new SourcePosition(sourceLocation);
sp = new SourcePosition(sourceLocation, value.getOriginalLanguage());
}
} catch (ThreadDeath td) {
throw td;
Expand All @@ -159,7 +159,7 @@ public final class GuestObject {
SourceSection sourceLocation = metaObject.getSourceLocation();
//System.err.println("\nSOURCE of metaobject "+metaObject+" is: "+sourceLocation);
if (sourceLocation != null && sourceLocation.isAvailable()) {
sp = new SourcePosition(sourceLocation);
sp = new SourcePosition(sourceLocation, value.getOriginalLanguage());
}
} catch (ThreadDeath td) {
throw td;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ static Object[] getFramesInfo(DebugStackFrame[] frames, boolean includeInternal)
System.err.println("frameInfos = "+frameInfos);
*//*
}*/
SourcePosition position = new SourcePosition(sf.getSourceSection());
SourcePosition position = new SourcePosition(sf.getSourceSection(), sf.getLanguage());
frameInfos.append(createPositionIdentificationString(position));
if (includeInternal) {
frameInfos.append('\n');
Expand Down Expand Up @@ -261,6 +261,8 @@ private static String createPositionIdentificationString(SourcePosition position
str.append('\n');
str.append(position.uri.toString());
str.append('\n');
str.append(position.mimeType);
str.append('\n');
str.append(position.sourceSection);
return str.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public void onSuspend(SuspendedEvent event) {
}
suspendedEvents.set(event);
try {
SourcePosition position = new SourcePosition(event.getSourceSection());
SourcePosition position = new SourcePosition(event.getSourceSection(), event.getTopStackFrame().getLanguage());
int stepCmd = JPDATruffleAccessor.executionHalted(
this, position,
event.getSuspendAnchor() == SuspendAnchor.BEFORE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package org.netbeans.modules.debugger.jpda.backend.truffle;

import com.oracle.truffle.api.nodes.LanguageInfo;
import com.oracle.truffle.api.source.Source;
import com.oracle.truffle.api.source.SourceSection;

Expand All @@ -41,8 +42,9 @@ final class SourcePosition {
final String sourceSection;
final String code;
final URI uri;
final String mimeType;

public SourcePosition(SourceSection sourceSection) {
public SourcePosition(SourceSection sourceSection, LanguageInfo languageInfo) {
Source source = sourceSection.getSource();
this.id = getId(source);
this.name = source.getName();
Expand All @@ -54,6 +56,15 @@ public SourcePosition(SourceSection sourceSection) {
this.sourceSection = sourceSection.getStartLine() + "," + sourceSection.getStartColumn() + "," + sourceSection.getEndLine() + "," + sourceSection.getEndColumn();
this.code = source.getCharacters().toString();
this.uri = source.getURI();
this.mimeType = findMIMEType(source, languageInfo);
}

private String findMIMEType(Source source, LanguageInfo languageInfo) {
String mimeType = source.getMimeType();
if (mimeType == null && languageInfo != null) {
mimeType = languageInfo.getDefaultMimeType();
}
return mimeType;
}

private static synchronized long getId(Source s) {
Expand Down
Loading