In case you work with a lot of different Magento instances as a temporary project you might want to have a nice method to check debug backtrace of some function execution in Magento 2 quickly without installing or enabling additional software on the server, e.g. Xdebug.

In this case, you can use the native Magento backtrace function from \Magento\Framework\Debug class and call it whenever you need:

\Magento\Framework\Debug::backtrace(false, true, false);

As a result, you will get this nice HTML debug-backtrace:

Magento 2 Debug Backtrace

You can also call the exit function to stop further code execution right after the backtrace.

Here is more information about the backtrace method:

* Prints or returns a backtrace
* @param bool $return return or print
* @param bool $html output in HTML format
* @param bool $withArgs add short arguments of methods
* @return string|bool
public static function backtrace($return = false, $html = true, $withArgs = true)

Additional Debug Backtrace Solution

If you don't like the look of the default Magento backtrace you can use a custom function. Just copy this code into your PHP class temporarily:

public static function debugHtmlBacktrace($title = '')
    $result = '';
    foreach(debug_backtrace() as $_stack) {
        $result .= '<tr>
            <td>' . (isset($_stack['file']) ? $_stack['file'] : '') . '</td>
            <td>' . (isset($_stack['line']) ? $_stack['line'] : '') . '</td>
            <td>' . (isset($_stack['function']) ? $_stack['function'] : '') . '</td>

    return '<br/>' . $title . '<table border="1">
        <tr><td>File</td><td>Line</td><td>Function</td></tr>' . $result . '</table>';

and execute it by:

echo self::debugHtmlBacktrace();

Here is the result example:

Magento 2 Debug Backtrace