Skip to content

Commit 044f37a

Browse files
committed
Merge remote-tracking branch 'origin/PHP-5.6'
Conflicts: sapi/phpdbg/phpdbg.c sapi/phpdbg/phpdbg_list.c
2 parents 87c28cc + 24babb0 commit 044f37a

5 files changed

Lines changed: 74 additions & 8 deletions

File tree

sapi/phpdbg/phpdbg.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -469,13 +469,11 @@ static void php_sapi_phpdbg_log_message(char *message TSRMLS_DC) /* {{{ */
469469
case E_COMPILE_ERROR:
470470
case E_USER_ERROR:
471471
case E_PARSE:
472-
case E_RECOVERABLE_ERROR:
473-
if (!(PHPDBG_G(flags) & PHPDBG_IN_EVAL)) {
474-
const char *file_char = zend_get_executed_filename(TSRMLS_C);
475-
zend_string *file = zend_string_init(file_char, strlen(file_char), 0);
476-
phpdbg_list_file(file, 3, zend_get_executed_lineno(TSRMLS_C) - 1, zend_get_executed_lineno(TSRMLS_C) TSRMLS_CC);
477-
efree(file);
478-
}
472+
case E_RECOVERABLE_ERROR: {
473+
const char *file_char = zend_get_executed_filename(TSRMLS_C);
474+
zend_string *file = zend_string_init(file_char, strlen(file_char), 0);
475+
phpdbg_list_file(file, 3, zend_get_executed_lineno(TSRMLS_C) - 1, zend_get_executed_lineno(TSRMLS_C) TSRMLS_CC);
476+
efree(file);
479477

480478
do {
481479
switch (phpdbg_interactive(1 TSRMLS_CC)) {
@@ -486,6 +484,7 @@ static void php_sapi_phpdbg_log_message(char *message TSRMLS_DC) /* {{{ */
486484
return;
487485
}
488486
} while (!(PHPDBG_G(flags) & PHPDBG_IS_QUITTING));
487+
}
489488

490489
}
491490
} else fprintf(stdout, "%s\n", message);
@@ -1521,6 +1520,11 @@ int main(int argc, char **argv) /* {{{ */
15211520
efree(SG(request_info).argv);
15221521
}
15231522

1523+
#ifndef _WIN32
1524+
/* reset it... else we risk a stack overflow upon next run (when clean'ing) */
1525+
php_stream_stdio_ops.write = PHPDBG_G(php_stdiop_write);
1526+
#endif
1527+
15241528
#ifndef ZTS
15251529
/* force cleanup of auto and core globals */
15261530
zend_hash_clean(CG(auto_globals));

sapi/phpdbg/phpdbg_frame.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "phpdbg_list.h"
2626

2727
ZEND_EXTERN_MODULE_GLOBALS(phpdbg);
28+
ZEND_EXTERN_MODULE_GLOBALS(output);
2829

2930
void phpdbg_restore_frame(TSRMLS_D) /* {{{ */
3031
{
@@ -174,8 +175,12 @@ void phpdbg_dump_backtrace(size_t num TSRMLS_DC) /* {{{ */
174175
zval *file, *line;
175176
int i = 0, limit = num;
176177

178+
PHPDBG_OUTPUT_BACKUP();
179+
177180
if (limit < 0) {
178181
phpdbg_error("backtrace", "type=\"minnum\"", "Invalid backtrace size %d", limit);
182+
183+
PHPDBG_OUTPUT_BACKUP_RESTORE();
179184
return;
180185
}
181186

@@ -218,4 +223,6 @@ void phpdbg_dump_backtrace(size_t num TSRMLS_DC) /* {{{ */
218223
phpdbg_xml("</backtrace>");
219224

220225
zval_dtor(&zbacktrace);
226+
227+
PHPDBG_OUTPUT_BACKUP_RESTORE();
221228
} /* }}} */

