From: Bob Weinand Date: Tue, 26 Nov 2013 10:02:58 +0000 (+0100) Subject: Enormous whitespace fix X-Git-Tag: php-5.6.0alpha1~110^2~40^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6ba73338dd34a2a80e0dd25ca333bfc0b859a930;p=php Enormous whitespace fix --- diff --git a/phpdbg.c b/phpdbg.c index fd31f422c9..f15e023503 100644 --- a/phpdbg.c +++ b/phpdbg.c @@ -70,14 +70,14 @@ static PHP_MINIT_FUNCTION(phpdbg) /* {{{ */ zend_execute = phpdbg_execute_ex; #endif - REGISTER_LONG_CONSTANT("PHPDBG_FILE", FILE_PARAM, CONST_CS|CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("PHPDBG_METHOD", METHOD_PARAM, CONST_CS|CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("PHPDBG_FILE", FILE_PARAM, CONST_CS|CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("PHPDBG_METHOD", METHOD_PARAM, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("PHPDBG_LINENO", NUMERIC_PARAM, CONST_CS|CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("PHPDBG_FUNC", STR_PARAM, CONST_CS|CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("PHPDBG_FUNC", STR_PARAM, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("PHPDBG_COLOR_PROMPT", PHPDBG_COLOR_PROMPT, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("PHPDBG_COLOR_NOTICE", PHPDBG_COLOR_NOTICE, CONST_CS|CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("PHPDBG_COLOR_ERROR", PHPDBG_COLOR_ERROR, CONST_CS|CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("PHPDBG_COLOR_ERROR", PHPDBG_COLOR_ERROR, CONST_CS|CONST_PERSISTENT); return SUCCESS; } /* }}} */ @@ -427,33 +427,33 @@ static inline void php_sapi_phpdbg_flush(void *context) /* {{{ */ /* {{{ sapi_module_struct phpdbg_sapi_module */ static sapi_module_struct phpdbg_sapi_module = { - "phpdbg", /* name */ - "phpdbg", /* pretty name */ + "phpdbg", /* name */ + "phpdbg", /* pretty name */ - php_sapi_phpdbg_module_startup, /* startup */ + php_sapi_phpdbg_module_startup, /* startup */ php_module_shutdown_wrapper, /* shutdown */ - NULL, /* activate */ - php_sapi_phpdbg_deactivate, /* deactivate */ + NULL, /* activate */ + php_sapi_phpdbg_deactivate, /* deactivate */ - php_sapi_phpdbg_ub_write, /* unbuffered write */ - php_sapi_phpdbg_flush, /* flush */ - NULL, /* get uid */ - NULL, /* getenv */ + php_sapi_phpdbg_ub_write, /* unbuffered write */ + php_sapi_phpdbg_flush, /* flush */ + NULL, /* get uid */ + NULL, /* getenv */ - php_error, /* error handler */ + php_error, /* error handler */ - php_sapi_phpdbg_header_handler, /* header handler */ - php_sapi_phpdbg_send_headers, /* send headers handler */ - php_sapi_phpdbg_send_header, /* send header handler */ + php_sapi_phpdbg_header_handler, /* header handler */ + php_sapi_phpdbg_send_headers, /* send headers handler */ + php_sapi_phpdbg_send_header, /* send header handler */ - NULL, /* read POST data */ + NULL, /* read POST data */ php_sapi_phpdbg_read_cookies, /* read Cookies */ - php_sapi_phpdbg_register_vars, /* register server variables */ - php_sapi_phpdbg_log_message, /* Log message */ - NULL, /* Get request time */ - NULL, /* Child terminate */ + php_sapi_phpdbg_register_vars, /* register server variables */ + php_sapi_phpdbg_log_message, /* Log message */ + NULL, /* Get request time */ + NULL, /* Child terminate */ STANDARD_SAPI_MODULE_PROPERTIES }; /* }}} */ @@ -487,11 +487,11 @@ const char phpdbg_ini_hardcoded[] = "max_input_time=-1\n\0"; /* overwriteable ini defaults must be set in phpdbg_ini_defaults() */ -#define INI_DEFAULT(name,value)\ - Z_SET_REFCOUNT(tmp, 0);\ -Z_UNSET_ISREF(tmp); \ -ZVAL_STRINGL(&tmp, zend_strndup(value, sizeof(value)-1), sizeof(value)-1, 0);\ -zend_hash_update(configuration_hash, name, sizeof(name), &tmp, sizeof(zval), NULL);\ +#define INI_DEFAULT(name, value) \ + Z_SET_REFCOUNT(tmp, 0); \ + Z_UNSET_ISREF(tmp); \ + ZVAL_STRINGL(&tmp, zend_strndup(value, sizeof(value)-1), sizeof(value)-1, 0); \ + zend_hash_update(configuration_hash, name, sizeof(name), &tmp, sizeof(zval), NULL); void phpdbg_ini_defaults(HashTable *configuration_hash) /* {{{ */ { diff --git a/phpdbg.h b/phpdbg.h index 7046ec3d00..b045d85fe0 100644 --- a/phpdbg.h +++ b/phpdbg.h @@ -106,22 +106,22 @@ #define PHPDBG_IS_COLOURED (1<<12) #define PHPDBG_IS_CLEANING (1<<13) -#define PHPDBG_IN_UNTIL (1<<14) -#define PHPDBG_IN_FINISH (1<<15) -#define PHPDBG_IN_LEAVE (1<<16) -#define PHPDBG_SEEK_MASK (PHPDBG_IN_UNTIL|PHPDBG_IN_FINISH|PHPDBG_IN_LEAVE) - -#define PHPDBG_IS_REGISTERED (1<<17) -#define PHPDBG_IS_STEPONEVAL (1<<18) -#define PHPDBG_IS_INITIALIZING (1<<19) +#define PHPDBG_IN_UNTIL (1<<14) +#define PHPDBG_IN_FINISH (1<<15) +#define PHPDBG_IN_LEAVE (1<<16) +#define PHPDBG_SEEK_MASK (PHPDBG_IN_UNTIL|PHPDBG_IN_FINISH|PHPDBG_IN_LEAVE) + +#define PHPDBG_IS_REGISTERED (1<<17) +#define PHPDBG_IS_STEPONEVAL (1<<18) +#define PHPDBG_IS_INITIALIZING (1<<19) #define PHPDBG_IS_SIGNALED (1<<20) -#define PHPDBG_IS_INTERACTIVE (1<<21) +#define PHPDBG_IS_INTERACTIVE (1<<21) #define PHPDBG_IS_BP_ENABLED (1<<22) #ifndef _WIN32 -# define PHPDBG_DEFAULT_FLAGS (PHPDBG_IS_QUIET|PHPDBG_IS_COLOURED|PHPDBG_IS_BP_ENABLED) +# define PHPDBG_DEFAULT_FLAGS (PHPDBG_IS_QUIET|PHPDBG_IS_COLOURED|PHPDBG_IS_BP_ENABLED) #else -# define PHPDBG_DEFAULT_FLAGS (PHPDBG_IS_QUIET|PHPDBG_IS_BP_ENABLED) +# define PHPDBG_DEFAULT_FLAGS (PHPDBG_IS_QUIET|PHPDBG_IS_BP_ENABLED) #endif /* }}} */ /* {{{ strings */ @@ -138,29 +138,29 @@ /* {{{ structs */ ZEND_BEGIN_MODULE_GLOBALS(phpdbg) - HashTable bp[PHPDBG_BREAK_TABLES]; /* break points */ - HashTable registered; /* registered */ - HashTable seek; /* seek oplines */ - phpdbg_frame_t frame; /* frame */ + HashTable bp[PHPDBG_BREAK_TABLES]; /* break points */ + HashTable registered; /* registered */ + HashTable seek; /* seek oplines */ + phpdbg_frame_t frame; /* frame */ - char *exec; /* file to execute */ - size_t exec_len; /* size of exec */ - zend_op_array *ops; /* op_array */ - zval *retval; /* return value */ - int bp_count; /* breakpoint count */ - int del_bp_num; /* breakpoint to delete */ - int vmret; /* return from last opcode handler execution */ + char *exec; /* file to execute */ + size_t exec_len; /* size of exec */ + zend_op_array *ops; /* op_array */ + zval *retval; /* return value */ + int bp_count; /* breakpoint count */ + int del_bp_num; /* breakpoint to delete */ + int vmret; /* return from last opcode handler execution */ - FILE *oplog; /* opline log */ - FILE *io[PHPDBG_IO_FDS]; /* io */ + FILE *oplog; /* opline log */ + FILE *io[PHPDBG_IO_FDS]; /* io */ - char *prompt[2]; /* prompt */ - const phpdbg_color_t *colors[PHPDBG_COLORS]; /* colors */ + char *prompt[2]; /* prompt */ + const phpdbg_color_t *colors[PHPDBG_COLORS]; /* colors */ - phpdbg_command_t *lcmd; /* last command */ - phpdbg_param_t lparam; /* last param */ + phpdbg_command_t *lcmd; /* last command */ + phpdbg_param_t lparam; /* last param */ - zend_ulong flags; /* phpdbg flags */ + zend_ulong flags; /* phpdbg flags */ ZEND_END_MODULE_GLOBALS(phpdbg) /* }}} */ #endif /* PHPDBG_H */ diff --git a/phpdbg_bp.c b/phpdbg_bp.c index 3fe4169b75..48e5ca0d34 100644 --- a/phpdbg_bp.c +++ b/phpdbg_bp.c @@ -38,10 +38,10 @@ static void phpdbg_llist_breakfile_dtor(void *data) /* {{{ */ static void phpdbg_class_breaks_dtor(void *data) /* {{{ */ { - phpdbg_breakmethod_t *bp = (phpdbg_breakmethod_t*) data; + phpdbg_breakmethod_t *bp = (phpdbg_breakmethod_t*) data; - efree((char*)bp->class_name); - efree((char*)bp->func_name); + efree((char*)bp->class_name); + efree((char*)bp->func_name); } /* }}} */ PHPDBG_API void phpdbg_export_breakpoints(FILE *handle TSRMLS_DC) /* {{{ */ @@ -154,42 +154,42 @@ PHPDBG_API void phpdbg_export_breakpoints(FILE *handle TSRMLS_DC) /* {{{ */ PHPDBG_API void phpdbg_set_breakpoint_file(const char *path, long line_num TSRMLS_DC) /* {{{ */ { - struct stat sb; - - 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); - - new_break.filename = estrndup(path, path_len); - new_break.line = line_num; - - PHPDBG_G(flags) |= PHPDBG_HAS_FILE_BP; - - 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_llist_init(&break_files, sizeof(phpdbg_breakfile_t), - phpdbg_llist_breakfile_dtor, 0); - - zend_hash_update(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE], - new_break.filename, path_len, &break_files, sizeof(zend_llist), - (void**)&break_files_ptr); - } - - 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); - } + struct stat sb; + + 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); + + new_break.filename = estrndup(path, path_len); + new_break.line = line_num; + + PHPDBG_G(flags) |= PHPDBG_HAS_FILE_BP; + + 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_llist_init(&break_files, sizeof(phpdbg_breakfile_t), + phpdbg_llist_breakfile_dtor, 0); + + zend_hash_update(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE], + new_break.filename, path_len, &break_files, sizeof(zend_llist), + (void**)&break_files_ptr); + } + + 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); + } } /* }}} */ PHPDBG_API void phpdbg_set_breakpoint_symbol(const char *name, size_t name_len TSRMLS_DC) /* {{{ */ @@ -205,47 +205,47 @@ PHPDBG_API void phpdbg_set_breakpoint_symbol(const char *name, size_t name_len T zend_hash_update(&PHPDBG_G(bp)[PHPDBG_BREAK_SYM], new_break.symbol, name_len, &new_break, sizeof(phpdbg_breaksymbol_t), NULL); - phpdbg_notice("Breakpoint #%d added at %s", + phpdbg_notice("Breakpoint #%d added at %s", new_break.id, new_break.symbol); } else { - phpdbg_notice("Breakpoint exists at %s", name); + phpdbg_notice("Breakpoint exists at %s", name); } } /* }}} */ PHPDBG_API void phpdbg_set_breakpoint_method(const char* class_name, const char* func_name TSRMLS_DC) /* {{{ */ { - HashTable class_breaks, *class_table; - size_t class_len = strlen(class_name); - size_t func_len = strlen(func_name); + HashTable class_breaks, *class_table; + size_t class_len = strlen(class_name); + size_t func_len = strlen(func_name); - if (zend_hash_find(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD], class_name, + if (zend_hash_find(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD], class_name, class_len, (void**)&class_table) != SUCCESS) { - zend_hash_init(&class_breaks, 8, NULL, phpdbg_class_breaks_dtor, 0); - zend_hash_update( - &PHPDBG_G(bp)[PHPDBG_BREAK_METHOD], - class_name, class_len, - (void**)&class_breaks, sizeof(HashTable), (void**)&class_table); - } + zend_hash_init(&class_breaks, 8, NULL, phpdbg_class_breaks_dtor, 0); + zend_hash_update( + &PHPDBG_G(bp)[PHPDBG_BREAK_METHOD], + class_name, class_len, + (void**)&class_breaks, sizeof(HashTable), (void**)&class_table); + } - if (!zend_hash_exists(class_table, func_name, func_len)) { - phpdbg_breakmethod_t new_break; + if (!zend_hash_exists(class_table, func_name, func_len)) { + phpdbg_breakmethod_t new_break; - PHPDBG_G(flags) |= PHPDBG_HAS_METHOD_BP; + PHPDBG_G(flags) |= PHPDBG_HAS_METHOD_BP; - new_break.class_name = estrndup(class_name, class_len); - new_break.class_len = class_len; - new_break.func_name = estrndup(func_name, func_len); - new_break.func_len = func_len; - new_break.id = PHPDBG_G(bp_count)++; + new_break.class_name = estrndup(class_name, class_len); + new_break.class_len = class_len; + new_break.func_name = estrndup(func_name, func_len); + new_break.func_len = func_len; + new_break.id = PHPDBG_G(bp_count)++; - zend_hash_update(class_table, func_name, func_len, + zend_hash_update(class_table, func_name, func_len, &new_break, sizeof(phpdbg_breakmethod_t), NULL); - phpdbg_notice("Breakpoint #%d added at %s::%s", - new_break.id, class_name, func_name); - } else { + phpdbg_notice("Breakpoint #%d added at %s::%s", + new_break.id, class_name, func_name); + } else { phpdbg_notice("Breakpoint exists at %s::%s", class_name, func_name); - } + } } /* }}} */ PHPDBG_API void phpdbg_set_breakpoint_opline(zend_ulong opline TSRMLS_DC) /* {{{ */ @@ -255,17 +255,17 @@ PHPDBG_API void phpdbg_set_breakpoint_opline(zend_ulong opline TSRMLS_DC) /* {{{ PHPDBG_G(flags) |= PHPDBG_HAS_OPLINE_BP; - new_break.name = NULL; + new_break.name = NULL; new_break.opline = opline; new_break.id = PHPDBG_G(bp_count)++; zend_hash_index_update(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE], opline, &new_break, sizeof(phpdbg_breakline_t), NULL); - phpdbg_notice("Breakpoint #%d added at %#lx", + phpdbg_notice("Breakpoint #%d added at %#lx", new_break.id, new_break.opline); } else { - phpdbg_notice("Breakpoint exists at %#lx", opline); + phpdbg_notice("Breakpoint exists at %#lx", opline); } } /* }}} */ @@ -305,28 +305,28 @@ PHPDBG_API void phpdbg_set_breakpoint_opline_ex(phpdbg_opline_ptr_t opline TSRML zend_hash_index_update(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE], (zend_ulong) opline, &new_break, sizeof(phpdbg_breakline_t), NULL); - phpdbg_notice("Breakpoint #%d added at %#lx", + phpdbg_notice("Breakpoint #%d added at %#lx", new_break.id, new_break.opline); } } /* }}} */ PHPDBG_API void phpdbg_set_breakpoint_expression(const char *expr, size_t expr_len TSRMLS_DC) /* {{{ */ { - zend_ulong hash = zend_inline_hash_func(expr, expr_len); + zend_ulong hash = zend_inline_hash_func(expr, expr_len); - if (!zend_hash_index_exists(&PHPDBG_G(bp)[PHPDBG_BREAK_COND], hash)) { - phpdbg_breakcond_t new_break; - zend_uint cops = CG(compiler_options); - zval pv; + if (!zend_hash_index_exists(&PHPDBG_G(bp)[PHPDBG_BREAK_COND], hash)) { + phpdbg_breakcond_t new_break; + zend_uint cops = CG(compiler_options); + zval pv; - ZVAL_STRINGL(&new_break.code, expr, expr_len, 1); + ZVAL_STRINGL(&new_break.code, expr, expr_len, 1); new_break.hash = hash; - new_break.id = PHPDBG_G(bp_count)++; + new_break.id = PHPDBG_G(bp_count)++; - cops = CG(compiler_options); + cops = CG(compiler_options); - CG(compiler_options) = ZEND_COMPILE_DEFAULT_FOR_EVAL; + CG(compiler_options) = ZEND_COMPILE_DEFAULT_FOR_EVAL; Z_STRLEN(pv) = expr_len + sizeof("return ;") - 1; Z_STRVAL(pv) = emalloc(Z_STRLEN(pv) + 1); @@ -340,14 +340,14 @@ PHPDBG_API void phpdbg_set_breakpoint_expression(const char *expr, size_t expr_l &pv, "Conditional Breakpoint Code" TSRMLS_CC); if (new_break.ops) { - phpdbg_breakcond_t *broken; + phpdbg_breakcond_t *brake; zend_hash_index_update( &PHPDBG_G(bp)[PHPDBG_BREAK_COND], hash, &new_break, - sizeof(phpdbg_breakcond_t), (void**)&broken); + sizeof(phpdbg_breakcond_t), (void**)&brake); phpdbg_notice("Conditional breakpoint #%d added %s/%p", - broken->id, Z_STRVAL(broken->code), broken->ops); + brake->id, Z_STRVAL(brake->code), brake->ops); PHPDBG_G(flags) |= PHPDBG_HAS_COND_BP; } else { @@ -357,9 +357,9 @@ PHPDBG_API void phpdbg_set_breakpoint_expression(const char *expr, size_t expr_l PHPDBG_G(bp_count)--; } CG(compiler_options) = cops; - } else { - phpdbg_notice("Conditional break %s exists", expr); - } + } else { + phpdbg_notice("Conditional break %s exists", expr); + } } /* }}} */ int phpdbg_find_breakpoint_file(zend_op_array *op_array TSRMLS_DC) /* {{{ */ @@ -399,9 +399,8 @@ int phpdbg_find_breakpoint_symbol(zend_function *fbc TSRMLS_DC) /* {{{ */ ops = (zend_op_array*)fbc; if (ops->scope) { - /* find method breaks here */ - return phpdbg_find_breakpoint_method( - ops TSRMLS_CC); + /* find method breaks here */ + return phpdbg_find_breakpoint_method(ops TSRMLS_CC); } fname = ops->function_name; @@ -410,10 +409,9 @@ int phpdbg_find_breakpoint_symbol(zend_function *fbc TSRMLS_DC) /* {{{ */ fname = "main"; } - if (zend_hash_find(&PHPDBG_G(bp)[PHPDBG_BREAK_SYM], fname, strlen(fname), - (void**)&bp) == SUCCESS) { + if (zend_hash_find(&PHPDBG_G(bp)[PHPDBG_BREAK_SYM], fname, strlen(fname), (void**)&bp) == SUCCESS) { phpdbg_notice("Breakpoint #%d in %s() at %s:%u", - bp->id, bp->symbol, + bp->id, bp->symbol, zend_get_executed_filename(TSRMLS_C), zend_get_executed_lineno(TSRMLS_C)); return SUCCESS; @@ -432,15 +430,13 @@ int phpdbg_find_breakpoint_method(zend_op_array *ops TSRMLS_DC) /* {{{ */ if (zend_hash_find(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD], ops->scope->name, ops->scope->name_length, (void**)&class_table) == SUCCESS) { - if (zend_hash_find( - class_table, - ops->function_name, - strlen(ops->function_name), (void**)&bp) == SUCCESS) { - - phpdbg_notice("Breakpoint #%d in %s::%s() at %s:%u", - bp->id, bp->class_name, bp->func_name, - zend_get_executed_filename(TSRMLS_C), - zend_get_executed_lineno(TSRMLS_C)); + if (zend_hash_find(class_table, ops->function_name, + strlen(ops->function_name), (void**)&bp) == SUCCESS) { + + phpdbg_notice("Breakpoint #%d in %s::%s() at %s:%u", + bp->id, bp->class_name, bp->func_name, + zend_get_executed_filename(TSRMLS_C), + zend_get_executed_lineno(TSRMLS_C)); return SUCCESS; } } @@ -455,7 +451,7 @@ int phpdbg_find_breakpoint_opline(phpdbg_opline_ptr_t opline TSRMLS_DC) /* {{{ * if (zend_hash_index_find(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE], (zend_ulong) opline, (void**)&bp) == SUCCESS) { phpdbg_notice("Breakpoint #%d in %#lx at %s:%u", - bp->id, bp->opline, + bp->id, bp->opline, zend_get_executed_filename(TSRMLS_C), zend_get_executed_lineno(TSRMLS_C)); @@ -490,69 +486,66 @@ int phpdbg_find_breakpoint_opcode(zend_uchar opcode TSRMLS_DC) /* {{{ */ int phpdbg_find_conditional_breakpoint(TSRMLS_D) /* {{{ */ { phpdbg_breakcond_t *bp; - HashPosition position; - int breakpoint = FAILURE; - - for (zend_hash_internal_pointer_reset_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_COND], &position); - zend_hash_get_current_data_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_COND], (void*)&bp, &position) == SUCCESS; - zend_hash_move_forward_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_COND], &position)) { - - zval *retval = NULL; - int orig_interactive = CG(interactive); - zval **orig_retval = EG(return_value_ptr_ptr); - zend_op_array *orig_ops = EG(active_op_array); - zend_op **orig_opline = EG(opline_ptr); - - ALLOC_INIT_ZVAL(retval); - - EG(return_value_ptr_ptr) = &retval; - EG(active_op_array) = bp->ops; - EG(no_extensions) = 1; - - if (!EG(active_symbol_table)) { - zend_rebuild_symbol_table(TSRMLS_C); - } - - CG(interactive) = 0; - - zend_try { - PHPDBG_G(flags) |= PHPDBG_IN_COND_BP; - zend_execute( - EG(active_op_array) TSRMLS_CC); - if (i_zend_is_true(retval)) { - breakpoint = SUCCESS; - } - } zend_catch { - phpdbg_error( - "Error detected while evaluating expression %s", Z_STRVAL(bp->code)); - CG(interactive) = orig_interactive; - - EG(no_extensions)=1; - EG(return_value_ptr_ptr) = orig_retval; - EG(active_op_array) = orig_ops; - EG(opline_ptr) = orig_opline; - PHPDBG_G(flags) &= ~PHPDBG_IN_COND_BP; - } zend_end_try(); - - CG(interactive) = orig_interactive; - - EG(no_extensions)=1; - EG(return_value_ptr_ptr) = orig_retval; - EG(active_op_array) = orig_ops; - EG(opline_ptr) = orig_opline; - PHPDBG_G(flags) &= ~PHPDBG_IN_COND_BP; - - if (breakpoint == SUCCESS) { - break; - } - } - - if (breakpoint == SUCCESS) { - phpdbg_notice("Conditional breakpoint #%d: (%s) %s:%u", - bp->id, Z_STRVAL(bp->code), + HashPosition position; + int breakpoint = FAILURE; + + for (zend_hash_internal_pointer_reset_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_COND], &position); + zend_hash_get_current_data_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_COND], (void*)&bp, &position) == SUCCESS; + zend_hash_move_forward_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_COND], &position)) { + zval *retval = NULL; + int orig_interactive = CG(interactive); + zval **orig_retval = EG(return_value_ptr_ptr); + zend_op_array *orig_ops = EG(active_op_array); + zend_op **orig_opline = EG(opline_ptr); + + ALLOC_INIT_ZVAL(retval); + + EG(return_value_ptr_ptr) = &retval; + EG(active_op_array) = bp->ops; + EG(no_extensions) = 1; + + if (!EG(active_symbol_table)) { + zend_rebuild_symbol_table(TSRMLS_C); + } + + CG(interactive) = 0; + + zend_try { + PHPDBG_G(flags) |= PHPDBG_IN_COND_BP; + zend_execute(EG(active_op_array) TSRMLS_CC); + if (i_zend_is_true(retval)) { + breakpoint = SUCCESS; + } + } zend_catch { + phpdbg_error("Error detected while evaluating expression %s", Z_STRVAL(bp->code)); + CG(interactive) = orig_interactive; + + EG(no_extensions)=1; + EG(return_value_ptr_ptr) = orig_retval; + EG(active_op_array) = orig_ops; + EG(opline_ptr) = orig_opline; + PHPDBG_G(flags) &= ~PHPDBG_IN_COND_BP; + } zend_end_try(); + + CG(interactive) = orig_interactive; + + EG(no_extensions)=1; + EG(return_value_ptr_ptr) = orig_retval; + EG(active_op_array) = orig_ops; + EG(opline_ptr) = orig_opline; + PHPDBG_G(flags) &= ~PHPDBG_IN_COND_BP; + + if (breakpoint == SUCCESS) { + break; + } + } + + if (breakpoint == SUCCESS) { + phpdbg_notice("Conditional breakpoint #%d: (%s) %s:%u", + bp->id, Z_STRVAL(bp->code), zend_get_executed_filename(TSRMLS_C), zend_get_executed_lineno(TSRMLS_C)); - } + } return breakpoint; } /* }}} */ @@ -699,123 +692,120 @@ PHPDBG_API void phpdbg_delete_breakpoint(zend_ulong num TSRMLS_DC) /* {{{ */ PHPDBG_API void phpdbg_clear_breakpoints(TSRMLS_D) /* {{{ */ { - zend_hash_clean(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE]); - zend_hash_clean(&PHPDBG_G(bp)[PHPDBG_BREAK_SYM]); - zend_hash_clean(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE]); - zend_hash_clean(&PHPDBG_G(bp)[PHPDBG_BREAK_OPCODE]); - zend_hash_clean(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD]); - zend_hash_clean(&PHPDBG_G(bp)[PHPDBG_BREAK_COND]); + zend_hash_clean(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE]); + zend_hash_clean(&PHPDBG_G(bp)[PHPDBG_BREAK_SYM]); + zend_hash_clean(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE]); + zend_hash_clean(&PHPDBG_G(bp)[PHPDBG_BREAK_OPCODE]); + zend_hash_clean(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD]); + zend_hash_clean(&PHPDBG_G(bp)[PHPDBG_BREAK_COND]); - PHPDBG_G(flags) &= ~PHPDBG_BP_MASK; + PHPDBG_G(flags) &= ~PHPDBG_BP_MASK; - PHPDBG_G(bp_count) = 0; + PHPDBG_G(bp_count) = 0; } /* }}} */ PHPDBG_API void phpdbg_print_breakpoints(zend_ulong type TSRMLS_DC) /* {{{ */ { - switch (type) { - case PHPDBG_BREAK_SYM: if ((PHPDBG_G(flags) & PHPDBG_HAS_SYM_BP)) { - HashPosition position; - phpdbg_breaksymbol_t *brake; - - phpdbg_writeln(SEPARATE); - phpdbg_writeln("Function Breakpoints:"); - for (zend_hash_internal_pointer_reset_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_SYM], &position); - zend_hash_get_current_data_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_SYM], (void**) &brake, &position) == SUCCESS; - zend_hash_move_forward_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_SYM], &position)) { - phpdbg_writeln( - "#%d\t\t%s", brake->id, brake->symbol); - } - } break; - - case PHPDBG_BREAK_METHOD: if ((PHPDBG_G(flags) & PHPDBG_HAS_METHOD_BP)) { - HashPosition position[2]; - HashTable *class_table; - char *class_name = NULL; - zend_uint class_len = 0; - zend_ulong class_idx = 0L; - - phpdbg_writeln(SEPARATE); - phpdbg_writeln("Method Breakpoints:"); - for (zend_hash_internal_pointer_reset_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD], &position[0]); - zend_hash_get_current_data_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD], (void**) &class_table, &position[0]) == SUCCESS; - zend_hash_move_forward_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD], &position[0])) { - - if (zend_hash_get_current_key_ex( - &PHPDBG_G(bp)[PHPDBG_BREAK_METHOD], - &class_name, &class_len, &class_idx, 0, &position[0]) == HASH_KEY_IS_STRING) { - - phpdbg_breakmethod_t *brake; - - for (zend_hash_internal_pointer_reset_ex(class_table, &position[1]); - zend_hash_get_current_data_ex(class_table, (void**)&brake, &position[1]) == SUCCESS; - zend_hash_move_forward_ex(class_table, &position[1])) { - phpdbg_writeln( - "#%d\t\t%s::%s", brake->id, brake->class_name, brake->func_name); - } - } - - } - } break; - - case PHPDBG_BREAK_FILE: if ((PHPDBG_G(flags) & PHPDBG_HAS_FILE_BP)) { - HashPosition position; - zend_llist *points; - - phpdbg_writeln(SEPARATE); - phpdbg_writeln("File Breakpoints:"); - for (zend_hash_internal_pointer_reset_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE], &position); - zend_hash_get_current_data_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE], (void**) &points, &position) == SUCCESS; - zend_hash_move_forward_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE], &position)) { - zend_llist_position lposition; - phpdbg_breakfile_t *brake; - - if ((brake = zend_llist_get_first_ex(points, &lposition))) { - do { - phpdbg_writeln("#%d\t\t%s:%lu", brake->id, brake->filename, brake->line); - } while ((brake = zend_llist_get_next_ex(points, &lposition))); - } - } - } break; - - case PHPDBG_BREAK_OPLINE: if ((PHPDBG_G(flags) & PHPDBG_HAS_OPLINE_BP)) { - HashPosition position; - phpdbg_breakline_t *brake; - - phpdbg_writeln(SEPARATE); - phpdbg_writeln("Opline Breakpoints:"); - for (zend_hash_internal_pointer_reset_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE], &position); - zend_hash_get_current_data_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE], (void**) &brake, &position) == SUCCESS; - zend_hash_move_forward_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE], &position)) { - phpdbg_writeln("#%d\t\t%#lx", brake->id, brake->opline); - } - } break; - - case PHPDBG_BREAK_COND: if ((PHPDBG_G(flags) & PHPDBG_HAS_COND_BP)) { - HashPosition position; - phpdbg_breakcond_t *brake; - - phpdbg_writeln(SEPARATE); - phpdbg_writeln("Conditional Breakpoints:"); - for (zend_hash_internal_pointer_reset_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_COND], &position); - zend_hash_get_current_data_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_COND], (void**) &brake, &position) == SUCCESS; - zend_hash_move_forward_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_COND], &position)) { - phpdbg_writeln("#%d\t\t%s", brake->id, Z_STRVAL(brake->code)); - } - } break; - - case PHPDBG_BREAK_OPCODE: if (PHPDBG_G(flags) & PHPDBG_HAS_OPCODE_BP) { - HashPosition position; - phpdbg_breakop_t *brake; - - phpdbg_writeln(SEPARATE); - phpdbg_writeln("Opcode Breakpoints:"); - for (zend_hash_internal_pointer_reset_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_OPCODE], &position); - zend_hash_get_current_data_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_OPCODE], (void**) &brake, &position) == SUCCESS; - zend_hash_move_forward_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_OPCODE], &position)) { - phpdbg_writeln("#%d\t\t%s", brake->id, brake->name); - } + switch (type) { + case PHPDBG_BREAK_SYM: if ((PHPDBG_G(flags) & PHPDBG_HAS_SYM_BP)) { + HashPosition position; + phpdbg_breaksymbol_t *brake; + + phpdbg_writeln(SEPARATE); + phpdbg_writeln("Function Breakpoints:"); + for (zend_hash_internal_pointer_reset_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_SYM], &position); + zend_hash_get_current_data_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_SYM], (void**) &brake, &position) == SUCCESS; + zend_hash_move_forward_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_SYM], &position)) { + phpdbg_writeln("#%d\t\t%s", brake->id, brake->symbol); + } + } break; + + case PHPDBG_BREAK_METHOD: if ((PHPDBG_G(flags) & PHPDBG_HAS_METHOD_BP)) { + HashPosition position[2]; + HashTable *class_table; + char *class_name = NULL; + zend_uint class_len = 0; + zend_ulong class_idx = 0L; + + phpdbg_writeln(SEPARATE); + phpdbg_writeln("Method Breakpoints:"); + for (zend_hash_internal_pointer_reset_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD], &position[0]); + zend_hash_get_current_data_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD], (void**) &class_table, &position[0]) == SUCCESS; + zend_hash_move_forward_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD], &position[0])) { + + if (zend_hash_get_current_key_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD], + &class_name, &class_len, &class_idx, 0, &position[0]) == HASH_KEY_IS_STRING) { + + phpdbg_breakmethod_t *brake; + + for (zend_hash_internal_pointer_reset_ex(class_table, &position[1]); + zend_hash_get_current_data_ex(class_table, (void**)&brake, &position[1]) == SUCCESS; + zend_hash_move_forward_ex(class_table, &position[1])) { + phpdbg_writeln("#%d\t\t%s::%s", brake->id, brake->class_name, brake->func_name); + } + } + + } + } break; + + case PHPDBG_BREAK_FILE: if ((PHPDBG_G(flags) & PHPDBG_HAS_FILE_BP)) { + HashPosition position; + zend_llist *points; + + phpdbg_writeln(SEPARATE); + phpdbg_writeln("File Breakpoints:"); + for (zend_hash_internal_pointer_reset_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE], &position); + zend_hash_get_current_data_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE], (void**) &points, &position) == SUCCESS; + zend_hash_move_forward_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE], &position)) { + zend_llist_position lposition; + phpdbg_breakfile_t *brake; + + if ((brake = zend_llist_get_first_ex(points, &lposition))) { + do { + phpdbg_writeln("#%d\t\t%s:%lu", brake->id, brake->filename, brake->line); + } while ((brake = zend_llist_get_next_ex(points, &lposition))); + } + } + } break; + + case PHPDBG_BREAK_OPLINE: if ((PHPDBG_G(flags) & PHPDBG_HAS_OPLINE_BP)) { + HashPosition position; + phpdbg_breakline_t *brake; + + phpdbg_writeln(SEPARATE); + phpdbg_writeln("Opline Breakpoints:"); + for (zend_hash_internal_pointer_reset_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE], &position); + zend_hash_get_current_data_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE], (void**) &brake, &position) == SUCCESS; + zend_hash_move_forward_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE], &position)) { + phpdbg_writeln("#%d\t\t%#lx", brake->id, brake->opline); + } + } break; + + case PHPDBG_BREAK_COND: if ((PHPDBG_G(flags) & PHPDBG_HAS_COND_BP)) { + HashPosition position; + phpdbg_breakcond_t *brake; + + phpdbg_writeln(SEPARATE); + phpdbg_writeln("Conditional Breakpoints:"); + for (zend_hash_internal_pointer_reset_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_COND], &position); + zend_hash_get_current_data_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_COND], (void**) &brake, &position) == SUCCESS; + zend_hash_move_forward_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_COND], &position)) { + phpdbg_writeln("#%d\t\t%s", brake->id, Z_STRVAL(brake->code)); + } } break; - } + + case PHPDBG_BREAK_OPCODE: if (PHPDBG_G(flags) & PHPDBG_HAS_OPCODE_BP) { + HashPosition position; + phpdbg_breakop_t *brake; + + phpdbg_writeln(SEPARATE); + phpdbg_writeln("Opcode Breakpoints:"); + for (zend_hash_internal_pointer_reset_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_OPCODE], &position); + zend_hash_get_current_data_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_OPCODE], (void**) &brake, &position) == SUCCESS; + zend_hash_move_forward_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_OPCODE], &position)) { + phpdbg_writeln("#%d\t\t%s", brake->id, brake->name); + } + } break; + } } /* }}} */ diff --git a/phpdbg_bp.h b/phpdbg_bp.h index 8b1a0f0bce..eb30e3ee25 100644 --- a/phpdbg_bp.h +++ b/phpdbg_bp.h @@ -28,8 +28,8 @@ typedef struct _zend_op *phpdbg_opline_ptr_t; /* }}} */ */ typedef struct _phpdbg_breakfile_t { const char *filename; - long line; - int id; + long line; + int id; } phpdbg_breakfile_t; /** @@ -37,36 +37,36 @@ typedef struct _phpdbg_breakfile_t { */ typedef struct _phpdbg_breaksymbol_t { const char *symbol; - int id; + int id; } phpdbg_breaksymbol_t; /** * Breakpoint method based representation */ typedef struct _phpdbg_breakmethod_t { - const char *class_name; - size_t class_len; - const char *func_name; - size_t func_len; - int id; + const char *class_name; + size_t class_len; + const char *func_name; + size_t func_len; + int id; } phpdbg_breakmethod_t; /** * Breakpoint opline based representation */ typedef struct _phpdbg_breakline_t { - const char *name; - zend_ulong opline; - int id; + const char *name; + zend_ulong opline; + int id; } phpdbg_breakline_t; /** * Breakpoint opcode based representation */ typedef struct _phpdbg_breakop_t { - zend_ulong hash; + zend_ulong hash; const char *name; - int id; + int id; } phpdbg_breakop_t; /** @@ -75,8 +75,8 @@ typedef struct _phpdbg_breakop_t { typedef struct _phpdbg_breakcond_t { zend_ulong hash; zval code; - zend_op_array *ops; - int id; + zend_op_array *ops; + int id; } phpdbg_breakcond_t; PHPDBG_API void phpdbg_set_breakpoint_file(const char*, long TSRMLS_DC); diff --git a/phpdbg_break.c b/phpdbg_break.c index 14facbc3df..1b9b14b82a 100644 --- a/phpdbg_break.c +++ b/phpdbg_break.c @@ -43,37 +43,37 @@ PHPDBG_BREAK(method) /* {{{ */ { switch (param->type) { case METHOD_PARAM: - phpdbg_set_breakpoint_method(param->method.class, param->method.name TSRMLS_CC); - break; + phpdbg_set_breakpoint_method(param->method.class, param->method.name TSRMLS_CC); + break; phpdbg_default_switch_case(); - } + } - return SUCCESS; + return SUCCESS; } /* }}} */ PHPDBG_BREAK(address) /* {{{ */ { switch (param->type) { case ADDR_PARAM: - phpdbg_set_breakpoint_opline(param->addr TSRMLS_CC); - break; + phpdbg_set_breakpoint_opline(param->addr TSRMLS_CC); + break; phpdbg_default_switch_case(); - } + } - return SUCCESS; + return SUCCESS; } /* }}} */ PHPDBG_BREAK(on) /* {{{ */ { - switch (param->type) { - case STR_PARAM: - phpdbg_set_breakpoint_expression(param->str, param->len TSRMLS_CC); - break; + switch (param->type) { + case STR_PARAM: + phpdbg_set_breakpoint_expression(param->str, param->len TSRMLS_CC); + break; - phpdbg_default_switch_case(); - } + phpdbg_default_switch_case(); + } return SUCCESS; } /* }}} */ @@ -82,12 +82,11 @@ PHPDBG_BREAK(lineno) /* {{{ */ { switch (param->type) { 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 !"); - } + 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(); @@ -106,7 +105,7 @@ PHPDBG_BREAK(func) /* {{{ */ phpdbg_default_switch_case(); } - return SUCCESS; + return SUCCESS; } /* }}} */ PHPDBG_BREAK(op) /* {{{ */ diff --git a/phpdbg_cmd.c b/phpdbg_cmd.c index 1d12334592..e9a81c9505 100644 --- a/phpdbg_cmd.c +++ b/phpdbg_cmd.c @@ -41,7 +41,7 @@ PHPDBG_API const char *phpdbg_get_param_type(const phpdbg_param_t *param TSRMLS_ return "string"; default: /* this is bad */ return "unknown"; - } + } } PHPDBG_API phpdbg_param_type phpdbg_parse_param(const char *str, size_t len, phpdbg_param_t *param TSRMLS_DC) /* {{{ */ @@ -63,7 +63,7 @@ PHPDBG_API phpdbg_param_type phpdbg_parse_param(const char *str, size_t len, php param->num = strtol(str, NULL, 0); param->type = NUMERIC_PARAM; - goto parsed; + goto parsed; } else if (phpdbg_is_class_method(str, len+1, &class_name, &func_name)) { @@ -93,7 +93,7 @@ PHPDBG_API phpdbg_param_type phpdbg_parse_param(const char *str, size_t len, php param->type = STR_PARAM; parsed: - phpdbg_debug("phpdbg_parse_param(\"%s\", %lu): %s", + phpdbg_debug("phpdbg_parse_param(\"%s\", %lu): %s", str, len, phpdbg_get_param_type(param TSRMLS_CC)); return param->type; } /* }}} */ @@ -134,31 +134,31 @@ PHPDBG_API phpdbg_input_t **phpdbg_read_argv(char *buffer, int *argc TSRMLS_DC) argv = (phpdbg_input_t**) emalloc(sizeof(phpdbg_input_t*)); (*argc) = 0; -#define RESET_STATE() do {\ - phpdbg_input_t *arg = emalloc(sizeof(phpdbg_input_t));\ - if (arg) {\ - b[l]=0;\ - arg->length = l;\ - arg->string = estrndup(b, arg->length);\ - arg->argv=NULL;\ - arg->argc=0;\ - argv = (phpdbg_input_t**) erealloc(argv, sizeof(phpdbg_input_t*) * ((*argc)+1));\ - argv[(*argc)++] = arg;\ - l=0;\ - }\ - state = IN_BETWEEN;\ -} while(0) +#define RESET_STATE() do { \ + phpdbg_input_t *arg = emalloc(sizeof(phpdbg_input_t)); \ + if (arg) { \ + b[l]=0; \ + arg->length = l; \ + arg->string = estrndup(b, arg->length); \ + arg->argv = NULL; \ + arg->argc = 0; \ + argv = (phpdbg_input_t**) erealloc(argv, sizeof(phpdbg_input_t*) * ((*argc)+1)); \ + argv[(*argc)++] = arg; \ + l = 0; \ + } \ + state = IN_BETWEEN; \ +} while (0) for (p = buffer; *p != '\0'; p++) { int c = (unsigned char) *p; switch (state) { case IN_BETWEEN: if (isspace(c)) { - continue; + continue; } if (c == '"') { - state = IN_STRING; - continue; + state = IN_STRING; + continue; } state = IN_WORD; b[l++]=c; @@ -170,7 +170,7 @@ PHPDBG_API phpdbg_input_t **phpdbg_read_argv(char *buffer, int *argc TSRMLS_DC) b[l-1]=c; continue; } - RESET_STATE(); + RESET_STATE(); } else { b[l++]=c; } @@ -178,7 +178,7 @@ PHPDBG_API phpdbg_input_t **phpdbg_read_argv(char *buffer, int *argc TSRMLS_DC) case IN_WORD: if (isspace(c)) { - RESET_STATE(); + RESET_STATE(); } else { b[l++]=c; } diff --git a/phpdbg_cmd.h b/phpdbg_cmd.h index 2c1822e32f..d72cb5b0bd 100644 --- a/phpdbg_cmd.h +++ b/phpdbg_cmd.h @@ -51,7 +51,7 @@ struct _phpdbg_input_t { }; typedef struct _phpdbg_param { - phpdbg_param_type type; + phpdbg_param_type type; long num; zend_ulong addr; struct { @@ -150,10 +150,8 @@ PHPDBG_API int phpdbg_do_cmd(const phpdbg_command_t*, phpdbg_input_t* TSRMLS_DC) * Default Switch Case */ #define phpdbg_default_switch_case() \ - default:\ - phpdbg_error(\ - "Unsupported parameter type (%s) for command", \ - phpdbg_get_param_type(param TSRMLS_CC)); \ - break + default: \ + phpdbg_error("Unsupported parameter type (%s) for command", phpdbg_get_param_type(param TSRMLS_CC)); \ + break #endif /* PHPDBG_CMD_H */ diff --git a/phpdbg_help.c b/phpdbg_help.c index 650025b7c1..b6bc28cb66 100644 --- a/phpdbg_help.c +++ b/phpdbg_help.c @@ -30,7 +30,7 @@ ZEND_EXTERN_MODULE_GLOBALS(phpdbg); PHPDBG_HELP(exec) /* {{{ */ { - phpdbg_help_header(); + phpdbg_help_header(); phpdbg_writeln("\tWill attempt execution, if compilation has not yet taken place, it occurs now"); phpdbg_writeln("The execution context must be set before execution can take place"); phpdbg_help_footer(); @@ -39,29 +39,29 @@ PHPDBG_HELP(exec) /* {{{ */ PHPDBG_HELP(step) /* {{{ */ { - phpdbg_help_header(); - phpdbg_writeln("You can enable and disable stepping at any phpdbg prompt during execution"); - phpdbg_writeln(EMPTY); - phpdbg_notice("Examples"); - phpdbg_writeln("\t%sstepping 1", phpdbg_get_prompt(TSRMLS_C)); - phpdbg_writeln("\t%ss 1", phpdbg_get_prompt(TSRMLS_C)); - phpdbg_writeln("\tWill enable stepping"); - phpdbg_writeln(EMPTY); - phpdbg_writeln("While stepping is enabled you are presented with a prompt after the execution of each opcode"); - phpdbg_help_footer(); - return SUCCESS; + phpdbg_help_header(); + phpdbg_writeln("You can enable and disable stepping at any phpdbg prompt during execution"); + phpdbg_writeln(EMPTY); + phpdbg_notice("Examples"); + phpdbg_writeln("\t%sstepping 1", phpdbg_get_prompt(TSRMLS_C)); + phpdbg_writeln("\t%ss 1", phpdbg_get_prompt(TSRMLS_C)); + phpdbg_writeln("\tWill enable stepping"); + phpdbg_writeln(EMPTY); + phpdbg_writeln("While stepping is enabled you are presented with a prompt after the execution of each opcode"); + phpdbg_help_footer(); + return SUCCESS; } /* }}} */ PHPDBG_HELP(next) /* {{{ */ { - phpdbg_help_header(); + phpdbg_help_header(); phpdbg_write("Step back into the vm and execute the next opcode"); phpdbg_writeln(EMPTY); - phpdbg_notice("Examples"); - phpdbg_writeln("\t%snext", phpdbg_get_prompt(TSRMLS_C)); - phpdbg_writeln("\t%sn", phpdbg_get_prompt(TSRMLS_C)); - phpdbg_writeln("\tWill cause control to be passed back to the vm, continuing execution"); - phpdbg_writeln(EMPTY); + phpdbg_notice("Examples"); + phpdbg_writeln("\t%snext", phpdbg_get_prompt(TSRMLS_C)); + phpdbg_writeln("\t%sn", phpdbg_get_prompt(TSRMLS_C)); + phpdbg_writeln("\tWill cause control to be passed back to the vm, continuing execution"); + phpdbg_writeln(EMPTY); phpdbg_writeln("Note: is only useful while executing"); phpdbg_help_footer(); return SUCCESS; @@ -69,14 +69,14 @@ PHPDBG_HELP(next) /* {{{ */ PHPDBG_HELP(until) /* {{{ */ { - phpdbg_help_header(); + phpdbg_help_header(); phpdbg_writeln("Step back into the vm, skipping breakpoints until the next source line"); phpdbg_writeln(EMPTY); - phpdbg_notice("Examples"); - phpdbg_writeln("\t%suntil", phpdbg_get_prompt(TSRMLS_C)); - phpdbg_writeln("\t%su", phpdbg_get_prompt(TSRMLS_C)); - phpdbg_writeln("\tWill cause control to be passed back to the vm, continuing execution"); - phpdbg_writeln(EMPTY); + phpdbg_notice("Examples"); + phpdbg_writeln("\t%suntil", phpdbg_get_prompt(TSRMLS_C)); + phpdbg_writeln("\t%su", phpdbg_get_prompt(TSRMLS_C)); + phpdbg_writeln("\tWill cause control to be passed back to the vm, continuing execution"); + phpdbg_writeln(EMPTY); phpdbg_writeln("Note: is only useful while executing"); phpdbg_help_footer(); return SUCCESS; @@ -84,14 +84,14 @@ PHPDBG_HELP(until) /* {{{ */ PHPDBG_HELP(finish) /* {{{ */ { - phpdbg_help_header(); + phpdbg_help_header(); phpdbg_writeln("Step back into the vm, skipping breakpoints until past the end of the current stack"); phpdbg_writeln(EMPTY); - phpdbg_notice("Examples"); - phpdbg_writeln("\t%sfinish", phpdbg_get_prompt(TSRMLS_C)); - phpdbg_writeln("\t%sF", phpdbg_get_prompt(TSRMLS_C)); - phpdbg_writeln("\tWill cause control to be passed back to the vm, continuing execution"); - phpdbg_writeln(EMPTY); + phpdbg_notice("Examples"); + phpdbg_writeln("\t%sfinish", phpdbg_get_prompt(TSRMLS_C)); + phpdbg_writeln("\t%sF", phpdbg_get_prompt(TSRMLS_C)); + phpdbg_writeln("\tWill cause control to be passed back to the vm, continuing execution"); + phpdbg_writeln(EMPTY); phpdbg_writeln("Note: this allows all breakpoints that would otherwise break execution in the current scope to be skipped"); phpdbg_help_footer(); return SUCCESS; @@ -99,7 +99,7 @@ PHPDBG_HELP(finish) /* {{{ */ PHPDBG_HELP(leave) /* {{{ */ { - phpdbg_help_header(); + phpdbg_help_header(); phpdbg_writeln("Step back into the vm, skipping breakpoints until the current stack is returning"); phpdbg_writeln(EMPTY); phpdbg_notice("Examples"); @@ -114,7 +114,7 @@ PHPDBG_HELP(leave) /* {{{ */ PHPDBG_HELP(compile) /* {{{ */ { - phpdbg_help_header(); + phpdbg_help_header(); phpdbg_writeln("Pre-compilation of the execution context provides the opportunity to inspect opcodes before execution"); phpdbg_writeln("The execution context must be set for compilation to succeed"); phpdbg_writeln(EMPTY); @@ -130,7 +130,7 @@ PHPDBG_HELP(compile) /* {{{ */ PHPDBG_HELP(print) /* {{{ */ { - phpdbg_help_header(); + phpdbg_help_header(); phpdbg_writeln("By default, print will show information about the current execution context"); phpdbg_writeln("Other printing commands give access to instruction information"); phpdbg_writeln(EMPTY); @@ -166,13 +166,15 @@ PHPDBG_HELP(print) /* {{{ */ phpdbg_writeln("Specific printers loaded are show below:"); phpdbg_notice("Commands"); { - const phpdbg_command_t *print_command = phpdbg_print_commands; + const phpdbg_command_t *print_command = phpdbg_print_commands; - phpdbg_writeln("\tAlias\tCommand\t\tPurpose"); - while (print_command && print_command->name) { + phpdbg_writeln("\tAlias\tCommand\t\tPurpose"); + while (print_command && print_command->name) { if (print_command->alias) { - phpdbg_writeln("\t[%c]\t%s\t\t%s", print_command->alias, print_command->name, print_command->tip); - } else phpdbg_writeln("\t[ ]\t%s\t\t%s", print_command->name, print_command->tip); + phpdbg_writeln("\t[%c]\t%s\t\t%s", print_command->alias, print_command->name, print_command->tip); + } else { + phpdbg_writeln("\t[ ]\t%s\t\t%s", print_command->name, print_command->tip); + } ++print_command; } } @@ -182,7 +184,7 @@ PHPDBG_HELP(print) /* {{{ */ PHPDBG_HELP(run) /* {{{ */ { - phpdbg_help_header(); + phpdbg_help_header(); phpdbg_writeln("Execute the current context inside the phpdbg vm"); phpdbg_writeln(EMPTY); phpdbg_notice("Examples"); @@ -197,7 +199,7 @@ PHPDBG_HELP(run) /* {{{ */ PHPDBG_HELP(eval) /* {{{ */ { - phpdbg_help_header(); + phpdbg_help_header(); phpdbg_writeln("Access to eval() allows you to change the environment during execution, careful though !!"); phpdbg_writeln(EMPTY); phpdbg_notice("Examples"); @@ -216,7 +218,7 @@ PHPDBG_HELP(eval) /* {{{ */ PHPDBG_HELP(break) /* {{{ */ { - phpdbg_help_header(); + phpdbg_help_header(); phpdbg_writeln("Setting a breakpoint stops execution at a specific stage"); phpdbg_writeln(EMPTY); phpdbg_notice("Examples"); @@ -259,18 +261,20 @@ PHPDBG_HELP(break) /* {{{ */ phpdbg_writeln("Specific breakers loaded are show below:"); phpdbg_notice("Commands"); { - const phpdbg_command_t *break_command = phpdbg_break_commands; + const phpdbg_command_t *break_command = phpdbg_break_commands; - phpdbg_writeln("\tAlias\tCommand\t\tPurpose"); - while (break_command && break_command->name) { + phpdbg_writeln("\tAlias\tCommand\t\tPurpose"); + while (break_command && break_command->name) { if (break_command->alias) { - phpdbg_writeln("\t[%c]\t%s\t\t%s", break_command->alias, break_command->name, break_command->tip); - } else phpdbg_writeln("\t[ ]\t%s\t\t%s", break_command->name, break_command->tip); + phpdbg_writeln("\t[%c]\t%s\t\t%s", break_command->alias, break_command->name, break_command->tip); + } else { + phpdbg_writeln("\t[ ]\t%s\t\t%s", break_command->name, break_command->tip); + } ++break_command; } } phpdbg_writeln("Note: Conditional breaks are costly, use them sparingly !"); - phpdbg_help_footer(); + phpdbg_help_footer(); return SUCCESS; } /* }}} */ @@ -278,7 +282,6 @@ PHPDBG_HELP(clean) /* {{{ */ { phpdbg_help_header(); phpdbg_writeln("While debugging you may experience errors because of attempts to redeclare classes, constants or functions"); - phpdbg_writeln("Cleaning the environment cleans these tables, so that files can be recompiled without exiting phpdbg"); phpdbg_help_footer(); return SUCCESS; @@ -288,7 +291,6 @@ PHPDBG_HELP(clear) /* {{{ */ { phpdbg_help_header(); phpdbg_writeln("Clearing breakpoints means you can once again run code without interruption"); - phpdbg_writeln("Note: all breakpoints are lost; be sure debugging is complete before clearing"); phpdbg_help_footer(); return SUCCESS; @@ -307,7 +309,9 @@ PHPDBG_HELP(info) /* {{{ */ while (info_command && info_command->name) { if (info_command->alias) { phpdbg_writeln("\t[%c]\t%s\t\t%s", info_command->alias, info_command->name, info_command->tip); - } else phpdbg_writeln("\t[ ]\t%s\t\t%s", info_command->name, info_command->tip); + } else { + phpdbg_writeln("\t[ ]\t%s\t\t%s", info_command->name, info_command->tip); + } ++info_command; } } @@ -332,15 +336,15 @@ PHPDBG_HELP(quiet) /* {{{ */ phpdbg_writeln(EMPTY); phpdbg_writeln("Note: Quietness is disabled automatically while stepping"); phpdbg_help_footer(); - return SUCCESS; + return SUCCESS; } /* }}} */ PHPDBG_HELP(back) /* {{{ */ { - phpdbg_help_header(); + phpdbg_help_header(); phpdbg_writeln("The backtrace is built with the default debug backtrace functionality"); - phpdbg_writeln(EMPTY); - phpdbg_notice("Examples"); + phpdbg_writeln(EMPTY); + phpdbg_notice("Examples"); phpdbg_writeln("\t%sback 5", phpdbg_get_prompt(TSRMLS_C)); phpdbg_writeln("\t%st 5", phpdbg_get_prompt(TSRMLS_C)); phpdbg_writeln("\tWill limit the number of frames to 5, the default is no limit"); @@ -352,10 +356,10 @@ PHPDBG_HELP(back) /* {{{ */ PHPDBG_HELP(frame) /* {{{ */ { - phpdbg_help_header(); + phpdbg_help_header(); phpdbg_writeln("When viewing a backtrace, it is sometimes useful to jump to a frame in that trace"); - phpdbg_writeln(EMPTY); - phpdbg_notice("Examples"); + phpdbg_writeln(EMPTY); + phpdbg_notice("Examples"); phpdbg_writeln("\t%sframe 2", phpdbg_get_prompt(TSRMLS_C)); phpdbg_writeln("\t%sf 2", phpdbg_get_prompt(TSRMLS_C)); phpdbg_writeln("\tWill go to frame 2, temporarily affecting scope and allowing access to the variables in that frame"); @@ -367,7 +371,7 @@ PHPDBG_HELP(frame) /* {{{ */ PHPDBG_HELP(list) /* {{{ */ { - phpdbg_help_header(); + phpdbg_help_header(); phpdbg_writeln("The list command displays source code for the given argument"); phpdbg_writeln(EMPTY); phpdbg_notice("Examples"); @@ -398,13 +402,15 @@ PHPDBG_HELP(list) /* {{{ */ phpdbg_writeln("Specific listers loaded are show below:"); phpdbg_notice("Commands"); { - const phpdbg_command_t *list_command = phpdbg_list_commands; + const phpdbg_command_t *list_command = phpdbg_list_commands; - phpdbg_writeln("\tAlias\tCommand\t\tPurpose"); - while (list_command && list_command->name) { + phpdbg_writeln("\tAlias\tCommand\t\tPurpose"); + while (list_command && list_command->name) { if (list_command->alias) { - phpdbg_writeln("\t[%c]\t%s\t\t%s", list_command->alias, list_command->name, list_command->tip); - } else phpdbg_writeln("\t[ ]\t%s\t\t%s", list_command->name, list_command->tip); + phpdbg_writeln("\t[%c]\t%s\t\t%s", list_command->alias, list_command->name, list_command->tip); + } else { + phpdbg_writeln("\t[ ]\t%s\t\t%s", list_command->name, list_command->tip); + } ++list_command; } } @@ -440,13 +446,15 @@ PHPDBG_HELP(set) /* {{{ */ phpdbg_writeln("Specific set commands are show below:"); phpdbg_notice("Commands"); { - const phpdbg_command_t *set_command = phpdbg_set_commands; + const phpdbg_command_t *set_command = phpdbg_set_commands; - phpdbg_writeln("\tAlias\tCommand\t\tPurpose"); - while (set_command && set_command->name) { + phpdbg_writeln("\tAlias\tCommand\t\tPurpose"); + while (set_command && set_command->name) { if (set_command->alias) { - phpdbg_writeln("\t[%c]\t%s\t\t%s", set_command->alias, set_command->name, set_command->tip); - } else phpdbg_writeln("\t[ ]\t%s\t\t%s", set_command->name, set_command->tip); + phpdbg_writeln("\t[%c]\t%s\t\t%s", set_command->alias, set_command->name, set_command->tip); + } else { + phpdbg_writeln("\t[ ]\t%s\t\t%s", set_command->name, set_command->tip); + } ++set_command; } } @@ -456,14 +464,17 @@ PHPDBG_HELP(set) /* {{{ */ if (PHPDBG_G(flags) & PHPDBG_IS_COLOURED) { phpdbg_writeln("\t%-20s\t\tExample", "Name"); - } else phpdbg_writeln("\tName"); + } else { + phpdbg_writeln("\tName"); + } while (color && color->name) { if (PHPDBG_G(flags) & PHPDBG_IS_COLOURED) { phpdbg_writeln( "\t%-20s\t\t\033[%smphpdbg rocks :)\033[0m", color->name, color->code); - } else phpdbg_writeln("\t%s", color->name); - + } else { + phpdbg_writeln("\t%s", color->name); + } ++color; } } @@ -475,15 +486,15 @@ PHPDBG_HELP(set) /* {{{ */ PHPDBG_HELP(register) /* {{{ */ { phpdbg_help_header(); - phpdbg_writeln("Register any global function for use as a command in phpdbg console"); + phpdbg_writeln("Register any global function for use as a command in phpdbg console"); phpdbg_writeln(EMPTY); - phpdbg_notice("Examples"); + phpdbg_notice("Examples"); phpdbg_writeln("\t%sregister scandir", phpdbg_get_prompt(TSRMLS_C)); - phpdbg_writeln("\t%sR scandir", phpdbg_get_prompt(TSRMLS_C)); - phpdbg_writeln("\tWill register the scandir function for use in phpdbg"); + phpdbg_writeln("\t%sR scandir", phpdbg_get_prompt(TSRMLS_C)); + phpdbg_writeln("\tWill register the scandir function for use in phpdbg"); phpdbg_writeln(EMPTY); - phpdbg_writeln("Note: arguments passed as strings, return (if present) print_r'd on console"); - if (zend_hash_num_elements(&PHPDBG_G(registered))) { + phpdbg_writeln("Note: arguments passed as strings, return (if present) print_r'd on console"); + if (zend_hash_num_elements(&PHPDBG_G(registered))) { HashPosition position; char *name = NULL; zend_uint name_len = 0; @@ -495,10 +506,10 @@ PHPDBG_HELP(register) /* {{{ */ phpdbg_writeln("|-------> %s", name); efree(name); } - } + } - phpdbg_help_footer(); - return SUCCESS; + phpdbg_help_footer(); + return SUCCESS; } /* }}} */ PHPDBG_HELP(source) /* {{{ */ @@ -507,13 +518,13 @@ PHPDBG_HELP(source) /* {{{ */ phpdbg_writeln("Sourcing a phpdbginit during your debugging session might save some time"); phpdbg_writeln("The source command can also be used to export breakpoints to a phpdbginit file"); phpdbg_writeln(EMPTY); - phpdbg_notice("Examples"); + phpdbg_notice("Examples"); phpdbg_writeln("\t%ssource /my/init", phpdbg_get_prompt(TSRMLS_C)); - phpdbg_writeln("\t%s. /my/init", phpdbg_get_prompt(TSRMLS_C)); - phpdbg_writeln("\tWill execute the phpdbginit file at /my/init"); + phpdbg_writeln("\t%s. /my/init", phpdbg_get_prompt(TSRMLS_C)); + phpdbg_writeln("\tWill execute the phpdbginit file at /my/init"); phpdbg_writeln("\t%ssource export /my/init", phpdbg_get_prompt(TSRMLS_C)); - phpdbg_writeln("\t%s. export /my/init", phpdbg_get_prompt(TSRMLS_C)); - phpdbg_writeln("\tWill export breakpoints to /my/init in phpdbginit file format"); + phpdbg_writeln("\t%s. export /my/init", phpdbg_get_prompt(TSRMLS_C)); + phpdbg_writeln("\tWill export breakpoints to /my/init in phpdbginit file format"); phpdbg_help_footer(); return SUCCESS; } /* }}} */ @@ -521,16 +532,16 @@ PHPDBG_HELP(source) /* {{{ */ PHPDBG_HELP(shell) /* {{{ */ { phpdbg_help_header(); - phpdbg_writeln("Direct access to shell commands saves having to switch windows/consoles"); + phpdbg_writeln("Direct access to shell commands saves having to switch windows/consoles"); phpdbg_writeln(EMPTY); - phpdbg_notice("Examples"); + phpdbg_notice("Examples"); phpdbg_writeln("\t%sshell ls /usr/src/php-src", phpdbg_get_prompt(TSRMLS_C)); - phpdbg_writeln("\t%s- ls /usr/src/php-src", phpdbg_get_prompt(TSRMLS_C)); - phpdbg_writeln("\tWill execute ls /usr/src/php-src, displaying the output in the console"); + phpdbg_writeln("\t%s- ls /usr/src/php-src", phpdbg_get_prompt(TSRMLS_C)); + phpdbg_writeln("\tWill execute ls /usr/src/php-src, displaying the output in the console"); phpdbg_writeln(EMPTY); - phpdbg_writeln("Note: read only commands please !"); - phpdbg_help_footer(); - return SUCCESS; + phpdbg_writeln("Note: read only commands please !"); + phpdbg_help_footer(); + return SUCCESS; } /* }}} */ PHPDBG_HELP(options) /* {{{ */ diff --git a/phpdbg_help.h b/phpdbg_help.h index 7a50b4ddd3..dea766dfaa 100644 --- a/phpdbg_help.h +++ b/phpdbg_help.h @@ -58,33 +58,33 @@ PHPDBG_HELP(shell); */ static const phpdbg_command_t phpdbg_help_commands[] = { PHPDBG_COMMAND_D_EX(exec, "the execution context should be a valid path", 'e', help_exec, NULL, 0), - PHPDBG_COMMAND_D_EX(compile, "allow inspection of code before execution", 'c', help_compile, NULL, 0), - PHPDBG_COMMAND_D_EX(step, "step through execution to break at every opcode", 's', help_step, NULL, 0), + PHPDBG_COMMAND_D_EX(compile, "allow inspection of code before execution", 'c', help_compile, NULL, 0), + PHPDBG_COMMAND_D_EX(step, "step through execution to break at every opcode", 's', help_step, NULL, 0), PHPDBG_COMMAND_D_EX(next, "continue executing while stepping or after breaking", 'n', help_next, NULL, 0), - PHPDBG_COMMAND_D_EX(run, "execute inside the phpdbg vm", 'r', help_run, NULL, 0), - PHPDBG_COMMAND_D_EX(eval, "access to eval() allows affecting the environment", 'E', help_eval, NULL, 0), - PHPDBG_COMMAND_D_EX(until, "continue until the current line is executed", 'u', help_until, NULL, 0), + PHPDBG_COMMAND_D_EX(run, "execute inside the phpdbg vm", 'r', help_run, NULL, 0), + PHPDBG_COMMAND_D_EX(eval, "access to eval() allows affecting the environment", 'E', help_eval, NULL, 0), + PHPDBG_COMMAND_D_EX(until, "continue until the current line is executed", 'u', help_until, NULL, 0), PHPDBG_COMMAND_D_EX(finish, "continue until the current function has returned", 'F', help_finish, NULL, 0), PHPDBG_COMMAND_D_EX(leave, "continue until the current function is returning", 'L', help_leave, NULL, 0), - PHPDBG_COMMAND_D_EX(print, "print context information or instructions", 'p', help_print, NULL, 0), + PHPDBG_COMMAND_D_EX(print, "print context information or instructions", 'p', help_print, NULL, 0), PHPDBG_COMMAND_D_EX(break, "breakpoints allow execution interruption", 'b', help_break, NULL, 0), - PHPDBG_COMMAND_D_EX(clean, "resetting the environment is useful while debugging", 'X', help_clean, NULL, 0), - PHPDBG_COMMAND_D_EX(clear, "reset breakpoints to execute without interruption", 'c', help_clear, NULL, 0), + PHPDBG_COMMAND_D_EX(clean, "resetting the environment is useful while debugging", 'X', help_clean, NULL, 0), + PHPDBG_COMMAND_D_EX(clear, "reset breakpoints to execute without interruption", 'c', help_clear, NULL, 0), PHPDBG_COMMAND_D_EX(info, "quick access to useful information on the console", 'i', help_info, NULL, 0), PHPDBG_COMMAND_D_EX(back, "show debug backtrace information during execution", 't', help_back, NULL, 0), PHPDBG_COMMAND_D_EX(frame, "switch to a frame in the current stack for inspection", 'f', help_frame, NULL, 0), - PHPDBG_COMMAND_D_EX(quiet, "be quiet during execution", 'Q', help_quiet, NULL, 0), - PHPDBG_COMMAND_D_EX(list, "list code gives you quick access to code", 'l', help_list, NULL, 0), - PHPDBG_COMMAND_D_EX(set, "configure how phpdbg looks and behaves", 'S', help_set, NULL, 0), - PHPDBG_COMMAND_D_EX(register, "register a function for use as a command", 'R', help_register,NULL, 0), - PHPDBG_COMMAND_D_EX(options, "show information about command line options", 'o', help_options, NULL, 0), - PHPDBG_COMMAND_D_EX(source, "load a phpdbginit file at the console", '.', help_source, NULL, 0), - PHPDBG_COMMAND_D_EX(shell, "execute system commands with direct shell access", '-', help_shell, NULL, 0), + PHPDBG_COMMAND_D_EX(quiet, "be quiet during execution", 'Q', help_quiet, NULL, 0), + PHPDBG_COMMAND_D_EX(list, "list code gives you quick access to code", 'l', help_list, NULL, 0), + PHPDBG_COMMAND_D_EX(set, "configure how phpdbg looks and behaves", 'S', help_set, NULL, 0), + PHPDBG_COMMAND_D_EX(register, "register a function for use as a command", 'R', help_register,NULL, 0), + PHPDBG_COMMAND_D_EX(options, "show information about command line options", 'o', help_options, NULL, 0), + PHPDBG_COMMAND_D_EX(source, "load a phpdbginit file at the console", '.', help_source, NULL, 0), + PHPDBG_COMMAND_D_EX(shell, "execute system commands with direct shell access", '-', help_shell, NULL, 0), PHPDBG_END_COMMAND }; #define phpdbg_help_header() \ - phpdbg_notice("Welcome to phpdbg, the interactive PHP debugger, v%s", PHPDBG_VERSION); + phpdbg_notice("Welcome to phpdbg, the interactive PHP debugger, v%s", PHPDBG_VERSION); #define phpdbg_help_footer() \ phpdbg_notice("Please report bugs to <%s>", PHPDBG_ISSUES); diff --git a/phpdbg_info.c b/phpdbg_info.c index 721778d638..727e676778 100644 --- a/phpdbg_info.c +++ b/phpdbg_info.c @@ -39,8 +39,8 @@ PHPDBG_INFO(break) /* {{{ */ PHPDBG_INFO(files) /* {{{ */ { - HashPosition pos; - char *fname; + HashPosition pos; + char *fname; phpdbg_notice("Included files: %d", zend_hash_num_elements(&EG(included_files))); @@ -226,9 +226,9 @@ static inline void phpdbg_print_class_name(zend_class_entry **ce TSRMLS_DC) /* { "%s %s %s (%d)", ((*ce)->type == ZEND_USER_CLASS) ? "User" : "Internal", - ((*ce)->ce_flags & ZEND_ACC_INTERFACE) ? + ((*ce)->ce_flags & ZEND_ACC_INTERFACE) ? "Interface" : - ((*ce)->ce_flags & ZEND_ACC_ABSTRACT) ? + ((*ce)->ce_flags & ZEND_ACC_ABSTRACT) ? "Abstract Class" : "Class", (*ce)->name, zend_hash_num_elements(&(*ce)->function_table)); @@ -236,7 +236,7 @@ static inline void phpdbg_print_class_name(zend_class_entry **ce TSRMLS_DC) /* { PHPDBG_INFO(classes) /* {{{ */ { - HashPosition position; + HashPosition position; zend_class_entry **ce; HashTable classes; @@ -246,10 +246,10 @@ PHPDBG_INFO(classes) /* {{{ */ zend_hash_get_current_data_ex(EG(class_table), (void**)&ce, &position) == SUCCESS; zend_hash_move_forward_ex(EG(class_table), &position)) { - if ((*ce)->type == ZEND_USER_CLASS) { - zend_hash_next_index_insert( - &classes, ce, sizeof(ce), NULL); - } + if ((*ce)->type == ZEND_USER_CLASS) { + zend_hash_next_index_insert( + &classes, ce, sizeof(ce), NULL); + } } phpdbg_notice("User Classes (%d)", @@ -271,13 +271,15 @@ PHPDBG_INFO(classes) /* {{{ */ } while ((pce = pce->parent)); } - if ((*ce)->info.user.filename) { - phpdbg_writeln( - "|---- in %s on line %u", - (*ce)->info.user.filename, - (*ce)->info.user.line_start); - } else phpdbg_writeln("|---- no source code"); - phpdbg_writeln(EMPTY); + if ((*ce)->info.user.filename) { + phpdbg_writeln( + "|---- in %s on line %u", + (*ce)->info.user.filename, + (*ce)->info.user.line_start); + } else { + phpdbg_writeln("|---- no source code"); + } + phpdbg_writeln(EMPTY); } zend_hash_destroy(&classes); @@ -287,7 +289,7 @@ PHPDBG_INFO(classes) /* {{{ */ PHPDBG_INFO(funcs) /* {{{ */ { - HashPosition position; + HashPosition position; zend_function *zf, **pzf; HashTable functions; @@ -297,10 +299,10 @@ PHPDBG_INFO(funcs) /* {{{ */ zend_hash_get_current_data_ex(EG(function_table), (void**)&zf, &position) == SUCCESS; zend_hash_move_forward_ex(EG(function_table), &position)) { - if (zf->type == ZEND_USER_FUNCTION) { - zend_hash_next_index_insert( - &functions, (void**) &zf, sizeof(zend_function), NULL); - } + if (zf->type == ZEND_USER_FUNCTION) { + zend_hash_next_index_insert( + &functions, (void**) &zf, sizeof(zend_function), NULL); + } } phpdbg_notice("User Functions (%d)", diff --git a/phpdbg_info.h b/phpdbg_info.h index 23fcae6902..8b0f117818 100644 --- a/phpdbg_info.h +++ b/phpdbg_info.h @@ -33,14 +33,14 @@ PHPDBG_INFO(vars); PHPDBG_INFO(literal); static const phpdbg_command_t phpdbg_info_commands[] = { - PHPDBG_COMMAND_D_EX(break, "show breakpoints", 'b', info_break, NULL, 0), - PHPDBG_COMMAND_D_EX(files, "lists included files", 'F', info_files, NULL, 0), - PHPDBG_COMMAND_D_EX(classes, "lists loaded classes", 'c', info_classes, NULL, 0), - PHPDBG_COMMAND_D_EX(funcs, "lists loaded classes", 'f', info_funcs, NULL, 0), - PHPDBG_COMMAND_D_EX(error, "show the last error", 'e', info_error, NULL, 0), - PHPDBG_COMMAND_D_EX(vars, "show active variables", 'v', info_vars, NULL, 0), - PHPDBG_COMMAND_D_EX(literal, "show active literal constants", 'l', info_literal, NULL, 0), - PHPDBG_END_COMMAND + PHPDBG_COMMAND_D_EX(break, "show breakpoints", 'b', info_break, NULL, 0), + PHPDBG_COMMAND_D_EX(files, "lists included files", 'F', info_files, NULL, 0), + PHPDBG_COMMAND_D_EX(classes, "lists loaded classes", 'c', info_classes, NULL, 0), + PHPDBG_COMMAND_D_EX(funcs, "lists loaded classes", 'f', info_funcs, NULL, 0), + PHPDBG_COMMAND_D_EX(error, "show the last error", 'e', info_error, NULL, 0), + PHPDBG_COMMAND_D_EX(vars, "show active variables", 'v', info_vars, NULL, 0), + PHPDBG_COMMAND_D_EX(literal, "show active literal constants", 'l', info_literal, NULL, 0), + PHPDBG_END_COMMAND }; #endif /* PHPDBG_INFO_H */ diff --git a/phpdbg_list.c b/phpdbg_list.c index 05231bcf97..e1ebafc7cd 100644 --- a/phpdbg_list.c +++ b/phpdbg_list.c @@ -53,82 +53,80 @@ PHPDBG_LIST(lines) /* {{{ */ phpdbg_default_switch_case(); } - return SUCCESS; + return SUCCESS; } /* }}} */ PHPDBG_LIST(func) /* {{{ */ { - switch (param->type) { - case STR_PARAM: - phpdbg_list_function_byname( - param->str, param->len TSRMLS_CC); - break; + switch (param->type) { + case STR_PARAM: + phpdbg_list_function_byname( + param->str, param->len TSRMLS_CC); + break; - phpdbg_default_switch_case(); - } + phpdbg_default_switch_case(); + } - return SUCCESS; + return SUCCESS; } /* }}} */ PHPDBG_LIST(method) /* {{{ */ { - 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); - } else { - phpdbg_error("Could not find %s::%s", param->method.class, param->method.name); - } - - efree(lcname); - } else { - phpdbg_error("Could not find the class %s", param->method.class); - } - } break; - - phpdbg_default_switch_case(); - } - - return SUCCESS; + 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); + } else { + phpdbg_error("Could not find %s::%s", param->method.class, param->method.name); + } + + efree(lcname); + } else { + phpdbg_error("Could not find the class %s", param->method.class); + } + } break; + + phpdbg_default_switch_case(); + } + + return SUCCESS; } /* }}} */ PHPDBG_LIST(class) /* {{{ */ { - 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 class requested (%s) is not user defined", (*ce)->name); - } - } else { - phpdbg_error("The requested class (%s) could not be found", param->str); - } - } break; - - phpdbg_default_switch_case(); - } - - return SUCCESS; + 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 class requested (%s) is not user defined", (*ce)->name); + } + } else { + phpdbg_error("The requested class (%s) could not be found", param->str); + } + } break; + + phpdbg_default_switch_case(); + } + + return SUCCESS; } /* }}} */ void phpdbg_list_file(const char *filename, long count, long offset, int highlight TSRMLS_DC) /* {{{ */ @@ -143,7 +141,7 @@ void phpdbg_list_file(const char *filename, long count, long offset, int highlig int all_content = (count == 0); int line = 0, displayed = 0; - if (VCWD_STAT(filename, &st) == FAILURE) { + if (VCWD_STAT(filename, &st) == FAILURE) { phpdbg_error("Failed to stat file %s", filename); return; } @@ -197,11 +195,13 @@ void phpdbg_list_file(const char *filename, long count, long offset, int highlig if (!offset || offset <= line) { /* Without offset, or offset reached */ if (!highlight) { - phpdbg_writeln("%05u: %.*s", line, (int)(pos - last_pos), last_pos); + 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); + 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; } @@ -229,8 +229,7 @@ void phpdbg_list_function(const zend_function *fbc TSRMLS_DC) /* {{{ */ const zend_op_array *ops; if (fbc->type != ZEND_USER_FUNCTION) { - phpdbg_error( - "The function requested (%s) is not user defined", fbc->common.function_name); + phpdbg_error("The function requested (%s) is not user defined", fbc->common.function_name); return; } @@ -242,39 +241,38 @@ void phpdbg_list_function(const zend_function *fbc TSRMLS_DC) /* {{{ */ 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); + 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 --git a/phpdbg_list.h b/phpdbg_list.h index 19a015105f..f9d9d20d39 100644 --- a/phpdbg_list.h +++ b/phpdbg_list.h @@ -36,11 +36,11 @@ void phpdbg_list_function(const zend_function* TSRMLS_DC); void phpdbg_list_file(const char*, long, long, int TSRMLS_DC); static const phpdbg_command_t phpdbg_list_commands[] = { - PHPDBG_COMMAND_D_EX(lines, "lists the specified lines", 'l', list_lines, NULL, 1), - PHPDBG_COMMAND_D_EX(class, "lists the specified class", 'c', list_class, NULL, 1), - PHPDBG_COMMAND_D_EX(method, "lists the specified method", 'm', list_method, NULL, 1), - PHPDBG_COMMAND_D_EX(func, "lists the specified function", 'f', list_func, NULL, 1), - PHPDBG_END_COMMAND + PHPDBG_COMMAND_D_EX(lines, "lists the specified lines", 'l', list_lines, NULL, 1), + PHPDBG_COMMAND_D_EX(class, "lists the specified class", 'c', list_class, NULL, 1), + PHPDBG_COMMAND_D_EX(method, "lists the specified method", 'm', list_method, NULL, 1), + PHPDBG_COMMAND_D_EX(func, "lists the specified function", 'f', list_func, NULL, 1), + PHPDBG_END_COMMAND }; #endif /* PHPDBG_LIST_H */ diff --git a/phpdbg_opcode.c b/phpdbg_opcode.c index 55816e7c87..6ad4a5c039 100644 --- a/phpdbg_opcode.c +++ b/phpdbg_opcode.c @@ -104,10 +104,10 @@ char *phpdbg_decode_opline(zend_op_array *ops, zend_op *op, HashTable *vars TSRM #ifdef ZEND_JMP_SET_VAR case ZEND_JMP_SET_VAR: #endif - decode[1] = phpdbg_decode_op(ops, &op->op1, op->op1_type, vars TSRMLS_CC); - asprintf( - &decode[2], "J%lu", op->op2.jmp_addr - ops->opcodes); - goto result; + decode[1] = phpdbg_decode_op(ops, &op->op1, op->op1_type, vars TSRMLS_CC); + asprintf( + &decode[2], "J%lu", op->op2.jmp_addr - ops->opcodes); + goto result; case ZEND_RECV_INIT: goto result; @@ -139,7 +139,7 @@ format: void phpdbg_print_opline_ex(zend_execute_data *execute_data, HashTable *vars, zend_bool ignore_flags TSRMLS_DC) /* {{{ */ { - /* force out a line while stepping so the user knows what is happening */ + /* force out a line while stepping so the user knows what is happening */ if (ignore_flags || (!(PHPDBG_G(flags) & PHPDBG_IS_QUIET) || (PHPDBG_G(flags) & PHPDBG_IS_STEPPING) || @@ -148,9 +148,7 @@ void phpdbg_print_opline_ex(zend_execute_data *execute_data, HashTable *vars, ze zend_op *opline = execute_data->opline; char *decode = phpdbg_decode_opline(execute_data->op_array, opline, vars TSRMLS_CC); - if (ignore_flags || - (!(PHPDBG_G(flags) & PHPDBG_IS_QUIET) || - (PHPDBG_G(flags) & PHPDBG_IS_STEPPING))) { + if (ignore_flags || (!(PHPDBG_G(flags) & PHPDBG_IS_QUIET) || (PHPDBG_G(flags) & PHPDBG_IS_STEPPING))) { /* output line info */ phpdbg_notice("L%-5u %16p %-30s %s %s", opline->lineno, @@ -158,7 +156,7 @@ void phpdbg_print_opline_ex(zend_execute_data *execute_data, HashTable *vars, ze phpdbg_decode_opcode(opline->opcode), decode, execute_data->op_array->filename ? execute_data->op_array->filename : "unknown"); - } + } if (!ignore_flags && PHPDBG_G(oplog)) { phpdbg_log_ex(PHPDBG_G(oplog), "L%-5u %16p %-30s %s %s", @@ -172,7 +170,7 @@ void phpdbg_print_opline_ex(zend_execute_data *execute_data, HashTable *vars, ze if (decode) { free(decode); } - } + } } /* }}} */ void phpdbg_print_opline(zend_execute_data *execute_data, zend_bool ignore_flags TSRMLS_DC) /* {{{ */ @@ -344,7 +342,7 @@ const char *phpdbg_decode_opcode(zend_uchar opcode) /* {{{ */ CASE(ZEND_YIELD); #endif #ifdef ZEND_GENERATOR_RETURN - CASE(ZEND_GENERATOR_RETURN); + CASE(ZEND_GENERATOR_RETURN); #endif #ifdef ZEND_FAST_CALL CASE(ZEND_FAST_CALL); @@ -357,6 +355,6 @@ const char *phpdbg_decode_opcode(zend_uchar opcode) /* {{{ */ #endif CASE(ZEND_OP_DATA); default: - return "UNKNOWN"; + return "UNKNOWN"; } } /* }}} */ diff --git a/phpdbg_print.c b/phpdbg_print.c index 4170059de2..859ac0ae60 100644 --- a/phpdbg_print.c +++ b/phpdbg_print.c @@ -28,8 +28,7 @@ ZEND_EXTERN_MODULE_GLOBALS(phpdbg); PHPDBG_PRINT(opline) /* {{{ */ { if (EG(in_execution) && EG(current_execute_data)) { - phpdbg_print_opline( - EG(current_execute_data), 1 TSRMLS_CC); + phpdbg_print_opline(EG(current_execute_data), 1 TSRMLS_CC); } else { phpdbg_error("Not Executing!"); } @@ -39,149 +38,138 @@ PHPDBG_PRINT(opline) /* {{{ */ static inline void phpdbg_print_function_helper(zend_function *method TSRMLS_DC) /* {{{ */ { - switch (method->type) { - case ZEND_USER_FUNCTION: { - zend_op_array* op_array = &(method->op_array); + switch (method->type) { + case ZEND_USER_FUNCTION: { + zend_op_array* op_array = &(method->op_array); HashTable vars; - if (op_array) { - zend_op *opline = &(op_array->opcodes[0]); - zend_uint opcode = 0, - end = op_array->last-1; - - if (method->common.scope) { - phpdbg_writeln( - "\tL%d-%d %s::%s() %s", - op_array->line_start, op_array->line_end, - method->common.scope->name, - method->common.function_name, - op_array->filename ? op_array->filename : "unknown"); - } else { - phpdbg_writeln( - "\tL%d-%d %s() %s", - method->common.function_name ? op_array->line_start : 0, - method->common.function_name ? op_array->line_end : 0, - method->common.function_name ? method->common.function_name : "{main}", - op_array->filename ? op_array->filename : "unknown"); - } + if (op_array) { + zend_op *opline = &(op_array->opcodes[0]); + zend_uint opcode = 0, + end = op_array->last-1; + + if (method->common.scope) { + phpdbg_writeln("\tL%d-%d %s::%s() %s", + op_array->line_start, op_array->line_end, + method->common.scope->name, + method->common.function_name, + op_array->filename ? op_array->filename : "unknown"); + } else { + phpdbg_writeln("\tL%d-%d %s() %s", + method->common.function_name ? op_array->line_start : 0, + method->common.function_name ? op_array->line_end : 0, + method->common.function_name ? method->common.function_name : "{main}", + op_array->filename ? op_array->filename : "unknown"); + } zend_hash_init(&vars, op_array->last, NULL, NULL, 0); - do { - char *decode = phpdbg_decode_opline(op_array, opline, &vars TSRMLS_CC); - if (decode != NULL) { - phpdbg_writeln( - "\t\tL%u\t%p %-30s %s", - opline->lineno, - opline, - phpdbg_decode_opcode(opline->opcode), - decode); - } else phpdbg_error("\tFailed to decode opline %16p", opline); - free(decode); - opline++; - } while (++opcode < end); - zend_hash_destroy(&vars); - } - } break; - - default: { - if (method->common.scope) { - phpdbg_writeln( - "\tInternal %s::%s()", method->common.scope->name, method->common.function_name); - } else { - phpdbg_writeln( - "\tInternal %s()", method->common.function_name); - } - } - } + do { + char *decode = phpdbg_decode_opline(op_array, opline, &vars TSRMLS_CC); + if (decode != NULL) { + phpdbg_writeln("\t\tL%u\t%p %-30s %s", + opline->lineno, + opline, + phpdbg_decode_opcode(opline->opcode), + decode); + free(decode); + } else { + phpdbg_error("\tFailed to decode opline %16p", opline); + } + opline++; + } while (++opcode < end); + zend_hash_destroy(&vars); + } + } break; + + default: { + if (method->common.scope) { + phpdbg_writeln("\tInternal %s::%s()", method->common.scope->name, method->common.function_name); + } else { + phpdbg_writeln("\tInternal %s()", method->common.function_name); + } + } + } } /* }}} */ 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; + 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(stack) /* {{{ */ { zend_op_array *ops = EG(active_op_array); - if (EG(in_execution) && ops) { - if (ops->function_name) { + if (EG(in_execution) && ops) { + if (ops->function_name) { if (ops->scope) { - phpdbg_notice( - "Stack in %s::%s()", ops->scope->name, ops->function_name); + phpdbg_notice("Stack in %s::%s()", ops->scope->name, ops->function_name); } else { - phpdbg_notice( - "Stack in %s()", ops->function_name); + phpdbg_notice("Stack in %s()", ops->function_name); } } else { if (ops->filename) { - phpdbg_notice( - "Stack in %s", ops->filename); + phpdbg_notice("Stack in %s", ops->filename); } else { - phpdbg_notice( - "Stack @ %p", ops); + phpdbg_notice("Stack @ %p", ops); } } - phpdbg_print_function_helper( - (zend_function*) ops TSRMLS_CC); - } else { - phpdbg_error("Not Executing!"); - } + phpdbg_print_function_helper((zend_function*) ops TSRMLS_CC); + } else { + phpdbg_error("Not Executing!"); + } - return SUCCESS; + return SUCCESS; } /* }}} */ PHPDBG_PRINT(class) /* {{{ */ { - zend_class_entry **ce; + zend_class_entry **ce; 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); - - 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); - } - } break; - - phpdbg_default_switch_case(); + 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); + + 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); + } + } break; + + phpdbg_default_switch_case(); } return SUCCESS; @@ -189,87 +177,81 @@ PHPDBG_PRINT(class) /* {{{ */ PHPDBG_PRINT(method) /* {{{ */ { - 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 *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 class %s could not be found", param->method.class); - } - } break; - - phpdbg_default_switch_case(); - } - - return SUCCESS; + 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 *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 class %s could not be found", param->method.class); + } + } break; + + phpdbg_default_switch_case(); + } + + return SUCCESS; } /* }}} */ PHPDBG_PRINT(func) /* {{{ */ { - 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); - } - - 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; - - phpdbg_default_switch_case(); - } - - return SUCCESS; + 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); + } + + 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; + + phpdbg_default_switch_case(); + } + + return SUCCESS; } /* }}} */ diff --git a/phpdbg_prompt.c b/phpdbg_prompt.c index c703bd42c6..009d19c8d0 100644 --- a/phpdbg_prompt.c +++ b/phpdbg_prompt.c @@ -38,7 +38,7 @@ /* {{{ command declarations */ const phpdbg_command_t phpdbg_prompt_commands[] = { PHPDBG_COMMAND_D(exec, "set execution context", 'e', NULL, 1), - PHPDBG_COMMAND_D(compile, "attempt compilation", 'c', NULL, 0), + PHPDBG_COMMAND_D(compile, "attempt compilation", 'c', NULL, 0), PHPDBG_COMMAND_D(step, "step through execution", 's', NULL, 1), PHPDBG_COMMAND_D(next, "continue execution", 'n', NULL, 0), PHPDBG_COMMAND_D(run, "attempt execution", 'r', NULL, 0), @@ -195,22 +195,21 @@ PHPDBG_COMMAND(exec) /* {{{ */ { switch (param->type) { case STR_PARAM: { - struct stat sb; + struct stat sb; - if (VCWD_STAT(param->str, &sb) != FAILURE) { - if (sb.st_mode & (S_IFREG|S_IFLNK)) { - char *res = phpdbg_resolve_path(param->str TSRMLS_CC); - size_t res_len = strlen(res); + if (VCWD_STAT(param->str, &sb) != FAILURE) { + if (sb.st_mode & (S_IFREG|S_IFLNK)) { + char *res = phpdbg_resolve_path(param->str TSRMLS_CC); + size_t res_len = strlen(res); - if ((res_len != PHPDBG_G(exec_len)) || - (memcmp(res, PHPDBG_G(exec), res_len) != SUCCESS)) { + if ((res_len != PHPDBG_G(exec_len)) || (memcmp(res, PHPDBG_G(exec), res_len) != SUCCESS)) { - 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_len) = 0L; - } + 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_len) = 0L; + } if (PHPDBG_G(ops)) { phpdbg_notice("Destroying compiled opcodes"); @@ -221,9 +220,9 @@ PHPDBG_COMMAND(exec) /* {{{ */ PHPDBG_G(exec_len) = res_len; phpdbg_notice("Set execution context: %s", PHPDBG_G(exec)); - } else { - phpdbg_notice("Execution context not changed"); - } + } else { + phpdbg_notice("Execution context not changed"); + } } else { phpdbg_error("Cannot use %s as execution context, not a valid file or symlink", param->str); } @@ -548,7 +547,7 @@ PHPDBG_COMMAND(run) /* {{{ */ { if (EG(in_execution)) { phpdbg_error("Cannot start another execution while one is in progress"); - return SUCCESS; + return SUCCESS; } if (PHPDBG_G(ops) || PHPDBG_G(exec)) { @@ -558,17 +557,16 @@ PHPDBG_COMMAND(run) /* {{{ */ if (!PHPDBG_G(ops)) { if (phpdbg_compile(TSRMLS_C) == FAILURE) { - phpdbg_error( - "Failed to compile %s, cannot run", PHPDBG_G(exec)); + phpdbg_error("Failed to compile %s, cannot run", PHPDBG_G(exec)); goto out; } } EG(active_op_array) = PHPDBG_G(ops); EG(return_value_ptr_ptr) = &PHPDBG_G(retval); - if (!EG(active_symbol_table)) { - zend_rebuild_symbol_table(TSRMLS_C); - } + if (!EG(active_symbol_table)) { + zend_rebuild_symbol_table(TSRMLS_C); + } /* clean seek state */ PHPDBG_G(flags) &= ~PHPDBG_SEEK_MASK; @@ -578,14 +576,13 @@ PHPDBG_COMMAND(run) /* {{{ */ zend_try { php_output_activate(TSRMLS_C); PHPDBG_G(flags) ^= PHPDBG_IS_INTERACTIVE; - zend_execute( - EG(active_op_array) TSRMLS_CC); + zend_execute(EG(active_op_array) TSRMLS_CC); PHPDBG_G(flags) ^= PHPDBG_IS_INTERACTIVE; php_output_deactivate(TSRMLS_C); } zend_catch { - EG(active_op_array) = orig_op_array; - EG(opline_ptr) = orig_opline; - EG(return_value_ptr_ptr) = orig_retval_ptr; + EG(active_op_array) = orig_op_array; + EG(opline_ptr) = orig_opline; + EG(return_value_ptr_ptr) = orig_retval_ptr; if (!(PHPDBG_G(flags) & PHPDBG_IS_QUITTING)) { phpdbg_error("Caught exit/error from VM"); @@ -598,8 +595,8 @@ PHPDBG_COMMAND(run) /* {{{ */ } EG(active_op_array) = orig_op_array; - EG(opline_ptr) = orig_opline; - EG(return_value_ptr_ptr) = orig_retval_ptr; + EG(opline_ptr) = orig_opline; + EG(return_value_ptr_ptr) = orig_retval_ptr; } else { phpdbg_error("Nothing to execute!"); @@ -915,7 +912,7 @@ PHPDBG_COMMAND(register) /* {{{ */ PHPDBG_COMMAND(quit) /* {{{ */ { - /* don't allow this to loop, ever ... */ + /* don't allow this to loop, ever ... */ if (!(PHPDBG_G(flags) & PHPDBG_IS_QUITTING)) { phpdbg_destroy_input((phpdbg_input_t**)&input TSRMLS_CC); @@ -958,7 +955,7 @@ PHPDBG_COMMAND(clear) /* {{{ */ phpdbg_clear_breakpoints(TSRMLS_C); - return SUCCESS; + return SUCCESS; } /* }}} */ PHPDBG_COMMAND(aliases) /* {{{ */ @@ -996,8 +993,8 @@ PHPDBG_COMMAND(aliases) /* {{{ */ PHPDBG_COMMAND(help) /* {{{ */ { - switch (param->type) { - case EMPTY_PARAM: { + switch (param->type) { + case EMPTY_PARAM: { const phpdbg_command_t *prompt_command = phpdbg_prompt_commands; const phpdbg_command_t *help_command = phpdbg_help_commands; @@ -1047,28 +1044,28 @@ PHPDBG_COMMAND(quiet) /* {{{ */ phpdbg_default_switch_case(); } - return SUCCESS; + return SUCCESS; } /* }}} */ PHPDBG_COMMAND(list) /* {{{ */ { switch (param->type) { - case NUMERIC_PARAM: - case EMPTY_PARAM: + case NUMERIC_PARAM: + case EMPTY_PARAM: return PHPDBG_LIST_HANDLER(lines)(PHPDBG_COMMAND_ARGS); case FILE_PARAM: return PHPDBG_LIST_HANDLER(lines)(PHPDBG_COMMAND_ARGS); case STR_PARAM: - phpdbg_list_function_byname(param->str, param->len TSRMLS_CC); + phpdbg_list_function_byname(param->str, param->len TSRMLS_CC); break; case METHOD_PARAM: - return PHPDBG_LIST_HANDLER(method)(PHPDBG_COMMAND_ARGS); + return PHPDBG_LIST_HANDLER(method)(PHPDBG_COMMAND_ARGS); phpdbg_default_switch_case(); - } + } return SUCCESS; } /* }}} */ @@ -1215,7 +1212,7 @@ void phpdbg_clean(zend_bool full TSRMLS_DC) /* {{{ */ static inline zend_execute_data *phpdbg_create_execute_data(zend_op_array *op_array, zend_bool nested TSRMLS_DC) /* {{{ */ { #if PHP_VERSION_ID >= 50500 - return zend_create_execute_data_from_op_array(op_array, nested TSRMLS_CC); + return zend_create_execute_data_from_op_array(op_array, nested TSRMLS_CC); #else #undef EX @@ -1229,7 +1226,7 @@ static inline zend_execute_data *phpdbg_create_execute_data(zend_op_array *op_ar #undef EX_Ts #define EX_Ts() EX(Ts) - zend_execute_data *execute_data = (zend_execute_data *)zend_vm_stack_alloc( + zend_execute_data *execute_data = (zend_execute_data *)zend_vm_stack_alloc( ZEND_MM_ALIGNED_SIZE(sizeof(zend_execute_data)) + ZEND_MM_ALIGNED_SIZE(sizeof(zval**) * op_array->last_var * (EG(active_symbol_table) ? 1 : 2)) + ZEND_MM_ALIGNED_SIZE(sizeof(temp_variable)) * op_array->T TSRMLS_CC); @@ -1315,28 +1312,28 @@ zend_vm_enter: } #endif -#define DO_INTERACTIVE() do {\ - if (!(PHPDBG_G(flags) & PHPDBG_IN_EVAL)) {\ - phpdbg_list_file(\ +#define DO_INTERACTIVE() do { \ + if (!(PHPDBG_G(flags) & PHPDBG_IN_EVAL)) { \ + phpdbg_list_file( \ zend_get_executed_filename(TSRMLS_C), \ 3, \ zend_get_executed_lineno(TSRMLS_C)-1, \ zend_get_executed_lineno(TSRMLS_C) \ - TSRMLS_CC\ - );\ - }\ + TSRMLS_CC \ + ); \ + } \ \ - do {\ - switch (phpdbg_interactive(TSRMLS_C)) {\ - case PHPDBG_LEAVE:\ - case PHPDBG_FINISH:\ - case PHPDBG_UNTIL:\ - case PHPDBG_NEXT:{\ - goto next;\ - }\ - }\ - } while(!(PHPDBG_G(flags) & PHPDBG_IS_QUITTING));\ -} while(0) + do { \ + switch (phpdbg_interactive(TSRMLS_C)) { \ + case PHPDBG_LEAVE: \ + case PHPDBG_FINISH: \ + case PHPDBG_UNTIL: \ + case PHPDBG_NEXT:{ \ + goto next; \ + } \ + } \ + } while (!(PHPDBG_G(flags) & PHPDBG_IS_QUITTING)); \ +} while (0) /* allow conditional breakpoints and initialization to access the vm uninterrupted */ diff --git a/phpdbg_set.c b/phpdbg_set.c index a0f5e74a70..f7a32bbcf9 100644 --- a/phpdbg_set.c +++ b/phpdbg_set.c @@ -150,6 +150,6 @@ PHPDBG_SET(oplog) /* {{{ */ phpdbg_default_switch_case(); } - return SUCCESS; + return SUCCESS; } /* }}} */ diff --git a/phpdbg_set.h b/phpdbg_set.h index c3afc0674d..2fcc0d06b4 100644 --- a/phpdbg_set.h +++ b/phpdbg_set.h @@ -30,11 +30,11 @@ PHPDBG_SET(oplog); PHPDBG_SET(break); static const phpdbg_command_t phpdbg_set_commands[] = { - PHPDBG_COMMAND_D_EX(prompt, "usage: set prompt ", 'p', set_prompt, NULL, 0), - PHPDBG_COMMAND_D_EX(color, "usage: set color ", 'c', set_color, NULL, 1), - PHPDBG_COMMAND_D_EX(oplog, "usage: set oplog ", 'O', set_oplog, NULL, 0), - PHPDBG_COMMAND_D_EX(break, "usage: set break ", 'b', set_break, NULL, 0), - PHPDBG_END_COMMAND + PHPDBG_COMMAND_D_EX(prompt, "usage: set prompt ", 'p', set_prompt, NULL, 0), + PHPDBG_COMMAND_D_EX(color, "usage: set color ", 'c', set_color, NULL, 1), + PHPDBG_COMMAND_D_EX(oplog, "usage: set oplog ", 'O', set_oplog, NULL, 0), + PHPDBG_COMMAND_D_EX(break, "usage: set break ", 'b', set_break, NULL, 0), + PHPDBG_END_COMMAND }; #endif /* PHPDBG_SET_H */ diff --git a/phpdbg_utils.c b/phpdbg_utils.c index 5a922e8e53..f18bbb55fa 100644 --- a/phpdbg_utils.c +++ b/phpdbg_utils.c @@ -34,39 +34,39 @@ ZEND_EXTERN_MODULE_GLOBALS(phpdbg); /* {{{ color structures */ const static phpdbg_color_t colors[] = { - PHPDBG_COLOR_D("none", "0;0"), - - PHPDBG_COLOR_D("white", "0;64"), - PHPDBG_COLOR_D("white-bold", "1;64"), - PHPDBG_COLOR_D("white-underline", "4;64"), - PHPDBG_COLOR_D("red", "0;31"), - PHPDBG_COLOR_D("red-bold", "1;31"), - PHPDBG_COLOR_D("red-underline", "4;31"), - PHPDBG_COLOR_D("green", "0;32"), - PHPDBG_COLOR_D("green-bold", "1;32"), - PHPDBG_COLOR_D("green-underline", "4;32"), - PHPDBG_COLOR_D("yellow", "0;33"), - PHPDBG_COLOR_D("yellow-bold", "1;33"), - PHPDBG_COLOR_D("yellow-underline", "4;33"), - PHPDBG_COLOR_D("blue", "0;34"), - PHPDBG_COLOR_D("blue-bold", "1;34"), - PHPDBG_COLOR_D("blue-underline", "4;34"), - PHPDBG_COLOR_D("purple", "0;35"), - PHPDBG_COLOR_D("purple-bold", "1;35"), - PHPDBG_COLOR_D("purple-underline", "4;35"), - PHPDBG_COLOR_D("cyan", "0;36"), - PHPDBG_COLOR_D("cyan-bold", "1;36"), - PHPDBG_COLOR_D("cyan-underline", "4;36"), - PHPDBG_COLOR_D("black", "0;30"), - PHPDBG_COLOR_D("black-bold", "1;30"), - PHPDBG_COLOR_D("black-underline", "4;30"), + PHPDBG_COLOR_D("none", "0;0"), + + PHPDBG_COLOR_D("white", "0;64"), + PHPDBG_COLOR_D("white-bold", "1;64"), + PHPDBG_COLOR_D("white-underline", "4;64"), + PHPDBG_COLOR_D("red", "0;31"), + PHPDBG_COLOR_D("red-bold", "1;31"), + PHPDBG_COLOR_D("red-underline", "4;31"), + PHPDBG_COLOR_D("green", "0;32"), + PHPDBG_COLOR_D("green-bold", "1;32"), + PHPDBG_COLOR_D("green-underline", "4;32"), + PHPDBG_COLOR_D("yellow", "0;33"), + PHPDBG_COLOR_D("yellow-bold", "1;33"), + PHPDBG_COLOR_D("yellow-underline", "4;33"), + PHPDBG_COLOR_D("blue", "0;34"), + PHPDBG_COLOR_D("blue-bold", "1;34"), + PHPDBG_COLOR_D("blue-underline", "4;34"), + PHPDBG_COLOR_D("purple", "0;35"), + PHPDBG_COLOR_D("purple-bold", "1;35"), + PHPDBG_COLOR_D("purple-underline", "4;35"), + PHPDBG_COLOR_D("cyan", "0;36"), + PHPDBG_COLOR_D("cyan-bold", "1;36"), + PHPDBG_COLOR_D("cyan-underline", "4;36"), + PHPDBG_COLOR_D("black", "0;30"), + PHPDBG_COLOR_D("black-bold", "1;30"), + PHPDBG_COLOR_D("black-underline", "4;30"), PHPDBG_COLOR_END }; /* }}} */ PHPDBG_API int phpdbg_is_numeric(const char *str) /* {{{ */ { - if (!str) - return 0; + if (!str) + return 0; for (; *str; str++) { if (isspace(*str) || *str == '-') { @@ -79,8 +79,8 @@ PHPDBG_API int phpdbg_is_numeric(const char *str) /* {{{ */ PHPDBG_API int phpdbg_is_empty(const char *str) /* {{{ */ { - if (!str) - return 1; + if (!str) + return 1; for (; *str; str++) { if (isspace(*str)) { @@ -100,8 +100,8 @@ PHPDBG_API int phpdbg_is_class_method(const char *str, size_t len, char **class, { char *sep = NULL; - if (strstr(str, " ") != NULL) - return 0; + if (strstr(str, " ") != NULL) + return 0; sep = strstr(str, "::"); @@ -110,13 +110,12 @@ PHPDBG_API int phpdbg_is_class_method(const char *str, size_t len, char **class, } if (class != NULL) { - *class = estrndup(str, sep - str); - (*class)[sep - str] = 0; + *class = estrndup(str, sep - str); + (*class)[sep - str] = 0; } if (method != NULL) { - *method = estrndup( - sep+2, str + len - (sep + 2)); + *method = estrndup(sep+2, str + len - (sep + 2)); } return 1; @@ -176,17 +175,17 @@ PHPDBG_API char *phpdbg_trim(const char *str, size_t len, size_t *new_len) /* {{ PHPDBG_API int phpdbg_print(int type TSRMLS_DC, FILE *fp, const char *format, ...) /* {{{ */ { - int rc = 0; + int rc = 0; char *buffer = NULL; va_list args; if (format != NULL && strlen(format) > 0L) { - va_start(args, format); - vspprintf(&buffer, 0, format, args); - va_end(args); + va_start(args, format); + vspprintf(&buffer, 0, format, args); + va_end(args); } - /* TODO(anyone) colours */ + /* TODO(anyone) colours */ switch (type) { case P_ERROR: @@ -210,25 +209,30 @@ PHPDBG_API int phpdbg_print(int type TSRMLS_DC, FILE *fp, const char *format, .. break; case P_WRITELN: { - if (buffer) { - rc = fprintf(fp, "%s\n", buffer); + if (buffer) { + rc = fprintf(fp, "%s\n", buffer); } else { - rc = fprintf(fp, "\n"); + rc = fprintf(fp, "\n"); } } break; - case P_WRITE: if (buffer) { - rc = fprintf(fp, "%s", buffer); - } break; + case P_WRITE: + if (buffer) { + rc = fprintf(fp, "%s", buffer); + } + break; /* no formatting on logging output */ - case P_LOG: if (buffer) { - struct timeval tp; - if (gettimeofday(&tp, NULL) == SUCCESS) { - rc = fprintf( - fp, "[%ld %.8F]: %s\n", tp.tv_sec, tp.tv_usec / 1000000.00, buffer); - } else rc = FAILURE; - } break; + case P_LOG: + if (buffer) { + struct timeval tp; + if (gettimeofday(&tp, NULL) == SUCCESS) { + rc = fprintf(fp, "[%ld %.8F]: %s\n", tp.tv_sec, tp.tv_usec / 1000000.00, buffer); + } else { + rc = FAILURE; + } + } + break; } if (buffer) { diff --git a/phpdbg_utils.h b/phpdbg_utils.h index e9c35d102d..eb44d7c8f8 100644 --- a/phpdbg_utils.h +++ b/phpdbg_utils.h @@ -61,9 +61,9 @@ PHPDBG_API int phpdbg_print(int TSRMLS_DC, FILE*, const char*, ...) PHP_ATTRIBUT #define phpdbg_log_ex(out, fmt, ...) phpdbg_print(P_LOG TSRMLS_CC, out, fmt, ##__VA_ARGS__) #if PHPDBG_DEBUG -# define phpdbg_debug(fmt, ...) phpdbg_print(P_LOG TSRMLS_CC, PHPDBG_G(io)[PHPDBG_STDERR], fmt, ##__VA_ARGS__) +# define phpdbg_debug(fmt, ...) phpdbg_print(P_LOG TSRMLS_CC, PHPDBG_G(io)[PHPDBG_STDERR], fmt, ##__VA_ARGS__) #else -# define phpdbg_debug(fmt, ...) +# define phpdbg_debug(fmt, ...) #endif /* {{{ For writing blank lines */ @@ -89,9 +89,9 @@ PHPDBG_API int phpdbg_print(int TSRMLS_DC, FILE*, const char*, ...) PHP_ATTRIBUT #define PHPDBG_COLORS 3 typedef struct _phpdbg_color_t { - char *name; - size_t name_length; - const char code[PHPDBG_COLOR_LEN]; + char *name; + size_t name_length; + const char code[PHPDBG_COLOR_LEN]; } phpdbg_color_t; PHPDBG_API const phpdbg_color_t *phpdbg_get_color(const char *name, size_t name_length TSRMLS_DC);