Exemplo n.º 1
0
static ncaiError ncai_check_stop_single_step(NCAIEnv* env)
{
    DebugUtilsTI* ti = env->ti_env->vm->vm_env->TI;
    GlobalNCAI* ncai = env->ti_env->vm->vm_env->NCAI;

    if (!ncai->step_enabled)
        return NCAI_ERROR_NONE;

    // Check that no environment has SingleStep enabled
    LMAutoUnlock lock(&ti->TIenvs_lock);
    bool disable = true;

    for (TIEnv *ti_env = ti->getEnvironments(); ti_env;
         ti_env = ti_env->next)
    {
        if (!ti_env->ncai_env)
            continue;

        if (ti_env->ncai_env->global_events[NCAI_EVENT_STEP - NCAI_MIN_EVENT_TYPE_VAL] ||
            ti_env->ncai_env->event_threads[NCAI_EVENT_STEP - NCAI_MIN_EVENT_TYPE_VAL])
        {
            disable = false;
            break;
        }
    }

    return disable ? ncai_stop_single_step(env) : NCAI_ERROR_NONE;
}
Exemplo n.º 2
0
static void report_loaded_unloaded_module(ncaiModule module, bool loaded)
{
    DebugUtilsTI *ti = VM_Global_State::loader_env->TI;

    hythread_t hythread = hythread_self();
    ncaiThread thread = reinterpret_cast<ncaiThread>(hythread);

    bool suspend_enabled = hythread_is_suspend_enabled();

    if (!suspend_enabled)
        hythread_suspend_enable();

    TIEnv *ti_env = ti->getEnvironments();
    TIEnv *next_ti_env;

    const char* trace_text = loaded ? "ModuleLoad" : "ModuleUnload";

    while (NULL != ti_env)
    {
        next_ti_env = ti_env->next;

        NCAIEnv* env = ti_env->ncai_env;

        if (NULL == env)
        {
            ti_env = next_ti_env;
            continue;
        }

        ncaiModuleLoad func_l =
            (ncaiModuleLoad)env->get_event_callback(NCAI_EVENT_MODULE_LOAD);
        ncaiModuleLoad func_u =
            (ncaiModuleUnload)env->get_event_callback(NCAI_EVENT_MODULE_UNLOAD);

        ncaiModule env_module = NULL;
        ncaiModLU func = loaded ? (ncaiModLU)func_l : (ncaiModLU)func_u;
        ncaiEventKind event =
            loaded ? NCAI_EVENT_MODULE_LOAD : NCAI_EVENT_MODULE_UNLOAD;

        if (NULL != func)
        {
            if (env->global_events[event - NCAI_MIN_EVENT_TYPE_VAL])
            {
                TRACE2("ncai.modules",
                    "Calling global " << trace_text << " callback for module "
                    << module->info->name);

                find_init_module_record(env, module, &env_module);
                func((ncaiEnv*)env, thread, env_module);

                TRACE2("ncai.modules",
                    "Finished global " << trace_text << " callback for module "
                    << module->info->name);

                ti_env = next_ti_env;
                continue;
            }

            ncaiEventThread* next_et;
            ncaiEventThread* first_et =
                env->event_threads[event - NCAI_MIN_EVENT_TYPE_VAL];

            for (ncaiEventThread* et = first_et; NULL != et; et = next_et)
            {
                next_et = et->next;

                if (et->thread == thread)
                {
                    TRACE2("ncai.modules",
                        "Calling local " << trace_text << " callback for module "
                        << module->info->name);

                    find_init_module_record(env, module, &env_module);
                    func((ncaiEnv*)env, thread, env_module);

                    TRACE2("ncai.modules",
                        "Finished local " << trace_text << " callback for module "
                        << module->info->name);
                }
                et = next_et;
            }
        }
        ti_env = next_ti_env;
    }

    if (!suspend_enabled)
        hythread_suspend_disable();
}