1
0
mirror of https://github.com/php/php-src.git synced 2026-04-22 23:48:14 +02:00

fix registered commands during init, add test

This commit is contained in:
krakjoe
2013-12-06 20:18:44 +00:00
parent 4562eb0bc8
commit ad2ea99c3e
2 changed files with 99 additions and 68 deletions
+71 -68
View File
@@ -67,6 +67,71 @@ const phpdbg_command_t phpdbg_prompt_commands[] = {
ZEND_EXTERN_MODULE_GLOBALS(phpdbg);
static inline int phpdbg_call_register(phpdbg_input_t *input TSRMLS_DC) /* {{{ */
{
phpdbg_input_t *function = input->argv[0];
if (zend_hash_exists(
&PHPDBG_G(registered), function->string, function->length+1)) {
zval fname, *fretval;
zend_fcall_info fci;
ZVAL_STRINGL(&fname, function->string, function->length, 1);
memset(&fci, 0, sizeof(zend_fcall_info));
fci.size = sizeof(zend_fcall_info);
fci.function_table = &PHPDBG_G(registered);
fci.function_name = &fname;
fci.symbol_table = EG(active_symbol_table);
fci.object_ptr = NULL;
fci.retval_ptr_ptr = &fretval;
fci.no_separation = 1;
if (input->argc > 1) {
int param;
zval params;
array_init(&params);
for (param = 0; param < (input->argc-1); param++) {
add_next_index_stringl(
&params,
input->argv[param+1]->string,
input->argv[param+1]->length, 1);
phpdbg_debug(
"created param[%d] from argv[%d]: %s",
param, param+1, input->argv[param+1]->string);
}
zend_fcall_info_args(&fci, &params TSRMLS_CC);
} else {
fci.params = NULL;
fci.param_count = 0;
}
phpdbg_debug(
"created %d params from %d arguments",
fci.param_count, input->argc);
zend_call_function(&fci, NULL TSRMLS_CC);
if (fretval) {
zend_print_zval_r(
fretval, 0 TSRMLS_CC);
phpdbg_writeln(EMPTY);
}
zval_dtor(&fname);
return SUCCESS;
}
return FAILURE;
} /* }}} */
void phpdbg_try_file_init(char *init_file, size_t init_file_len, zend_bool free_init TSRMLS_DC) {
struct stat sb;
@@ -125,9 +190,12 @@ void phpdbg_try_file_init(char *init_file, size_t init_file_len, zend_bool free_
{
phpdbg_input_t *input = phpdbg_read_input(cmd TSRMLS_CC);
switch (phpdbg_do_cmd(phpdbg_prompt_commands, input TSRMLS_CC)) {
case FAILURE:
phpdbg_error(
"Unrecognized command in %s:%d: %s!", init_file, line, cmd);
case FAILURE:
if (!(PHPDBG_G(flags) & PHPDBG_IS_QUITTING)) {
if (phpdbg_call_register(input TSRMLS_CC) == FAILURE) {
phpdbg_error("Unrecognized command in %s:%d: %s!", init_file, line, input->string);
}
}
break;
}
phpdbg_destroy_input(&input TSRMLS_CC);
@@ -1070,71 +1138,6 @@ PHPDBG_COMMAND(list) /* {{{ */
return SUCCESS;
} /* }}} */
static inline int phpdbg_call_register(phpdbg_input_t *input TSRMLS_DC) /* {{{ */
{
phpdbg_input_t *function = input->argv[0];
if (zend_hash_exists(
&PHPDBG_G(registered), function->string, function->length+1)) {
zval fname, *fretval;
zend_fcall_info fci;
ZVAL_STRINGL(&fname, function->string, function->length, 1);
memset(&fci, 0, sizeof(zend_fcall_info));
fci.size = sizeof(zend_fcall_info);
fci.function_table = &PHPDBG_G(registered);
fci.function_name = &fname;
fci.symbol_table = EG(active_symbol_table);
fci.object_ptr = NULL;
fci.retval_ptr_ptr = &fretval;
fci.no_separation = 1;
if (input->argc > 1) {
int param;
zval params;
array_init(&params);
for (param = 0; param < (input->argc-1); param++) {
add_next_index_stringl(
&params,
input->argv[param+1]->string,
input->argv[param+1]->length, 1);
phpdbg_debug(
"created param[%d] from argv[%d]: %s",
param, param+1, input->argv[param+1]->string);
}
zend_fcall_info_args(&fci, &params TSRMLS_CC);
} else {
fci.params = NULL;
fci.param_count = 0;
}
phpdbg_debug(
"created %d params from %d arguments",
fci.param_count, input->argc);
zend_call_function(&fci, NULL TSRMLS_CC);
if (fretval) {
zend_print_zval_r(
fretval, 0 TSRMLS_CC);
phpdbg_writeln(EMPTY);
}
zval_dtor(&fname);
return SUCCESS;
}
return FAILURE;
} /* }}} */
int phpdbg_interactive(TSRMLS_D) /* {{{ */
{
int ret = SUCCESS;
+28
View File
@@ -0,0 +1,28 @@
#################################################
# name: register
# purpose: test registration functions
# expect: TEST::FORMAT
# options: -rr
#################################################
#[Registered test_function]
#array(5) {
# [0]=>
# string(1) "1"
# [1]=>
# string(1) "2"
# [2]=>
# string(1) "3"
# [3]=>
# string(1) "4"
# [4]=>
# string(1) "5"
#}
#################################################
<:
function test_function() {
var_dump(func_get_args());
}
:>
R test_function
test_function 1 2 3 4 5
q