1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 #ifndef PHPDBG_CMD_H
22 #define PHPDBG_CMD_H
23
24 #include "TSRM.h"
25
26
27 enum {
28 NO_ARG = 0,
29 REQUIRED_ARG,
30 OPTIONAL_ARG
31 };
32
33 typedef enum {
34 EMPTY_PARAM = 0,
35 ADDR_PARAM,
36 FILE_PARAM,
37 NUMERIC_FILE_PARAM,
38 METHOD_PARAM,
39 STR_PARAM,
40 NUMERIC_PARAM,
41 NUMERIC_FUNCTION_PARAM,
42 NUMERIC_METHOD_PARAM,
43 STACK_PARAM,
44 EVAL_PARAM,
45 SHELL_PARAM,
46 COND_PARAM,
47 OP_PARAM,
48 ORIG_PARAM,
49 RUN_PARAM
50 } phpdbg_param_type;
51
52 typedef struct _phpdbg_param phpdbg_param_t;
53 struct _phpdbg_param {
54 phpdbg_param_type type;
55 long num;
56 zend_ulong addr;
57 struct {
58 char *name;
59 long line;
60 } file;
61 struct {
62 char *class;
63 char *name;
64 } method;
65 char *str;
66 size_t len;
67 phpdbg_param_t *next;
68 phpdbg_param_t *top;
69 };
70
71 #define phpdbg_init_param(v, t) do{ \
72 (v)->type = (t); \
73 (v)->addr = 0; \
74 (v)->num = 0; \
75 (v)->file.name = NULL; \
76 (v)->file.line = 0; \
77 (v)->method.class = NULL; \
78 (v)->method.name = NULL; \
79 (v)->str = NULL; \
80 (v)->len = 0; \
81 (v)->next = NULL; \
82 (v)->top = NULL; \
83 } while(0)
84
85 #ifndef YYSTYPE
86 #define YYSTYPE phpdbg_param_t
87 #endif
88
89 #define PHPDBG_ASYNC_SAFE 1
90
91 typedef int (*phpdbg_command_handler_t)(const phpdbg_param_t*);
92
93 typedef struct _phpdbg_command_t phpdbg_command_t;
94 struct _phpdbg_command_t {
95 const char *name;
96 size_t name_len;
97 const char *tip;
98 size_t tip_len;
99 char alias;
100 phpdbg_command_handler_t handler;
101 const phpdbg_command_t *subs;
102 char *args;
103 const phpdbg_command_t *parent;
104 zend_bool flags;
105 };
106
107
108
109 #define PHPDBG_STRL(s) s, sizeof(s)-1
110 #define PHPDBG_MAX_CMD 500
111 #define PHPDBG_FRAME(v) (PHPDBG_G(frame).v)
112 #define PHPDBG_EX(v) (EG(current_execute_data)->v)
113
114 typedef struct {
115 int num;
116 zend_execute_data *execute_data;
117 } phpdbg_frame_t;
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132 PHPDBG_API char* phpdbg_read_input(char *buffered);
133 PHPDBG_API void phpdbg_destroy_input(char**);
134 PHPDBG_API int phpdbg_ask_user_permission(const char *question);
135
136
137
138
139 PHPDBG_API void phpdbg_stack_push(phpdbg_param_t *stack, phpdbg_param_t *param);
140 PHPDBG_API void phpdbg_stack_separate(phpdbg_param_t *param);
141 PHPDBG_API const phpdbg_command_t *phpdbg_stack_resolve(const phpdbg_command_t *commands, const phpdbg_command_t *parent, phpdbg_param_t **top);
142 PHPDBG_API int phpdbg_stack_verify(const phpdbg_command_t *command, phpdbg_param_t **stack);
143 PHPDBG_API int phpdbg_stack_execute(phpdbg_param_t *stack, zend_bool allow_async_unsafe);
144 PHPDBG_API void phpdbg_stack_free(phpdbg_param_t *stack);
145
146
147
148
149 PHPDBG_API void phpdbg_clear_param(phpdbg_param_t*);
150 PHPDBG_API void phpdbg_copy_param(const phpdbg_param_t*, phpdbg_param_t*);
151 PHPDBG_API zend_bool phpdbg_match_param(const phpdbg_param_t *, const phpdbg_param_t *);
152 PHPDBG_API zend_ulong phpdbg_hash_param(const phpdbg_param_t *);
153 PHPDBG_API const char* phpdbg_get_param_type(const phpdbg_param_t*);
154 PHPDBG_API char* phpdbg_param_tostring(const phpdbg_param_t *param, char **pointer);
155 PHPDBG_API void phpdbg_param_debug(const phpdbg_param_t *param, const char *msg);
156
157
158
159
160 #define PHPDBG_COMMAND_HANDLER(name) phpdbg_do_##name
161
162 #define PHPDBG_COMMAND_D_EXP(name, tip, alias, handler, children, args, parent, flags) \
163 {PHPDBG_STRL(#name), tip, sizeof(tip)-1, alias, phpdbg_do_##handler, children, args, parent, flags}
164
165 #define PHPDBG_COMMAND_D_EX(name, tip, alias, handler, children, args, flags) \
166 {PHPDBG_STRL(#name), tip, sizeof(tip)-1, alias, phpdbg_do_##handler, children, args, NULL, flags}
167
168 #define PHPDBG_COMMAND_D(name, tip, alias, children, args, flags) \
169 {PHPDBG_STRL(#name), tip, sizeof(tip)-1, alias, phpdbg_do_##name, children, args, NULL, flags}
170
171 #define PHPDBG_COMMAND(name) int phpdbg_do_##name(const phpdbg_param_t *param)
172
173 #define PHPDBG_COMMAND_ARGS param
174
175 #define PHPDBG_END_COMMAND {NULL, 0, NULL, 0, '\0', NULL, NULL, NULL, NULL, 0}
176
177
178
179
180 #define phpdbg_default_switch_case() \
181 default: \
182 phpdbg_error("command", "type=\"wrongarg\" got=\"%s\"", "Unsupported parameter type (%s) for command", phpdbg_get_param_type(param)); \
183 break
184
185 #endif