Search in sources :

Example 66 with SourceSection

use of com.oracle.truffle.api.source.SourceSection in project sulong by graalvm.

the class DIScopeBuilder method buildSection.

private SourceSection buildSection(MDFile file, long startLine, long startCol) {
    if (file == null) {
        return null;
    }
    final Source source = asSource(file);
    if (source == null) {
        return null;
    }
    final int line = (int) startLine;
    final int col = (int) startCol;
    SourceSection section;
    try {
        if (line <= 0) {
            // this happens e.g. for functions implicitly generated by llvm in section
            // '.text.startup'
            section = source.createSection(1);
        } else if (col <= 0) {
            // columns in llvm 3.2 metadata are usually always 0
            section = source.createSection(line);
        } else {
            section = source.createSection(line, col, 0);
        }
    } catch (Throwable ignored) {
        // if the source file has changed since it was last compiled the line and column
        // information in the metadata might not be accurate anymore
        section = null;
    }
    return section;
}
Also used : SourceSection(com.oracle.truffle.api.source.SourceSection) Source(com.oracle.truffle.api.source.Source)

Example 67 with SourceSection

use of com.oracle.truffle.api.source.SourceSection in project sulong by graalvm.

the class DebugInfoFunctionProcessor method initSourceFunction.

private void initSourceFunction(FunctionDefinition function, Source bitcodeSource) {
    final MDBaseNode debugInfo = getDebugInfo(function);
    LLVMSourceLocation scope = null;
    LLVMSourceFunctionType type = null;
    if (debugInfo != null) {
        scope = cache.buildLocation(debugInfo);
        LLVMSourceType actualType = cache.parseType(debugInfo);
        if (actualType instanceof LLVMSourceFunctionType) {
            type = (LLVMSourceFunctionType) actualType;
        }
    }
    if (scope == null) {
        final String sourceText = String.format("%s:%s", bitcodeSource.getName(), function.getName());
        final Source irSource = Source.newBuilder(sourceText).mimeType(DIScopeBuilder.getMimeType(null)).name(sourceText).build();
        final SourceSection simpleSection = irSource.createSection(1);
        scope = LLVMSourceLocation.createBitcodeFunction(function.getName(), simpleSection);
    }
    final SourceFunction sourceFunction = new SourceFunction(scope, type);
    function.setSourceFunction(sourceFunction);
    for (SourceVariable local : sourceFunction.getVariables()) {
        local.processFragments();
    }
}
Also used : MDBaseNode(com.oracle.truffle.llvm.parser.metadata.MDBaseNode) LLVMSourceLocation(com.oracle.truffle.llvm.runtime.debug.scope.LLVMSourceLocation) LLVMSourceType(com.oracle.truffle.llvm.runtime.debug.LLVMSourceType) SourceSection(com.oracle.truffle.api.source.SourceSection) LLVMSourceFunctionType(com.oracle.truffle.llvm.runtime.debug.LLVMSourceFunctionType) Source(com.oracle.truffle.api.source.Source)

Example 68 with SourceSection

use of com.oracle.truffle.api.source.SourceSection in project sulong by graalvm.

the class LLVMSourceScope method create.

@TruffleBoundary
public static Iterable<Scope> create(Node node, Frame frame, LLVMContext context) {
    final LLVMSourceContext sourceContext = context.getSourceContext();
    final RootNode rootNode = node.getRootNode();
    LLVMNode llvmNode = findStatementNode(node);
    if (rootNode == null || llvmNode == null) {
        return Collections.singleton(new LLVMSourceScope(sourceContext, node).toScope(frame));
    }
    LLVMSourceLocation scope = llvmNode.getSourceLocation();
    final SourceSection sourceSection = llvmNode.getSourceSection();
    LLVMSourceScope baseScope = new LLVMSourceScope(sourceContext, new LinkedList<>(), rootNode);
    LLVMSourceScope staticScope = null;
    for (boolean isLocalScope = true; isLocalScope && scope != null; scope = scope.getParent()) {
        final LLVMSourceScope next = toScope(scope, sourceContext, rootNode, sourceSection);
        copySymbols(next, baseScope);
        if (scope.getKind() == LLVMSourceLocation.Kind.FUNCTION) {
            baseScope.setName(next.getName());
            if (scope.getCompileUnit() != null) {
                staticScope = toScope(scope.getCompileUnit(), sourceContext, null, sourceSection);
            }
            isLocalScope = false;
        }
    }
    List<Scope> scopeList = new ArrayList<>();
    scopeList.add(baseScope.toScope(frame));
    for (; scope != null; scope = scope.getParent()) {
        // e.g. lambdas are compiled to calls to a method in a locally defined class. We
        // cannot access the locals of the enclosing function since they do not lie on the
        // function's frame. They are still accessible from the calling function's frame, so
        // we can simply ignore this scope here. Also, any variables actually used in the
        // lambda would still be available as the members of the 'this' pointer.
        final LLVMSourceScope next = toScope(scope, sourceContext, null, sourceSection);
        switch(scope.getKind()) {
            case NAMESPACE:
            case FILE:
            case BLOCK:
                if (next.hasSymbols()) {
                    scopeList.add(next.toScope(frame));
                }
                break;
            case COMPILEUNIT:
                if (staticScope == null) {
                    staticScope = next;
                } else {
                    copySymbols(next, staticScope);
                }
                break;
        }
    }
    if (staticScope != null && staticScope.hasSymbols()) {
        scopeList.add(staticScope.toScope(frame));
    }
    return Collections.unmodifiableList(scopeList);
}
Also used : RootNode(com.oracle.truffle.api.nodes.RootNode) Scope(com.oracle.truffle.api.Scope) ArrayList(java.util.ArrayList) SourceSection(com.oracle.truffle.api.source.SourceSection) LLVMNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMNode) LLVMSourceContext(com.oracle.truffle.llvm.runtime.debug.LLVMSourceContext) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Aggregations

SourceSection (com.oracle.truffle.api.source.SourceSection)68 Test (org.junit.Test)23 Source (com.oracle.truffle.api.source.Source)15 Source (org.graalvm.polyglot.Source)12 Breakpoint (com.oracle.truffle.api.debug.Breakpoint)11 DebuggerSession (com.oracle.truffle.api.debug.DebuggerSession)8 SuspendedEvent (com.oracle.truffle.api.debug.SuspendedEvent)8 AbstractInstrumentationTest (com.oracle.truffle.api.instrumentation.test.AbstractInstrumentationTest)6 Node (com.oracle.truffle.api.nodes.Node)6 RootNode (com.oracle.truffle.api.nodes.RootNode)6 DebugStackFrame (com.oracle.truffle.api.debug.DebugStackFrame)5 DebugValue (com.oracle.truffle.api.debug.DebugValue)5 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)3 DebugScope (com.oracle.truffle.api.debug.DebugScope)3 Counter (com.oracle.truffle.api.instrumentation.test.examples.StatementProfilerExample.Counter)3 Params (com.oracle.truffle.tools.chromeinspector.commands.Params)3 RootCallTarget (com.oracle.truffle.api.RootCallTarget)2 InstrumentableNode (com.oracle.truffle.api.instrumentation.InstrumentableNode)2 WrapperNode (com.oracle.truffle.api.instrumentation.InstrumentableNode.WrapperNode)2 SourceSectionFilter (com.oracle.truffle.api.instrumentation.SourceSectionFilter)2