コード例 #1
0
void
MR_agc_dump_roots(MR_RootList roots)
{
#ifndef MR_HIGHLEVEL_CODE
    MR_Word saved_regs[MR_MAX_FAKE_REG];
    MR_Float saved_f_regs[MR_MAX_VIRTUAL_F_REG];
#endif

    fflush(NULL);
    fprintf(stderr, "Dumping roots\n");

    if (MR_debug_agc_print_vars) {
        while (roots != NULL) {
#ifndef MR_HIGHLEVEL_CODE
            /*
            ** Restore the registers, because we need to save them to a more
            ** permanent backing store (we are going to call Mercury soon,
            ** and we don't want it messing with the saved registers).
            */
            MR_restore_registers();
            MR_copy_regs_to_saved_regs(MR_MAX_FAKE_REG - 1, saved_regs,
                MR_MAX_VIRTUAL_F_REG - 1, saved_f_regs);

            MR_hp_word = MR_ENGINE(MR_eng_debug_heap_zone->MR_zone_min);
            MR_virtual_hp_word = MR_ENGINE(MR_eng_debug_heap_zone->MR_zone_min);
#endif /* !MR_HIGHLEVEL_CODE */

            fflush(NULL);
            MR_write_variable(roots->type_info, *roots->root);
            fflush(NULL);
            fprintf(stderr, "\n");

#ifndef MR_HIGHLEVEL_CODE
            MR_copy_saved_regs_to_regs(MR_MAX_FAKE_REG - 1, saved_regs,
                MR_MAX_VIRTUAL_F_REG, saved_f_regs);
            MR_save_registers();
#endif /* !MR_HIGHLEVEL_CODE */
            roots = roots->next;
        }
    }
}
コード例 #2
0
ファイル: mercury_agc_debug.c プロジェクト: htzh/mercury
static void
MR_dump_live_variables(const MR_LabelLayout *label_layout,
    MR_MemoryZone *heap_zone, MR_bool top_frame,
    MR_Word *stack_pointer, MR_Word *current_frame)
{
    int                 short_var_count;
    int                 long_var_count;
    int                 i;
    MR_TypeInfo         type_info;
    MR_Word             value;
    MR_TypeInfoParams   type_params;
    MR_Word             saved_regs[MR_MAX_FAKE_REG];
    MR_Float            saved_f_regs[MR_MAX_VIRTUAL_F_REG];
    MR_Word             *current_regs;
    MR_Float            *current_f_regs;

    long_var_count = MR_long_desc_var_count(label_layout);
    short_var_count = MR_short_desc_var_count(label_layout);

    // For the top stack frame, we should pass a pointer to a filled-in
    // saved_regs instead of NULL. For other stack frames, passing NULL
    // is fine, since output arguments are not live yet for any call
    // except the top one.

    MR_restore_registers();
    MR_copy_regs_to_saved_regs(MR_MAX_FAKE_REG - 1, saved_regs,
        MR_MAX_VIRTUAL_F_REG - 1, saved_f_regs);
    if (top_frame) {
        current_regs = saved_regs;
        current_f_regs = saved_f_regs;
    } else {
        current_regs = NULL;
        current_f_regs = NULL;
    }
    type_params = MR_materialize_type_params_base(label_layout,
        current_regs, stack_pointer, current_frame);

    for (i = 0; i < long_var_count; i++) {
        fprintf(stderr, "%-12s\t", "");
        if (MR_PROC_LAYOUT_HAS_PROC_ID(label_layout->MR_sll_entry)) {
            MR_print_proc_id(stderr, label_layout->MR_sll_entry);
        }

        MR_dump_long_value(MR_long_desc_var_locn(label_layout, i),
            heap_zone, stack_pointer, current_frame, top_frame);
        fprintf(stderr, "\n");
        fflush(NULL);

        if (MR_debug_agc_print_vars) {
            // Call Mercury but use the debugging heap.

            MR_hp_word = MR_ENGINE(MR_eng_debug_heap_zone->MR_zone_min);
            MR_virtual_hp_word = MR_ENGINE(MR_eng_debug_heap_zone->MR_zone_min);

            if (MR_get_type_and_value_base(label_layout, i,
                    current_regs, stack_pointer, current_frame, current_f_regs,
                    type_params, &type_info, &value)) {
                printf("\t");
                MR_write_variable(type_info, value);
                printf("\n");
            }

            fflush(NULL);
        }
    }

    for (i = 0; i < short_var_count; i++) {
        fprintf(stderr, "%-12s\t", "");
        if (MR_PROC_LAYOUT_HAS_PROC_ID(label_layout->MR_sll_entry)) {
            MR_print_proc_id(stderr, label_layout->MR_sll_entry);
        }

        MR_dump_short_value(MR_short_desc_var_locn(label_layout, i),
            heap_zone, stack_pointer, current_frame, top_frame);
        fprintf(stderr, "\n");
        fflush(NULL);

        if (MR_debug_agc_print_vars) {
            // Call Mercury but use the debugging heap.

            MR_hp_word = MR_ENGINE(MR_eng_debug_heap_zone->MR_zone_min);
            MR_virtual_hp_word = MR_ENGINE(MR_eng_debug_heap_zone->MR_zone_min);

            if (MR_get_type_and_value_base(label_layout, i,
                    current_regs, stack_pointer, current_frame, current_f_regs,
                    type_params, &type_info, &value)) {
                printf("\t");
                MR_write_variable(type_info, value);
                printf("\n");
            }

            fflush(NULL);
        }
    }

    MR_copy_saved_regs_to_regs(MR_MAX_FAKE_REG - 1, saved_regs,
        MR_MAX_VIRTUAL_F_REG - 1, saved_f_regs);
    MR_save_registers();
    MR_free(type_params);
}
コード例 #3
0
static MR_bool
MR_spy_cond_is_true(MR_SpyPoint *point, const MR_LabelLayout *label_layout)
{
    int             max_mr_num;
    MR_Word         saved_regs[MR_MAX_FAKE_REG];
    int             max_f_num;
    MR_Float        saved_f_regs[MR_MAX_VIRTUAL_F_REG];
    const char      *problem;
    char            *bad_path;
    MR_TypeInfo     type_info;
    MR_Word         value;
    const char      *name;
    MR_Word         *value_ptr;
    MR_TypeInfo     sub_type_info;
    MR_Word         *sub_value_ptr;
    MR_Word         match;
    MR_bool         saved_trace_func_enabled;
    MR_bool         retval;
    MR_SpyCond      *cond;

    if (point->MR_spy_cond == NULL) {
        return MR_TRUE;
    }

    MR_restore_transient_registers();

    cond = point->MR_spy_cond;

    /*
    ** From this point, returning should be done by setting both
    ** MR_spy_point_cond_problem and retval, and goto end.
    */

    MR_spy_point_cond_bad = cond;
    MR_spy_point_cond_problem = "internal error in MR_spy_cond_is_true";
    retval = MR_TRUE;

    MR_compute_max_mr_num(max_mr_num, label_layout);
    max_f_num = label_layout->MR_sll_entry->MR_sle_max_f_num;
    /* This also saves the regs in MR_fake_regs. */
    MR_copy_regs_to_saved_regs(max_mr_num, saved_regs,
        max_f_num, saved_f_regs);
    MR_trace_init_point_vars(label_layout, saved_regs, saved_f_regs,
        (MR_TracePort) label_layout->MR_sll_port, MR_FALSE);

    problem = MR_lookup_unambiguous_var_spec(cond->MR_cond_var_spec,
        &type_info, &value, &name);
    if (problem != NULL) {
        if (cond->MR_cond_require_var) {
            MR_spy_point_cond_problem = problem;
            retval = MR_TRUE;
        } else {
            MR_spy_point_cond_problem = NULL;
            retval = MR_FALSE;
        }

        goto end;
    }

    value_ptr = &value;
    bad_path = MR_select_specified_subterm(cond->MR_cond_path,
        type_info, value_ptr, &sub_type_info, &sub_value_ptr);

    if (bad_path != NULL) {
        if (cond->MR_cond_require_var) {
            MR_spy_point_cond_problem = MR_trace_bad_path(cond->MR_cond_path,
                bad_path);
            retval = MR_TRUE;
        } else {
            MR_spy_point_cond_problem = NULL;
            retval = MR_FALSE;
        }
        goto end;
    }

#ifdef MR_DEBUG_SPY_COND
    MR_print_cterm(stdout, cond->cond_term);
    fprintf(stdout, ": ");
#endif

    saved_trace_func_enabled = MR_trace_func_enabled;
    MR_trace_func_enabled = MR_FALSE;
    MR_TRACE_CALL_MERCURY(
        ML_BROWSE_match_with_cterm((MR_Word) sub_type_info, *sub_value_ptr,
            cond->MR_cond_term, &match);
    );