com php-src: Fix oplog with eval()ed code: sapi/phpdbg/phpdbg.h sapi/phpdbg/phpdbg_list.c
| From: | Bob Weinand | Date: | Mon, 24 Aug 2015 11:28:35 +0000 |
| Subject: | com php-src: Fix oplog with eval()ed code: sapi/phpdbg/phpdbg.h sapi/phpdbg/phpdbg_list.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-88740@lists.php.net to get a copy of this message | ||
Commit: 6b3228fda452e3ff53b8b0bd87f74c6d5ceafa6d
Author: Bob Weinand <bobwei9@hotmail.com> Mon, 24 Aug 2015 12:28:35 +0100
Parents: db5898c9e55b33c9378295a8a85aa863202996bc
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=6b3228fda452e3ff53b8b0bd87f74c6d5ceafa6d
Log:
Fix oplog with eval()ed code
Changed paths:
M sapi/phpdbg/phpdbg.h
M sapi/phpdbg/phpdbg_list.c
Diff:
diff --git a/sapi/phpdbg/phpdbg.h b/sapi/phpdbg/phpdbg.h
index ed18e7b..01b0cbb 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 f3181c0..2424103 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) {