Example #1
0
int main(int argc, char **argv) {
   struct stat buf;
   DIR *dir_pointer;
   struct dirent *dp;

   if (chdir(PLAYERS_STUFF)) {
      perror(FAN_ERR_PLAY_STUFF);
      exit(-1);
   }
   if ((dir_pointer = opendir(".")) == NULL) {
      perror(FAN_ERR_PLAY_STUFF);
      exit(-1);
   }
   for (dp = readdir(dir_pointer); dp != NULL; dp = readdir(dir_pointer)) {
     if (stat(dp->d_name,&buf) == -1) {
        perror(FAN_ERR_PLAY_STUFF);
        exit(-1);
     }
     if (S_ISREG(buf.st_mode)) unlink(dp->d_name);
   }
   if (closedir(dir_pointer)) {
      perror(FAN_ERR_PLAY_STUFF);
      exit(-1);
   }
   if (chdir(FANTASY_ETC)) {
      perror(FAN_ERR_ETC);
      exit(-1);
   }
   if (system("tar xf initial_world.tar") == -1) {
      perror(FAN_ERR_WORLD);
      exit(-1);
   }
   if (set_current_location(PLAYERS_LOCATION,STARTING_LOCATION) == -1) {
      perror(FAN_ERR_START);
      exit(-1);
   }
   if (set_current_location(DRAGONS_LOCATION,DRAGONS_LAIR) == -1) {
      perror(FAN_ERR_LAIR);
      exit(-1);
   }
   /*commented out - to be re-introduced when Practical Sheet 9 is done*/
   if (system("dragon") == -1)
      perror(FAN_WARN_DRAGON);

   if (system("look") == -1) {
      perror(FAN_ERR_LOOK);
      exit(-1);
   }
   exit(0);
}
void JvmtiEnvThreadState::reset_current_location(jvmtiEvent event_type, bool enabled) {
  assert(event_type == JVMTI_EVENT_SINGLE_STEP || event_type == JVMTI_EVENT_BREAKPOINT,
         "must be single-step or breakpoint event");

  // Current location is used to detect the following:
  // 1) a breakpoint event followed by single-stepping to the same bci
  // 2) single-step to a bytecode that will be transformed to a fast version
  // We skip to avoid posting the duplicate single-stepping event.

  // If single-stepping is disabled, clear current location so that
  // single-stepping to the same method and bcp at a later time will be
  // detected if single-stepping is enabled at that time (see 4388912).

  // If single-stepping is enabled, set the current location to the
  // current method and bcp. This covers the following type of case,
  // e.g., the debugger stepi command:
  // - bytecode single stepped
  // - SINGLE_STEP event posted and SINGLE_STEP event disabled
  // - SINGLE_STEP event reenabled
  // - bytecode rewritten to fast version

  // If breakpoint event is disabled, clear current location only if
  // single-stepping is not enabled.  Otherwise, keep the thread location
  // to detect any duplicate events.

  if (enabled) {
    // If enabling breakpoint, no need to reset.
    // Can't do anything if empty stack.
    if (event_type == JVMTI_EVENT_SINGLE_STEP && _thread->has_last_Java_frame()) {
      jmethodID method_id;
      int bci;
      // The java thread stack may not be walkable for a running thread
      // so get current location at safepoint.
      VM_GetCurrentLocation op(_thread);
      VMThread::execute(&op);
      op.get_current_location(&method_id, &bci);
      set_current_location(method_id, bci);
    }
  } else if (event_type == JVMTI_EVENT_SINGLE_STEP || !is_enabled(JVMTI_EVENT_SINGLE_STEP)) {
    // If this is to disable breakpoint, also check if single-step is not enabled
    clear_current_location();
  }
}
// Given that a new (potential) event has come in,
// maintain the current JVMTI location on a per-thread per-env basis
// and use it to filter out duplicate events:
// - instruction rewrites
// - breakpoint followed by single step
// - single step at a breakpoint
void JvmtiEnvThreadState::compare_and_set_current_location(Method* new_method,
                                                           address new_location, jvmtiEvent event) {

  int new_bci = new_location - new_method->code_base();

  // The method is identified and stored as a jmethodID which is safe in this
  // case because the class cannot be unloaded while a method is executing.
  jmethodID new_method_id = new_method->jmethod_id();

  // the last breakpoint or single step was at this same location
  if (_current_bci == new_bci && _current_method_id == new_method_id) {
    switch (event) {
    case JVMTI_EVENT_BREAKPOINT:
      // Repeat breakpoint is complicated. If we previously posted a breakpoint
      // event at this location and if we also single stepped at this location
      // then we skip the duplicate breakpoint.
      _breakpoint_posted = _breakpoint_posted && _single_stepping_posted;
      break;
    case JVMTI_EVENT_SINGLE_STEP:
      // Repeat single step is easy: just don't post it again.
      // If step is pending for popframe then it may not be
      // a repeat step. The new_bci and method_id is same as current_bci
      // and current method_id after pop and step for recursive calls.
      // This has been handled by clearing the location
      _single_stepping_posted = true;
      break;
    default:
      assert(false, "invalid event value passed");
      break;
    }
    return;
  }

  set_current_location(new_method_id, new_bci);
  _breakpoint_posted = false;
  _single_stepping_posted = false;
}