anchor.diff:    int seqNr = 0;  // Sequence number of next debugger command message.
     Command lastCommand = null;  // Most recent command sent to target.
     List<String> errors = new List();
  +  bool cleanupDone = false;
   
     // Data collected from debug target.
     Map currentMessage = null;  // Currently handled message sent by target.
  
positive.code:       if (errorsDetected) {
          error("Error while handling script entry");
          error("Message received from debug target: $msg");
          close(killDebugee: true);
          return;
        }
        if (shutdownEventSeen) {
          close();
          return;
        }
        if (isPaused) sendNextCommand();
  
negative.code:         var trace = getAttachedStackTrace(e);
          if (trace != null) msg += "\nStackTrace: $trace";
          error(msg);
          cleanup();
        });
    }
  
    void cleanup() {
      if (cleanupDone) return;
      if (socket != null) {
        socket.close().catchError((error) {
          // Print this directly in addition to adding it to the
          // error message queue, in case the error message queue
          // gets printed before this error handler is called.
          print("Error occurred while closing socket: $error");
          error("Error while closing socket: $error");
        });
      }
      targetProcess.kill();
      // If the process was already dead exitCode is already
      // available and we call exit() in the next event loop cycle.
      // Otherwise this will wait for the process to exit.
      targetProcess.exitCode.then((exitCode) {
        if (errorsDetected) {
          print("\n===== Errors detected: =====");
          for (int i = 0; i < errors.length; i++) print(errors[i]);
          print("============================\n");
        }
        exit(errors.length);
      });
      cleanupDone = true;
    }
  }
  
  