From 593e7b28e89a4c7ff34e2c0a3c05db43929f1db0 Mon Sep 17 00:00:00 2001 From: krakjoe Date: Sat, 16 Nov 2013 21:23:14 +0000 Subject: [PATCH 01/11] stat execution context and check it is a regular file or symlink --- phpdbg_prompt.c | 50 +++++++++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/phpdbg_prompt.c b/phpdbg_prompt.c index 91cc881d60e..e5276979e8b 100644 --- a/phpdbg_prompt.c +++ b/phpdbg_prompt.c @@ -193,33 +193,43 @@ static PHPDBG_COMMAND(exec) /* {{{ */ 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; - } + struct stat sb; + + 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(ops)) { - phpdbg_notice("Destroying compiled opcodes"); - phpdbg_clean(0 TSRMLS_CC); + if (PHPDBG_G(ops)) { + phpdbg_notice("Destroying compiled opcodes"); + phpdbg_clean(0 TSRMLS_CC); + } + + PHPDBG_G(exec) = phpdbg_resolve_path(param->str TSRMLS_CC); + + if (!PHPDBG_G(exec)) { + phpdbg_error("Cannot get real file path"); + return FAILURE; + } + + 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); } - - PHPDBG_G(exec) = phpdbg_resolve_path(param->str TSRMLS_CC); - - if (!PHPDBG_G(exec)) { - phpdbg_error("Cannot get real file path"); - return FAILURE; - } - - PHPDBG_G(exec_len) = strlen(PHPDBG_G(exec)); - - 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; } /* }}} */ From f0ed1810810174c6cc8b528cdf911efbc4e8bfa5 Mon Sep 17 00:00:00 2001 From: krakjoe Date: Sat, 16 Nov 2013 21:25:22 +0000 Subject: [PATCH 02/11] get rid of No Expression Provided messages, not required anymore --- phpdbg_prompt.c | 120 ++++++++++++++++++++++-------------------------- 1 file changed, 55 insertions(+), 65 deletions(-) diff --git a/phpdbg_prompt.c b/phpdbg_prompt.c index e5276979e8b..1361cc70f4e 100644 --- a/phpdbg_prompt.c +++ b/phpdbg_prompt.c @@ -188,47 +188,42 @@ void phpdbg_welcome(zend_bool cleaning TSRMLS_DC) /* {{{ */ static PHPDBG_COMMAND(exec) /* {{{ */ { - if (param->type == EMPTY_PARAM) { - phpdbg_error("No expression provided"); - return SUCCESS; - } else { - if (param->type == STR_PARAM) { - struct stat sb; - - 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(ops)) { - phpdbg_notice("Destroying compiled opcodes"); - phpdbg_clean(0 TSRMLS_CC); - } + if (param->type == STR_PARAM) { + struct stat sb; + + 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; + } - PHPDBG_G(exec) = phpdbg_resolve_path(param->str TSRMLS_CC); + if (PHPDBG_G(ops)) { + phpdbg_notice("Destroying compiled opcodes"); + phpdbg_clean(0 TSRMLS_CC); + } - if (!PHPDBG_G(exec)) { - phpdbg_error("Cannot get real file path"); - return FAILURE; - } + PHPDBG_G(exec) = phpdbg_resolve_path(param->str TSRMLS_CC); - PHPDBG_G(exec_len) = strlen(PHPDBG_G(exec)); + if (!PHPDBG_G(exec)) { + phpdbg_error("Cannot get real file path"); + return FAILURE; + } - 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); - } - } else { - phpdbg_error("Unsupported parameter type (%s) for command", phpdbg_get_param_type(param TSRMLS_CC)); - } - } + 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); + } + } else { + phpdbg_error("Unsupported parameter type (%s) for command", phpdbg_get_param_type(param TSRMLS_CC)); + } return SUCCESS; } /* }}} */ @@ -355,37 +350,32 @@ static PHPDBG_COMMAND(run) /* {{{ */ 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; + if (param->type == STR_PARAM) { + zend_bool stepping = (PHPDBG_G(flags) & PHPDBG_IS_STEPPING); + zval retval; - PHPDBG_G(flags) &= ~ PHPDBG_IS_STEPPING; + 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; + /* 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; - } - } else { - phpdbg_error( - "Unsupported parameter type (%s) for command", phpdbg_get_param_type(param TSRMLS_CC)); - return FAILURE; - } - } + /* 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; } /* }}} */ From 102e3477d75a83e88aba64f1c22963b7938d427b Mon Sep 17 00:00:00 2001 From: krakjoe Date: Sat, 16 Nov 2013 21:28:59 +0000 Subject: [PATCH 03/11] remove more no expression provided messages --- phpdbg_break.c | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/phpdbg_break.c b/phpdbg_break.c index 03d87f6e199..a866eb063ae 100644 --- a/phpdbg_break.c +++ b/phpdbg_break.c @@ -29,12 +29,10 @@ ZEND_EXTERN_MODULE_GLOBALS(phpdbg); PHPDBG_BREAK(file) /* {{{ */ { switch (param->type) { - case EMPTY_PARAM: - phpdbg_error("No expression provided"); - break; case FILE_PARAM: phpdbg_set_breakpoint_file(param->file.name, param->file.line TSRMLS_CC); break; + default: phpdbg_error("Unsupported parameter type (%s) for function", phpdbg_get_param_type(param TSRMLS_CC)); break; @@ -46,9 +44,6 @@ PHPDBG_BREAK(file) /* {{{ */ PHPDBG_BREAK(method) /* {{{ */ { switch (param->type) { - case EMPTY_PARAM: - phpdbg_error("No expression provided"); - break; case METHOD_PARAM: phpdbg_set_breakpoint_method(param->method.class, param->method.name TSRMLS_CC); break; @@ -64,12 +59,10 @@ PHPDBG_BREAK(method) /* {{{ */ PHPDBG_BREAK(address) /* {{{ */ { switch (param->type) { - case EMPTY_PARAM: - phpdbg_error("No expression provided"); - break; case ADDR_PARAM: phpdbg_set_breakpoint_opline(param->addr TSRMLS_CC); break; + default: phpdbg_error( "Unsupported parameter type (%s) for function", phpdbg_get_param_type(param TSRMLS_CC)); @@ -99,12 +92,10 @@ PHPDBG_BREAK(lineno) /* {{{ */ } switch (param->type) { - case EMPTY_PARAM: - phpdbg_error("No expression provided!"); - break; case NUMERIC_PARAM: phpdbg_set_breakpoint_file(phpdbg_current_file(TSRMLS_C), param->num TSRMLS_CC); break; + default: phpdbg_error( "Unsupported parameter type (%s) for function", phpdbg_get_param_type(param TSRMLS_CC)); @@ -117,12 +108,10 @@ PHPDBG_BREAK(lineno) /* {{{ */ PHPDBG_BREAK(func) /* {{{ */ { switch (param->type) { - case EMPTY_PARAM: - phpdbg_error("No expression provided!"); - break; case STR_PARAM: phpdbg_set_breakpoint_symbol(param->str TSRMLS_CC); break; + default: phpdbg_error("Unsupported parameter type (%s) for function", phpdbg_get_param_type(param TSRMLS_CC)); break; From b424771ce87930891f63613877728c43ebab7c9d Mon Sep 17 00:00:00 2001 From: krakjoe Date: Sat, 16 Nov 2013 22:40:01 +0000 Subject: [PATCH 04/11] stat before setting breakpoints on files default switch case for command handlers trace route through handler tree for debugging etc **selected --- phpdbg_bp.c | 48 +++++++++++++++++++++++--------------- phpdbg_break.c | 61 ++++++++++++++++++++----------------------------- phpdbg_list.c | 5 ++-- phpdbg_print.c | 2 -- phpdbg_prompt.c | 47 +++++++++++++++++++++++++------------ phpdbg_prompt.h | 9 +++++++- 6 files changed, 98 insertions(+), 74 deletions(-) diff --git a/phpdbg_bp.c b/phpdbg_bp.c index a1ce1816748..76d8b01764a 100644 --- a/phpdbg_bp.c +++ b/phpdbg_bp.c @@ -45,32 +45,42 @@ static void phpdbg_class_breaks_dtor(void *data) /* {{{ */ void phpdbg_set_breakpoint_file(const char *path, long line_num TSRMLS_DC) /* {{{ */ { - phpdbg_breakfile_t new_break; - zend_llist *break_files_ptr; - size_t path_len = strlen(path); + struct stat sb; - new_break.filename = estrndup(path, path_len); - new_break.line = line_num; + if (VCWD_STAT(path, &sb) != FAILURE) { + if (sb.st_mode & S_IFREG|S_IFLNK) { + phpdbg_breakfile_t new_break; + zend_llist *break_files_ptr; + size_t path_len = strlen(path); - PHPDBG_G(flags) |= PHPDBG_HAS_FILE_BP; + new_break.filename = estrndup(path, path_len); + new_break.line = line_num; - if (zend_hash_find(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE], - new_break.filename, path_len, (void**)&break_files_ptr) == FAILURE) { - zend_llist break_files; + PHPDBG_G(flags) |= PHPDBG_HAS_FILE_BP; - zend_llist_init(&break_files, sizeof(phpdbg_breakfile_t), - phpdbg_llist_breakfile_dtor, 0); + if (zend_hash_find(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE], + new_break.filename, path_len, (void**)&break_files_ptr) == FAILURE) { + zend_llist break_files; - zend_hash_update(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE], - new_break.filename, path_len, &break_files, sizeof(zend_llist), - (void**)&break_files_ptr); - } + zend_llist_init(&break_files, sizeof(phpdbg_breakfile_t), + phpdbg_llist_breakfile_dtor, 0); - new_break.id = PHPDBG_G(bp_count)++; - zend_llist_add_element(break_files_ptr, &new_break); + zend_hash_update(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE], + new_break.filename, path_len, &break_files, sizeof(zend_llist), + (void**)&break_files_ptr); + } - phpdbg_notice("Breakpoint #%d added at %s:%ld", - new_break.id, new_break.filename, new_break.line); + new_break.id = PHPDBG_G(bp_count)++; + zend_llist_add_element(break_files_ptr, &new_break); + + phpdbg_notice("Breakpoint #%d added at %s:%ld", + new_break.id, new_break.filename, new_break.line); + } else { + phpdbg_error("Cannot set breakpoint in %s, it is not a regular file", path); + } + } else { + phpdbg_error("Cannot stat %s, it does not exist", path); + } } /* }}} */ void phpdbg_set_breakpoint_symbol(const char *name TSRMLS_DC) /* {{{ */ diff --git a/phpdbg_break.c b/phpdbg_break.c index a866eb063ae..21500436346 100644 --- a/phpdbg_break.c +++ b/phpdbg_break.c @@ -32,10 +32,8 @@ PHPDBG_BREAK(file) /* {{{ */ case FILE_PARAM: phpdbg_set_breakpoint_file(param->file.name, param->file.line TSRMLS_CC); break; - - default: - phpdbg_error("Unsupported parameter type (%s) for function", phpdbg_get_param_type(param TSRMLS_CC)); - break; + + phpdbg_default_switch_case(); } return SUCCESS; @@ -47,10 +45,8 @@ PHPDBG_BREAK(method) /* {{{ */ case METHOD_PARAM: phpdbg_set_breakpoint_method(param->method.class, param->method.name TSRMLS_CC); break; - - default: - phpdbg_error("Unsupported parameter type (%s) for function", phpdbg_get_param_type(param TSRMLS_CC)); - break; + + phpdbg_default_switch_case(); } return SUCCESS; @@ -63,10 +59,7 @@ PHPDBG_BREAK(address) /* {{{ */ phpdbg_set_breakpoint_opline(param->addr TSRMLS_CC); break; - default: - phpdbg_error( - "Unsupported parameter type (%s) for function", phpdbg_get_param_type(param TSRMLS_CC)); - return FAILURE; + phpdbg_default_switch_case(); } return SUCCESS; @@ -74,32 +67,30 @@ PHPDBG_BREAK(address) /* {{{ */ PHPDBG_BREAK(on) /* {{{ */ { - if (param->type == STR_PARAM) { - phpdbg_set_breakpoint_expression(param->str, param->len TSRMLS_CC); - } else { - phpdbg_error( - "Unsupported parameter type (%s) for command", phpdbg_get_param_type(param TSRMLS_CC)); - return FAILURE; - } + switch (param->type) { + case STR_PARAM: + phpdbg_set_breakpoint_expression(param->str, param->len TSRMLS_CC); + break; + + phpdbg_default_switch_case(); + } + return SUCCESS; } /* }}} */ PHPDBG_BREAK(lineno) /* {{{ */ { - if (!PHPDBG_G(exec)) { - phpdbg_error("Not file context found!"); - return SUCCESS; - } - switch (param->type) { - case NUMERIC_PARAM: - phpdbg_set_breakpoint_file(phpdbg_current_file(TSRMLS_C), param->num TSRMLS_CC); - break; - - default: - phpdbg_error( - "Unsupported parameter type (%s) for function", phpdbg_get_param_type(param TSRMLS_CC)); - return FAILURE; + case NUMERIC_PARAM: { + if (PHPDBG_G(exec)) { + phpdbg_set_breakpoint_file(phpdbg_current_file(TSRMLS_C), param->num TSRMLS_CC); + } else { + phpdbg_error( + "Execution context not set !"); + } + } break; + + phpdbg_default_switch_case(); } return SUCCESS; @@ -111,10 +102,8 @@ PHPDBG_BREAK(func) /* {{{ */ case STR_PARAM: phpdbg_set_breakpoint_symbol(param->str TSRMLS_CC); break; - - default: - phpdbg_error("Unsupported parameter type (%s) for function", phpdbg_get_param_type(param TSRMLS_CC)); - break; + + phpdbg_default_switch_case(); } return SUCCESS; diff --git a/phpdbg_list.c b/phpdbg_list.c index 78ec2fc75a4..04f137dcd5d 100644 --- a/phpdbg_list.c +++ b/phpdbg_list.c @@ -203,12 +203,13 @@ void phpdbg_list_file(const char *filename, long count, long offset TSRMLS_DC) / int all_content = (count == 0); unsigned int line = 0, displayed = 0; - if (VCWD_STAT(filename, &st) == -1) { + if (VCWD_STAT(filename, &st) == FAILURE) { 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; } diff --git a/phpdbg_print.c b/phpdbg_print.c index 92609089998..adfc06cb856 100644 --- a/phpdbg_print.c +++ b/phpdbg_print.c @@ -117,12 +117,10 @@ PHPDBG_PRINT(class) /* {{{ */ } else { phpdbg_error( "Cannot find class %s", param->str); - return FAILURE; } } else { phpdbg_error( "Unsupported parameter type (%s) for command", phpdbg_get_param_type(param TSRMLS_CC)); - return FAILURE; } return SUCCESS; diff --git a/phpdbg_prompt.c b/phpdbg_prompt.c index 1361cc70f4e..91caf4525ee 100644 --- a/phpdbg_prompt.c +++ b/phpdbg_prompt.c @@ -101,6 +101,8 @@ void phpdbg_init(char *init_file, size_t init_file_len, zend_bool use_default TS 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])) @@ -141,7 +143,7 @@ void phpdbg_init(char *init_file, size_t init_file_len, zend_bool use_default TS goto next_line; } - switch (phpdbg_do_cmd(phpdbg_prompt_commands, cmd, cmd_len TSRMLS_CC)) { + switch (phpdbg_do_cmd(phpdbg_prompt_commands, &selected, cmd, cmd_len TSRMLS_CC)) { case FAILURE: phpdbg_error( "Unrecognized command in %s:%d: %s!", init_file, line, cmd); @@ -691,7 +693,9 @@ static PHPDBG_COMMAND(list) /* {{{ */ 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, + char *cmd_line, size_t cmd_len TSRMLS_DC) /* {{{ */ { int rc = FAILURE; @@ -703,12 +707,14 @@ int phpdbg_do_cmd(const phpdbg_command_t *command, char *cmd_line, size_t cmd_le #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) || ((expr_len == 1) && (command->alias && command->alias == cmd_line[0]))) { - phpdbg_param_t *param = emalloc(sizeof(phpdbg_param_t)); + param = emalloc(sizeof(phpdbg_param_t)); PHPDBG_G(last) = (phpdbg_command_t*) command; @@ -727,20 +733,30 @@ int phpdbg_do_cmd(const phpdbg_command_t *command, char *cmd_line, size_t cmd_le PHPDBG_G(lparam) = param; if (command->subs && (param->type == STR_PARAM)) { - if (phpdbg_do_cmd(command->subs, param->str, param->len TSRMLS_CC) == SUCCESS) { + if (phpdbg_do_cmd(command->subs, selected, param->str, param->len TSRMLS_CC) == SUCCESS) { rc = SUCCESS; - break; + /* because we can */ + phpdbg_clear_param(param TSRMLS_CC); + efree(param); + goto done; } } - phpdbg_debug("phpdbg_do_cmd(%s, \"%s\")", - command->name, phpdbg_get_param_type(param TSRMLS_CC)); - + *selected = command; + rc = command->handler(param TSRMLS_CC); - break; - } - ++command; - } + + 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 +789,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); diff --git a/phpdbg_prompt.h b/phpdbg_prompt.h index 3781d833175..8e4a0c144c9 100644 --- a/phpdbg_prompt.h +++ b/phpdbg_prompt.h @@ -33,7 +33,7 @@ /** * Command Executor */ -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, char *cmd_line, size_t cmd_len TSRMLS_DC); /** * Command Declarators @@ -59,4 +59,11 @@ void phpdbg_execute_ex(zend_execute_data *execute_data TSRMLS_DC); void phpdbg_execute_ex(zend_op_array *op_array TSRMLS_DC); #endif +#define phpdbg_default_switch_case() \ + default:\ + phpdbg_error(\ + "Unsupported parameter type (%s) for command", \ + phpdbg_get_param_type(param TSRMLS_CC)); \ + break + #endif /* PHPDBG_PROMPT_H */ From 7bc369399b4bcc60423cde47e5e8e1ad5adf2786 Mon Sep 17 00:00:00 2001 From: krakjoe Date: Sat, 16 Nov 2013 22:58:30 +0000 Subject: [PATCH 05/11] switches in list.c, be consistent in all command handlers --- phpdbg_list.c | 94 +++++++++++------------ phpdbg_prompt.c | 199 ++++++++++++++++++++++++------------------------ 2 files changed, 145 insertions(+), 148 deletions(-) diff --git a/phpdbg_list.c b/phpdbg_list.c index 04f137dcd5d..7074fb21546 100644 --- a/phpdbg_list.c +++ b/phpdbg_list.c @@ -90,12 +90,13 @@ PHPDBG_LIST(lines) /* {{{ */ 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: + i_phpdbg_list_func( + param->str, param->len TSRMLS_CC); + break; + + phpdbg_default_switch_case(); } return SUCCESS; @@ -103,28 +104,29 @@ PHPDBG_LIST(func) /* {{{ */ 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_hash_find(&(*ce)->function_table, lcname, strlen(lcname)+1, (void**) &function) == SUCCESS) { - phpdbg_list_function( - function TSRMLS_CC); + 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); + } + + 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); } - - 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)); + } break; + + phpdbg_default_switch_case(); } return SUCCESS; @@ -132,29 +134,30 @@ PHPDBG_LIST(method) /* {{{ */ PHPDBG_LIST(class) /* {{{ */ { - if (param->type == STR_PARAM) { - zend_class_entry **ce; + 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 TSRMLS_CC - ); + 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 + ); + } 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; @@ -184,10 +187,7 @@ void phpdbg_list_dispatch(phpdbg_param_t *param TSRMLS_DC) /* {{{ */ phpdbg_do_list_method(param TSRMLS_CC); break; - default: - phpdbg_error( - "Unsupported parameter type (%s) for function", phpdbg_get_param_type(param TSRMLS_CC)); - break; + phpdbg_default_switch_case(); } } /* }}} */ diff --git a/phpdbg_prompt.c b/phpdbg_prompt.c index 91caf4525ee..393485e0da5 100644 --- a/phpdbg_prompt.c +++ b/phpdbg_prompt.c @@ -190,43 +190,45 @@ void phpdbg_welcome(zend_bool cleaning TSRMLS_DC) /* {{{ */ static PHPDBG_COMMAND(exec) /* {{{ */ { - if (param->type == STR_PARAM) { - struct stat sb; - - 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; + switch (param->type) { + case STR_PARAM: { + struct stat sb; + + 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(ops)) { + phpdbg_notice("Destroying compiled opcodes"); + phpdbg_clean(0 TSRMLS_CC); + } + + PHPDBG_G(exec) = phpdbg_resolve_path(param->str TSRMLS_CC); + + if (!PHPDBG_G(exec)) { + phpdbg_error("Cannot get real file path"); + return FAILURE; + } + + 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); } - - if (PHPDBG_G(ops)) { - phpdbg_notice("Destroying compiled opcodes"); - phpdbg_clean(0 TSRMLS_CC); - } - - PHPDBG_G(exec) = phpdbg_resolve_path(param->str TSRMLS_CC); - - if (!PHPDBG_G(exec)) { - phpdbg_error("Cannot get real file path"); - return FAILURE; - } - - 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); + phpdbg_error("Cannot stat %s, ensure the file exists", param->str); } - } else { - phpdbg_error("Cannot stat %s, ensure the file exists", param->str); - } - } else { - phpdbg_error("Unsupported parameter type (%s) for command", phpdbg_get_param_type(param TSRMLS_CC)); + } break; + + phpdbg_default_switch_case(); } - + return SUCCESS; } /* }}} */ @@ -274,18 +276,21 @@ static PHPDBG_COMMAND(compile) /* {{{ */ 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; - } + 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"); - } else { - phpdbg_error("Unsupported parameter type (%s) for command", phpdbg_get_param_type(param TSRMLS_CC)); - } + phpdbg_notice("Stepping %s", + (PHPDBG_G(flags) & PHPDBG_IS_STEPPING) ? "on" : "off"); + } break; + + phpdbg_default_switch_case(); + } return SUCCESS; } /* }}} */ @@ -352,33 +357,33 @@ static PHPDBG_COMMAND(run) /* {{{ */ static PHPDBG_COMMAND(eval) /* {{{ */ { - if (param->type == STR_PARAM) { - zend_bool stepping = (PHPDBG_G(flags) & PHPDBG_IS_STEPPING); - zval retval; + switch (param->type) { + case STR_PARAM: { + zend_bool stepping = (PHPDBG_G(flags) & PHPDBG_IS_STEPPING); + zval retval; - PHPDBG_G(flags) &= ~ PHPDBG_IS_STEPPING; + 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; + /* 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; - } - } else { - phpdbg_error( - "Unsupported parameter type (%s) for command", phpdbg_get_param_type(param TSRMLS_CC)); - return FAILURE; + /* switch stepping back on */ + if (stepping) { + PHPDBG_G(flags) |= PHPDBG_IS_STEPPING; + } + } break; + + phpdbg_default_switch_case(); } - + return SUCCESS; } /* }}} */ @@ -412,16 +417,12 @@ static PHPDBG_COMMAND(back) /* {{{ */ 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) /* {{{ */ @@ -493,10 +494,7 @@ static PHPDBG_COMMAND(break) /* {{{ */ 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; @@ -583,42 +581,41 @@ static PHPDBG_COMMAND(aliases) /* {{{ */ 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+"); if (!PHPDBG_G(oplog)) { phpdbg_error("Failed to open %s for oplog", param->str); PHPDBG_G(oplog) = old; - return FAILURE; } else { if (old) { phpdbg_notice("Closing previously open oplog"); 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) /* {{{ */ From a28ea698b8a961c7cdab2423e8328dede03250f7 Mon Sep 17 00:00:00 2001 From: krakjoe Date: Sat, 16 Nov 2013 23:11:39 +0000 Subject: [PATCH 06/11] cleanup in list ... last time --- phpdbg_list.c | 106 ++++++++++++++++++------------------------------ phpdbg_list.h | 2 +- phpdbg_prompt.c | 25 +++++++++++- 3 files changed, 64 insertions(+), 69 deletions(-) diff --git a/phpdbg_list.c b/phpdbg_list.c index 7074fb21546..ce1a7f1377b 100644 --- a/phpdbg_list.c +++ b/phpdbg_list.c @@ -31,44 +31,6 @@ 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) { @@ -92,7 +54,7 @@ PHPDBG_LIST(func) /* {{{ */ { switch (param->type) { case STR_PARAM: - i_phpdbg_list_func( + phpdbg_list_function_byname( param->str, param->len TSRMLS_CC); break; @@ -163,34 +125,6 @@ PHPDBG_LIST(class) /* {{{ */ return SUCCESS; } /* }}} */ -void phpdbg_list_dispatch(phpdbg_param_t *param TSRMLS_DC) /* {{{ */ -{ - 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 TSRMLS_CC); - } else phpdbg_list_file(phpdbg_current_file(TSRMLS_C), param->num, 0 TSRMLS_CC); - } else phpdbg_error("Not executing, and execution context not set"); - } break; - - case FILE_PARAM: - phpdbg_list_file(param->file.name, param->file.line, 0 TSRMLS_CC); - break; - - case STR_PARAM: { - i_phpdbg_list_func(param->str, param->len TSRMLS_CC); - } break; - - case METHOD_PARAM: - phpdbg_do_list_method(param TSRMLS_CC); - break; - - phpdbg_default_switch_case(); - } -} /* }}} */ - void phpdbg_list_file(const char *filename, long count, long offset TSRMLS_DC) /* {{{ */ { unsigned char *mem, *pos, *last_pos, *end_pos; @@ -289,3 +223,41 @@ void phpdbg_list_function(const zend_function *fbc TSRMLS_DC) /* {{{ */ ops->line_end - ops->line_start + 1, ops->line_start 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 = 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 --git a/phpdbg_list.h b/phpdbg_list.h index 66d0e70baec..5c7e9885ebf 100644 --- a/phpdbg_list.h +++ b/phpdbg_list.h @@ -39,9 +39,9 @@ PHPDBG_LIST(class); PHPDBG_LIST(method); PHPDBG_LIST(func); +void phpdbg_list_function_byname(const char *, size_t TSRMLS_DC); void phpdbg_list_function(const zend_function* TSRMLS_DC); void phpdbg_list_file(const char*, long, long TSRMLS_DC); -void phpdbg_list_dispatch(phpdbg_param_t *param TSRMLS_DC); static const phpdbg_command_t phpdbg_list_commands[] = { PHPDBG_LIST_EX_D(lines, "lists the specified lines", 'l'), diff --git a/phpdbg_prompt.c b/phpdbg_prompt.c index 393485e0da5..451988f003c 100644 --- a/phpdbg_prompt.c +++ b/phpdbg_prompt.c @@ -685,7 +685,30 @@ static PHPDBG_COMMAND(quiet) { /* {{{ */ 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 TSRMLS_CC); + } else phpdbg_list_file(phpdbg_current_file(TSRMLS_C), param->num, 0 TSRMLS_CC); + } else phpdbg_error("Not executing, and execution context not set"); + } break; + + case FILE_PARAM: + phpdbg_list_file(param->file.name, param->file.line, 0 TSRMLS_CC); + break; + + case STR_PARAM: { + phpdbg_list_function_byname(param->str, param->len TSRMLS_CC); + } break; + + case METHOD_PARAM: + phpdbg_do_list_method(param TSRMLS_CC); + break; + + phpdbg_default_switch_case(); + } return SUCCESS; } /* }}} */ From 8f4f4f06284c028be574178257a228526c7670b9 Mon Sep 17 00:00:00 2001 From: krakjoe Date: Sat, 16 Nov 2013 23:25:33 +0000 Subject: [PATCH 07/11] uniform code in print.c --- phpdbg_print.c | 188 ++++++++++++++++++++++++------------------------ phpdbg_prompt.c | 72 ++++++++++--------- 2 files changed, 132 insertions(+), 128 deletions(-) diff --git a/phpdbg_print.c b/phpdbg_print.c index adfc06cb856..09e6d7fab7c 100644 --- a/phpdbg_print.c +++ b/phpdbg_print.c @@ -90,37 +90,38 @@ PHPDBG_PRINT(class) /* {{{ */ { zend_class_entry **ce; - if (param->type == STR_PARAM) { - if (zend_lookup_class(param->str, param->len, &ce TSRMLS_CC) == SUCCESS) { - phpdbg_notice( - "%s %s: %s", - ((*ce)->type == ZEND_USER_CLASS) ? - "User" : "Internal", - ((*ce)->ce_flags & ZEND_ACC_INTERFACE) ? - "Interface" : - ((*ce)->ce_flags & ZEND_ACC_ABSTRACT) ? - "Abstract Class" : - "Class", - (*ce)->name); - - phpdbg_writeln("Methods (%d):", zend_hash_num_elements(&(*ce)->function_table)); - if (zend_hash_num_elements(&(*ce)->function_table)) { - HashPosition position; - zend_function *method; + switch (param->type) { + case STR_PARAM: { + if (zend_lookup_class(param->str, param->len, &ce TSRMLS_CC) == SUCCESS) { + phpdbg_notice( + "%s %s: %s", + ((*ce)->type == ZEND_USER_CLASS) ? + "User" : "Internal", + ((*ce)->ce_flags & ZEND_ACC_INTERFACE) ? + "Interface" : + ((*ce)->ce_flags & ZEND_ACC_ABSTRACT) ? + "Abstract Class" : + "Class", + (*ce)->name); - for (zend_hash_internal_pointer_reset_ex(&(*ce)->function_table, &position); - zend_hash_get_current_data_ex(&(*ce)->function_table, (void**) &method, &position) == SUCCESS; - zend_hash_move_forward_ex(&(*ce)->function_table, &position)) { - phpdbg_print_function_helper(method TSRMLS_CC); + phpdbg_writeln("Methods (%d):", zend_hash_num_elements(&(*ce)->function_table)); + if (zend_hash_num_elements(&(*ce)->function_table)) { + HashPosition position; + zend_function *method; + + for (zend_hash_internal_pointer_reset_ex(&(*ce)->function_table, &position); + zend_hash_get_current_data_ex(&(*ce)->function_table, (void**) &method, &position) == SUCCESS; + zend_hash_move_forward_ex(&(*ce)->function_table, &position)) { + phpdbg_print_function_helper(method TSRMLS_CC); + } } + } else { + phpdbg_error( + "The class %s could not be found", param->str); } - } else { - phpdbg_error( - "Cannot find class %s", param->str); - } - } else { - phpdbg_error( - "Unsupported parameter type (%s) for command", phpdbg_get_param_type(param TSRMLS_CC)); + } break; + + phpdbg_default_switch_case(); } return SUCCESS; @@ -128,33 +129,34 @@ PHPDBG_PRINT(class) /* {{{ */ PHPDBG_PRINT(method) /* {{{ */ { - if (param->type == METHOD_PARAM) { - zend_class_entry **ce; - - if (zend_lookup_class(param->method.class, strlen(param->method.class), &ce TSRMLS_CC) == SUCCESS) { - zend_function *fbc; - char *lcname = zend_str_tolower_dup(param->method.name, strlen(param->method.name)); + switch (param->type) { + case METHOD_PARAM: { + zend_class_entry **ce; - if (zend_hash_find(&(*ce)->function_table, lcname, strlen(lcname)+1, (void**)&fbc) == SUCCESS) { - phpdbg_notice( - "%s Method %s", - (fbc->type == ZEND_USER_FUNCTION) ? "User" : "Internal", - fbc->common.function_name); - - phpdbg_print_function_helper(fbc TSRMLS_CC); + if (zend_lookup_class(param->method.class, strlen(param->method.class), &ce TSRMLS_CC) == SUCCESS) { + zend_function *fbc; + 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**)&fbc) == SUCCESS) { + phpdbg_notice( + "%s Method %s", + (fbc->type == ZEND_USER_FUNCTION) ? "User" : "Internal", + fbc->common.function_name); + + phpdbg_print_function_helper(fbc TSRMLS_CC); + } else { + phpdbg_error( + "The method %s could not be found", param->method.name); + } + + efree(lcname); } else { phpdbg_error( - "The method %s could not be found", param->method.name); + "The class %s could not be found", param->method.class); } - - efree(lcname); - } else { - phpdbg_error( - "Failed to find the requested class %s", param->method.class); - } - } else { - phpdbg_error( - "Unsupported parameter type (%s) for command", phpdbg_get_param_type(param TSRMLS_CC)); + } break; + + phpdbg_default_switch_case(); } return SUCCESS; @@ -162,51 +164,51 @@ PHPDBG_PRINT(method) /* {{{ */ PHPDBG_PRINT(func) /* {{{ */ { - if (param->type == STR_PARAM) { - HashTable *func_table = EG(function_table); - zend_function* fbc; - const char *func_name = param->str; - size_t func_name_len = param->len; - char *lcname; - /* search active scope if begins with period */ - if (func_name[0] == '.') { - if (EG(scope)) { - func_name++; - func_name_len--; + switch (param->type) { + case STR_PARAM: { + HashTable *func_table = EG(function_table); + zend_function* fbc; + const char *func_name = param->str; + size_t func_name_len = param->len; + char *lcname; + /* 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 SUCCESS; - } - } else if (!EG(function_table)) { - phpdbg_error( - "No function table loaded"); - return SUCCESS; - } else { - func_table = EG(function_table); - } + func_table = &EG(scope)->function_table; + } else { + phpdbg_error("No active class"); + return SUCCESS; + } + } else if (!EG(function_table)) { + phpdbg_error( + "No function table loaded"); + return SUCCESS; + } else { + func_table = EG(function_table); + } - lcname = zend_str_tolower_dup(func_name, func_name_len); + lcname = zend_str_tolower_dup(func_name, func_name_len); + + if (zend_hash_find(func_table, lcname, strlen(lcname)+1, (void**)&fbc) == SUCCESS) { + phpdbg_notice( + "%s %s %s", + (fbc->type == ZEND_USER_FUNCTION) ? "User" : "Internal", + (fbc->common.scope) ? "Method" : "Function", + fbc->common.function_name); + + phpdbg_print_function_helper(fbc TSRMLS_CC); + } else { + phpdbg_error( + "The function %s could not be found", func_name); + } + + efree(lcname); + } break; - if (zend_hash_find(func_table, lcname, strlen(lcname)+1, (void**)&fbc) == SUCCESS) { - phpdbg_notice( - "%s %s %s", - (fbc->type == ZEND_USER_FUNCTION) ? "User" : "Internal", - (fbc->common.scope) ? "Method" : "Function", - fbc->common.function_name); - - phpdbg_print_function_helper(fbc TSRMLS_CC); - } else { - phpdbg_error( - "Function %s not found", func_name); - } - - efree(lcname); - - } else { - phpdbg_error( - "Unsupported parameter type (%s) for command", phpdbg_get_param_type(param TSRMLS_CC)); + phpdbg_default_switch_case(); } return SUCCESS; diff --git a/phpdbg_prompt.c b/phpdbg_prompt.c index 451988f003c..100d4af9c6e 100644 --- a/phpdbg_prompt.c +++ b/phpdbg_prompt.c @@ -427,51 +427,53 @@ static PHPDBG_COMMAND(back) /* {{{ */ 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_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_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_writeln(SEPARATE); - } else { - phpdbg_error("You must use a specific printer"); + phpdbg_default_switch_case(); } - + return SUCCESS; } /* }}} */ From 434949c5b40d56d5f1d97180a78cff8b968a50d2 Mon Sep 17 00:00:00 2001 From: krakjoe Date: Sat, 16 Nov 2013 23:35:11 +0000 Subject: [PATCH 08/11] consistency in prompt/list, do not return FAILURE from command handlers --- phpdbg_list.c | 2 +- phpdbg_prompt.c | 138 +++++++++++++++++++++++++----------------------- 2 files changed, 73 insertions(+), 67 deletions(-) diff --git a/phpdbg_list.c b/phpdbg_list.c index ce1a7f1377b..a778f640b15 100644 --- a/phpdbg_list.c +++ b/phpdbg_list.c @@ -227,7 +227,7 @@ 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 = str; + char *func_name = (char*) str; size_t func_name_len = len; /* search active scope if begins with period */ diff --git a/phpdbg_prompt.c b/phpdbg_prompt.c index 100d4af9c6e..d3876be0fb5 100644 --- a/phpdbg_prompt.c +++ b/phpdbg_prompt.c @@ -211,7 +211,7 @@ static PHPDBG_COMMAND(exec) /* {{{ */ if (!PHPDBG_G(exec)) { phpdbg_error("Cannot get real file path"); - return FAILURE; + return SUCCESS; } PHPDBG_G(exec_len) = strlen(PHPDBG_G(exec)); @@ -262,8 +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"); @@ -271,7 +272,9 @@ static PHPDBG_COMMAND(compile) /* {{{ */ } } - return phpdbg_compile(TSRMLS_C); + phpdbg_compile(TSRMLS_C); + + return SUCCESS; } /* }}} */ static PHPDBG_COMMAND(step) /* {{{ */ @@ -309,7 +312,7 @@ static PHPDBG_COMMAND(run) /* {{{ */ { if (EG(in_execution)) { phpdbg_error("Cannot start another execution while one is in progress"); - return FAILURE; + return SUCCESS; } if (PHPDBG_G(ops) || PHPDBG_G(exec)) { @@ -319,8 +322,9 @@ static PHPDBG_COMMAND(run) /* {{{ */ if (!PHPDBG_G(ops)) { if (phpdbg_compile(TSRMLS_C) == FAILURE) { - phpdbg_error("Failed to compile %s, cannot run", PHPDBG_G(exec)); - return FAILURE; + phpdbg_error( + "Failed to compile %s, cannot run", PHPDBG_G(exec)); + goto out; } } @@ -340,19 +344,20 @@ static PHPDBG_COMMAND(run) /* {{{ */ if (!(PHPDBG_G(flags) & PHPDBG_IS_QUITTING)) { phpdbg_error("Caught excetion in VM"); - return FAILURE; - } else return SUCCESS; + goto out; + } } zend_end_try(); EG(active_op_array) = orig_op_array; 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) /* {{{ */ @@ -391,7 +396,7 @@ static PHPDBG_COMMAND(back) /* {{{ */ { if (!EG(in_execution)) { phpdbg_error("Not executing!"); - return FAILURE; + return SUCCESS; } switch (param->type) { @@ -518,7 +523,7 @@ static PHPDBG_COMMAND(clean) /* {{{ */ { if (EG(in_execution)) { phpdbg_error("Cannot clean environment while executing"); - return FAILURE; + return SUCCESS; } phpdbg_notice("Cleaning Execution Environment"); @@ -622,64 +627,65 @@ static PHPDBG_COMMAND(oplog) /* {{{ */ 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; + 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_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; + } + + 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_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; - } - - 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(); - } else { - 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(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; @@ -764,7 +770,7 @@ int phpdbg_do_cmd( const phpdbg_command_t *command, } } - *selected = command; + *selected = (phpdbg_command_t*) command; rc = command->handler(param TSRMLS_CC); From 22ae0d51a184f95740217833def50a5cba951b0b Mon Sep 17 00:00:00 2001 From: krakjoe Date: Sun, 17 Nov 2013 09:30:44 +0000 Subject: [PATCH 09/11] add print exec command to show current execution context instructions make phpdbg_compile public --- phpdbg_help.c | 2 ++ phpdbg_print.c | 22 +++++++++++++++++++++- phpdbg_print.h | 2 ++ phpdbg_prompt.c | 2 +- phpdbg_prompt.h | 1 + 5 files changed, 27 insertions(+), 2 deletions(-) diff --git a/phpdbg_help.c b/phpdbg_help.c index e7de30af935..2a0c998c0bb 100644 --- a/phpdbg_help.c +++ b/phpdbg_help.c @@ -94,6 +94,8 @@ PHPDBG_HELP(print) /* {{{ */ phpdbg_writeln("Will print the instructions for the global function my_function"); phpdbg_writeln("\t%sprint opline", PROMPT); phpdbg_writeln("Will print the instruction for the current opline"); + phpdbg_writeln("\t%sprint exec", PROMPT); + phpdbg_writeln("Will print the instruction for the execution context"); phpdbg_writeln(EMPTY); phpdbg_writeln("Specific printers loaded are show below:"); phpdbg_notice("Commands"); diff --git a/phpdbg_print.c b/phpdbg_print.c index 09e6d7fab7c..9a4a1585d61 100644 --- a/phpdbg_print.c +++ b/phpdbg_print.c @@ -57,7 +57,7 @@ static inline void phpdbg_print_function_helper(zend_function *method TSRMLS_DC) phpdbg_writeln( "\t#%d-%d %s() %s", op_array->line_start, op_array->line_end, - method->common.function_name, + method->common.function_name ? method->common.function_name : "{main}", op_array->filename ? op_array->filename : "unknown"); } @@ -86,6 +86,26 @@ static inline void phpdbg_print_function_helper(zend_function *method TSRMLS_DC) } } +PHPDBG_PRINT(exec) /* {{{ */ +{ + if (PHPDBG_G(exec)) { + if (!PHPDBG_G(ops)) { + phpdbg_compile(TSRMLS_C); + } + + if (PHPDBG_G(ops)) { + phpdbg_notice( + "Context %s", PHPDBG_G(exec)); + + phpdbg_print_function_helper((zend_function*) PHPDBG_G(ops) TSRMLS_CC); + } + } else { + phpdbg_error("No execution context set"); + } + + return SUCCESS; +} /* }}} */ + PHPDBG_PRINT(class) /* {{{ */ { zend_class_entry **ce; diff --git a/phpdbg_print.h b/phpdbg_print.h index 01bc27fa43e..dc6a13338cd 100644 --- a/phpdbg_print.h +++ b/phpdbg_print.h @@ -34,6 +34,7 @@ /** * Printer Forward Declarations */ +PHPDBG_PRINT(exec); PHPDBG_PRINT(opline); PHPDBG_PRINT(class); PHPDBG_PRINT(method); @@ -43,6 +44,7 @@ PHPDBG_PRINT(func); * Commands */ static const phpdbg_command_t phpdbg_print_commands[] = { + PHPDBG_PRINT_D(exec, "print execution context instructions", 'e'), PHPDBG_PRINT_D(opline, "print the current opline information", 'o'), PHPDBG_PRINT_D(class, "print out the instructions in the specified class", 'c'), PHPDBG_PRINT_D(method, "print out the instructions in the specified method", 'm'), diff --git a/phpdbg_prompt.c b/phpdbg_prompt.c index d3876be0fb5..0281fd7ec6d 100644 --- a/phpdbg_prompt.c +++ b/phpdbg_prompt.c @@ -232,7 +232,7 @@ static PHPDBG_COMMAND(exec) /* {{{ */ return SUCCESS; } /* }}} */ -static inline int phpdbg_compile(TSRMLS_D) /* {{{ */ +int phpdbg_compile(TSRMLS_D) /* {{{ */ { zend_file_handle fh; diff --git a/phpdbg_prompt.h b/phpdbg_prompt.h index 8e4a0c144c9..f3839d03150 100644 --- a/phpdbg_prompt.h +++ b/phpdbg_prompt.h @@ -51,6 +51,7 @@ void phpdbg_init(char *init_file, size_t init_file_len, zend_bool use_default TS void phpdbg_welcome(zend_bool cleaning TSRMLS_DC); int phpdbg_interactive(TSRMLS_D); void phpdbg_print_opline(zend_execute_data *execute_data, zend_bool ignore_flags TSRMLS_DC); +int phpdbg_compile(TSRMLS_D); void phpdbg_clean(zend_bool full TSRMLS_DC); #if PHP_VERSION_ID >= 50500 From 5768e98cb03a72716c685f7ab90067289d1db67f Mon Sep 17 00:00:00 2001 From: krakjoe Date: Sun, 17 Nov 2013 09:36:14 +0000 Subject: [PATCH 10/11] correction --- phpdbg_help.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpdbg_help.c b/phpdbg_help.c index 2a0c998c0bb..4526f9fa834 100644 --- a/phpdbg_help.c +++ b/phpdbg_help.c @@ -95,7 +95,7 @@ PHPDBG_HELP(print) /* {{{ */ phpdbg_writeln("\t%sprint opline", PROMPT); phpdbg_writeln("Will print the instruction for the current opline"); phpdbg_writeln("\t%sprint exec", PROMPT); - phpdbg_writeln("Will print the instruction for the execution context"); + phpdbg_writeln("Will print the instructions for the execution context"); phpdbg_writeln(EMPTY); phpdbg_writeln("Specific printers loaded are show below:"); phpdbg_notice("Commands"); From dcead8ea90537dea6b06306ebb4767b2ff57d5ba Mon Sep 17 00:00:00 2001 From: krakjoe Date: Sun, 17 Nov 2013 11:11:09 +0000 Subject: [PATCH 11/11] add highlight param to file listing --- phpdbg_list.c | 18 ++++++++++++------ phpdbg_list.h | 2 +- phpdbg_prompt.c | 9 +++++---- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/phpdbg_list.c b/phpdbg_list.c index a778f640b15..ba1e31e43e2 100644 --- a/phpdbg_list.c +++ b/phpdbg_list.c @@ -38,8 +38,8 @@ PHPDBG_LIST(lines) /* {{{ */ 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 TSRMLS_CC); - } else phpdbg_list_file(phpdbg_current_file(TSRMLS_C), param->num, 0 TSRMLS_CC); + 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; @@ -106,7 +106,7 @@ PHPDBG_LIST(class) /* {{{ */ 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 + (*ce)->info.user.line_start, 0 TSRMLS_CC ); } else { phpdbg_error("The source of the requested class (%s) cannot be found", (*ce)->name); @@ -125,7 +125,7 @@ PHPDBG_LIST(class) /* {{{ */ return SUCCESS; } /* }}} */ -void phpdbg_list_file(const char *filename, long count, long offset TSRMLS_DC) /* {{{ */ +void phpdbg_list_file(const char *filename, long count, long offset, int highlight TSRMLS_DC) /* {{{ */ { unsigned char *mem, *pos, *last_pos, *end_pos; struct stat st; @@ -185,7 +185,13 @@ void phpdbg_list_file(const char *filename, long count, long offset TSRMLS_DC) / if (!offset || offset <= line) { /* Without offset, or offset reached */ - phpdbg_writeln("%05u: %.*s", line, (int)(pos - last_pos), last_pos); + if (!highlight) { + phpdbg_writeln("%05u: %.*s", line, (int)(pos - last_pos), last_pos); + } else { + if (highlight != line) { + phpdbg_writeln(" %05u: %.*s", line, (int)(pos - last_pos), last_pos); + } else phpdbg_writeln(">%05u: %.*s", line, (int)(pos - last_pos), last_pos); + } ++displayed; } @@ -220,7 +226,7 @@ void phpdbg_list_function(const zend_function *fbc TSRMLS_DC) /* {{{ */ 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) diff --git a/phpdbg_list.h b/phpdbg_list.h index 5c7e9885ebf..0d869a94d7c 100644 --- a/phpdbg_list.h +++ b/phpdbg_list.h @@ -41,7 +41,7 @@ PHPDBG_LIST(func); void phpdbg_list_function_byname(const char *, size_t TSRMLS_DC); void phpdbg_list_function(const zend_function* TSRMLS_DC); -void phpdbg_list_file(const char*, long, long TSRMLS_DC); +void phpdbg_list_file(const char*, long, long, int TSRMLS_DC); static const phpdbg_command_t phpdbg_list_commands[] = { PHPDBG_LIST_EX_D(lines, "lists the specified lines", 'l'), diff --git a/phpdbg_prompt.c b/phpdbg_prompt.c index 0281fd7ec6d..d68933be3aa 100644 --- a/phpdbg_prompt.c +++ b/phpdbg_prompt.c @@ -698,13 +698,13 @@ static PHPDBG_COMMAND(list) /* {{{ */ 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 TSRMLS_CC); - } else phpdbg_list_file(phpdbg_current_file(TSRMLS_C), param->num, 0 TSRMLS_CC); + 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 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; case STR_PARAM: { @@ -1013,7 +1013,8 @@ zend_vm_enter: #define DO_INTERACTIVE() do {\ phpdbg_list_file(\ zend_get_executed_filename(TSRMLS_C), \ - 2, \ + 3, \ + zend_get_executed_lineno(TSRMLS_C)-1, \ zend_get_executed_lineno(TSRMLS_C) \ TSRMLS_CC\ );\