Пример #1
0
void
MR_copy_saved_regs_to_regs(int max_mr_num, MR_Word *saved_regs,
    int max_f_num, MR_Float *saved_f_regs)
{
    /*
    ** We execute the converse procedure to MR_copy_regs_to_saved_regs.
    ** The MR_save_transient_registers is there so that a call to the
    ** MR_restore_transient_registers macro after MR_trace will do the
    ** right thing.
    */

    int i;

    for (i = 0; i <= max_mr_num; i++) {
        MR_fake_reg[i] = saved_regs[i];
    }

#ifdef MR_BOXED_FLOAT
    for (i = 0; i <= max_f_num; i++) {
        MR_float_reg[i] = saved_f_regs[i];
    }
#else
    (void) max_f_num;
    (void) saved_f_regs;
#endif

    MR_restore_registers();
    MR_save_transient_registers();
}
Пример #2
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;
        }
    }
}
Пример #3
0
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);
}