/* ** cmdprint.c - mruby debugger print command functions ** */ #include #include "mrdb.h" #include #include #include #include #include #include #include "apiprint.h" dbgcmd_state dbgcmd_print(mrb_state *mrb, mrdb_state *mrdb) { mrb_value expr; mrb_value result; mrb_value s; uint8_t wcnt; int ai; if (mrdb->wcnt <= 1) { puts("Parameter not specified."); return DBGST_PROMPT; } ai = mrb_gc_arena_save(mrb); /* eval expr */ expr = mrb_str_new_cstr(mrb, NULL); for (wcnt=1; wcntwcnt; wcnt++) { expr = mrb_str_cat_lit(mrb, expr, " "); expr = mrb_str_cat_cstr(mrb, expr, mrdb->words[wcnt]); } result = mrb_debug_eval(mrb, mrdb->dbg, RSTRING_PTR(expr), RSTRING_LEN(expr), NULL, 0); /* $print_no = result */ s = mrb_str_cat_lit(mrb, result, "\0"); printf("$%lu = %s\n", (unsigned long)mrdb->print_no++, RSTRING_PTR(s)); if (mrdb->print_no == 0) { mrdb->print_no = 1; } mrb_gc_arena_restore(mrb, ai); return DBGST_PROMPT; } dbgcmd_state dbgcmd_eval(mrb_state *mrb, mrdb_state *mrdb) { return dbgcmd_print(mrb, mrdb); } dbgcmd_state dbgcmd_info_local(mrb_state *mrb, mrdb_state *mrdb) { mrb_value result; mrb_value s; int ai; ai = mrb_gc_arena_save(mrb); result = mrb_debug_eval(mrb, mrdb->dbg, "local_variables", 0, NULL, 1); s = mrb_str_cat_lit(mrb, result, "\0"); printf("$%lu = %s\n", (unsigned long)mrdb->print_no++, RSTRING_PTR(s)); if (mrdb->print_no == 0) { mrdb->print_no = 1; } mrb_gc_arena_restore(mrb, ai); return DBGST_PROMPT; }