Skip to content

Commit

Permalink
Merge PR #305: Assisted actor debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
smarr committed Aug 5, 2019
2 parents 03bebb1 + 357de08 commit d3985a8
Show file tree
Hide file tree
Showing 13 changed files with 435 additions and 8 deletions.
6 changes: 5 additions & 1 deletion core-lib/Kernel.ns
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ class Kernel vmMirror: vmMirror = Object <: Value (
private class Top = ()()

public class Thing = Top ()(
protected error: msg = ( vmMirror printNewline: 'ERROR: ' + msg. vmMirror exit: 1 )
protected error: msg = (
vmMirror printNewline: 'ERROR: ' + msg.
vmMirror markTurnErroneous: nil.
vmMirror exit: 1
)

(* Error recovering *)
protected doesNotUnderstand: selector arguments: arguments = (
Expand Down
6 changes: 5 additions & 1 deletion core-lib/System.ns
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ class System usingVmMirror: vmMirror = Value (
public exit: error = ( vmMirror exit: error )
public exit = ( self exit: 0 )
public warning: msg = ( vmMirror printWarning: msg. )
public error: msg = ( vmMirror printError: msg. self exit: 1 )
public error: msg = (
vmMirror printError: msg.
vmMirror markTurnErroneous: nil.
self exit: 1
)

(* VM *)
public arguments = ( ^ vmMirror vmArguments: nil )
Expand Down
2 changes: 1 addition & 1 deletion core-lib/demos/ReplayDemo.ns
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class ReplayDemo usingPlatform: platform = Value (
flightPrices at: flightId put: (amount + 10) ]
ifFalse:[
(* didn't match price, fail *)
'Payment FAILED' println.
self error: 'Payment FAILED'.
resolved ifFalse: [
completionRes resolve: false.
resolved:: true ] ]
Expand Down
12 changes: 12 additions & 0 deletions som
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ profile.add_argument('-tp', '--truffle-profile', help='enable Graal-level profil
tools = parser.add_argument_group('Tools', 'Additional Tools')
tools.add_argument('-wd', '--web-debugger', help='start Web debugger',
dest='web_debugger', action='store_true', default=False)
tools.add_argument('-ad', '--assisted-debugging', help='enable assisted debugging',
dest='assisted_debugging', action='store_true', default=False)
tools.add_argument('-adbp', '--assisted-debugging-breakpoints', help='set assisted debugging breakpoints limit',
dest='assisted_debugging_breakpoints', default=0)
tools.add_argument('-dm', '--dynamic-metrics', help='Capture Dynamic Metrics',
dest='dynamic_metrics', action='store_true', default=False)
tools.add_argument('-si', '--si-candidates', help='Identify candidates for super-instructions',
Expand Down Expand Up @@ -352,6 +356,14 @@ if (args.truffle_profile or args.web_debugger or
if args.web_debugger:
flags += ['-Dsom.truffleDebugger=true']

if args.assisted_debugging:
flags += ['-Dsom.assistedDebugging=true']

if args.assisted_debugging_breakpoints:
flags += ['-Dsom.assistedDebugging=true']
if args.assisted_debugging_breakpoints:
flags += ['-Dsom.assistedDebuggingBp=%s' % args.assisted_debugging_breakpoints ]

if not args.interpreter and args.perf_warnings:
flags += ['-Dgraal.TruffleCompilationExceptionsAreFatal=true',
'-Dgraal.TraceTrufflePerformanceWarnings=true',
Expand Down
9 changes: 9 additions & 0 deletions src/som/Launcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import som.vm.VmSettings;
import tools.concurrency.TracingActors.ReplayActor;
import tools.concurrency.TracingBackend;
import tools.parser.KomposTraceParser;
import tools.snapshot.SnapshotBackend;


Expand Down Expand Up @@ -64,6 +65,14 @@ private static void finalizeExecution(final int exitCode) {
if (VmSettings.MEMORY_TRACING) {
TracingBackend.reportPeakMemoryUsage();
}

// Note: Kompos Trace is parsed right after writing it
// to produce the list of messages on the erroneous path.
// Could be done at the beginning of assisted debugging.
if (VmSettings.KOMPOS_TRACING) {
KomposTraceParser tp = new KomposTraceParser();
tp.createStackTraceFile(VmSettings.TRACE_FILE);
}
}

public static Builder createContextBuilder(final String[] args) {
Expand Down
7 changes: 7 additions & 0 deletions src/som/interpreter/actors/EventualMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import som.vmobjects.SBlock;
import som.vmobjects.SSymbol;
import tools.concurrency.TracingActivityThread;
import tools.parser.KomposTraceParser;
import tools.snapshot.SnapshotBackend;
import tools.snapshot.SnapshotBuffer;

Expand Down Expand Up @@ -54,6 +55,12 @@ protected EventualMessage(final Object[] args,
this.haltOnResolver = haltOnResolver;
if (VmSettings.KOMPOS_TRACING) {
this.messageId = TracingActivityThread.newEntityId();
if (VmSettings.ASSISTED_DEBUGGING) {
if (KomposTraceParser.isMessageInErrorStackTrace(this.messageId)
|| this.messageId == 0) {
this.haltOnReceive = true;
}
}
} else {
this.messageId = 0;
}
Expand Down
28 changes: 28 additions & 0 deletions src/som/primitives/SystemPrims.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package som.primitives;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.net.URI;
import java.util.ArrayList;
Expand Down Expand Up @@ -216,6 +218,32 @@ public final Object doSObject(final String argument) {
}
}

/**
* This primitive is used be Kernel.ns and System.ns before the system is shut down with an
* error. We use this primitive to log the messageId of the turn the error occured in.
* The logged messageId can then be used in assisted debugging to backtrack from the error
* to the system start, and generate breakpoints for messages on that path.
*/
@GenerateNodeFactory
@Primitive(primitive = "markTurnErroneous:")
public abstract static class MarkTurnErroneousPrim extends UnaryExpressionNode {
@Specialization
public final Object doSObject(final Object receiver) {
if (VmSettings.KOMPOS_TRACING) {
EventualMessage errorMsg = EventualMessage.getCurrentExecutingMessage();
long msgId = errorMsg.getMessageId();

File f = new File(VmSettings.TRACE_FILE + "_errorMsgId.trace");
try (BufferedWriter writer = new BufferedWriter(new FileWriter(f))) {
writer.write(String.valueOf(msgId));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return receiver;
}
}

@GenerateNodeFactory
@Primitive(primitive = "printStackTrace:")
public abstract static class PrintStackTracePrim extends UnaryExpressionNode {
Expand Down
5 changes: 5 additions & 0 deletions src/som/vm/VmSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public class VmSettings implements Settings {
public static final boolean DNU_PRINT_STACK_TRACE;
public static final boolean REPLAY;
public static final boolean KOMPOS_TRACING;
public static final boolean ASSISTED_DEBUGGING;

public static final boolean TRACE_SMALL_IDS;
public static final boolean SNAPSHOTS_ENABLED;
public static final boolean TRACK_SNAPSHOT_ENTITIES;
Expand All @@ -34,6 +36,7 @@ public class VmSettings implements Settings {

public static final int BUFFERS_PER_THREAD;
public static final int BUFFER_SIZE;
public static final int ASSISTED_DEBUGGING_BREAKPOINTS;
public static final boolean RECYCLE_BUFFERS;
public static final int BUFFER_TIMEOUT;

Expand All @@ -56,6 +59,7 @@ public class VmSettings implements Settings {
MEMORY_TRACING = getBool("som.memoryTracing", false);
REPLAY = getBool("som.replay", false);
KOMPOS_TRACING = getBool("som.komposTracing", false) || TRUFFLE_DEBUGGER_ENABLED; // REPLAY;
ASSISTED_DEBUGGING = getBool("som.assistedDebugging", false) && KOMPOS_TRACING;
DISABLE_TRACE_FILE = getBool("som.disableTraceFile", false) || (REPLAY && !KOMPOS_TRACING);
TRACE_SMALL_IDS = getBool("som.smallIds", false);

Expand All @@ -74,6 +78,7 @@ public class VmSettings implements Settings {
IGV_DUMP_AFTER_PARSING = getBool("som.igvDumpAfterParsing", false);
ANSI_COLOR_IN_OUTPUT = getBool("som.useAnsiColoring", false);

ASSISTED_DEBUGGING_BREAKPOINTS = getInteger("som.assistedDebuggingBp", -1);
BUFFER_SIZE = getInteger("som.buffSize", 1024 * 1024);
BUFFERS_PER_THREAD = getInteger("som.buffPerThread", 4);
BUFFER_TIMEOUT = getInteger("som.buffDelay", 50);
Expand Down
Loading

0 comments on commit d3985a8

Please sign in to comment.