sapi/phpdbg/phpdbg_list.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,16 @@ void phpdbg_list_file(zend_string *filename, uint count, int offset, uint highli
126126
{
127127
uint line, lastline;
128128
phpdbg_file_source *data;
129+
char resolved_path_buf[MAXPATHLEN];
130+
const char *abspath;
129131

130-
if (!(data = zend_hash_find_ptr(&PHPDBG_G(file_sources), filename))) {
132+
if (VCWD_REALPATH(filename->val, resolved_path_buf)) {
133+
abspath = resolved_path_buf;
134+
} else {
135+
abspath = filename->val;
136+
}
137+
138+
if (!(data = zend_hash_str_find_ptr(&PHPDBG_G(file_sources), abspath, strlen(abspath)))) {
131139
phpdbg_error("list", "type=\"unknownfile\"", "Could not find information about included file...");
132140
return;
133141
}
@@ -230,6 +238,7 @@ zend_op_array *phpdbg_compile_file(zend_file_handle *file, int type TSRMLS_DC) {
230238
char *filename = (char *)(file->opened_path ? file->opened_path : file->filename);
231239
uint line;
232240
char *bufptr, *endptr;
241+
char resolved_path_buf[MAXPATHLEN];
233242

234243
zend_stream_fixup(file, &data.buf, &data.len TSRMLS_CC);
235244

@@ -256,6 +265,9 @@ zend_op_array *phpdbg_compile_file(zend_file_handle *file, int type TSRMLS_DC) {
256265
fake.opened_path = file->opened_path;
257266

258267
*(dataptr = emalloc(sizeof(phpdbg_file_source) + sizeof(uint) * data.len)) = data;
268+
if (VCWD_REALPATH(filename, resolved_path_buf)) {
269+
filename = resolved_path_buf;
270+
}
259271

260272
for (line = 0, bufptr = data.buf - 1, endptr = data.buf + data.len; ++bufptr < endptr;) {
261273
if (*bufptr == '\n') {

sapi/phpdbg/phpdbg_prompt.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include "phpdbg_eol.h"
4444

4545
ZEND_EXTERN_MODULE_GLOBALS(phpdbg);
46+
ZEND_EXTERN_MODULE_GLOBALS(output);
4647

4748
#ifdef HAVE_LIBDL
4849
#ifdef PHP_WIN32
@@ -645,12 +646,21 @@ PHPDBG_COMMAND(ev) /* {{{ */
645646
zend_bool stepping = ((PHPDBG_G(flags) & PHPDBG_IS_STEPPING) == PHPDBG_IS_STEPPING);
646647
zval retval;
647648

649+
zend_execute_data *original_execute_data = EG(current_execute_data);
650+
zend_class_entry *original_scope = EG(scope);
651+
zend_vm_stack original_stack = EG(vm_stack);
652+
original_stack->top = EG(vm_stack_top);
653+
654+
PHPDBG_OUTPUT_BACKUP();
655+
648656
if (PHPDBG_G(flags) & PHPDBG_IN_SIGNAL_HANDLER) {
649657
phpdbg_try_access {
650658
phpdbg_parse_variable(param->str, param->len, &EG(symbol_table).ht, 0, phpdbg_output_ev_variable, 0 TSRMLS_CC);
651659
} phpdbg_catch_access {
652660
phpdbg_error("signalsegv", "", "Could not fetch data, invalid data source");
653661
} phpdbg_end_try_access();
662+
663+
PHPDBG_OUTPUT_BACKUP_RESTORE();
654664
return SUCCESS;
655665
}
656666

@@ -672,6 +682,12 @@ PHPDBG_COMMAND(ev) /* {{{ */
672682
phpdbg_out("\n");
673683
zval_ptr_dtor(&retval);
674684
}
685+
} zend_catch {
686+
EG(current_execute_data) = original_execute_data;
687+
EG(scope) = original_scope;
688+
EG(vm_stack_top) = original_stack->top;
689+
EG(vm_stack_end) = original_stack->end;
690+
EG(vm_stack) = original_stack;
675691
} zend_end_try();
676692
PHPDBG_G(flags) &= ~PHPDBG_IN_EVAL;
677693

@@ -682,6 +698,8 @@ PHPDBG_COMMAND(ev) /* {{{ */
682698

683699
CG(unclean_shutdown) = 0;
684700

701+
PHPDBG_OUTPUT_BACKUP_RESTORE();
702+
685703
return SUCCESS;
686704
} /* }}} */
687705

sapi/phpdbg/phpdbg_utils.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,29 @@ int phpdbg_is_auto_global(char *name, int len TSRMLS_DC);
9494

9595
PHPDBG_API void phpdbg_xml_var_dump(zval *zv TSRMLS_DC);
9696

97+
#ifdef ZTS
98+
#define PHPDBG_OUTPUT_BACKUP_DEFINES() \
99+
zend_output_globals *output_globals_ptr; \
100+
zend_output_globals original_output_globals; \
101+
output_globals_ptr = (zend_output_globals *) (*((void ***) tsrm_ls))[TSRM_UNSHUFFLE_RSRC_ID(output_globals_id)];
102+
#else
103+
#define PHPDBG_OUTPUT_BACKUP_DEFINES() \
104+
zend_output_globals *output_globals_ptr; \
105+
zend_output_globals original_output_globals; \
106+
output_globals_ptr = &output_globals;
107+
#endif
108+
109+
#define PHPDBG_OUTPUT_BACKUP_SWAP() \
110+
original_output_globals = *output_globals_ptr; \
111+
memset(output_globals_ptr, 0, sizeof(zend_output_globals)); \
112+
php_output_activate(TSRMLS_C);
113+
114+
#define PHPDBG_OUTPUT_BACKUP() \
115+
PHPDBG_OUTPUT_BACKUP_DEFINES() \
116+
PHPDBG_OUTPUT_BACKUP_SWAP()
117+
118+
#define PHPDBG_OUTPUT_BACKUP_RESTORE() \
119+
php_output_deactivate(TSRMLS_C); \
120+
*output_globals_ptr = original_output_globals;
121+
97122
#endif /* PHPDBG_UTILS_H */

0 commit comments

Comments
 (0)