Skip to content

Commit 41537cd

Browse files
krakjoebwoebi
authored andcommitted
remove dodgy param parser, bring userland breakpoint api inline with PHP7
1 parent 51c1cc4 commit 41537cd

File tree

5 files changed

+278
-316
lines changed

5 files changed

+278
-316
lines changed

sapi/phpdbg/phpdbg.c

Lines changed: 65 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -301,24 +301,12 @@ static PHP_FUNCTION(phpdbg_exec)
301301
}
302302
} /* }}} */
303303

304-
/* {{{ proto void phpdbg_break([integer type, string expression])
304+
/* {{{ proto void phpdbg_break_next()
305305
instructs phpdbg to insert a breakpoint at the next opcode */
306-
static PHP_FUNCTION(phpdbg_break)
306+
static PHP_FUNCTION(phpdbg_break_next)
307307
{
308-
if (ZEND_NUM_ARGS() > 0) {
309-
long type = 0;
310-
char *expr = NULL;
311-
int expr_len = 0;
312-
phpdbg_param_t param;
313-
314-
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ls", &type, &expr, &expr_len) == FAILURE) {
315-
return;
316-
}
317-
318-
phpdbg_parse_param(expr, expr_len, &param TSRMLS_CC);
319-
phpdbg_do_break(&param TSRMLS_CC);
320-
phpdbg_clear_param(&param TSRMLS_CC);
321-
308+
if (zend_parse_parameters_none() != SUCCESS) {
309+
return;
322310
} else if (EG(current_execute_data) && EG(active_op_array)) {
323311
zend_ulong opline_num = (EG(current_execute_data)->opline -
324312
EG(active_op_array)->opcodes);
@@ -328,6 +316,48 @@ static PHP_FUNCTION(phpdbg_break)
328316
}
329317
} /* }}} */
330318

319+
/* {{{ proto void phpdbg_break_file(string file, integer line) */
320+
static PHP_FUNCTION(phpdbg_break_file)
321+
{
322+
char *file = NULL;
323+
int flen = 0;
324+
long line;
325+
326+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl", &file, &flen, &line) == FAILURE) {
327+
return;
328+
}
329+
330+
phpdbg_set_breakpoint_file(file, line TSRMLS_CC);
331+
} /* }}} */
332+
333+
/* {{{ proto void phpdbg_break_method(string class, string method) */
334+
static PHP_FUNCTION(phpdbg_break_method)
335+
{
336+
char *class = NULL,
337+
*method = NULL;
338+
int clen = 0,
339+
mlen = 0;
340+
341+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &class, &clen, &method, &mlen) == FAILURE) {
342+
return;
343+
}
344+
345+
phpdbg_set_breakpoint_method(class, method TSRMLS_CC);
346+
} /* }}} */
347+
348+
/* {{{ proto void phpdbg_break_function(string function) */
349+
static PHP_FUNCTION(phpdbg_break_function)
350+
{
351+
char *function = NULL;
352+
int function_len;
353+
354+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &function, &function_len) == FAILURE) {
355+
return;
356+
}
357+
358+
phpdbg_set_breakpoint_symbol(function, function_len TSRMLS_CC);
359+
} /* }}} */
360+
331361
/* {{{ proto void phpdbg_clear(void)
332362
instructs phpdbg to clear breakpoints */
333363
static PHP_FUNCTION(phpdbg_clear)
@@ -377,9 +407,21 @@ static PHP_FUNCTION(phpdbg_prompt)
377407
phpdbg_set_prompt(prompt TSRMLS_CC);
378408
} /* }}} */
379409

380-
ZEND_BEGIN_ARG_INFO_EX(phpdbg_break_arginfo, 0, 0, 0)
381-
ZEND_ARG_INFO(0, type)
382-
ZEND_ARG_INFO(0, expression)
410+
ZEND_BEGIN_ARG_INFO_EX(phpdbg_break_next_arginfo, 0, 0, 0)
411+
ZEND_END_ARG_INFO()
412+
413+
ZEND_BEGIN_ARG_INFO_EX(phpdbg_break_file_arginfo, 0, 0, 2)
414+
ZEND_ARG_INFO(0, file)
415+
ZEND_ARG_INFO(0, line)
416+
ZEND_END_ARG_INFO()
417+
418+
ZEND_BEGIN_ARG_INFO_EX(phpdbg_break_method_arginfo, 0, 0, 2)
419+
ZEND_ARG_INFO(0, class)
420+
ZEND_ARG_INFO(0, method)
421+
ZEND_END_ARG_INFO()
422+
423+
ZEND_BEGIN_ARG_INFO_EX(phpdbg_break_function_arginfo, 0, 0, 1)
424+
ZEND_ARG_INFO(0, function)
383425
ZEND_END_ARG_INFO()
384426

385427
ZEND_BEGIN_ARG_INFO_EX(phpdbg_color_arginfo, 0, 0, 0)
@@ -400,7 +442,10 @@ ZEND_END_ARG_INFO()
400442

