Skip to content

Commit 61ba269

Browse files
committed
Show full stacktraces for exceptions in phpdbg
1 parent 8902128 commit 61ba269

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

sapi/phpdbg/phpdbg_prompt.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -555,27 +555,30 @@ static inline void phpdbg_handle_exception(void) /* }}} */
555555
{
556556
zend_fcall_info fci;
557557
zval trace;
558+
zend_object *ex = EG(exception);
558559

559560
/* get filename and linenumber before unsetting exception */
560561
const char *filename = zend_get_executed_filename();
561562
uint32_t lineno = zend_get_executed_lineno();
562563

564+
EG(exception) = NULL;
565+
563566
/* call __toString */
564567
ZVAL_STRINGL(&fci.function_name, "__tostring", sizeof("__tostring") - 1);
565568
fci.size = sizeof(fci);
566-
fci.function_table = &EG(exception)->ce->function_table;
569+
fci.function_table = &ex->ce->function_table;
567570
fci.symbol_table = NULL;
568-
fci.object = EG(exception);
571+
fci.object = ex;
569572
fci.retval = &trace;
570573
fci.param_count = 0;
571574
fci.params = NULL;
572575
fci.no_separation = 1;
573576
if (zend_call_function(&fci, NULL) == SUCCESS) {
574-
phpdbg_writeln("exception", "name=\"%s\" trace=\"%.*s\"", "Uncaught %s!\n%.*s", EG(exception)->ce->name->val, Z_STRLEN(trace), Z_STRVAL(trace));
577+
phpdbg_writeln("exception", "name=\"%s\" trace=\"%.*s\"", "Uncaught %s!\n%.*s", ex->ce->name->val, Z_STRLEN(trace), Z_STRVAL(trace));
575578

576579
zval_ptr_dtor(&trace);
577580
} else {
578-
phpdbg_error("exception", "name=\"%s\"", "Uncaught %s!", EG(exception)->ce->name->val);
581+
phpdbg_error("exception", "name=\"%s\"", "Uncaught %s!", ex->ce->name->val);
579582
}
580583

581584
/* output useful information about address */
@@ -587,8 +590,7 @@ static inline void phpdbg_handle_exception(void) /* }}} */
587590
OBJ_RELEASE(EG(prev_exception));
588591
EG(prev_exception) = 0;
589592
}
590-
OBJ_RELEASE(EG(exception));
591-
EG(exception) = NULL;
593+
OBJ_RELEASE(ex);
592594
EG(opline_before_exception) = NULL;
593595
} /* }}} */
594596

0 commit comments

Comments
 (0)