aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/syntax
diff options
context:
space:
mode:
authorGravatar Googler <noreply@google.com>2018-06-07 14:07:17 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-06-07 14:08:44 -0700
commit5e893626640351de0f12e36bb14d80af0ff1e036 (patch)
treeb9a7083618290b867bd40383881a06e89060ce27 /src/main/java/com/google/devtools/build/lib/syntax
parent755278df00f65818dc092fe4f8a31bdec1aaaab5 (diff)
Add an initial skylark debug server implementation.
Not intending this to be a complete implementation yet. Among the things still to do: - officially add support for debugging aspects, rules, etc., with corresponding tests. - handle breakpoints at return statements (an edge case which bypasses Eval). PiperOrigin-RevId: 199692670
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/syntax')
-rw-r--r--src/main/java/com/google/devtools/build/lib/syntax/DebugServer.java14
-rw-r--r--src/main/java/com/google/devtools/build/lib/syntax/DebugServerUtils.java23
2 files changed, 29 insertions, 8 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/DebugServer.java b/src/main/java/com/google/devtools/build/lib/syntax/DebugServer.java
index f462550797..0238e51959 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/DebugServer.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/DebugServer.java
@@ -14,11 +14,14 @@
package com.google.devtools.build.lib.syntax;
+import java.util.function.Function;
+
/** A debug server interface, called from core skylark code. */
public interface DebugServer {
/**
- * Tracks the execution of the given callable object in the debug server.
+ * Executes the given callable and returns its result, while making any skylark evaluation visible
+ * to the debugger. This method should be used to evaluate all debuggable Skylark code.
*
* @param env the Skylark execution environment
* @param threadName the descriptive name of the thread
@@ -29,6 +32,15 @@ public interface DebugServer {
<T> T runWithDebugging(Environment env, String threadName, DebugCallable<T> callable)
throws EvalException, InterruptedException;
+ /** Shuts down the debug server, closing any open sockets, etc. */
+ void close();
+
+ /**
+ * Returns a custom {@link Eval} supplier used to intercept statement execution to check for
+ * breakpoints.
+ */
+ Function<Environment, Eval> evalOverride();
+
/** Represents an invocation that will be tracked as a thread by the Skylark debug server. */
interface DebugCallable<T> {
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/DebugServerUtils.java b/src/main/java/com/google/devtools/build/lib/syntax/DebugServerUtils.java
index f653cd994f..808d10704a 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/DebugServerUtils.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/DebugServerUtils.java
@@ -16,10 +16,14 @@ package com.google.devtools.build.lib.syntax;
import com.google.devtools.build.lib.syntax.DebugServer.DebugCallable;
import java.util.concurrent.atomic.AtomicReference;
-import java.util.function.Function;
import java.util.function.Supplier;
-/** A helper class for enabling/disabling skylark debugging. */
+/**
+ * A helper class for enabling/disabling skylark debugging.
+ *
+ * <p>{@code runWithDebuggingIfEnabled} must be called after {@code initializeDebugServer}, and
+ * before {@code disableDebugging}.
+ */
public final class DebugServerUtils {
private DebugServerUtils() {}
@@ -30,15 +34,20 @@ public final class DebugServerUtils {
* Called at the start of a debuggable skylark session to enable debugging. The custom {@link
* Eval} supplier provided should intercept statement execution to check for breakpoints.
*/
- public static void initializeDebugServer(
- DebugServer server, Function<Environment, Eval> evalOverride) {
+ public static void initializeDebugServer(DebugServer server) {
instance.set(server);
- Eval.setEvalSupplier(evalOverride);
+ Eval.setEvalSupplier(server.evalOverride());
}
- /** Called at the end of a debuggable skylark session to disable debugging. */
+ /**
+ * Called at the end of a debuggable skylark session to shut down the debug server and disable
+ * debugging.
+ */
public static void disableDebugging() {
- instance.set(null);
+ DebugServer server = instance.getAndSet(null);
+ if (server != null) {
+ server.close();
+ }
Eval.removeCustomEval();
}