]> granicus.if.org Git - php/commitdiff
Fix first frame in backtrace
authorBob Weinand <bobwei9@hotmail.com>
Tue, 21 Apr 2015 20:20:11 +0000 (22:20 +0200)
committerBob Weinand <bobwei9@hotmail.com>
Tue, 21 Apr 2015 20:20:11 +0000 (22:20 +0200)
sapi/phpdbg/phpdbg_frame.c

index 6d1163b069cbd1f644e8f4b913e084d421ab4fcb..584052ee0b65d1ed529618e1da0422a908cfc1e6 100644 (file)
@@ -182,7 +182,9 @@ void phpdbg_dump_backtrace(size_t num) /* {{{ */
        HashPosition position;
        zval zbacktrace;
        zval *tmp;
-       zval *file, *line;
+       zval startline, startfile;
+       const char *startfilename;
+       zval *file = &startfile, *line = &startline;
        int i = 0, limit = num;
 
        PHPDBG_OUTPUT_BACKUP();
@@ -203,18 +205,13 @@ void phpdbg_dump_backtrace(size_t num) /* {{{ */
 
        phpdbg_xml("<backtrace %r>");
 
+       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);
        tmp = zend_hash_get_current_data_ex(Z_ARRVAL(zbacktrace), &position);
-       while (1) {
-               file = zend_hash_str_find(Z_ARRVAL_P(tmp), ZEND_STRL("file"));
-               line = zend_hash_str_find(Z_ARRVAL_P(tmp), ZEND_STRL("line"));
-               zend_hash_move_forward_ex(Z_ARRVAL(zbacktrace), &position);
-
-               if (!(tmp = zend_hash_get_current_data_ex(Z_ARRVAL(zbacktrace), &position))) {
-                       phpdbg_write("frame", "id=\"%d\" symbol=\"{main}\" file=\"%s\" line=\"%d\"", "frame #%d: {main} at %s:%ld", i, Z_STRVAL_P(file), Z_LVAL_P(line));
-                       break;
-               }
-
+       while ((tmp = zend_hash_get_current_data_ex(Z_ARRVAL(zbacktrace), &position))) {
                if (file) { /* userland */
                        phpdbg_out("frame #%d: ", i);
                        phpdbg_xml("<frame %r id=\"%d\" file=\"%s\" line=\"%d\"", i, Z_STRVAL_P(file), Z_LVAL_P(line));
@@ -227,12 +224,17 @@ void phpdbg_dump_backtrace(size_t num) /* {{{ */
                        phpdbg_dump_prototype(tmp);
                        phpdbg_out(" (internal function)\n");
                }
+
+               file = zend_hash_str_find(Z_ARRVAL_P(tmp), ZEND_STRL("file"));
+               line = zend_hash_str_find(Z_ARRVAL_P(tmp), ZEND_STRL("line"));
+               zend_hash_move_forward_ex(Z_ARRVAL(zbacktrace), &position);
        }
 
-       phpdbg_out("\n");
+       phpdbg_writeln("frame", "id=\"%d\" symbol=\"{main}\" file=\"%s\" line=\"%d\"", "frame #%d: {main} at %s:%ld", i, Z_STRVAL_P(file), Z_LVAL_P(line));
        phpdbg_xml("</backtrace>");
 
        zval_dtor(&zbacktrace);
+       zend_string_release(Z_STR(startfile));
 
        PHPDBG_OUTPUT_BACKUP_RESTORE();
 } /* }}} */