Search in sources :

Example 1 with CallFrame

use of org.rstudio.studio.client.workbench.views.environment.model.CallFrame in project rstudio by rstudio.

the class BreakpointManager method onContextDepthChanged.

@Override
public void onContextDepthChanged(ContextDepthChangedEvent event) {
    // When we move around in debug context and hit a breakpoint, the initial
    // evaluation state is a temporary construction that needs to be stepped
    // past to begin actually evaluating the function. Step past it
    // immediately.
    JsArray<CallFrame> frames = event.getCallFrames();
    Set<FileFunction> activeFunctions = new TreeSet<FileFunction>();
    boolean hasSourceEquiv = false;
    for (int idx = 0; idx < frames.length(); idx++) {
        CallFrame frame = frames.get(idx);
        String functionName = frame.getFunctionName();
        String fileName = frame.getFileName();
        if (functionName.equals(".doTrace") && event.isServerInitiated()) {
            events_.fireEvent(new SendToConsoleEvent(DebugCommander.NEXT_COMMAND, true));
        }
        activeFunctions.add(new FileFunction(functionName, fileName, "", false));
        if (frame.isSourceEquiv()) {
            activeSource_ = fileName;
            hasSourceEquiv = true;
        }
    }
    // For any functions that were previously active in the callstack but
    // are no longer active, enable any pending breakpoints for those 
    // functions.
    Set<FileFunction> enableFunctions = new TreeSet<FileFunction>();
    for (FileFunction function : activeFunctions_) {
        if (!activeFunctions.contains(function)) {
            for (Breakpoint breakpoint : breakpoints_) {
                if (breakpoint.isPendingDebugCompletion() && breakpoint.getState() == Breakpoint.STATE_INACTIVE && function.containsBreakpoint(breakpoint)) {
                    enableFunctions.add(function);
                }
            }
        }
    }
    for (FileFunction function : enableFunctions) {
        prepareAndSetFunctionBreakpoints(function);
    }
    // Record the new frame list.
    activeFunctions_ = activeFunctions;
    // breakpoints in the file we were sourcing.
    if (!hasSourceEquiv && activeSource_ != null) {
        activateTopLevelBreakpoints(activeSource_);
        activeSource_ = null;
    }
}
Also used : Breakpoint(org.rstudio.studio.client.common.debugging.model.Breakpoint) TreeSet(java.util.TreeSet) CallFrame(org.rstudio.studio.client.workbench.views.environment.model.CallFrame) SendToConsoleEvent(org.rstudio.studio.client.workbench.views.console.events.SendToConsoleEvent) Breakpoint(org.rstudio.studio.client.common.debugging.model.Breakpoint)

Example 2 with CallFrame

use of org.rstudio.studio.client.workbench.views.environment.model.CallFrame in project rstudio by rstudio.

the class EnvironmentPresenter method loadNewContextState.

private void loadNewContextState(int contextDepth, String environmentName, String functionEnvName, boolean isLocalEvironment, JsArray<CallFrame> callFrames, boolean useBrowseSources, String functionCode) {
    boolean enteringDebugMode = setContextDepth(contextDepth);
    environmentName_ = environmentName;
    functionEnvName_ = functionEnvName;
    view_.setEnvironmentName(environmentName_, isLocalEvironment);
    if (callFrames != null && callFrames.length() > 0 && contextDepth > 0) {
        view_.setCallFrames(callFrames, enteringDebugMode);
        CallFrame browseFrame = callFrames.get(contextDepth_ - 1);
        String newBrowseFile = browseFrame.getAliasedFileName().trim();
        boolean sourceChanged = false;
        // the server thinks the document is clean.
        if (fileContainsUnsavedChanges(newBrowseFile)) {
            useBrowseSources = true;
        }
        // triggered.
        if ((!newBrowseFile.equals(currentBrowseFile_) || useBrowseSources != useCurrentBrowseSource_) && !(useBrowseSources && useCurrentBrowseSource_)) {
            openOrUpdateFileBrowsePoint(false, false);
        }
        useCurrentBrowseSource_ = useBrowseSources;
        if (!currentBrowseSource_.equals(functionCode)) {
            currentBrowseSource_ = functionCode;
            sourceChanged = true;
        }
        // highlight the active line in the file now being debugged
        currentBrowseFile_ = newBrowseFile;
        currentBrowsePosition_ = browseFrame.getRange();
        currentFunctionLineNumber_ = browseFrame.getFunctionLineNumber();
        openOrUpdateFileBrowsePoint(true, sourceChanged);
    } else {
        openOrUpdateFileBrowsePoint(false, false);
        useCurrentBrowseSource_ = false;
        currentBrowseSource_ = "";
        currentBrowseFile_ = "";
        currentBrowsePosition_ = null;
        currentFunctionLineNumber_ = 0;
    }
}
Also used : CallFrame(org.rstudio.studio.client.workbench.views.environment.model.CallFrame) JsArrayString(com.google.gwt.core.client.JsArrayString)

Example 3 with CallFrame

use of org.rstudio.studio.client.workbench.views.environment.model.CallFrame in project rstudio by rstudio.

the class CallFramePanel method setCallFrames.

public void setCallFrames(JsArray<CallFrame> frameList, int contextDepth) {
    clearCallFrames();
    // Check to see whether every function on the stack is internal. 
    // If it is, the traceback window may appear empty, so show everything
    // to give the user some context.
    boolean allInternal = true;
    int idxSourceEquiv = Integer.MAX_VALUE;
    for (int idx = 0; idx < frameList.length(); idx++) {
        CallFrame frame = frameList.get(idx);
        if (frame.isNavigable()) {
            allInternal = false;
        }
        if (frame.isSourceEquiv())
            idxSourceEquiv = idx;
    }
    for (int idx = frameList.length() - 1; idx >= 0; idx--) {
        CallFrame frame = frameList.get(idx);
        // Always show the first frame, since that's where execution is 
        // actually halted. From the remaining frames, show them if they are
        // "navigable" (user) frames, or if the user has elected to show all
        // frames.
        CallFrameItem item = new CallFrameItem(frame, observer_, frame.isHidden() || (!panelHost_.getShowInternalFunctions() && ((!frame.isNavigable()) || idx > idxSourceEquiv) && !allInternal && idx > 0));
        if (contextDepth == frame.getContextDepth()) {
            item.setActive();
        }
        callFrameItems_.add(item);
    }
    // now walk forwards through the frames and add each to the UI
    Collections.reverse(callFrameItems_);
    for (CallFrameItem item : callFrameItems_) {
        callFramePanel.add(item);
    }
}
Also used : CallFrame(org.rstudio.studio.client.workbench.views.environment.model.CallFrame)

Aggregations

CallFrame (org.rstudio.studio.client.workbench.views.environment.model.CallFrame)3 JsArrayString (com.google.gwt.core.client.JsArrayString)1 TreeSet (java.util.TreeSet)1 Breakpoint (org.rstudio.studio.client.common.debugging.model.Breakpoint)1 SendToConsoleEvent (org.rstudio.studio.client.workbench.views.console.events.SendToConsoleEvent)1