diff --git a/sapi/phpdbg/phpdbg.c b/sapi/phpdbg/phpdbg.c index 2d0f148fd7aa7..6f81a7a7c05f8 100644 --- a/sapi/phpdbg/phpdbg.c +++ b/sapi/phpdbg/phpdbg.c @@ -90,11 +90,6 @@ static void php_phpdbg_destroy_bp_condition(zval *data) /* {{{ */ efree(brake); } /* }}} */ -static void php_phpdbg_destroy_registered(zval *data) /* {{{ */ -{ - zend_function_dtor(data); -} /* }}} */ - static void php_phpdbg_destroy_file_source(zval *data) /* {{{ */ { phpdbg_file_source *source = (phpdbg_file_source *) Z_PTR_P(data); @@ -164,7 +159,7 @@ static PHP_MINIT_FUNCTION(phpdbg) /* {{{ */ zend_hash_init(&PHPDBG_G(bp)[PHPDBG_BREAK_MAP], 8, NULL, NULL, 0); zend_hash_init(&PHPDBG_G(seek), 8, NULL, NULL, 0); - zend_hash_init(&PHPDBG_G(registered), 8, NULL, php_phpdbg_destroy_registered, 0); + zend_hash_init(&PHPDBG_G(registered), 8, NULL, NULL, true); zend_hash_init(&PHPDBG_G(file_sources), 0, NULL, php_phpdbg_destroy_file_source, 0); phpdbg_setup_watchpoints(); diff --git a/sapi/phpdbg/phpdbg_prompt.c b/sapi/phpdbg/phpdbg_prompt.c index 6333fdcb76554..1fa15ecdb0cc5 100644 --- a/sapi/phpdbg/phpdbg_prompt.c +++ b/sapi/phpdbg/phpdbg_prompt.c @@ -81,7 +81,7 @@ const phpdbg_command_t phpdbg_prompt_commands[] = { PHPDBG_COMMAND_D(clear, "clear breakpoints", 'C', NULL, 0, 0), PHPDBG_COMMAND_D(help, "show help menu", 'h', phpdbg_help_commands, "|s", PHPDBG_ASYNC_SAFE), PHPDBG_COMMAND_D(set, "set phpdbg configuration", 'S', phpdbg_set_commands, "s", PHPDBG_ASYNC_SAFE), - PHPDBG_COMMAND_D(register, "register a function", 'R', NULL, "s", 0), + PHPDBG_COMMAND_D(register, "register a phpdbginit function as a command alias", 'R', NULL, "s", 0), PHPDBG_COMMAND_D(source, "execute a phpdbginit", '<', NULL, "s", 0), PHPDBG_COMMAND_D(export, "export breaks to a .phpdbginit script", '>', NULL, "s", PHPDBG_ASYNC_SAFE), PHPDBG_COMMAND_D(sh, "shell a command", 0 , NULL, "i", 0), @@ -96,34 +96,18 @@ static inline int phpdbg_call_register(phpdbg_param_t *stack) /* {{{ */ phpdbg_param_t *name = NULL; if (stack->type == STACK_PARAM) { - char *lc_name; - name = stack->next; if (!name || name->type != STR_PARAM) { return FAILURE; } - lc_name = zend_str_tolower_dup(name->str, name->len); - - if (zend_hash_str_exists(&PHPDBG_G(registered), lc_name, name->len)) { - zval fretval; - zend_fcall_info fci; - - memset(&fci, 0, sizeof(zend_fcall_info)); - - ZVAL_STRINGL(&fci.function_name, lc_name, name->len); - fci.size = sizeof(zend_fcall_info); - fci.object = NULL; - fci.retval = &fretval; - fci.param_count = 0; - fci.params = NULL; - fci.named_params = NULL; - - zval params; + zend_function *user_fn = zend_hash_str_find_ptr_lc(&PHPDBG_G(registered), name->str, name->len); + if (user_fn != NULL) { + HashTable *params_ht = NULL; if (name->next) { phpdbg_param_t *next = name->next; - + zval params; array_init(¶ms); while (next) { @@ -173,27 +157,19 @@ static inline int phpdbg_call_register(phpdbg_param_t *stack) /* {{{ */ next = next->next; } /* Add positional arguments */ - fci.named_params = Z_ARRVAL(params); + params_ht = Z_ARRVAL(params); + phpdbg_debug("created " PRIu32 " params from arguments", zend_hash_num_elements(params_ht)); } phpdbg_activate_err_buf(0); phpdbg_free_err_buf(); - phpdbg_debug("created %d params from arguments", fci.param_count); - if (zend_call_function(&fci, NULL) == SUCCESS) { - zend_print_zval_r(&fretval, 0); - phpdbg_out("\n"); - zval_ptr_dtor(&fretval); - } - - zval_ptr_dtor_str(&fci.function_name); - efree(lc_name); + zend_call_known_function(user_fn, NULL, NULL, NULL, 0, NULL, params_ht); + phpdbg_out("\n"); return SUCCESS; } - - efree(lc_name); } return FAILURE; @@ -1420,7 +1396,6 @@ PHPDBG_COMMAND(register) /* {{{ */ if (!zend_hash_str_exists(&PHPDBG_G(registered), lcname, lcname_len)) { if ((function = zend_hash_str_find_ptr(EG(function_table), lcname, lcname_len))) { zend_hash_str_update_ptr(&PHPDBG_G(registered), lcname, lcname_len, function); - function_add_ref(function); phpdbg_notice("Registered %s", lcname); } else { diff --git a/sapi/phpdbg/tests/register_function.phpt b/sapi/phpdbg/tests/register_function.phpt new file mode 100644 index 0000000000000..bf4f1615d3235 --- /dev/null +++ b/sapi/phpdbg/tests/register_function.phpt @@ -0,0 +1,30 @@ +--TEST-- +Test registering of functions +--PHPDBG-- +R testfunc +testfunc 1 2 3 +R var_dump +var_dump foo +q +--FILE-- + +--EXPECTF-- +[Successful compilation of %s] +prompt> [Registered testfunc] +prompt> array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} + +prompt> [Registered var_dump] +prompt> string(3) "foo" + +prompt>