/*
 *   call-seq:
 *      Debugger.debug_load(file, stop = false, increment_start = false) -> nil
 *
 *   Same as Kernel#load but resets current context's frames.
 *   +stop+ parameter forces the debugger to stop at the first line of code in the +file+
 *   +increment_start+ determines if start_count should be incremented. When
 *    control threads are used, they have to be set up before loading the
 *    debugger; so here +increment_start+ will be false.    
 *   FOR INTERNAL USE ONLY.
 */
static VALUE
debug_debug_load(int argc, VALUE *argv, VALUE self)
{
    VALUE file, stop, context, increment_start;
    debug_context_t *debug_context;
    int state = 0;
    
    if(rb_scan_args(argc, argv, "12", &file, &stop, &increment_start) == 1) 
    {
        stop = Qfalse;
        increment_start = Qtrue;
    }

    debug_start(self);
    if (Qfalse == increment_start) start_count--;
    
    context = debug_current_context(self);
    Data_Get_Struct(context, debug_context_t, debug_context);
    debug_context->stack_size = 0;
    if(RTEST(stop))
      debug_context->stop_next = 1;
    /* Initializing $0 to the script's path */
    ruby_script(RSTRING(file)->ptr);
    rb_load_protect(file, 0, &state);
    if (0 != state) {
      VALUE errinfo = ruby_errinfo;
      debug_suspend(self);
      reset_stepping_stop_points(debug_context);
      ruby_errinfo = Qnil;
      return errinfo;
    }

    /* We don't want to stop the debugger yet, because the
     * user may have set breakpoints in at_exit blocks that
     * should be hit. But we don't want to step out into debugger
     * code either, so we reset stepping stop points here.
     */
    reset_stepping_stop_points(debug_context);

    return Qnil;
}