com php-src: Merge remote-tracking branch 'origin/PHP-5.6' into str_size_and_int64_56_backport: ext/date/ php_date.c ext/phar/phar_path_check.c
ext/standar d/url.c main/php_variables.c main/php_variables.h sapi/litespeed/lsapi_main.c sapi/phpdbg/phpdbg.c s api/phpdbg/phpdbg.h
sapi/phpdbg/phpdbg_bp.c sapi/phpd bg/phpdbg_bp.h sapi/phpdbg/phpdbg_cmd.c sapi/phpdbg /phpdbg_cmd.h sapi/phpdbg/phpdbg_frame.c sapi/phpdb
g/phpdbg_info.c sapi/phpdbg/phpdbg_list.c
| From: | Anatol Belski | Date: | Fri, 25 Apr 2014 17:49:10 +0000 |
| Subject: | com php-src: Merge remote-tracking branch 'origin/PHP-5.6' into str_size_and_int64_56_backport: ext/date/ php_date.c ext/phar/phar_path_check.c ext/standar d/url.c main/php_variables.c main/php_variables.h sapi/litespeed/lsapi_main.c sapi/phpdbg/phpdbg.c s api/phpdbg/phpdbg.h sapi/phpdbg/phpdbg_bp.c sapi/phpd bg/phpdbg_bp.h sapi/phpdbg/phpdbg_cmd.c sapi/phpdbg /phpdbg_cmd.h sapi/phpdbg/phpdbg_frame.c sapi/phpdb g/phpdbg_info.c sapi/phpdbg/phpdbg_list.c |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-77155@lists.php.net to get a copy of this message | ||
Commit: 36a0950b393a409eaaca692f31c41b70953cc4e1
Author: Anatol Belski <ab@php.net> Fri, 25 Apr 2014 19:49:10 +0200
Parents: 70707a58c9297b18ba6f6e1cbbfd0d241a732a74 70fdb21d9354f34050c30842a313eddae766a580
Branches: str_size_and_int64_56_backport
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=36a0950b393a409eaaca692f31c41b70953cc4e1
Log:
Merge remote-tracking branch 'origin/PHP-5.6' into str_size_and_int64_56_backport
* origin/PHP-5.6: (158 commits)
fixed test
updated NEWS
updated NEWS
Fixed bug #67118 DateTime constructor crash with invalid data
update NEWS
update NEWS
add a test case previously broken by a bad fix
Revert "Fixed bug #64604"
updated libmagic.patch for 5.6+
updated libmagic.patch
backport this piece from 5.6, related to the #66307 fix
updated NEWS
Fixed bug #66307 Fileinfo crashes with powerpoint files
use a portable strndup implementation
fixed C89 compat
prepare config.w32
fix dll export
add parser files to dist
Fix accepting ill-formed UTF-8 characters
sapi/litespeed/lsapi_main.c: Fix bug #63228
...
Conflicts:
ext/date/php_date.c
sapi/phpdbg/phpdbg_bp.c
sapi/phpdbg/phpdbg_frame.c
sapi/phpdbg/phpdbg_help.c
sapi/phpdbg/phpdbg_list.c
sapi/phpdbg/phpdbg_prompt.c
Bugs:
https://bugs.php.net/67118
https://bugs.php.net/64604
https://bugs.php.net/66307
https://bugs.php.net/63228
Changed paths:
MM ext/date/php_date.c
MM ext/phar/phar_path_check.c
MM ext/standard/url.c
MM main/php_variables.c
MM main/php_variables.h
MM sapi/litespeed/lsapi_main.c
MM sapi/phpdbg/phpdbg.c
MM sapi/phpdbg/phpdbg.h
MM sapi/phpdbg/phpdbg_bp.c
MM sapi/phpdbg/phpdbg_bp.h
MM sapi/phpdbg/phpdbg_cmd.c
MM sapi/phpdbg/phpdbg_cmd.h
MM sapi/phpdbg/phpdbg_frame.c
MM sapi/phpdbg/phpdbg_info.c
MM sapi/phpdbg/phpdbg_list.c
MM sapi/phpdbg/phpdbg_list.h
MM sapi/phpdbg/phpdbg_prompt.c
diff --cc ext/date/php_date.c index 02e5a87,f81f87e..c8c2d8e --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@@ -2715,8 -2728,10 +2715,10 @@@ PHP_METHOD(DateTime, __construct zend_error_handling error_handling; zend_replace_error_handling(EH_THROW, NULL, &error_handling TSRMLS_CC); - if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sO!", &time_str, &time_str_len, &timezone_object, date_ce_timezone)) { + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|SO!", &time_str, &time_str_len, &timezone_object, date_ce_timezone)) { - php_date_initialize(zend_object_store_get_object(getThis() TSRMLS_CC), time_str, time_str_len, NULL, timezone_object, 1 TSRMLS_CC); + if (!php_date_initialize(zend_object_store_get_object(getThis() TSRMLS_CC), time_str, time_str_len, NULL, timezone_object, 1 TSRMLS_CC)) { + ZVAL_NULL(getThis()); + } } zend_restore_error_handling(&error_handling TSRMLS_CC); } diff --cc main/php_variables.h index 141e0e4,2331c58..c33308b --- a/main/php_variables.h +++ b/main/php_variables.h @@@ -38,10 -38,10 +38,10 @@@ void php_startup_auto_globals(TSRMLS_D) extern PHPAPI void (*php_import_environment_variables)(zval *array_ptr TSRMLS_DC); PHPAPI void php_register_variable(char *var, char *val, zval *track_vars_array TSRMLS_DC); /* binary-safe version */ -PHPAPI void php_register_variable_safe(char *var, char *val, int val_len, zval *track_vars_array TSRMLS_DC); +PHPAPI void php_register_variable_safe(char *var, char *val, php_size_t val_len, zval *track_vars_array TSRMLS_DC); PHPAPI void php_register_variable_ex(char *var, zval *val, zval *track_vars_array TSRMLS_DC); - int php_hash_environment(TSRMLS_D); + PHPAPI int php_hash_environment(TSRMLS_D); END_EXTERN_C() #define NUM_TRACK_VARS 6 diff --cc sapi/phpdbg/phpdbg.c index 3fe9ce8,064e266..6b19c25 --- a/sapi/phpdbg/phpdbg.c +++ b/sapi/phpdbg/phpdbg.c @@@ -222,11 -232,11 +232,11 @@@ static PHP_FUNCTION(phpdbg_exec if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &exec, &exec_len) == FAILURE) { return; } - + { - struct stat sb; + zend_stat_t sb; zend_bool result = 1; - + if (VCWD_STAT(exec, &sb) != FAILURE) { if (sb.st_mode & (S_IFREG|S_IFLNK)) { if (PHPDBG_G(exec)) { diff --cc sapi/phpdbg/phpdbg.h index 0cf1a48,be009e4..e10dfe1 --- a/sapi/phpdbg/phpdbg.h +++ b/sapi/phpdbg/phpdbg.h @@@ -178,11 -199,24 +199,24 @@@ ZEND_BEGIN_MODULE_GLOBALS(phpdbg char *prompt[2]; /* prompt */ const phpdbg_color_t *colors[PHPDBG_COLORS]; /* colors */ - - phpdbg_command_t *lcmd; /* last command */ - phpdbg_param_t lparam; /* last param */ + char *buffer; /* buffer */ - zend_ulong flags; /* phpdbg flags */ + php_uint_t flags; /* phpdbg flags */ ZEND_END_MODULE_GLOBALS(phpdbg) /* }}} */ + /* the beginning (= the important part) of the _zend_mm_heap struct defined in Zend/zend_alloc.c + Needed for realizing watchpoints */ + struct _zend_mm_heap { + int use_zend_alloc; + void *(*_malloc)(size_t); + void (*_free)(void *); + void *(*_realloc)(void *, size_t); + size_t free_bitmap; + size_t large_free_bitmap; + size_t block_size; + size_t compact_size; + zend_mm_segment *segments_list; + zend_mm_storage *storage; + }; + #endif /* PHPDBG_H */ diff --cc sapi/phpdbg/phpdbg_bp.c index c5c8731,a18316a..142ada4 --- a/sapi/phpdbg/phpdbg_bp.c +++ b/sapi/phpdbg/phpdbg_bp.c @@@ -219,16 -219,22 +219,22 @@@ PHPDBG_API void phpdbg_export_breakpoin } } /* }}} */ -PHPDBG_API void phpdbg_set_breakpoint_file(const char *path, long line_num TSRMLS_DC) /* {{{ */ +PHPDBG_API void phpdbg_set_breakpoint_file(const char *path, php_int_t line_num TSRMLS_DC) /* {{{ */ { - zend_stat_t sb; - - if (VCWD_STAT(path, &sb) != FAILURE) { - if (sb.st_mode & (S_IFREG|S_IFLNK)) { + php_stream_statbuf ssb; + char realpath[MAXPATHLEN]; + + if (php_stream_stat_path(path, &ssb) != FAILURE) { + if (ssb.sb.st_mode & (S_IFREG|S_IFLNK)) { HashTable *broken; phpdbg_breakfile_t new_break; - size_t path_len = strlen(path); - + size_t path_len = 0L; + + if (VCWD_REALPATH(path, realpath)) { + path = realpath; + } + path_len = strlen(path); + if (zend_hash_find(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE], path, path_len, (void**)&broken) == FAILURE) { HashTable breaks; @@@ -324,12 -330,12 +330,12 @@@ PHPDBG_API void phpdbg_set_breakpoint_m PHPDBG_BREAK_MAPPING(new_break.id, class_table); } else { phpdbg_notice("Breakpoint exists at %s::%s", class_name, func_name); - } + } - efree(lcname); + efree(lcname); } /* }}} */ -PHPDBG_API void phpdbg_set_breakpoint_opline(zend_ulong opline TSRMLS_DC) /* {{{ */ +PHPDBG_API void phpdbg_set_breakpoint_opline(php_uint_t opline TSRMLS_DC) /* {{{ */ { if (!zend_hash_index_exists(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE], opline)) { phpdbg_breakline_t new_break; @@@ -760,56 -766,26 +766,26 @@@ PHPDBG_API void phpdbg_set_breakpoint_e } } /* }}} */ - PHPDBG_API void phpdbg_set_breakpoint_at(const phpdbg_param_t *param, const phpdbg_input_t *input TSRMLS_DC) /* {{{ */ + PHPDBG_API void phpdbg_set_breakpoint_at(const phpdbg_param_t *param TSRMLS_DC) /* {{{ */ { - if (input->argc > 3 && phpdbg_argv_is(2, "if")) { - phpdbg_breakcond_t new_break; - phpdbg_param_t new_param; - - php_uint_t expr_hash = Z_UI(0); - size_t expr_len; - const char *join = strstr(input->string, "if"); - const char *expr = (join) + sizeof("if"); - - expr_len = strlen(expr); - expr = phpdbg_trim(expr, expr_len, &expr_len); - expr_hash = zend_inline_hash_func(expr, expr_len); - - { - /* get a clean parameter from input string */ - size_t sparam_len = 0L; - char *sparam = input->string; - - sparam[ - strstr(input->string, " ") - input->string] = 0; - sparam_len = strlen(sparam); - - switch (phpdbg_parse_param(sparam, sparam_len, &new_param TSRMLS_CC)) { - case EMPTY_PARAM: - case NUMERIC_PARAM: - phpdbg_clear_param( - &new_param TSRMLS_CC); - goto usage; - - default: { /* do nothing */ } break; - } - - expr_hash += phpdbg_hash_param(&new_param TSRMLS_CC); - } - - if (!zend_hash_index_exists(&PHPDBG_G(bp)[PHPDBG_BREAK_COND], expr_hash)) { + phpdbg_breakcond_t new_break; + phpdbg_param_t *condition; - zend_ulong hash = 0L; ++ zend_uint_t hash = 0L; + + if (param->next) { + condition = param->next; + hash = zend_inline_hash_func(condition->str, condition->len); + + if (!zend_hash_index_exists(&PHPDBG_G(bp)[PHPDBG_BREAK_COND], hash)) { phpdbg_create_conditional_break( - &new_break, &new_param, expr, expr_len, expr_hash TSRMLS_CC); + &new_break, param, + condition->str, condition->len, hash TSRMLS_CC); } else { phpdbg_notice( - "Conditional break %s exists at the specified location", expr); - } - - phpdbg_clear_param(&new_param TSRMLS_CC); - } else { - usage: - phpdbg_error("usage: break at <func|method|file:line|address> if <expression>"); + "Conditional break %s exists at the specified location", condition->str); + } } + } /* }}} */ static inline phpdbg_breakbase_t *phpdbg_find_breakpoint_file(zend_op_array *op_array TSRMLS_DC) /* {{{ */ diff --cc sapi/phpdbg/phpdbg_bp.h index c36ed9d,97980e7..17a680b --- a/sapi/phpdbg/phpdbg_bp.h +++ b/sapi/phpdbg/phpdbg_bp.h @@@ -113,13 -113,13 +113,13 @@@ PHPDBG_API void phpdbg_set_breakpoint_f PHPDBG_API void phpdbg_set_breakpoint_symbol(const char* func_name, size_t func_name_len TSRMLS_DC); PHPDBG_API void phpdbg_set_breakpoint_method(const char* class_name, const char* func_name TSRMLS_DC); PHPDBG_API void phpdbg_set_breakpoint_opcode(const char* opname, size_t opname_len TSRMLS_DC); -PHPDBG_API void phpdbg_set_breakpoint_opline(zend_ulong opline TSRMLS_DC); +PHPDBG_API void phpdbg_set_breakpoint_opline(php_uint_t opline TSRMLS_DC); PHPDBG_API void phpdbg_set_breakpoint_opline_ex(phpdbg_opline_ptr_t opline TSRMLS_DC); -PHPDBG_API void phpdbg_set_breakpoint_method_opline(const char *class, const char *method, zend_ulong opline TSRMLS_DC); -PHPDBG_API void phpdbg_set_breakpoint_function_opline(const char *function, zend_ulong opline TSRMLS_DC); -PHPDBG_API void phpdbg_set_breakpoint_file_opline(const char *file, zend_ulong opline TSRMLS_DC); +PHPDBG_API void phpdbg_set_breakpoint_method_opline(const char *class, const char *method, php_uint_t opline TSRMLS_DC); +PHPDBG_API void phpdbg_set_breakpoint_function_opline(const char *function, php_uint_t opline TSRMLS_DC); +PHPDBG_API void phpdbg_set_breakpoint_file_opline(const char *file, php_uint_t opline TSRMLS_DC); PHPDBG_API void phpdbg_set_breakpoint_expression(const char* expression, size_t expression_len TSRMLS_DC); - PHPDBG_API void phpdbg_set_breakpoint_at(const phpdbg_param_t *param, const phpdbg_input_t *input TSRMLS_DC); /* }}} */ + PHPDBG_API void phpdbg_set_breakpoint_at(const phpdbg_param_t *param TSRMLS_DC); /* }}} */ /* {{{ Breakpoint Detection API */ PHPDBG_API phpdbg_breakbase_t* phpdbg_find_breakpoint(zend_execute_data* TSRMLS_DC); /* }}} */ diff --cc sapi/phpdbg/phpdbg_cmd.c index 6b800cc,d4ce8eb..26d10a4 --- a/sapi/phpdbg/phpdbg_cmd.c +++ b/sapi/phpdbg/phpdbg_cmd.c @@@ -249,11 -283,15 +283,15 @@@ PHPDBG_API void phpdbg_copy_param(cons } } /* }}} */ -PHPDBG_API zend_ulong phpdbg_hash_param(const phpdbg_param_t *param TSRMLS_DC) /* {{{ */ +PHPDBG_API php_uint_t phpdbg_hash_param(const phpdbg_param_t *param TSRMLS_DC) /* {{{ */ { - zend_ulong hash = param->type; + php_uint_t hash = param->type; switch (param->type) { + case STACK_PARAM: + /* nope */ + break; + case STR_PARAM: hash += zend_inline_hash_func(param->str, param->len); break; diff --cc sapi/phpdbg/phpdbg_cmd.h index 787f8f8,571d065..497cc23 --- a/sapi/phpdbg/phpdbg_cmd.h +++ b/sapi/phpdbg/phpdbg_cmd.h @@@ -40,26 -39,24 +39,24 @@@ typedef enum STR_PARAM, NUMERIC_PARAM, NUMERIC_FUNCTION_PARAM, - NUMERIC_METHOD_PARAM + NUMERIC_METHOD_PARAM, + STACK_PARAM, + EVAL_PARAM, + SHELL_PARAM, + COND_PARAM, + OP_PARAM, + ORIG_PARAM, + RUN_PARAM } phpdbg_param_type; - typedef struct _phpdbg_input_t phpdbg_input_t; - - struct _phpdbg_input_t { - char * const *start; - char *string; - size_t length; - phpdbg_input_t **argv; - int argc; - }; - - typedef struct _phpdbg_param { + typedef struct _phpdbg_param phpdbg_param_t; + struct _phpdbg_param { phpdbg_param_type type; - long num; - zend_ulong addr; + php_int_t num; + php_uint_t addr; struct { char *name; - long line; + php_int_t line; } file; struct { char *class; @@@ -132,14 -145,10 +145,10 @@@ PHPDBG_API phpdbg_param_type phpdbg_par PHPDBG_API void phpdbg_clear_param(phpdbg_param_t* TSRMLS_DC); PHPDBG_API void phpdbg_copy_param(const phpdbg_param_t*, phpdbg_param_t* TSRMLS_DC); PHPDBG_API zend_bool phpdbg_match_param(const phpdbg_param_t *, const phpdbg_param_t * TSRMLS_DC); -PHPDBG_API zend_ulong phpdbg_hash_param(const phpdbg_param_t * TSRMLS_DC); +PHPDBG_API php_uint_t phpdbg_hash_param(const phpdbg_param_t * TSRMLS_DC); PHPDBG_API const char* phpdbg_get_param_type(const phpdbg_param_t* TSRMLS_DC); PHPDBG_API char* phpdbg_param_tostring(const phpdbg_param_t *param, char **pointer TSRMLS_DC); - - /* - * Command Executor - */ - PHPDBG_API int phpdbg_do_cmd(const phpdbg_command_t*, phpdbg_input_t* TSRMLS_DC); + PHPDBG_API void phpdbg_param_debug(const phpdbg_param_t *param, const char *msg); /** * Command Declarators diff --cc sapi/phpdbg/phpdbg_frame.c index 48506ad,a235fe8..8537185 --- a/sapi/phpdbg/phpdbg_frame.c +++ b/sapi/phpdbg/phpdbg_frame.c @@@ -186,7 -186,7 +186,7 @@@ void phpdbg_dump_backtrace(size_t num T if (zend_hash_get_current_data_ex(Z_ARRVAL(zbacktrace), (void**)&tmp, &position) == FAILURE) { - phpdbg_write("frame #0: {main} at %s:%pd", Z_STRVAL_PP(file), Z_IVAL_PP(line)); - phpdbg_write("frame #%d: {main} at %s:%ld", i, Z_STRVAL_PP(file), Z_LVAL_PP(line)); ++ phpdbg_write("frame #%d: {main} at %s:%pd", i, Z_STRVAL_PP(file), Z_LVAL_PP(line)); break; } diff --cc sapi/phpdbg/phpdbg_list.c index 12cdc91,037c6c3..55fc3df --- a/sapi/phpdbg/phpdbg_list.c +++ b/sapi/phpdbg/phpdbg_list.c @@@ -130,18 -124,15 +124,15 @@@ PHPDBG_LIST(class) /* {{{ * return SUCCESS; } /* }}} */ -void phpdbg_list_file(const char *filename, long count, long offset, int highlight TSRMLS_DC) /* {{{ */ +void phpdbg_list_file(const char *filename, php_int_t count, php_int_t offset, php_int_t highlight TSRMLS_DC) /* {{{ */ { - unsigned char *mem, *pos, *last_pos, *end_pos; - struct stat st; + zend_stat_t st; - #ifndef _WIN32 - int fd; - #else - HANDLE fd, map; - #endif - int all_content = (count == 0); - int line = 0, displayed = 0; - + char *opened = NULL; + char buffer[8096] = {0,}; - long line = 0; ++ php_int_t line = 0; + + php_stream *stream = NULL; + if (VCWD_STAT(filename, &st) == FAILURE) { phpdbg_error("Failed to stat file %s", filename); return; @@@ -196,33 -151,21 +151,21 @@@ if (!offset || offset <= line) { /* Without offset, or offset reached */ if (!highlight) { - phpdbg_writeln("%05u: %.*s", line, (int)(pos - last_pos), last_pos); - phpdbg_write("%05ld: %s", line, buffer); ++ phpdbg_write("%05" ZEND_INT_FMT_SPEC ": %s", line, buffer); } else { if (highlight != line) { - phpdbg_writeln(" %05u: %.*s", line, (int)(pos - last_pos), last_pos); - phpdbg_write(" %05ld: %s", line, buffer); ++ phpdbg_write(" %05" ZEND_INT_FMT_SPEC ": %s", line, buffer); } else { - phpdbg_writeln(">%05u: %.*s", line, (int)(pos - last_pos), last_pos); - phpdbg_write(">%05ld: %s", line, buffer); ++ phpdbg_write(">%05" ZEND_INT_FMT_SPEC ": %s", line, buffer); } } - ++displayed; } - - last_pos = pos + 1; - - if (!all_content && displayed == count) { - /* Reached max line to display */ + + if ((count + (offset-1)) == line) break; - } } - - #ifndef _WIN32 - munmap(mem, st.st_size); - close(fd); - #else - UnmapViewOfFile(mem); - CloseHandle(map); - CloseHandle(fd); - #endif + + php_stream_close(stream); } /* }}} */ void phpdbg_list_function(const zend_function *fbc TSRMLS_DC) /* {{{ */ diff --cc sapi/phpdbg/phpdbg_list.h index 1d35520,14905f6..831e44d --- a/sapi/phpdbg/phpdbg_list.h +++ b/sapi/phpdbg/phpdbg_list.h @@@ -34,14 -34,8 +34,8 @@@ PHPDBG_LIST(func) void phpdbg_list_function_byname(const char *, size_t TSRMLS_DC); void phpdbg_list_function(const zend_function* TSRMLS_DC); -void phpdbg_list_file(const char*, long, long, int TSRMLS_DC); +void phpdbg_list_file(const char*, php_int_t, php_int_t, php_int_t 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 - }; + extern const phpdbg_command_t phpdbg_list_commands[]; #endif /* PHPDBG_LIST_H */ diff --cc sapi/phpdbg/phpdbg_prompt.c index 4e28b6b,7a28a75..8669f01 --- a/sapi/phpdbg/phpdbg_prompt.c +++ b/sapi/phpdbg/phpdbg_prompt.c @@@ -135,8 -190,8 +190,8 @@@ static inline int phpdbg_call_register( void phpdbg_try_file_init(char *init_file, size_t init_file_len, zend_bool free_init TSRMLS_DC) /* {{{ */ { - struct stat sb; + zend_stat_t sb; - + if (init_file && VCWD_STAT(init_file, &sb) != -1) { FILE *fp = fopen(init_file, "r"); if (fp) { @@@ -264,47 -347,47 +347,47 @@@ void phpdbg_init(char *init_file, size_ PHPDBG_COMMAND(exec) /* {{{ */ { - switch (param->type) { - case STR_PARAM: { - zend_stat_t 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 ((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; - } - struct stat sb; ++ zend_stat_t sb; - if (PHPDBG_G(ops)) { - phpdbg_notice("Destroying compiled opcodes"); - phpdbg_clean(0 TSRMLS_CC); - } + 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); - PHPDBG_G(exec) = res; - PHPDBG_G(exec_len) = res_len; + if ((res_len != PHPDBG_G(exec_len)) || (memcmp(res, PHPDBG_G(exec), res_len) != SUCCESS)) { - phpdbg_notice("Set execution context: %s", PHPDBG_G(exec)); - } else { - phpdbg_notice("Execution context not changed"); - } - } else { - phpdbg_error("Cannot use %s as execution context, not a valid file or symlink", param->str); + 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"); + phpdbg_clean(0 TSRMLS_CC); + } + + PHPDBG_G(exec) = res; + PHPDBG_G(exec_len) = res_len; + + *SG(request_info).argv = PHPDBG_G(exec); + php_hash_environment(TSRMLS_C); + + phpdbg_notice("Set execution context: %s", PHPDBG_G(exec)); + + if (phpdbg_compile(TSRMLS_C) == FAILURE) { + phpdbg_error("Failed to compile %s", PHPDBG_G(exec)); } } else { - phpdbg_error("Cannot stat %s, ensure the file exists", param->str); + phpdbg_notice("Execution context not changed"); } - } break; - - phpdbg_default_switch_case(); + } else { + phpdbg_error("Cannot use %s as execution context, not a valid file or symlink", param->str); + } + } else { + phpdbg_error("Cannot stat %s, ensure the file exists", param->str); } - return SUCCESS; } /* }}} */ @@@ -799,29 -859,30 +859,30 @@@ PHPDBG_COMMAND(sh) /* {{{ * PHPDBG_COMMAND(source) /* {{{ */ { - switch (param->type) { - case STR_PARAM: { - if (input->argc > 2) { - if (phpdbg_argv_is(1, "export")) { - FILE *h = VCWD_FOPEN(input->argv[2]->string, "w+"); - if (h) { - phpdbg_export_breakpoints(h TSRMLS_CC); - fclose(h); - } else phpdbg_error("Failed to open %s", input->argv[1]->string); - } else { - phpdbg_error( - "Incorrect usage of source command, see help"); - } - } else { - zend_stat_t sb; - if (VCWD_STAT(param->str, &sb) != -1) { - phpdbg_try_file_init(param->str, param->len, 0 TSRMLS_CC); - } else phpdbg_error("Cannot stat %s", param->str); - } - } break; - struct stat sb; ++ zend_stat_t sb; + + if (VCWD_STAT(param->str, &sb) != -1) { + phpdbg_try_file_init(param->str, param->len, 0 TSRMLS_CC); + } else { + phpdbg_error( + "Failed to stat %s, file does not exist", param->str); + } + + return SUCCESS; + } /* }}} */ - phpdbg_default_switch_case(); + PHPDBG_COMMAND(export) /* {{{ */ + { + FILE *handle = VCWD_FOPEN(param->str, "w+"); + + if (handle) { + phpdbg_export_breakpoints(handle TSRMLS_CC); + fclose(handle); + } else { + phpdbg_error( + "Failed to open or create %s, check path and permissions", param->str); } + return SUCCESS; } /* }}} */
diff --cc ext/date/php_date.c index 02e5a87,f81f87e..c8c2d8e --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@@ -2715,8 -2728,10 +2715,10 @@@ PHP_METHOD(DateTime, __construct zend_error_handling error_handling; zend_replace_error_handling(EH_THROW, NULL, &error_handling TSRMLS_CC); - if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sO!", &time_str, &time_str_len, &timezone_object, date_ce_timezone)) { + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|SO!", &time_str, &time_str_len, &timezone_object, date_ce_timezone)) { - php_date_initialize(zend_object_store_get_object(getThis() TSRMLS_CC), time_str, time_str_len, NULL, timezone_object, 1 TSRMLS_CC); + if (!php_date_initialize(zend_object_store_get_object(getThis() TSRMLS_CC), time_str, time_str_len, NULL, timezone_object, 1 TSRMLS_CC)) { + ZVAL_NULL(getThis()); + } } zend_restore_error_handling(&error_handling TSRMLS_CC); } diff --cc main/php_variables.h index 141e0e4,2331c58..c33308b --- a/main/php_variables.h +++ b/main/php_variables.h @@@ -38,10 -38,10 +38,10 @@@ void php_startup_auto_globals(TSRMLS_D) extern PHPAPI void (*php_import_environment_variables)(zval *array_ptr TSRMLS_DC); PHPAPI void php_register_variable(char *var, char *val, zval *track_vars_array TSRMLS_DC); /* binary-safe version */ -PHPAPI void php_register_variable_safe(char *var, char *val, int val_len, zval *track_vars_array TSRMLS_DC); +PHPAPI void php_register_variable_safe(char *var, char *val, php_size_t val_len, zval *track_vars_array TSRMLS_DC); PHPAPI void php_register_variable_ex(char *var, zval *val, zval *track_vars_array TSRMLS_DC); - int php_hash_environment(TSRMLS_D); + PHPAPI int php_hash_environment(TSRMLS_D); END_EXTERN_C() #define NUM_TRACK_VARS 6 diff --cc sapi/phpdbg/phpdbg.c index 3fe9ce8,064e266..6b19c25 --- a/sapi/phpdbg/phpdbg.c +++ b/sapi/phpdbg/phpdbg.c @@@ -222,11 -232,11 +232,11 @@@ static PHP_FUNCTION(phpdbg_exec if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &exec, &exec_len) == FAILURE) { return; } - + { - struct stat sb; + zend_stat_t sb; zend_bool result = 1; - + if (VCWD_STAT(exec, &sb) != FAILURE) { if (sb.st_mode & (S_IFREG|S_IFLNK)) { if (PHPDBG_G(exec)) { diff --cc sapi/phpdbg/phpdbg.h index 0cf1a48,be009e4..e10dfe1 --- a/sapi/phpdbg/phpdbg.h +++ b/sapi/phpdbg/phpdbg.h @@@ -178,11 -199,24 +199,24 @@@ ZEND_BEGIN_MODULE_GLOBALS(phpdbg char *prompt[2]; /* prompt */ const phpdbg_color_t *colors[PHPDBG_COLORS]; /* colors */ - - phpdbg_command_t *lcmd; /* last command */ - phpdbg_param_t lparam; /* last param */ + char *buffer; /* buffer */ - zend_ulong flags; /* phpdbg flags */ + php_uint_t flags; /* phpdbg flags */ ZEND_END_MODULE_GLOBALS(phpdbg) /* }}} */ + /* the beginning (= the important part) of the _zend_mm_heap struct defined in Zend/zend_alloc.c + Needed for realizing watchpoints */ + struct _zend_mm_heap { + int use_zend_alloc; + void *(*_malloc)(size_t); + void (*_free)(void *); + void *(*_realloc)(void *, size_t); + size_t free_bitmap; + size_t large_free_bitmap; + size_t block_size; + size_t compact_size; + zend_mm_segment *segments_list; + zend_mm_storage *storage; + }; + #endif /* PHPDBG_H */ diff --cc sapi/phpdbg/phpdbg_bp.c index c5c8731,a18316a..142ada4 --- a/sapi/phpdbg/phpdbg_bp.c +++ b/sapi/phpdbg/phpdbg_bp.c @@@ -219,16 -219,22 +219,22 @@@ PHPDBG_API void phpdbg_export_breakpoin } } /* }}} */ -PHPDBG_API void phpdbg_set_breakpoint_file(const char *path, long line_num TSRMLS_DC) /* {{{ */ +PHPDBG_API void phpdbg_set_breakpoint_file(const char *path, php_int_t line_num TSRMLS_DC) /* {{{ */ { - zend_stat_t sb; - - if (VCWD_STAT(path, &sb) != FAILURE) { - if (sb.st_mode & (S_IFREG|S_IFLNK)) { + php_stream_statbuf ssb; + char realpath[MAXPATHLEN]; + + if (php_stream_stat_path(path, &ssb) != FAILURE) { + if (ssb.sb.st_mode & (S_IFREG|S_IFLNK)) { HashTable *broken; phpdbg_breakfile_t new_break; - size_t path_len = strlen(path); - + size_t path_len = 0L; + + if (VCWD_REALPATH(path, realpath)) { + path = realpath; + } + path_len = strlen(path); + if (zend_hash_find(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE], path, path_len, (void**)&broken) == FAILURE) { HashTable breaks; @@@ -324,12 -330,12 +330,12 @@@ PHPDBG_API void phpdbg_set_breakpoint_m PHPDBG_BREAK_MAPPING(new_break.id, class_table); } else { phpdbg_notice("Breakpoint exists at %s::%s", class_name, func_name); - } + } - efree(lcname); + efree(lcname); } /* }}} */ -PHPDBG_API void phpdbg_set_breakpoint_opline(zend_ulong opline TSRMLS_DC) /* {{{ */ +PHPDBG_API void phpdbg_set_breakpoint_opline(php_uint_t opline TSRMLS_DC) /* {{{ */ { if (!zend_hash_index_exists(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE], opline)) { phpdbg_breakline_t new_break; @@@ -760,56 -766,26 +766,26 @@@ PHPDBG_API void phpdbg_set_breakpoint_e } } /* }}} */ - PHPDBG_API void phpdbg_set_breakpoint_at(const phpdbg_param_t *param, const phpdbg_input_t *input TSRMLS_DC) /* {{{ */ + PHPDBG_API void phpdbg_set_breakpoint_at(const phpdbg_param_t *param TSRMLS_DC) /* {{{ */ { - if (input->argc > 3 && phpdbg_argv_is(2, "if")) { - phpdbg_breakcond_t new_break; - phpdbg_param_t new_param; - - php_uint_t expr_hash = Z_UI(0); - size_t expr_len; - const char *join = strstr(input->string, "if"); - const char *expr = (join) + sizeof("if"); - - expr_len = strlen(expr); - expr = phpdbg_trim(expr, expr_len, &expr_len); - expr_hash = zend_inline_hash_func(expr, expr_len); - - { - /* get a clean parameter from input string */ - size_t sparam_len = 0L; - char *sparam = input->string; - - sparam[ - strstr(input->string, " ") - input->string] = 0; - sparam_len = strlen(sparam); - - switch (phpdbg_parse_param(sparam, sparam_len, &new_param TSRMLS_CC)) { - case EMPTY_PARAM: - case NUMERIC_PARAM: - phpdbg_clear_param( - &new_param TSRMLS_CC); - goto usage; - - default: { /* do nothing */ } break; - } - - expr_hash += phpdbg_hash_param(&new_param TSRMLS_CC); - } - - if (!zend_hash_index_exists(&PHPDBG_G(bp)[PHPDBG_BREAK_COND], expr_hash)) { + phpdbg_breakcond_t new_break; + phpdbg_param_t *condition; - zend_ulong hash = 0L; ++ zend_uint_t hash = 0L; + + if (param->next) { + condition = param->next; + hash = zend_inline_hash_func(condition->str, condition->len); + + if (!zend_hash_index_exists(&PHPDBG_G(bp)[PHPDBG_BREAK_COND], hash)) { phpdbg_create_conditional_break( - &new_break, &new_param, expr, expr_len, expr_hash TSRMLS_CC); + &new_break, param, + condition->str, condition->len, hash TSRMLS_CC); } else { phpdbg_notice( - "Conditional break %s exists at the specified location", expr); - } - - phpdbg_clear_param(&new_param TSRMLS_CC); - } else { - usage: - phpdbg_error("usage: break at <func|method|file:line|address> if <expression>"); + "Conditional break %s exists at the specified location", condition->str); + } } + } /* }}} */ static inline phpdbg_breakbase_t *phpdbg_find_breakpoint_file(zend_op_array *op_array TSRMLS_DC) /* {{{ */ diff --cc sapi/phpdbg/phpdbg_bp.h index c36ed9d,97980e7..17a680b --- a/sapi/phpdbg/phpdbg_bp.h +++ b/sapi/phpdbg/phpdbg_bp.h @@@ -113,13 -113,13 +113,13 @@@ PHPDBG_API void phpdbg_set_breakpoint_f PHPDBG_API void phpdbg_set_breakpoint_symbol(const char* func_name, size_t func_name_len TSRMLS_DC); PHPDBG_API void phpdbg_set_breakpoint_method(const char* class_name, const char* func_name TSRMLS_DC); PHPDBG_API void phpdbg_set_breakpoint_opcode(const char* opname, size_t opname_len TSRMLS_DC); -PHPDBG_API void phpdbg_set_breakpoint_opline(zend_ulong opline TSRMLS_DC); +PHPDBG_API void phpdbg_set_breakpoint_opline(php_uint_t opline TSRMLS_DC); PHPDBG_API void phpdbg_set_breakpoint_opline_ex(phpdbg_opline_ptr_t opline TSRMLS_DC); -PHPDBG_API void phpdbg_set_breakpoint_method_opline(const char *class, const char *method, zend_ulong opline TSRMLS_DC); -PHPDBG_API void phpdbg_set_breakpoint_function_opline(const char *function, zend_ulong opline TSRMLS_DC); -PHPDBG_API void phpdbg_set_breakpoint_file_opline(const char *file, zend_ulong opline TSRMLS_DC); +PHPDBG_API void phpdbg_set_breakpoint_method_opline(const char *class, const char *method, php_uint_t opline TSRMLS_DC); +PHPDBG_API void phpdbg_set_breakpoint_function_opline(const char *function, php_uint_t opline TSRMLS_DC); +PHPDBG_API void phpdbg_set_breakpoint_file_opline(const char *file, php_uint_t opline TSRMLS_DC); PHPDBG_API void phpdbg_set_breakpoint_expression(const char* expression, size_t expression_len TSRMLS_DC); - PHPDBG_API void phpdbg_set_breakpoint_at(const phpdbg_param_t *param, const phpdbg_input_t *input TSRMLS_DC); /* }}} */ + PHPDBG_API void phpdbg_set_breakpoint_at(const phpdbg_param_t *param TSRMLS_DC); /* }}} */ /* {{{ Breakpoint Detection API */ PHPDBG_API phpdbg_breakbase_t* phpdbg_find_breakpoint(zend_execute_data* TSRMLS_DC); /* }}} */ diff --cc sapi/phpdbg/phpdbg_cmd.c index 6b800cc,d4ce8eb..26d10a4 --- a/sapi/phpdbg/phpdbg_cmd.c +++ b/sapi/phpdbg/phpdbg_cmd.c @@@ -249,11 -283,15 +283,15 @@@ PHPDBG_API void phpdbg_copy_param(cons } } /* }}} */ -PHPDBG_API zend_ulong phpdbg_hash_param(const phpdbg_param_t *param TSRMLS_DC) /* {{{ */ +PHPDBG_API php_uint_t phpdbg_hash_param(const phpdbg_param_t *param TSRMLS_DC) /* {{{ */ { - zend_ulong hash = param->type; + php_uint_t hash = param->type; switch (param->type) { + case STACK_PARAM: + /* nope */ + break; + case STR_PARAM: hash += zend_inline_hash_func(param->str, param->len); break; diff --cc sapi/phpdbg/phpdbg_cmd.h index 787f8f8,571d065..497cc23 --- a/sapi/phpdbg/phpdbg_cmd.h +++ b/sapi/phpdbg/phpdbg_cmd.h @@@ -40,26 -39,24 +39,24 @@@ typedef enum STR_PARAM, NUMERIC_PARAM, NUMERIC_FUNCTION_PARAM, - NUMERIC_METHOD_PARAM + NUMERIC_METHOD_PARAM, + STACK_PARAM, + EVAL_PARAM, + SHELL_PARAM, + COND_PARAM, + OP_PARAM, + ORIG_PARAM, + RUN_PARAM } phpdbg_param_type; - typedef struct _phpdbg_input_t phpdbg_input_t; - - struct _phpdbg_input_t { - char * const *start; - char *string; - size_t length; - phpdbg_input_t **argv; - int argc; - }; - - typedef struct _phpdbg_param { + typedef struct _phpdbg_param phpdbg_param_t; + struct _phpdbg_param { phpdbg_param_type type; - long num; - zend_ulong addr; + php_int_t num; + php_uint_t addr; struct { char *name; - long line; + php_int_t line; } file; struct { char *class; @@@ -132,14 -145,10 +145,10 @@@ PHPDBG_API phpdbg_param_type phpdbg_par PHPDBG_API void phpdbg_clear_param(phpdbg_param_t* TSRMLS_DC); PHPDBG_API void phpdbg_copy_param(const phpdbg_param_t*, phpdbg_param_t* TSRMLS_DC); PHPDBG_API zend_bool phpdbg_match_param(const phpdbg_param_t *, const phpdbg_param_t * TSRMLS_DC); -PHPDBG_API zend_ulong phpdbg_hash_param(const phpdbg_param_t * TSRMLS_DC); +PHPDBG_API php_uint_t phpdbg_hash_param(const phpdbg_param_t * TSRMLS_DC); PHPDBG_API const char* phpdbg_get_param_type(const phpdbg_param_t* TSRMLS_DC); PHPDBG_API char* phpdbg_param_tostring(const phpdbg_param_t *param, char **pointer TSRMLS_DC); - - /* - * Command Executor - */ - PHPDBG_API int phpdbg_do_cmd(const phpdbg_command_t*, phpdbg_input_t* TSRMLS_DC); + PHPDBG_API void phpdbg_param_debug(const phpdbg_param_t *param, const char *msg); /** * Command Declarators diff --cc sapi/phpdbg/phpdbg_frame.c index 48506ad,a235fe8..8537185 --- a/sapi/phpdbg/phpdbg_frame.c +++ b/sapi/phpdbg/phpdbg_frame.c @@@ -186,7 -186,7 +186,7 @@@ void phpdbg_dump_backtrace(size_t num T if (zend_hash_get_current_data_ex(Z_ARRVAL(zbacktrace), (void**)&tmp, &position) == FAILURE) { - phpdbg_write("frame #0: {main} at %s:%pd", Z_STRVAL_PP(file), Z_IVAL_PP(line)); - phpdbg_write("frame #%d: {main} at %s:%ld", i, Z_STRVAL_PP(file), Z_LVAL_PP(line)); ++ phpdbg_write("frame #%d: {main} at %s:%pd", i, Z_STRVAL_PP(file), Z_LVAL_PP(line)); break; } diff --cc sapi/phpdbg/phpdbg_list.c index 12cdc91,037c6c3..55fc3df --- a/sapi/phpdbg/phpdbg_list.c +++ b/sapi/phpdbg/phpdbg_list.c @@@ -130,18 -124,15 +124,15 @@@ PHPDBG_LIST(class) /* {{{ * return SUCCESS; } /* }}} */ -void phpdbg_list_file(const char *filename, long count, long offset, int highlight TSRMLS_DC) /* {{{ */ +void phpdbg_list_file(const char *filename, php_int_t count, php_int_t offset, php_int_t highlight TSRMLS_DC) /* {{{ */ { - unsigned char *mem, *pos, *last_pos, *end_pos; - struct stat st; + zend_stat_t st; - #ifndef _WIN32 - int fd; - #else - HANDLE fd, map; - #endif - int all_content = (count == 0); - int line = 0, displayed = 0; - + char *opened = NULL; + char buffer[8096] = {0,}; - long line = 0; ++ php_int_t line = 0; + + php_stream *stream = NULL; + if (VCWD_STAT(filename, &st) == FAILURE) { phpdbg_error("Failed to stat file %s", filename); return; @@@ -196,33 -151,21 +151,21 @@@ if (!offset || offset <= line) { /* Without offset, or offset reached */ if (!highlight) { - phpdbg_writeln("%05u: %.*s", line, (int)(pos - last_pos), last_pos); - phpdbg_write("%05ld: %s", line, buffer); ++ phpdbg_write("%05" ZEND_INT_FMT_SPEC ": %s", line, buffer); } else { if (highlight != line) { - phpdbg_writeln(" %05u: %.*s", line, (int)(pos - last_pos), last_pos); - phpdbg_write(" %05ld: %s", line, buffer); ++ phpdbg_write(" %05" ZEND_INT_FMT_SPEC ": %s", line, buffer); } else { - phpdbg_writeln(">%05u: %.*s", line, (int)(pos - last_pos), last_pos); - phpdbg_write(">%05ld: %s", line, buffer); ++ phpdbg_write(">%05" ZEND_INT_FMT_SPEC ": %s", line, buffer); } } - ++displayed; } - - last_pos = pos + 1; - - if (!all_content && displayed == count) { - /* Reached max line to display */ + + if ((count + (offset-1)) == line) break; - } } - - #ifndef _WIN32 - munmap(mem, st.st_size); - close(fd); - #else - UnmapViewOfFile(mem); - CloseHandle(map); - CloseHandle(fd); - #endif + + php_stream_close(stream); } /* }}} */ void phpdbg_list_function(const zend_function *fbc TSRMLS_DC) /* {{{ */ diff --cc sapi/phpdbg/phpdbg_list.h index 1d35520,14905f6..831e44d --- a/sapi/phpdbg/phpdbg_list.h +++ b/sapi/phpdbg/phpdbg_list.h @@@ -34,14 -34,8 +34,8 @@@ PHPDBG_LIST(func) void phpdbg_list_function_byname(const char *, size_t TSRMLS_DC); void phpdbg_list_function(const zend_function* TSRMLS_DC); -void phpdbg_list_file(const char*, long, long, int TSRMLS_DC); +void phpdbg_list_file(const char*, php_int_t, php_int_t, php_int_t 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 - }; + extern const phpdbg_command_t phpdbg_list_commands[]; #endif /* PHPDBG_LIST_H */ diff --cc sapi/phpdbg/phpdbg_prompt.c index 4e28b6b,7a28a75..8669f01 --- a/sapi/phpdbg/phpdbg_prompt.c +++ b/sapi/phpdbg/phpdbg_prompt.c @@@ -135,8 -190,8 +190,8 @@@ static inline int phpdbg_call_register( void phpdbg_try_file_init(char *init_file, size_t init_file_len, zend_bool free_init TSRMLS_DC) /* {{{ */ { - struct stat sb; + zend_stat_t sb; - + if (init_file && VCWD_STAT(init_file, &sb) != -1) { FILE *fp = fopen(init_file, "r"); if (fp) { @@@ -264,47 -347,47 +347,47 @@@ void phpdbg_init(char *init_file, size_ PHPDBG_COMMAND(exec) /* {{{ */ { - switch (param->type) { - case STR_PARAM: { - zend_stat_t 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 ((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; - } - struct stat sb; ++ zend_stat_t sb; - if (PHPDBG_G(ops)) { - phpdbg_notice("Destroying compiled opcodes"); - phpdbg_clean(0 TSRMLS_CC); - } + 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); - PHPDBG_G(exec) = res; - PHPDBG_G(exec_len) = res_len; + if ((res_len != PHPDBG_G(exec_len)) || (memcmp(res, PHPDBG_G(exec), res_len) != SUCCESS)) { - phpdbg_notice("Set execution context: %s", PHPDBG_G(exec)); - } else { - phpdbg_notice("Execution context not changed"); - } - } else { - phpdbg_error("Cannot use %s as execution context, not a valid file or symlink", param->str); + 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"); + phpdbg_clean(0 TSRMLS_CC); + } + + PHPDBG_G(exec) = res; + PHPDBG_G(exec_len) = res_len; + + *SG(request_info).argv = PHPDBG_G(exec); + php_hash_environment(TSRMLS_C); + + phpdbg_notice("Set execution context: %s", PHPDBG_G(exec)); + + if (phpdbg_compile(TSRMLS_C) == FAILURE) { + phpdbg_error("Failed to compile %s", PHPDBG_G(exec)); } } else { - phpdbg_error("Cannot stat %s, ensure the file exists", param->str); + phpdbg_notice("Execution context not changed"); } - } break; - - phpdbg_default_switch_case(); + } else { + phpdbg_error("Cannot use %s as execution context, not a valid file or symlink", param->str); + } + } else { + phpdbg_error("Cannot stat %s, ensure the file exists", param->str); } - return SUCCESS; } /* }}} */ @@@ -799,29 -859,30 +859,30 @@@ PHPDBG_COMMAND(sh) /* {{{ * PHPDBG_COMMAND(source) /* {{{ */ { - switch (param->type) { - case STR_PARAM: { - if (input->argc > 2) { - if (phpdbg_argv_is(1, "export")) { - FILE *h = VCWD_FOPEN(input->argv[2]->string, "w+"); - if (h) { - phpdbg_export_breakpoints(h TSRMLS_CC); - fclose(h); - } else phpdbg_error("Failed to open %s", input->argv[1]->string); - } else { - phpdbg_error( - "Incorrect usage of source command, see help"); - } - } else { - zend_stat_t sb; - if (VCWD_STAT(param->str, &sb) != -1) { - phpdbg_try_file_init(param->str, param->len, 0 TSRMLS_CC); - } else phpdbg_error("Cannot stat %s", param->str); - } - } break; - struct stat sb; ++ zend_stat_t sb; + + if (VCWD_STAT(param->str, &sb) != -1) { + phpdbg_try_file_init(param->str, param->len, 0 TSRMLS_CC); + } else { + phpdbg_error( + "Failed to stat %s, file does not exist", param->str); + } + + return SUCCESS; + } /* }}} */ - phpdbg_default_switch_case(); + PHPDBG_COMMAND(export) /* {{{ */ + { + FILE *handle = VCWD_FOPEN(param->str, "w+"); + + if (handle) { + phpdbg_export_breakpoints(handle TSRMLS_CC); + fclose(handle); + } else { + phpdbg_error( + "Failed to open or create %s, check path and permissions", param->str); } + return SUCCESS; } /* }}} */