Sha256: dc54759cd71ac25572200603a344de75581c5228ba292c1333518b80372f8ec9

Contents?: true

Size: 1.78 KB

Versions: 135

Compression:

Stored size: 1.78 KB

Contents

/*
 * Copyright 2006-2007 Yu Su
 * Distributed under the BSD License
 */
package com.xruby.debug.cmd;

import com.sun.jdi.StackFrame;
import com.sun.jdi.IncompatibleThreadStateException;
import com.sun.jdi.Location;
import com.sun.jdi.AbsentInformationException;
import com.xruby.debug.Instruction;
import com.xruby.debug.Result;
import com.xruby.debug.ThreadInfo;
import com.xruby.debug.SourceCodeMgr;

import static java.lang.System.err;
import static java.lang.System.out;

/**
 * List the source code, only for commandline tools
 *
 * @author Yu Su (beanworms@gmail.com)
 */
public class ListInsn implements Instruction {

    private int range;

    public ListInsn(int range) {
        if(range > 0) {
            this.range = range;
        } else {
            this.range = 5;
        }
    }

    public Result execute() {
        Result result = null;
        
        ThreadInfo threadInfo = ThreadInfo.getCurrentThreadInfo();
        StackFrame frame;
        try {
            frame = threadInfo.getCurrentFrame();
        } catch (IncompatibleThreadStateException exc) {
            err.println("<location unavailable>");
            return result;
        }
        if (frame == null) {
            err.println("No frames on the current call stack");
        } else {
            Location loc = frame.location();
            // TODO: Print out source code
            try {
                String sourceFile = loc.sourceName();
                int lineNumber = loc.lineNumber();

                out.println(SourceCodeMgr.getSourceSnippet(sourceFile, lineNumber, range));
            } catch (AbsentInformationException e) {
                err.println("Debug information lost");
            }
        }
        
        return result;
    }
}

Version data entries

135 entries across 135 versions & 2 rubygems

Version Path
rhodes-7.6.0 platform/shared/xruby/src/com/xruby/debug/cmd/ListInsn.java
rhodes-7.5.1 platform/shared/xruby/src/com/xruby/debug/cmd/ListInsn.java
rhodes-7.4.1 platform/shared/xruby/src/com/xruby/debug/cmd/ListInsn.java
rhodes-7.1.17 platform/shared/xruby/src/com/xruby/debug/cmd/ListInsn.java
rhodes-6.2.0 platform/shared/xruby/src/com/xruby/debug/cmd/ListInsn.java
rhodes-6.0.11 platform/shared/xruby/src/com/xruby/debug/cmd/ListInsn.java
rhodes-5.5.18 platform/shared/xruby/src/com/xruby/debug/cmd/ListInsn.java
rhodes-5.5.17 platform/shared/xruby/src/com/xruby/debug/cmd/ListInsn.java
rhodes-5.5.15 platform/shared/xruby/src/com/xruby/debug/cmd/ListInsn.java
rhodes-5.5.0.22 platform/shared/xruby/src/com/xruby/debug/cmd/ListInsn.java
rhodes-5.5.2 platform/shared/xruby/src/com/xruby/debug/cmd/ListInsn.java
rhodes-5.5.0.7 platform/shared/xruby/src/com/xruby/debug/cmd/ListInsn.java
rhodes-5.5.0.3 platform/shared/xruby/src/com/xruby/debug/cmd/ListInsn.java
rhodes-5.5.0 platform/shared/xruby/src/com/xruby/debug/cmd/ListInsn.java
tauplatform-1.0.3 platform/shared/xruby/src/com/xruby/debug/cmd/ListInsn.java
tauplatform-1.0.2 platform/shared/xruby/src/com/xruby/debug/cmd/ListInsn.java
tauplatform-1.0.1 platform/shared/xruby/src/com/xruby/debug/cmd/ListInsn.java
rhodes-3.5.1.12 platform/shared/xruby/src/com/xruby/debug/cmd/ListInsn.java
rhodes-3.3.5 platform/shared/xruby/src/com/xruby/debug/cmd/ListInsn.java
rhodes-3.4.2 platform/shared/xruby/src/com/xruby/debug/cmd/ListInsn.java