Googler | 29eafdf | 2018-05-23 12:32:07 -0700 | [diff] [blame] | 1 | // Copyright 2018 The Bazel Authors. All rights reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package com.google.devtools.build.lib.syntax; |
| 16 | |
| 17 | import com.google.devtools.build.lib.events.Location; |
| 18 | import java.util.Collection; |
| 19 | import java.util.function.Predicate; |
| 20 | import javax.annotation.Nullable; |
| 21 | |
| 22 | /** A context in which debugging can occur. Implemented by Skylark environments. */ |
| 23 | public interface Debuggable { |
| 24 | |
brendandouglas | 01683d3 | 2018-06-26 08:53:10 -0700 | [diff] [blame] | 25 | /** Evaluates a Skylark statement in the adapter's environment. */ |
| 26 | Object evaluate(String statement) throws EvalException, InterruptedException; |
Googler | 29eafdf | 2018-05-23 12:32:07 -0700 | [diff] [blame] | 27 | |
| 28 | /** |
| 29 | * Returns the stack frames corresponding of the context's current (paused) state. |
| 30 | * |
| 31 | * <p>For all stack frames except the innermost, location information is retrieved from the |
| 32 | * current context. The innermost frame's location must be supplied as {@code currentLocation} by |
| 33 | * the caller. |
| 34 | */ |
| 35 | Collection<DebugFrame> listFrames(Location currentLocation); |
| 36 | |
| 37 | /** |
| 38 | * Given a requested stepping behavior, returns a predicate over the context that tells the |
| 39 | * debugger when to pause. |
| 40 | * |
| 41 | * <p>The predicate will return true if we are at the next statement where execution should pause, |
| 42 | * and it will return false if we are not yet at that statement. No guarantee is made about the |
| 43 | * predicate's return value after we have reached the desired statement. |
| 44 | * |
| 45 | * <p>A null return value indicates that no further pausing should occur. |
| 46 | */ |
| 47 | @Nullable |
| 48 | ReadyToPause stepControl(Stepping stepping); |
| 49 | |
| 50 | /** |
| 51 | * When stepping, this determines whether or not the context has yet reached a state for which |
| 52 | * execution should be paused. |
| 53 | * |
| 54 | * <p>A single instance is only useful for advancing by one pause. A new instance may be required |
| 55 | * after that. |
| 56 | */ |
| 57 | interface ReadyToPause extends Predicate<Environment> {} |
| 58 | |
| 59 | /** Describes the stepping behavior that should occur when execution of a thread is continued. */ |
| 60 | enum Stepping { |
| 61 | /** Continue execution without stepping. */ |
| 62 | NONE, |
| 63 | /** |
| 64 | * If the thread is paused on a statement that contains a function call, step into that |
| 65 | * function. Otherwise, this is the same as OVER. |
| 66 | */ |
| 67 | INTO, |
| 68 | /** |
| 69 | * Step over the current statement and any functions that it may call, stopping at the next |
| 70 | * statement in the same frame. If no more statements are available in the current frame, same |
| 71 | * as OUT. |
| 72 | */ |
| 73 | OVER, |
| 74 | /** |
| 75 | * Continue execution until the current frame has been exited and then pause. If we are |
| 76 | * currently in the outer-most frame, same as NONE. |
| 77 | */ |
| 78 | OUT, |
| 79 | } |
| 80 | } |