Commit 477ffc74 authored by kimu_shu's avatar kimu_shu

Add "info locals" command to mrdb

parent 971bfd13
...@@ -31,7 +31,7 @@ mrdb_check_syntax(mrb_state *mrb, mrb_debug_context *dbg, const char *expr, size ...@@ -31,7 +31,7 @@ mrdb_check_syntax(mrb_state *mrb, mrb_debug_context *dbg, const char *expr, size
} }
mrb_value mrb_value
mrb_debug_eval(mrb_state *mrb, mrb_debug_context *dbg, const char *expr, size_t len, mrb_bool *exc) mrb_debug_eval(mrb_state *mrb, mrb_debug_context *dbg, const char *expr, size_t len, mrb_bool *exc, int direct_eval)
{ {
void (*tmp)(struct mrb_state *, struct mrb_irep *, mrb_code *, mrb_value *); void (*tmp)(struct mrb_state *, struct mrb_irep *, mrb_code *, mrb_value *);
mrb_value ruby_code; mrb_value ruby_code;
...@@ -48,6 +48,11 @@ mrb_debug_eval(mrb_state *mrb, mrb_debug_context *dbg, const char *expr, size_t ...@@ -48,6 +48,11 @@ mrb_debug_eval(mrb_state *mrb, mrb_debug_context *dbg, const char *expr, size_t
v = mrb_obj_value(mrb->exc); v = mrb_obj_value(mrb->exc);
mrb->exc = 0; mrb->exc = 0;
} }
else if (direct_eval) {
recv = dbg->regs[0];
v = mrb_funcall(mrb, recv, expr, 0);
}
else { else {
/* /*
* begin * begin
......
...@@ -8,6 +8,6 @@ ...@@ -8,6 +8,6 @@
#include <mruby.h> #include <mruby.h>
#include "mrdb.h" #include "mrdb.h"
mrb_value mrb_debug_eval(mrb_state*, mrb_debug_context*, const char*, size_t, mrb_bool*); mrb_value mrb_debug_eval(mrb_state*, mrb_debug_context*, const char*, size_t, mrb_bool*, int);
#endif /* APIPRINT_H_ */ #endif /* APIPRINT_H_ */
...@@ -81,6 +81,12 @@ static help_msg help_msg_list[] = { ...@@ -81,6 +81,12 @@ static help_msg help_msg_list[] = {
"Status of specified breakpoints (all user-settable breakpoints if no argument).\n" "Status of specified breakpoints (all user-settable breakpoints if no argument).\n"
"Arguments are breakpoint numbers with spaces in between.\n" "Arguments are breakpoint numbers with spaces in between.\n"
}, },
{
"i[nfo]", "l[ocals]", "Print name of local variables",
"Usage: info locals\n"
"\n"
"Print name of local variables.\n"
},
{ {
"l[ist]", NULL, "List specified line", "l[ist]", NULL, "List specified line",
"Usage: list\n" "Usage: list\n"
......
...@@ -36,7 +36,7 @@ dbgcmd_print(mrb_state *mrb, mrdb_state *mrdb) ...@@ -36,7 +36,7 @@ dbgcmd_print(mrb_state *mrb, mrdb_state *mrdb)
expr = mrb_str_cat_cstr(mrb, expr, mrdb->words[wcnt]); expr = mrb_str_cat_cstr(mrb, expr, mrdb->words[wcnt]);
} }
result = mrb_debug_eval(mrb, mrdb->dbg, RSTRING_PTR(expr), RSTRING_LEN(expr), NULL); result = mrb_debug_eval(mrb, mrdb->dbg, RSTRING_PTR(expr), RSTRING_LEN(expr), NULL, 0);
/* $print_no = result */ /* $print_no = result */
s = mrb_str_cat_lit(mrb, result, "\0"); s = mrb_str_cat_lit(mrb, result, "\0");
...@@ -56,3 +56,26 @@ dbgcmd_eval(mrb_state *mrb, mrdb_state *mrdb) ...@@ -56,3 +56,26 @@ dbgcmd_eval(mrb_state *mrb, mrdb_state *mrdb)
{ {
return dbgcmd_print(mrb, 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;
}
...@@ -52,6 +52,7 @@ static const debug_command debug_command_list[] = { ...@@ -52,6 +52,7 @@ static const debug_command debug_command_list[] = {
{"eval", NULL, 2, 0, 0, DBGCMD_EVAL, dbgcmd_eval}, /* ev[al] */ {"eval", NULL, 2, 0, 0, DBGCMD_EVAL, dbgcmd_eval}, /* ev[al] */
{"help", NULL, 1, 0, 1, DBGCMD_HELP, dbgcmd_help}, /* h[elp] */ {"help", NULL, 1, 0, 1, DBGCMD_HELP, dbgcmd_help}, /* h[elp] */
{"info", "breakpoints", 1, 1, 1, DBGCMD_INFO_BREAK, dbgcmd_info_break}, /* i[nfo] b[reakpoints] */ {"info", "breakpoints", 1, 1, 1, DBGCMD_INFO_BREAK, dbgcmd_info_break}, /* i[nfo] b[reakpoints] */
{"info", "locals", 1, 1, 0, DBGCMD_INFO_LOCAL, dbgcmd_info_local}, /* i[nfo] l[ocals] */
{"list", NULL, 1, 0, 1, DBGCMD_LIST, dbgcmd_list}, /* l[ist] */ {"list", NULL, 1, 0, 1, DBGCMD_LIST, dbgcmd_list}, /* l[ist] */
{"print", NULL, 1, 0, 0, DBGCMD_PRINT, dbgcmd_print}, /* p[rint] */ {"print", NULL, 1, 0, 0, DBGCMD_PRINT, dbgcmd_print}, /* p[rint] */
{"quit", NULL, 1, 0, 0, DBGCMD_QUIT, dbgcmd_quit}, /* q[uit] */ {"quit", NULL, 1, 0, 0, DBGCMD_QUIT, dbgcmd_quit}, /* q[uit] */
......
...@@ -23,6 +23,7 @@ typedef enum debug_command_id { ...@@ -23,6 +23,7 @@ typedef enum debug_command_id {
DBGCMD_STEP, DBGCMD_STEP,
DBGCMD_BREAK, DBGCMD_BREAK,
DBGCMD_INFO_BREAK, DBGCMD_INFO_BREAK,
DBGCMD_INFO_LOCAL,
DBGCMD_WATCH, DBGCMD_WATCH,
DBGCMD_INFO_WATCH, DBGCMD_INFO_WATCH,
DBGCMD_ENABLE, DBGCMD_ENABLE,
...@@ -151,6 +152,7 @@ dbgcmd_state dbgcmd_next(mrb_state*, mrdb_state*); ...@@ -151,6 +152,7 @@ dbgcmd_state dbgcmd_next(mrb_state*, mrdb_state*);
/* cmdbreak.c */ /* cmdbreak.c */
dbgcmd_state dbgcmd_break(mrb_state*, mrdb_state*); dbgcmd_state dbgcmd_break(mrb_state*, mrdb_state*);
dbgcmd_state dbgcmd_info_break(mrb_state*, mrdb_state*); dbgcmd_state dbgcmd_info_break(mrb_state*, mrdb_state*);
dbgcmd_state dbgcmd_info_local(mrb_state*, mrdb_state*);
dbgcmd_state dbgcmd_delete(mrb_state*, mrdb_state*); dbgcmd_state dbgcmd_delete(mrb_state*, mrdb_state*);
dbgcmd_state dbgcmd_enable(mrb_state*, mrdb_state*); dbgcmd_state dbgcmd_enable(mrb_state*, mrdb_state*);
dbgcmd_state dbgcmd_disable(mrb_state*, mrdb_state*); dbgcmd_state dbgcmd_disable(mrb_state*, mrdb_state*);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment