1 /* 2 ** mrdb.h - mruby debugger 3 ** 4 */ 5 6 #ifndef MRDB_H 7 #define MRDB_H 8 9 #include <mruby.h> 10 11 #include "mrdbconf.h" 12 13 #ifdef _MSC_VER 14 # define __func__ __FUNCTION__ 15 #endif 16 17 #define MAX_COMMAND_WORD (16) 18 19 typedef enum debug_command_id { 20 DBGCMD_RUN, 21 DBGCMD_CONTINUE, 22 DBGCMD_NEXT, 23 DBGCMD_STEP, 24 DBGCMD_BREAK, 25 DBGCMD_INFO_BREAK, 26 DBGCMD_INFO_LOCAL, 27 DBGCMD_WATCH, 28 DBGCMD_INFO_WATCH, 29 DBGCMD_ENABLE, 30 DBGCMD_DISABLE, 31 DBGCMD_DELETE, 32 DBGCMD_PRINT, 33 DBGCMD_DISPLAY, 34 DBGCMD_INFO_DISPLAY, 35 DBGCMD_DELETE_DISPLAY, 36 DBGCMD_EVAL, 37 DBGCMD_BACKTRACE, 38 DBGCMD_LIST, 39 DBGCMD_HELP, 40 DBGCMD_QUIT, 41 DBGCMD_UNKNOWN 42 } debug_command_id; 43 44 typedef enum dbgcmd_state { 45 DBGST_CONTINUE, 46 DBGST_PROMPT, 47 DBGST_COMMAND_ERROR, 48 DBGST_MAX, 49 DBGST_RESTART 50 } dbgcmd_state; 51 52 typedef enum mrdb_exemode { 53 DBG_INIT, 54 DBG_RUN, 55 DBG_STEP, 56 DBG_NEXT, 57 DBG_QUIT, 58 } mrdb_exemode; 59 60 typedef enum mrdb_exephase { 61 DBG_PHASE_BEFORE_RUN, 62 DBG_PHASE_RUNNING, 63 DBG_PHASE_AFTER_RUN, 64 DBG_PHASE_RESTART, 65 } mrdb_exephase; 66 67 typedef enum mrdb_brkmode { 68 BRK_INIT, 69 BRK_BREAK, 70 BRK_STEP, 71 BRK_NEXT, 72 BRK_QUIT, 73 } mrdb_brkmode; 74 75 typedef enum { 76 MRB_DEBUG_BPTYPE_NONE, 77 MRB_DEBUG_BPTYPE_LINE, 78 MRB_DEBUG_BPTYPE_METHOD, 79 } mrb_debug_bptype; 80 81 struct mrb_irep; 82 struct mrbc_context; 83 struct mrb_debug_context; 84 85 typedef struct mrb_debug_linepoint { 86 const char *file; 87 uint16_t lineno; 88 } mrb_debug_linepoint; 89 90 typedef struct mrb_debug_methodpoint { 91 const char *class_name; 92 const char *method_name; 93 } mrb_debug_methodpoint; 94 95 typedef struct mrb_debug_breakpoint { 96 uint32_t bpno; 97 uint8_t enable; 98 mrb_debug_bptype type; 99 union point { 100 mrb_debug_linepoint linepoint; 101 mrb_debug_methodpoint methodpoint; 102 } point; 103 } mrb_debug_breakpoint; 104 105 typedef struct mrb_debug_context { 106 struct mrb_irep *root_irep; 107 struct mrb_irep *irep; 108 const mrb_code *pc; 109 mrb_value *regs; 110 111 const char *prvfile; 112 int32_t prvline; 113 mrb_callinfo *prvci; 114 115 mrdb_exemode xm; 116 mrdb_exephase xphase; 117 mrdb_brkmode bm; 118 int16_t bmi; 119 120 uint16_t ccnt; 121 uint16_t scnt; 122 123 mrb_debug_breakpoint bp[MAX_BREAKPOINT]; 124 uint32_t bpnum; 125 int32_t next_bpno; 126 int32_t method_bpno; 127 int32_t stopped_bpno; 128 mrb_bool isCfunc; 129 130 mrdb_exemode (*break_hook)(mrb_state *mrb, struct mrb_debug_context *dbg); 131 132 } mrb_debug_context; 133 134 typedef struct mrdb_state { 135 char *command; 136 uint8_t wcnt; 137 uint8_t pi; 138 char *words[MAX_COMMAND_WORD]; 139 const char *srcpath; 140 uint32_t print_no; 141 142 mrb_debug_context *dbg; 143 } mrdb_state; 144 145 typedef dbgcmd_state (*debug_command_func)(mrb_state*, mrdb_state*); 146 147 /* cmdrun.c */ 148 dbgcmd_state dbgcmd_run(mrb_state*, mrdb_state*); 149 dbgcmd_state dbgcmd_continue(mrb_state*, mrdb_state*); 150 dbgcmd_state dbgcmd_step(mrb_state*, mrdb_state*); 151 dbgcmd_state dbgcmd_next(mrb_state*, mrdb_state*); 152 /* cmdbreak.c */ 153 dbgcmd_state dbgcmd_break(mrb_state*, mrdb_state*); 154 dbgcmd_state dbgcmd_info_break(mrb_state*, mrdb_state*); 155 dbgcmd_state dbgcmd_info_local(mrb_state*, mrdb_state*); 156 dbgcmd_state dbgcmd_delete(mrb_state*, mrdb_state*); 157 dbgcmd_state dbgcmd_enable(mrb_state*, mrdb_state*); 158 dbgcmd_state dbgcmd_disable(mrb_state*, mrdb_state*); 159 /* cmdprint.c */ 160 dbgcmd_state dbgcmd_print(mrb_state*, mrdb_state*); 161 dbgcmd_state dbgcmd_eval(mrb_state*, mrdb_state*); 162 /* cmdmisc.c */ 163 dbgcmd_state dbgcmd_list(mrb_state*, mrdb_state*); 164 dbgcmd_state dbgcmd_help(mrb_state*, mrdb_state*); 165 dbgcmd_state dbgcmd_quit(mrb_state*, mrdb_state*); 166 167 #endif 168