Skip to content

Commit b65cef9

Browse files
committed
more on functions
1 parent 5af3714 commit b65cef9

File tree

2 files changed

+61
-31
lines changed

2 files changed

+61
-31
lines changed

phpdbg_cmd.c

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -331,17 +331,33 @@ int phpdbg_do_cmd_ex(const phpdbg_command_t *command, phpdbg_input_t *input TSRM
331331
(command->alias &&
332332
(input->argv[0]->length == 1) &&
333333
(command->alias == *input->argv[0]->string))) {
334-
if (command->subs && input->argc > 1) {
335-
phpdbg_input_t sub;
336-
337-
sub.argc = input->argc-1;
338-
sub.argv = &input->argv[1];
334+
335+
phpdbg_param_t param;
336+
337+
param.type = EMPTY_PARAM;
338+
339+
if (input->argc > 1) {
340+
if (command->subs) {
341+
phpdbg_input_t sub;
342+
343+
sub.argc = input->argc-1;
344+
sub.argv = &input->argv[1];
345+
346+
phpdbg_debug(
347+
"trying sub commands in \"%s\" for \"%s\" with %d arguments",
348+
command->name, sub.argv[0]->string, sub.argc-1);
339349

340-
return phpdbg_do_cmd_ex(command->subs, &sub TSRMLS_CC);
350+
return phpdbg_do_cmd_ex(command->subs, &sub TSRMLS_CC);
351+
} else {
352+
phpdbg_parse_param(
353+
input->argv[1]->string,
354+
input->argv[1]->length,
355+
&param TSRMLS_CC);
356+
}
341357
}
342358

343359
phpdbg_debug(
344-
"found command %s for %s with %d arguments",
360+
"found command \"%s\" for \"%s\" have %d arguments",
345361
command->name, input->argv[0]->string, input->argc-1);
346362
{
347363
int arg;
@@ -353,6 +369,14 @@ int phpdbg_do_cmd_ex(const phpdbg_command_t *command, phpdbg_input_t *input TSRM
353369
input->argv[arg]->length);
354370
}
355371
}
372+
373+
PHPDBG_G(lcmd) = (phpdbg_command_t*) command;
374+
phpdbg_clear_param(
375+
&PHPDBG_G(lparam) TSRMLS_CC);
376+
PHPDBG_G(lparam) = param;
377+
378+
rc = command->handler(&param TSRMLS_CC);
379+
356380
break;
357381
}
358382
command++;

phpdbg_prompt.c

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ void phpdbg_init(char *init_file, size_t init_file_len, zend_bool use_default TS
153153
}
154154
goto next_line;
155155
}
156-
156+
157157
switch (phpdbg_do_cmd(phpdbg_prompt_commands, cmd, cmd_len TSRMLS_CC)) {
158158
case FAILURE:
159159
phpdbg_error(
@@ -914,26 +914,29 @@ static PHPDBG_COMMAND(list) /* {{{ */
914914

915915
static inline int phpdbg_call_register(phpdbg_input_t *input TSRMLS_DC) /* {{{ */
916916
{
917-
/* temporary, until we can handle arrays of strings */
918-
const char *cmd = input->string;
919-
size_t cmd_len = input->length;
920-
const char *start = (const char*) input->start;
921-
size_t offset = strlen(cmd)+(sizeof(" ")-1);
917+
phpdbg_input_t *function = input->argv[0];
922918

923-
if (zend_hash_exists(&PHPDBG_G(registered), cmd, strlen(cmd)+1)) {
924-
zval fname, *fretval, *farg = NULL;
919+
if (zend_hash_exists(
920+
&PHPDBG_G(registered), function->string, function->length+1)) {
921+
zval fname, *fretval;
925922
zend_fcall_info fci;
926-
zend_fcall_info_cache fcic;
927-
928-
zval **params[1];
923+
zval **params = NULL;
929924

930-
if (offset < cmd_len) {
931-
ALLOC_INIT_ZVAL(farg);
932-
ZVAL_STRING(farg, &start[offset], 1);
933-
params[0] = &farg;
925+
if (input->argc > 1) {
926+
int arg;
927+
928+
params = emalloc(sizeof(zval*) * input->argc);
929+
930+
for (arg = 1; arg <= (input->argc-1); arg++) {
931+
MAKE_STD_ZVAL((params[arg-1]));
932+
ZVAL_STRINGL(
933+
(params[arg-1]),
934+
input->argv[arg]->string,
935+
input->argv[arg]->length, 1);
936+
}
934937
}
935938

936-
ZVAL_STRINGL(&fname, cmd, strlen(cmd), 1);
939+
ZVAL_STRINGL(&fname, function->string, function->length, 1);
937940

938941
fci.size = sizeof(fci);
939942
fci.function_table = &PHPDBG_G(registered);
@@ -942,17 +945,22 @@ static inline int phpdbg_call_register(phpdbg_input_t *input TSRMLS_DC) /* {{{ *
942945
fci.object_ptr = NULL;
943946
fci.retval_ptr_ptr = &fretval;
944947

945-
/* todo parse parameters better */
946-
fci.param_count = (offset < cmd_len) ? 1 : 0;
947-
fci.params = (offset < cmd_len) ? params : NULL;
948+
fci.param_count = (input->argc > 1) ? (input->argc-1) : 0;
949+
fci.params = (input->argc > 1) ? &params : NULL;
948950
fci.no_separation = 1;
949951

950952
zend_call_function(
951953
&fci, NULL TSRMLS_CC);
952954

953955
zval_dtor(&fname);
954-
if (offset < cmd_len) {
955-
zval_ptr_dtor(&farg);
956+
957+
if (input->argc > 1) {
958+
int arg;
959+
960+
for (arg = 1; arg <= (input->argc-1); arg++) {
961+
zval_ptr_dtor(&params[arg-1]);
962+
}
963+
efree(params);
956964
}
957965
if (fretval) {
958966
zend_print_zval_r(
@@ -973,9 +981,7 @@ int phpdbg_interactive(TSRMLS_D) /* {{{ */
973981

974982
if (input && input->length > 0L) {
975983
do {
976-
phpdbg_do_cmd_ex(phpdbg_prompt_commands, input TSRMLS_CC);
977-
978-
switch (ret = phpdbg_do_cmd(phpdbg_prompt_commands, input->string, input->length TSRMLS_CC)) {
984+
switch (ret = phpdbg_do_cmd_ex(phpdbg_prompt_commands, input TSRMLS_CC)) {
979985
case FAILURE:
980986
if (!(PHPDBG_G(flags) & PHPDBG_IS_QUITTING)) {
981987
if (phpdbg_call_register(input TSRMLS_CC) == FAILURE) {

0 commit comments

Comments
 (0)