401443
zend_function_entry phpdbg_user_functions[] = {
402444
PHP_FE(phpdbg_clear, phpdbg_clear_arginfo)
403-
PHP_FE(phpdbg_break, phpdbg_break_arginfo)
445+
PHP_FE(phpdbg_break_next, phpdbg_break_next_arginfo)
446+
PHP_FE(phpdbg_break_file, phpdbg_break_file_arginfo)
447+
PHP_FE(phpdbg_break_method, phpdbg_break_method_arginfo)
448+
PHP_FE(phpdbg_break_function, phpdbg_break_function_arginfo)
404449
PHP_FE(phpdbg_exec, phpdbg_exec_arginfo)
405450
PHP_FE(phpdbg_color, phpdbg_color_arginfo)
406451
PHP_FE(phpdbg_prompt, phpdbg_prompt_arginfo)

sapi/phpdbg/phpdbg_cmd.c

Lines changed: 0 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -70,79 +70,6 @@ PHPDBG_API const char *phpdbg_get_param_type(const phpdbg_param_t *param TSRMLS_
7070
}
7171
}
7272

73-
PHPDBG_API phpdbg_param_type phpdbg_parse_param(const char *str, size_t len, phpdbg_param_t *param TSRMLS_DC) /* {{{ */
74-
{
75-
char *class_name, *func_name;
76-
77-
if (len == 0) {
78-
param->type = EMPTY_PARAM;
79-
goto parsed;
80-
}
81-
82-
if (phpdbg_is_addr(str)) {
83-
param->addr = strtoul(str, 0, 16);
84-
param->type = ADDR_PARAM;
85-
goto parsed;
86-
87-
} else if (phpdbg_is_numeric(str)) {
88-
param->num = strtol(str, NULL, 0);
89-
param->type = NUMERIC_PARAM;
90-
goto parsed;
91-
92-
} else if (phpdbg_is_class_method(str, len+1, &class_name, &func_name)) {
93-
param->method.class = class_name;
94-
param->method.name = func_name;
95-
param->type = METHOD_PARAM;
96-
goto parsed;
97-
} else {
98-
char *line_pos = strrchr(str, ':');
99-
100-
if (line_pos && phpdbg_is_numeric(line_pos+1)) {
101-
if (strchr(str, ':') == line_pos) {
102-
char path[MAXPATHLEN];
103-
104-
memcpy(path, str, line_pos - str);
105-
path[line_pos - str] = 0;
106-
*line_pos = 0;
107-
param->file.name = phpdbg_resolve_path(path TSRMLS_CC);
108-
param->file.line = strtol(line_pos+1, NULL, 0);
109-
param->type = FILE_PARAM;
110-
111-
goto parsed;
112-
}
113-
}
114-
115-
line_pos = strrchr(str, '#');
116-
117-
if (line_pos && phpdbg_is_numeric(line_pos+1)) {
118-
if (strchr(str, '#') == line_pos) {
119-
param->num = strtol(line_pos + 1, NULL, 0);
120-
121-
if (phpdbg_is_class_method(str, line_pos - str, &class_name, &func_name)) {
122-
param->method.class = class_name;
123-
param->method.name = func_name;
124-
param->type = NUMERIC_METHOD_PARAM;
125-
} else {
126-
param->len = line_pos - str;
127-
param->str = estrndup(str, param->len);
128-
param->type = NUMERIC_FUNCTION_PARAM;
129-
}
130-
131-
goto parsed;
132-
}
133-
}
134-
}
135-
136-
param->str = estrndup(str, len);
137-
param->len = len;
138-
param->type = STR_PARAM;
139-
140-
parsed:
141-
phpdbg_debug("phpdbg_parse_param(\"%s\", %lu): %s",
142-
str, len, phpdbg_get_param_type(param TSRMLS_CC));
143-
return param->type;
144-
} /* }}} */
145-
14673
PHPDBG_API void phpdbg_clear_param(phpdbg_param_t *param TSRMLS_DC) /* {{{ */
14774
{
14875
if (param) {

sapi/phpdbg/phpdbg_cmd.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ PHPDBG_API void phpdbg_stack_free(phpdbg_param_t *stack);
145145
/*
146146
* Parameter Management
147147
*/
148-
PHPDBG_API phpdbg_param_type phpdbg_parse_param(const char*, size_t, phpdbg_param_t* TSRMLS_DC);
149148
PHPDBG_API void phpdbg_clear_param(phpdbg_param_t* TSRMLS_DC);
150149
PHPDBG_API void phpdbg_copy_param(const phpdbg_param_t*, phpdbg_param_t* TSRMLS_DC);
151150
PHPDBG_API zend_bool phpdbg_match_param(const phpdbg_param_t *, const phpdbg_param_t * TSRMLS_DC);

0 commit comments

Comments
 (0)