summaryrefslogtreecommitdiffstats
path: root/web/server/h2o/libh2o/deps/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/mrdb.h
blob: 5ac12c1cd366a43104185c5c296e374dbd69916b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/*
** mrdb.h - mruby debugger
**
*/

#ifndef MRDB_H
#define MRDB_H

#include <mruby.h>

#include "mrdbconf.h"

#ifdef _MSC_VER
# define __func__ __FUNCTION__
#endif

#define MAX_COMMAND_WORD (16)

typedef enum debug_command_id {
  DBGCMD_RUN,
  DBGCMD_CONTINUE,
  DBGCMD_NEXT,
  DBGCMD_STEP,
  DBGCMD_BREAK,
  DBGCMD_INFO_BREAK,
  DBGCMD_WATCH,
  DBGCMD_INFO_WATCH,
  DBGCMD_ENABLE,
  DBGCMD_DISABLE,
  DBGCMD_DELETE,
  DBGCMD_PRINT,
  DBGCMD_DISPLAY,
  DBGCMD_INFO_DISPLAY,
  DBGCMD_DELETE_DISPLAY,
  DBGCMD_EVAL,
  DBGCMD_BACKTRACE,
  DBGCMD_LIST,
  DBGCMD_HELP,
  DBGCMD_QUIT,
  DBGCMD_UNKNOWN
} debug_command_id;

typedef enum dbgcmd_state {
  DBGST_CONTINUE,
  DBGST_PROMPT,
  DBGST_COMMAND_ERROR,
  DBGST_MAX,
  DBGST_RESTART
} dbgcmd_state;

typedef enum mrdb_exemode {
  DBG_INIT,
  DBG_RUN,
  DBG_STEP,
  DBG_NEXT,
  DBG_QUIT,
} mrdb_exemode;

typedef enum mrdb_exephase {
  DBG_PHASE_BEFORE_RUN,
  DBG_PHASE_RUNNING,
  DBG_PHASE_AFTER_RUN,
  DBG_PHASE_RESTART,
} mrdb_exephase;

typedef enum mrdb_brkmode {
  BRK_INIT,
  BRK_BREAK,
  BRK_STEP,
  BRK_NEXT,
  BRK_QUIT,
} mrdb_brkmode;

typedef enum {
  MRB_DEBUG_BPTYPE_NONE,
  MRB_DEBUG_BPTYPE_LINE,
  MRB_DEBUG_BPTYPE_METHOD,
} mrb_debug_bptype;

struct mrb_irep;
struct mrbc_context;
struct mrb_debug_context;

typedef struct mrb_debug_linepoint {
  const char *file;
  uint16_t lineno;
} mrb_debug_linepoint;

typedef struct mrb_debug_methodpoint {
  const char *class_name;
  const char *method_name;
} mrb_debug_methodpoint;

typedef struct mrb_debug_breakpoint {
  uint32_t bpno;
  uint8_t enable;
  mrb_debug_bptype type;
  union point {
    mrb_debug_linepoint linepoint;
    mrb_debug_methodpoint methodpoint;
  } point;
} mrb_debug_breakpoint;

typedef struct mrb_debug_context {
  struct mrb_irep *root_irep;
  struct mrb_irep *irep;
  mrb_code *pc;
  mrb_value *regs;

  const char *prvfile;
  int32_t prvline;
  mrb_callinfo *prvci;

  mrdb_exemode xm;
  mrdb_exephase xphase;
  mrdb_brkmode bm;
  int16_t bmi;

  uint16_t ccnt;
  uint16_t scnt;

  mrb_debug_breakpoint bp[MAX_BREAKPOINT];
  uint32_t bpnum;
  int32_t next_bpno;
  int32_t method_bpno;
  int32_t stopped_bpno;
  mrb_bool isCfunc;

  mrdb_exemode (*break_hook)(mrb_state *mrb, struct mrb_debug_context *dbg);

} mrb_debug_context;

typedef struct mrdb_state {
  char *command;
  uint8_t wcnt;
  uint8_t pi;
  char *words[MAX_COMMAND_WORD];
  const char *srcpath;
  uint32_t print_no;

  mrb_debug_context *dbg;
} mrdb_state;

typedef dbgcmd_state (*debug_command_func)(mrb_state*, mrdb_state*);

/* cmdrun.c */
dbgcmd_state dbgcmd_run(mrb_state*, mrdb_state*);
dbgcmd_state dbgcmd_continue(mrb_state*, mrdb_state*);
dbgcmd_state dbgcmd_step(mrb_state*, mrdb_state*);
dbgcmd_state dbgcmd_next(mrb_state*, mrdb_state*);
/* cmdbreak.c */
dbgcmd_state dbgcmd_break(mrb_state*, mrdb_state*);
dbgcmd_state dbgcmd_info_break(mrb_state*, mrdb_state*);
dbgcmd_state dbgcmd_delete(mrb_state*, mrdb_state*);
dbgcmd_state dbgcmd_enable(mrb_state*, mrdb_state*);
dbgcmd_state dbgcmd_disable(mrb_state*, mrdb_state*);
/* cmdprint.c */
dbgcmd_state dbgcmd_print(mrb_state*, mrdb_state*);
dbgcmd_state dbgcmd_eval(mrb_state*, mrdb_state*);
/* cmdmisc.c */
dbgcmd_state dbgcmd_list(mrb_state*, mrdb_state*);
dbgcmd_state dbgcmd_help(mrb_state*, mrdb_state*);
dbgcmd_state dbgcmd_quit(mrb_state*, mrdb_state*);

#endif