forked from php/php-src
- Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphpdbg_cmd.h
181 lines (157 loc) · 5.89 KB
/
phpdbg_cmd.h
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Felipe Pena <felipe@php.net> |
| Authors: Joe Watkins <joe.watkins@live.co.uk> |
| Authors: Bob Weinand <bwoebi@php.net> |
+----------------------------------------------------------------------+
*/
#ifndefPHPDBG_CMD_H
#definePHPDBG_CMD_H
#include"TSRM.h"
#include"zend_generators.h"
/* {{{ Command and Parameter */
enum {
NO_ARG=0,
REQUIRED_ARG,
OPTIONAL_ARG
};
typedefenum {
EMPTY_PARAM=0,
ADDR_PARAM,
FILE_PARAM,
NUMERIC_FILE_PARAM,
METHOD_PARAM,
STR_PARAM,
NUMERIC_PARAM,
NUMERIC_FUNCTION_PARAM,
NUMERIC_METHOD_PARAM,
STACK_PARAM,
EVAL_PARAM,
SHELL_PARAM,
COND_PARAM,
OP_PARAM,
ORIG_PARAM,
RUN_PARAM
} phpdbg_param_type;
typedefstruct_phpdbg_paramphpdbg_param_t;
struct_phpdbg_param {
phpdbg_param_typetype;
zend_longnum;
zend_ulongaddr;
struct {
char*name;
zend_ulongline;
} file;
struct {
char*class;
char*name;
} method;
char*str;
size_tlen;
phpdbg_param_t*next;
phpdbg_param_t*top;
};
#definephpdbg_init_param(v, t) do{ \
(v)->type = (t); \
(v)->addr = 0; \
(v)->num = 0; \
(v)->file.name = NULL; \
(v)->file.line = 0; \
(v)->method.class = NULL; \
(v)->method.name = NULL; \
(v)->str = NULL; \
(v)->len = 0; \
(v)->next = NULL; \
(v)->top = NULL; \
} while(0)
#definePHPDBG_ASYNC_SAFE 1
typedefint (*phpdbg_command_handler_t)(constphpdbg_param_t*);
typedefstruct_phpdbg_command_tphpdbg_command_t;
struct_phpdbg_command_t {
constchar*name; /* Command name */
size_tname_len; /* Command name length */
constchar*tip; /* Menu tip */
size_ttip_len; /* Menu tip length */
charalias; /* Alias */
phpdbg_command_handler_thandler; /* Command handler */
constphpdbg_command_t*subs; /* Sub Commands */
char*args; /* Argument Spec */
constphpdbg_command_t*parent; /* Parent Command */
boolflags; /* General flags */
};
/* }}} */
/* {{{ misc */
#definePHPDBG_STRL(s) s, sizeof(s)-1
#definePHPDBG_MAX_CMD 500
#definePHPDBG_FRAME(v) (PHPDBG_G(frame).v)
#definePHPDBG_EX(v) (EG(current_execute_data)->v)
typedefstruct {
intnum;
zend_generator*generator;
zend_execute_data*execute_data;
} phpdbg_frame_t;
/* }}} */
/*
* Workflow:
* 1) the lexer/parser creates a stack of commands and arguments from input
* 2) the commands at the top of the stack are resolved sensibly using aliases, abbreviations and case insensitive matching
* 3) the remaining arguments in the stack are verified (optionally) against the handlers declared argument specification
* 4) the handler is called passing the top of the stack as the only parameter
* 5) the stack is destroyed upon return from the handler
*/
/*
* Input Management
*/
PHPDBG_APIchar*phpdbg_read_input(constchar*buffered);
PHPDBG_APIvoidphpdbg_destroy_input(char**input);
PHPDBG_APIintphpdbg_ask_user_permission(constchar*question);
/**
* Stack Management
*/
PHPDBG_APIvoidphpdbg_stack_push(phpdbg_param_t*stack, phpdbg_param_t*param);
PHPDBG_APIvoidphpdbg_stack_separate(phpdbg_param_t*param);
PHPDBG_APIconstphpdbg_command_t*phpdbg_stack_resolve(constphpdbg_command_t*commands, constphpdbg_command_t*parent, phpdbg_param_t**top);
PHPDBG_APIintphpdbg_stack_verify(constphpdbg_command_t*command, phpdbg_param_t**stack);
PHPDBG_APIintphpdbg_stack_execute(phpdbg_param_t*stack, boolallow_async_unsafe);
PHPDBG_APIvoidphpdbg_stack_free(phpdbg_param_t*stack);
/*
* Parameter Management
*/
PHPDBG_APIvoidphpdbg_clear_param(phpdbg_param_t*);
PHPDBG_APIvoidphpdbg_copy_param(constphpdbg_param_t*, phpdbg_param_t*);
PHPDBG_APIboolphpdbg_match_param(constphpdbg_param_t*, constphpdbg_param_t*);
PHPDBG_APIzend_ulongphpdbg_hash_param(constphpdbg_param_t*);
PHPDBG_APIconstchar*phpdbg_get_param_type(constphpdbg_param_t*);
PHPDBG_APIchar*phpdbg_param_tostring(constphpdbg_param_t*param, char**pointer);
PHPDBG_APIvoidphpdbg_param_debug(constphpdbg_param_t*param, constchar*msg);
/**
* Command Declarators
*/
#definePHPDBG_COMMAND_HANDLER(name) phpdbg_do_##name
#definePHPDBG_COMMAND_D_EXP(name, tip, alias, handler, children, args, parent, flags) \
{PHPDBG_STRL(#name), tip, sizeof(tip)-1, alias, phpdbg_do_##handler, children, args, parent, flags}
#definePHPDBG_COMMAND_D_EX(name, tip, alias, handler, children, args, flags) \
{PHPDBG_STRL(#name), tip, sizeof(tip)-1, alias, phpdbg_do_##handler, children, args, NULL, flags}
#definePHPDBG_COMMAND_D(name, tip, alias, children, args, flags) \
{PHPDBG_STRL(#name), tip, sizeof(tip)-1, alias, phpdbg_do_##name, children, args, NULL, flags}
#definePHPDBG_COMMAND(name) int phpdbg_do_##name(const phpdbg_param_t *param)
#definePHPDBG_COMMAND_ARGS param
#definePHPDBG_END_COMMAND {NULL, 0, NULL, 0, '\0', NULL, NULL, NULL, NULL, 0}
/*
* Default Switch Case
*/
#definephpdbg_default_switch_case() \
default: \
phpdbg_error("Unsupported parameter type (%s) for command", phpdbg_get_param_type(param)); \
break
#endif/* PHPDBG_CMD_H */