}
} /* }}} */
-int phpdbg_do_cmd(const phpdbg_command_t *command, const phpdbg_input_t *input TSRMLS_DC) /* {{{ */
+int phpdbg_do_cmd(const phpdbg_command_t *command, phpdbg_input_t *input TSRMLS_DC) /* {{{ */
{
int rc = FAILURE;
phpdbg_param_t param;
param.type = EMPTY_PARAM;
-
+
if (input->argc > 1) {
if (command->subs) {
phpdbg_input_t sub;
+ sub.length = input->length;
+ sub.string = input->string;
+ sub.start = input->start;
+
+ sub.string += input->argv[0]->length;
+ sub.length -= input->argv[0]->length;
+ while (isspace(*sub.string)) {
+ sub.string++;
+ sub.length--;
+ }
sub.argc = input->argc-1;
sub.argv = &input->argv[1];
-
+ sub.string = estrndup(sub.string, sub.length);
+
phpdbg_debug(
"trying sub commands in \"%s\" for \"%s\" with %d arguments",
command->name, sub.argv[0]->string, sub.argc-1);
if (phpdbg_do_cmd(command->subs, &sub TSRMLS_CC) == SUCCESS) {
+ efree(sub.string);
return SUCCESS;
}
+
+ efree(sub.string);
+ } else {
+ char *store = input->string;
+
+ input->string += input->argv[0]->length;
+ input->length -= input->argv[0]->length;
+ while (isspace(*input->string)) {
+ input->string++;
+ input->length--;
+ }
+ input->string = estrndup(input->string, input->length);
+ efree(store);
}
/* pass parameter on */
phpdbg_parse_param(
- input->argv[1]->string,
- input->argv[1]->length,
+ input->string,
+ input->length,
¶m TSRMLS_CC);
}
PHPDBG_COMMAND(eval) /* {{{ */
{
- zend_bool stepping = ((PHPDBG_G(flags) & PHPDBG_IS_STEPPING)==PHPDBG_IS_STEPPING);
- zval retval;
- char *code = NULL;
-
- if (!(PHPDBG_G(flags) & PHPDBG_IS_STEPONEVAL)) {
- PHPDBG_G(flags) &= ~ PHPDBG_IS_STEPPING;
- }
-
- if (input && input->start) {
- code = (char*) input->start;
+ switch (param->type) {
+ case STR_PARAM: {
+ zend_bool stepping = ((PHPDBG_G(flags) & PHPDBG_IS_STEPPING)==PHPDBG_IS_STEPPING);
+ zval retval;
- if (memcmp(
- code, "eval", sizeof("eval")-1) == SUCCESS) {
- code += sizeof("eval")-1;
- } else code += sizeof("E")-1;
+ if (!(PHPDBG_G(flags) & PHPDBG_IS_STEPONEVAL)) {
+ PHPDBG_G(flags) &= ~ PHPDBG_IS_STEPPING;
+ }
- while (code && isspace(*code)) {
- code++;
- }
- } else phpdbg_error("Nothing to execute");
-
- /* disable stepping while eval() in progress */
- PHPDBG_G(flags) |= PHPDBG_IN_EVAL;
- if (zend_eval_stringl(code, strlen(code),
- &retval, "eval()'d code" TSRMLS_CC) == SUCCESS) {
- zend_print_zval_r(
- &retval, 0 TSRMLS_CC);
- phpdbg_writeln(EMPTY);
- zval_dtor(&retval);
- }
- PHPDBG_G(flags) &= ~PHPDBG_IN_EVAL;
+ /* disable stepping while eval() in progress */
+ PHPDBG_G(flags) |= PHPDBG_IN_EVAL;
+ if (zend_eval_stringl(param->str, param->len,
+ &retval, "eval()'d code" TSRMLS_CC) == SUCCESS) {
+ zend_print_zval_r(
+ &retval, 0 TSRMLS_CC);
+ phpdbg_writeln(EMPTY);
+ zval_dtor(&retval);
+ }
+ PHPDBG_G(flags) &= ~PHPDBG_IN_EVAL;
- /* switch stepping back on */
- if (stepping &&
- !(PHPDBG_G(flags) & PHPDBG_IS_STEPONEVAL)) {
- PHPDBG_G(flags) |= PHPDBG_IS_STEPPING;
+ /* switch stepping back on */
+ if (stepping &&
+ !(PHPDBG_G(flags) & PHPDBG_IS_STEPONEVAL)) {
+ PHPDBG_G(flags) |= PHPDBG_IS_STEPPING;
+ }
+ } break;
+
+ phpdbg_default_switch_case();
}
return SUCCESS;
switch (param->type) {
case STR_PARAM: {
FILE *fd = NULL;
- char * program = NULL;
-
- /* we expect an input, I hope we get one ! */
- if (input && input->start) {
- program = (char*) input->start;
-
- if (memcmp(
- program, "shell", sizeof("shell")-1) == SUCCESS) {
- program += sizeof("shell")-1;
- } else program += sizeof("-")-1;
-
- while (program && isspace(*program)) {
- program++;
- }
- } else program = param->str;
-
- if ((fd=VCWD_POPEN((char*)program, "w"))) {
+ if ((fd=VCWD_POPEN((char*)param->str, "w"))) {
/* do something perhaps ?? do we want input ?? */
fclose(fd);
} else {
phpdbg_error(
- "Failed to execute %s", program);
+ "Failed to execute %s", param->str);
}
} break;