From: Felipe Pena Date: Sun, 17 Nov 2013 11:28:14 +0000 (-0200) Subject: - Fix conflict X-Git-Tag: php-5.6.0alpha1~110^2~279 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=dd25fb44fd4b76d59b223cb385fa452b004ac665;p=php - Fix conflict --- dd25fb44fd4b76d59b223cb385fa452b004ac665 diff --cc phpdbg_list.c index 981367b197,ba1e31e43e..1b7938cab0 --- a/phpdbg_list.c +++ b/phpdbg_list.c @@@ -31,138 -31,97 +31,103 @@@ 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; } /* }}} */ @@@ -206,8 -141,9 +147,9 @@@ void phpdbg_list_file(const char *filen 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; } @@@ -284,6 -226,44 +232,44 @@@ void phpdbg_list_function(const zend_fu 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); + } + diff --cc phpdbg_prompt.c index 91cc881d60,d68933be3a..b78efb426a --- a/phpdbg_prompt.c +++ b/phpdbg_prompt.c @@@ -101,6 -101,8 +101,8 @@@ void phpdbg_init(char *init_file, size_ 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])) @@@ -188,38 -190,45 +190,45 @@@ void phpdbg_welcome(zend_bool cleaning 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; } /* }}} */ @@@ -253,8 -262,9 +262,9 @@@ static PHPDBG_COMMAND(compile) /* {{{ * { 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"); @@@ -262,23 -272,28 +272,28 @@@ } } - 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; } /* }}} */ @@@ -336,47 -352,43 +352,43 @@@ static PHPDBG_COMMAND(run) /* {{{ * 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; } /* }}} */ @@@ -393,9 -405,9 +405,9 @@@ static PHPDBG_COMMAND(back) /* {{{ * 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); @@@ -410,65 -422,63 +422,63 @@@ 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; } /* }}} */ @@@ -490,11 -500,8 +500,8 @@@ static PHPDBG_COMMAND(break) /* {{{ * 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; @@@ -571,30 -578,32 +578,32 @@@ static PHPDBG_COMMAND(aliases) /* {{{ * 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+"); @@@ -608,93 -616,117 +616,111 @@@ 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); @@@ -703,6 -735,8 +729,8 @@@ #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) @@@ -716,12 -750,12 +744,12 @@@ 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; @@@ -733,14 -770,21 +764,21 @@@ } } - 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; } /* }}} */ @@@ -773,11 -817,14 +811,14 @@@ int phpdbg_interactive(TSRMLS_D) /* {{ 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);