#define PHPDBG_STRL(s) s, sizeof(s)-1
#define PHPDBG_MAX_CMD 500
-/**
- * Command Executor
- */
+/*
+* Workflow:
+* 1) read input
+* input takes the line from console, creates argc/argv
+* 2) parse parameters into suitable types based on arg_type
+* takes input from 1) and arg_type and creates parameters
+* 3) do command
+* executes commands
+* 4) destroy parameters
+* cleans up what was allocated by creation of parameters
+* 5) destroy input
+* cleans up what was allocated by creation of input
+*/
+
+/*
+* Input Management
+*/
phpdbg_input_t* phpdbg_read_input(char *buffered TSRMLS_DC);
phpdbg_input_t** phpdbg_read_argv(char *buffer, int *argc TSRMLS_DC);
-int phpdbg_do_cmd(const phpdbg_command_t*, phpdbg_input_t *input TSRMLS_DC);
+void phpdbg_destroy_input(phpdbg_input_t** TSRMLS_DC);
+
+/*
+* Parameter Management
+*/
phpdbg_param_type phpdbg_parse_param(const char*, size_t, phpdbg_param_t* TSRMLS_DC);
void phpdbg_clear_param(phpdbg_param_t* TSRMLS_DC);
const char* phpdbg_get_param_type(const phpdbg_param_t* TSRMLS_DC);
-void phpdbg_destroy_input(phpdbg_input_t** TSRMLS_DC);
+
+/*
+* Command Executor
+*/
+int phpdbg_do_cmd(const phpdbg_command_t*, phpdbg_input_t *input TSRMLS_DC);
/**
* Command Declarators
if (zend_hash_exists(
&PHPDBG_G(registered), function->string, function->length+1)) {
+
zval fname, *fretval;
zend_fcall_info fci;
- zval **params = NULL;
+
+ ZVAL_STRINGL(&fname, function->string, function->length, 1);
+ fci.size = sizeof(fci);
+ 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 arg;
+ zval ***params;
+ zval *zparam;
+
+ fci.param_count = (input->argc > 1) ? (input->argc-1) : 0;
+ fci.params = (zval***) emalloc(fci.param_count * sizeof(zval**));
- params = emalloc(sizeof(zval*) * input->argc);
+ params = fci.params;
for (arg = 1; arg <= (input->argc-1); arg++) {
- MAKE_STD_ZVAL((params[arg-1]));
+ MAKE_STD_ZVAL(zparam);
ZVAL_STRINGL(
- (params[arg-1]),
+ zparam,
input->argv[arg]->string,
input->argv[arg]->length, 1);
+
+ *params++ = &zparam;
}
+ } else {
+ fci.params = NULL;
+ fci.param_count = 0;
}
- ZVAL_STRINGL(&fname, function->string, function->length, 1);
-
- fci.size = sizeof(fci);
- 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.param_count = (input->argc > 1) ? (input->argc-1) : 0;
- fci.params = (input->argc > 1) ? ¶ms : NULL;
- fci.no_separation = 1;
-
- zend_call_function(
- &fci, NULL TSRMLS_CC);
+ zend_call_function(&fci, NULL TSRMLS_CC);
- zval_dtor(&fname);
-
if (input->argc > 1) {
- int arg;
+ int param;
- for (arg = 1; arg <= (input->argc-1); arg++) {
- zval_ptr_dtor(¶ms[arg-1]);
+ for (param = 0; param < fci.param_count; param++) {
+ zval_ptr_dtor(fci.params[param]);
}
- efree(params);
+ efree(fci.params);
}
+
if (fretval) {
zend_print_zval_r(
fretval, 0 TSRMLS_CC);
phpdbg_writeln(EMPTY);
}
+
+ zval_dtor(&fname);
+
return SUCCESS;
}