ZEND_EXTERN_MODULE_GLOBALS(phpdbg);
- static inline void i_phpdbg_list_func(const char *str, size_t len TSRMLS_DC)
- {
- HashTable *func_table = EG(function_table);
- zend_function* fbc;
- char *func_name = str;
- size_t func_name_len = len;
-
- /* search active scope if begins with period */
- if (func_name[0] == '.') {
- if (EG(scope)) {
- func_name++;
- func_name_len--;
-
- func_table = &EG(scope)->function_table;
- } else {
- phpdbg_error("No active class");
- return;
- }
- } else if (!EG(function_table)) {
- phpdbg_error("No function table loaded");
- return;
- } else {
- func_table = EG(function_table);
- }
-
- /* use lowercase names, case insensitive */
- func_name = zend_str_tolower_dup(func_name, func_name_len);
-
- if (zend_hash_find(func_table, func_name, func_name_len+1,
- (void**)&fbc) == SUCCESS) {
- phpdbg_list_function(fbc TSRMLS_CC);
- } else {
- phpdbg_error("Function %s not found", func_name);
- }
-
- efree(func_name);
- }
-
PHPDBG_LIST(lines) /* {{{ */
{
- switch (param->type) {
- case NUMERIC_PARAM:
- case EMPTY_PARAM: {
- if (PHPDBG_G(exec) || zend_is_executing(TSRMLS_C)) {
- if (param->type == EMPTY_PARAM) {
- phpdbg_list_file(phpdbg_current_file(TSRMLS_C), 0, 0, 0 TSRMLS_CC);
- } else phpdbg_list_file(phpdbg_current_file(TSRMLS_C), param->num, 0, 0 TSRMLS_CC);
- } else phpdbg_error("Not executing, and execution context not set");
- } break;
-
- default:
- phpdbg_error("Unsupported parameter type (%s) for function", phpdbg_get_param_type(param TSRMLS_CC));
- }
-
+ if (!PHPDBG_G(exec) || !zend_is_executing(TSRMLS_C)) {
+ phpdbg_error("Not executing, and execution context not set");
+ return SUCCESS;
+ }
+
+ switch (param->type) {
+ case NUMERIC_PARAM:
+ case EMPTY_PARAM:
+ phpdbg_list_file(phpdbg_current_file(TSRMLS_C),
+ param->type == EMPTY_PARAM ? 0 : param->num,
- zend_get_executed_lineno(TSRMLS_C) TSRMLS_CC);
++ zend_get_executed_lineno(TSRMLS_C), 0 TSRMLS_CC);
+ break;
+ case FILE_PARAM:
- phpdbg_list_file(param->file.name, param->file.line, 0 TSRMLS_CC);
++ phpdbg_list_file(param->file.name, param->file.line, 0, 0 TSRMLS_CC);
+ break;
+ default:
+ phpdbg_error("Unsupported parameter type (%s) for function",
+ phpdbg_get_param_type(param TSRMLS_CC));
+ }
+
return SUCCESS;
} /* }}} */
PHPDBG_LIST(func) /* {{{ */
{
- if (param->type == STR_PARAM) {
- i_phpdbg_list_func(
- param->str, param->len TSRMLS_CC);
- } else {
- phpdbg_error(
- "Unsupported parameter type (%s) for function", phpdbg_get_param_type(param TSRMLS_CC));
+ switch (param->type) {
+ case STR_PARAM:
+ phpdbg_list_function_byname(
+ param->str, param->len TSRMLS_CC);
+ break;
-
++
+ phpdbg_default_switch_case();
}
-
+
return SUCCESS;
} /* }}} */
PHPDBG_LIST(method) /* {{{ */
{
- if (param->type == METHOD_PARAM) {
- zend_class_entry **ce;
+ switch (param->type) {
+ case METHOD_PARAM: {
+ zend_class_entry **ce;
-
++
+ if (zend_lookup_class(param->method.class, strlen(param->method.class), &ce TSRMLS_CC) == SUCCESS) {
+ zend_function *function;
+ char *lcname = zend_str_tolower_dup(
+ param->method.name, strlen(param->method.name));
-
+
- if (zend_lookup_class(param->method.class, strlen(param->method.class), &ce TSRMLS_CC) == SUCCESS) {
- zend_function *function;
- char *lcname = zend_str_tolower_dup(
- param->method.name, strlen(param->method.name));
+ if (zend_hash_find(&(*ce)->function_table, lcname, strlen(lcname)+1, (void**) &function) == SUCCESS) {
+ phpdbg_list_function(
+ function TSRMLS_CC);
+ } else {
+ phpdbg_error("Could not find ::%s in %s", param->method.name, param->method.class);
+ }
-
+
- if (zend_hash_find(&(*ce)->function_table, lcname, strlen(lcname)+1, (void**) &function) == SUCCESS) {
- phpdbg_list_function(
- function TSRMLS_CC);
+ efree(lcname);
} else {
- phpdbg_error("Could not find ::%s in %s", param->method.name, param->method.class);
+ phpdbg_error("Could not find the class %s", param->method.class);
}
-
+ } break;
- efree(lcname);
- } else {
- phpdbg_error("Could not find the class %s", param->method.class);
- }
- } else {
- phpdbg_error(
- "Unsupported parameter type (%s) for function", phpdbg_get_param_type(param TSRMLS_CC));
+
+ phpdbg_default_switch_case();
}
-
+
return SUCCESS;
} /* }}} */
PHPDBG_LIST(class) /* {{{ */
{
- if (param->type == STR_PARAM) {
- zend_class_entry **ce;
-
- if (zend_lookup_class(param->str, param->len, &ce TSRMLS_CC) == SUCCESS) {
- if ((*ce)->type == ZEND_USER_CLASS) {
- if ((*ce)->info.user.filename) {
- phpdbg_list_file(
- (*ce)->info.user.filename,
- (*ce)->info.user.line_end - (*ce)->info.user.line_start + 1,
- (*ce)->info.user.line_start TSRMLS_CC
- );
+ switch (param->type) {
+ case STR_PARAM: {
+ zend_class_entry **ce;
-
++
+ if (zend_lookup_class(param->str, param->len, &ce TSRMLS_CC) == SUCCESS) {
+ if ((*ce)->type == ZEND_USER_CLASS) {
+ if ((*ce)->info.user.filename) {
+ phpdbg_list_file(
+ (*ce)->info.user.filename,
+ (*ce)->info.user.line_end - (*ce)->info.user.line_start + 1,
+ (*ce)->info.user.line_start, 0 TSRMLS_CC
+ );
+ } else {
+ phpdbg_error("The source of the requested class (%s) cannot be found", (*ce)->name);
+ }
} else {
- phpdbg_error("The source of the requested class (%s) cannot be found", (*ce)->name);
+ phpdbg_error("The class requested (%s) is not user defined", (*ce)->name);
}
} else {
- phpdbg_error("The class requested (%s) is not user defined", (*ce)->name);
+ phpdbg_error("The requested class (%s) could not be found", param->str);
}
- } else {
- phpdbg_error("The requested class (%s) could not be found", param->str);
- }
- } else {
- phpdbg_error(
- "Unsupported parameter type (%s) for function", phpdbg_get_param_type(param TSRMLS_CC));
+ } break;
-
++
+ phpdbg_default_switch_case();
}
-
+
return SUCCESS;
} /* }}} */
phpdbg_error("Failed to stat file %s", filename);
return;
}
-
++
#ifndef _WIN32
- if ((fd = VCWD_OPEN(filename, O_RDONLY)) == -1) {
+ if ((fd = VCWD_OPEN(filename, O_RDONLY)) == FAILURE) {
phpdbg_error("Failed to open file %s to list", filename);
return;
}
ops = (zend_op_array*)fbc;
phpdbg_list_file(ops->filename,
- ops->line_end - ops->line_start + 1, ops->line_start TSRMLS_CC);
+ ops->line_end - ops->line_start + 1, ops->line_start, 0 TSRMLS_CC);
} /* }}} */
-
+ void phpdbg_list_function_byname(const char *str, size_t len TSRMLS_DC)
+ {
+ HashTable *func_table = EG(function_table);
+ zend_function* fbc;
+ char *func_name = (char*) str;
+ size_t func_name_len = len;
-
++
+ /* search active scope if begins with period */
+ if (func_name[0] == '.') {
+ if (EG(scope)) {
+ func_name++;
+ func_name_len--;
+
+ func_table = &EG(scope)->function_table;
+ } else {
+ phpdbg_error("No active class");
+ return;
+ }
+ } else if (!EG(function_table)) {
+ phpdbg_error("No function table loaded");
+ return;
+ } else {
+ func_table = EG(function_table);
+ }
-
++
+ /* use lowercase names, case insensitive */
+ func_name = zend_str_tolower_dup(func_name, func_name_len);
-
++
+ if (zend_hash_find(func_table, func_name, func_name_len+1,
+ (void**)&fbc) == SUCCESS) {
+ phpdbg_list_function(fbc TSRMLS_CC);
+ } else {
+ phpdbg_error("Function %s not found", func_name);
+ }
++
+ efree(func_name);
+ }
+
zend_bool in_code = 0;
while (fgets(cmd, PHPDBG_MAX_CMD, fp) != NULL) {
-
+ phpdbg_command_t *selected = NULL;
++
cmd_len = strlen(cmd)-1;
while (*cmd && isspace(cmd[cmd_len-1]))
static PHPDBG_COMMAND(exec) /* {{{ */
{
- if (param->type == EMPTY_PARAM) {
- phpdbg_error("No expression provided");
- return SUCCESS;
- } else {
- if (param->type == STR_PARAM) {
- if (PHPDBG_G(exec)) {
- phpdbg_notice("Unsetting old execution context: %s", PHPDBG_G(exec));
- efree(PHPDBG_G(exec));
- PHPDBG_G(exec) = NULL;
- }
-
- if (PHPDBG_G(ops)) {
- phpdbg_notice("Destroying compiled opcodes");
- phpdbg_clean(0 TSRMLS_CC);
- }
+ switch (param->type) {
+ case STR_PARAM: {
+ struct stat sb;
- PHPDBG_G(exec) = phpdbg_resolve_path(param->str TSRMLS_CC);
+ if (VCWD_STAT(param->str, &sb) != FAILURE) {
+ if (sb.st_mode & S_IFREG|S_IFLNK) {
+ if (PHPDBG_G(exec)) {
+ phpdbg_notice("Unsetting old execution context: %s", PHPDBG_G(exec));
+ efree(PHPDBG_G(exec));
+ PHPDBG_G(exec) = NULL;
+ }
- if (!PHPDBG_G(exec)) {
- phpdbg_error("Cannot get real file path");
- return FAILURE;
- }
+ if (PHPDBG_G(ops)) {
+ phpdbg_notice("Destroying compiled opcodes");
+ phpdbg_clean(0 TSRMLS_CC);
+ }
- PHPDBG_G(exec_len) = strlen(PHPDBG_G(exec));
+ PHPDBG_G(exec) = phpdbg_resolve_path(param->str TSRMLS_CC);
+
+ if (!PHPDBG_G(exec)) {
+ phpdbg_error("Cannot get real file path");
+ return SUCCESS;
+ }
+
+ PHPDBG_G(exec_len) = strlen(PHPDBG_G(exec));
+
+ phpdbg_notice("Set execution context: %s", PHPDBG_G(exec));
-
++
+ } else {
+ phpdbg_error("Cannot use %s as execution context, not a valid file or symlink", param->str);
+ }
+ } else {
+ phpdbg_error("Cannot stat %s, ensure the file exists", param->str);
+ }
+ } break;
-
++
+ phpdbg_default_switch_case();
+ }
- phpdbg_notice("Set execution context: %s", PHPDBG_G(exec));
- } else {
- phpdbg_error("Unsupported parameter type (%s) for command", phpdbg_get_param_type(param TSRMLS_CC));
- }
- }
-
-
return SUCCESS;
} /* }}} */
{
if (!PHPDBG_G(exec)) {
phpdbg_error("No execution context");
- return FAILURE;
+ return SUCCESS;
}
-
++
if (!EG(in_execution)) {
if (PHPDBG_G(ops)) {
phpdbg_error("Destroying previously compiled opcodes");
}
}
- return phpdbg_compile(TSRMLS_C);
+ phpdbg_compile(TSRMLS_C);
-
++
+ return SUCCESS;
} /* }}} */
static PHPDBG_COMMAND(step) /* {{{ */
{
- if (param->type == EMPTY_PARAM || param->type == NUMERIC_PARAM) {
- if (param->type == NUMERIC_PARAM && param->num) {
- PHPDBG_G(flags) |= PHPDBG_IS_STEPPING;
- } else {
- PHPDBG_G(flags) &= ~PHPDBG_IS_STEPPING;
- }
-
- phpdbg_notice("Stepping %s",
- (PHPDBG_G(flags) & PHPDBG_IS_STEPPING) ? "on" : "off");
- } else {
- phpdbg_error("Unsupported parameter type (%s) for command", phpdbg_get_param_type(param TSRMLS_CC));
- }
+ switch (param->type) {
+ case EMPTY_PARAM:
+ case NUMERIC_PARAM: {
+ if (param->type == NUMERIC_PARAM && param->num) {
+ PHPDBG_G(flags) |= PHPDBG_IS_STEPPING;
+ } else {
+ PHPDBG_G(flags) &= ~PHPDBG_IS_STEPPING;
+ }
+
+ phpdbg_notice("Stepping %s",
+ (PHPDBG_G(flags) & PHPDBG_IS_STEPPING) ? "on" : "off");
+ } break;
-
++
+ phpdbg_default_switch_case();
+ }
return SUCCESS;
} /* }}} */
EG(opline_ptr) = orig_opline;
EG(return_value_ptr_ptr) = orig_retval_ptr;
- return SUCCESS;
} else {
phpdbg_error("Nothing to execute!");
- return FAILURE;
}
-
++
+ out:
+ return SUCCESS;
} /* }}} */
static PHPDBG_COMMAND(eval) /* {{{ */
{
- if (param->type == EMPTY_PARAM) {
- phpdbg_error("No expression provided!");
- return FAILURE;
- } else {
- if (param->type == STR_PARAM) {
- zend_bool stepping = (PHPDBG_G(flags) & PHPDBG_IS_STEPPING);
- zval retval;
-
- PHPDBG_G(flags) &= ~ PHPDBG_IS_STEPPING;
-
- /* 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 (param->type) {
+ case STR_PARAM: {
+ zend_bool stepping = (PHPDBG_G(flags) & PHPDBG_IS_STEPPING);
+ zval retval;
+
+ PHPDBG_G(flags) &= ~ PHPDBG_IS_STEPPING;
+
+ /* 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_STEPPING;
+ }
+ } break;
-
++
+ phpdbg_default_switch_case();
+ }
- /* switch stepping back on */
- if (stepping) {
- PHPDBG_G(flags) |= PHPDBG_IS_STEPPING;
- }
- } else {
- phpdbg_error(
- "Unsupported parameter type (%s) for command", phpdbg_get_param_type(param TSRMLS_CC));
- return FAILURE;
- }
- }
-
return SUCCESS;
} /* }}} */
zval zbacktrace;
zval **tmp;
HashPosition position;
-- int i = 0,
++ int i = 0,
limit = (param->type == NUMERIC_PARAM) ? param->num : 0;
--
++
zend_fetch_debug_backtrace(
&zbacktrace, 0, 0, limit TSRMLS_CC);
phpdbg_writeln(EMPTY);
zval_dtor(&zbacktrace);
-
- return SUCCESS;
} break;
-
- default: {
- phpdbg_error(
- "Unsupported parameter type (%s) for command", phpdbg_get_param_type(param TSRMLS_CC));
- return FAILURE;
- }
+
+ phpdbg_default_switch_case();
}
-
++
+ return SUCCESS;
} /* }}} */
static PHPDBG_COMMAND(print) /* {{{ */
{
- if (param->type == EMPTY_PARAM) {
- phpdbg_writeln(SEPARATE);
- phpdbg_notice("Execution Context Information");
+ switch (param->type) {
+ case EMPTY_PARAM: {
+ phpdbg_writeln(SEPARATE);
+ phpdbg_notice("Execution Context Information");
#ifdef HAVE_LIBREADLINE
- phpdbg_writeln("Readline\tyes");
+ phpdbg_writeln("Readline\tyes");
#else
- phpdbg_writeln("Readline\tno");
+ phpdbg_writeln("Readline\tno");
#endif
- phpdbg_writeln("Exec\t\t%s", PHPDBG_G(exec) ? PHPDBG_G(exec) : "none");
- phpdbg_writeln("Compiled\t%s", PHPDBG_G(ops) ? "yes" : "no");
- phpdbg_writeln("Stepping\t%s", (PHPDBG_G(flags) & PHPDBG_IS_STEPPING) ? "on" : "off");
- phpdbg_writeln("Quietness\t%s", (PHPDBG_G(flags) & PHPDBG_IS_QUIET) ? "on" : "off");
- phpdbg_writeln("Oplog\t\t%s", PHPDBG_G(oplog) ? "on" : "off");
+ phpdbg_writeln("Exec\t\t%s", PHPDBG_G(exec) ? PHPDBG_G(exec) : "none");
+ phpdbg_writeln("Compiled\t%s", PHPDBG_G(ops) ? "yes" : "no");
+ phpdbg_writeln("Stepping\t%s", (PHPDBG_G(flags) & PHPDBG_IS_STEPPING) ? "on" : "off");
+ phpdbg_writeln("Quietness\t%s", (PHPDBG_G(flags) & PHPDBG_IS_QUIET) ? "on" : "off");
+ phpdbg_writeln("Oplog\t\t%s", PHPDBG_G(oplog) ? "on" : "off");
- if (PHPDBG_G(ops)) {
- phpdbg_writeln("Opcodes\t\t%d", PHPDBG_G(ops)->last);
+ if (PHPDBG_G(ops)) {
+ phpdbg_writeln("Opcodes\t\t%d", PHPDBG_G(ops)->last);
- if (PHPDBG_G(ops)->last_var) {
- phpdbg_writeln("Variables\t%d", PHPDBG_G(ops)->last_var-1);
- } else {
- phpdbg_writeln("Variables\tNone");
- }
- }
+ if (PHPDBG_G(ops)->last_var) {
+ phpdbg_writeln("Variables\t%d", PHPDBG_G(ops)->last_var-1);
+ } else {
+ phpdbg_writeln("Variables\tNone");
+ }
+ }
- phpdbg_writeln("Executing\t%s", EG(in_execution) ? "yes" : "no");
- if (EG(in_execution)) {
- phpdbg_writeln("VM Return\t%d", PHPDBG_G(vmret));
- }
- phpdbg_writeln("Classes\t\t%d", zend_hash_num_elements(EG(class_table)));
- phpdbg_writeln("Functions\t%d", zend_hash_num_elements(EG(function_table)));
- phpdbg_writeln("Constants\t%d", zend_hash_num_elements(EG(zend_constants)));
- phpdbg_writeln("Included\t%d", zend_hash_num_elements(&EG(included_files)));
-
- phpdbg_print_breakpoints(PHPDBG_BREAK_FILE TSRMLS_CC);
- phpdbg_print_breakpoints(PHPDBG_BREAK_SYM TSRMLS_CC);
- phpdbg_print_breakpoints(PHPDBG_BREAK_METHOD TSRMLS_CC);
- phpdbg_print_breakpoints(PHPDBG_BREAK_OPLINE TSRMLS_CC);
- phpdbg_print_breakpoints(PHPDBG_BREAK_COND TSRMLS_CC);
-
- phpdbg_writeln(SEPARATE);
- } else {
- phpdbg_error("You must use a specific printer");
+ phpdbg_writeln("Executing\t%s", EG(in_execution) ? "yes" : "no");
+ if (EG(in_execution)) {
+ phpdbg_writeln("VM Return\t%d", PHPDBG_G(vmret));
+ }
+ phpdbg_writeln("Classes\t\t%d", zend_hash_num_elements(EG(class_table)));
+ phpdbg_writeln("Functions\t%d", zend_hash_num_elements(EG(function_table)));
+ phpdbg_writeln("Constants\t%d", zend_hash_num_elements(EG(zend_constants)));
+ phpdbg_writeln("Included\t%d", zend_hash_num_elements(&EG(included_files)));
+
+ phpdbg_print_breakpoints(PHPDBG_BREAK_FILE TSRMLS_CC);
+ phpdbg_print_breakpoints(PHPDBG_BREAK_SYM TSRMLS_CC);
+ phpdbg_print_breakpoints(PHPDBG_BREAK_METHOD TSRMLS_CC);
+ phpdbg_print_breakpoints(PHPDBG_BREAK_OPLINE TSRMLS_CC);
+ phpdbg_print_breakpoints(PHPDBG_BREAK_COND TSRMLS_CC);
-
++
+ phpdbg_writeln(SEPARATE);
+ } break;
-
++
+ phpdbg_default_switch_case();
}
-
+
return SUCCESS;
} /* }}} */
case STR_PARAM:
phpdbg_set_breakpoint_symbol(param->str TSRMLS_CC);
break;
--
- default:
- phpdbg_error(
- "Unsupported parameter type (%s) for command", phpdbg_get_param_type(param TSRMLS_CC));
- return FAILURE;
++
+ phpdbg_default_switch_case();
}
return SUCCESS;
prompt_command->name, prompt_command->tip);
}
}
--
++
++prompt_command;
}
phpdbg_help_footer();
--
++
return SUCCESS;
} /* }}} */
static PHPDBG_COMMAND(oplog) /* {{{ */
{
- if (param->type == EMPTY_PARAM ||
- ((param->type == NUMERIC_PARAM) && !param->num)) {
- if (PHPDBG_G(oplog)) {
- phpdbg_notice("Disabling oplog");
- fclose(
- PHPDBG_G(oplog));
- return SUCCESS;
- } else {
- phpdbg_error("No oplog currently open");
- return FAILURE;
- }
- } else {
- if (param->type == STR_PARAM) {
- /* open oplog */
+ switch (param->type) {
+ case EMPTY_PARAM:
+ case NUMERIC_PARAM:
+ if ((param->type != NUMERIC_PARAM) || !param->num) {
+ if (PHPDBG_G(oplog)) {
+ phpdbg_notice("Disabling oplog");
+ fclose(
+ PHPDBG_G(oplog));
+ } else {
+ phpdbg_error("No oplog currently open");
+ }
+ }
+ break;
-
++
+ case STR_PARAM: {
+ /* open oplog */
FILE *old = PHPDBG_G(oplog);
PHPDBG_G(oplog) = fopen(param->str, "w+");
fclose(old);
}
phpdbg_notice("Successfully opened oplog %s", param->str);
-
- return SUCCESS;
}
- } else {
- phpdbg_error(
- "Unsupported parameter type (%s) for command", phpdbg_get_param_type(param TSRMLS_CC));
- return FAILURE;
- }
+ } break;
-
++
+ phpdbg_default_switch_case();
}
-
++
+ return SUCCESS;
} /* }}} */
static PHPDBG_COMMAND(help) /* {{{ */
{
- if (param->type == EMPTY_PARAM) {
- const phpdbg_command_t *prompt_command = phpdbg_prompt_commands;
- const phpdbg_command_t *help_command = phpdbg_help_commands;
-
- phpdbg_help_header();
- phpdbg_writeln("To get help regarding a specific command type \"help command\"");
-
- phpdbg_notice("Commands");
-
- while (prompt_command && prompt_command->name) {
- phpdbg_writeln(
- "\t%s\t%s", prompt_command->name, prompt_command->tip);
- ++prompt_command;
- }
+ switch (param->type) {
+ case EMPTY_PARAM: {
+ const phpdbg_command_t *prompt_command = phpdbg_prompt_commands;
+ const phpdbg_command_t *help_command = phpdbg_help_commands;
-
+
- phpdbg_notice("Helpers Loaded");
+ phpdbg_help_header();
+ phpdbg_writeln("To get help regarding a specific command type \"help command\"");
- while (help_command && help_command->name) {
- phpdbg_writeln("\t%s\t%s", help_command->name, help_command->tip);
- ++help_command;
- }
+ phpdbg_notice("Commands");
- phpdbg_notice("Command Line Options and Flags");
- phpdbg_writeln("\tOption\tExample\t\t\tPurpose");
- phpdbg_writeln(EMPTY);
- phpdbg_writeln("\t-c\t-c/my/php.ini\t\tSet php.ini file to load");
- phpdbg_writeln("\t-d\t-dmemory_limit=4G\tSet a php.ini directive");
- phpdbg_writeln("\t-n\t-N/A\t\t\tDisable default php.ini");
- phpdbg_writeln("\t-e\t-emytest.php\t\tSet execution context");
- phpdbg_writeln("\t-v\tN/A\t\t\tEnable opline output while executing");
- phpdbg_writeln("\t-s\tN/A\t\t\tEnable stepping");
- phpdbg_writeln("\t-b\tN/A\t\t\tDisable the use of colours");
- phpdbg_writeln("\t-i\t-imy.init\t\tSet the phpdbginit file");
- phpdbg_writeln("\t-I\tN/A\t\t\tDisable loading .phpdbginit");
- phpdbg_writeln("\t-O\t-Omy.oplog\t\tSets oplog output file");
- phpdbg_help_footer();
- } else {
- phpdbg_error(
- "Unsupported parameter type (%s) for command", phpdbg_get_param_type(param TSRMLS_CC));
- return FAILURE;
- }
+ while (prompt_command && prompt_command->name) {
+ phpdbg_writeln(
+ "\t%s\t%s", prompt_command->name, prompt_command->tip);
+ ++prompt_command;
+ }
+
+ phpdbg_notice("Helpers Loaded");
+
+ while (help_command && help_command->name) {
+ phpdbg_writeln("\t%s\t%s", help_command->name, help_command->tip);
+ ++help_command;
+ }
+
+ phpdbg_notice("Command Line Options and Flags");
+ phpdbg_writeln("\tOption\tExample\t\t\tPurpose");
+ phpdbg_writeln(EMPTY);
+ phpdbg_writeln("\t-c\t-c/my/php.ini\t\tSet php.ini file to load");
+ phpdbg_writeln("\t-d\t-dmemory_limit=4G\tSet a php.ini directive");
+ phpdbg_writeln("\t-n\t-N/A\t\t\tDisable default php.ini");
+ phpdbg_writeln("\t-e\t-emytest.php\t\tSet execution context");
+ phpdbg_writeln("\t-v\tN/A\t\t\tEnable opline output while executing");
+ phpdbg_writeln("\t-s\tN/A\t\t\tEnable stepping");
+ phpdbg_writeln("\t-b\tN/A\t\t\tDisable the use of colours");
+ phpdbg_writeln("\t-i\t-imy.init\t\tSet the phpdbginit file");
+ phpdbg_writeln("\t-I\tN/A\t\t\tDisable loading .phpdbginit");
+ phpdbg_writeln("\t-O\t-Omy.oplog\t\tSets oplog output file");
+ phpdbg_help_footer();
+ } break;
-
++
+ phpdbg_default_switch_case();
+ }
return SUCCESS;
} /* }}} */
- static PHPDBG_COMMAND(quiet) { /* {{{ */
- if (param->type == NUMERIC_PARAM) {
- if (param->num) {
- PHPDBG_G(flags) |= PHPDBG_IS_QUIET;
- } else {
- PHPDBG_G(flags) &= ~PHPDBG_IS_QUIET;
- }
- phpdbg_notice("Quietness %s",
- (PHPDBG_G(flags) & PHPDBG_IS_QUIET) ? "enabled" : "disabled");
- } else {
- phpdbg_error(
- "Unsupported parameter type (%s) for command", phpdbg_get_param_type(param TSRMLS_CC));
- return FAILURE;
+ static PHPDBG_COMMAND(quiet) /* {{{ */
+ {
+ switch (param->type) {
+ case NUMERIC_PARAM: {
+ if (param->num) {
+ PHPDBG_G(flags) |= PHPDBG_IS_QUIET;
+ } else {
+ PHPDBG_G(flags) &= ~PHPDBG_IS_QUIET;
+ }
+ phpdbg_notice("Quietness %s",
+ (PHPDBG_G(flags) & PHPDBG_IS_QUIET) ? "enabled" : "disabled");
+ } break;
-
++
+ phpdbg_default_switch_case();
}
--
++
return SUCCESS;
} /* }}} */
static PHPDBG_COMMAND(list) /* {{{ */
{
- phpdbg_list_dispatch(param TSRMLS_CC);
+ switch (param->type) {
+ case NUMERIC_PARAM:
- case EMPTY_PARAM: {
- if (PHPDBG_G(exec) || zend_is_executing(TSRMLS_C)) {
- if (param->type == EMPTY_PARAM) {
- phpdbg_list_file(phpdbg_current_file(TSRMLS_C), 0, 0, 0 TSRMLS_CC);
- } else phpdbg_list_file(phpdbg_current_file(TSRMLS_C), param->num, 0, 0 TSRMLS_CC);
- } else phpdbg_error("Not executing, and execution context not set");
- } break;
-
++ case EMPTY_PARAM:
++ return PHPDBG_LIST_HANDLER(lines)(param TSRMLS_CC);
++
+ case FILE_PARAM:
- phpdbg_list_file(param->file.name, param->file.line, 0, 0 TSRMLS_CC);
- break;
-
- case STR_PARAM: {
++ return PHPDBG_LIST_HANDLER(lines)(param TSRMLS_CC);
++
++ case STR_PARAM:
+ phpdbg_list_function_byname(param->str, param->len TSRMLS_CC);
- } break;
-
++ break;
++
+ case METHOD_PARAM:
- phpdbg_do_list_method(param TSRMLS_CC);
- break;
-
++ return PHPDBG_LIST_HANDLER(method)(param TSRMLS_CC);
++ break;
++
+ phpdbg_default_switch_case();
+ }
return SUCCESS;
} /* }}} */
- int phpdbg_do_cmd(const phpdbg_command_t *command, char *cmd_line, size_t cmd_len TSRMLS_DC) /* {{{ */
-int phpdbg_do_cmd( const phpdbg_command_t *command,
- phpdbg_command_t **selected,
++int phpdbg_do_cmd( const phpdbg_command_t *command,
++ phpdbg_command_t **selected,
+ char *cmd_line, size_t cmd_len TSRMLS_DC) /* {{{ */
{
int rc = FAILURE;
--
++
char *expr = NULL;
#ifndef _WIN32
const char *cmd = strtok_r(cmd_line, " ", &expr);
#endif
size_t expr_len = (cmd != NULL) ? strlen(cmd) : 0;
-
+ phpdbg_param_t *param = NULL;
++
while (command && command->name && command->handler) {
if ((command->name_len == expr_len
&& memcmp(cmd, command->name, expr_len) == 0)
if (PHPDBG_G(lparam)) {
//phpdbg_clear_param(
// PHPDBG_G(lparam) TSRMLS_CC);
-- //efree(PHPDBG_G(lparam));
++ //efree(PHPDBG_G(lparam));
}
--
++
phpdbg_parse_param(
expr,
-- (cmd_len - expr_len) ? (((cmd_len - expr_len) - sizeof(" "))+1) : 0,
++ (cmd_len - expr_len) ? (((cmd_len - expr_len) - sizeof(" "))+1) : 0,
param TSRMLS_CC);
PHPDBG_G(lparam) = param;
}
}
- phpdbg_debug("phpdbg_do_cmd(%s, \"%s\")",
- command->name, phpdbg_get_param_type(param TSRMLS_CC));
+ *selected = (phpdbg_command_t*) command;
-
+
rc = command->handler(param TSRMLS_CC);
- break;
- }
- ++command;
- }
-
- break;
++
++ break;
+ }
+ ++command;
+ }
-
++
+ done:
+ if (selected && param) {
+ phpdbg_debug(
+ "phpdbg_do_cmd(%s, \"%s\"): %d",
+ command->name, phpdbg_get_param_type(param TSRMLS_CC), (rc==SUCCESS));
+ }
return rc;
} /* }}} */
cmd[cmd_len] = '\0';
if (*cmd && cmd_len > 0L) {
-
+ /* keep a cursor to selected command */
+ phpdbg_command_t *selected = NULL;
++
#ifdef HAVE_LIBREADLINE
add_history(cmd);
#endif
-
+
- switch (ret = phpdbg_do_cmd(phpdbg_prompt_commands, cmd, cmd_len TSRMLS_CC)) {
+ switch (ret = phpdbg_do_cmd(phpdbg_prompt_commands, &selected, cmd, cmd_len TSRMLS_CC)) {
case FAILURE:
if (!(PHPDBG_G(flags) & PHPDBG_IS_QUITTING)) {
phpdbg_error("Failed to execute %s!", cmd);