diff options
-rw-r--r-- | sapi/phpdbg/phpdbg.h | 1 | ||||
-rw-r--r-- | sapi/phpdbg/phpdbg_list.c | 49 |
2 files changed, 50 insertions, 0 deletions
diff --git a/sapi/phpdbg/phpdbg.h b/sapi/phpdbg/phpdbg.h index ed18e7ba55..01b0cbb3ca 100644 --- a/sapi/phpdbg/phpdbg.h +++ b/sapi/phpdbg/phpdbg.h @@ -265,6 +265,7 @@ ZEND_BEGIN_MODULE_GLOBALS(phpdbg) zend_op_array *(*compile_file)(zend_file_handle *file_handle, int type); zend_op_array *(*init_compile_file)(zend_file_handle *file_handle, int type); + zend_op_array *(*compile_string)(zval *source_string, char *filename); HashTable file_sources; FILE *oplog; /* opline log */ diff --git a/sapi/phpdbg/phpdbg_list.c b/sapi/phpdbg/phpdbg_list.c index f3181c0701..2424103480 100644 --- a/sapi/phpdbg/phpdbg_list.c +++ b/sapi/phpdbg/phpdbg_list.c @@ -31,6 +31,7 @@ #include "phpdbg_utils.h" #include "phpdbg_prompt.h" #include "php_streams.h" +#include "zend_exceptions.h" ZEND_EXTERN_MODULE_GLOBALS(phpdbg); @@ -318,6 +319,52 @@ zend_op_array *phpdbg_init_compile_file(zend_file_handle *file, int type) { return op_array; } +zend_op_array *phpdbg_compile_string(zval *source_string, char *filename) { + zend_string *fake_name; + zend_op_array *op_array; + phpdbg_file_source *dataptr; + uint line; + char *bufptr, *endptr; + + if (PHPDBG_G(flags) & PHPDBG_IN_EVAL) { + return PHPDBG_G(compile_string)(source_string, filename); + } + + dataptr = emalloc(sizeof(phpdbg_file_source) + sizeof(uint) * Z_STRLEN_P(source_string)); + dataptr->buf = estrndup(Z_STRVAL_P(source_string), Z_STRLEN_P(source_string)); + dataptr->len = Z_STRLEN_P(source_string); + for (line = 0, bufptr = dataptr->buf - 1, endptr = dataptr->buf + dataptr->len; ++bufptr < endptr;) { + if (*bufptr == '\n') { + dataptr->line[++line] = (uint)(bufptr - dataptr->buf) + 1; + } + } + dataptr->lines = ++line; + dataptr->line[line] = endptr - dataptr->buf; + + op_array = PHPDBG_G(compile_string)(source_string, filename); + + if (op_array == NULL) { + efree(dataptr->buf); + efree(dataptr); + return NULL; + } + + fake_name = zend_strpprintf(0, "%s\0%p", filename, op_array->opcodes); + + dataptr = erealloc(dataptr, sizeof(phpdbg_file_source) + sizeof(uint) * line); + zend_hash_add_ptr(&PHPDBG_G(file_sources), fake_name, dataptr); + + dataptr->filename = estrndup(ZSTR_VAL(fake_name), ZSTR_LEN(fake_name)); + zend_string_release(fake_name); + + dataptr->op_array = *op_array; + if (dataptr->op_array.refcount) { + ++*dataptr->op_array.refcount; + } + + return op_array; +} + void phpdbg_free_file_source(zval *zv) { phpdbg_file_source *data = Z_PTR_P(zv); @@ -332,8 +379,10 @@ void phpdbg_free_file_source(zval *zv) { void phpdbg_init_list(void) { PHPDBG_G(compile_file) = zend_compile_file; + PHPDBG_G(compile_string) = zend_compile_string; zend_hash_init(&PHPDBG_G(file_sources), 1, NULL, (dtor_func_t) phpdbg_free_file_source, 0); zend_compile_file = phpdbg_compile_file; + zend_compile_string = phpdbg_compile_string; } void phpdbg_list_update(void) { |