Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 19 additions & 18 deletions sapi/phpdbg/phpdbg_frame.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,10 @@ static void phpdbg_dump_prototype(zval *tmp) /* {{{ */

void phpdbg_dump_backtrace(size_t num) /* {{{ */
{
HashPosition position;
zval zbacktrace;
zval *tmp;
zval startline, startfile;
const char *startfilename;
zval *file = &startfile, *line = &startline;
zend_string *file = NULL;
zend_long line = 0;
int i = 0, limit = num;

PHPDBG_OUTPUT_BACKUP();
Expand All @@ -269,42 +267,45 @@ void phpdbg_dump_backtrace(size_t num) /* {{{ */
return;
} phpdbg_end_try_access();

Z_LVAL(startline) = zend_get_executed_lineno();
startfilename = zend_get_executed_filename();
Z_STR(startfile) = zend_string_init(startfilename, strlen(startfilename), 0);

zend_hash_internal_pointer_reset_ex(Z_ARRVAL(zbacktrace), &position);
line = zend_get_executed_lineno();
file = zend_get_executed_filename_ex();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unlike zend_get_executed_filename, this can return NULL.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why that is a problem? file is always guarded by a NULL check.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, nvm


zval *function_name = NULL;
while ((tmp = zend_hash_get_current_data_ex(Z_ARRVAL(zbacktrace), &position))) {
ZEND_HASH_FOREACH_VAL(Z_ARRVAL(zbacktrace), tmp) {
if (file) { /* userland */
phpdbg_out("frame #%d: ", i);
phpdbg_dump_prototype(tmp);
phpdbg_out(" at %s:"ZEND_LONG_FMT"\n", Z_STRVAL_P(file), Z_LVAL_P(line));
phpdbg_out(" at %s:"ZEND_LONG_FMT"\n", ZSTR_VAL(file), line);
i++;
} else {
phpdbg_out(" => ");
phpdbg_dump_prototype(tmp);
phpdbg_out(" (internal function)\n");
}

file = zend_hash_find(Z_ARRVAL_P(tmp), ZSTR_KNOWN(ZEND_STR_FILE));
line = zend_hash_find(Z_ARRVAL_P(tmp), ZSTR_KNOWN(ZEND_STR_LINE));
zval *file_zv = zend_hash_find(Z_ARRVAL_P(tmp), ZSTR_KNOWN(ZEND_STR_FILE));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just change this to
file = zend_hash_find_ptr(Z_ARRVAL_P(tmp), ZSTR_KNOWN(ZEND_STR_FILE));
and remove the if-else part.
That makes the code less noisy.

if (file_zv) {
ZEND_ASSERT(Z_TYPE_P(file_zv) == IS_STRING);
file = Z_STR_P(file_zv);
} else {
file = NULL;
}
zval *line_zv = zend_hash_find(Z_ARRVAL_P(tmp), ZSTR_KNOWN(ZEND_STR_LINE));
if (line_zv) {
line = Z_LVAL_P(line_zv);
}
function_name = zend_hash_find(Z_ARRVAL_P(tmp), ZSTR_KNOWN(ZEND_STR_FUNCTION));

zend_hash_move_forward_ex(Z_ARRVAL(zbacktrace), &position);
}
} ZEND_HASH_FOREACH_END();

/* This is possible for fibers' start closure for example, which have a frame that doesn't contain the info
* of which location stated the fiber if that stack frame is already torn down. same behaviour with debug_backtrace(). */
if (file == NULL) {
phpdbg_writeln(" => %s (internal function)", Z_STRVAL_P(function_name));
} else {
phpdbg_writeln("frame #%d: {main} at %s:"ZEND_LONG_FMT, i, Z_STRVAL_P(file), Z_LVAL_P(line));
phpdbg_writeln("frame #%d: {main} at %s:"ZEND_LONG_FMT, i, ZSTR_VAL(file), line);
}

zval_ptr_dtor_nogc(&zbacktrace);
zend_string_release(Z_STR(startfile));

PHPDBG_OUTPUT_BACKUP_RESTORE();
} /* }}} */
Expand Down