Beispiel #1
0
static void
setupSignals() {
    SignalThread *st = new SignalThread();

    st->ignore(SIGPIPE);
    st->setHandler(SIGINT, finalize);
    st->start(false, false);
}
Beispiel #2
0
  void* SignalThread::run(void* ptr) {
    SignalThread* thread = reinterpret_cast<SignalThread*>(ptr);
    VM* vm = thread->vm();

    State state_obj(vm), *state = &state_obj;

    vm->set_stack_bounds(state->shared().config.machine_thread_stack_size.value);
    vm->set_current_thread();

    RUBINIUS_THREAD_START(
        const_cast<RBX_DTRACE_CHAR_P>(vm->name().c_str()), vm->thread_id(), 1);

    NativeMethod::init_thread(state);

    thread->run(state);

    // The system is halted and exit(3) has been called so the following code
    // does not run. It is here to make the compiler happy.

    return 0;
  }
Beispiel #3
0
  void* SignalThread::run(void* ptr) {
    SignalThread* thread = reinterpret_cast<SignalThread*>(ptr);
    VM* vm = thread->vm();

    State state_obj(vm), *state = &state_obj;

    vm->set_stack_bounds(state->shared().config.machine_thread_stack_size.value);
    vm->set_current_thread();

    RUBINIUS_THREAD_START(
        const_cast<RBX_DTRACE_CHAR_P>(vm->name().c_str()), vm->thread_id(), 1);

    NativeMethod::init_thread(state);

    int exit_code = 0;

    // TODO: clean up and unify with main() exception handling.
    try {
      thread->run(state);
    } catch(Assertion *e) {
      std::cout << "VM Assertion:" << std::endl;
      std::cout << "  " << e->reason << std::endl << std::endl;
      e->print_backtrace();

      std::cout << std::endl << "Ruby backtrace:" << std::endl;
      state->vm()->print_backtrace();
      delete e;
      exit_code = 1;
    } catch(RubyException &e) {
      std::cout << "Ruby Exception hit toplevel:\n";
      // Prints Ruby backtrace, and VM backtrace if captured
      e.show(state);
      exit_code = 1;
    } catch(TypeError &e) {

      /* TypeError's here are dealt with specially so that they can deliver
       * more information, such as _why_ there was a type error issue.
       *
       * This has the same name as the RubyException TypeError (run `5 + "string"`
       * as an example), but these are NOT the same - this exception is raised
       * internally when cNil gets passed to an array method, for instance, when
       * an array was expected.
       */
      std::cout << "Type Error detected:" << std::endl;
      TypeInfo* wanted = state->vm()->find_type(e.type);

      if(!e.object->reference_p()) {
        std::cout << "  Tried to use non-reference value " << e.object;
      } else {
        TypeInfo* was = state->vm()->find_type(e.object->type_id());
        std::cout << "  Tried to use object of type " <<
          was->type_name << " (" << was->type << ")";
      }

      std::cout << " as type " << wanted->type_name << " (" <<
        wanted->type << ")" << std::endl;

      e.print_backtrace();

      std::cout << "Ruby backtrace:" << std::endl;
      state->vm()->print_backtrace();
      exit_code = 1;
    } catch(VMException &e) {
      std::cout << "Unknown VM exception detected:" << std::endl;
      e.print_backtrace();
      exit_code = 1;
    } catch(std::exception& e) {
      std::cout << "C++ exception detected: " << e.what() << std::endl;
      exit_code = 1;
    } catch(...) {
      std::cout << "Unknown C++ exception detected at top level" << std::endl;
      exit_code = 1;
    }

    // We caught an exception, so exit directly here.
    exit(exit_code);
  }