Skip to content

Commit 5af3714

Browse files
committed
debugging new input stuff
1 parent 1a2618b commit 5af3714

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

phpdbg_cmd.c

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ static inline phpdbg_input_t** phpdbg_read_argv(char *buffer, int *argc TSRMLS_D
137137
phpdbg_input_t *arg = emalloc(sizeof(phpdbg_input_t));\
138138
if (arg) {\
139139
b[l]=0;\
140-
arg->string = estrndup(b, l);\
140+
arg->length = l;\
141+
arg->string = estrndup(b, arg->length);\
141142
arg->argv=NULL;\
142143
arg->argc=0;\
143144
argv = (phpdbg_input_t**) erealloc(argv, sizeof(phpdbg_input_t*) * ((*argc)+1));\
@@ -319,6 +320,52 @@ void phpdbg_destroy_input(phpdbg_input_t **input TSRMLS_DC) /*{{{ */
319320
}
320321
} /* }}} */
321322

323+
int phpdbg_do_cmd_ex(const phpdbg_command_t *command, phpdbg_input_t *input TSRMLS_DC) /* {{{ */
324+
{
325+
int rc = FAILURE;
326+
327+
if (input->argc > 0) {
328+
while (command && command->name && command->handler) {
329+
if (((command->name_len == input->argv[0]->length) &&
330+
(memcmp(command->name, input->argv[0]->string, command->name_len) == SUCCESS)) ||
331+
(command->alias &&
332+
(input->argv[0]->length == 1) &&
333+
(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];
339+
340+
return phpdbg_do_cmd_ex(command->subs, &sub TSRMLS_CC);
341+
}
342+
343+
phpdbg_debug(
344+
"found command %s for %s with %d arguments",
345+
command->name, input->argv[0]->string, input->argc-1);
346+
{
347+
int arg;
348+
for (arg=1; arg<input->argc; arg++) {
349+
phpdbg_debug(
350+
"\t#%d: [%s=%d]",
351+
arg,
352+
input->argv[arg]->string,
353+
input->argv[arg]->length);
354+
}
355+
}
356+
break;
357+
}
358+
command++;
359+
}
360+
} else {
361+
/* this should NEVER happen */
362+
phpdbg_error(
363+
"No function executed !!");
364+
}
365+
366+
return rc;
367+
} /* }}} */
368+
322369
int phpdbg_do_cmd(const phpdbg_command_t *command, char *cmd_line, size_t cmd_len TSRMLS_DC) /* {{{ */
323370
{
324371
int rc = FAILURE;

phpdbg_cmd.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ struct _phpdbg_command_t {
8888
* Command Executor
8989
*/
9090
phpdbg_input_t* phpdbg_read_input(TSRMLS_D);
91+
int phpdbg_do_cmd_ex(const phpdbg_command_t*, phpdbg_input_t *input TSRMLS_DC);
9192
int phpdbg_do_cmd(const phpdbg_command_t*, char*, size_t TSRMLS_DC);
9293
phpdbg_param_type phpdbg_parse_param(const char*, size_t, phpdbg_param_t* TSRMLS_DC);
9394
void phpdbg_clear_param(phpdbg_param_t* TSRMLS_DC);

phpdbg_prompt.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -973,6 +973,8 @@ int phpdbg_interactive(TSRMLS_D) /* {{{ */
973973

974974
if (input && input->length > 0L) {
975975
do {
976+
phpdbg_do_cmd_ex(phpdbg_prompt_commands, input TSRMLS_CC);
977+
976978
switch (ret = phpdbg_do_cmd(phpdbg_prompt_commands, input->string, input->length TSRMLS_CC)) {
977979
case FAILURE:
978980
if (!(PHPDBG_G(flags) & PHPDBG_IS_QUITTING)) {

0 commit comments

Comments
 (0)