mirror of
https://github.com/php/php-src.git
synced 2025-08-19 08:49:28 +02:00
more on functions
This commit is contained in:
parent
5af371409c
commit
b65cef950a
2 changed files with 61 additions and 31 deletions
28
phpdbg_cmd.c
28
phpdbg_cmd.c
|
@ -331,17 +331,33 @@ int phpdbg_do_cmd_ex(const phpdbg_command_t *command, phpdbg_input_t *input TSRM
|
||||||
(command->alias &&
|
(command->alias &&
|
||||||
(input->argv[0]->length == 1) &&
|
(input->argv[0]->length == 1) &&
|
||||||
(command->alias == *input->argv[0]->string))) {
|
(command->alias == *input->argv[0]->string))) {
|
||||||
if (command->subs && input->argc > 1) {
|
|
||||||
|
phpdbg_param_t param;
|
||||||
|
|
||||||
|
param.type = EMPTY_PARAM;
|
||||||
|
|
||||||
|
if (input->argc > 1) {
|
||||||
|
if (command->subs) {
|
||||||
phpdbg_input_t sub;
|
phpdbg_input_t sub;
|
||||||
|
|
||||||
sub.argc = input->argc-1;
|
sub.argc = input->argc-1;
|
||||||
sub.argv = &input->argv[1];
|
sub.argv = &input->argv[1];
|
||||||
|
|
||||||
|
phpdbg_debug(
|
||||||
|
"trying sub commands in \"%s\" for \"%s\" with %d arguments",
|
||||||
|
command->name, sub.argv[0]->string, sub.argc-1);
|
||||||
|
|
||||||
return phpdbg_do_cmd_ex(command->subs, &sub TSRMLS_CC);
|
return phpdbg_do_cmd_ex(command->subs, &sub TSRMLS_CC);
|
||||||
|
} else {
|
||||||
|
phpdbg_parse_param(
|
||||||
|
input->argv[1]->string,
|
||||||
|
input->argv[1]->length,
|
||||||
|
¶m TSRMLS_CC);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
phpdbg_debug(
|
phpdbg_debug(
|
||||||
"found command %s for %s with %d arguments",
|
"found command \"%s\" for \"%s\" have %d arguments",
|
||||||
command->name, input->argv[0]->string, input->argc-1);
|
command->name, input->argv[0]->string, input->argc-1);
|
||||||
{
|
{
|
||||||
int arg;
|
int arg;
|
||||||
|
@ -353,6 +369,14 @@ int phpdbg_do_cmd_ex(const phpdbg_command_t *command, phpdbg_input_t *input TSRM
|
||||||
input->argv[arg]->length);
|
input->argv[arg]->length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PHPDBG_G(lcmd) = (phpdbg_command_t*) command;
|
||||||
|
phpdbg_clear_param(
|
||||||
|
&PHPDBG_G(lparam) TSRMLS_CC);
|
||||||
|
PHPDBG_G(lparam) = param;
|
||||||
|
|
||||||
|
rc = command->handler(¶m TSRMLS_CC);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
command++;
|
command++;
|
||||||
|
|
|
@ -914,26 +914,29 @@ static PHPDBG_COMMAND(list) /* {{{ */
|
||||||
|
|
||||||
static inline int phpdbg_call_register(phpdbg_input_t *input TSRMLS_DC) /* {{{ */
|
static inline int phpdbg_call_register(phpdbg_input_t *input TSRMLS_DC) /* {{{ */
|
||||||
{
|
{
|
||||||
/* temporary, until we can handle arrays of strings */
|
phpdbg_input_t *function = input->argv[0];
|
||||||
const char *cmd = input->string;
|
|
||||||
size_t cmd_len = input->length;
|
|
||||||
const char *start = (const char*) input->start;
|
|
||||||
size_t offset = strlen(cmd)+(sizeof(" ")-1);
|
|
||||||
|
|
||||||
if (zend_hash_exists(&PHPDBG_G(registered), cmd, strlen(cmd)+1)) {
|
if (zend_hash_exists(
|
||||||
zval fname, *fretval, *farg = NULL;
|
&PHPDBG_G(registered), function->string, function->length+1)) {
|
||||||
|
zval fname, *fretval;
|
||||||
zend_fcall_info fci;
|
zend_fcall_info fci;
|
||||||
zend_fcall_info_cache fcic;
|
zval **params = NULL;
|
||||||
|
|
||||||
zval **params[1];
|
if (input->argc > 1) {
|
||||||
|
int arg;
|
||||||
|
|
||||||
if (offset < cmd_len) {
|
params = emalloc(sizeof(zval*) * input->argc);
|
||||||
ALLOC_INIT_ZVAL(farg);
|
|
||||||
ZVAL_STRING(farg, &start[offset], 1);
|
for (arg = 1; arg <= (input->argc-1); arg++) {
|
||||||
params[0] = &farg;
|
MAKE_STD_ZVAL((params[arg-1]));
|
||||||
|
ZVAL_STRINGL(
|
||||||
|
(params[arg-1]),
|
||||||
|
input->argv[arg]->string,
|
||||||
|
input->argv[arg]->length, 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ZVAL_STRINGL(&fname, cmd, strlen(cmd), 1);
|
ZVAL_STRINGL(&fname, function->string, function->length, 1);
|
||||||
|
|
||||||
fci.size = sizeof(fci);
|
fci.size = sizeof(fci);
|
||||||
fci.function_table = &PHPDBG_G(registered);
|
fci.function_table = &PHPDBG_G(registered);
|
||||||
|
@ -942,17 +945,22 @@ static inline int phpdbg_call_register(phpdbg_input_t *input TSRMLS_DC) /* {{{ *
|
||||||
fci.object_ptr = NULL;
|
fci.object_ptr = NULL;
|
||||||
fci.retval_ptr_ptr = &fretval;
|
fci.retval_ptr_ptr = &fretval;
|
||||||
|
|
||||||
/* todo parse parameters better */
|
fci.param_count = (input->argc > 1) ? (input->argc-1) : 0;
|
||||||
fci.param_count = (offset < cmd_len) ? 1 : 0;
|
fci.params = (input->argc > 1) ? ¶ms : NULL;
|
||||||
fci.params = (offset < cmd_len) ? params : NULL;
|
|
||||||
fci.no_separation = 1;
|
fci.no_separation = 1;
|
||||||
|
|
||||||
zend_call_function(
|
zend_call_function(
|
||||||
&fci, NULL TSRMLS_CC);
|
&fci, NULL TSRMLS_CC);
|
||||||
|
|
||||||
zval_dtor(&fname);
|
zval_dtor(&fname);
|
||||||
if (offset < cmd_len) {
|
|
||||||
zval_ptr_dtor(&farg);
|
if (input->argc > 1) {
|
||||||
|
int arg;
|
||||||
|
|
||||||
|
for (arg = 1; arg <= (input->argc-1); arg++) {
|
||||||
|
zval_ptr_dtor(¶ms[arg-1]);
|
||||||
|
}
|
||||||
|
efree(params);
|
||||||
}
|
}
|
||||||
if (fretval) {
|
if (fretval) {
|
||||||
zend_print_zval_r(
|
zend_print_zval_r(
|
||||||
|
@ -973,9 +981,7 @@ int phpdbg_interactive(TSRMLS_D) /* {{{ */
|
||||||
|
|
||||||
if (input && input->length > 0L) {
|
if (input && input->length > 0L) {
|
||||||
do {
|
do {
|
||||||
phpdbg_do_cmd_ex(phpdbg_prompt_commands, input TSRMLS_CC);
|
switch (ret = phpdbg_do_cmd_ex(phpdbg_prompt_commands, input TSRMLS_CC)) {
|
||||||
|
|
||||||
switch (ret = phpdbg_do_cmd(phpdbg_prompt_commands, input->string, input->length TSRMLS_CC)) {
|
|
||||||
case FAILURE:
|
case FAILURE:
|
||||||
if (!(PHPDBG_G(flags) & PHPDBG_IS_QUITTING)) {
|
if (!(PHPDBG_G(flags) & PHPDBG_IS_QUITTING)) {
|
||||||
if (phpdbg_call_register(input TSRMLS_CC) == FAILURE) {
|
if (phpdbg_call_register(input TSRMLS_CC) == FAILURE) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue