Browse Source

improve R

pull/550/head
krakjoe 13 years ago
parent
commit
80386a329b
  1. 32
      phpdbg_cmd.h
  2. 58
      phpdbg_prompt.c

32
phpdbg_cmd.h

@ -84,16 +84,38 @@ struct _phpdbg_command_t {
#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

58
phpdbg_prompt.c

@ -923,55 +923,63 @@ static inline int phpdbg_call_register(phpdbg_input_t *input TSRMLS_DC) /* {{{ *
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) ? &params : 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(&params[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;
}

Loading…
Cancel
Save